From: David Carrillo-Cisneros <davidcc@google.com>
To: linux-kernel@vger.kernel.org
Cc: "x86@kernel.org" <x86@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Andi Kleen <ak@linux.intel.com>, Kan Liang <kan.liang@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Borislav Petkov <bp@suse.de>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Vikas Shivappa <vikas.shivappa@linux.intel.com>,
Mark Rutland <mark.rutland@arm.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Vince Weaver <vince@deater.net>, Paul Turner <pjt@google.com>,
Stephane Eranian <eranian@google.com>,
David Carrillo-Cisneros <davidcc@google.com>
Subject: [RFC 6/6] perf/core: use rb-tree index to optimize filtered perf_iterate_ctx
Date: Tue, 10 Jan 2017 02:25:02 -0800 [thread overview]
Message-ID: <20170110102502.106187-7-davidcc@google.com> (raw)
In-Reply-To: <20170110102502.106187-1-davidcc@google.com>
A version of perf_iterate_ctx uses event_filter_match. Replace it with
the rb-tree.
Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
---
kernel/events/core.c | 64 ++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 47 insertions(+), 17 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f5d9c13b485f..0b31c57afe77 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6397,22 +6397,53 @@ typedef void (perf_iterate_f)(struct perf_event *event, void *data);
static void
perf_iterate_ctx(struct perf_event_context *ctx,
perf_iterate_f output,
- void *data, bool all)
+ void *data)
{
struct perf_event *event;
- list_for_each_entry_rcu(event, &ctx->event_list, event_entry) {
- if (!all) {
- if (event->state < PERF_EVENT_STATE_INACTIVE)
- continue;
- if (!event_filter_match(event))
- continue;
- }
+ list_for_each_entry_rcu(event, &ctx->event_list, event_entry)
+ output(event, data);
+}
+static void
+perf_iterate_group(struct perf_event *group, perf_iterate_f output, void *data)
+{
+ struct perf_event *event;
+
+ output(group, data);
+ list_for_each_entry(event, &group->sibling_list, group_entry)
output(event, data);
- }
}
+static void
+perf_iterate_ctx_matching(struct perf_event_context *ctx,
+ struct perf_cpu_context *cpuctx,
+ perf_iterate_f output,
+ void *data)
+{
+ struct perf_event *event, *tmp;
+ u32 stamp_max;
+
+ /* This lists are not RCU safe. Need to find is this is true or if we can work around it */
+ lockdep_assert_held(&ctx->lock);
+ /* Active events have already passed event_filter_match. */
+ list_for_each_entry(event, &ctx->active_pinned_groups, ctx_active_entry)
+ perf_iterate_group(event, output, data);
+
+ list_for_each_entry(event, &ctx->active_flexible_groups, ctx_active_entry)
+ perf_iterate_group(event, output, data);
+
+ event = NULL;
+ ctx_inactive_groups_interval(ctx, cpuctx, EVENT_PINNED | EVENT_FLEXIBLE,
+ &event, &stamp_max);
+
+ list_for_each_entry_safe_from(
+ event, tmp, &ctx->inactive_groups, ctx_active_entry) {
+ if (event_filter_match(event))
+ perf_iterate_group(event, output, data);
+ }
+};
+
static void perf_iterate_sb_cpu(perf_iterate_f output, void *data)
{
struct pmu_event_list *pel = this_cpu_ptr(&pmu_sb_events);
@@ -6457,7 +6488,7 @@ perf_iterate_sb(perf_iterate_f output, void *data,
* context.
*/
if (task_ctx) {
- perf_iterate_ctx(task_ctx, output, data, false);
+ perf_iterate_ctx_matching(task_ctx, NULL, output, data);
goto done;
}
@@ -6466,7 +6497,7 @@ perf_iterate_sb(perf_iterate_f output, void *data,
for_each_task_context_nr(ctxn) {
ctx = rcu_dereference(current->perf_event_ctxp[ctxn]);
if (ctx)
- perf_iterate_ctx(ctx, output, data, false);
+ perf_iterate_ctx_matching(ctx, NULL, output, data);
}
done:
preempt_enable();
@@ -6518,8 +6549,7 @@ void perf_event_exec(void)
perf_event_enable_on_exec(ctxn);
- perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL,
- true);
+ perf_iterate_ctx(ctx, perf_event_addr_filters_exec, NULL);
}
rcu_read_unlock();
}
@@ -6568,10 +6598,10 @@ static int __perf_pmu_output_stop(void *info)
};
rcu_read_lock();
- perf_iterate_ctx(&cpuctx->ctx, __perf_event_output_stop, &ro, false);
+ perf_iterate_ctx_matching(&cpuctx->ctx, cpuctx, __perf_event_output_stop, &ro);
if (cpuctx->task_ctx)
- perf_iterate_ctx(cpuctx->task_ctx, __perf_event_output_stop,
- &ro, false);
+ perf_iterate_ctx_matching(cpuctx->task_ctx, NULL, __perf_event_output_stop,
+ &ro);
rcu_read_unlock();
return ro.err;
@@ -7090,7 +7120,7 @@ static void perf_addr_filters_adjust(struct vm_area_struct *vma)
if (!ctx)
continue;
- perf_iterate_ctx(ctx, __perf_addr_filters_adjust, vma, true);
+ perf_iterate_ctx(ctx, __perf_addr_filters_adjust, vma);
}
rcu_read_unlock();
}
--
2.11.0.390.gc69c2f50cf-goog
next prev parent reply other threads:[~2017-01-10 10:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 10:24 [RFC 0/6] optimize ctx switch with rb-tree David Carrillo-Cisneros
2017-01-10 10:24 ` [RFC 1/6] perf/core: create active and inactive event groups David Carrillo-Cisneros
2017-01-10 13:49 ` Mark Rutland
2017-01-10 20:45 ` David Carrillo-Cisneros
2017-01-12 11:05 ` Mark Rutland
[not found] ` <CALcN6mhPmpSqKhE3Ua+j-xROLzeAyrgdCk4AGGtfF9kExXRTJg@mail.gmail.com>
2017-01-13 11:01 ` Mark Rutland
2017-01-10 10:24 ` [RFC 2/6] perf/core: add a rb-tree index to inactive_groups David Carrillo-Cisneros
2017-01-10 14:14 ` Mark Rutland
2017-01-10 20:20 ` David Carrillo-Cisneros
2017-01-12 11:47 ` Mark Rutland
2017-01-13 7:34 ` David Carrillo-Cisneros
2017-01-16 2:03 ` [lkp-developer] [perf/core] 33da94bd89: BUG:unable_to_handle_kernel kernel test robot
2017-01-16 2:03 ` kernel test robot
2017-01-10 10:24 ` [RFC 3/6] perf/core: use rb-tree to sched in event groups David Carrillo-Cisneros
2017-01-10 16:38 ` Mark Rutland
2017-01-10 20:51 ` David Carrillo-Cisneros
2017-01-12 12:14 ` Mark Rutland
2017-01-13 8:01 ` David Carrillo-Cisneros
2017-01-13 10:24 ` Mark Rutland
2017-01-11 20:31 ` Liang, Kan
2017-01-12 10:11 ` Mark Rutland
2017-01-12 13:28 ` Liang, Kan
2017-01-13 8:05 ` David Carrillo-Cisneros
2017-01-10 10:25 ` [RFC 4/6] perf/core: avoid rb-tree traversal when no inactive events David Carrillo-Cisneros
2017-01-10 10:25 ` [RFC 5/6] perf/core: rotation no longer necessary. Behavior has changed. Beware David Carrillo-Cisneros
2017-01-10 10:25 ` David Carrillo-Cisneros [this message]
2017-01-16 2:05 ` [lkp-developer] [perf/core] 49c04ee1a7: WARNING:at_kernel/events/core.c:#perf_iterate_ctx_matching kernel test robot
2017-01-16 2:05 ` kernel test robot
2017-04-25 17:27 ` [RFC 0/6] optimize ctx switch with rb-tree Liang, Kan
2017-04-25 17:49 ` David Carrillo-Cisneros
2017-04-25 18:11 ` Budankov, Alexey
2017-04-25 18:54 ` David Carrillo-Cisneros
2017-04-26 10:34 ` Budankov, Alexey
2017-04-26 19:40 ` David Carrillo-Cisneros
2017-04-26 10:52 ` Mark Rutland
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=20170110102502.106187-7-davidcc@google.com \
--to=davidcc@google.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=bp@suse.de \
--cc=dave.hansen@linux.intel.com \
--cc=eranian@google.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=tglx@linutronix.de \
--cc=vikas.shivappa@linux.intel.com \
--cc=vince@deater.net \
--cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.