Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kcachegrind cycle estimation

After going to their github page and seeing some pdf manual form their kde docs site, I am still confused. Suppose there are these two lines in a test code:

double a1 {asinh(1 / ep)};                   // 5 instr.
double b1 {log((1 + sqrt(1 + ep*ep)) / ep)}; // 12 instr.

where ep is some value that can be predefined. The comments are mine and done, in Codeblocks, by running the debugger with the disassembler, then patiently hitting "next instruction" and counting. These correspond with what Kacachegrind says if I set it to show "Instruction fetch". I suppose it should make sense (I am a beginner in C++, btw). But if I switch to "Cycle estimation" I get some very strange readings. For the current example, it's 115 and 122, but other, seemingly similar expressions, like:

double Ap {1.0};
double ep {0.9};

show 222 and 2 (instr. fetch shows 2 for both)! What goes on here? Can someone please explain?

like image 496
a concerned citizen Avatar asked Jul 11 '16 15:07

a concerned citizen


2 Answers

I think I found the answer after many clicks and getting used to Kcachegrind more. The total "cycle estimation" uses this formula:

CEst = Ir + 10 L1m + 100 LLm

where

Ir  = Instruction Fetch
L1m = L1 Miss Sum
Llm = Last-level Miss Sum

So, for my case, where CEst showed 2 and 222, but 2 Ir each, the first one had 2 instruction fetches and no misses, while the other had 2 instruction fetches but also two misses of each, =>

2*Ir + 10*2*L1m + 100*2*Llm = 2 + 20 + 200 = 222

This is consistent throughout all the codes I tried.

like image 140
a concerned citizen Avatar answered Sep 24 '22 08:09

a concerned citizen


The current source code of kcachgrind suggest a slightly more complex calculation than in the other answer:

QString GlobalConfig::knownFormula(const QString& name)
{
    if (name == QLatin1String("L1m")) return QStringLiteral("I1mr + D1mr + D1mw");
    if (name == QLatin1String("L2m")) return QStringLiteral("I2mr + D2mr + D2mw");
    if (name == QLatin1String("LLm")) return QStringLiteral("ILmr + DLmr + DLmw");
    if (name == QLatin1String("Bm"))  return QStringLiteral("Bim + Bcm");
    if (name == QLatin1String("CEst"))
        return QStringLiteral("Ir + 10 Bm + 10 L1m + 20 Ge + 100 L2m + 100 LLm");

    return QString();
}
like image 30
PlasmaHH Avatar answered Sep 24 '22 08:09

PlasmaHH