From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Boqun Feng <boqun.feng@gmail.com>
Subject: Re: [RFC PATCH] membarrier: expedited private command
Date: Thu, 27 Jul 2017 20:31:37 +0000 (UTC) [thread overview]
Message-ID: <681315624.29102.1501187497745.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20170727195531.GE28975@worktop>
----- On Jul 27, 2017, at 3:55 PM, Peter Zijlstra peterz@infradead.org wrote:
> On Thu, Jul 27, 2017 at 02:59:43PM -0400, Mathieu Desnoyers wrote:
>> diff --git a/kernel/membarrier.c b/kernel/membarrier.c
>> index 9f9284f37f8d..8c6c0f96f617 100644
>> --- a/kernel/membarrier.c
>> +++ b/kernel/membarrier.c
>> @@ -19,10 +19,81 @@
>> #include <linux/tick.h>
>>
>> /*
>> + * XXX For cpu_rq(). Should we rather move
>> + * membarrier_private_expedited() to sched/core.c or create
>> + * sched/membarrier.c ?
>
> The later perhaps.
Allright, will do that in v2.
>
>> +static void membarrier_private_expedited(void)
>> +{
>> + int cpu, this_cpu;
>> + cpumask_var_t tmpmask;
>> +
>> + if (num_online_cpus() == 1)
>> + return;
>> +
>> + /*
>> + * Matches memory barriers around rq->curr modification in
>> + * scheduler.
>> + */
>> + smp_mb(); /* system call entry is not a mb. */
>> +
>> + if (!alloc_cpumask_var(&tmpmask, GFP_NOWAIT)) {
>
> Why GFP_NOWAIT ? and falback. There seems to be a desire to make this a
> nonblocking syscall. Should we document this somewhere?
blocking a synchronization system call due to memory allocation
pressure seemed like an unwanted effect back in 2010, so I kept
the same approach. Perhaps we could state that all the "expedited"
commands should be non-blocking ?
>
>> + /* Fallback for OOM. */
>> + membarrier_private_expedited_ipi_each();
>> + goto end;
>> + }
>> +
>> + this_cpu = raw_smp_processor_id();
>
> This is a tad dodgy, you might want to put in a comment on how migrating
> this thread is ok.
How about this ?
/*
* Skipping the current CPU is OK even through we can be
* migrated at any point. The current CPU, at the point where we
* read raw_smp_processor_id(), is ensured to be in program
* order with respect to the caller thread. Therefore, we can
* skip this CPU from the iteration.
*/
>
>> + for_each_online_cpu(cpu) {
>
> One would also need cpus_read_lock() if you rely on the online mask.
OK.
>
>> + struct task_struct *p;
>> +
>> + if (cpu == this_cpu)
>> + continue;
>> + rcu_read_lock();
>> + p = task_rcu_dereference(&cpu_rq(cpu)->curr);
>> + if (p && p->mm == current->mm)
>> + __cpumask_set_cpu(cpu, tmpmask);
>> + rcu_read_unlock();
>> + }
>> + smp_call_function_many(tmpmask, ipi_mb, NULL, 1);
>> + free_cpumask_var(tmpmask);
>> +end:
>> + /*
>> + * Memory barrier on the caller thread _after_ we finished
>> + * waiting for the last IPI. Matches memory barriers around
>> + * rq->curr modification in scheduler.
>> + */
>> + smp_mb(); /* exit from system call is not a mb */
>> +}
>
>> @@ -2737,6 +2757,7 @@ context_switch(struct rq *rq, struct task_struct *prev,
>>
>> mm = next->mm;
>> oldmm = prev->active_mm;
>> + membarrier_expedited_mb_after_set_current(mm, oldmm);
>> /*
>> * For paravirt, this is coupled with an exit in switch_to to
>> * combine the page table reload and the switch backend into
>
> As said on IRC, we have finish_task_switch()->if (mm)
> mmdrop(mm)->atomic_dec_and_test() providing a smp_mb(). We just need to
> deal with the !mm case.
Yes, I have a v2 brewing that includes this change :)
Thanks!
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2017-07-27 20:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 18:59 [RFC PATCH] membarrier: expedited private command Mathieu Desnoyers
2017-07-27 19:55 ` Peter Zijlstra
2017-07-27 20:31 ` Mathieu Desnoyers [this message]
2017-07-27 20:06 ` Paul E. McKenney
2017-07-27 20:18 ` Mathieu Desnoyers
2017-07-27 20:26 ` Paul E. McKenney
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=681315624.29102.1501187497745.JavaMail.zimbra@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--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 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.