Kernel Newbies archive mirror
 help / color / mirror / Atom feed
From: Martin Kaiser <lists@kaiser.cx>
To: kernelnewbies@kernelnewbies.org
Subject: workqueue - queue + drain
Date: Thu, 11 Aug 2022 18:03:51 +0200	[thread overview]
Message-ID: <20220811160351.urbqbhquu5u74obe@viti.kaiser.cx> (raw)

Dear all,

would you mind helping me understand how workers and workqueues act in a
seemingly simple scenario? I'm calling

queue_work(my_queue, my_worker)

to add a worker to a queue that was created by calling
create_singlethread_workqueue().

This goes into

queue_work
   queue_work_on
         ...
         if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
            __queue_work(cpu, wq, work);
            ret = true;
         }
         ... return false if __queue_work hasn't been called...


with

static void __queue_work(int cpu, struct workqueue_struct *wq, struct work_struct *work)
   ...
   /* if draining, only works from the same workqueue are allowed */
   if (unlikely(wq->flags & __WQ_DRAINING) &&
       WARN_ON_ONCE(!is_chained_work(wq)))
      return;


If drain_workqueue(my_queue) is running while
queue_work(my_queue, my_worker)
is called, my_worker will have WORK_STRUCT_PENDING_BIT set, but it's not
queued and no error is returned.

With WORK_STRUCT_PENDING_BIT set, all further attempts to
queue_work(my_queue, my_worker)
later, after draining is done, will fail.

This code has been unchanged since at least 4.14. Could anyone shed some
light on this, where am I getting things wrong?

Thanks and best regards,

   Martin

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

             reply	other threads:[~2022-08-11 16:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 16:03 Martin Kaiser [this message]
2022-09-27 12:50 ` workqueue - queue + drain Fabio M. De Francesco

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=20220811160351.urbqbhquu5u74obe@viti.kaiser.cx \
    --to=lists@kaiser.cx \
    --cc=kernelnewbies@kernelnewbies.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).