Skip to content

Commit 6c7e550

Browse files
fbuihuuIngo Molnar
authored andcommitted
perf: Introduce is_sampling_event()
and use it when appropriate. Signed-off-by: Franck Bui-Huu <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 35d3778 commit 6c7e550

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

arch/x86/kernel/cpu/perf_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static int x86_setup_perfctr(struct perf_event *event)
442442
struct hw_perf_event *hwc = &event->hw;
443443
u64 config;
444444

445-
if (!hwc->sample_period) {
445+
if (!is_sampling_event(event)) {
446446
hwc->sample_period = x86_pmu.max_period;
447447
hwc->last_period = hwc->sample_period;
448448
local64_set(&hwc->period_left, hwc->sample_period);

include/linux/perf_event.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,11 @@ extern int perf_event_overflow(struct perf_event *event, int nmi,
969969
struct perf_sample_data *data,
970970
struct pt_regs *regs);
971971

972+
static inline bool is_sampling_event(struct perf_event *event)
973+
{
974+
return event->attr.sample_period != 0;
975+
}
976+
972977
/*
973978
* Return 1 for a software event, 0 for a hardware event
974979
*/

kernel/perf_event.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg)
25142514
int ret = 0;
25152515
u64 value;
25162516

2517-
if (!event->attr.sample_period)
2517+
if (!is_sampling_event(event))
25182518
return -EINVAL;
25192519

25202520
if (copy_from_user(&value, arg, sizeof(value)))
@@ -4385,7 +4385,7 @@ static void perf_swevent_event(struct perf_event *event, u64 nr,
43854385
if (!regs)
43864386
return;
43874387

4388-
if (!hwc->sample_period)
4388+
if (!is_sampling_event(event))
43894389
return;
43904390

43914391
if (nr == 1 && hwc->sample_period == 1 && !event->attr.freq)
@@ -4548,7 +4548,7 @@ static int perf_swevent_add(struct perf_event *event, int flags)
45484548
struct hw_perf_event *hwc = &event->hw;
45494549
struct hlist_head *head;
45504550

4551-
if (hwc->sample_period) {
4551+
if (is_sampling_event(event)) {
45524552
hwc->last_period = hwc->sample_period;
45534553
perf_swevent_set_period(event);
45544554
}
@@ -4920,7 +4920,7 @@ static void perf_swevent_start_hrtimer(struct perf_event *event)
49204920

49214921
hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
49224922
hwc->hrtimer.function = perf_swevent_hrtimer;
4923-
if (hwc->sample_period) {
4923+
if (is_sampling_event(event)) {
49244924
s64 period = local64_read(&hwc->period_left);
49254925

49264926
if (period) {
@@ -4941,7 +4941,7 @@ static void perf_swevent_cancel_hrtimer(struct perf_event *event)
49414941
{
49424942
struct hw_perf_event *hwc = &event->hw;
49434943

4944-
if (hwc->sample_period) {
4944+
if (is_sampling_event(event)) {
49454945
ktime_t remaining = hrtimer_get_remaining(&hwc->hrtimer);
49464946
local64_set(&hwc->period_left, ktime_to_ns(remaining));
49474947

0 commit comments

Comments
 (0)