kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
@ 2019-07-29 17:18 Muni Sekhar
  2019-07-29 17:28 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Muni Sekhar @ 2019-07-29 17:18 UTC (permalink / raw)
  To: kernelnewbies

Hi All,

Let us assume that multiple processes are waiting on wait_event()\
wait_event_interruptible()\ wait_event_interruptible_timeout(), which
process gets woken up on calling wake_up()??

I presume wake_up() picks one process, but is there any algorithm to
pick which process?


-- 
Thanks,
Sekhar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 17:18 wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up() Muni Sekhar
@ 2019-07-29 17:28 ` Greg KH
  2019-07-29 18:01 ` Bharath Vedartham
  2019-07-29 18:27 ` Valdis Klētnieks
  2 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2019-07-29 17:28 UTC (permalink / raw)
  To: Muni Sekhar; +Cc: kernelnewbies

On Mon, Jul 29, 2019 at 10:48:57PM +0530, Muni Sekhar wrote:
> Hi All,
> 
> Let us assume that multiple processes are waiting on wait_event()\
> wait_event_interruptible()\ wait_event_interruptible_timeout(), which
> process gets woken up on calling wake_up()??
> 
> I presume wake_up() picks one process, but is there any algorithm to
> pick which process?

try it and see!  :)


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 17:18 wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up() Muni Sekhar
  2019-07-29 17:28 ` Greg KH
@ 2019-07-29 18:01 ` Bharath Vedartham
  2019-07-29 18:07   ` Muni Sekhar
  2019-07-29 18:27 ` Valdis Klētnieks
  2 siblings, 1 reply; 11+ messages in thread
From: Bharath Vedartham @ 2019-07-29 18:01 UTC (permalink / raw)
  To: Muni Sekhar; +Cc: kernelnewbies

On Mon, Jul 29, 2019 at 10:48:57PM +0530, Muni Sekhar wrote:
> Hi All,
> 
> Let us assume that multiple processes are waiting on wait_event()\
> wait_event_interruptible()\ wait_event_interruptible_timeout(), which
> process gets woken up on calling wake_up()??
> 
> I presume wake_up() picks one process, but is there any algorithm to
> pick which process?
> 
> 
> -- 
> Thanks,
> Sekhar
Sorry to spoil the fun here. But check out what the queue data structure
is all about. 'wait_queue' :)

Thank you
Bharath
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 18:01 ` Bharath Vedartham
@ 2019-07-29 18:07   ` Muni Sekhar
  2019-07-29 18:29     ` Valdis Klētnieks
  0 siblings, 1 reply; 11+ messages in thread
From: Muni Sekhar @ 2019-07-29 18:07 UTC (permalink / raw)
  To: Bharath Vedartham; +Cc: kernelnewbies

On Mon, Jul 29, 2019 at 11:31 PM Bharath Vedartham <linux.bhar@gmail.com> wrote:
>
> On Mon, Jul 29, 2019 at 10:48:57PM +0530, Muni Sekhar wrote:
> > Hi All,
> >
> > Let us assume that multiple processes are waiting on wait_event()\
> > wait_event_interruptible()\ wait_event_interruptible_timeout(), which
> > process gets woken up on calling wake_up()??
> >
> > I presume wake_up() picks one process, but is there any algorithm to
> > pick which process?
> >
> >
> > --
> > Thanks,
> > Sekhar
> Sorry to spoil the fun here. But check out what the queue data structure
> is all about. 'wait_queue' :)
A wait queue is a doubly linked list of wait_queue_t structures that
hold pointers to the process task structures of the processes that are
blocking. Each list is headed up by a wait_queue_head_t structure,
which marks the head of the list and holds the spinlock to the list to
prevent wait_queue_t additional race conditions

>
> Thank you
> Bharath
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies@kernelnewbies.org
> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



-- 
Thanks,
Sekhar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 17:18 wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up() Muni Sekhar
  2019-07-29 17:28 ` Greg KH
  2019-07-29 18:01 ` Bharath Vedartham
@ 2019-07-29 18:27 ` Valdis Klētnieks
  2019-07-30  1:59   ` Muni Sekhar
  2019-08-06  8:45   ` Muni Sekhar
  2 siblings, 2 replies; 11+ messages in thread
From: Valdis Klētnieks @ 2019-07-29 18:27 UTC (permalink / raw)
  To: Muni Sekhar; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 925 bytes --]

On Mon, 29 Jul 2019 22:48:57 +0530, Muni Sekhar said:
> Let us assume that multiple processes are waiting on wait_event()\
> wait_event_interruptible()\ wait_event_interruptible_timeout(), which
> process gets woken up on calling wake_up()??
>
> I presume wake_up() picks one process, but is there any algorithm to
> pick which process?

Hint:  If you have more than one process waiting, and they do the same thing
(think multiple copies of the same kthread), it probably doesn't matter.

If they do different things and which one gets picked matters for correctness,
you're doing it wrong and probably need some locking.

If they do different things and the results will be correct no matter which
order they're picked, but you want one to go first for latency/througput
considerations, you have a scheduling/priority issue and probably need to fix
it using the vast plethora of knobs and tools available for that purpose.


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 18:07   ` Muni Sekhar
@ 2019-07-29 18:29     ` Valdis Klētnieks
  0 siblings, 0 replies; 11+ messages in thread
From: Valdis Klētnieks @ 2019-07-29 18:29 UTC (permalink / raw)
  To: Muni Sekhar; +Cc: Bharath Vedartham, kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 785 bytes --]

On Mon, 29 Jul 2019 23:37:34 +0530, Muni Sekhar said:
> On Mon, Jul 29, 2019 at 11:31 PM Bharath Vedartham <linux.bhar@gmail.com> wrote:
> > Sorry to spoil the fun here. But check out what the queue data structure
> > is all about. 'wait_queue' :)
> A wait queue is a doubly linked list of wait_queue_t structures that
> hold pointers to the process task structures of the processes that are
> blocking. Each list is headed up by a wait_queue_head_t structure,
> which marks the head of the list and holds the spinlock to the list to
> prevent wait_queue_t additional race conditions

So... if you're picking the first entry off a linked list, how do you ensure that
the one you want run is the one that gets picked?

Make sure the right one is at the head of the list, of course. ;)


[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 18:27 ` Valdis Klētnieks
@ 2019-07-30  1:59   ` Muni Sekhar
  2019-08-06  8:45   ` Muni Sekhar
  1 sibling, 0 replies; 11+ messages in thread
From: Muni Sekhar @ 2019-07-30  1:59 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: kernelnewbies

On Mon, Jul 29, 2019 at 11:57 PM Valdis Klētnieks
<valdis.kletnieks@vt.edu> wrote:
>
> On Mon, 29 Jul 2019 22:48:57 +0530, Muni Sekhar said:
> > Let us assume that multiple processes are waiting on wait_event()\
> > wait_event_interruptible()\ wait_event_interruptible_timeout(), which
> > process gets woken up on calling wake_up()??
> >
> > I presume wake_up() picks one process, but is there any algorithm to
> > pick which process?
>
> Hint:  If you have more than one process waiting, and they do the same thing
> (think multiple copies of the same kthread), it probably doesn't matter.
>
> If they do different things and which one gets picked matters for correctness,
> you're doing it wrong and probably need some locking.
>
> If they do different things and the results will be correct no matter which
> order they're picked, but you want one to go first for latency/througput
> considerations, you have a scheduling/priority issue and probably need to fix
> it using the vast plethora of knobs and tools available for that purpose.
What are those tools? Can you give some more details on how to fix
latency/throughput issues using those tools..
>


-- 
Thanks,
Sekhar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-07-29 18:27 ` Valdis Klētnieks
  2019-07-30  1:59   ` Muni Sekhar
@ 2019-08-06  8:45   ` Muni Sekhar
  2019-08-06 11:42     ` Valdis Klētnieks
  1 sibling, 1 reply; 11+ messages in thread
From: Muni Sekhar @ 2019-08-06  8:45 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: kernelnewbies

On Mon, Jul 29, 2019 at 11:57 PM Valdis Klētnieks
<valdis.kletnieks@vt.edu> wrote:
>
> On Mon, 29 Jul 2019 22:48:57 +0530, Muni Sekhar said:
> > Let us assume that multiple processes are waiting on wait_event()\
> > wait_event_interruptible()\ wait_event_interruptible_timeout(), which
> > process gets woken up on calling wake_up()??
> >
> > I presume wake_up() picks one process, but is there any algorithm to
> > pick which process?
>
> Hint:  If you have more than one process waiting, and they do the same thing
> (think multiple copies of the same kthread), it probably doesn't matter.
>
> If they do different things and which one gets picked matters for correctness,
> you're doing it wrong and probably need some locking.
>
> If they do different things and the results will be correct no matter which
> order they're picked, but you want one to go first for latency/througput
> considerations, you have a scheduling/priority issue and probably need to fix
> it using the vast plethora of knobs and tools available for that purpose.
If they do different things, does the waiting threads wakeup order is
the same in which they were enqueued (FIFO order)?
>


-- 
Thanks,
Sekhar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-08-06  8:45   ` Muni Sekhar
@ 2019-08-06 11:42     ` Valdis Klētnieks
  2019-08-06 12:00       ` Muni Sekhar
  0 siblings, 1 reply; 11+ messages in thread
From: Valdis Klētnieks @ 2019-08-06 11:42 UTC (permalink / raw)
  To: Muni Sekhar; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 382 bytes --]

On Tue, 06 Aug 2019 14:15:53 +0530, Muni Sekhar said:

> If they do different things, does the waiting threads wakeup order is
> the same in which they were enqueued (FIFO order)?

You missed the point - if you have (for example) something that's waiting for
mouse I/O and something that's waiting for a network packet, under what
conditions will they be using the same wait event?

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-08-06 11:42     ` Valdis Klētnieks
@ 2019-08-06 12:00       ` Muni Sekhar
  2019-08-06 12:26         ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Muni Sekhar @ 2019-08-06 12:00 UTC (permalink / raw)
  To: Valdis Klētnieks; +Cc: kernelnewbies

On Tue, Aug 6, 2019 at 5:12 PM Valdis Klētnieks <valdis.kletnieks@vt.edu> wrote:
>
> On Tue, 06 Aug 2019 14:15:53 +0530, Muni Sekhar said:
>
> > If they do different things, does the waiting threads wakeup order is
> > the same in which they were enqueued (FIFO order)?
>
> You missed the point - if you have (for example) something that's waiting for
> mouse I/O and something that's waiting for a network packet, under what
> conditions will they be using the same wait event?
In this example they won't wait on the same wait event. Let us
consider buggy code is written like that and more than one
process(they do different things) waiting on the same wait event which
process gets woken up? Is the process at the head of the list?



-- 
Thanks,
Sekhar

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up()
  2019-08-06 12:00       ` Muni Sekhar
@ 2019-08-06 12:26         ` Greg KH
  0 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2019-08-06 12:26 UTC (permalink / raw)
  To: Muni Sekhar; +Cc: Valdis Klētnieks, kernelnewbies

On Tue, Aug 06, 2019 at 05:30:43PM +0530, Muni Sekhar wrote:
> On Tue, Aug 6, 2019 at 5:12 PM Valdis Klētnieks <valdis.kletnieks@vt.edu> wrote:
> >
> > On Tue, 06 Aug 2019 14:15:53 +0530, Muni Sekhar said:
> >
> > > If they do different things, does the waiting threads wakeup order is
> > > the same in which they were enqueued (FIFO order)?
> >
> > You missed the point - if you have (for example) something that's waiting for
> > mouse I/O and something that's waiting for a network packet, under what
> > conditions will they be using the same wait event?
> In this example they won't wait on the same wait event. Let us
> consider buggy code is written like that and more than one
> process(they do different things) waiting on the same wait event which
> process gets woken up? Is the process at the head of the list?

Again, try it and see, it is trivial to do this test.

Also, when you write buggy code, you get buggy results :)

thanks,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-08-06 12:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-29 17:18 wait_event()\ wait_event_interruptible()\ wait_event_interruptible_timeout() and wake_up() Muni Sekhar
2019-07-29 17:28 ` Greg KH
2019-07-29 18:01 ` Bharath Vedartham
2019-07-29 18:07   ` Muni Sekhar
2019-07-29 18:29     ` Valdis Klētnieks
2019-07-29 18:27 ` Valdis Klētnieks
2019-07-30  1:59   ` Muni Sekhar
2019-08-06  8:45   ` Muni Sekhar
2019-08-06 11:42     ` Valdis Klētnieks
2019-08-06 12:00       ` Muni Sekhar
2019-08-06 12:26         ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).