All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
To: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	linux-kernel
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-api <linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Andy Lutomirski <luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Paul E. McKenney"
	<paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
	Boqun Feng <boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Andrew Hunter <ahh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	maged michael
	<maged.michael-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Avi Kivity <avi-VrcmuVmyx1hWk0Htik3J/w@public.gmane.org>,
	Benjamin Herrenschmidt
	<benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>,
	Paul Mackerras <paulus-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>,
	Michael Ellerman <mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org>,
	Dave Watson <davejwatson-b10kYP2dOMg@public.gmane.org>,
	"H. Peter Anvin" <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>,
	Andrea Parri
	<parri.andrea-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"Russell King,
	ARM Linux" <linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org>,
	Greg Hackmann <ghackmann-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>,
	David
Subject: Re: [PATCH for 4.16 04/10] membarrier: provide SHARED_EXPEDITED command (v2)
Date: Tue, 16 Jan 2018 19:02:25 +0000 (UTC)	[thread overview]
Message-ID: <1577189631.3966.1516129345161.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1801161915090.2366@nanos>

----- On Jan 16, 2018, at 1:20 PM, Thomas Gleixner tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org wrote:

> On Mon, 15 Jan 2018, Mathieu Desnoyers wrote:
>> +static int membarrier_shared_expedited(void)
>> +{
>> +	int cpu;
>> +	bool fallback = false;
>> +	cpumask_var_t tmpmask;
>> +
>> +	if (num_online_cpus() == 1)
>> +		return 0;
>> +
>> +	/*
>> +	 * Matches memory barriers around rq->curr modification in
>> +	 * scheduler.
>> +	 */
>> +	smp_mb();	/* system call entry is not a mb. */
>> +
>> +	/*
>> +	 * Expedited membarrier commands guarantee that they won't
>> +	 * block, hence the GFP_NOWAIT allocation flag and fallback
>> +	 * implementation.
>> +	 */
>> +	if (!zalloc_cpumask_var(&tmpmask, GFP_NOWAIT)) {
>> +		/* Fallback for OOM. */
>> +		fallback = true;
>> +	}
>> +
>> +	cpus_read_lock();
>> +	for_each_online_cpu(cpu) {
>> +		struct task_struct *p;
>> +
>> +		/*
>> +		 * 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.
>> +		 */
>> +		if (cpu == raw_smp_processor_id())
>> +			continue;
>> +		rcu_read_lock();
>> +		p = task_rcu_dereference(&cpu_rq(cpu)->curr);
>> +		if (p && p->mm && (atomic_read(&p->mm->membarrier_state) &
>> +				   MEMBARRIER_STATE_SHARED_EXPEDITED)) {
> 
> This does not make sense vs. the documentation:
> 
>> + * @MEMBARRIER_CMD_SHARED_EXPEDITED:
>> + *                          Execute a memory barrier on all running threads
>> + *                          part of a process which previously registered
>> + *                          with MEMBARRIER_CMD_REGISTER_SHARED_EXPEDITED.
> 
> This should say:
> 
>> + *                          Execute a memory barrier on all running threads
>> + *                          of all processes which previously registered
>> + *                          with MEMBARRIER_CMD_REGISTER_SHARED_EXPEDITED.

Good point, will fix.

> 
> And I really have to ask whether this should be named _GLOBAL_ instead of
> _SHARED_.
> 
> Hmm?

I agree with you that this behavior fits better a "global" definition
than a "shared" one, especially given that it does not target a specific
shared memory mapping. The main issue I have is due to the pre-existing
MEMBARRIER_CMD_SHARED introduced in Linux 4.3. That one should also have
been called "MEMBARRIER_CMD_GLOBAL" based on the current line of thoughts.

Do you envision a way to transition forward to a new "MEMBARRIER_CMD_GLOBAL" for
the currently existing MEMBARRIER_CMD_SHARED ?

Perhaps with a duplicated enum entry ?

enum membarrier_cmd {
        MEMBARRIER_CMD_QUERY                                    = 0,
        MEMBARRIER_CMD_SHARED                                   = (1 << 0), /* use MEMBARRIER_CMD_GLOBAL instead */
        MEMBARRIER_CMD_GLOBAL                                   = (1 << 0),
[...]
};

Thanks,

Mathieu

> 
> Thanks,
> 
> 	tglx

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

WARNING: multiple messages have this Message-ID (diff)
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-api <linux-api@vger.kernel.org>,
	Andy Lutomirski <luto@kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Boqun Feng <boqun.feng@gmail.com>, Andrew Hunter <ahh@google.com>,
	maged michael <maged.michael@gmail.com>,
	Avi Kivity <avi@scylladb.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Dave Watson <davejwatson@fb.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andrea Parri <parri.andrea@gmail.com>,
	"Russell King, ARM Linux" <linux@armlinux.org.uk>,
	Greg Hackmann <ghackmann@google.com>,
	Will Deacon <will.deacon@arm.com>, David Sehr <sehr@google.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86 <x86@kernel.org>
Subject: Re: [PATCH for 4.16 04/10] membarrier: provide SHARED_EXPEDITED command (v2)
Date: Tue, 16 Jan 2018 19:02:25 +0000 (UTC)	[thread overview]
Message-ID: <1577189631.3966.1516129345161.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1801161915090.2366@nanos>

----- On Jan 16, 2018, at 1:20 PM, Thomas Gleixner tglx@linutronix.de wrote:

> On Mon, 15 Jan 2018, Mathieu Desnoyers wrote:
>> +static int membarrier_shared_expedited(void)
>> +{
>> +	int cpu;
>> +	bool fallback = false;
>> +	cpumask_var_t tmpmask;
>> +
>> +	if (num_online_cpus() == 1)
>> +		return 0;
>> +
>> +	/*
>> +	 * Matches memory barriers around rq->curr modification in
>> +	 * scheduler.
>> +	 */
>> +	smp_mb();	/* system call entry is not a mb. */
>> +
>> +	/*
>> +	 * Expedited membarrier commands guarantee that they won't
>> +	 * block, hence the GFP_NOWAIT allocation flag and fallback
>> +	 * implementation.
>> +	 */
>> +	if (!zalloc_cpumask_var(&tmpmask, GFP_NOWAIT)) {
>> +		/* Fallback for OOM. */
>> +		fallback = true;
>> +	}
>> +
>> +	cpus_read_lock();
>> +	for_each_online_cpu(cpu) {
>> +		struct task_struct *p;
>> +
>> +		/*
>> +		 * 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.
>> +		 */
>> +		if (cpu == raw_smp_processor_id())
>> +			continue;
>> +		rcu_read_lock();
>> +		p = task_rcu_dereference(&cpu_rq(cpu)->curr);
>> +		if (p && p->mm && (atomic_read(&p->mm->membarrier_state) &
>> +				   MEMBARRIER_STATE_SHARED_EXPEDITED)) {
> 
> This does not make sense vs. the documentation:
> 
>> + * @MEMBARRIER_CMD_SHARED_EXPEDITED:
>> + *                          Execute a memory barrier on all running threads
>> + *                          part of a process which previously registered
>> + *                          with MEMBARRIER_CMD_REGISTER_SHARED_EXPEDITED.
> 
> This should say:
> 
>> + *                          Execute a memory barrier on all running threads
>> + *                          of all processes which previously registered
>> + *                          with MEMBARRIER_CMD_REGISTER_SHARED_EXPEDITED.

Good point, will fix.

> 
> And I really have to ask whether this should be named _GLOBAL_ instead of
> _SHARED_.
> 
> Hmm?

I agree with you that this behavior fits better a "global" definition
than a "shared" one, especially given that it does not target a specific
shared memory mapping. The main issue I have is due to the pre-existing
MEMBARRIER_CMD_SHARED introduced in Linux 4.3. That one should also have
been called "MEMBARRIER_CMD_GLOBAL" based on the current line of thoughts.

Do you envision a way to transition forward to a new "MEMBARRIER_CMD_GLOBAL" for
the currently existing MEMBARRIER_CMD_SHARED ?

Perhaps with a duplicated enum entry ?

enum membarrier_cmd {
        MEMBARRIER_CMD_QUERY                                    = 0,
        MEMBARRIER_CMD_SHARED                                   = (1 << 0), /* use MEMBARRIER_CMD_GLOBAL instead */
        MEMBARRIER_CMD_GLOBAL                                   = (1 << 0),
[...]
};

Thanks,

Mathieu

> 
> Thanks,
> 
> 	tglx

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2018-01-16 19:02 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15 19:10 [PATCH for 4.16 00/10] membarrier updates for 4.16 Mathieu Desnoyers
2018-01-15 19:10 ` Mathieu Desnoyers
2018-01-15 19:10 ` [PATCH for 4.16 01/10] membarrier: selftest: Test private expedited cmd (v2) Mathieu Desnoyers
2018-01-15 19:10   ` [Linux-kselftest-mirror] " Mathieu Desnoyers
2018-01-15 19:10   ` mathieu.desnoyers
2018-01-15 19:10   ` Mathieu Desnoyers
2018-01-15 19:10 ` [PATCH for 4.16 02/10] powerpc: membarrier: Skip memory barrier in switch_mm() (v7) Mathieu Desnoyers
2018-01-15 19:10   ` Mathieu Desnoyers
2018-01-15 19:10 ` [PATCH for 4.16 03/10] membarrier: Document scheduler barrier requirements (v5) Mathieu Desnoyers
2018-01-15 19:10   ` Mathieu Desnoyers
2018-01-15 19:10 ` [PATCH for 4.16 04/10] membarrier: provide SHARED_EXPEDITED command (v2) Mathieu Desnoyers
2018-01-15 19:10   ` Mathieu Desnoyers
2018-01-16 18:20   ` Thomas Gleixner
2018-01-16 18:20     ` Thomas Gleixner
2018-01-16 19:02     ` Mathieu Desnoyers [this message]
2018-01-16 19:02       ` Mathieu Desnoyers
     [not found]       ` <1577189631.3966.1516129345161.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2018-01-16 19:04         ` Thomas Gleixner
2018-01-16 19:04           ` Thomas Gleixner
     [not found] ` <20180115191104.12437-1-mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2018-01-15 19:10   ` [PATCH for 4.16 05/10] membarrier: selftest: Test shared expedited cmd Mathieu Desnoyers
2018-01-15 19:10     ` [Linux-kselftest-mirror] " Mathieu Desnoyers
2018-01-15 19:10     ` mathieu.desnoyers
2018-01-15 19:10     ` Mathieu Desnoyers
2018-01-15 19:11   ` [PATCH for 4.16 07/10] x86: Introduce sync_core_before_usermode (v2) Mathieu Desnoyers
2018-01-15 19:11     ` Mathieu Desnoyers
2018-01-16 18:28     ` Thomas Gleixner
2018-01-16 18:28       ` Thomas Gleixner
2018-01-15 19:11 ` [PATCH for 4.16 06/10] membarrier: Provide core serializing command Mathieu Desnoyers
2018-01-15 19:11   ` Mathieu Desnoyers
2018-01-15 19:11 ` [PATCH for 4.16 08/10] membarrier: x86: Provide core serializing command (v3) Mathieu Desnoyers
2018-01-15 19:11   ` Mathieu Desnoyers
2018-01-16 18:29   ` Thomas Gleixner
2018-01-16 18:29     ` Thomas Gleixner
2018-01-16 19:22     ` Mathieu Desnoyers
2018-01-16 19:22       ` Mathieu Desnoyers
2018-01-16 20:41       ` Mathieu Desnoyers
2018-01-16 20:41         ` Mathieu Desnoyers
2018-01-15 19:11 ` [PATCH for 4.16 09/10] membarrier: arm64: Provide core serializing command Mathieu Desnoyers
2018-01-15 19:11   ` Mathieu Desnoyers
2018-01-15 19:11 ` [PATCH for 4.16 10/10] membarrier: selftest: Test private expedited sync core cmd Mathieu Desnoyers
2018-01-15 19:11   ` [Linux-kselftest-mirror] " Mathieu Desnoyers
2018-01-15 19:11   ` mathieu.desnoyers
2018-01-15 19:11   ` Mathieu Desnoyers

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=1577189631.3966.1516129345161.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers-vg+e7yoek/dwk0htik3j/w@public.gmane.org \
    --cc=ahh-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=avi-VrcmuVmyx1hWk0Htik3J/w@public.gmane.org \
    --cc=benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org \
    --cc=boqun.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=davejwatson-b10kYP2dOMg@public.gmane.org \
    --cc=ghackmann-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
    --cc=linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=maged.michael-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org \
    --cc=parri.andrea-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    --cc=paulus-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org \
    --cc=peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.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.