> +     u64 delta = 0;
...
> +     if (((prev & 0x80000000) && !(val & 0x80000000)) || (val >
prev))
> +             delta = (val - prev) & 0xfffffffful;
> +
> +     return delta;

The above is incorrect modulo arithmetic.

It is probably intended to do:
    s32 delta = val - prev;
    return delta < 0 ? 0 : delta;
which will just ignore the fact that some counts are rolled back.

More accurate would be:
    static u64 val64;
    u32 val = read_perf_count();
    s32 delta = val - val_64;
    if (delta < 0)
        return;
    val64 += delta;
Which will not double count for rolled back events.
(The low bits of val64 should always match the actual counter.)

        David


_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Reply via email to