user2463118
user2463118

Reputation: 51

cache vs uncache memory access in embedded Linux

I have an embedded target running embedded Linux and I want to calculate the following timings:

1) cache memory read/write timings 2) uncache memory read/write timings

Are there any standard tests in Linux to calculate the above timings?

I have written my own test that is:

void *mem_src  = (void*)malloc(MEM_SIZE);
void *mem_dest = (void*)malloc(MEM_SIZE);

clock_gettime(CLOCK_THREAD_CPUTIME_ID, &pre);
memcpy(mem_dest, mem_src, MEM_SIZE);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &post);

printf("time %ld\n",
        (SEC_TO_NSEC(post.tv_sec) + post.tv_nsec) -
        (SEC_TO_NSEC(pre.tv_sec) + pre.tv_nsec));

But the problem is that this test can only calculate the timings for cache memory access because the malloc in user space allocates the memory from cache region only. I want the similar test for uncache memory region.

Upvotes: 3

Views: 1738

Answers (1)

Leeor
Leeor

Reputation: 19706

First of all = your test measures memory bandwidth - if you want latency you need to make the accesses dependent (for e.g. traverse a linked list).

Second - you don't initialize your copied data so you'll get page faults within the times loop. Same problem described in here - cpu cacheline and prefetch policy

For uncacheable requests - easiest option is to check if you compiler recognizes streaming stores/loads, they should behave very similarly to uncacheables (unless you're interested in measuring MMIO or similar special cases)

Upvotes: 2

Related Questions