/** * 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; }