The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
buddy.c File Reference

A Buddy System implementation. More...

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <errno.h>
#include <core/core.h>
#include <mm/mm.h>
#include <scheduler/process.h>
+ Include dependency graph for buddy.c:

Go to the source code of this file.

Functions

static int left_child (int index)
 
static int right_child (int index)
 
static int parent (int index)
 
static bool is_power_of_2 (int index)
 
static size_t next_power_of_2 (size_t size)
 
struct buddybuddy_new (struct lp_struct *lp, size_t num_of_fragments)
 
void buddy_destroy (struct buddy *self)
 
int buddy_alloc (struct buddy *self, size_t size)
 
void buddy_free (struct buddy *self, size_t offset)
 
void * allocate_lp_memory (struct lp_struct *lp, size_t size)
 
void free_lp_memory (struct lp_struct *lp, void *ptr)
 

Detailed Description

A Buddy System implementation.

This file is part of ROOT-Sim (ROme OpTimistic Simulator).

ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.

ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author

Definition in file buddy.c.

Function Documentation

int buddy_alloc ( struct buddy self,
size_t  size 
)

allocate size from a buddy system self

Returns
the offset from the beginning of memory to be managed

Definition at line 118 of file buddy.c.

+ Here is the call graph for this function:

struct buddy* buddy_new ( struct lp_struct lp,
size_t  num_of_fragments 
)

allocate a new buddy structure

Parameters
lpA pointer to the lp_struct of the LP from whose buddy we are allocating memory
num_of_fragmentsnumber of fragments of the memory to be managed
Returns
pointer to the allocated buddy structure

Definition at line 78 of file buddy.c.