From: Tejun Heo <tj@kernel.org>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org,
Lai Jiangshan <jiangshanlai@gmail.com>,
kernel-team@fb.com
Subject: Re: simple repro case
Date: Sat, 17 Jun 2017 08:11:49 -0400 [thread overview]
Message-ID: <20170617121149.GC20758@htj.duckdns.org> (raw)
In-Reply-To: <20170617121008.GB20758@htj.duckdns.org>
Here's a simple rerpo. The test code runs whenever a CPU goes
off/online. The test kthread is created on a different CPU and
migrated to the target CPU while running. Without the previous patch
applied, the kthread ends up running on the wrong CPU.
Thanks.
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index c74bf39ef764..faed30edbb21 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4648,12 +4648,56 @@ int workqueue_prepare_cpu(unsigned int cpu)
return 0;
}
+#include <linux/delay.h>
+
+static int test_last_cpu = -1;
+
+static int test_kthread_migration_threadfn(void *data)
+{
+ while (!kthread_should_stop()) {
+ test_last_cpu = raw_smp_processor_id();
+ cond_resched();
+ }
+ return 0;
+}
+
+static void test_kthread_migration(int inactive_cpu)
+{
+ int start_cpu = cpumask_any(cpu_online_mask);
+ struct task_struct *task;
+
+ printk("TEST: cpu %d inactive, starting on %d and migrating (active/online=%*pbl/%*pbl)\n",
+ inactive_cpu, start_cpu, cpumask_pr_args(cpu_active_mask),
+ cpumask_pr_args(cpu_online_mask));
+
+ task = kthread_create(test_kthread_migration_threadfn, NULL, "test");
+ if (IS_ERR(task)) {
+ printk("TEST: kthread_create failed with %ld\n", PTR_ERR(task));
+ return;
+ }
+
+ kthread_bind(task, start_cpu);
+ wake_up_process(task);
+ msleep(100);
+ printk("TEST: test_last_cpu=%d cpus_allowed=%*pbl\n",
+ test_last_cpu, cpumask_pr_args(&task->cpus_allowed));
+ printk("TEST: migrating to inactve cpu %d\n", inactive_cpu);
+ set_cpus_allowed_ptr(task, cpumask_of(inactive_cpu));
+ msleep(100);
+ printk("TEST: test_last_cpu=%d cpus_allowed=%*pbl\n",
+ test_last_cpu, cpumask_pr_args(&task->cpus_allowed));
+ kthread_stop(task);
+ return;
+}
+
int workqueue_online_cpu(unsigned int cpu)
{
struct worker_pool *pool;
struct workqueue_struct *wq;
int pi;
+ test_kthread_migration(cpu);
+
mutex_lock(&wq_pool_mutex);
for_each_pool(pool, pi) {
@@ -4680,6 +4724,8 @@ int workqueue_offline_cpu(unsigned int cpu)
struct work_struct unbind_work;
struct workqueue_struct *wq;
+ test_kthread_migration(cpu);
+
/* unbinding per-cpu workers should happen on the local CPU */
INIT_WORK_ONSTACK(&unbind_work, wq_unbind_fn);
queue_work_on(cpu, system_highpri_wq, &unbind_work);
next prev parent reply other threads:[~2017-06-17 12:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-17 12:10 [PATCH RFC] sched: Allow migrating kthreads into online but inactive CPUs Tejun Heo
2017-06-17 12:11 ` Tejun Heo [this message]
2017-06-21 14:24 ` simple repro case Steven Rostedt
2017-06-21 17:59 ` Tejun Heo
2017-07-25 16:58 ` [PATCH RFC] sched: Allow migrating kthreads into online but inactive CPUs Peter Zijlstra
2017-07-25 17:52 ` Paul E. McKenney
2017-07-26 12:57 ` Paul E. McKenney
2018-05-31 12:28 ` [tip:sched/urgent] sched/core: Fix rules for running on online && !active CPUs tip-bot for Peter Zijlstra
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=20170617121149.GC20758@htj.duckdns.org \
--to=tj@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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