From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753859AbbDNTfp (ORCPT ); Tue, 14 Apr 2015 15:35:45 -0400 Received: from www.linutronix.de ([62.245.132.108]:37610 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751761AbbDNTfg (ORCPT ); Tue, 14 Apr 2015 15:35:36 -0400 Date: Tue, 14 Apr 2015 21:35:57 +0200 (CEST) From: Thomas Gleixner To: Mathieu Desnoyers cc: Andrew Morton , linux-kernel@vger.kernel.org, Josh Triplett , KOSAKI Motohiro , Steven Rostedt , Nicholas Miell , Linus Torvalds , Ingo Molnar , Alan Cox , Lai Jiangshan , Stephen Hemminger , Peter Zijlstra , David Howells Subject: Re: [PATCH v14 for 4.1] sys_membarrier(): system-wide memory barrier (x86) In-Reply-To: <191985313.30287.1429039372434.JavaMail.zimbra@efficios.com> Message-ID: References: <1428952229-3577-1-git-send-email-mathieu.desnoyers@efficios.com> <76701995.30245.1429038138581.JavaMail.zimbra@efficios.com> <191985313.30287.1429039372434.JavaMail.zimbra@efficios.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Apr 2015, Mathieu Desnoyers wrote: > Thinking about it a bit more, one reason for doing the QUERY along > with the exact set of flags queried allow us to do more than just > returning which flags are supported: it allows us to tell userspace > whether the combination of flags used is valid or not. > > For instance, if we add a MEMBARRIER_PRIVATE flag in a future release > to issue memory barriers only to other threads from the same process, > and we add a MEMBARRIER_EXPEDITED which uses IPIs to issue those > barriers, we could very well have a situation where using > > EXPEDITED | PRIVATE would be valid (only sending IPIs to CPUs > running threads from the same process) > > but > > EXPEDITED alone would be invalid (-EINVAL), until we figure out > how to expedite memory barriers to all processors without impacting > other processes, if at all possible. > > Using QUERY with an empty set of flags could however return the set of > flags supported, which could be a nice feature. Anyway, I think > the "0" flag should be the basic always correct configuration that > is always supported, otherwise we'd have -ENOSYS. Therefore, querying > whether the empty set of flags is supported has little value, other > than checking for -ENOSYS. > > So considering the above, the typical use of this query method from > library initialization would be: > > int supported_flags = sys_membarrier(MEMBARRIER_QUERY); > > ... check for -ENOSYS .... > ... check whether the flags we need are supported ... > > if (sys_membarrier(MEMBARRIER_QUERY | flag1 | flag2)) > goto error; > > then we are guaranteed that using sys_membarrier(flag1 | flag2) > will always succeed within the application, without needing to > handle errors every time it is used. This property is useful > to implement a synchronize_rcu() that returns "void" and simplify > error handling within the application. So how many of these "flags" are you planning to implement and how many valid combinations are going to exist? I doubt it's more than a dozen. So I prefer explicit operation modes for the valid ones rather than having a random pile of "flags". Thanks, tglx