diff --git a/Makefile b/Makefile index 26dda13..ce27fd2 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Students' Makefile for the Malloc Lab # CC = gcc -CFLAGS = -Wall -O2 -m32 +CFLAGS = -Wall -O2 -m32 -g03 OBJS = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o diff --git a/TAGS b/TAGS new file mode 100644 index 0000000..59a5da8 --- /dev/null +++ b/TAGS @@ -0,0 +1,274 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_OUTPUT_FILESEP slash /slash or backslash/ +!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/ +!_TAG_PROGRAM_AUTHOR Universal Ctags Team // +!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ +!_TAG_PROGRAM_URL https://ctags.io/ /official site/ +!_TAG_PROGRAM_VERSION 0.0.0 /a3c87ab5/ +ALIGN mm.c /^#define ALIGN(/;" d file: signature:(size) +ALIGNMENT config.h /^#define ALIGNMENT /;" d +ALIGNMENT mm.c /^#define ALIGNMENT /;" d file: +ALLOC mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" e enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +AVG_LIBC_THRUPUT config.h /^#define AVG_LIBC_THRUPUT /;" d +CACHE_BLOCK fcyc.c /^#define CACHE_BLOCK /;" d file: +CACHE_BYTES fcyc.c /^#define CACHE_BYTES /;" d file: +CC Makefile /^CC = gcc$/;" m +CFLAGS Makefile /^CFLAGS = -Wall -O2 -m32 -g03$/;" m +CHUNKSIZE mm.c /^#define CHUNKSIZE /;" d file: +CLEAR_CACHE fcyc.c /^#define CLEAR_CACHE /;" d file: +COMPENSATE fcyc.c /^#define COMPENSATE /;" d file: +DEFAULT_TRACEFILES config.h /^#define DEFAULT_TRACEFILES /;" d +DSIZE mm.c /^#define DSIZE /;" d file: +EPSILON fcyc.c /^#define EPSILON /;" d file: +FREE mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" e enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +FTRP mm.c /^#define FTRP(/;" d file: signature:(bp) +GET mm.c /^#define GET(/;" d file: signature:(p) +GET_ALLOC mm.c /^#define GET_ALLOC(/;" d file: signature:(p) +GET_SIZE mm.c /^#define GET_SIZE(/;" d file: signature:(p) +HDRLINES mdriver.c /^#define HDRLINES /;" d file: +HDRP mm.c /^#define HDRP(/;" d file: signature:(bp) +IS_ALIGNED mdriver.c /^#define IS_ALIGNED(/;" d file: signature:(p) +K fcyc.c /^#define K /;" d file: +KEEP_SAMPLES fcyc.c /^#define KEEP_SAMPLES /;" d file: +KEEP_VALS fcyc.c /^#define KEEP_VALS /;" d file: +LINENUM mdriver.c /^#define LINENUM(/;" d file: signature:(i) +MAX mm.c /^#define MAX(/;" d file: signature:(x,y) +MAXLINE mdriver.c /^#define MAXLINE /;" d file: +MAXSAMPLES fcyc.c /^#define MAXSAMPLES /;" d file: +MAX_ETIME ftimer.c /^#define MAX_ETIME /;" d file: +MAX_HEAP config.h /^#define MAX_HEAP /;" d +Mhz fsecs.c /^static double Mhz; \/* estimated CPU clock frequency *\/$/;" v typeref:typename:double file: +NEVENT clock.c /^#define NEVENT /;" d file: +NEXT_BLKP mm.c /^#define NEXT_BLKP(/;" d file: signature:(bp) +OBJS Makefile /^OBJS = mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o$/;" m +PACK mm.c /^#define PACK(/;" d file: signature:(size,alloc) +PREV_BLKP mm.c /^#define PREV_BLKP(/;" d file: signature:(bp) +PUT mm.c /^#define PUT(/;" d file: signature:(p,val) +REALLOC mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" e enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +RECORDTHRESH clock.c /^#define RECORDTHRESH /;" d file: +SIZE_T_SIZE mm.c /^#define SIZE_T_SIZE /;" d file: +THRESHOLD clock.c /^#define THRESHOLD /;" d file: +TRACEDIR config.h /^#define TRACEDIR /;" d +USE_FCYC config.h /^#define USE_FCYC /;" d +USE_GETTOD config.h /^#define USE_GETTOD /;" d +USE_ITIMER config.h /^#define USE_ITIMER /;" d +UTIL_WEIGHT config.h /^#define UTIL_WEIGHT /;" d +WSIZE mm.c /^#define WSIZE /;" d file: +__CONFIG_H_ config.h /^#define __CONFIG_H_$/;" d +__anon19bd20ef0108 mdriver.c /^typedef struct {$/;" s file: +__anon19bd20ef0108::ALLOC mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" e enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +__anon19bd20ef0108::FREE mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" e enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +__anon19bd20ef0108::REALLOC mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" e enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +__anon19bd20ef0108::__anon19bd20ef0203 mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" g struct:__anon19bd20ef0108 file: access:public +__anon19bd20ef0108::index mdriver.c /^ int index; \/* index for free() to use later *\/$/;" m struct:__anon19bd20ef0108 typeref:typename:int file: access:public +__anon19bd20ef0108::size mdriver.c /^ int size; \/* byte size of alloc\/realloc request *\/$/;" m struct:__anon19bd20ef0108 typeref:typename:int file: access:public +__anon19bd20ef0108::type mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" m struct:__anon19bd20ef0108 typeref:enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +__anon19bd20ef0203 mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" g struct:__anon19bd20ef0108 file: access:public +__anon19bd20ef0308 mdriver.c /^typedef struct {$/;" s file: +__anon19bd20ef0308::block_sizes mdriver.c /^ size_t *block_sizes; \/* ... and a corresponding array of payload sizes *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:size_t * file: access:public +__anon19bd20ef0308::blocks mdriver.c /^ char **blocks; \/* array of ptrs returned by malloc\/realloc... *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:char ** file: access:public +__anon19bd20ef0308::num_ids mdriver.c /^ int num_ids; \/* number of alloc\/realloc ids *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +__anon19bd20ef0308::num_ops mdriver.c /^ int num_ops; \/* number of distinct requests *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +__anon19bd20ef0308::ops mdriver.c /^ traceop_t *ops; \/* array of requests *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:traceop_t * file: access:public +__anon19bd20ef0308::sugg_heapsize mdriver.c /^ int sugg_heapsize; \/* suggested heap size (unused) *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +__anon19bd20ef0308::weight mdriver.c /^ int weight; \/* weight for this trace (unused) *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +__anon19bd20ef0408 mdriver.c /^typedef struct {$/;" s file: +__anon19bd20ef0408::ranges mdriver.c /^ range_t *ranges;$/;" m struct:__anon19bd20ef0408 typeref:typename:range_t * file: access:public +__anon19bd20ef0408::trace mdriver.c /^ trace_t *trace; $/;" m struct:__anon19bd20ef0408 typeref:typename:trace_t * file: access:public +__anon19bd20ef0508 mdriver.c /^typedef struct {$/;" s file: +__anon19bd20ef0508::ops mdriver.c /^ double ops; \/* number of ops (malloc\/free\/realloc) in the trace *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:double file: access:public +__anon19bd20ef0508::secs mdriver.c /^ double secs; \/* number of secs needed to run the trace *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:double file: access:public +__anon19bd20ef0508::util mdriver.c /^ double util; \/* space utilization for this trace (always 0 for libc) *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:double file: access:public +__anon19bd20ef0508::valid mdriver.c /^ int valid; \/* was the trace processed correctly by the allocator? *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:int file: access:public +__anon7c9aaad50108 mm.h /^typedef struct {$/;" s +__anon7c9aaad50108::id1 mm.h /^ char *id1; \/* login ID of first member *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +__anon7c9aaad50108::id2 mm.h /^ char *id2; \/* login ID of second member *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +__anon7c9aaad50108::name1 mm.h /^ char *name1; \/* full name of first member *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +__anon7c9aaad50108::name2 mm.h /^ char *name2; \/* full name of second member (if any) *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +__anon7c9aaad50108::teamname mm.h /^ char *teamname; \/* ID1+ID2 or ID1 *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +access_counter clock.c /^void access_counter(unsigned *hi, unsigned *lo)$/;" f typeref:typename:void signature:(unsigned * hi,unsigned * lo) +add_range mdriver.c /^static int add_range(range_t **ranges, char *lo, int size, $/;" f typeref:typename:int file: signature:(range_t ** ranges,char * lo,int size,int tracenum,int opnum) +add_range mdriver.c /^static int add_range(range_t **ranges, char *lo, int size, $/;" p typeref:typename:int file: signature:(range_t ** ranges,char * lo,int size,int tracenum,int opnum) +add_sample fcyc.c /^static void add_sample(double val)$/;" f typeref:typename:void file: signature:(double val) +app_error mdriver.c /^static void app_error(char *msg);$/;" p typeref:typename:void file: signature:(char * msg) +app_error mdriver.c /^void app_error(char *msg) $/;" f typeref:typename:void signature:(char * msg) +block_sizes mdriver.c /^ size_t *block_sizes; \/* ... and a corresponding array of payload sizes *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:size_t * file: access:public +blocks mdriver.c /^ char **blocks; \/* array of ptrs returned by malloc\/realloc... *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:char ** file: access:public +cache_block fcyc.c /^static int cache_block = CACHE_BLOCK;$/;" v typeref:typename:int file: +cache_buf fcyc.c /^static int *cache_buf = NULL;$/;" v typeref:typename:int * file: +cache_bytes fcyc.c /^static int cache_bytes = CACHE_BYTES;$/;" v typeref:typename:int file: +callibrate clock.c /^static void callibrate(int verbose)$/;" f typeref:typename:void file: signature:(int verbose) +clean Makefile /^clean:$/;" t +clear fcyc.c /^static void clear()$/;" f typeref:typename:void file: signature:() +clear_cache fcyc.c /^static int clear_cache = CLEAR_CACHE;$/;" v typeref:typename:int file: +clear_ranges mdriver.c /^static void clear_ranges(range_t **ranges)$/;" f typeref:typename:void file: signature:(range_t ** ranges) +clear_ranges mdriver.c /^static void clear_ranges(range_t **ranges);$/;" p typeref:typename:void file: signature:(range_t ** ranges) +clock.o Makefile /^clock.o: clock.c clock.h$/;" t +coalesce mm.c /^static void *coalesce(void *bp) {$/;" f typeref:typename:void * file: signature:(void * bp) +compensate fcyc.c /^static int compensate = COMPENSATE;$/;" v typeref:typename:int file: +counter clock.c /^static unsigned int (*counter)(void)= (void *)counterRoutine;$/;" v typeref:typename:unsigned int (*)(void) file: +counterRoutine clock.c /^static unsigned int counterRoutine[] =$/;" v typeref:typename:unsigned int[] file: +cyc_hi clock.c /^static unsigned cyc_hi = 0;$/;" v typeref:typename:unsigned file: +cyc_lo clock.c /^static unsigned cyc_lo = 0;$/;" v typeref:typename:unsigned file: +cyc_per_tick clock.c /^static double cyc_per_tick = 0.0;$/;" v typeref:typename:double file: +default_tracefiles mdriver.c /^static char *default_tracefiles[] = { $/;" v typeref:typename:char * [] file: +epsilon fcyc.c /^static double epsilon = EPSILON;$/;" v typeref:typename:double file: +errors mdriver.c /^static int errors = 0; \/* number of errs found when running student malloc *\/$/;" v typeref:typename:int file: +eval_libc_speed mdriver.c /^static void eval_libc_speed(void *ptr)$/;" f typeref:typename:void file: signature:(void * ptr) +eval_libc_speed mdriver.c /^static void eval_libc_speed(void *ptr);$/;" p typeref:typename:void file: signature:(void * ptr) +eval_libc_valid mdriver.c /^static int eval_libc_valid(trace_t *trace, int tracenum)$/;" f typeref:typename:int file: signature:(trace_t * trace,int tracenum) +eval_libc_valid mdriver.c /^static int eval_libc_valid(trace_t *trace, int tracenum);$/;" p typeref:typename:int file: signature:(trace_t * trace,int tracenum) +eval_mm_speed mdriver.c /^static void eval_mm_speed(void *ptr)$/;" f typeref:typename:void file: signature:(void * ptr) +eval_mm_speed mdriver.c /^static void eval_mm_speed(void *ptr);$/;" p typeref:typename:void file: signature:(void * ptr) +eval_mm_util mdriver.c /^static double eval_mm_util(trace_t *trace, int tracenum, range_t **ranges)$/;" f typeref:typename:double file: signature:(trace_t * trace,int tracenum,range_t ** ranges) +eval_mm_util mdriver.c /^static double eval_mm_util(trace_t *trace, int tracenum, range_t **ranges);$/;" p typeref:typename:double file: signature:(trace_t * trace,int tracenum,range_t ** ranges) +eval_mm_valid mdriver.c /^static int eval_mm_valid(trace_t *trace, int tracenum, range_t **ranges) $/;" f typeref:typename:int file: signature:(trace_t * trace,int tracenum,range_t ** ranges) +eval_mm_valid mdriver.c /^static int eval_mm_valid(trace_t *trace, int tracenum, range_t **ranges);$/;" p typeref:typename:int file: signature:(trace_t * trace,int tracenum,range_t ** ranges) +extend_heap mm.c /^static void *extend_heap(size_t words)$/;" f typeref:typename:void * file: signature:(size_t words) +fcyc fcyc.c /^double fcyc(test_funct f, void *argp)$/;" f typeref:typename:double signature:(test_funct f,void * argp) +fcyc fcyc.h /^double fcyc(test_funct f, void* argp);$/;" p typeref:typename:double signature:(test_funct f,void * argp) +fcyc.o Makefile /^fcyc.o: fcyc.c fcyc.h$/;" t +find_fit mm.c /^static void *find_fit(size_t asize)$/;" f typeref:typename:void * file: signature:(size_t asize) +first_p ftimer.c /^static struct itimerval first_p; \/* prof time*\/$/;" v typeref:struct:itimerval file: +first_r ftimer.c /^static struct itimerval first_r; \/* real time *\/$/;" v typeref:struct:itimerval file: +first_u ftimer.c /^static struct itimerval first_u; \/* user time *\/$/;" v typeref:struct:itimerval file: +free_trace mdriver.c /^static void free_trace(trace_t *trace);$/;" p typeref:typename:void file: signature:(trace_t * trace) +free_trace mdriver.c /^void free_trace(trace_t *trace)$/;" f typeref:typename:void signature:(trace_t * trace) +fsecs fsecs.c /^double fsecs(fsecs_test_funct f, void *argp) $/;" f typeref:typename:double signature:(fsecs_test_funct f,void * argp) +fsecs fsecs.h /^double fsecs(fsecs_test_funct f, void *argp);$/;" p typeref:typename:double signature:(fsecs_test_funct f,void * argp) +fsecs.o Makefile /^fsecs.o: fsecs.c fsecs.h config.h$/;" t +fsecs_test_funct fsecs.h /^typedef void (*fsecs_test_funct)(void *);$/;" t typeref:typename:void (*)(void *) +ftimer.o Makefile /^ftimer.o: ftimer.c ftimer.h config.h$/;" t +ftimer_gettod ftimer.c /^double ftimer_gettod(ftimer_test_funct f, void *argp, int n)$/;" f typeref:typename:double signature:(ftimer_test_funct f,void * argp,int n) +ftimer_gettod ftimer.h /^double ftimer_gettod(ftimer_test_funct f, void *argp, int n);$/;" p typeref:typename:double signature:(ftimer_test_funct f,void * argp,int n) +ftimer_itimer ftimer.c /^double ftimer_itimer(ftimer_test_funct f, void *argp, int n)$/;" f typeref:typename:double signature:(ftimer_test_funct f,void * argp,int n) +ftimer_itimer ftimer.h /^double ftimer_itimer(ftimer_test_funct f, void *argp, int n);$/;" p typeref:typename:double signature:(ftimer_test_funct f,void * argp,int n) +ftimer_test_funct ftimer.h /^typedef void (*ftimer_test_funct)(void *); $/;" t typeref:typename:void (*)(void *) +get_comp_counter clock.c /^double get_comp_counter() $/;" f typeref:typename:double signature:() +get_comp_counter clock.h /^double get_comp_counter();$/;" p typeref:typename:double signature:() +get_counter clock.c /^double get_counter() $/;" f typeref:typename:double signature:() +get_counter clock.c /^double get_counter()$/;" f typeref:typename:double signature:() +get_counter clock.h /^double get_counter();$/;" p typeref:typename:double signature:() +get_etime ftimer.c /^static double get_etime(void) {$/;" f typeref:typename:double file: signature:(void) +get_etime ftimer.c /^static double get_etime(void);$/;" p typeref:typename:double file: signature:(void) +has_converged fcyc.c /^static int has_converged()$/;" f typeref:typename:int file: signature:() +heap_listp mm.c /^static char *heap_listp;$/;" v typeref:typename:char * file: +hi mdriver.c /^ char *hi; \/* high payload address *\/$/;" m struct:range_t typeref:typename:char * file: access:public +id1 mm.h /^ char *id1; \/* login ID of first member *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +id2 mm.h /^ char *id2; \/* login ID of second member *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +index mdriver.c /^ int index; \/* index for free() to use later *\/$/;" m struct:__anon19bd20ef0108 typeref:typename:int file: access:public +init_etime ftimer.c /^static void init_etime(void)$/;" f typeref:typename:void file: signature:(void) +init_etime ftimer.c /^static void init_etime(void);$/;" p typeref:typename:void file: signature:(void) +init_fsecs fsecs.c /^void init_fsecs(void)$/;" f typeref:typename:void signature:(void) +init_fsecs fsecs.h /^void init_fsecs(void);$/;" p typeref:typename:void signature:(void) +init_sampler fcyc.c /^static void init_sampler()$/;" f typeref:typename:void file: signature:() +kbest fcyc.c /^static int kbest = K;$/;" v typeref:typename:int file: +lo mdriver.c /^ char *lo; \/* low payload address *\/$/;" m struct:range_t typeref:typename:char * file: access:public +main mdriver.c /^int main(int argc, char **argv)$/;" f typeref:typename:int signature:(int argc,char ** argv) +malloc_error mdriver.c /^static void malloc_error(int tracenum, int opnum, char *msg);$/;" p typeref:typename:void file: signature:(int tracenum,int opnum,char * msg) +malloc_error mdriver.c /^void malloc_error(int tracenum, int opnum, char *msg)$/;" f typeref:typename:void signature:(int tracenum,int opnum,char * msg) +maxsamples fcyc.c /^static int maxsamples = MAXSAMPLES;$/;" v typeref:typename:int file: +mdriver Makefile /^mdriver: $(OBJS)$/;" t +mdriver.o Makefile /^mdriver.o: mdriver.c fsecs.h fcyc.h clock.h memlib.h config.h mm.h$/;" t +mem_brk memlib.c /^static char *mem_brk; \/* points to last byte of heap *\/$/;" v typeref:typename:char * file: +mem_deinit memlib.c /^void mem_deinit(void)$/;" f typeref:typename:void signature:(void) +mem_deinit memlib.h /^void mem_deinit(void);$/;" p typeref:typename:void signature:(void) +mem_heap_hi memlib.c /^void *mem_heap_hi()$/;" f typeref:typename:void * signature:() +mem_heap_hi memlib.h /^void *mem_heap_hi(void);$/;" p typeref:typename:void * signature:(void) +mem_heap_lo memlib.c /^void *mem_heap_lo()$/;" f typeref:typename:void * signature:() +mem_heap_lo memlib.h /^void *mem_heap_lo(void);$/;" p typeref:typename:void * signature:(void) +mem_heapsize memlib.c /^size_t mem_heapsize() $/;" f typeref:typename:size_t signature:() +mem_heapsize memlib.h /^size_t mem_heapsize(void);$/;" p typeref:typename:size_t signature:(void) +mem_init memlib.c /^void mem_init(void)$/;" f typeref:typename:void signature:(void) +mem_init memlib.h /^void mem_init(void); $/;" p typeref:typename:void signature:(void) +mem_max_addr memlib.c /^static char *mem_max_addr; \/* largest legal heap address *\/ $/;" v typeref:typename:char * file: +mem_pagesize memlib.c /^size_t mem_pagesize()$/;" f typeref:typename:size_t signature:() +mem_pagesize memlib.h /^size_t mem_pagesize(void);$/;" p typeref:typename:size_t signature:(void) +mem_reset_brk memlib.c /^void mem_reset_brk()$/;" f typeref:typename:void signature:() +mem_reset_brk memlib.h /^void mem_reset_brk(void); $/;" p typeref:typename:void signature:(void) +mem_sbrk memlib.c /^void *mem_sbrk(int incr) $/;" f typeref:typename:void * signature:(int incr) +mem_sbrk memlib.h /^void *mem_sbrk(int incr);$/;" p typeref:typename:void * signature:(int incr) +mem_start_brk memlib.c /^static char *mem_start_brk; \/* points to first byte of heap *\/$/;" v typeref:typename:char * file: +memlib.o Makefile /^memlib.o: memlib.c memlib.h$/;" t +mhz clock.c /^double mhz(int verbose)$/;" f typeref:typename:double signature:(int verbose) +mhz clock.h /^double mhz(int verbose);$/;" p typeref:typename:double signature:(int verbose) +mhz_full clock.c /^double mhz_full(int verbose, int sleeptime)$/;" f typeref:typename:double signature:(int verbose,int sleeptime) +mhz_full clock.h /^double mhz_full(int verbose, int sleeptime);$/;" p typeref:typename:double signature:(int verbose,int sleeptime) +mm.o Makefile /^mm.o: mm.c mm.h memlib.h$/;" t +mm_free mm.c /^void mm_free(void *ptr)$/;" f typeref:typename:void signature:(void * ptr) +mm_free mm.h /^extern void mm_free (void *ptr);$/;" p typeref:typename:void signature:(void * ptr) +mm_init mm.c /^int mm_init(void)$/;" f typeref:typename:int signature:(void) +mm_init mm.h /^extern int mm_init (void);$/;" p typeref:typename:int signature:(void) +mm_malloc mm.c /^void *mm_malloc(size_t size)$/;" f typeref:typename:void * signature:(size_t size) +mm_malloc mm.h /^extern void *mm_malloc (size_t size);$/;" p typeref:typename:void * signature:(size_t size) +mm_realloc mm.c /^void *mm_realloc(void *ptr, size_t size)$/;" f typeref:typename:void * signature:(void * ptr,size_t size) +mm_realloc mm.h /^extern void *mm_realloc(void *ptr, size_t size);$/;" p typeref:typename:void * signature:(void * ptr,size_t size) +msg mdriver.c /^char msg[MAXLINE]; \/* for whenever we need to compose an error message *\/$/;" v typeref:typename:char[] +name1 mm.h /^ char *name1; \/* full name of first member *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +name2 mm.h /^ char *name2; \/* full name of second member (if any) *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +next mdriver.c /^ struct range_t *next; \/* next list element *\/$/;" m struct:range_t typeref:struct:range_t * file: access:public +num_ids mdriver.c /^ int num_ids; \/* number of alloc\/realloc ids *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +num_ops mdriver.c /^ int num_ops; \/* number of distinct requests *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +ops mdriver.c /^ double ops; \/* number of ops (malloc\/free\/realloc) in the trace *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:double file: access:public +ops mdriver.c /^ traceop_t *ops; \/* array of requests *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:traceop_t * file: access:public +ovhd clock.c /^double ovhd()$/;" f typeref:typename:double signature:() +ovhd clock.h /^double ovhd();$/;" p typeref:typename:double signature:() +place mm.c /^static void place(void *bp, size_t asize)$/;" f typeref:typename:void file: signature:(void * bp,size_t asize) +printresults mdriver.c /^static void printresults(int n, stats_t *stats) $/;" f typeref:typename:void file: signature:(int n,stats_t * stats) +printresults mdriver.c /^static void printresults(int n, stats_t *stats);$/;" p typeref:typename:void file: signature:(int n,stats_t * stats) +range_t mdriver.c /^typedef struct range_t {$/;" s file: +range_t mdriver.c /^} range_t;$/;" t typeref:struct:range_t file: +range_t::hi mdriver.c /^ char *hi; \/* high payload address *\/$/;" m struct:range_t typeref:typename:char * file: access:public +range_t::lo mdriver.c /^ char *lo; \/* low payload address *\/$/;" m struct:range_t typeref:typename:char * file: access:public +range_t::next mdriver.c /^ struct range_t *next; \/* next list element *\/$/;" m struct:range_t typeref:struct:range_t * file: access:public +ranges mdriver.c /^ range_t *ranges;$/;" m struct:__anon19bd20ef0408 typeref:typename:range_t * file: access:public +read_trace mdriver.c /^static trace_t *read_trace(char *tracedir, char *filename)$/;" f typeref:typename:trace_t * file: signature:(char * tracedir,char * filename) +read_trace mdriver.c /^static trace_t *read_trace(char *tracedir, char *filename);$/;" p typeref:typename:trace_t * file: signature:(char * tracedir,char * filename) +remove_range mdriver.c /^static void remove_range(range_t **ranges, char *lo)$/;" f typeref:typename:void file: signature:(range_t ** ranges,char * lo) +remove_range mdriver.c /^static void remove_range(range_t **ranges, char *lo);$/;" p typeref:typename:void file: signature:(range_t ** ranges,char * lo) +samplecount fcyc.c /^static int samplecount = 0;$/;" v typeref:typename:int file: +samples fcyc.c /^static double *samples = NULL;$/;" v typeref:typename:double * file: +secs mdriver.c /^ double secs; \/* number of secs needed to run the trace *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:double file: access:public +set_fcyc_cache_block fcyc.c /^void set_fcyc_cache_block(int bytes) {$/;" f typeref:typename:void signature:(int bytes) +set_fcyc_cache_block fcyc.h /^void set_fcyc_cache_block(int bytes);$/;" p typeref:typename:void signature:(int bytes) +set_fcyc_cache_size fcyc.c /^void set_fcyc_cache_size(int bytes)$/;" f typeref:typename:void signature:(int bytes) +set_fcyc_cache_size fcyc.h /^void set_fcyc_cache_size(int bytes);$/;" p typeref:typename:void signature:(int bytes) +set_fcyc_clear_cache fcyc.c /^void set_fcyc_clear_cache(int clear)$/;" f typeref:typename:void signature:(int clear) +set_fcyc_clear_cache fcyc.h /^void set_fcyc_clear_cache(int clear);$/;" p typeref:typename:void signature:(int clear) +set_fcyc_compensate fcyc.c /^void set_fcyc_compensate(int compensate_arg)$/;" f typeref:typename:void signature:(int compensate_arg) +set_fcyc_compensate fcyc.h /^void set_fcyc_compensate(int compensate_arg);$/;" p typeref:typename:void signature:(int compensate_arg) +set_fcyc_epsilon fcyc.c /^void set_fcyc_epsilon(double epsilon_arg)$/;" f typeref:typename:void signature:(double epsilon_arg) +set_fcyc_epsilon fcyc.h /^void set_fcyc_epsilon(double epsilon_arg);$/;" p typeref:typename:void signature:(double epsilon_arg) +set_fcyc_k fcyc.c /^void set_fcyc_k(int k)$/;" f typeref:typename:void signature:(int k) +set_fcyc_k fcyc.h /^void set_fcyc_k(int k);$/;" p typeref:typename:void signature:(int k) +set_fcyc_maxsamples fcyc.c /^void set_fcyc_maxsamples(int maxsamples_arg)$/;" f typeref:typename:void signature:(int maxsamples_arg) +set_fcyc_maxsamples fcyc.h /^void set_fcyc_maxsamples(int maxsamples_arg);$/;" p typeref:typename:void signature:(int maxsamples_arg) +sink fcyc.c /^static volatile int sink = 0;$/;" v typeref:typename:volatile int file: +size mdriver.c /^ int size; \/* byte size of alloc\/realloc request *\/$/;" m struct:__anon19bd20ef0108 typeref:typename:int file: access:public +speed_t mdriver.c /^} speed_t;$/;" t typeref:struct:__anon19bd20ef0408 file: +start_comp_counter clock.c /^void start_comp_counter() $/;" f typeref:typename:void signature:() +start_comp_counter clock.h /^void start_comp_counter();$/;" p typeref:typename:void signature:() +start_counter clock.c /^void start_counter()$/;" f typeref:typename:void signature:() +start_counter clock.h /^void start_counter();$/;" p typeref:typename:void signature:() +start_tick clock.c /^static clock_t start_tick = 0;$/;" v typeref:typename:clock_t file: +stats_t mdriver.c /^} stats_t; $/;" t typeref:struct:__anon19bd20ef0508 file: +sugg_heapsize mdriver.c /^ int sugg_heapsize; \/* suggested heap size (unused) *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public +team mm.c /^team_t team = {$/;" v typeref:typename:team_t +team_t mm.h /^} team_t;$/;" t typeref:struct:__anon7c9aaad50108 +teamname mm.h /^ char *teamname; \/* ID1+ID2 or ID1 *\/$/;" m struct:__anon7c9aaad50108 typeref:typename:char * access:public +test_funct fcyc.h /^typedef void (*test_funct)(void *);$/;" t typeref:typename:void (*)(void *) +trace mdriver.c /^ trace_t *trace; $/;" m struct:__anon19bd20ef0408 typeref:typename:trace_t * file: access:public +trace_t mdriver.c /^} trace_t;$/;" t typeref:struct:__anon19bd20ef0308 file: +tracedir mdriver.c /^static char tracedir[MAXLINE] = TRACEDIR;$/;" v typeref:typename:char[] file: +traceop_t mdriver.c /^} traceop_t;$/;" t typeref:struct:__anon19bd20ef0108 file: +type mdriver.c /^ enum {ALLOC, FREE, REALLOC} type; \/* type of request *\/$/;" m struct:__anon19bd20ef0108 typeref:enum:__anon19bd20ef0108::__anon19bd20ef0203 file: access:public +unix_error mdriver.c /^static void unix_error(char *msg);$/;" p typeref:typename:void file: signature:(char * msg) +unix_error mdriver.c /^void unix_error(char *msg) $/;" f typeref:typename:void signature:(char * msg) +usage mdriver.c /^static void usage(void) $/;" f typeref:typename:void file: signature:(void) +usage mdriver.c /^static void usage(void);$/;" p typeref:typename:void file: signature:(void) +util mdriver.c /^ double util; \/* space utilization for this trace (always 0 for libc) *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:double file: access:public +valid mdriver.c /^ int valid; \/* was the trace processed correctly by the allocator? *\/$/;" m struct:__anon19bd20ef0508 typeref:typename:int file: access:public +values fcyc.c /^static double *values = NULL;$/;" v typeref:typename:double * file: +verbose mdriver.c /^int verbose = 0; \/* global flag for verbose output *\/$/;" v typeref:typename:int +weight mdriver.c /^ int weight; \/* weight for this trace (unused) *\/$/;" m struct:__anon19bd20ef0308 typeref:typename:int file: access:public diff --git a/mdriver b/mdriver new file mode 100755 index 0000000..a1d43d7 Binary files /dev/null and b/mdriver differ diff --git a/mm.c b/mm.c index 3c2e695..70c7e2e 100644 --- a/mm.c +++ b/mm.c @@ -41,38 +41,182 @@ team_t team = { /* rounds up to the nearest multiple of ALIGNMENT */ #define ALIGN(size) (((size) + (ALIGNMENT-1)) & ~0x7) - #define SIZE_T_SIZE (ALIGN(sizeof(size_t))) +/* Page 830, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ +/* Basic constants and macros */ +#define WSIZE 4 /* Word and header/footer size (bytes) */ +#define DSIZE 8 /* Double word size (bytes) */ +#define CHUNKSIZE (1<<12) /* Extend heap by this amount (bytes) */ + +#define MAX(x, y) ((x) > (y)? (x) : (y)) + +/* Pack a size and allocated bit into a word */ +#define PACK(size, alloc) ((size) | (alloc)) + +/* Read and write a word at address p */ +#define GET(p) (*(unsigned int *)(p)) +#define PUT(p, val) (*(unsigned int *)(p) = (val)) + +/* Read the size and allocated fields from address p */ +#define GET_SIZE(p) (GET(p) & ~0x7) +#define GET_ALLOC(p) (GET(p) & 0x1) + +/* Given block ptr bp, compute address of its header and footer */ +#define HDRP(bp) ((char *)(bp) - WSIZE) +#define FTRP(bp) ((char *)(bp) + GET_SIZE(HDRP(bp)) - DSIZE) + +/* Given block ptr bp, compute address of next and previous blocks */ +#define NEXT_BLKP(bp) ((char *)(bp) + GET_SIZE(((char *)(bp) - WSIZE))) +#define PREV_BLKP(bp) ((char *)(bp) - GET_SIZE(((char *)(bp) - DSIZE))) + +static char *heap_listp; + +/* Page 856-858, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ +static void place(void *bp, size_t asize) +{ + size_t csize = GET_SIZE(HDRP(bp)); + if ((csize - asize) >= (2*DSIZE)) { + PUT(HDRP(bp), PACK(asize, 1)); + PUT(FTRP(bp), PACK(asize, 1)); + bp = NEXT_BLKP(bp); + PUT(HDRP(bp), PACK(csize-asize, 0)); + PUT(FTRP(bp), PACK(csize-asize, 0)); + } + else { + PUT(HDRP(bp), PACK(csize, 1)); + PUT(FTRP(bp), PACK(csize, 1)); + } +} + +/* Page 856, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ +static void *find_fit(size_t asize) +{ + /* First fit search */ + void *bp; + + for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) { + if (!GET_ALLOC(HDRP(bp)) && (asize <= GET_SIZE(HDRP(bp)))) { + return bp; + } + } + return NULL; /* No fit */ +} + +/* Page 833, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ +static void *coalesce(void *bp) { + size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))); + size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); + size_t size = GET_SIZE(HDRP(bp)); + + if (prev_alloc && next_alloc) { /* Case 1 */ + return bp; + } else if (prev_alloc && !next_alloc) { /* Case 2 */ + size += GET_SIZE(HDRP(NEXT_BLKP(bp))); + PUT(HDRP(bp),PACK(size,0)); + PUT(FTRP(bp),PACK(size,0)); + } else if (!prev_alloc && next_alloc) { /* Case 3 */ + size += GET_SIZE(HDRP(PREV_BLKP(bp))); + PUT(FTRP(bp), PACK(size, 0)); + PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0)); + bp = PREV_BLKP(bp); + } else { /* Case 4 */ + size += GET_SIZE(HDRP(PREV_BLKP(bp))) + + GET_SIZE(FTRP(NEXT_BLKP(bp))); + PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0)); + PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0)); + bp = PREV_BLKP(bp); + } + return bp; +} + +/* Page 831, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ +static void *extend_heap(size_t words) +{ + char *bp; + size_t size; + + /* Allocate an even number of words to maintain alignment */ + size = (words % 2) ? (words+1) * WSIZE : words * WSIZE; + if ((long)(bp = mem_sbrk(size)) == -1) + return NULL; + + /* Initialize free block header/footer and the epilogue header */ + PUT(HDRP(bp), PACK(size,0)); /* Free block header */ + PUT(FTRP(bp), PACK(size,0)); /* Free block footer */ + PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* New epilogue header */ + + /* Coalesce if the previous block was free */ + return coalesce(bp); +} + + +/* Page 831, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ /* * mm_init - initialize the malloc package. */ int mm_init(void) { + /* Create the initial empty heap */ + if ((heap_listp = mem_sbrk(4*WSIZE)) == (void *)-1) + return -1; + PUT(heap_listp, 0); /* Alignment padding */ + PUT(heap_listp + (1*WSIZE), PACK(DSIZE, 1)); /* Prologue header */ + PUT(heap_listp + (2*WSIZE), PACK(DSIZE, 1)); /* Prologue footer */ + PUT(heap_listp + (3*WSIZE), PACK(0, 1)); /* Epilogue header */ + heap_listp += (2*WSIZE); + + /* Extend the empty heap with a free block of CHUNKSIZE bytes */ + if (extend_heap(CHUNKSIZE/WSIZE) == NULL) + return -1; return 0; } +/* Page 834, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ /* * mm_malloc - Allocate a block by incrementing the brk pointer. * Always allocate a block whose size is a multiple of the alignment. */ void *mm_malloc(size_t size) { - int newsize = ALIGN(size + SIZE_T_SIZE); - void *p = mem_sbrk(newsize); - if (p == (void *)-1) + size_t asize; + /* Adjusted block size */ + size_t extendsize; /* Amount to extend heap if no fit */ + char *bp; + + /* Ignore spurious requests */ + if (size == 0) return NULL; - else { - *(size_t *)p = size; - return (void *)((char *)p + SIZE_T_SIZE); + + /* Adjust block size to include overhead and alignment reqs. */ + if (size <= DSIZE) + asize = 2*DSIZE; + else + asize = DSIZE * ((size + (DSIZE) + (DSIZE-1)) / DSIZE); + /* Search the free list for a fit */ + if ((bp = find_fit(asize)) != NULL) { + place(bp, asize); + return bp; } + + /* No fit found. Get more memory and place the block */ + extendsize = MAX(asize,CHUNKSIZE); + if ((bp = extend_heap(extendsize/WSIZE)) == NULL) + return NULL; + place(bp, asize); + return bp; } +/* Page 833, Pearson R. Bryant – D. O’Hallaron. Computer Systems: A Programmer’s Perspective.3rd Edition, Pearson, 2003. */ /* * mm_free - Freeing a block does nothing. */ void mm_free(void *ptr) { + size_t size= GET_SIZE(HDRP(ptr)); + PUT(HDRP(ptr), PACK(size, 0)); + PUT(FTRP(ptr), PACK(size, 0)); + coalesce(ptr); } /* @@ -97,3 +241,8 @@ void *mm_realloc(void *ptr, size_t size) mm_free(oldptr); return newptr; } + +//////////////////////////////////////////////////////////////// +/// Helper Functions +//////////////////////////////////////////////////////////////// +