LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Laight" <David.Laight@ACULAB.COM>
To: <linuxppc-dev@lists.ozlabs.org>
Subject: RE: [PATCH V3] POWER: perf_event: Skip updating kernel counters ifregister value shrinks
Date: Fri, 8 Apr 2011 09:38:49 +0100	[thread overview]
Message-ID: <AE90C24D6B3A694183C094C60CF0A2F6D8ACE8@saturn3.aculab.com> (raw)

=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

                 reply	other threads:[~2011-04-08  8:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AE90C24D6B3A694183C094C60CF0A2F6D8ACE8@saturn3.aculab.com \
    --to=david.laight@aculab.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox