diff options
author | 2019-10-27 18:52:39 +0800 | |
---|---|---|
committer | 2019-11-15 11:44:07 +0100 | |
commit | 52ba4b0b99770e892f43da1238f437155acb8b58 (patch) | |
tree | 18ee181729eb2cea9841a2bffb72d3da055ccabd /kernel | |
parent | perf/core: Provide a kernel-internal interface to recalibrate event period (diff) | |
download | linux-52ba4b0b99770e892f43da1238f437155acb8b58.tar.gz linux-52ba4b0b99770e892f43da1238f437155acb8b58.tar.bz2 linux-52ba4b0b99770e892f43da1238f437155acb8b58.zip |
perf/core: Provide a kernel-internal interface to pause perf_event
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.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Like Xu <like.xu@linux.intel.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/events/core.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c index e1b83d2731da..fc9f5ebf4849 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5029,6 +5029,24 @@ static void _perf_event_reset(struct perf_event *event) perf_event_update_userpage(event); } +/* Assume it's not an event with inherit set. */ +u64 perf_event_pause(struct perf_event *event, bool reset) +{ + struct perf_event_context *ctx; + u64 count; + + ctx = perf_event_ctx_lock(event); + WARN_ON_ONCE(event->attr.inherit); + _perf_event_disable(event); + count = local64_read(&event->count); + if (reset) + local64_set(&event->count, 0); + perf_event_ctx_unlock(event, ctx); + + return count; +} +EXPORT_SYMBOL_GPL(perf_event_pause); + /* * Holding the top-level event's child_mutex means that any * descendant process that has inherited this event will block |