All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: "Michał Nazarewicz" <m.nazarewicz@samsung.com>
Cc: linux-usb@vger.kernel.org, Peter Korsgaard <jacmet@sunsite.dk>,
	Rupesh Gujare <rupeshgujare@gmail.com>,
	linux-kernel@vger.kernel.org,
	David Brownell <dbrownell@users.sourceforge.net>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Subject: Re: [PATCH 2/8] sched: __wake_up_locked() exported
Date: Wed, 7 Apr 2010 17:28:29 -0700	[thread overview]
Message-ID: <20100408002829.GB4365@kroah.com> (raw)
In-Reply-To: <op.vasx0rg07p4s8u@pikus>

On Wed, Apr 07, 2010 at 07:11:05PM +0200, Michał Nazarewicz wrote:
> >On Wed, Apr 07, 2010 at 03:41:29PM +0200, Michal Nazarewicz wrote:
> >>The __wake_up_locked() function has been exported in case modules need it.
> 
> On Wed, 07 Apr 2010 17:29:22 +0200, Greg KH <greg@kroah.com> wrote:
> >What module needs it?
> 
> FunctionFS (f_fs) uses it (thus FunctionFS Gadget (g_ffs) uses it).
> 
> >Why is it needed?
> 
> The FunctionFS uses wait_queue_head_t's spinlock to protect a data
> structure (a queue) used by FunctionFS.
> 
> In an earlier version of the code there was another spinlock for
> the queue alone thus when waiting for an event the following had
> to be used:
> 
> #v+
> spin_lock(&queue.lock);
> while (queue.empty) {
> 	spin_unlock(&queue.lock);
> 	wait_event(&queue.wait_queue, !queue.empty);
> 	spin_lock(&queue.lock);
> }
> ...
> spin_unlock(&queue.lock);
> #v-
> 
> I disliked this code very much and at first hoped that there's some
> "wait_event_holding_lock()" macro which would define the loop shown
> above (similar to user-space condition variables; see
> pthread_cond_wait(3) <http://linux.die.net/man/3/pthread_cond_wait>).
> 
> What makes matter worse is that wait_event() calls prepare_to_wait()
> which locks the wait_queue_head_t's spinlock so in the end we have
> unlock one spinlock prior to locking another in situation where one
> spinlock would suffice.
> 
> In searching for a better solution I stumbled across fs/timerfd.c which
> used the wait_queue_head_t's spinlock to lock it's own structures:
> 
> * http://lxr.linux.no/#linux+v2.6.33/fs/timerfd.c#L39
> * http://lxr.linux.no/#linux+v2.6.33/fs/timerfd.c#L106
> 
> So, in the end, I decided to use the same approach in FunctionFS and
> hence by using wait_queue_head_t's spinlock I removed one (unneeded)
> spinlock and decreased number of spin_lock and spin_unlock operations,
> ie. to something like (simplified code):
> 
> #v+
> spin_lock(&queue.wait_queue.lock);
> my_wait_event_locked(&queue.wait_queue, !queue.empty);
> ...
> spin_unlock(&queue.lock);
> #v-
> 
> where my_wait_event_locked() is a function that does what wait_event()
> does but assumes the wait_queue_head_t's lock is held when entering
> and leaves it held when exiting.
> 
> >Are you sure that you really need it?
> 
> I could live without it but I strongly believe the code is somehow
> cleaner and more optimised when __wake_up_locked() is used.

Ok, thanks for the detailed description, that makes more sense.

Perhaps you should put this into the patch description next time :)

Oh, and maybe we should move this type of functionality into the core
kernel so that the two users don't have to open-code it both times?  If
there are 2 users, odds are someone else will want to also do the same
thing in the near future.

thanks,

greg k-h

  reply	other threads:[~2010-04-08  0:31 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-07 13:41 [PATCH 0/7] The FunctionFS composite function Michal Nazarewicz
2010-04-07 13:41 ` [PATCH 1/8] USB: composite: allow optional removal of __init and __exit tags Michal Nazarewicz
2010-04-07 13:41   ` [PATCH 2/8] sched: __wake_up_locked() exported Michal Nazarewicz
2010-04-07 13:41     ` [PATCH 3/8] USB: f_fs: the FunctionFS driver Michal Nazarewicz
2010-04-07 13:41       ` [PATCH 4/8] USB: Ethernet: allow optional removal of __init and __init_data tags Michal Nazarewicz
2010-04-07 13:41         ` [PATCH 5/8] USB: g_ffs: the FunctionFS gadget driver Michal Nazarewicz
2010-04-07 13:41           ` [PATCH 6/8] USB: ffs-test: FunctionFS testing program Michal Nazarewicz
2010-04-07 13:41             ` [PATCH 7/8] USB: testusb: imported David Brownell's USB testing application Michal Nazarewicz
2010-04-07 13:41               ` [PATCH 8/8] USB: testusb: testusb compatibility with FunctionFS gadget Michal Nazarewicz
2010-04-08  0:30                 ` Greg KH
2010-04-08  0:29               ` [PATCH 7/8] USB: testusb: imported David Brownell's USB testing application Greg KH
2010-04-09 19:21                 ` [PATCHv2 7/8] USB: testusb: an " Michal Nazarewicz
2010-04-09 19:21                   ` [PATCHv2 8/8] USB: testusb: testusb compatibility with FunctionFS gadget Michal Nazarewicz
2010-04-10 22:51                   ` [PATCHv2 7/8] USB: testusb: an USB testing application David Brownell
2010-04-14  9:30                 ` [PATCH 7/8] USB: testusb: imported David Brownell's " David Brownell
2010-04-14 16:46                   ` Greg KH
2010-04-14 16:47                   ` Greg KH
2010-04-08  6:10               ` Heikki Krogerus
2010-04-08  6:18                 ` Greg KH
2010-04-08  6:34                   ` Heikki Krogerus
2010-04-14  9:41               ` David Brownell
2010-04-14 12:50                 ` Michał Nazarewicz
2010-04-14 16:47                   ` Greg KH
2010-04-07 17:11       ` [PATCH 3/8] USB: f_fs: the FunctionFS driver Michał Nazarewicz
2010-04-07 15:29     ` [PATCH 2/8] sched: __wake_up_locked() exported Greg KH
2010-04-07 17:11       ` Michał Nazarewicz
2010-04-08  0:28         ` Greg KH [this message]
2010-04-07 15:28   ` [PATCH 1/8] USB: composite: allow optional removal of __init and __exit tags Greg KH
2010-04-07 15:39     ` Michał Nazarewicz
2010-04-08  0:26       ` Greg KH
2010-04-09 19:21 [PATCH 0/7] The FunctionFS composite function Michal Nazarewicz
2010-04-09 19:21 ` [PATCHv2 1/8] wait_event_interruptible_locked() interface Michal Nazarewicz
2010-04-09 19:21   ` [PATCHv2 2/8] fs/timerfd.c: make use of wait_event_interruptible_locked_irq() Michal Nazarewicz
2010-04-09 19:21     ` [PATCHv2 3/8] USB: gadget: __init and __exit tags removed Michal Nazarewicz
2010-04-09 19:21       ` [PATCHv2 4/8] USB: f_fs: the FunctionFS driver Michal Nazarewicz
2010-04-09 19:21         ` [PATCHv2 5/8] USB: g_ffs: the FunctionFS gadget driver Michal Nazarewicz
2010-04-09 19:21           ` [PATCHv2 6/8] USB: ffs-test: FunctionFS testing program Michal Nazarewicz
2010-04-29 22:15       ` [PATCHv2 3/8] USB: gadget: __init and __exit tags removed Greg KH
2010-04-29 23:02         ` Michal Nazarewicz
2010-04-29 23:22           ` Greg KH
2010-04-30  5:41             ` Michal Nazarewicz
2010-04-11 14:31     ` [PATCHv2 2/8] fs/timerfd.c: make use of wait_event_interruptible_locked_irq() Thomas Gleixner
2010-04-11 19:16       ` Michal Nazarewicz
2010-04-11 19:16         ` Michal Nazarewicz
2010-04-11 15:02   ` [PATCHv2 1/8] wait_event_interruptible_locked() interface Thomas Gleixner
2010-04-11 15:02     ` Thomas Gleixner
2010-04-11 19:27     ` Michal Nazarewicz

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=20100408002829.GB4365@kroah.com \
    --to=greg@kroah.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=jacmet@sunsite.dk \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.nazarewicz@samsung.com \
    --cc=m.szyprowski@samsung.com \
    --cc=rupeshgujare@gmail.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 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.