From 4bd20aac8c9404bcb04b49b13c4145f12f4ff48e Mon Sep 17 00:00:00 2001 From: "jordan@hack_attack" Date: Mon, 3 Oct 2016 13:06:40 -0700 Subject: [PATCH] page allocation is wrong --- src/apc/ir.c | 30 +++++--------- src/apc/ir.h | 26 ++---------- src/apc/irmem.c | 104 ++++++++++++++++++++++++------------------------ 3 files changed, 63 insertions(+), 97 deletions(-) diff --git a/src/apc/ir.c b/src/apc/ir.c index fe613ba..8030755 100644 --- a/src/apc/ir.c +++ b/src/apc/ir.c @@ -50,10 +50,6 @@ extern struct vdat* curr_vdat(void); -extern -struct ele* -curr_ele(void); - extern struct set* curr_set(void); @@ -272,16 +268,13 @@ insert_ele_label uint64_t ref_id ) { - struct ele* curr_elep; struct odat* curr_odatp; - curr_elep = curr_ele(); curr_odatp = alloc_odat(); memmove(curr_odatp->name, name, 32); + curr_odatp->ref_id = ref_id; - memmove(curr_elep->name, name, 32); - curr_elep->ref_id = ref_id; } /* We don't make an odat here, at output time we will resolve @@ -297,17 +290,17 @@ insert_ele_olink struct link* curr_linkp; curr_cdatp = curr_cdat(); - curr_elep = curr_ele(); + //curr_elep = curr_ele(); curr_linkp = alloc_link(); - curr_elep->cdat_idx = curr_cdatp->idx; - curr_elep->ref_id = ref_id; + //curr_elep->cdat_idx = curr_cdatp->idx; + //curr_elep->ref_id = ref_id; curr_linkp->type = 1; curr_linkp->link_t.olink.ref_id = ref_id; curr_linkp->cdat_idx = curr_cdatp->idx; curr_linkp->set_idx = curr_cdatp->num_sets++; - curr_linkp->ele_idx = curr_setp->num_ele++; + //curr_linkp->ele_idx = curr_setp->num_ele++; } @@ -330,7 +323,7 @@ insert_ele_vlink curr_linkp->cdat_idx = curr_cdatp->idx; curr_linkp->type = 2; curr_linkp->set_idx = curr_cdatp->num_sets; - curr_linkp->ele_idx = curr_setp->num_ele; + //curr_linkp->ele_idx = curr_setp->num_ele; curr_linkp->link_t.vlink.ref_id = ref_id; memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); @@ -352,7 +345,7 @@ insert_ele_svlink curr_linkp->cdat_idx = curr_cdatp->idx; curr_linkp->type = 3; - curr_linkp->ele_idx = curr_setp->num_ele; + //curr_linkp->ele_idx = curr_setp->num_ele; curr_linkp->link_t.svlink.ref_id = ref_id; @@ -372,25 +365,20 @@ insert_ele() struct ref* prev_refp; - curr_cdatp = curr_cdat(); curr_odatp = curr_odat(); //malloced @ insert_ele_label curr_vdatp = curr_vdat(); curr_setp = curr_set(); - curr_elep = curr_ele(); curr_refp = alloc_ref(); prev_refp = prev_ref(); curr_vdatp->creator = curr_odatp; - /* Populate ele in cdat */ - curr_elep->cdat_idx = curr_cdatp->idx; - curr_setp->num_ele++; /* Populate odat for ele */ curr_odatp->cdat_idx = curr_cdatp->idx; curr_odatp->refp = curr_refp; - /* Add ele to ref_buf */ - ref_id = curr_elep->ref_id; + ref_id = curr_odatp->ref_id; + if(ref_id == -1) /* user did not define a ref_id so */ { ref_id = ss_ref_id; diff --git a/src/apc/ir.h b/src/apc/ir.h index ff4a4f1..0292e01 100644 --- a/src/apc/ir.h +++ b/src/apc/ir.h @@ -25,6 +25,8 @@ #define MAX_CLASSES 256 #define MAX_FRAMES 256 #define PTRS_IN_PAGE 1024 +#define MAX_CHUNKS 256 +#define PAGES_PER_CHUNK 16 /* General: All information from the directory structure is stored in */ /* five buffers that comprise the IR: cdat_buf, odat_buf, vdat_buf, ref_buf */ @@ -46,26 +48,11 @@ because cdats have a root cdat that all cdats are a subclass of. This root cdat can have a set_list like other cdats. */ -/* Elements: Ele stands for element and has two representations in the IR. */ -/* In the cdat_buf eles store their name, cdat_idx (their classes index in */ -/* the cdat_buf) and the ref_id (refer to ref ). In the odat_buf, eles store */ -/* their object data (odat). At output time, the ref_id is dereferenced to */ -/* determine the elements odat which is the data that the engine expects */ -extern struct cdat** cdat_stackp; -/* from an element. */ - - /* All bufs are of pointers to their respective structs. When a buf is full */ /* (number of data structs pointers >= max number of data struct pointers), */ /* we need to allocate a more pointers for that buf. Allocate these */ /* pointers a page at a time (1024 = Page bytes (4096)/bytes per pointer(4)) */ -struct ele { - char name[32]; - uint64_t ref_id; - int cdat_idx; -}; - /* Sets: The set is similar to the ele, but it contains a list of its */ /* elements. The set is populated at parse time AFTER the elements are */ /* populated, due to the nature of bottom up parsing. */ @@ -74,8 +61,6 @@ struct set { char name[32]; uint64_t ref_id; int cdat_idx; - int num_ele; - struct ele ele_list[MAX_ELES]; }; /* Cdats: A cdat is a class data structure. Cdats serve as the central */ @@ -193,12 +178,6 @@ struct link { TODO: Need more info about objects at runtime, to described the reasoning behind odat structure at compile-time*/ -/* Each set has a quad_list or a list of quads. The quad_list - is the ? */ -struct quad { - int x, y, z; - uint64_t ref_id; //rgba -}; struct root { int x, y, z; @@ -209,6 +188,7 @@ struct odat { int vdat_id; int cdat_idx; int hitbox; + uint64_t ref_id; struct root root; struct ref* refp; /* pointer to it's ref on ref_list */ void* quad_filep; diff --git a/src/apc/irmem.c b/src/apc/irmem.c index 958910d..140a16a 100644 --- a/src/apc/irmem.c +++ b/src/apc/irmem.c @@ -23,8 +23,6 @@ struct odat* curr_odat(void); struct vdat* curr_vdat(void); -struct ele* -curr_ele(void); struct set* curr_set(void); struct ref* @@ -34,20 +32,23 @@ curr_model(void); void inc_posts(void); -#define CURR_CDAT (*cdat_stackp) -#define CURR_SET set_list[CURR_CDAT->num_sets] -#define CURR_ELE ele_list[CURR_CDAT->CURR_SET.num_ele] -#define PREV_REF (ref_buf[num_refs-1]) -#define CURR_REF (ref_buf[num_refs]) -#define PREV_ODAT (odat_buf[num_odats-1]) -#define CURR_ODAT (odat_buf[num_odats]) -#define CURR_VDAT (vdat_buf[num_vdats]) -#define PREV_VDAT (vdat_buf[num_vdats-1]) -#define CURR_MODEL (CURR_VDAT->model_list[CURR_VDAT->num_models]) -#define CURR_LINK (link_buf[num_links]) -#define CURR_POST (post_buf[num_posts]) -#define CURR_QUAD (CURR_ODAT->quad_file) +#define CURR_CDAT (*cdat_stackp) +#define CURR_SET set_list[CURR_CDAT->num_sets] +#define REF_IDX (num_refs % (refs_per_page * pages_per_chunk)) +#define PREV_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize - (sizeof (struct ref)))) +#define CURR_REF (ref_buf[num_ref_chunks] + (REF_IDX * (sizeof (struct ref)) + pagesize)) +#define ODAT_IDX (num_odats % (odats_per_page * pages_per_chunk)) +#define CURR_ODAT (odat_buf[num_odat_chunks] + (ODAT_IDX * (sizeof (struct odat)) + pagesize)) +#define VDAT_IDX (num_vdats % (vdats_per_page * pages_per_chunk)) +#define CURR_VDAT (vdat_buf[num_vdat_chunks] + (VDAT_IDX * (sizeof (struct vdat)) + pagesize)) +#define CURR_MODEL (CURR_VDAT.model_list[CURR_VDAT.num_models]) +#define CURR_LINK (link_buf[num_links]) +#define CURR_POST (post_buf[num_posts]) +#define CURR_QUAD (CURR_ODAT->quad_file) +long pagesize; + +int pages_per_chunk = 10; int num_cdats = 0; int curr_max_cdats = PTRS_IN_PAGE; @@ -57,19 +58,20 @@ struct cdat* cdat_stack[PTRS_IN_PAGE]; struct cdat** cdat_stackp; -int num_odats = -1; -int curr_max_odats = PTRS_IN_PAGE; -struct odat* odat_buf[PTRS_IN_PAGE]; - +int num_odat_chunks = 0; +int num_odats = 0; +void* odat_buf[MAX_CHUNKS]; +long odats_per_page; -int num_vdats = -1; -int curr_max_vdats = PTRS_IN_PAGE; -struct vdat* vdat_buf[PTRS_IN_PAGE]; +int num_vdat_chunks = 0; +int num_vdats = 0; +void* vdat_buf[MAX_CHUNKS]; +long vdats_per_page; - -int num_refs = -1; -int curr_max_refs = PTRS_IN_PAGE; -struct ref* ref_buf[PTRS_IN_PAGE]; +int num_ref_chunks = 0; +int num_refs = 0; +void* ref_buf[MAX_CHUNKS]; +long refs_per_page; uint64_t ss_ref_id = 0x00FFFFFF; /* system space for ref_ids */ int num_posts = -1; @@ -101,7 +103,12 @@ ir_init() cdat_stackp = cdat_stack; *cdat_stackp++ = cdat_buf[num_cdats++]; - return 0; + pagesize = sysconf(_SC_PAGESIZE); + odats_per_page = (sizeof (struct odat)/pagesize); + vdats_per_page = (sizeof (struct vdat)/pagesize); + refs_per_page = (sizeof (struct ref)/pagesize); + + return 0; } @@ -155,15 +162,14 @@ struct odat* alloc_odat () { - num_odats++; - if(num_odats >= curr_max_odats) - { if( (realloc((void*) odat_buf, PTRS_IN_PAGE * 4)) == NULL) - perror("realloc odat_buf failed"); - curr_max_odats += PTRS_IN_PAGE; + + if(!(num_odats % (odats_per_page * pages_per_chunk))) //chunk is full + { + num_odat_chunks++; + if( ((odat_buf[num_odat_chunks] = malloc(odats_per_page * pages_per_chunk)) == NULL) ) + perror("malloc odat chunk failed"); } - if( (CURR_ODAT = (struct odat*) malloc(sizeof (struct odat))) == NULL) - perror("malloc odat failed"); return CURR_ODAT; } @@ -173,13 +179,13 @@ alloc_vdat () { num_vdats++; - if(num_vdats >= curr_max_vdats) - { if( (realloc((void*) vdat_buf, PTRS_IN_PAGE * 4)) == NULL) - perror("realloc vdat_buf failed"); - curr_max_vdats += PTRS_IN_PAGE; + + if(!(num_vdats % (vdats_per_page * pages_per_chunk))) //chunk is full + { + num_vdat_chunks++; + if( ((vdat_buf[num_vdat_chunks] = malloc(vdats_per_page * pages_per_chunk)) == NULL) ) + perror("malloc vdat chunk failed"); } - if((CURR_VDAT = (struct vdat*) malloc(sizeof (struct vdat))) == NULL) - perror("malloc vdat failed"); } @@ -210,14 +216,12 @@ alloc_ref { CURR_POST = CURR_REF; inc_posts(); } - - if(num_refs >= curr_max_refs) - { if( (realloc((void*) ref_buf, PTRS_IN_PAGE * 4)) == NULL) - perror("realloc ref_buf failed"); - curr_max_refs += PTRS_IN_PAGE; + if(!(num_refs % (refs_per_page * pages_per_chunk))) //chunk is full + { + num_ref_chunks++; + if( ((ref_buf[num_ref_chunks] = malloc(refs_per_page * pages_per_chunk)) == NULL) ) + perror("malloc ref chunk failed"); } - if((CURR_REF = (struct ref*) malloc(sizeof (struct ref))) == NULL) - perror("malloc ref failed"); return CURR_REF; } @@ -260,12 +264,6 @@ curr_set { return &CURR_CDAT->CURR_SET; } -struct ele* -curr_ele -() -{ - return &CURR_CDAT->CURR_SET.CURR_ELE; -} struct ref* prev_ref () -- 2.18.0