mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@cam.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Russell King <rmk+lkml@arm.linux.org.uk>
Subject: Re: [patch 2/3] mutex subsystem: fastpath inlining
Date: Tue, 27 Dec 2005 16:59:20 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0512271548030.3309@localhost.localdomain> (raw)
In-Reply-To: <20051227115525.GC23587@elte.hu>

On Tue, 27 Dec 2005, Ingo Molnar wrote:

> 
> * Nicolas Pitre <nico@cam.org> wrote:
> 
> > Some architectures, notably ARM for instance, might benefit from 
> > inlining the mutex fast paths. [...]
> 
> what is the effect on text size? Could you post the before- and 
> after-patch vmlinux 'size kernel/test.o' output in the nondebug case, 
> with Arjan's latest 'convert a couple of semaphore users to mutexes' 
> patch applied? [make sure you've got enough of those users compiled in, 
> so that the inlining cost is truly measured. Perhaps also do 
> before/after 'size' output of a few affected .o files, without mixing 
> kernel/mutex.o into it, like vmlinux does.]

Theory should be convincing enough.  First of all, all the semaphore 
fast paths are always inlined currently, on all architectures I've 
looked at.  A down() fast path is always looking like this:

        mrs     ip, cpsr
        orr     lr, ip, #128
        msr     cpsr_c, lr
        ldr     lr, [r0]
        subs    lr, lr, #1
        str     lr, [r0]
        msr     cpsr_c, ip
        movmi   ip, r0
        blmi    __down_failed

So our starting point for comparison is 9 instructions for every down() 
occurence in the kernel.  Same thing for up().  Every instruction is 
invariably 4 bytes.

Now let's look at the typical mutex_lock():

        mov     r4, #0
        swp     r3, r4, [r0]
        cmp     r3, #1
        blne      __mutex_lock_noinline

This is 4 instructions.  Further more, the first "mov r4, #0" can often 
be eliminated when gcc can cse the constant 0 from another 
register.  We're talking about 3 instructions then, down from 9 !

We therefore saves between 20 and 24 bytes of kernel .text for every 
down() and every up() simply going with mutexes.

Now if the mutex_lock and mutex_unlock were not inlined, the above 3 or 
4 instructions would become one or two per call site, which is still a 
gain in space, however not as important as the one provided by the move 
from semaphores to mutexes.  It however would be more costly in terms of 
cycles since a function prologue and epilogue is somewhat costly on ARM, 
especially with frame pointer enabled (I'll let RMK elaborate on his 
reasons for not disabling them).

And for mutex_lock_interruptible(), the inlined fastpath is not bigger 
than the non-inlined one, considering that the return value has to be 
tested (the test is done twice in the non-inlined case: once inside the 
function, and once outside of it) while the inlined version needs only 
one test.  They are therefore equivalent in terms of space.


Nicolas

  reply	other threads:[~2005-12-27 21:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-23 16:16 [patch 00/11] mutex subsystem, -V7 Ingo Molnar
2005-12-24  5:15 ` Nicolas Pitre
2005-12-24  5:23   ` Nicolas Pitre
2005-12-26 19:24 ` Nicolas Pitre
2005-12-26 19:25 ` [patch 1/3] mutex subsystem: trylock Nicolas Pitre
2005-12-27 11:51   ` Ingo Molnar
2005-12-27 20:47     ` Nicolas Pitre
2005-12-28  7:48       ` Ingo Molnar
2005-12-28  8:13         ` Ingo Molnar
2005-12-28 16:29           ` Nicolas Pitre
2005-12-28 17:09             ` Ingo Molnar
2005-12-27 12:05   ` Arjan van de Ven
2005-12-27 13:15     ` Ingo Molnar
2005-12-29  4:06       ` Nicolas Pitre
2005-12-29  8:33         ` Ingo Molnar
2005-12-29  9:01           ` Nick Piggin
2005-12-29 17:15             ` Nicolas Pitre
2005-12-30  2:05               ` Nick Piggin
2005-12-29 16:46           ` Nicolas Pitre
2005-12-29  3:22     ` Nicolas Pitre
2005-12-26 19:25 ` [patch 2/3] mutex subsystem: fastpath inlining Nicolas Pitre
2005-12-27 11:55   ` Ingo Molnar
2005-12-27 21:59     ` Nicolas Pitre [this message]
2005-12-28  7:41       ` Ingo Molnar
2005-12-29  2:53         ` Nicolas Pitre
2005-12-29  8:41           ` Ingo Molnar
2006-01-06 21:20             ` Nicolas Pitre
2005-12-26 19:26 ` [patch 3/3] mutex subsystem: inline mutex_is_locked() Nicolas Pitre
2005-12-27 11:37   ` Ingo Molnar

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=Pine.LNX.4.64.0512271548030.3309@localhost.localdomain \
    --to=nico@cam.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rmk+lkml@arm.linux.org.uk \
    /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®