lkml.org 
[lkml]   [2015]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/2 --resend] perf: update userspace page info for software event
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.


\
 
 \ /
  Last update: 2015-02-11 12:41    [W:0.069 / U:1.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site