コード例 #1
0
ファイル: split.c プロジェクト: acv/wiggle
struct file split_stream(struct stream s, int type)
{
	int cnt;
	struct file f;

	char *c, *end;

	end = s.body+s.len;
	c = s.body;

	cnt = split_internal(c, end, type, NULL);
	f.list = malloc(cnt*sizeof(struct elmnt));

	f.elcnt = split_internal(c, end, type, f.list);
	return f;
}
コード例 #2
0
/**
 * split a specific stream's VM to multiple cores
 * number of cores is implied by the size of the vector
 *
 */
void
TrexVmSplitter::split(TrexStream *stream, std::vector<TrexStream *> core_streams) {

    /* nothing to do if no VM */
    if (stream->m_vm.is_vm_empty()) {
        return;
    }

    /* prepare some vars */
    m_dp_core_count = core_streams.size();
    m_core_streams  = &core_streams;
    m_stream        = stream;

    uint16_t cache_size=m_stream->m_cache_size;
    /* split the cache_size  */
    if (cache_size>0) {

        /* TBD need to check if we need to it is not too big from pool */
        if (cache_size > 10000) {
            throw TrexException("Cache is too big try to reduce it ");
        }

        /* split like variable splitters with leftovers */
        uint16_t cache_per_core = cache_size/m_dp_core_count;
        uint16_t leftover   = cache_size % m_dp_core_count;

        if (cache_per_core<1) {
            cache_per_core=1;
            leftover=0;
        }

        for (TrexStream *core_stream : *m_core_streams) {
            core_stream->m_cache_size = cache_per_core;
            if (leftover) {
                core_stream->m_cache_size+=1;
                leftover-=1;
            }
        }
    }


    /* if we cannot split - compile the main and duplicate */
    bool rc = split_internal();
    if (!rc) {

        /* compile the stream and simply clone it to all streams */
        m_stream->vm_compile();

        /* for every core - simply clone the DP object */
        for (TrexStream *core_stream : *m_core_streams) {
            core_stream->m_vm_dp = m_stream->m_vm_dp->clone();
        }

        /* no need for the reference stream DP object */
        delete m_stream->m_vm_dp;
        m_stream->m_vm_dp = NULL;
    }
}