Ejemplo n.º 1
0
slice_allocator_alloc(slice_allocator_t *sa, sa_size_t size)
#endif /* !DEBUG */
{
	slice_t *slice = 0;
	
	lck_spin_lock(sa->spinlock);
	
	/*
	 * Locate a slice with residual capacity. First, check for a partially
	 * full slice, and use some more of its capacity. Next, look to see if
	 * we have a ready to go empty slice. If not, finally go to underlying
	 * allocator for a new slice.
	 */
	if (!list_is_empty(&sa->partial)) {
		slice = list_head(&sa->partial);
	} else if (!list_is_empty(&sa->free)) {
		slice = list_tail(&sa->free);
		list_remove_tail(&sa->free);
		list_insert_head(&sa->partial, slice);
	} else {
		lck_spin_unlock(sa->spinlock);
		slice = (slice_t *)osif_malloc(sa->slice_size);;
		slice_init(slice, sa);
		lck_spin_lock(sa->spinlock);
		
		list_insert_head(&sa->partial, slice);
	}
	
#ifdef SA_CHECK_SLICE_SIZE
	if (sa->max_alloc_size != slice->sa->max_alloc_size) {
		REPORT("slice_allocator_alloc - alloc size (%llu) sa %llu slice"
			   " %llu\n", size, sa->max_alloc_size,
			   slice->sa->max_alloc_size);
	}
#endif /* SA_CHECK_SLICE_SIZE */
	
	/* Grab memory from the slice */
#ifndef DEBUG
	void *p = slice_alloc(slice);
#else
	void *p = slice_alloc(slice, size);
#endif /* !DEBUG */
	
	/*
	 * Check to see if the slice buffer has become full. If it has, then
	 * move it into the full list so that we no longer keep trying to
	 * allocate from it.
	 */
	if (slice_is_full(slice)) {
		list_remove(&sa->partial, slice);
#ifdef SLICE_ALLOCATOR_TRACK_FULL_SLABS
		list_insert_head(&sa->full, slice);
#endif /* SLICE_ALLOCATOR_TRACK_FULL_SLABS */
	}
	
	lck_spin_unlock(sa->spinlock);
	
	return (p);
}
int bsp_slice_init(void)
{
	int ret = 0;
	ret=slice_init();
	ret|=hrt_slice_init();
	if(ret){
		hardtimer_print_error("failed.\n");
		return BSP_ERROR;
	}
	timeslice_ctrl.is_inited_flag = 1;
	hardtimer_print_error("ok.\n");
	return BSP_OK;
}
Ejemplo n.º 3
0
void __init init_mem_info()
{
	int i;

	KLIST0_INIT(&memory_info.zone_list);
	for (i = 0; i < NUM_ZONES; i++)
		KLIST0_INIT(&mem_zone[i].list);

	arch_init_boot_zone(mem_zone);

	slice_init();

	for (i = 0; i < NUM_ZONES; i++)
		klist0_append(&mem_zone[i].list, &memory_info.zone_list);

	mma_init();
}