Skip to content

Commit ca55950

Browse files
Kan LiangIngo Molnar
authored andcommitted
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. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 75a9001 commit ca55950

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

kernel/events/core.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,11 @@ event_filter_match(struct perf_event *event)
23512351
perf_cgroup_match(event);
23522352
}
23532353

2354+
static inline bool is_event_in_freq_mode(struct perf_event *event)
2355+
{
2356+
return event->attr.freq && event->attr.sample_freq;
2357+
}
2358+
23542359
static void
23552360
event_sched_out(struct perf_event *event, struct perf_event_context *ctx)
23562361
{
@@ -2388,7 +2393,7 @@ event_sched_out(struct perf_event *event, struct perf_event_context *ctx)
23882393

23892394
if (!is_software_event(event))
23902395
cpc->active_oncpu--;
2391-
if (event->attr.freq && event->attr.sample_freq) {
2396+
if (is_event_in_freq_mode(event)) {
23922397
ctx->nr_freq--;
23932398
epc->nr_freq--;
23942399
}
@@ -2686,7 +2691,7 @@ event_sched_in(struct perf_event *event, struct perf_event_context *ctx)
26862691

26872692
if (!is_software_event(event))
26882693
cpc->active_oncpu++;
2689-
if (event->attr.freq && event->attr.sample_freq) {
2694+
if (is_event_in_freq_mode(event)) {
26902695
ctx->nr_freq++;
26912696
epc->nr_freq++;
26922697
}
@@ -4252,11 +4257,11 @@ static void perf_adjust_freq_unthr_events(struct list_head *event_list)
42524257
if (hwc->interrupts == MAX_INTERRUPTS) {
42534258
hwc->interrupts = 0;
42544259
perf_log_throttle(event, 1);
4255-
if (!event->attr.freq || !event->attr.sample_freq)
4260+
if (!is_event_in_freq_mode(event))
42564261
event->pmu->start(event, 0);
42574262
}
42584263

4259-
if (!event->attr.freq || !event->attr.sample_freq)
4264+
if (!is_event_in_freq_mode(event))
42604265
continue;
42614266

42624267
/*
@@ -12848,7 +12853,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
1284812853

1284912854
hwc = &event->hw;
1285012855
hwc->sample_period = attr->sample_period;
12851-
if (attr->freq && attr->sample_freq)
12856+
if (is_event_in_freq_mode(event))
1285212857
hwc->sample_period = 1;
1285312858
hwc->last_period = hwc->sample_period;
1285412859

0 commit comments

Comments
 (0)