From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org
Cc: Kan Liang <kan.liang@linux.intel.com>,
Stephane Eranian <eranian@google.com>,
Ian Rogers <irogers@google.com>
Subject: [PATCH 6/7] perf: avoid double checking CPU and cgroup
Date: Mon, 1 Jul 2019 23:59:54 -0700 [thread overview]
Message-ID: <20190702065955.165738-7-irogers@google.com> (raw)
In-Reply-To: <20190702065955.165738-1-irogers@google.com>
When ctx_groups_sched_in iterates the CPU and cgroup of events is known
to match the current task. Avoid double checking this with
event_filter_match by passing in an additional argument.
Signed-off-by: Ian Rogers <irogers@google.com>
---
kernel/events/core.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 7608bd562dac..a66477ee196a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2079,10 +2079,12 @@ static inline int pmu_filter_match(struct perf_event *event)
}
static inline int
-event_filter_match(struct perf_event *event)
+event_filter_match(struct perf_event *event, bool check_cgroup_and_cpu)
{
- return (event->cpu == -1 || event->cpu == smp_processor_id()) &&
- perf_cgroup_match(event) && pmu_filter_match(event);
+ return (!check_cgroup_and_cpu ||
+ ((event->cpu == -1 || event->cpu == smp_processor_id()) &&
+ perf_cgroup_match(event))) &&
+ pmu_filter_match(event);
}
static void
@@ -2797,7 +2799,7 @@ static void __perf_event_enable(struct perf_event *event,
if (!ctx->is_active)
return;
- if (!event_filter_match(event)) {
+ if (!event_filter_match(event, /*check_cpu_and_cgroup=*/true)) {
ctx_sched_in(ctx, cpuctx, EVENT_TIME, current);
return;
}
@@ -3573,7 +3575,10 @@ static int pinned_sched_in(struct perf_event_context *ctx,
if (event->state <= PERF_EVENT_STATE_OFF)
return 0;
- if (!event_filter_match(event))
+ /* The caller already checked the CPU and cgroup before calling
+ * pinned_sched_in.
+ */
+ if (!event_filter_match(event, /*check_cpu_and_cgroup=*/false))
return 0;
if (group_can_go_on(event, cpuctx, 1)) {
@@ -3599,7 +3604,10 @@ static int flexible_sched_in(struct perf_event_context *ctx,
if (event->state <= PERF_EVENT_STATE_OFF)
return 0;
- if (!event_filter_match(event))
+ /* The caller already checked the CPU and cgroup before calling
+ * felxible_sched_in.
+ */
+ if (!event_filter_match(event, /*check_cpu_and_cgroup=*/false))
return 0;
if (group_can_go_on(event, cpuctx, *can_add_hw)) {
@@ -3899,7 +3907,7 @@ static void perf_adjust_freq_unthr_context(struct perf_event_context *ctx,
if (event->state != PERF_EVENT_STATE_ACTIVE)
continue;
- if (!event_filter_match(event))
+ if (!event_filter_match(event, /*check_cpu_and_cgroup=*/true))
continue;
perf_pmu_disable(event->pmu);
@@ -6929,7 +6937,8 @@ perf_iterate_ctx(struct perf_event_context *ctx,
if (!all) {
if (event->state < PERF_EVENT_STATE_INACTIVE)
continue;
- if (!event_filter_match(event))
+ if (!event_filter_match(event,
+ /*check_cpu_and_cgroup=*/true))
continue;
}
@@ -6953,7 +6962,7 @@ static void perf_iterate_sb_cpu(perf_iterate_f output, void *data)
if (event->state < PERF_EVENT_STATE_INACTIVE)
continue;
- if (!event_filter_match(event))
+ if (!event_filter_match(event, /*check_cpu_and_cgroup=*/true))
continue;
output(event, data);
}
--
2.22.0.410.gd8fdbe21b5-goog
next prev parent reply other threads:[~2019-07-02 7:00 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-02 6:59 [PATCH 0/7] Optimize cgroup context switch Ian Rogers
2019-07-02 6:59 ` [PATCH 1/7] perf: propagate perf_install_in_context errors up Ian Rogers
2019-07-05 14:13 ` Jiri Olsa
2019-07-02 6:59 ` [PATCH 2/7] perf/cgroup: order events in RB tree by cgroup id Ian Rogers
2019-07-08 15:38 ` Peter Zijlstra
2019-07-08 15:45 ` Peter Zijlstra
2019-07-08 16:16 ` Peter Zijlstra
2019-07-24 22:34 ` Ian Rogers
2019-07-08 16:21 ` Peter Zijlstra
2019-07-02 6:59 ` [PATCH 3/7] perf: order iterators for visit_groups_merge into a min-heap Ian Rogers
2019-07-08 16:30 ` Peter Zijlstra
2019-07-24 22:34 ` Ian Rogers
2019-07-08 16:36 ` Peter Zijlstra
2019-07-02 6:59 ` [PATCH 4/7] perf: avoid a bounded set of visit_groups_merge iterators Ian Rogers
2019-07-02 6:59 ` [PATCH 5/7] perf: cache perf_event_groups_first for cgroups Ian Rogers
2019-07-08 16:50 ` Peter Zijlstra
2019-07-08 16:51 ` Peter Zijlstra
2019-07-02 6:59 ` Ian Rogers [this message]
2019-07-02 6:59 ` [PATCH 7/7] perf: rename visit_groups_merge to ctx_groups_sched_in Ian Rogers
2019-07-24 22:37 ` [PATCH v2 0/7] Optimize cgroup context switch Ian Rogers
2019-07-24 22:37 ` [PATCH v2 1/7] perf: propagate perf_install_in_context errors up Ian Rogers
2019-07-24 22:37 ` [PATCH v2 2/7] perf/cgroup: order events in RB tree by cgroup id Ian Rogers
2020-03-06 14:42 ` [tip: perf/core] perf/cgroup: Order " tip-bot2 for Ian Rogers
2019-07-24 22:37 ` [PATCH v2 3/7] perf: order iterators for visit_groups_merge into a min-heap Ian Rogers
2019-07-24 22:37 ` [PATCH v2 4/7] perf: avoid a bounded set of visit_groups_merge iterators Ian Rogers
2019-08-07 21:11 ` Peter Zijlstra
2019-07-24 22:37 ` [PATCH v2 5/7] perf: cache perf_event_groups_first for cgroups Ian Rogers
2019-07-24 22:37 ` [PATCH v2 6/7] perf: avoid double checking CPU and cgroup Ian Rogers
2019-07-24 22:37 ` [PATCH v2 7/7] perf: rename visit_groups_merge to ctx_groups_sched_in Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190702065955.165738-7-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox