void torlib_init(void) { cos_map_init_static(&torrents); /* save descriptors for the null and root spots */ null_torrent.td = td_null; if (td_null != cos_map_add(&torrents, &null_torrent)) BUG(); root_torrent.td = td_root; if (td_root != cos_map_add(&torrents, &root_torrent)) BUG(); }
static int net_conn_init(void) { cos_map_init_static(&connections); cos_map_add(&connections, (void*)1); return 0; }
int tor_cons(struct torrent *t, void *data, int flags) { td_t td; assert(t && data); td = (td_t)cos_map_add(&torrents, t); if (td == -1) return -1; t->td = td; t->data = data; t->flags = flags; t->offset = 0; return 0; }
static inline struct desc_track *call_desc_alloc() { struct desc_track *desc = NULL; int map_id = 0; while(1) { desc = cslab_alloc_IDL_service_slab(); assert(desc); map_id = cos_map_add(&IDL_service_desc_maps, desc); desc->IDL_id = map_id; desc->IDL_server_id = -1; // reset to -1 if (map_id >= 2) break; } assert(desc && desc->IDL_id >= 1); return desc; }
long content_create(spdid_t spdid, long evt_id, struct cos_array *d) { struct connection *c = http_new_connection(0, evt_id); long c_id; // printc("HTTP open connection"); if (NULL == c) return -ENOMEM; c_id = cos_map_add(&conn_map, c); if (c_id < 0) { http_free_connection(c); return -ENOMEM; } c->conn_id = c_id; return c_id; }
static int rdlk_alloc() { struct rec_data_lk *rd = NULL; int map_id = 0; // lock return lock id from 1, and cos_map starts from 0 // here want cos_map to return some ids at least from 1 and later while(1) { rd = cslab_alloc_rdlk(); assert(rd); map_id = cos_map_add(&uniq_lkids, rd); if (map_id >= 1) break; rd->s_lkid = -1; // -1 means that this is a dummy record } assert(map_id >= 1); return map_id; }
static int map_rd_create() { struct rec_data_tor *rd = NULL; int map_id = 0; // ramfs return torrent id from 2 (rd_root is 1), and cos_map starts from 0 // here want cos_map to return some ids at least from 2 and later while(1) { rd = cslab_alloc_rd(); assert(rd); map_id = cos_map_add(&uniq_tids, rd); /* printc("record added %d\n", map_id); */ if (map_id >= 2) break; rd->s_tid = -1; // -1 means that this is a dummy record } assert(map_id >= 2); return map_id; }
static inline struct intern_connection *net_conn_alloc(conn_t conn_type, u16_t tid, long data) { struct intern_connection *ic; net_connection_t nc; ic = malloc(sizeof(struct intern_connection)); if (NULL == ic) return NULL; nc = cos_map_add(&connections, ic); if (-1 == nc) { free(ic); return NULL; } memset(ic, 0, sizeof(struct intern_connection)); ic->connection_id = nc; ic->tid = tid; ic->thd_status = ACTIVE; ic->conn_type = conn_type; ic->data = data; return ic; }
/* * mapping_* functions are for maintaining mappings between an * external event and an event structure */ static long mapping_create(struct evt *e) { return cos_map_add(&evt_map, e); }
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; }
int cbuf_c_create(spdid_t spdid, int size, long cbid) { int ret = -1; void *v; struct spd_tmem_info *sti; struct cos_cbuf_item *cbuf_item; struct cb_desc *d; union cbuf_meta *mc = NULL; /* DOUT("thd: %d spd: %d cbuf_c_create is called here!!\n", cos_get_thd_id(), spdid); */ /* DOUT("passed cbid is %ld\n",cbid); */ TAKE(); sti = get_spd_info(spdid); /* Make sure we have access to the component shared page */ assert(SPD_IS_MANAGED(sti)); assert(cbid >= 0); if (cbid) { // vector should already exist v = cos_map_lookup(&cb_ids, cbid); if (unlikely((spdid_t)(int)v != spdid)) goto err; } else { cbid = cos_map_add(&cb_ids, (void *)(unsigned long)spdid); if ((mc = __spd_cbvect_lookup_range(sti, (cbid))) == NULL){ RELEASE(); return cbid*-1; } } cos_map_del(&cb_ids, cbid); cbuf_item = tmem_grant(sti); assert(cbuf_item); d = &cbuf_item->desc; d->principal = cos_get_thd_id(); d->obj_sz = PAGE_SIZE; d->owner.spd = sti->spdid; d->owner.cbd = d; /* Jiguo: This can be two different cases: 1. A local cached one is returned with a cbid 2. A cbuf item is obtained from the global free list without cbid */ DOUT("d->cbid is %d\n",d->cbid); if (d->cbid == 0) { INIT_LIST(&d->owner, next, prev); // only created when first time cbid = cos_map_add(&cb_ids, d); // we use a new cbuf DOUT("new cbid is %ld\n",cbid); } else { cbid = cbuf_item->desc.cbid; // use a local cached one DOUT("cached cbid is %ld\n",cbid); } DOUT("cbuf_create:::new cbid is %ld\n",cbid); ret = d->cbid = cbid; mc = __spd_cbvect_lookup_range(sti, cbid); assert(mc); cbuf_item->entry = mc; mc->c.ptr = d->owner.addr >> PAGE_ORDER; mc->c.obj_sz = ((unsigned int)PAGE_SIZE) >> CBUF_OBJ_SZ_SHIFT; mc->c_0.th_id = cos_get_thd_id(); mc->c.flags |= CBUFM_IN_USE | CBUFM_TOUCHED; done: RELEASE(); return ret; err: ret = -1; goto done; }