Example #1
0
int valloc_alloc_at(spdid_t spdid, spdid_t dest, void *addr, unsigned long npages)
{
	int ret = -1, i = 0;
	struct spd_vas_tracker *trac;
	struct spd_vas_occupied *occ;
	unsigned long off, ext_size;

	LOCK();
	trac = cos_vect_lookup(&spd_vect, dest);
	if (!trac) {
		if (__valloc_init(dest) ||
		    !(trac = cos_vect_lookup(&spd_vect, dest))) goto done;
	}

	if (unlikely(npages > MAP_MAX * sizeof(u32_t))) {
		printc("valloc: cannot alloc more than %u bytes in one time!\n", 32 * WORDS_PER_PAGE * PAGE_SIZE);
		goto done;
	}

	while (trac->extents[i].map) {
		if (addr < trac->extents[i].start || addr > trac->extents[i].end) {
			if (++i == MAX_SPD_VAS_LOCATIONS) goto done;
			continue;
		}
		/* the address is in the range of an existing extent */
		occ = trac->extents[i].map;
		off = ((char*)addr - (char*)trac->extents[i].start) / PAGE_SIZE;
		assert(off + npages < MAP_MAX * sizeof(u32_t));
		ret = bitmap_extent_set_at(&occ->pgd_occupied[0], off, npages, MAP_MAX);
		goto done;
	}

	ext_size = round_up_to_pgd_page(npages * PAGE_SIZE);
	trac->extents[i].map = alloc_page();
	occ = trac->extents[i].map;
	assert(occ);
	if (vas_mgr_take(spdid, dest, (vaddr_t)addr, ext_size) == 0) goto free;
	trac->extents[i].start = addr;
	trac->extents[i].end = (void *)((uintptr_t)addr + ext_size);
	bitmap_set_contig(&occ->pgd_occupied[0], 0, ext_size / PAGE_SIZE, 1);
	bitmap_set_contig(&occ->pgd_occupied[0], 0, npages, 0);
	ret = 0;
done:
	UNLOCK();
	return ret;
free:
	free_page(trac->extents[i].map);
	goto done;
}
Example #2
0
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;
}
Example #3
0
void *valloc_alloc(spdid_t spdid, spdid_t dest, unsigned long npages)
{
	void *ret = NULL;
	struct spd_vas_tracker *trac;
	struct spd_vas_occupied *occ;
	unsigned long ext_size;
	long off, i = 0;

	LOCK();

	trac = cos_vect_lookup(&spd_vect, dest);
	if (!trac) {
		if (__valloc_init(dest) ||
		    !(trac = cos_vect_lookup(&spd_vect, dest))) goto done;
	}

	if (unlikely(npages > MAP_MAX * sizeof(u32_t))) {
		printc("valloc: cannot alloc more than %u bytes in one time!\n", 32 * WORDS_PER_PAGE * PAGE_SIZE);
		goto done;
	}

	while (trac->extents[i].map) {
		occ = trac->extents[i].map;
		off = bitmap_extent_find_set(&occ->pgd_occupied[0], 0, npages, MAP_MAX);
		if (off < 0) {
			if (++i == MAX_SPD_VAS_LOCATIONS) goto done;
			continue;
		}
		ret = (void *)((char *)trac->extents[i].start + off * PAGE_SIZE);
		goto done;
	}

	ext_size = round_up_to_pgd_page(npages * PAGE_SIZE);
	trac->extents[i].map = alloc_page();
	occ = trac->extents[i].map;
	assert(occ);
	trac->extents[i].start = (void*)vas_mgr_expand(spdid, dest, ext_size);
	trac->extents[i].end = (void *)(trac->extents[i].start + ext_size);
	bitmap_set_contig(&occ->pgd_occupied[0], 0, ext_size / PAGE_SIZE, 1);
	bitmap_set_contig(&occ->pgd_occupied[0], 0, npages, 0);
	ret = trac->extents[i].start;
done:
	UNLOCK();
	return ret;
}
Example #4
0
void *valloc_alloc(spdid_t spdid, spdid_t dest, unsigned long npages)
{
	void *ret = NULL;
	struct spd_vas_tracker *trac;
	struct spd_vas_occupied *occ;
	long off;

	LOCK();

	trac = cos_vect_lookup(&spd_vect, dest);
	if (!trac) {
		if (__valloc_init(dest) ||
		    !(trac = cos_vect_lookup(&spd_vect, dest))) goto done;
	}

	occ = trac->map;
	assert(occ);
	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:   
	UNLOCK();
	return ret;
}