From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Andi Kleen <ak@linux.intel.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
tglx@linutronix.de, bp@alien8.de, linux-kernel@vger.kernel.org,
eranian@google.com, alexey.budankov@linux.intel.com,
vitaly.slobodskoy@intel.com
Subject: Re: [RFC PATCH V3 2/7] perf: attach/detach PMU specific data
Date: Wed, 8 Jan 2020 14:52:10 -0500 [thread overview]
Message-ID: <78364595-78f5-f9da-1b45-a94f49f81996@linux.intel.com> (raw)
In-Reply-To: <20200108165009.GQ15478@tassilo.jf.intel.com>
On 1/8/2020 11:50 AM, Andi Kleen wrote:
>> +static int
>> +attach_system_wide_ctx_data(size_t ctx_size)
>> +{
>> + int i, num_thread, pos, nr_failed_alloc;
>> + unsigned long flags = GFP_ATOMIC;
>> + struct perf_ctx_data *tsk_data;
>> + struct perf_ctx_data **data;
>> + struct task_struct *g, *p;
>> + bool re_alloc = true;
>> +
>> + /* Retrieve total number of threads */
>> + num_thread = nr_threads;
>> +
>> + data = kcalloc(num_thread, sizeof(*data), GFP_KERNEL);
>
> This probably needs kvcalloc for reliability and avoiding stalls.
>
Yes, kvcalloc looks better.
>> + if (!data) {
>> + printk_once(KERN_DEBUG
>> + "Failed to allocate space for LBR callstack. "
>> + "The LBR callstack for all tasks may be cutoff.\n");
>> + return -ENOMEM;
>> + }
>> +
>> + atomic_inc(&nr_task_data_sys_wide_events);
>> +
>> +repeat:
>> + /*
>> + * Allocate perf_ctx_data for all existing threads.
>> + * The perf_ctx_data for new threads will be allocated in
>> + * perf_event_fork().
>> + * Do a quick allocation in first round with GFP_ATOMIC.
>> + */
>> + for (i = 0; i < num_thread; i++) {
>> + if (alloc_perf_ctx_data(ctx_size, flags, &data[i]))
>> + break;
>> + }
>> + num_thread = i;
>> + nr_failed_alloc = 0;
>> + pos = 0;
>> +
>
>> + rcu_read_lock();
>> + for_each_process_thread(g, p) {
>> + raw_spin_lock(&p->perf_ctx_data_lock);
>> + tsk_data = p->perf_ctx_data;
>> + if (tsk_data) {
>
> That will be a lot of locks even for tasks that don't use perf, but I guess we
> really need it and it's bounded by the number of tasks.
Right. We don't know which tasks will be monitored later. So we have to
attach the perf_ctx_data for all of them. The per-task lock is required
to sync the writers of perf_ctx_data RCU pointer.
Thanks,
Kan
>
>> + }
>> +
>> + if (pos < num_thread) {
>> + refcount_set(&data[pos]->refcount, TASK_DATA_SYS_WIDE);
>> + rcu_assign_pointer(p->perf_ctx_data, data[pos++]);
>> + } else {
>> + /*
>> + * The quick allocation in first round may be failed.
>> + * Track the number in nr_failed_alloc.
>> + */
>> + nr_failed_alloc++;
>> + }
>> + raw_spin_unlock(&p->perf_ctx_data_lock);
>> + }
>> + rcu_read_unlock();
>
>
> -Andi
>
next prev parent reply other threads:[~2020-01-08 19:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-08 15:03 [RFC PATCH V3 1/7] perf: Save PMU specific data in task_struct kan.liang
2020-01-08 15:03 ` [RFC PATCH V3 2/7] perf: attach/detach PMU specific data kan.liang
2020-01-08 16:50 ` Andi Kleen
2020-01-08 19:52 ` Liang, Kan [this message]
2020-01-08 15:03 ` [RFC PATCH V3 3/7] perf: Supply task information to sched_task() kan.liang
2020-01-08 15:03 ` [RFC PATCH V3 4/7] perf/x86/lbr: Fix shorter LBRs call stacks for system-wide mode kan.liang
2020-01-08 15:03 ` [RFC PATCH V3 5/7] perf/x86: Remove swap_task_ctx() kan.liang
2020-01-08 15:03 ` [RFC PATCH V3 6/7] perf: Clean up pmu specific data kan.liang
2020-01-08 15:03 ` [RFC PATCH V3 7/7] perf: Clean up event context from sched_task() kan.liang
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=78364595-78f5-f9da-1b45-a94f49f81996@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=bp@alien8.de \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=vitaly.slobodskoy@intel.com \
/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
all inboxes | Powered by JetHome®