perf: Fix the throttle logic for group
Subsystems (12)
v3 cover perf: Fix the throttle logic for group
From: Kan Liang <[email protected]>
Changes since V2:
- Add a cleanup patch to check if an event is in freq mode
- Rename the parameter of the perf_event_unthrottle_group()
- Add Tested-by from Leo and Thomas
- Add Acked-by from Guo Ren
Changes since V1:
- Apply the suggested throttle/unthrottle functions from Peter. The MAX_INTERRUPTS and throttle logs are applied to all events.
- Update the description and comments accordingly
- Add Reviewed-by from Ravi and Max
The sampling read doesn't work well with a group.
The issue was originally found by the 'Basic leader sampling test' case failed on s390.
https://lore.kernel.org/all/[email protected]/
Stephane debugged it and found it was caused by the throttling logic.
https://lore.kernel.org/all/CABPqkBQzCMNS_PfLZBWVuX9o8Z55PovwJvpVWMWzyeExFJ5R4Q@mail.gmail.com/
The throttle logic is generic and shared by all ARCHs. It also impacts other ARCHs, e.g., X86.
On an Intel GNR machine,
$ perf record -e "{cycles,cycles}:S" ...$ perf report -D | grep THROTTLE | tail -2
THROTTLE events: 426 ( 9.0%)
UNTHROTTLE events: 425 ( 9.0%)$ perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 1020120874009167 0x74970 [0x68]: PERF_RECORD_SAMPLE(IP, 0x1): ... sample_read: .... group nr 2 ..... id 0000000000000327, value 000000000cbb993a, lost 0 ..... id 0000000000000328, value 00000002211c26df, lost 0
The patch set tries to provide a generic fix for the group throttle support. So the buggy driver-specific implementation can be removed.
The patch set is verified on newer Intel platforms (Kan), ARM (Leo Yan), and s390 (Thomas Richter).
Kan Liang (16):
perf: Clean up event in freq mode check
perf: Fix the throttle logic for a group perf/x86/intel: Remove driver-specific throttle support perf/x86/amd: Remove driver-specific throttle support perf/x86/zhaoxin: Remove driver-specific throttle support powerpc/perf: Remove driver-specific throttle support s390/perf: Remove driver-specific throttle support perf/arm: Remove driver-specific throttle support perf/apple_m1: Remove driver-specific throttle support alpha/perf: Remove driver-specific throttle support arc/perf: Remove driver-specific throttle support csky/perf: Remove driver-specific throttle support loongarch/perf: Remove driver-specific throttle support sparc/perf: Remove driver-specific throttle support xtensa/perf: Remove driver-specific throttle support mips/perf: Remove driver-specific throttle support
arch/alpha/kernel/perf_event.c | 11 ++--- arch/arc/kernel/perf_event.c | 6 +-- arch/csky/kernel/perf_event.c | 3 +- arch/loongarch/kernel/perf_event.c | 3 +- arch/mips/kernel/perf_event_mipsxx.c | 3 +- arch/powerpc/perf/core-book3s.c | 6 +-- arch/powerpc/perf/core-fsl-emb.c | 3 +- arch/s390/kernel/perf_cpum_cf.c | 2 - arch/s390/kernel/perf_cpum_sf.c | 5 +- arch/sparc/kernel/perf_event.c | 3 +- arch/x86/events/amd/core.c | 3 +- arch/x86/events/amd/ibs.c | 4 +- arch/x86/events/core.c | 3 +- arch/x86/events/intel/core.c | 6 +-- arch/x86/events/intel/ds.c | 7 ++- arch/x86/events/intel/knc.c | 3 +- arch/x86/events/intel/p4.c | 3 +- arch/x86/events/zhaoxin/core.c | 3 +- arch/xtensa/kernel/perf_event.c | 3 +- drivers/perf/apple_m1_cpu_pmu.c | 3 +- drivers/perf/arm_pmuv3.c | 3 +- drivers/perf/arm_v6_pmu.c | 3 +- drivers/perf/arm_v7_pmu.c | 3 +- drivers/perf/arm_xscale_pmu.c | 6 +-- kernel/events/core.c | 73 ++++++++++++++++++++-------- 25 files changed, 84 insertions(+), 87 deletions(-)
Signature · 1 line
2.38.1
PATCH v3 1/16 perf: Clean up event in freq mode check
From: Kan Liang <[email protected]>
Add a helper to check if an event is in freq mode to improve the readability.
No functional change.
--- kernel/events/core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
kernel/events/core.c +10 -5
@@ -2442,6 +2442,11 @@ event_filter_match(struct perf_event *event)perf_cgroup_match (event); } +static inline bool is_event_in_freq_mode (struct perf_event *event) +{ +return event->attr.freq && event->attr.sample_freq; +} +static void event_sched_out (struct perf_event *event,struct perf_event_context *ctx) {
@@ -2479,7 +2484,7 @@ event_sched_out(struct perf_event *event, struct perf_event_context *ctx)if (!is_software_event (event)) cpc->active_oncpu--; -if (event->attr.freq && event->attr.sample_freq) { +if (is_event_in_freq_mode (event)) { ctx->nr_freq--; epc->nr_freq--; }
@@ -2780,7 +2785,7 @@ event_sched_in(struct perf_event *event, struct perf_event_context *ctx)if (!is_software_event (event)) cpc->active_oncpu++; -if (event->attr.freq && event->attr.sample_freq) { +if (is_event_in_freq_mode (event)) { ctx->nr_freq++; epc->nr_freq++; }
@@ -4391,11 +4396,11 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list)if (hwc->interrupts ==MAX_INTERRUPTS ) { hwc->interrupts =0 ;perf_log_throttle (event,1 ); -if (!event->attr.freq || !event->attr.sample_freq) +if (!is_event_in_freq_mode (event)) event->pmu->start (event,0 ); } -if (!event->attr.freq || !event->attr.sample_freq) +if (!is_event_in_freq_mode (event))continue ;/*
@@ -13129,7 +13134,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, hwc = &event->hw; hwc->sample_period = attr->sample_period; -if (attr->freq && attr->sample_freq) +if (is_event_in_freq_mode (event)) hwc->sample_period =1 ; hwc->last_period = hwc->sample_period;
Signature · 1 line
2.38.1
[tip: perf/core] perf/core: Add the is_event_in_freq_mode() helper to simplify the code
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: ca559503b89c30bc49178d0e4a1e0b23f991fb9f Gitweb: https://git.kernel.org/tip/ca559503b89c30bc49178d0e4a1e0b23f991fb9f Author: Kan Liang <[email protected]> AuthorDate: Fri, 16 May 2025 11:28:38 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 17 May 2025 10:02:27 +02:00
perf/core: Add the is_event_in_freq_mode() helper to simplify the code
Add a helper to check if an event is in freq mode to improve readability.
No functional changes.
--- kernel/events/core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
kernel/events/core.c +10 -5
@@ -2351,6 +2351,11 @@ event_filter_match(struct perf_event *event)perf_cgroup_match (event); } +static inline bool is_event_in_freq_mode (struct perf_event *event) +{ +return event->attr.freq && event->attr.sample_freq; +} +static void event_sched_out (struct perf_event *event,struct perf_event_context *ctx) {
@@ -2388,7 +2393,7 @@ event_sched_out(struct perf_event *event, struct perf_event_context *ctx)if (!is_software_event (event)) cpc->active_oncpu--; -if (event->attr.freq && event->attr.sample_freq) { +if (is_event_in_freq_mode (event)) { ctx->nr_freq--; epc->nr_freq--; }
@@ -2686,7 +2691,7 @@ event_sched_in(struct perf_event *event, struct perf_event_context *ctx)if (!is_software_event (event)) cpc->active_oncpu++; -if (event->attr.freq && event->attr.sample_freq) { +if (is_event_in_freq_mode (event)) { ctx->nr_freq++; epc->nr_freq++; }
@@ -4252,11 +4257,11 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list)if (hwc->interrupts ==MAX_INTERRUPTS ) { hwc->interrupts =0 ;perf_log_throttle (event,1 ); -if (!event->attr.freq || !event->attr.sample_freq) +if (!is_event_in_freq_mode (event)) event->pmu->start (event,0 ); } -if (!event->attr.freq || !event->attr.sample_freq) +if (!is_event_in_freq_mode (event))continue ;/*
@@ -12848,7 +12853,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu, hwc = &event->hw; hwc->sample_period = attr->sample_period; -if (attr->freq && attr->sample_freq) +if (is_event_in_freq_mode (event)) hwc->sample_period =1 ; hwc->last_period = hwc->sample_period;
PATCH v3 2/16 perf: Fix the throttle logic for a group
In reply to [email protected]From: Kan Liang <[email protected]>
The current throttle logic doesn't work well with a group, e.g., the following sampling-read case.
$ perf record -e "{cycles,cycles}:S" ...$ perf report -D | grep THROTTLE | tail -2
THROTTLE events: 426 ( 9.0%)
UNTHROTTLE events: 425 ( 9.0%)$ perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 1020120874009167 0x74970 [0x68]: PERF_RECORD_SAMPLE(IP, 0x1): ... sample_read: .... group nr 2 ..... id 0000000000000327, value 000000000cbb993a, lost 0 ..... id 0000000000000328, value 00000002211c26df, lost 0
The second cycles event has a much larger value than the first cycles event in the same group.
The current throttle logic in the generic code only logs the THROTTLE event. It relies on the specific driver implementation to disable events. For all ARCHs, the implementation is similar. Only the event is disabled, rather than the group.
The logic to disable the group should be generic for all ARCHs. Add the logic in the generic code. The following patch will remove the buggy driver-specific implementation.
The throttle only happens when an event is overflowed. Stop the entire group when any event in the group triggers the throttle. The MAX_INTERRUPTS is set to all throttle events.
The unthrottled could happen in 3 places.
- event/group sched. All events in the group are scheduled one by one. All of them will be unthrottled eventually. Nothing needs to be changed.
- The perf_adjust_freq_unthr_events for each tick. Needs to restart the group altogether.
- The __perf_event_period(). The whole group needs to be restarted altogether as well.
With the fix,
$ sudo perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 3573470770332 0x12f5f8 [0x70]: PERF_RECORD_SAMPLE(IP, 0x2): ... sample_read: .... group nr 2 ..... id 0000000000000a28, value 00000004fd3dfd8f, lost 0 ..... id 0000000000000a29, value 00000004fd3dfd8f, lost 0
--- kernel/events/core.c | 60 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-)
kernel/events/core.c +44 -16
@@ -2739,6 +2739,39 @@ void perf_event_disable_inatomic(struct perf_event *event)static void perf_log_throttle (struct perf_event *event,int enable);static void perf_log_itrace_start (struct perf_event *event); +static void perf_event_unthrottle (struct perf_event *event,bool start) +{ + event->hw.interrupts =0 ; +if (start) + event->pmu->start (event,0 ); +perf_log_throttle (event,1 ); +} + +static void perf_event_throttle (struct perf_event *event) +{ + event->pmu->stop (event,0 ); + event->hw.interrupts =MAX_INTERRUPTS ; +perf_log_throttle (event,0 ); +} + +static void perf_event_unthrottle_group (struct perf_event *event,bool skip_start_event) +{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_unthrottle (leader, skip_start_event ? leader != event : true); +for_each_sibling_event (sibling, leader) +perf_event_unthrottle (sibling, skip_start_event ? sibling != event : true); +} + +static void perf_event_throttle_group (struct perf_event *event) +{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_throttle (leader); +for_each_sibling_event (sibling, leader) +perf_event_throttle (sibling); +} +static int event_sched_in (struct perf_event *event,struct perf_event_context *ctx) {
@@ -4393,12 +4426,8 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) hwc = &event->hw; -if (hwc->interrupts ==MAX_INTERRUPTS ) { - hwc->interrupts =0 ; -perf_log_throttle (event,1 ); -if (!is_event_in_freq_mode (event)) - event->pmu->start (event,0 ); - } +if (hwc->interrupts ==MAX_INTERRUPTS ) +perf_event_unthrottle_group (event,is_event_in_freq_mode (event));if (!is_event_in_freq_mode (event))continue ;
@@ -6426,14 +6455,6 @@ static void __perf_event_period(struct perf_event *event, active = (event->state ==PERF_EVENT_STATE_ACTIVE );if (active) {perf_pmu_disable (event->pmu); -/* -* We could be throttled; unthrottle now to avoid the tick -* trying to unthrottle while we already re-started the event. -*/ -if (event->hw.interrupts ==MAX_INTERRUPTS ) { - event->hw.interrupts =0 ; -perf_log_throttle (event,1 ); - } event->pmu->stop (event,PERF_EF_UPDATE ); }
@@ -6441,6 +6462,14 @@ static void __perf_event_period(struct perf_event *event,if (active) { event->pmu->start (event,PERF_EF_RELOAD ); +/* +* Once the period is force-reset, the event starts immediately. +* But the event/group could be throttled. Unthrottle the +* event/group now to avoid the next tick trying to unthrottle +* while we already re-started the event/group. +*/ +if (event->hw.interrupts ==MAX_INTERRUPTS ) +perf_event_unthrottle_group (event, true);perf_pmu_enable (event->pmu); } }
@@ -10331,8 +10360,7 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle)if (unlikely (throttle && hwc->interrupts >= max_samples_per_tick)) {__this_cpu_inc (perf_throttled_count);tick_dep_set_cpu (smp_processor_id (),TICK_DEP_BIT_PERF_EVENTS ); - hwc->interrupts =MAX_INTERRUPTS ; -perf_log_throttle (event,0 ); +perf_event_throttle_group (event); ret =1 ; }
Signature · 1 line
2.38.1
Re: [PATCH V3 02/16] perf: Fix the throttle logic for a group
Quoted 3 lines · * [email protected] <[email protected]> wrote:
The throttle only happens when an event is overflowed. Stop the entire group when any event in the group triggers the throttle. The
MAX_INTERRUPTSis set to all throttle events.
Since this is a relatively long series with a healthy dose of breakage-risk, I'm wondering about bisectability:
- patch #2 auto-throttles groups, ie. stops the PMU
- patches #3-#16 removes explicit PMU-stop calls.
In the interim commits, will the double PMU-stop in drivers not updated yet do anything noticeable, such as generate warnings, etc?
Thanks,
Ingo
Re: [PATCH V3 02/16] perf: Fix the throttle logic for a group
Quoted 10 lines · Ingo Molnar
Quoted 3 lines · * [email protected] <[email protected]> wrote:
The throttle only happens when an event is overflowed. Stop the entire group when any event in the group triggers the throttle. The
MAX_INTERRUPTSis set to all throttle events.Since this is a relatively long series with a healthy dose of breakage-risk, I'm wondering about bisectability:
Quoted 7 lines
- patch #2 auto-throttles groups, ie. stops the PMU
- patches #3-#16 removes explicit PMU-stop calls.
In the interim commits, will the double PMU-stop in drivers not updated yet do anything noticeable, such as generate warnings, etc?
The short answer is no.
Here are the details for different ARCHs.
There is a active_mask to track the active counter/event in X86. The current implementation checks the corresponding bit first. If it is already cleared, do nothing. It avoids the double PMU-stop. I've tested on my machine.
AMD and Zhaoxin shares the same x86_pmu_stop() as Intel. They are OK as well.
powerpc, S390, ARC, sparc and xtensa utilize the PERF_HES_STOPPED flag instead. If the flag has been set, do nothing. It can also avoids the double PMU-stop.
ARM, apple m1, csky, loongarch and mips invoke the disable_event, rather than PMU stop. The disable_event unconditionally disables the counter register. It doesn't check if the register is already disabled. But I don't think double writing a register can trigger any issue.
Alpha utilizes the PERF_HES_STOPPED flag. But it seems still writes the counter register even it's already disabled. Because the cpuc->enabled is used to check whether to write to the register. It's not updated in the alpha_pmu_stop(). But again, I don't think double writing a register can trigger any issue.
Thanks,
Kan
Namhyung Kim
maintainerRe: [PATCH V3 02/16] perf: Fix the throttle logic for a group
In reply to [email protected]Hi Kan,
Quoted 43 lines · On Fri, May 16, 2025 at 11:28:39AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The current throttle logic doesn't work well with a group, e.g., the following sampling-read case.
$ perf record -e "{cycles,cycles}:S" ...$ perf report -D | grep THROTTLE | tail -2 THROTTLE events: 426 ( 9.0%) UNTHROTTLE events: 425 ( 9.0%)$ perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 1020120874009167 0x74970 [0x68]: PERF_RECORD_SAMPLE(IP, 0x1): ... sample_read: .... group nr 2 ..... id 0000000000000327, value 000000000cbb993a, lost 0 ..... id 0000000000000328, value 00000002211c26df, lost 0The second cycles event has a much larger value than the first cycles event in the same group.
The current throttle logic in the generic code only logs the THROTTLE event. It relies on the specific driver implementation to disable events. For all ARCHs, the implementation is similar. Only the event is disabled, rather than the group.
The logic to disable the group should be generic for all ARCHs. Add the logic in the generic code. The following patch will remove the buggy driver-specific implementation.
The throttle only happens when an event is overflowed. Stop the entire group when any event in the group triggers the throttle. The
MAX_INTERRUPTSis set to all throttle events.The unthrottled could happen in 3 places.
- event/group sched. All events in the group are scheduled one by one. All of them will be unthrottled eventually. Nothing needs to be changed.
- Theperf_adjust_freq_unthr_eventsfor each tick. Needs to restart the group altogether.
- The__perf_event_period(). The whole group needs to be restarted altogether as well.
Quoted 7 lines
With the fix,
$ sudo perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 3573470770332 0x12f5f8 [0x70]: PERF_RECORD_SAMPLE(IP, 0x2): ... sample_read: .... group nr 2 ..... id 0000000000000a28, value 00000004fd3dfd8f, lost 0 ..... id 0000000000000a29, value 00000004fd3dfd8f, lost 0
Thanks for working on this!
Quoted 27 lines
Suggested-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Kan Liang <[email protected]>--- kernel/events/core.c | 60 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-)kernel/events/core.c +12
-0@@ -2739,6 +2739,39 @@ void perf_event_disable_inatomic(struct perf_event *event)static void perf_log_throttle (struct perf_event *event,int enable);static void perf_log_itrace_start (struct perf_event *event); +static void perf_event_unthrottle (struct perf_event *event,bool start) +{ + event->hw.interrupts =0 ; +if (start) + event->pmu->start (event,0 ); +perf_log_throttle (event,1 ); +} + +static void perf_event_throttle (struct perf_event *event) +{ + event->pmu->stop (event,0 ); + event->hw.interrupts =MAX_INTERRUPTS ;
kernel/events/core.c void perf_event_disable_inatomic(struct perf_event *event) · line 2763
Quoted 10 lines
kernel/events/core.c +10
-0+perf_log_throttle (event,0 ); +} + +static void perf_event_unthrottle_group (struct perf_event *event,bool skip_start_event) +{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_unthrottle (leader, skip_start_event ? leader != event : true); +for_each_sibling_event (sibling, leader) +perf_event_unthrottle (sibling, skip_start_event ? sibling != event : true);
This will add more PERF_RECORD_THROTTLE records for sibling events. Maybe we can generate it for the actual target event only?
Also the condition for skip_start_event is if it's a freq event. I think we can skip pmu->start() if the sibling is also a freq event. I remember KVM folks concern about the number of PMU accesses as it can cause VM exits.
Thanks,
Namhyung
Quoted 72 lines
kernel/events/core.c +22
-16+} + +static void perf_event_throttle_group (struct perf_event *event) +{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_throttle (leader); +for_each_sibling_event (sibling, leader) +perf_event_throttle (sibling); +} +static int event_sched_in (struct perf_event *event,struct perf_event_context *ctx) {@@ -4393,12 +4426,8 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) hwc = &event->hw; -if (hwc->interrupts ==MAX_INTERRUPTS ) { - hwc->interrupts =0 ; -perf_log_throttle (event,1 ); -if (!is_event_in_freq_mode (event)) - event->pmu->start (event,0 ); - } +if (hwc->interrupts ==MAX_INTERRUPTS ) +perf_event_unthrottle_group (event,is_event_in_freq_mode (event));if (!is_event_in_freq_mode (event))continue ;@@ -6426,14 +6455,6 @@ static void __perf_event_period(struct perf_event *event, active = (event->state ==PERF_EVENT_STATE_ACTIVE );if (active) {perf_pmu_disable (event->pmu); -/* -* We could be throttled; unthrottle now to avoid the tick -* trying to unthrottle while we already re-started the event. -*/ -if (event->hw.interrupts ==MAX_INTERRUPTS ) { - event->hw.interrupts =0 ; -perf_log_throttle (event,1 ); - } event->pmu->stop (event,PERF_EF_UPDATE ); }@@ -6441,6 +6462,14 @@ static void __perf_event_period(struct perf_event *event,if (active) { event->pmu->start (event,PERF_EF_RELOAD ); +/* +* Once the period is force-reset, the event starts immediately. +* But the event/group could be throttled. Unthrottle the +* event/group now to avoid the next tick trying to unthrottle +* while we already re-started the event/group. +*/ +if (event->hw.interrupts ==MAX_INTERRUPTS ) +perf_event_unthrottle_group (event, true);perf_pmu_enable (event->pmu); } }@@ -10331,8 +10360,7 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle)if (unlikely (throttle && hwc->interrupts >= max_samples_per_tick)) {__this_cpu_inc (perf_throttled_count);tick_dep_set_cpu (smp_processor_id (),TICK_DEP_BIT_PERF_EVENTS ); - hwc->interrupts =MAX_INTERRUPTS ; -perf_log_throttle (event,0 ); +perf_event_throttle_group (event); ret =1 ; }Signature · 1 line
2.38.1
Re: [PATCH V3 02/16] perf: Fix the throttle logic for a group
Quoted 87 lines · Namhyung Kim
Hi Kan,
Quoted 43 lines · On Fri, May 16, 2025 at 11:28:39AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The current throttle logic doesn't work well with a group, e.g., the following sampling-read case.
$ perf record -e "{cycles,cycles}:S" ...$ perf report -D | grep THROTTLE | tail -2 THROTTLE events: 426 ( 9.0%) UNTHROTTLE events: 425 ( 9.0%)$ perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 1020120874009167 0x74970 [0x68]: PERF_RECORD_SAMPLE(IP, 0x1): ... sample_read: .... group nr 2 ..... id 0000000000000327, value 000000000cbb993a, lost 0 ..... id 0000000000000328, value 00000002211c26df, lost 0The second cycles event has a much larger value than the first cycles event in the same group.
The current throttle logic in the generic code only logs the THROTTLE event. It relies on the specific driver implementation to disable events. For all ARCHs, the implementation is similar. Only the event is disabled, rather than the group.
The logic to disable the group should be generic for all ARCHs. Add the logic in the generic code. The following patch will remove the buggy driver-specific implementation.
The throttle only happens when an event is overflowed. Stop the entire group when any event in the group triggers the throttle. The
MAX_INTERRUPTSis set to all throttle events.The unthrottled could happen in 3 places.
- event/group sched. All events in the group are scheduled one by one. All of them will be unthrottled eventually. Nothing needs to be changed.
- Theperf_adjust_freq_unthr_eventsfor each tick. Needs to restart the group altogether.
- The__perf_event_period(). The whole group needs to be restarted altogether as well.Quoted 7 lines
With the fix,
$ sudo perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 3573470770332 0x12f5f8 [0x70]: PERF_RECORD_SAMPLE(IP, 0x2): ... sample_read: .... group nr 2 ..... id 0000000000000a28, value 00000004fd3dfd8f, lost 0 ..... id 0000000000000a29, value 00000004fd3dfd8f, lost 0Thanks for working on this!
Quoted 31 lines
Suggested-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Kan Liang <[email protected]>--- kernel/events/core.c | 60 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-)kernel/events/core.c +16
-0@@ -2739,6 +2739,39 @@ void perf_event_disable_inatomic(struct perf_event *event)static void perf_log_throttle (struct perf_event *event,int enable);static void perf_log_itrace_start (struct perf_event *event); +static void perf_event_unthrottle (struct perf_event *event,bool start) +{ + event->hw.interrupts =0 ; +if (start) + event->pmu->start (event,0 ); +perf_log_throttle (event,1 ); +} + +static void perf_event_throttle (struct perf_event *event) +{ + event->pmu->stop (event,0 ); + event->hw.interrupts =MAX_INTERRUPTS ; +perf_log_throttle (event,0 ); +} + +static void perf_event_unthrottle_group (struct perf_event *event,bool skip_start_event)
Quoted 8 lines
kernel/events/core.c void perf_event_disable_inatomic(struct perf_event *event) · line 2763
Quoted 6 lines
kernel/events/core.c +6
-0+{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_unthrottle (leader, skip_start_event ? leader != event : true); +for_each_sibling_event (sibling, leader) +perf_event_unthrottle (sibling, skip_start_event ? sibling != event : true);This will add more
PERF_RECORD_THROTTLErecords for sibling events.
Yes
Quoted 1 line
Maybe we can generate it for the actual target event only?
The current code cannot track the actual target event for unthrottle. Because the MAX_INTERRUPTS are set for all events when event_throttle.
But I think we can only add a PERF_RECORD_THROTTLE record for the leader event, which can reduce the number of THROTTLE records.
The sample right after the THROTTLE record must be generated by the actual target event. I think it should be good enough for the perf tool to locate the event.
I will add the below patch as a separate improvement in V4.
kernel/events/core.c +0 -0
@@ -2744,14 +2744,16 @@ static void perf_event_unthrottle(struct
perf_event *event, bool start)
event->hw.interrupts = 0;
if (start)
event->pmu->start(event, 0);
- perf_log_throttle(event, 1);
+ if (event == event->group_leader)
+ perf_log_throttle(event, 1);
}
static void perf_event_throttle(struct perf_event *event) {
event->pmu->stop(event, 0); event->hw.interrupts = MAX_INTERRUPTS;
- perf_log_throttle(event, 0);
+ if (event == event->group_leader)
+ perf_log_throttle(event, 0);
}
Quoted 3 lines
Also the condition for
skip_start_eventis if it's a freq event. I think we can skippmu->start()if the sibling is also a freq event.
The skip_start_event is if it will be start later separately. It intends to avoid the double start.
In the perf_adjust_freq_unthr_events(), it will only adjust and start the leader event, not group. If we skip pmu->start() for a freq sibling event, it will not start until the next context switch.
Thanks,
Kan
Quoted 79 lines
I remember KVM folks concern about the number of PMU accesses as it can cause VM exits.
Thanks,
NamhyungQuoted 72 lines
kernel/events/core.c +22
-16+} + +static void perf_event_throttle_group (struct perf_event *event) +{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_throttle (leader); +for_each_sibling_event (sibling, leader) +perf_event_throttle (sibling); +} +static int event_sched_in (struct perf_event *event,struct perf_event_context *ctx) {@@ -4393,12 +4426,8 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list) hwc = &event->hw; -if (hwc->interrupts ==MAX_INTERRUPTS ) { - hwc->interrupts =0 ; -perf_log_throttle (event,1 ); -if (!is_event_in_freq_mode (event)) - event->pmu->start (event,0 ); - } +if (hwc->interrupts ==MAX_INTERRUPTS ) +perf_event_unthrottle_group (event,is_event_in_freq_mode (event));if (!is_event_in_freq_mode (event))continue ;@@ -6426,14 +6455,6 @@ static void __perf_event_period(struct perf_event *event, active = (event->state ==PERF_EVENT_STATE_ACTIVE );if (active) {perf_pmu_disable (event->pmu); -/* -* We could be throttled; unthrottle now to avoid the tick -* trying to unthrottle while we already re-started the event. -*/ -if (event->hw.interrupts ==MAX_INTERRUPTS ) { - event->hw.interrupts =0 ; -perf_log_throttle (event,1 ); - } event->pmu->stop (event,PERF_EF_UPDATE ); }@@ -6441,6 +6462,14 @@ static void __perf_event_period(struct perf_event *event,if (active) { event->pmu->start (event,PERF_EF_RELOAD ); +/* +* Once the period is force-reset, the event starts immediately. +* But the event/group could be throttled. Unthrottle the +* event/group now to avoid the next tick trying to unthrottle +* while we already re-started the event/group. +*/ +if (event->hw.interrupts ==MAX_INTERRUPTS ) +perf_event_unthrottle_group (event, true);perf_pmu_enable (event->pmu); } }@@ -10331,8 +10360,7 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle)if (unlikely (throttle && hwc->interrupts >= max_samples_per_tick)) {__this_cpu_inc (perf_throttled_count);tick_dep_set_cpu (smp_processor_id (),TICK_DEP_BIT_PERF_EVENTS ); - hwc->interrupts =MAX_INTERRUPTS ; -perf_log_throttle (event,0 ); +perf_event_throttle_group (event); ret =1 ; }Signature · 1 line
2.38.1
Namhyung Kim
maintainerRe: [PATCH V3 02/16] perf: Fix the throttle logic for a group
Quoted 99 lines · Kan
Quoted 87 lines · Namhyung Kim
Hi Kan,
Quoted 43 lines · On Fri, May 16, 2025 at 11:28:39AM -0700, [email protected] wrote:
From: Kan Liang <[email protected]>
The current throttle logic doesn't work well with a group, e.g., the following sampling-read case.
$ perf record -e "{cycles,cycles}:S" ...$ perf report -D | grep THROTTLE | tail -2 THROTTLE events: 426 ( 9.0%) UNTHROTTLE events: 425 ( 9.0%)$ perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 1020120874009167 0x74970 [0x68]: PERF_RECORD_SAMPLE(IP, 0x1): ... sample_read: .... group nr 2 ..... id 0000000000000327, value 000000000cbb993a, lost 0 ..... id 0000000000000328, value 00000002211c26df, lost 0The second cycles event has a much larger value than the first cycles event in the same group.
The current throttle logic in the generic code only logs the THROTTLE event. It relies on the specific driver implementation to disable events. For all ARCHs, the implementation is similar. Only the event is disabled, rather than the group.
The logic to disable the group should be generic for all ARCHs. Add the logic in the generic code. The following patch will remove the buggy driver-specific implementation.
The throttle only happens when an event is overflowed. Stop the entire group when any event in the group triggers the throttle. The
MAX_INTERRUPTSis set to all throttle events.The unthrottled could happen in 3 places.
- event/group sched. All events in the group are scheduled one by one. All of them will be unthrottled eventually. Nothing needs to be changed.
- Theperf_adjust_freq_unthr_eventsfor each tick. Needs to restart the group altogether.
- The__perf_event_period(). The whole group needs to be restarted altogether as well.Quoted 7 lines
With the fix,
$ sudo perf report -D | grep PERF_RECORD_SAMPLE -a4 | tail -n 5 0 3573470770332 0x12f5f8 [0x70]: PERF_RECORD_SAMPLE(IP, 0x2): ... sample_read: .... group nr 2 ..... id 0000000000000a28, value 00000004fd3dfd8f, lost 0 ..... id 0000000000000a29, value 00000004fd3dfd8f, lost 0Thanks for working on this!
Quoted 31 lines
Suggested-by Peter Zijlstra (Intel) <[email protected]>Signed-off-by Kan Liang <[email protected]>--- kernel/events/core.c | 60 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-)kernel/events/core.c +16
-0@@ -2739,6 +2739,39 @@ void perf_event_disable_inatomic(struct perf_event *event)static void perf_log_throttle (struct perf_event *event,int enable);static void perf_log_itrace_start (struct perf_event *event); +static void perf_event_unthrottle (struct perf_event *event,bool start) +{ + event->hw.interrupts =0 ; +if (start) + event->pmu->start (event,0 ); +perf_log_throttle (event,1 ); +} + +static void perf_event_throttle (struct perf_event *event) +{ + event->pmu->stop (event,0 ); + event->hw.interrupts =MAX_INTERRUPTS ; +perf_log_throttle (event,0 ); +} + +static void perf_event_unthrottle_group (struct perf_event *event,bool skip_start_event)Quoted 8 lines
kernel/events/core.c void perf_event_disable_inatomic(struct perf_event *event) · line 2763
Quoted 6 lines
kernel/events/core.c +6
-0+{ +struct perf_event *sibling, *leader = event->group_leader; + +perf_event_unthrottle (leader, skip_start_event ? leader != event : true); +for_each_sibling_event (sibling, leader) +perf_event_unthrottle (sibling, skip_start_event ? sibling != event : true);This will add more
PERF_RECORD_THROTTLErecords for sibling events.
Quoted 6 lines
Yes
Quoted 1 line
Maybe we can generate it for the actual target event only?
The current code cannot track the actual target event for unthrottle. Because the
MAX_INTERRUPTSare set for all events whenevent_throttle.
Right.
Quoted 3 lines
But I think we can only add a
PERF_RECORD_THROTTLErecord for the leader event, which can reduce the number of THROTTLE records.
Sounds good.
Quoted 4 lines
The sample right after the THROTTLE record must be generated by the actual target event. I think it should be good enough for the perf tool to locate the event.
IIRC perf tool doesn't track which event is throttled, but yeah, it'd be possible to use the next sample to locate it.
Quoted 15 lines
I will add the below patch as a separate improvement in V4.
kernel/events/core.c +2
-1@@ -2744,14 +2744,16 @@ static void perf_event_unthrottle(struct perf_event *event, bool start) event->hw.interrupts = 0;if (start) event->pmu->start (event,0 ); -perf_log_throttle (event,1 ); +if (event == event->group_leader) +perf_log_throttle (event,1 );
kernel/events/core.c static void perf_event_unthrottle(struct · line 2758
Quoted 10 lines
kernel/events/core.c +2
-1}static void perf_event_throttle (struct perf_event *event) { event->pmu->stop (event,0 ); event->hw.interrupts =MAX_INTERRUPTS ; -perf_log_throttle (event,0 ); +if (event == event->group_leader) +perf_log_throttle (event,0 ); }
Looks good.
Quoted 6 lines
Quoted 5 lines
Also the condition for
skip_start_eventis if it's a freq event. I think we can skippmu->start()if the sibling is also a freq event.
Quoted 6 lines
The
skip_start_eventis if it will be start later separately. It intends to avoid the double start.In the
perf_adjust_freq_unthr_events(), it will only adjust and start the leader event, not group. If we skippmu->start()for a freq sibling event, it will not start until the next context switch.
Oh, I missed that it only has leaders in the active list.
Thanks,
Namhyung
PATCH v3 3/16 perf/x86/intel: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/x86/events/core.c | 3 +-- arch/x86/events/intel/core.c | 6 ++---- arch/x86/events/intel/ds.c | 7 +++---- arch/x86/events/intel/knc.c | 3 +-- arch/x86/events/intel/p4.c | 3 +-- 5 files changed, 8 insertions(+), 14 deletions(-)
arch/x86/events/core.c +1 -2
@@ -1730,8 +1730,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs)perf_sample_save_brstack (&data, event, &cpuc->lbr_stack,NULL ); -if (perf_event_overflow (event, &data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }if (handled)
arch/x86/events/intel/core.c +2 -4
@@ -3138,8 +3138,7 @@ static void x86_pmu_handle_guest_pebs(struct pt_regs *regs,continue ;perf_sample_data_init (data,0 , event->hw.last_period); -if (perf_event_overflow (event, data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, data, regs);/* Inject one fake event is enough. */ break ;
@@ -3282,8 +3281,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)if (has_branch_stack (event))intel_pmu_lbr_save_brstack (&data, cpuc, event); -if (perf_event_overflow (event, &data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }return handled;
arch/x86/events/intel/ds.c +3 -4
@@ -2368,8 +2368,7 @@ __intel_pmu_pebs_last_event(struct perf_event *event,* All but the last records are processed. * The last one is left to be able to call the overflow handler. */ -if (perf_event_overflow (event, data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, data, regs); }if (hwc->flags &PERF_X86_EVENT_AUTO_RELOAD ) {
@@ -2597,8 +2596,8 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_dif (error[bit]) {perf_log_lost_samples (event, error[bit]); -if (iregs &&perf_event_account_interrupt (event)) -x86_pmu_stop (event,0 ); +if (iregs) +perf_event_account_interrupt (event); }if (counts[bit]) {
arch/x86/events/intel/knc.c +1 -2
@@ -254,8 +254,7 @@ static int knc_pmu_handle_irq(struct pt_regs *regs)perf_sample_data_init (&data,0 , last_period); -if (perf_event_overflow (event, &data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }/*
arch/x86/events/intel/p4.c +1 -2
@@ -1072,8 +1072,7 @@ static int p4_pmu_handle_irq(struct pt_regs *regs)continue ; -if (perf_event_overflow (event, &data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }if (handled)
Signature · 1 line
2.38.1
PATCH v3 4/16 perf/x86/amd: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/x86/events/amd/core.c | 3 +-- arch/x86/events/amd/ibs.c | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-)
arch/x86/events/amd/core.c +1 -2
@@ -1003,8 +1003,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)perf_sample_save_brstack (&data, event, &cpuc->lbr_stack,NULL ); -if (perf_event_overflow (event, &data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }/*
arch/x86/events/amd/ibs.c +1 -3
@@ -1373,9 +1373,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) hwc->sample_period = perf_ibs->min_period; out: -if (throttle) { -perf_ibs_stop (event,0 ); - }else { +if (!throttle) {if (perf_ibs == &perf_ibs_op) {if (ibs_caps &IBS_CAPS_OPCNTEXT ) { new_config = period &IBS_OP_MAX_CNT_EXT_MASK ;
Signature · 1 line
2.38.1
PATCH v3 5/16 perf/x86/zhaoxin: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/x86/events/zhaoxin/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/events/zhaoxin/core.c +1 -2
@@ -397,8 +397,7 @@ static int zhaoxin_pmu_handle_irq(struct pt_regs *regs)if (!x86_perf_event_set_period (event))continue ; -if (perf_event_overflow (event, &data, regs)) -x86_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }/*
Signature · 1 line
2.38.1
PATCH v3 6/16 powerpc/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/powerpc/perf/core-book3s.c | 6 ++---- arch/powerpc/perf/core-fsl-emb.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +2 -4
@@ -2344,12 +2344,10 @@ static void record_and_restart(struct perf_event *event, unsigned long val, ppmu->get_mem_weight (&data.weight.full, event->attr.sample_type); data.sample_flags |=PERF_SAMPLE_WEIGHT_TYPE ; } -if (perf_event_overflow (event, &data, regs)) -power_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); }else if (period) {/* Account for interrupt in case of invalid SIAR */ -if (perf_event_account_interrupt (event)) -power_pmu_stop (event,0 ); +perf_event_account_interrupt (event); } }
arch/powerpc/perf/core-fsl-emb.c +1 -2
@@ -635,8 +635,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val,perf_sample_data_init (&data,0 , last_period); -if (perf_event_overflow (event, &data, regs)) -fsl_emb_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); } }
Signature · 1 line
2.38.1
PATCH v3 7/16 s390/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/s390/kernel/perf_cpum_cf.c | 2 -- arch/s390/kernel/perf_cpum_sf.c | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-)
arch/s390/kernel/perf_cpum_cf.c +0 -2
@@ -980,8 +980,6 @@ static int cfdiag_push_sample(struct perf_event *event, } overflow =perf_event_overflow (event, &data, ®s); -if (overflow) - event->pmu->stop (event,0 );perf_event_update_userpage (event);return overflow;
arch/s390/kernel/perf_cpum_sf.c +1 -4
@@ -1072,10 +1072,7 @@ static int perf_push_sample(struct perf_event *event, overflow =0 ;if (perf_event_exclude (event, ®s, sde_regs)) goto out; -if (perf_event_overflow (event, &data, ®s)) { - overflow =1 ; - event->pmu->stop (event,0 ); - } + overflow =perf_event_overflow (event, &data, ®s);perf_event_update_userpage (event); out:return overflow;
Signature · 1 line
2.38.1
PATCH v3 8/16 perf/arm: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- drivers/perf/arm_pmuv3.c | 3 +-- drivers/perf/arm_v6_pmu.c | 3 +-- drivers/perf/arm_v7_pmu.c | 3 +-- drivers/perf/arm_xscale_pmu.c | 6 ++---- 4 files changed, 5 insertions(+), 10 deletions(-)
drivers/perf/arm_pmuv3.c +1 -2
@@ -887,8 +887,7 @@ static irqreturn_t armv8pmu_handle_irq(struct arm_pmu *cpu_pmu)* an irq_work which will be taken care of in the handling of * IPI_IRQ_WORK. */ -if (perf_event_overflow (event, &data, regs)) - cpu_pmu->disable (event); +perf_event_overflow (event, &data, regs); }armv8pmu_start (cpu_pmu);
drivers/perf/arm_v6_pmu.c +1 -2
@@ -276,8 +276,7 @@ armv6pmu_handle_irq(struct arm_pmu *cpu_pmu)if (!armpmu_event_set_period (event))continue ; -if (perf_event_overflow (event, &data, regs)) - cpu_pmu->disable (event); +perf_event_overflow (event, &data, regs); }/*
drivers/perf/arm_v7_pmu.c +1 -2
@@ -930,8 +930,7 @@ static irqreturn_t armv7pmu_handle_irq(struct arm_pmu *cpu_pmu)if (!armpmu_event_set_period (event))continue ; -if (perf_event_overflow (event, &data, regs)) - cpu_pmu->disable (event); +perf_event_overflow (event, &data, regs); }/*
drivers/perf/arm_xscale_pmu.c +2 -4
@@ -186,8 +186,7 @@ xscale1pmu_handle_irq(struct arm_pmu *cpu_pmu)if (!armpmu_event_set_period (event))continue ; -if (perf_event_overflow (event, &data, regs)) - cpu_pmu->disable (event); +perf_event_overflow (event, &data, regs); }irq_work_run ();
@@ -519,8 +518,7 @@ xscale2pmu_handle_irq(struct arm_pmu *cpu_pmu)if (!armpmu_event_set_period (event))continue ; -if (perf_event_overflow (event, &data, regs)) - cpu_pmu->disable (event); +perf_event_overflow (event, &data, regs); }irq_work_run ();
Signature · 1 line
2.38.1
PATCH v3 9/16 perf/apple_m1: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- drivers/perf/apple_m1_cpu_pmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/perf/apple_m1_cpu_pmu.c +1 -2
@@ -474,8 +474,7 @@ static irqreturn_t m1_pmu_handle_irq(struct arm_pmu *cpu_pmu)if (!armpmu_event_set_period (event))continue ; -if (perf_event_overflow (event, &data, regs)) -m1_pmu_disable_event (event); +perf_event_overflow (event, &data, regs); } cpu_pmu->start (cpu_pmu);
Signature · 1 line
2.38.1
PATCH v3 10/16 alpha/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/alpha/kernel/perf_event.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
arch/alpha/kernel/perf_event.c +3 -8
@@ -852,14 +852,9 @@ static void alpha_perf_event_irq_handler(unsigned long la_ptr,alpha_perf_event_update (event, hwc, idx, alpha_pmu->pmc_max_period[idx]+1 );perf_sample_data_init (&data,0 , hwc->last_period); -if (alpha_perf_event_set_period (event, hwc, idx)) { -if (perf_event_overflow (event, &data, regs)) { -/* Interrupts coming too quickly; "throttle" the -* counter, i.e., disable it for a little while. -*/ -alpha_pmu_stop (event,0 ); - } - } +if (alpha_perf_event_set_period (event, hwc, idx)) +perf_event_overflow (event, &data, regs); +wrperfmon (PERFMON_CMD_ENABLE , cpuc->idx_mask);return ;
Signature · 1 line
2.38.1
PATCH v3 11/16 arc/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/arc/kernel/perf_event.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/arc/kernel/perf_event.c +2 -4
@@ -599,10 +599,8 @@ static irqreturn_t arc_pmu_intr(int irq, void *dev)arc_perf_event_update (event, &event->hw, event->hw.idx);perf_sample_data_init (&data,0 , hwc->last_period); -if (arc_pmu_event_set_period (event)) { -if (perf_event_overflow (event, &data, regs)) -arc_pmu_stop (event,0 ); - } +if (arc_pmu_event_set_period (event)) +perf_event_overflow (event, &data, regs); active_ints &= ~BIT (idx); }while (active_ints);
Signature · 1 line
2.38.1
Re: [PATCH V3 11/16] arc/perf: Remove driver-specific throttle support
Quoted 5 lines · On 5/16/25 11:28, [email protected] wrote:
From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Quoted 7 lines
Besides the throttle,
perf_event_overflowmay return true because ofevent_limit. It already does an inatomic event disable. Thepmu->stopis not required either.
Please let me know if you wane to take it via ARC tree.
Thx,
-Vineet
Quoted 21 lines
--- arch/arc/kernel/perf_event.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)arch/arc/kernel/perf_event.c +2
-4@@ -599,10 +599,8 @@ static irqreturn_t arc_pmu_intr(int irq, void *dev)arc_perf_event_update (event, &event->hw, event->hw.idx);perf_sample_data_init (&data,0 , hwc->last_period); -if (arc_pmu_event_set_period (event)) { -if (perf_event_overflow (event, &data, regs)) -arc_pmu_stop (event,0 ); - } +if (arc_pmu_event_set_period (event)) +perf_event_overflow (event, &data, regs); active_ints &= ~BIT (idx); }while (active_ints);
PATCH v3 12/16 csky/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/csky/kernel/perf_event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/csky/kernel/perf_event.c +1 -2
@@ -1139,8 +1139,7 @@ static irqreturn_t csky_pmu_handle_irq(int irq_num, void *dev)perf_sample_data_init (&data,0 , hwc->last_period);csky_pmu_event_set_period (event); -if (perf_event_overflow (event, &data, regs)) -csky_pmu_stop_event (event); +perf_event_overflow (event, &data, regs); }csky_pmu_enable (&csky_pmu.pmu);
Signature · 1 line
2.38.1
PATCH v3 13/16 loongarch/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/loongarch/kernel/perf_event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/loongarch/kernel/perf_event.c +1 -2
@@ -479,8 +479,7 @@ static void handle_associated_event(struct cpu_hw_events *cpuc, int idx,if (!loongarch_pmu_event_set_period (event, hwc, idx))return ; -if (perf_event_overflow (event, data, regs)) -loongarch_pmu_disable_event (idx); +perf_event_overflow (event, data, regs); }static irqreturn_t pmu_handle_irq (int irq,void *dev)
Signature · 1 line
2.38.1
PATCH v3 14/16 sparc/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/sparc/kernel/perf_event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/sparc/kernel/perf_event.c +1 -2
@@ -1668,8 +1668,7 @@ static int __kprobes perf_event_nmi_handler(struct notifier_block *self,if (!sparc_perf_event_set_period (event, hwc, idx))continue ; -if (perf_event_overflow (event, &data, regs)) -sparc_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); } finish_clock =sched_clock ();
Signature · 1 line
2.38.1
PATCH v3 15/16 xtensa/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/xtensa/kernel/perf_event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/xtensa/kernel/perf_event.c +1 -2
@@ -388,8 +388,7 @@ irqreturn_t xtensa_pmu_irq_handler(int irq, void *dev_id)struct pt_regs *regs =get_irq_regs ();perf_sample_data_init (&data,0 , last_period); -if (perf_event_overflow (event, &data, regs)) -xtensa_pmu_stop (event,0 ); +perf_event_overflow (event, &data, regs); } rc =IRQ_HANDLED ;
Signature · 1 line
2.38.1
PATCH v3 16/16 mips/perf: Remove driver-specific throttle support
In reply to [email protected]From: Kan Liang <[email protected]>
The throttle support has been added in the generic code. Remove the driver-specific throttle support.
Besides the throttle, perf_event_overflow may return true because of event_limit. It already does an inatomic event disable. The pmu->stop is not required either.
--- arch/mips/kernel/perf_event_mipsxx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/mips/kernel/perf_event_mipsxx.c +1 -2
@@ -791,8 +791,7 @@ static void handle_associated_event(struct cpu_hw_events *cpuc,if (!mipspmu_event_set_period (event, hwc, idx))return ; -if (perf_event_overflow (event, data, regs)) -mipsxx_pmu_disable_event (idx); +perf_event_overflow (event, data, regs); }
Signature · 1 line
2.38.1