public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "weiqi@kylinos.com.cn" <weiqi@kylinos.com.cn>
To: Tejun Heo <tj@kernel.org>
Cc: "weiqi@kylinos.com.cn" <weiqi@kylinos.com.cn>,
	torvalds <torvalds@linux-foundation.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: race condition in schedule_on_each_cpu()
Date: Sat, 08 Jun 2013 19:30:21 +0800	[thread overview]
Message-ID: <51B315CD.9010908@kylinos.com.cn> (raw)
In-Reply-To: <51B27744.6090507@kylinos.com.cn>

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

Hello Tejun Heo,

I've backported the  schedule_on_each_cpu()  "direct excution" patch on 
3.0.30-rt50,
and  It  fixed my problem.

attachment is the effective patch.

However, I do not understand why  machine1 can expose problem,  but 
machine2 not.

I guess, because it's  rt-kernel's  preempt level related, so , is this 
difference due to cpu performance?

How do you think about this ?

Thank you~

[-- Attachment #2: direct_execution.patch --]
[-- Type: text/plain, Size: 1170 bytes --]

diff -up linux-3.0.30-rt50/kernel/workqueue.c.bak linux-3.0.30-rt50/kernel/workqueue.c
--- linux-3.0.30-rt50/kernel/workqueue.c.bak	2013-06-08 19:09:06.801059232 +0800
+++ linux-3.0.30-rt50/kernel/workqueue.c	2013-06-08 19:09:15.680069626 +0800
@@ -1922,6 +1922,7 @@ static int worker_thread(void *__worker)
 
 	/* tell the scheduler that this is a workqueue worker */
 	worker->task->flags |= PF_WQ_WORKER;
+	smp_mb();
 woke_up:
 	spin_lock_irq(&gcwq->lock);
 
@@ -2736,6 +2737,7 @@ EXPORT_SYMBOL(schedule_delayed_work_on);
 int schedule_on_each_cpu(work_func_t func)
 {
 	int cpu;
+	int orig = -1;
 	struct work_struct __percpu *works;
 
 	works = alloc_percpu(struct work_struct);
@@ -2744,13 +2746,20 @@ int schedule_on_each_cpu(work_func_t fun
 
 	get_online_cpus();
 
+	if(current->flags & PF_WQ_WORKER)
+		orig = raw_smp_processor_id();
+
 	for_each_online_cpu(cpu) {
 		struct work_struct *work = per_cpu_ptr(works, cpu);
 
 		INIT_WORK(work, func);
-		schedule_work_on(cpu, work);
+		if(cpu != orig)
+			schedule_work_on(cpu, work);
 	}
 
+	if (orig >= 0)
+		func(per_cpu_ptr(works,orig));
+
 	for_each_online_cpu(cpu)
 		flush_work(per_cpu_ptr(works, cpu));
 

  parent reply	other threads:[~2013-06-08 11:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <tencent_0777D84B54B4163A3B85255A@qq.com>
2013-06-06 21:23 ` race condition in schedule_on_each_cpu() Tejun Heo
2013-06-07  1:34   ` weiqi
2013-06-07  2:24     ` weiqi
2013-06-07 23:22       ` Tejun Heo
     [not found]         ` <51B27744.6090507@kylinos.com.cn>
2013-06-08 11:30           ` weiqi [this message]
     [not found] <51A7FFE8.6060204@kylinos.com.cn>
     [not found] ` <20130531023246.GD30479@mtj.dyndns.org>
     [not found]   ` <51A821F3.1000605@kylinos.com.cn>
2013-05-31  5:03     ` Tejun Heo

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=51B315CD.9010908@kylinos.com.cn \
    --to=weiqi@kylinos.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.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