mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "D.W.Howells" <dhowells@astarte.free-online.co.uk>
To: andrea@suse.de
Cc: linux-kernel@vger.kernel.org, dhowells@redhat.com,
	torvalds@transmeta.com
Subject: Re: generic rwsem [Re: Alpha "process table hang"]
Date: Tue, 17 Apr 2001 22:48:02 +0100	[thread overview]
Message-ID: <01041722480200.05613@orion.ddi.co.uk> (raw)


> I am sure ppc couldn't race (at least unless up_read/up_write were excuted 
> from irq/softnet context and that never happens in 2.4.4pre3, see below ;). 

This is not actually using the rwsem code I wrote at the moment.

> And incidentally the above is what (I guess Richard) did on the alpha and
> that should really go into common code instead of having
> asm-i386/rwsem-xadd.h asm-alpha/rwsem.h etcc.etc... just implement
> atomic_inc_return using xadd in asm-i386/atomic.h, that's much better
> design IMHO. 

I disagree... you want such primitives to be as efficient as possible. The 
whole point of having asm/xxxx.h files is that you can stuff them full of 
dirty tricks specific to certain architectures.

> That can obviously be done for example with C code like this: 
>        count = atomic_inc_return(&sem->count); 
>        if (__builtin_expect(count == 0, 0)) 
>                slow_path() 
>
> The above is the perfect C implementation IMHO

But not so efficient since it _has_ to take a jump unless the compiler can 
emit code in alternative text sections when it seems appropriate. Plus, you 
have to test count's value. XADD sets EFLAGS based on the result in memory, 
something that allows all but one fastpath to be two instructions in length 
(the one that isn't is three).

But, yes, there should probably be two generic cases: one implemented with a 
spinlock in the rwsem struct (as I supply) and one implemented using 
atomic_add_return(). Note, however! atomic_add_return() is not necessarily 
implemented efficiently: if it involves a cmpxchg loop (as many seem to), 
then that is really quite inefficient, and may be better done as a spinlock 
anyway.

I've had a look at your implementation... It seems to hold the spinlocks for 
an awfully long time... specifically around the local variable initialisation 
in the 'failed' functions. Don't forget that the compiler can't reorder these 
because they're inside the spinlock. I would, if I were you, fold the 
'failed' functions into the main ones to avoid this problem.

Your rw_semaphore structure is also rather large: 46 bytes without debugging 
stuff (16 bytes apiece for the waitqueues and 12 bytes for the rest). 
Contrast that with mine: generic is 24 bytes and the i386-xadd optimised is 
20.

Admittedly, though, yours is extremely simple and easy to follow, but I don't 
think it's going to be very fast.

Of course, I still prefer mine... smaller, faster, more efficient:-)

David

             reply	other threads:[~2001-04-17 21:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-17 21:48 D.W.Howells [this message]
2001-04-17 23:06 ` Andrea Arcangeli
  -- strict thread matches above, loose matches on Subject: below --
2001-04-17 23:54 D.W.Howells
2001-04-18 20:49 ` Andrea Arcangeli
2001-04-17 19:18 D.W.Howells
2001-04-17 20:49 ` Andrea Arcangeli
2001-04-17 21:29   ` Christoph Hellwig
2001-04-17 22:06     ` Andrea Arcangeli
2001-04-11 17:57 Alpha "process table hang" Bob McElrath
     [not found] ` <E14nOzo-0007Ew-00@the-village.bc.nu>
2001-04-13 13:48   ` Bob McElrath
2001-04-17 15:07     ` generic rwsem [Re: Alpha "process table hang"] Andrea Arcangeli
2001-04-17 15:28       ` Bob McElrath
2001-04-19 16:21         ` Bob McElrath
2001-04-19 17:17           ` Andrea Arcangeli
2001-04-23 23:27             ` Bob McElrath
2001-04-23 23:40               ` Andrea Arcangeli
2001-04-17 15:45       ` Christoph Hellwig
2001-04-17 16:59       ` David Howells
2001-04-17 17:55         ` Andrea Arcangeli

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=01041722480200.05613@orion.ddi.co.uk \
    --to=dhowells@astarte.free-online.co.uk \
    --cc=andrea@suse.de \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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®