コード例 #1
0
ファイル: vmm_mbuf.c プロジェクト: IRT-SystemX/xvisor-next
void *m_ext_get(struct vmm_mbuf *m, u32 size, enum vmm_mbuf_alloc_types how)
{
	void *buf;
	u32 slab;
	struct mempool *mp = NULL;

	if (VMM_MBUF_ALLOC_DMA == how) {
		buf = vmm_dma_malloc(size);
		if (!buf) {
			return NULL;
		}
		m->m_flags |= M_EXT_DMA;
		MEXTADD(m, buf, size, ext_dma_free, NULL);
	} else {
		for (slab = 0; slab < EPOOL_SLAB_COUNT; slab++) {
			if (size <= epool_slab_buf_size(slab)) {
				mp = mbpctrl.epool_slabs[slab];
				break;
			}
		}

		if (mp && (buf = mempool_malloc(mp))) {
			m->m_flags |= M_EXT_POOL;
			MEXTADD(m, buf, size, ext_pool_free, mp);
		} else if ((buf = vmm_malloc(size))) {
			m->m_flags |= M_EXT_HEAP;
			MEXTADD(m, buf, size, ext_heap_free, NULL);
		} else {
			return NULL;
		}
	}

	return m->m_extbuf;
}
コード例 #2
0
ファイル: vmm_mbuf.c プロジェクト: IRT-SystemX/xvisor-next
int __init vmm_mbufpool_init(void)
{
	u32 slab, b_size, b_count, epool_sz;

	memset(&mbpctrl, 0, sizeof(mbpctrl));

	/* Create mbuf pool */
	b_size = sizeof(struct vmm_mbuf);
	b_count = CONFIG_NET_MBUF_POOL_SIZE;
	mbpctrl.mpool = mempool_ram_create(b_size,
					VMM_SIZE_TO_PAGE(b_size * b_count),
					VMM_MEMORY_FLAGS_NORMAL);
	if (!mbpctrl.mpool) {
		return VMM_ENOMEM;
	}

	/* Create ext slab pools */
	epool_sz = (CONFIG_NET_MBUF_EXT_POOL_SIZE_KB * 1024);
	for (slab = 0; slab < EPOOL_SLAB_COUNT; slab++) {
		b_size = epool_slab_buf_size(slab);
		b_count = epool_slab_buf_count(epool_sz, slab);
		if (b_count && b_size) {
			mbpctrl.epool_slabs[slab] = 
				mempool_ram_create(b_size,
					VMM_SIZE_TO_PAGE(b_size * b_count),
					VMM_MEMORY_FLAGS_NORMAL);
		} else {
			mbpctrl.epool_slabs[slab] = NULL;
		}
	}

	return VMM_OK;
}
コード例 #3
0
ファイル: vmm_mbuf.c プロジェクト: IRT-SystemX/xvisor-next
static u32 epool_slab_buf_count(u32 pool_sz, u32 slab)
{
	u32 slab_size, buf_size, weight, total_weight;

	switch (slab) {
	case 0:
		weight = 1;
		break;
	case 1:
		weight = 1;
		break;
	case 2:
		weight = 4;
		break;
	case 3:
		weight = 2;
		break;
	default:
		return 0;
	};
	total_weight = 8;

	buf_size = epool_slab_buf_size(slab);
	if (!buf_size) {
		return 0;
	}

	slab_size = udiv32(pool_sz, total_weight) * weight;
	if (!slab_size) {
		return 0;
	}

	return udiv32(slab_size, buf_size);
}
コード例 #4
0
ファイル: vmm_mbuf.c プロジェクト: machinoid/xvisor-next
int __init vmm_mbufpool_init(void)
{
	u32 slab, buf_size, buf_count, epool_sz;

	memset(&mbpctrl, 0, sizeof(mbpctrl));

	/* Create mbuf pool */
	mbpctrl.mpool = mempool_create(sizeof(struct vmm_mbuf), 
					CONFIG_NET_MBUF_POOL_SIZE);
	if (!mbpctrl.mpool) {
		return VMM_ENOMEM;
	}

	/* Create ext slab pools */
	epool_sz = (CONFIG_NET_MBUF_EXT_POOL_KB * 1024);
	for (slab = 0; slab < EPOOL_SLAB_COUNT; slab++) {
		buf_size = epool_slab_buf_size(slab);
		buf_count = epool_slab_buf_count(epool_sz, slab);
		if (buf_count && buf_size) {
			mbpctrl.epool_slabs[slab] = 
					mempool_create(buf_size, buf_count);
		} else {
			mbpctrl.epool_slabs[slab] = NULL;
		}
	}

	return VMM_OK;
}
コード例 #5
0
ファイル: vmm_mbuf.c プロジェクト: machinoid/xvisor-next
void *m_ext_get(struct vmm_mbuf *m, u32 size, int how)
{
	void *buf;
	u32 slab;
	struct mempool *mp;

	mp = NULL;
	for (slab = 0; slab < EPOOL_SLAB_COUNT; slab++) {
		if (size <= epool_slab_buf_size(slab)) {
			mp = mbpctrl.epool_slabs[slab];
			break;
		}
	}

	if (mp && (buf = mempool_malloc(mp))) {
		MEXTADD(m, buf, size, ext_pool_free, mp);
	} else if ((buf = vmm_malloc(size))) {
		MEXTADD(m, buf, size, NULL, NULL);
	}

	return m->m_extbuf;
}