From: Oleg Nesterov <oleg@tv-sign.ru>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>,
Gregory Haskins <ghaskins@novell.com>,
Daniel Walker <dwalker@mvista.com>,
linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RT: Add priority-queuing and priority-inheritance to workqueue infrastructure
Date: Mon, 6 Aug 2007 20:40:33 +0400 [thread overview]
Message-ID: <20070806164033.GA4021@tv-sign.ru> (raw)
In-Reply-To: <1186411921.7182.24.camel@twins>
On 08/06, Peter Zijlstra wrote:
>
> On Mon, 2007-08-06 at 18:45 +0400, Oleg Nesterov wrote:
> > On 08/06, Peter Zijlstra wrote:
>
> > > > I suspect most of the barrier/flush semantics could be replaced with
> > > > completions from specific work items.
> >
> > Hm. But this is exactly how it works?
>
> Yes, barriers work by enqueueing work and waiting for that one work item
> to fall out, thereby knowing that all previous work has been completed.
>
> My point was that most flushes are there to wait for a previously
> enqueued work item, and might as well wait for that one.
>
> Let me try to illustrate: a regular pattern is, we enqueue work A and
> then flush the whole queue to ensure A is processed. So instead of
> enqueueing A, then B in the barrier code, and wait for B to pop out, we
> might as well wait for A to begin with.
This is a bit off-topic, but in that particular case we can do
if (cancel_work_sync(&A))
A->func(&A);
unless we want to execute ->func() on another CPU of course. It is easy to
implement flush_work() which waits for a single work_strcut, but it is not
so useful when it comes to schedule_on_each_cpu().
But I agree, flush_workqueue() should be avoided if possible. Not sure
it makes sense, but we can do something like below.
Oleg.
--- kernel/workqueue.c~ 2007-07-28 16:58:17.000000000 +0400
+++ kernel/workqueue.c 2007-08-06 20:33:25.000000000 +0400
@@ -572,25 +572,54 @@ EXPORT_SYMBOL(schedule_delayed_work_on);
*
* schedule_on_each_cpu() is very slow.
*/
+
+struct xxx
+{
+ atomic_t count;
+ struct completion done;
+ work_func_t func;
+};
+
+struct yyy
+{
+ struct work_struct work;
+ struct xxx *xxx;
+};
+
+static void yyy_func(struct work_struct *work)
+{
+ struct xxx *xxx = container_of(work, struct yyy, work)->xxx;
+ xxx->func(work);
+
+ if (atomic_dec_and_test(&xxx->count))
+ complete(&xxx->done);
+}
+
int schedule_on_each_cpu(work_func_t func)
{
int cpu;
- struct work_struct *works;
+ struct xxx xxx;
+ struct yyy *works;
- works = alloc_percpu(struct work_struct);
+ init_completion(&xxx.done);
+ xxx.func = func;
+
+ works = alloc_percpu(struct yyy);
if (!works)
return -ENOMEM;
preempt_disable(); /* CPU hotplug */
+ atomic_set(&xxx.count, num_online_cpus());
for_each_online_cpu(cpu) {
- struct work_struct *work = per_cpu_ptr(works, cpu);
+ struct yyy *yyy = per_cpu_ptr(works, cpu);
- INIT_WORK(work, func);
- set_bit(WORK_STRUCT_PENDING, work_data_bits(work));
- __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), work);
+ yyy->xxx = &xxx;
+ INIT_WORK(&yyy->work, yyy_func);
+ set_bit(WORK_STRUCT_PENDING, work_data_bits(&yyy->work));
+ __queue_work(per_cpu_ptr(keventd_wq->cpu_wq, cpu), &yyy->work);
}
preempt_enable();
- flush_workqueue(keventd_wq);
+ wait_for_completion(&xxx.done);
free_percpu(works);
return 0;
}
next prev parent reply other threads:[~2007-08-06 16:38 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-01 0:26 Gregory Haskins
2007-08-01 3:52 ` Daniel Walker
2007-08-01 11:59 ` Gregory Haskins
2007-08-01 15:10 ` Daniel Walker
2007-08-01 15:19 ` Gregory Haskins
2007-08-01 15:55 ` Daniel Walker
2007-08-01 17:32 ` Gregory Haskins
2007-08-01 21:48 ` Esben Nielsen
2007-08-01 17:01 ` Peter Zijlstra
2007-08-01 17:10 ` Daniel Walker
2007-08-01 18:26 ` Oleg Nesterov
2007-08-01 18:39 ` Daniel Walker
2007-08-01 20:25 ` Oleg Nesterov
2007-08-01 18:12 ` Oleg Nesterov
2007-08-01 18:29 ` Daniel Walker
2007-08-01 20:18 ` Oleg Nesterov
2007-08-01 20:32 ` Oleg Nesterov
2007-08-01 20:43 ` Daniel Walker
2007-08-01 20:34 ` Daniel Walker
2007-08-01 20:50 ` Oleg Nesterov
2007-08-01 21:02 ` Daniel Walker
2007-08-01 21:13 ` Gregory Haskins
2007-08-01 21:34 ` Oleg Nesterov
2007-08-01 21:59 ` Gregory Haskins
2007-08-01 22:22 ` Oleg Nesterov
2007-08-01 23:53 ` Gregory Haskins
2007-08-02 19:50 ` Oleg Nesterov
2007-08-06 11:35 ` Gregory Haskins
2007-08-06 14:26 ` Oleg Nesterov
2007-08-06 14:57 ` Gregory Haskins
2007-08-06 15:36 ` Oleg Nesterov
2007-08-06 15:50 ` Gregory Haskins
2007-08-06 16:50 ` Oleg Nesterov
2007-08-06 16:57 ` Gregory Haskins
2007-08-06 11:49 ` Ingo Molnar
2007-08-06 13:18 ` Oleg Nesterov
2007-08-06 13:29 ` Peter Zijlstra
2007-08-06 13:32 ` Peter Zijlstra
2007-08-06 14:45 ` Oleg Nesterov
2007-08-06 14:52 ` Peter Zijlstra
2007-08-06 16:40 ` Oleg Nesterov [this message]
2007-08-06 15:04 ` Gregory Haskins
2007-08-06 15:38 ` Oleg Nesterov
2007-08-06 19:33 ` Oleg Nesterov
2007-08-06 19:37 ` Gregory Haskins
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=20070806164033.GA4021@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=dwalker@mvista.com \
--cc=ghaskins@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.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
all inboxes | Powered by JetHome®