public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Shaohua Li <shli@fb.com>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 2/2 --resend] perf: update userspace page info for software event
Date: Wed, 11 Feb 2015 12:15:33 +0100	[thread overview]
Message-ID: <20150211111533.GS23123@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <aa2dd2e4f1e9f2225758be5ba00f14d6909a8ce1.1423180257.git.shli@fb.com>

On Thu, Feb 05, 2015 at 03:55:32PM -0800, Shaohua Li wrote:
> For hardware event, the userspace page of the event gets updated in
> context switch, so if we read time in the page, we get updated info. For
> software event, this is missed currently. This patch makes the behavior
> consistency.
> 
> With this patch, we can implement clock_gettime(THREAD_CPUTIME) with
> PERF_COUNT_SW_DUMMY in userspace as suggested by Andy and Peter. Code
> likes this:
> 
>   if (pc->cap_user_time) {
> 	do {
> 		seq = pc->lock;
> 		barrier();
> 
> 		running = pc->time_running;
> 		cyc = rdtsc();
> 		time_mult = pc->time_mult;
> 		time_shift = pc->time_shift;
> 		time_offset = pc->time_offset;
> 
> 		barrier();
> 	} while (pc->lock != seq);
> 
> 	quot = (cyc >> time_shift);
> 	rem = cyc & ((1 << time_shift) - 1);
> 	delta = time_offset + quot * time_mult +
> 		((rem * time_mult) >> time_shift);

You could maybe use:

static inline u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift)
{
        return (u64)(((unsigned __int128)a * mul) >> shift);
}

And save yourself a mult instruction if you have suitable (64bit)
hardware and a recent GCC.

> 	running += delta;
> 	return running;
>   }
> 

Thanks for poking me. Applied.

  reply	other threads:[~2015-02-11 11:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 23:55 [PATCH 1/2 --resend] perf: update shadow timestamp before add event Shaohua Li
2015-02-05 23:55 ` [PATCH 2/2 --resend] perf: update userspace page info for software event Shaohua Li
2015-02-11 11:15   ` Peter Zijlstra [this message]
2015-02-18 17:13   ` [tip:perf/core] perf: Update " tip-bot for Shaohua Li
2015-02-18 17:13 ` [tip:perf/core] perf: Update shadow timestamp before add event tip-bot for Shaohua Li

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=20150211111533.GS23123@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    --cc=shli@fb.com \
    /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