Part Number: AM5728
Hello,
I'm using GLSDK-7.04 setup. I doing read and write from ARM core to shared memory CMEM.
To read and write 320 KB of data to CMEM it is taking more time(around 9.7 ms).
Code:
#include <ti/ipc/Std.h>
#include <ti/cmem.h>
#include <pthread.h>
#include <semaphore.h>
#include <ti/ipc/Ipc.h>
#include <ti/ipc/MessageQ.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <string.h>
#define SUCCESS (0)
#define FAILURE (-1)
#define SHARED_MEM_SIZE (320*1024u)
#define HEAPID 0
char *s8SharedMem;
static long get_nanos(void) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return (long)ts.tv_sec * 1000000000L + ts.tv_nsec;
}
int main(void)
{
int s32ReturnValue;
char num;
CMEM_AllocParams cmemAttrs;
int status;
char *ptr;
long time1, time2;
int i,j,k;
int s32CacheInvChk;
int s32Status;
s32Status = 0;
cmemAttrs.type = CMEM_HEAP;
cmemAttrs.flags = CMEM_NONCACHED;
cmemAttrs.alignment = 4;
s32ReturnValue = SUCCESS;
s32CacheInvChk = 0;
if(s32ReturnValue == SUCCESS)
{
if(CMEM_init() != SUCCESS)
{
printf("\nCmem initialization failed");
s32ReturnValue = FAILURE;
}
else
{
printf("\ncmem init successfull");
}
}
if(s32ReturnValue == SUCCESS)
{
if((s8SharedMem = CMEM_alloc(SHARED_MEM_SIZE, &cmemAttrs)) == NULL)
{
printf("\nCmem allocation failed");
s32ReturnValue = FAILURE;
}
else
{
printf("\ncmem alloc successfull");
}
}
if(s32ReturnValue == SUCCESS)
{
if((ptr = CMEM_alloc(SHARED_MEM_SIZE, &cmemAttrs)) == NULL)
{
printf("\nCmem allocation failed");
s32ReturnValue = FAILURE;
}
else
{
printf("\ncmem alloc successfull");
}
}
for(i=0; i < 1024; i++)
{
ptr[i] = 'c';
}
s32CacheInvChk = CMEM_cacheInv ((void *)ptr, 1024);
if (0 == s32CacheInvChk )
{
time1 = get_nanos();
for(i=0,j=0; i< 320; i++)
{
memcpy(s8SharedMem+j, (const char *)ptr, 1024);
/*printf("s8SharedMem: = %x\n", s8SharedMem+j);*/
j += 1024;
}
time2 = get_nanos();
printf("\ntime taken to write:%ld",time2-time1);
time1 = 0;
time2 = 0;
time1 = get_nanos();
for(i=0,j=0; i< 320; i++)
{
memcpy(ptr+j, s8SharedMem+j, 1024);
j += 1024;
}
time2 = get_nanos();
printf("\ntime taken to read:%ld",time2-time1);
}
else
{
s32ReturnValue = FAILURE;
}
CMEM_free(s8SharedMem, &cmemAttrs);
return s32ReturnValue;
}
Logs:
root@dra7xx-evm:~# ./pjtArm_profile
CMEM Debug: init: entered - ref_count 0, cmem_fd -2
CMEM Debug: init: successfully opened /dev/cmem, matching driver version...
CMEM Debug: getVersion: entered
CMEM Debug: getVersion: exiting, ioctl CMEM_IOCGETVERSION returned 0x4000000
CMEM Debug: init: ... match good (0x4000000)
CMEM Debug: init: exiting, returning success
CMEM Debug: alloc: entered w/ size 0x50000, params - type HEAP, flags NONCACHED, align 0x4
CMEM Debug: allocHeap: allocated phys buffer 0xb5200000
CMEM Debug: allocHeap: mmap succeeded, returning virt buffer 0xb6e2b000
cmem init successfull
CMEM Debug: alloc: entered w/ size 0x50000, params - type HEAP, flags NONCACHED, align 0x4
CMEM Debug: allocHeap: allocated phys buffer 0xb5250000
CMEM Debug: allocHeap: mmap succeeded, returning virt buffer 0xb6ddb000
cmem alloc successfull
cmem alloc successfull
time taken to write:4571452
CMEM Debug: free: entered w/ ptr 0xb6e2b000, params - type HEAP
CMEM Debug: free: ioctl CMEM_IOCFREEHEAP succeeded, size 0x50000
CMEM Debug: free: munmap succeeded, returning 0
time taken to read:5150228
If we calculate the total time to perform write and read to CMEM is 9.7 ms(milli-seconds).
If we do memcpy of 320 KB data from heap to heap or global buffer to another global buffer it is taking 220 micro-seconds. so the problem is not with memcpy.
If we do same operation between heap/global buffer and CMEM it is taking 4.5 ms. So the problem is with CMEM only.
Can anyone suggest me how to increase the speed ?