void *valloc_alloc(spdid_t spdid, spdid_t dest, unsigned long npages) { /* JWW print out a few things : spdid, heap ptr, make sure the heap ptr is sane */ void *ret = NULL; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; long off; /*JWW REMOVE THIS */ struct cos_component_information *ci; unsigned long page_off; void *hp; /* /JWW */ LOCK(); /*JWW REMOVE THIS */ ci = cos_get_vas_page(); if (cinfo_map(cos_spd_id(), (vaddr_t)ci, spdid)) { // error cos_release_vas_page(ci); printc("CINFO_MAP ERROR\n"); } hp = (void*)ci->cos_heap_ptr; // now print some things out. // printc("valloc alloc heap_ptr: %x, ucap_tbl: %x, npages: %ul \n", (unsigned int) hp, (unsigned int) ci->cos_user_caps, npages); /* /JWW */ page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; trac = cos_vect_lookup(&spd_vect, dest); if (!trac) { printc("valloc init being called\n"); if (__valloc_init(dest) || !(trac = cos_vect_lookup(&spd_vect, dest))) goto done; } // printc("valloc alloc past init\n"); occ = trac->map; assert(occ); // off = bitmap_extent_find_set(&occ->pgd_occupied[0], page_off, npages, MAP_MAX); off = bitmap_extent_find_set(&occ->pgd_occupied[0], 0, npages, MAP_MAX); if (off < 0) goto done; ret = ((char *)trac->extents[0].start) + (off * PAGE_SIZE); done: // printc("valloc alloc returning %x\n", (unsigned int) ret); UNLOCK(); return ret; }
static int __valloc_init(spdid_t spdid) { int ret = -1; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; struct cos_component_information *ci; unsigned long page_off; void *hp; if (cos_vect_lookup(&spd_vect, spdid)) goto success; trac = malloc(sizeof(struct spd_vas_tracker)); if (!trac) goto done; occ = alloc_page(); if (!occ) goto err_free1; ci = cos_get_vas_page(); if (cinfo_map(cos_spd_id(), (vaddr_t)ci, spdid)) goto err_free2; hp = (void*)ci->cos_heap_ptr; // printc("valloc init heap_ptr: %x\n", (unsigned int) hp); trac->spdid = spdid; trac->ci = ci; trac->map = occ; trac->extents[0].start = (void*)round_to_pgd_page(hp); trac->extents[0].end = (void*)round_up_to_pgd_page(hp); page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; bitmap_set_contig(&occ->pgd_occupied[0], page_off, (PGD_SIZE/PAGE_SIZE)-page_off, 1); cos_vect_add_id(&spd_vect, trac, spdid); assert(cos_vect_lookup(&spd_vect, spdid)); success: // printc("valloc init success\n"); ret = 0; done: return ret; err_free2: cos_release_vas_page(ci); free_page(occ); err_free1: free(trac); goto done; }
/** * maps the compoenents spdid info page on startup * I do it this way since not every component may require stacks or * what spdid's I even have access too. * I am not sure if this is the best way to handle this, but it * should work for now. */ static inline void get_cos_info_page(spdid_t spdid) { spdid_t s; int i; int found = 0; void *hp; if(spdid > MAX_NUM_SPDS){ BUG(); } for (i = 0; i < MAX_NUM_SPDS; i++) { s = cinfo_get_spdid(i); if(!s) { printc("Unable to map compoents cinfo page!\n"); BUG(); } if (s == spdid) { found = 1; break; } } if(!found){ DOUT("Could not find cinfo for spdid: %d\n", spdid); BUG(); } hp = cos_get_vas_page(); if(cinfo_map(cos_spd_id(), (vaddr_t)hp, s)){ DOUT("Could not map cinfo page for %d\n", spdid); BUG(); } spd_stk_info_list[spdid].ci = hp; DOUT("mapped -- id: %ld, hp:%x, sp:%x\n", spd_stk_info_list[spdid].ci->cos_this_spd_id, (unsigned int)spd_stk_info_list[spdid].ci->cos_heap_ptr, (unsigned int)spd_stk_info_list[spdid].ci->cos_stacks.freelists[0].freelist); }
/** * cos_init */ void cos_init(void *arg){ int i; struct cos_stk_item *stk_item; DOUT("<stkmgr>: STACK in cos_init\n"); memset(spd_stk_info_list, 0, sizeof(struct spd_stk_info) * MAX_NUM_SPDS); for(i = 0; i < MAX_NUM_SPDS; i++){ spd_stk_info_list[i].spdid = i; INIT_LIST(&spd_stk_info_list[i].stk_list, next, prev); INIT_LIST(&spd_stk_info_list[i].bthd_list, next, prev); } // Initialize our free stack list for(i = 0; i < MAX_NUM_STACKS; i++){ // put stk list is some known state stk_item = &(all_stk_list[i]); stk_item->stk = NULL; INIT_LIST(stk_item, next, prev); // allocate a page stk_item->hptr = alloc_page(); if (stk_item->hptr == NULL){ DOUT("<stk_mgr>: ERROR, could not allocate stack\n"); } else { // figure out or location of the top of the stack stk_item->stk = (struct cos_stk *)D_COS_STK_ADDR((char *)stk_item->hptr); freelist_add(stk_item); } } stacks_allocated = 0; // Map all of the spds we can into this component for (i = 0 ; i < MAX_NUM_SPDS ; i++) { spdid_t spdid; void *hp; hp = cos_get_vas_page(); spdid = cinfo_get_spdid(i); if (!spdid) break; if(cinfo_map(cos_spd_id(), (vaddr_t)hp, spdid)){ DOUT("Could not map cinfo page for %d\n", spdid); BUG(); } spd_stk_info_list[spdid].ci = hp; DOUT("mapped -- id: %ld, hp:%x, sp:%x\n", spd_stk_info_list[spdid].ci->cos_this_spd_id, (unsigned int)spd_stk_info_list[spdid].ci->cos_heap_ptr, (unsigned int)spd_stk_info_list[spdid].ci->cos_stacks.freelists[0].freelist); stacks_target += DEFAULT_TARGET_ALLOC; spd_stk_info_list[spdid].num_allocated = 0; spd_stk_info_list[spdid].num_desired = DEFAULT_TARGET_ALLOC; } LOCK_INIT(); DOUT("Done mapping components information pages!\n"); DOUT("<stkmgr>: init finished\n"); return; }
void cos_init(void *d) { DOUT("CBUFMgr: %d in spd %ld cbuf mgr running.....\n", cos_get_thd_id(), cos_spd_id()); LOCK_INIT(); cos_map_init_static(&cb_ids); BUG_ON(cos_map_add(&cb_ids, NULL)); /* reserve id 0 */ int i; memset(spd_tmem_info_list, 0, sizeof(struct spd_tmem_info) * MAX_NUM_SPDS); for(i = 0; i < MAX_NUM_SPDS; i++){ spd_tmem_info_list[i].spdid = i; INIT_LIST(&spd_tmem_info_list[i].ci, next, prev); INIT_LIST(&spd_tmem_info_list[i].tmem_list, next, prev); INIT_LIST(&spd_tmem_info_list[i].bthd_list, next, prev); } free_tmem_list = NULL; INIT_LIST(&global_blk_list, next, prev); tmems_allocated = 0; // Map all of the spds we can into this component for (i = 0 ; i < MAX_NUM_SPDS ; i++) { spdid_t spdid = i; void *hp; hp = valloc_alloc(cos_spd_id(), cos_spd_id(), 1); spdid = cinfo_get_spdid(i); if (!spdid) break; if(cinfo_map(cos_spd_id(), (vaddr_t)hp, spdid)){ DOUT("Could not map cinfo page for %d\n", spdid); BUG(); } /* spd_tmem_info_list[spdid].ci = hp; */ spd_tmem_info_list[spdid].ci.spd_cinfo_page = hp; /* spd_tmem_info_list[spdid].spd_cinfo_page = hp; */ spd_tmem_info_list[spdid].ci.meta = NULL; spd_tmem_info_list[spdid].managed = 1; spd_tmem_info_list[spdid].relinquish_mark = 0; tmems_target += DEFAULT_TARGET_ALLOC; spd_tmem_info_list[spdid].num_allocated = 0; spd_tmem_info_list[spdid].num_desired = DEFAULT_TARGET_ALLOC; spd_tmem_info_list[spdid].num_blocked_thds = 0; spd_tmem_info_list[spdid].num_waiting_thds = 0; spd_tmem_info_list[spdid].num_glb_blocked = 0; spd_tmem_info_list[spdid].ss_counter = 0; spd_tmem_info_list[spdid].ss_max = MAX_NUM_MEM; empty_comps++; } over_quota_total = 0; over_quota_limit = MAX_NUM_MEM; event_waiting(); return; }