* [KJ] using "mutexes" in place of semaphores
@ 2007-02-17 12:48 Robert P. J. Day
2007-02-17 13:56 ` Arnd Bergmann
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Robert P. J. Day @ 2007-02-17 12:48 UTC (permalink / raw)
To: kernel-janitors
another possible aesthetic cleanup is to replace the use of general
semaphores that are initialized to 1 with the simpler reference to an
actual "mutex" (since, after all, that's what mutexes are there for).
there's a small number of semaphore initializations of the form
"sema_init(&sem, 1)" that could be rewritten as the simpler
"init_MUTEX(&sem)". in some places, the name of the semaphore itself
makes it clear that it's a mutex anyway, such as:
drivers/scsi/megaraid/megaraid_sas.c: sema_init(&instance->aen_mutex, 1);
a quick count shows that there's only a couple dozen instances of
calling sema_init() with a count of 1, while there are many more calls
of init_MUTEX() in the tree, suggesting that init_MUTEX() really is
the preferred standard.
thoughts? is this worth it?
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [KJ] using "mutexes" in place of semaphores
2007-02-17 12:48 [KJ] using "mutexes" in place of semaphores Robert P. J. Day
@ 2007-02-17 13:56 ` Arnd Bergmann
2007-02-17 13:58 ` Robert P. J. Day
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2007-02-17 13:56 UTC (permalink / raw)
To: kernel-janitors
On Saturday 17 February 2007 13:48, Robert P. J. Day wrote:
> a quick count shows that there's only a couple dozen instances of
> calling sema_init() with a count of 1, while there are many more calls
> of init_MUTEX() in the tree, suggesting that init_MUTEX() really is
> the preferred standard.
>
> thoughts? is this worth it?
I guess you missed the important point here, which is that we're also
trying to get rid of the usage of a struct semaphore as a mutex.
Basically, every instance of init_MUTEX() can (and should) be converted
to using mutex_init() on a struct mutex. Those few places that call
sema_init with a count of one are probably just a subset of these.
Similarly, most of the occurences of sema_init(sem, 0) seem to be
the kind that should be converted to 'struct completion'.
Arnd <><
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [KJ] using "mutexes" in place of semaphores
2007-02-17 12:48 [KJ] using "mutexes" in place of semaphores Robert P. J. Day
2007-02-17 13:56 ` Arnd Bergmann
@ 2007-02-17 13:58 ` Robert P. J. Day
2007-02-17 16:39 ` Robert P. J. Day
2007-02-17 18:48 ` Arnd Bergmann
3 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2007-02-17 13:58 UTC (permalink / raw)
To: kernel-janitors
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1326 bytes --]
On Sat, 17 Feb 2007, Arnd Bergmann wrote:
> On Saturday 17 February 2007 13:48, Robert P. J. Day wrote:
> > a quick count shows that there's only a couple dozen instances of
> > calling sema_init() with a count of 1, while there are many more calls
> > of init_MUTEX() in the tree, suggesting that init_MUTEX() really is
> > the preferred standard.
> >
> > thoughts? is this worth it?
>
> I guess you missed the important point here, which is that we're also
> trying to get rid of the usage of a struct semaphore as a mutex.
>
> Basically, every instance of init_MUTEX() can (and should) be converted
> to using mutex_init() on a struct mutex. Those few places that call
> sema_init with a count of one are probably just a subset of these.
> Similarly, most of the occurences of sema_init(sem, 0) seem to be
> the kind that should be converted to 'struct completion'.
ah, i wasn't aware that there even *was* a "struct mutex" -- i thought
a general semaphore was used for that. thanks.
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================
[-- Attachment #2: Type: text/plain, Size: 168 bytes --]
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [KJ] using "mutexes" in place of semaphores
2007-02-17 12:48 [KJ] using "mutexes" in place of semaphores Robert P. J. Day
2007-02-17 13:56 ` Arnd Bergmann
2007-02-17 13:58 ` Robert P. J. Day
@ 2007-02-17 16:39 ` Robert P. J. Day
2007-02-17 18:48 ` Arnd Bergmann
3 siblings, 0 replies; 5+ messages in thread
From: Robert P. J. Day @ 2007-02-17 16:39 UTC (permalink / raw)
To: kernel-janitors
On Sat, 17 Feb 2007, Arnd Bergmann wrote:
> Basically, every instance of init_MUTEX() can (and should) be
> converted to using mutex_init() on a struct mutex. Those few places
> that call sema_init with a count of one are probably just a subset
> of these. Similarly, most of the occurences of sema_init(sem, 0)
> seem to be the kind that should be converted to 'struct completion'.
waitaminnit. you're not claiming that a currently-locked semaphore is
exactly equivalent to a completion, are you?
as i read it, calling "complete()" on a completion will wake *all*
processes waiting for that completion, no? not just one, as a
semaphore would.
so i'm assuming what you're saying is that, in many places where you
see a "sema_init(sem, 0)", it would be *appropriate* to have used a
completion instead, is that what you meant? thanks.
rday
--
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://fsdev.net/wiki/index.php?title=Main_Page
====================================
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [KJ] using "mutexes" in place of semaphores
2007-02-17 12:48 [KJ] using "mutexes" in place of semaphores Robert P. J. Day
` (2 preceding siblings ...)
2007-02-17 16:39 ` Robert P. J. Day
@ 2007-02-17 18:48 ` Arnd Bergmann
3 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2007-02-17 18:48 UTC (permalink / raw)
To: kernel-janitors
On Saturday 17 February 2007 17:39, Robert P. J. Day wrote:
> waitaminnit. you're not claiming that a currently-locked semaphore is
> exactly equivalent to a completion, are you?
>
> as i read it, calling "complete()" on a completion will wake *all*
> processes waiting for that completion, no? not just one, as a
> semaphore would.
>
> so i'm assuming what you're saying is that, in many places where you
> see a "sema_init(sem, 0)", it would be *appropriate* to have used a
> completion instead, is that what you meant? thanks.
>
Right, I looked at three instances where sema_init(sem, 0) was used,
and two of them use it only to do what a completion does.
Arnd <><
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-02-17 18:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-17 12:48 [KJ] using "mutexes" in place of semaphores Robert P. J. Day
2007-02-17 13:56 ` Arnd Bergmann
2007-02-17 13:58 ` Robert P. J. Day
2007-02-17 16:39 ` Robert P. J. Day
2007-02-17 18:48 ` Arnd Bergmann
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.