Re: [PATCH v2 2/4] perf/core: Provide a kernel-internal interface to pause perf_event

From: Like Xu
Date: Mon Oct 14 2019 - 21:47:48 EST


On 2019/10/14 19:51, Peter Zijlstra wrote:
On Sun, Oct 13, 2019 at 05:15:31PM +0800, Like Xu wrote:
Exporting perf_event_pause() as an external accessor for kernel users (such
as KVM) who may do both disable perf_event and read count with just one
time to hold perf_event_ctx_lock. Also the value could be reset optionally.

+u64 perf_event_pause(struct perf_event *event, bool reset)
+{
+ struct perf_event_context *ctx;
+ u64 count, enabled, running;
+
+ ctx = perf_event_ctx_lock(event);

+ _perf_event_disable(event);
+ count = __perf_event_read_value(event, &enabled, &running);
+ if (reset)
+ local64_set(&event->count, 0);

This local64_set() already assumes there are no child events, so maybe
write the thing like:

WARN_ON_ONCE(event->attr.inherit);
_perf_event_disable(event);
count = local64_read(&event->count);
local64_set(&event->count, 0);


Thanks. It looks good to me and I will apply this.


+ perf_event_ctx_unlock(event, ctx);
+
+ return count;
+}
+EXPORT_SYMBOL_GPL(perf_event_pause);