From: "Yan, Zheng" <zheng.z.yan@intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: mingo@elte.hu, andi@firstfloor.org, eranian@google.com,
linux-kernel@vger.kernel.org, ming.m.lin@intel.com
Subject: Re: [PATCH 2/5] perf: generic intel uncore support
Date: Tue, 17 Apr 2012 14:56:02 +0800 [thread overview]
Message-ID: <4F8D1402.80901@intel.com> (raw)
In-Reply-To: <1334578074.28150.38.camel@twins>
On 04/16/2012 08:07 PM, Peter Zijlstra wrote:
> On Sun, 2012-04-01 at 11:11 +0800, Yan, Zheng wrote:
>> Any hints how to do this. I'm afraid it requires big changes to perf core.
>
>
> Sorry for taking so long..
>
>
> I think something like the (completely untested) below should suffice..
>
> In your driver, have hotplug notifiers keep track of what cpu is the
> active cpu for your node, if it needs to change due to it going offline,
> pick a new one and use the below function to migrate the events.
>
> The only missing piece is not doing the normal
> perf_event_exit_cpu_context() thing for these PMUs, except of course
> once there's no cpus left in your node.
>
> Doing that might want an extra struct pmu method, which if not set
> defaults to perf_event_exit_cpu_context, and otherwise does your custom
> migrate/exit.
>
> ---
> kernel/events/core.c | 33 +++++++++++++++++++++++++++++++++
> 1 files changed, 33 insertions(+), 0 deletions(-)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index a6a9ec4..824becf 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -1641,6 +1641,8 @@ perf_install_in_context(struct perf_event_context *ctx,
> lockdep_assert_held(&ctx->mutex);
>
> event->ctx = ctx;
> + if (event->cpu != -1)
> + event->cpu = cpu;
>
> if (!task) {
> /*
> @@ -6375,6 +6377,8 @@ SYSCALL_DEFINE5(perf_event_open,
> mutex_lock(&ctx->mutex);
>
> if (move_group) {
> + synchronize_rcu();
> +
> perf_install_in_context(ctx, group_leader, cpu);
> get_ctx(ctx);
> list_for_each_entry(sibling, &group_leader->sibling_list,
> @@ -6477,6 +6481,35 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
> }
> EXPORT_SYMBOL_GPL(perf_event_create_kernel_counter);
>
> +void perf_pmu_migrate_context(struct pmu *pmu, int src_cpu, int dst_cpu)
> +{
> + struct perf_cpu_context *src_cpuctx = per_cpu(pmu->pmu_cpu_context, src_cpu);
> + struct perf_cpu_context *dst_cpuctx = per_cpu(pmu->pmu_cpu_context, dst_cpu);
> + struct perf_event_context *src_ctx = &src_cpuctx->ctx;
> + struct perf_event_context *dst_ctx = &dst_cpuctx->ctx;
> + struct perf_event *event, *tmp;
> + LIST_HEAD(events);
> +
> + mutex_lock(&src_ctx->mutex);
> + list_for_each_entry_safe(event, tmp, &src_ctx->event_list, event_entry) {
> + perf_remove_from_context(event);
> + put_ctx(src_ctx);
> + list_add(&event->event_entry, &events);
> + }
> + mutex_unlock(&src_ctx->mutex);
> +
> + synchronize_rcu();
> +
> + mutex_lock(&dst_ctx->mutex);
> + list_for_each_entry_safe(event, tmp, &events, event_entry) {
> + list_del(&event->event_entry);
> + perf_install_in_context(dst_ctx, event, dst_cpu);
> + get_ctx(dst_ctx);
> + }
> + mutex_unlock(&dst_ctx->mutex);
> +}
> +EXPORT_SYMBOL_GPL(perf_pmu_migrate_context);
> +
> static void sync_child_event(struct perf_event *child_event,
> struct task_struct *child)
> {
>
Thank you every much.
How about interpreting the parameter 'cpu' for perf_event_open() as target socket
instead of target cpu? So that we can get rid of raw_spin_lock in the uncore_box.
The event_init() pmu callback can do this job easily.
Regards
Yan, Zheng
next prev parent reply other threads:[~2012-04-17 6:58 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-28 6:43 [RFC PATCH 0/5] perf: Intel uncore pmu counting support Yan, Zheng
2012-03-28 6:43 ` [PATCH 1/5] perf: Export perf_assign_events Yan, Zheng
2012-03-28 6:43 ` [PATCH 2/5] perf: generic intel uncore support Yan, Zheng
2012-03-28 9:24 ` Andi Kleen
2012-03-28 9:38 ` Peter Zijlstra
2012-03-28 11:24 ` Yan, Zheng
2012-03-31 3:18 ` Peter Zijlstra
2012-04-01 3:11 ` Yan, Zheng
2012-04-02 22:10 ` Peter Zijlstra
2012-04-02 22:11 ` Peter Zijlstra
2012-04-03 8:28 ` Yan, Zheng
2012-04-03 14:29 ` Peter Zijlstra
2012-04-04 1:47 ` Yan, Zheng
2012-04-10 0:48 ` Yan, Zheng
2012-04-16 12:11 ` Peter Zijlstra
2012-04-02 22:16 ` Peter Zijlstra
2012-04-02 22:24 ` Peter Zijlstra
2012-04-16 12:07 ` Peter Zijlstra
2012-04-17 6:56 ` Yan, Zheng [this message]
2012-03-28 6:43 ` [PATCH 3/5] perf: Add Nehalem and Sandy Bridge " Yan, Zheng
2012-03-28 6:43 ` [PATCH 4/5] perf: Generic pci uncore device support Yan, Zheng
2012-03-28 6:43 ` [PATCH 5/5] perf: Add Sandy Bridge-EP uncore support Yan, Zheng
2012-03-28 6:49 ` [RFC PATCH 0/5] perf: Intel uncore pmu counting support Ingo Molnar
2012-03-28 8:49 ` Peter Zijlstra
2012-03-28 9:02 ` Yan, Zheng
2012-03-28 8:57 ` Andi Kleen
2012-03-28 9:30 ` Ingo Molnar
2012-03-28 10:58 ` Peter Zijlstra
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=4F8D1402.80901@intel.com \
--to=zheng.z.yan@intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=andi@firstfloor.org \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.m.lin@intel.com \
--cc=mingo@elte.hu \
/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;
as well as URLs for NNTP newsgroup(s).