[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200810202453.GD3982@worktop.programming.kicks-ass.net>
Date: Mon, 10 Aug 2020 22:24:53 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Rob Herring <robh@...nel.org>
Cc: linux-kernel@...r.kernel.org, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung@...nel.org>
Subject: Re: [RFC] libperf: Add support for user space counter access
On Fri, Aug 07, 2020 at 05:05:17PM -0600, Rob Herring wrote:
> x86 and arm64 can both support direct access of event counters in
> userspace. The access sequence is less than trivial and currently exists
> in perf test code (tools/perf/arch/x86/tests/rdpmc.c) with copies in
> projects such as PAPI and libpfm4.
>
> Patches to add arm64 userspace support are pending[1].
>
> For this RFC, looking for a yes, seems like a good idea, or no, go away we
> don't want this in libperf.
I'd like it lots better if you'd at least take an optimized version of
this, also see this thread:
https://lkml.kernel.org/r/20200322101848.GF2452@worktop.programming.kicks-ass.net
Also, I usually strip out all the multiplexing crud out (and use pinned
counters), which saves a bunch.
static inline u64 mmap_read_pinned(void *addr)
{
struct perf_event_mmap_page *pc = addr;
u32 seq, idx, width = 0;
u64 count;
s64 pmc = 0;
do {
seq = pc->lock;
barrier();
idx = pc->index;
count = pc->offset;
if (pc->cap_user_rdpmc && idx) {
width = pc->pmc_width;
pmc = rdpmc(idx - 1);
}
barrier();
} while (pc->lock != seq);
if (idx) {
pmc <<= 64 - width;
pmc >>= 64 - width; /* shift right signed */
count += pmc;
}
return count;
}
Powered by blists - more mailing lists