RE: [PATCH V3] POWER: perf_event: Skip updating kernel counters ifregister value shrinks
From: David Laight <hidden>
Date: 2011-04-08 08:39:19
From: David Laight <hidden>
Date: 2011-04-08 08:39:19
=20
+ u64 delta =3D 0;
...
+ if (((prev & 0x80000000) && !(val & 0x80000000)) || (val >
prev))
+ delta =3D (val - prev) & 0xfffffffful; + + return delta;
The above is incorrect modulo arithmetic.
It is probably intended to do:
s32 delta =3D 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 =3D read_perf_count();
s32 delta =3D val - val_64;
if (delta < 0)
return;
val64 +=3D delta;
Which will not double count for rolled back events.
(The low bits of val64 should always match the actual counter.)
David