This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/AM5728: The speed of hepbuf is more slow than memory

Part Number: AM5728

Tool/software: TI-RTOS

I have write a function to test the speed of memory and hepbuf. The heapbuf's speed to alloc memory is faster than memory, but the heapbuf's assignment speed is more slow than memory. Is there some mistakes?

Following is the test result:

....................
cpu performance test:memory
BIOS cpu freq: 1176000000 Hz
Timestamp freq: 1176000000 Hz
rtn=100,loop=100,time=1676 us.[from 109833022 to 111804625clks]
....................
cpu performance test:heapbuf alloc
BIOS cpu freq: 1176000000 Hz
Timestamp freq: 1176000000 Hz
rtn=100,loop=100,time=381 us.[from 133030120 to 133478566clks]
....................
cpu performance test:memory calculate
BIOS cpu freq: 1176000000 Hz
Timestamp freq: 1176000000 Hz
rtn=10250000,loop=10000,time=168643 us.[from 175988237 to 374313319clks]
cclock_start=2300,clock_stop=2400,clock_per_second=100,time=1 s.
....................
cpu performance test:heapbuf calculate
BIOS cpu freq: 1176000000 Hz
Timestamp freq: 1176000000 Hz
rtn=10000,loop=10000,time=1515941 us.[from 422841607 to 2205588507clks]
cclock_start=2400,clock_stop=7200,clock_per_second=100,time=48 s.
 
Here is the code:
//MEMORY ALLOC
int cpu_memoryalloc_benchmark_test_group(void)
{
    xdc_runtime_Types_FreqHz time_freq,bios_freq;
    Timestamp_getFreq(&time_freq);
    BIOS_getCpuFreq(&bios_freq);

    appPrint("\n....................\n");
    appPrint("\ncpu performance test:memory");
    appPrint("\nBIOS cpu freq: %u Hz",bios_freq.lo);
    appPrint("\nTimestamp freq: %u Hz",time_freq.lo);

    Uint32 timer_0;
    Uint32 timer_1;
    Uint32 timer_us;
    int ret=0;
    int loop = 100;
    timer_0 = Timestamp_get32();
    ret = cpu_memoryalloc_benchmark(loop);
    timer_1 = Timestamp_get32();
    timer_us = (timer_1-timer_0)/(time_freq.lo/1000000);
    appPrint("\nrtn=%d,loop=%d,time=%u us.[from %u to %uclks]",ret,loop,timer_us,timer_0,timer_1);
    return timer_us;
}

int cpu_memoryalloc_benchmark(int loop)
{
    int ret = 0;
    unsigned char *address = 0;
    for(int i=0;i<loop;i++)
    {
        address=malloc(1024*1024*1);
        if(address == 0)
        {
            ret = -1;
            return ret;
        }
        else
        {
            ret+=1;
            free(address);
        }
    }
    return ret;
}
//20190131 heapbuf—_alloc
int cpu_heapbufalloc_benchmark_test_group(void)
{
    xdc_runtime_Types_FreqHz time_freq,bios_freq;
    Timestamp_getFreq(&time_freq);
    BIOS_getCpuFreq(&bios_freq);

    appPrint("\n....................\n");
    appPrint("\ncpu performance test:heapbuf alloc");
    appPrint("\nBIOS cpu freq: %u Hz",bios_freq.lo);
    appPrint("\nTimestamp freq: %u Hz",time_freq.lo);

    Uint32 timer_0;
    Uint32 timer_1;
    Uint32 timer_us;
    int ret=0;
    int loop = 100;
    timer_0 = Timestamp_get32();
    ret = cpu_heapbufalloc_benchmark(loop);
    timer_1 = Timestamp_get32();
    timer_us = (timer_1-timer_0)/(time_freq.lo/1000000);
    appPrint("\nrtn=%d,loop=%d,time=%u us.[from %u to %uclks]",ret,loop,timer_us,timer_0,timer_1);
    return timer_us;
}
int cpu_heapbufalloc_benchmark(int loop)
{
    int ret = 0;
    unsigned char *address = 0;
    for(int i=0;i<loop;i++)
    {
        //address=malloc(1024*1024*1);

        address=Memory_alloc(otherHeap,1024*1024*1,0,NULL);
        if(address == 0)
        {
            ret = -1;
            return ret;
        }
        else
        {
            ret+=1;
            //free(address);
            Memory_free(otherHeap,address,1024*1024*1);

        }
    }
    return ret;
}
//20190213 memory--calculate
int cpu_memorycalculate_benchmark_test_group(void)
{
    xdc_runtime_Types_FreqHz time_freq,bios_freq;
    Timestamp_getFreq(&time_freq);
    BIOS_getCpuFreq(&bios_freq);

    appPrint("\n....................\n");
    appPrint("\ncpu performance test:memory calculate");
    appPrint("\nBIOS cpu freq: %u Hz",bios_freq.lo);
    appPrint("\nTimestamp freq: %u Hz",time_freq.lo);

    Uint32 timer_0;
    Uint32 timer_1;
    Uint32 timer_us;
    int ret=0;
    int loop = 10000;
    clock_t clock_start = clock();
    timer_0 = Timestamp_get32();
    ret = cpu_memory_calculate_benchmark(loop);
    timer_1 = Timestamp_get32();
    timer_us = (timer_1-timer_0)/(time_freq.lo/1000000);
    clock_t clock_stop = clock();
    appPrint("\nrtn=%d,loop=%d,time=%u us.[from %u to %uclks]",ret,loop,timer_us,timer_0,timer_1);
    appPrint("\ncclock_start=%d,clock_stop=%d,clock_per_second=%d,time=%u s.",clock_start,clock_stop,CLOCKS_PER_SEC,((clock_stop-clock_start)/CLOCKS_PER_SEC));
    return timer_us;
}
int cpu_memory_calculate_benchmark(int loop)
{
    int ret = 0;
    unsigned char *address = 0;
    for(int i=0;i<loop;i++)
    {
        address=malloc(1024*1024*1);

        //address=Memory_alloc(otherHeap,1024*1024*1,0,NULL);
        if(address == 0)
        {
            ret = -1;
            return ret;
        }
        else
        {
            memset(address,0,1024*1024*1);
            for(int m=0;m<1024;m++)
            {
                for(int j=0;j<1024;j++)
                {
                        address[m*1024+j]=255;
                }
                ret+=1;
            }
            ret+=1;
            free(address);
            //Memory_free(otherHeap,address,1024*1024*1);

        }
    }
    return ret;
}

//20190213 heapbuf—_calculate
int cpu_heapbufcalculate_benchmark_test_group(void)
{
    xdc_runtime_Types_FreqHz time_freq,bios_freq;
    Timestamp_getFreq(&time_freq);
    BIOS_getCpuFreq(&bios_freq);

    appPrint("\n....................\n");
    appPrint("\ncpu performance test:heapbuf calculate");
    appPrint("\nBIOS cpu freq: %u Hz",bios_freq.lo);
    appPrint("\nTimestamp freq: %u Hz",time_freq.lo);

    Uint32 timer_0;
    Uint32 timer_1;
    Uint32 timer_us;
    int ret=0;
    int loop = 10000;
    clock_t clock_start = clock();
    timer_0 = Timestamp_get32();
    ret = cpu_heapbuf_calculate_benchmark(loop);
    timer_1 = Timestamp_get32();
    timer_us = (timer_1-timer_0)/(time_freq.lo/1000000);
    clock_t clock_stop = clock();
    appPrint("\nrtn=%d,loop=%d,time=%u us.[from %u to %uclks]",ret,loop,timer_us,timer_0,timer_1);
    appPrint("\ncclock_start=%d,clock_stop=%d,clock_per_second=%d,time=%u s.",clock_start,clock_stop,CLOCKS_PER_SEC,((clock_stop-clock_start)/CLOCKS_PER_SEC));
    return timer_us;
}
int cpu_heapbuf_calculate_benchmark(int loop)
{
    int ret = 0;
    unsigned char *address = 0;
    for(int i=0;i<loop;i++)
    {
        //address=malloc(1024*1024*1);

        address=Memory_alloc(otherHeap,1024*1024*1,0,NULL);
        if(address == 0)
        {
            ret = -1;
            return ret;
        }
        else
        {
            memset(address,0,1024*1024*1);
            for(int m=0;m<1024;m++)
            {
                for(int j=0;j<1024;j++)
                {
                    address[m*1024+j]=255;
                }
            }
            ret+=1;
            //free(address);
            Memory_free(otherHeap,address,1024*1024*1);

        }
    }
    return ret;
}