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.

Cache for the task stack variables



I wrote a program like the below:

#include <std.h>

#include <log.h>
#include <clk.h>
#include "L1DRAMcfg.h"

#define N 512


short x[256];

short y[256];

Void task();

/*
* ======== main ========
*/
Void main()
{
LOG_printf(&trace, "hello world!");

/* fall into DSP/BIOS idle loop */
return;
}

Void task()
{
int a[N], b[N];
int i, sum;
// Float timeout, milliSecsPerIntr, cycles;
LgUns start, stop, result;

LOG_printf(&trace, "This is the first task!");

sum = 0;
for(i = 0; i < N; i++)
{
a[i] = i;
b[i] = i;
}

for(i = 0; i < 256; i++)
{
x[i] = i;
y[i] = i;
}

start = CLK_gethtime();

for(i = 0; i < N; i++)
sum += a[i] * b[i];

for(i = 0; i < 256; i++)
sum += x[i] * y[i];

stop = CLK_gethtime();
result = stop - start;

LOG_printf(&trace, "The start time is: %d\n", start);
LOG_printf(&trace, "The stop time is: %d\n", stop);
LOG_printf(&trace, "The result is: %d\n", result);


LOG_printf(&trace, "The sum is: %d\n", sum);
}

I debug the program in emulation in CCS 5. I notice that  in the task, when the program runs to the end, global variables,  such as array x and y, are cached in the L1D. But local variables, such as array a and b, are not cached in any cache. I want to hnow how to change the configuration to cache the task local variables.

  • I checked again. I modify the cache parameters in the .tcf file and check the LOG result. It shows that the number of used cycles changes according to change of the cache size. So the local variables are cached in the running process. Now my question is how to watch the status of these variables in the cache.

  • Hi,

    It wasn't clear on the second post if your local variables are now being cached?  Whether something gets cached or not simply depends on whether its placed in memory that is cacheable.  For external memory, make sure the MAR bits for that memory is enabled.

    Typically if using CCS to debug, the memory browser shows L1D, L1P, and L2 cache views so you can tell whether something is cached into any of those caches.

    Judah

  • Hi,  judahvang

    It is my fault. I did not clarify the problem.

    In the second post, I commented out all the line related to the global variables. So the main code snapshot would look like this:

    start = CLK_gethtime();

    for(i = 0; i < N; i++)
    sum += a[i] * b[i];

    stop = CLK_gethtime();
    result = stop - start;

    LOG_printf(&trace, "The start time is: %d\n", start);
    LOG_printf(&trace, "The stop time is: %d\n", stop);
    LOG_printf(&trace, "The result is: %d\n", result);

    Then, I use CCS to debug. I find that array a and b did not show up in the cache view like array x and y did. So at first I thougt array a and b were not cached. But when I changed the cache size in the .tcf file and ran the program, the variable "result" which was printed by LOG_printf in the above code snapshot also changed. In other words, I increase the cache size, then the result decreases. According to this, I guess local variable a and b are actually cached.