From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932458AbbJMVrS (ORCPT ); Tue, 13 Oct 2015 17:47:18 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:62087 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932242AbbJMVqo (ORCPT ); Tue, 13 Oct 2015 17:46:44 -0400 From: Arnd Bergmann To: Peter Zijlstra Cc: Ingo Molnar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Brown , Liam Girdwood , akpm@linux-foundation.org Subject: Re: [PATCH] mutex: make mutex_lock_nested an inline function Date: Tue, 13 Oct 2015 23:46:35 +0200 Message-ID: <11817958.z9KtmeKzV7@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <20151013203812.GM17308@twins.programming.kicks-ass.net> References: <11282238.AHmyWliPRj@wuerfel> <20151013203812.GM17308@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:p4W7bQx1jurKWQfHr6UVivRip1C0L9+6EY/6PX+E8zdPoz1ulN9 qefPrMqGEld/I4jsmTb53qpAlfWpuu8lGpvEYYbsVN65upgnuIjlmoerRW7KcjBOq4oViI2 CTlXmAVHvMIATdA/gWZA769jGVbsWHuqWTAY0Ao5OGr10umQgfhKZvrmcuU3cGi/IJA7hnm 16KIvtpkClsieat6aat7w== X-UI-Out-Filterresults: notjunk:1;V01:K0:Hszfw9HntxY=:i8/YDgm/rO93DfkYl8wo3Y sSbcmrh3Nxi+8vt3QEmIVbg6I/9J63/WQSpdSXc+gCyFkvYiujZ8R7GysSE2O8/AUrGVa04Tc aMaTdECjU/nskeLIZLwD9bomKyEWCbuxK1zCl2J6tz3uyU0NfPxlJnCEUr56bm9EFF3qq6HnQ GTaS5Xpb4wD1Gxouq851ta+DhHmmEuKyG2swmk/5fEty3JpNZKZQeJjO3GlFIbrqn7fqHO7sO CraO1Kl5HOqC2aRUrKmGWve+l3H6/ny+S97z6f8yaUJpdvva+LNeqJZBeMSKpG0Yy4jM9tEMx 0UWbXh2UB0egvgHPHzqQYGlh6rqh0o8zgkeGykEDolzXWx2zxAeav/KafMXbajleLuEz3Udzl 7zYxoLmbcRop9yJrAyZi1hMqfrvaD2Jj1lCXM3pyHha2BWGnWYICh/+ytuiuub1bVJs+Y4t5j E92gdS4oK5NzxNWlbOtd+KGz0tE6rzGP8jOPHIZF8O3iiPtPLlPDHmw7fG18geO9SArQHijbd HxHTlugxOKZZuc/YzKkDGtiZXPFSoYT95yH3Qg5Ov0fRDrRHzZq3EXZ8bw+6adFCD+b8Zk9LX EZiJ/MznNBhnouXubXuENeuYB/JMzxmS2UOKgpdfiErU1ke5FMlaAOSRUOubjOlhxPKG+NhAC zc3gJmZMngXZFGnocHf7xh0F8EVPYFcr3KQysUdZ04hE9XM6Tea+NSYVy8v20PhGxnV6ztq0H eO776M9u8lCOhR8g Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 13 October 2015 22:38:12 Peter Zijlstra wrote: > On Tue, Oct 13, 2015 at 10:30:08PM +0200, Arnd Bergmann wrote: > > The second argument of the mutex_lock_nested() helper is only > > evaluated if CONFIG_DEBUG_LOCK_ALLOC is set. Otherwise we > > get this build warning for the new regulator_lock_supply > > function: > > > > drivers/regulator/core.c: In function 'regulator_lock_supply': > > drivers/regulator/core.c:142:6: warning: unused variable 'i' [-Wunused-variable] > > > > To avoid the warning, this patch changes the definition of > > mutex_lock_nested() to be static inline function rather than > > a macro, which tells gcc that the variable is potentially > > used. > > > -# define mutex_lock_nested(lock, subclass) mutex_lock(lock) > > +static inline void mutex_lock_nested(struct mutex *lock, unsigned int subclass) > > +{ > > + return mutex_lock(lock); > > +} > > Can you verify that this results in an identical kernel? > > Having this a proper argument results in the compiler having to actually > evaluate the expression resulting in @subclass, this might have side > effects and generate code. > > A quick grep shows a large amount of trivial code that optimizers will > still happily throw away, but it should be verified that this does not > result in pointless code generation. Indeed, I'm seeing a tiny code growth with ARM multi_v7_defconfig when my patch is applied, as the image (according to size -A) grows from 13740187 bytes to 13740283, all of it in .text of two drivers (i2c-core and three files of bluetooth.ko). --- build/multi_v7_defconfig-before/vmlinux.o.size 2015-10-13 23:11:40.544389776 +0200 +++ build/multi_v7_defconfig/vmlinux.o.size 2015-10-13 23:08:00.151043811 +0200 @@ -1,6 +1,6 @@ build/multi_v7_defconfig/vmlinux.o : section size addr -.text 8219408 0 +.text 8219504 0 --- build/multi_v7_defconfig-before/net/bluetooth/bluetooth.ko.size 2015-10-13 23:11:40.704382038 +0200 +++ build/multi_v7_defconfig/net/bluetooth/bluetooth.ko.size 2015-10-13 23:07:58.639116862 +0200 @@ -1,7 +1,7 @@ build/multi_v7_defconfig/net/bluetooth/bluetooth.ko : section size addr .note.gnu.build-id 36 0 -.text 241512 0 +.text 241696 0 --- build/multi_v7_defconfig-before/drivers/i2c/i2c-core.o.size 2015-10-13 23:11:40.636385326 +0200 +++ build/multi_v7_defconfig/drivers/i2c/i2c-core.o.size 2015-10-13 23:07:53.403369830 +0200 @@ -1,6 +1,6 @@ build/multi_v7_defconfig/drivers/i2c/i2c-core.o : section size addr -.text 12112 0 +.text 12208 0 The code in question is a) static ssize_t i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { ... mutex_lock_nested(&adap->userspace_clients_lock, i2c_adapter_depth(adap)); ... } and b) static inline void l2cap_chan_lock(struct l2cap_chan *chan) { mutex_lock_nested(&chan->lock, atomic_read(&chan->nesting)); } The first one has a small size impact but no performance change as it is only called during probe/release of i2c modules. The second one adds an extra pointer access (due to the volatile keyword in atomic_read()) for every caller of l2cap_chan_lock(). Arnd