Skip to content

Commit 3c00ed3

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/ds: Factor out functions for PEBS records processing
Factor out functions to process normal and the last PEBS records, which can be shared with the later patch. Move the event updating related codes (intel_pmu_save_and_restart()) to the end, where all samples have been processed. For the current usage, it doesn't matter when perf updates event counts and reset the counter. Because all counters are stopped when the PEBS buffer is drained. Drop the return of the !intel_pmu_save_and_restart(event) check. Because it never happen. The intel_pmu_save_and_restart(event) only returns 0, when !hwc->event_base or the period_left > 0. - The !hwc->event_base is impossible for the PEBS event, since the PEBS event is only available on GP and fixed counters, which always have a valid hwc->event_base. - The check only happens for the case of non-AUTO_RELOAD and single PEBS, which implies that the event must be overflowed. The period_left must be always <= 0 for an overflowed event after the x86_pmu_update(). Co-developed-by: "Peter Zijlstra (Intel)" <peterz@infradead.org> Signed-off-by: "Peter Zijlstra (Intel)" <peterz@infradead.org> Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20241119135504.1463839-4-kan.liang@linux.intel.com
1 parent 7087bfb commit 3c00ed3

File tree

1 file changed

+67
-42
lines changed
  • arch/x86/events/intel

1 file changed

+67
-42
lines changed

arch/x86/events/intel/ds.c

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,46 +2164,33 @@ intel_pmu_save_and_restart_reload(struct perf_event *event, int count)
21642164
return 0;
21652165
}
21662166

2167+
typedef void (*setup_fn)(struct perf_event *, struct pt_regs *, void *,
2168+
struct perf_sample_data *, struct pt_regs *);
2169+
2170+
static struct pt_regs dummy_iregs;
2171+
21672172
static __always_inline void
21682173
__intel_pmu_pebs_event(struct perf_event *event,
21692174
struct pt_regs *iregs,
2175+
struct pt_regs *regs,
21702176
struct perf_sample_data *data,
2171-
void *base, void *top,
2172-
int bit, int count,
2173-
void (*setup_sample)(struct perf_event *,
2174-
struct pt_regs *,
2175-
void *,
2176-
struct perf_sample_data *,
2177-
struct pt_regs *))
2177+
void *at,
2178+
setup_fn setup_sample)
21782179
{
2179-
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2180-
struct hw_perf_event *hwc = &event->hw;
2181-
struct x86_perf_regs perf_regs;
2182-
struct pt_regs *regs = &perf_regs.regs;
2183-
void *at = get_next_pebs_record_by_bit(base, top, bit);
2184-
static struct pt_regs dummy_iregs;
2185-
2186-
if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) {
2187-
/*
2188-
* Now, auto-reload is only enabled in fixed period mode.
2189-
* The reload value is always hwc->sample_period.
2190-
* May need to change it, if auto-reload is enabled in
2191-
* freq mode later.
2192-
*/
2193-
intel_pmu_save_and_restart_reload(event, count);
2194-
} else if (!intel_pmu_save_and_restart(event))
2195-
return;
2196-
2197-
if (!iregs)
2198-
iregs = &dummy_iregs;
2180+
setup_sample(event, iregs, at, data, regs);
2181+
perf_event_output(event, data, regs);
2182+
}
21992183

2200-
while (count > 1) {
2201-
setup_sample(event, iregs, at, data, regs);
2202-
perf_event_output(event, data, regs);
2203-
at += cpuc->pebs_record_size;
2204-
at = get_next_pebs_record_by_bit(at, top, bit);
2205-
count--;
2206-
}
2184+
static __always_inline void
2185+
__intel_pmu_pebs_last_event(struct perf_event *event,
2186+
struct pt_regs *iregs,
2187+
struct pt_regs *regs,
2188+
struct perf_sample_data *data,
2189+
void *at,
2190+
int count,
2191+
setup_fn setup_sample)
2192+
{
2193+
struct hw_perf_event *hwc = &event->hw;
22072194

22082195
setup_sample(event, iregs, at, data, regs);
22092196
if (iregs == &dummy_iregs) {
@@ -2222,6 +2209,44 @@ __intel_pmu_pebs_event(struct perf_event *event,
22222209
if (perf_event_overflow(event, data, regs))
22232210
x86_pmu_stop(event, 0);
22242211
}
2212+
2213+
if (hwc->flags & PERF_X86_EVENT_AUTO_RELOAD) {
2214+
/*
2215+
* Now, auto-reload is only enabled in fixed period mode.
2216+
* The reload value is always hwc->sample_period.
2217+
* May need to change it, if auto-reload is enabled in
2218+
* freq mode later.
2219+
*/
2220+
intel_pmu_save_and_restart_reload(event, count);
2221+
} else
2222+
intel_pmu_save_and_restart(event);
2223+
}
2224+
2225+
static __always_inline void
2226+
__intel_pmu_pebs_events(struct perf_event *event,
2227+
struct pt_regs *iregs,
2228+
struct perf_sample_data *data,
2229+
void *base, void *top,
2230+
int bit, int count,
2231+
setup_fn setup_sample)
2232+
{
2233+
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2234+
struct x86_perf_regs perf_regs;
2235+
struct pt_regs *regs = &perf_regs.regs;
2236+
void *at = get_next_pebs_record_by_bit(base, top, bit);
2237+
int cnt = count;
2238+
2239+
if (!iregs)
2240+
iregs = &dummy_iregs;
2241+
2242+
while (cnt > 1) {
2243+
__intel_pmu_pebs_event(event, iregs, regs, data, at, setup_sample);
2244+
at += cpuc->pebs_record_size;
2245+
at = get_next_pebs_record_by_bit(at, top, bit);
2246+
cnt--;
2247+
}
2248+
2249+
__intel_pmu_pebs_last_event(event, iregs, regs, data, at, count, setup_sample);
22252250
}
22262251

22272252
static void intel_pmu_drain_pebs_core(struct pt_regs *iregs, struct perf_sample_data *data)
@@ -2258,8 +2283,8 @@ static void intel_pmu_drain_pebs_core(struct pt_regs *iregs, struct perf_sample_
22582283
return;
22592284
}
22602285

2261-
__intel_pmu_pebs_event(event, iregs, data, at, top, 0, n,
2262-
setup_pebs_fixed_sample_data);
2286+
__intel_pmu_pebs_events(event, iregs, data, at, top, 0, n,
2287+
setup_pebs_fixed_sample_data);
22632288
}
22642289

22652290
static void intel_pmu_pebs_event_update_no_drain(struct cpu_hw_events *cpuc, int size)
@@ -2390,9 +2415,9 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d
23902415
}
23912416

23922417
if (counts[bit]) {
2393-
__intel_pmu_pebs_event(event, iregs, data, base,
2394-
top, bit, counts[bit],
2395-
setup_pebs_fixed_sample_data);
2418+
__intel_pmu_pebs_events(event, iregs, data, base,
2419+
top, bit, counts[bit],
2420+
setup_pebs_fixed_sample_data);
23962421
}
23972422
}
23982423
}
@@ -2444,9 +2469,9 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_d
24442469
if (WARN_ON_ONCE(!event->attr.precise_ip))
24452470
continue;
24462471

2447-
__intel_pmu_pebs_event(event, iregs, data, base,
2448-
top, bit, counts[bit],
2449-
setup_pebs_adaptive_sample_data);
2472+
__intel_pmu_pebs_events(event, iregs, data, base,
2473+
top, bit, counts[bit],
2474+
setup_pebs_adaptive_sample_data);
24502475
}
24512476
}
24522477

0 commit comments

Comments
 (0)