Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Stefan Metzmacher <metze@samba.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Steve French <smfrench@gmail.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	"linux-cifs@vger.kernel.org" <linux-cifs@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: Questions about wake_up[_interruptible][_all]
Date: Thu, 14 Aug 2025 09:57:14 +0200	[thread overview]
Message-ID: <13851363-0dc9-465c-9ced-3ede4904eef0@samba.org> (raw)
In-Reply-To: <20250813173705.0e910f5a@gandalf.local.home>

Am 13.08.25 um 23:37 schrieb Steven Rostedt:
> On Wed, 13 Aug 2025 22:28:08 +0200
> Stefan Metzmacher <metze@samba.org> wrote:
> 
>> I guess I understand the difference between
>> wait_event() and wait_event_interruptible(),
>> the first ignores any signal even kill and the
>> 2nd returns -ERESTARTSYS on any signal.
> 
> The main difference is what the code does after the wait_event*().
> 
> If you use wait_event_interruptible() the first thing the code should do is
> to check if a signal is pending or not. Or at least check some status to
> know that what it is waiting for did not happen and handle it properly.
> 
> But there's places in the kernel where the task is waiting for something
> and it expects that whatever it is waiting for *must* happen eventually and
> it should not continue until it does.
> 
> Looking at one example: fs/jbd2/journal.c: jbd2_journal_start_thread()
> 
> It creates a thread, tests that it is created, and then waits for that
> thread to acknowledge that it is running, and the function should not
> return until it does.
> 
> If someone were to send a signal to that waiter and wake it up prematurely,
> the following code may become buggy as it expects the thread to be
> initialized and active when it is not.

Thanks!

Via a private channel I also got this answer:

wake_up_interruptible() only wakes tasks that are in the
TASK_INTERRUPTIBLE state.

wake_up() wakes tasks that are in either the TASK_INTERRUPTIBLE or
TASK_UNINTERRUPTIBLE state, as per the TASK_NORMAL macro used in the
definition of wake_up().

Call chain:

wake_up_interruptible
   __wake_up(mode = TASK_INTERRUPTIBLE)
     __wake_up_common_lock(mode = TASK_INTERRUPTIBLE)
       __wake_up_common(mode = TASK_INTERRUPTIBLE)
         curr->func(mode = TASK_INTERRUPTIBLE)
           // curr->func is usually default_wake_function
           default_wake_function(mode = TASK_INTERRUPTIBLE)
             try_to_wake_up(state = TASK_INTERRUPTIBLE)
               ttwu_state_match(state = TASK_INTERRUPTIBLE)
                 __task_state_match(state = TASK_INTERRUPTIBLE):
                 if (READ_ONCE(p->__state) & state) ...

metze

  reply	other threads:[~2025-08-14  7:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-13 20:28 Questions about wake_up[_interruptible][_all] Stefan Metzmacher
2025-08-13 21:37 ` Steven Rostedt
2025-08-14  7:57   ` Stefan Metzmacher [this message]
2025-08-15  2:47     ` Steven Rostedt

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=13851363-0dc9-465c-9ced-3ede4904eef0@samba.org \
    --to=metze@samba.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=smfrench@gmail.com \
    --cc=vschneid@redhat.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