Hello,
While amusing myself with an old MPC5554, I used to invalidate and flush the cache (which is operating in its default setup as unified data/instruction cache) with the following code (__asm macro following Green Hills compilers syntax):
__asmleaf void flush_inv_cache_line(unsigned int flushed_way, unsigned int flushed_set) {
%reg flushed_way %reg flushed_set
mfspr r3, l1finv0
insrwi r3, flushed_way, 5, 3
insrwi r3, flushed_set, 7, 20
li r4, 2
rlwimi r3, r4, 0, 30, 31
msync
mtspr l1finv0, r3
}
void flush_inv_cache(void) {
unsigned int i;
unsigned int j;
for (i = 0u; i < 8u; i++)
{
for (j = 0u; j < 128u; j++)
{
flush_inv_cache_line(i, j);
}
}
}
I used this invalidation procedure before measuring the time of a function (large enough to take some tens of microseconds) that was called periodically by a sort of OS (much larger than the function itself) and I guess that, given the random-like nature of this cache, it would contain nothing "useful" when my measured function is called.
However, when I measured the execution time of my function, I noticed that it ran faster (a couple percent) when called after the cache flush and invalidation than when called with the cache state "messed up" by the OS, which would mean that an "empty" cache is a more favorable condition for timing than a "messed up" one.
Is this result expected or both measurements should be about equal and there are flaws in my experiments?
Thanks!
Ricardo
解決済! 解決策の投稿を見る。
Hello David,
The cache is configured as copy-back.
My ultimate goal with this experiment was verifying the worst-case scenario for this cache and I got puzzled that, seemingly, being flushed/invalidated is not the most pessimistic condition I could find. If I want to measure the execution time of a given function in a worst-case cache condition, shall I fill the cache with "useless" data, rather than flush/invalidate it?
Thanks!
Yes, with copy-back mode it would be so. Anyway, there will always be some randomness.
Do you have it configured as write-thru or copy-back mode?
If I understand your question well, execution time of certain function is faster if cache is empty/invalidated. It would mean that rest of the code always replaces these cache line by other content and this must be flushed before the function is again loaded to the cache an executed.
If it is so, you could possibly lock time critical function to the cache, that's also an option.