mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:44:45 +01:00
perf: Clean up mediated vPMU accounting
The mediated_pmu_account_event() and perf_create_mediated_pmu() functions implement the exclusion between '!exclude_guest' counters and mediated vPMUs. Their implementation is basically identical, except mirrored in what they count/check. Make sure the actual implementations reflect this similarity. Notably: - while perf_release_mediated_pmu() has an underflow check; mediated_pmu_unaccount_event() did not. - while perf_create_mediated_pmu() has an inc_not_zero() path; mediated_pmu_account_event() did not. Also, the inc_not_zero() path can be outsite of perf_mediated_pmu_mutex. The mutex must guard the 0->1 (of either nr_include_guest_events or nr_mediated_pmu_vms) transition, but once a counter is already non-zero, it can safely be incremented further. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20251208115156.GE3707891@noisy.programming.kicks-ass.net
This commit is contained in:
parent
3006911f28
commit
3cb3c2f688
1 changed files with 7 additions and 2 deletions
|
|
@ -6344,8 +6344,10 @@ static int mediated_pmu_account_event(struct perf_event *event)
|
|||
if (!is_include_guest_event(event))
|
||||
return 0;
|
||||
|
||||
guard(mutex)(&perf_mediated_pmu_mutex);
|
||||
if (atomic_inc_not_zero(&nr_include_guest_events))
|
||||
return 0;
|
||||
|
||||
guard(mutex)(&perf_mediated_pmu_mutex);
|
||||
if (atomic_read(&nr_mediated_pmu_vms))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
|
|
@ -6358,6 +6360,9 @@ static void mediated_pmu_unaccount_event(struct perf_event *event)
|
|||
if (!is_include_guest_event(event))
|
||||
return;
|
||||
|
||||
if (WARN_ON_ONCE(!atomic_read(&nr_include_guest_events)))
|
||||
return;
|
||||
|
||||
atomic_dec(&nr_include_guest_events);
|
||||
}
|
||||
|
||||
|
|
@ -6373,10 +6378,10 @@ static void mediated_pmu_unaccount_event(struct perf_event *event)
|
|||
*/
|
||||
int perf_create_mediated_pmu(void)
|
||||
{
|
||||
guard(mutex)(&perf_mediated_pmu_mutex);
|
||||
if (atomic_inc_not_zero(&nr_mediated_pmu_vms))
|
||||
return 0;
|
||||
|
||||
guard(mutex)(&perf_mediated_pmu_mutex);
|
||||
if (atomic_read(&nr_include_guest_events))
|
||||
return -EBUSY;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue