Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1695161 > unrolled thread

[PATCH tip/core/rcu 0/5] Related non-RCU updates

Started by"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
First post2017-07-25 00:00 +0200
Last post2017-07-25 00:30 +0200
Articles 6 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH tip/core/rcu 0/5] Related non-RCU updates "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 00:00 +0200
    [PATCH tip/core/rcu 2/5] init_task: Remove redundant INIT_TASK_RCU_TREE_PREEMPT() macro "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 00:00 +0200
    [PATCH tip/core/rcu 3/5] EXPERIMENTAL sched: Allow migrating kthreads into online but inactive CPUs "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 00:00 +0200
    [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 00:00 +0200
      Re: [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using  smp_processor_id() in preemptible Wanpeng Li <kernellwp@gmail.com> - 2017-07-25 00:10 +0200
        Re: [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using  smp_processor_id() in preemptible "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 00:30 +0200

#1695161 — [PATCH tip/core/rcu 0/5] Related non-RCU updates

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-07-25 00:00 +0200
Subject[PATCH tip/core/rcu 0/5] Related non-RCU updates
Message-ID<u6Tyq-2jq-17@gated-at.bofh.it>
Hello!

This series is outside of RCU, including things like fixes for bug
triggered by RCU commits.

1.	Fix pr_fmt() bug for header use of printk, courtesy of Joe Perches.

2.	Remove redundant INIT_TASK_RCU_TREE_PREEMPT() macro.

3.	Allow migrating kthreads into online but inactive CPUs, courtesy
	of Tejun Heo.

4.	Add expedited option to sys_membarrier().

5.	Fix use of smp_processor_id() in preemptible in cputime,
	courtesy of Wanpeng Li.

							Thanx, Paul

------------------------------------------------------------------------

 arch/blackfin/kernel/module.c   |   39 +++++++++++++++++++++------------------
 include/linux/init_task.h       |    8 +-------
 include/uapi/linux/membarrier.h |   11 +++++++++++
 kernel/membarrier.c             |    7 ++++++-
 kernel/sched/core.c             |    9 +++++++--
 kernel/sched/cputime.c          |    6 +++---
 6 files changed, 49 insertions(+), 31 deletions(-)

[toc] | [next] | [standalone]


#1695162 — [PATCH tip/core/rcu 2/5] init_task: Remove redundant INIT_TASK_RCU_TREE_PREEMPT() macro

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-07-25 00:00 +0200
Subject[PATCH tip/core/rcu 2/5] init_task: Remove redundant INIT_TASK_RCU_TREE_PREEMPT() macro
Message-ID<u6Tyq-2jq-29@gated-at.bofh.it>
In reply to#1695161
Back in the dim distant past, the task_struct structure's RCU-related
fields optionally included those needed for CONFIG_RCU_BOOST, even in
CONFIG_PREEMPT_RCU builds.  The INIT_TASK_RCU_TREE_PREEMPT() macro was
used to provide initializers for those optional CONFIG_RCU_BOOST fields.
However, the CONFIG_RCU_BOOST fields are now included unconditionally
in CONFIG_PREEMPT_RCU builds, so there is no longer any need fro the
INIT_TASK_RCU_TREE_PREEMPT() macro.  This commit therefore removes it
in favor of initializing the ->rcu_blocked_node field directly in the
INIT_TASK_RCU_PREEMPT() macro.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 include/linux/init_task.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index a2f6707e9fc0..0e849715e5be 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -126,17 +126,11 @@ extern struct group_info init_groups;
 #endif
 
 #ifdef CONFIG_PREEMPT_RCU
-#define INIT_TASK_RCU_TREE_PREEMPT()					\
-	.rcu_blocked_node = NULL,
-#else
-#define INIT_TASK_RCU_TREE_PREEMPT(tsk)
-#endif
-#ifdef CONFIG_PREEMPT_RCU
 #define INIT_TASK_RCU_PREEMPT(tsk)					\
 	.rcu_read_lock_nesting = 0,					\
 	.rcu_read_unlock_special.s = 0,					\
 	.rcu_node_entry = LIST_HEAD_INIT(tsk.rcu_node_entry),		\
-	INIT_TASK_RCU_TREE_PREEMPT()
+	.rcu_blocked_node = NULL,
 #else
 #define INIT_TASK_RCU_PREEMPT(tsk)
 #endif
-- 
2.5.2

[toc] | [prev] | [next] | [standalone]


#1695168 — [PATCH tip/core/rcu 3/5] EXPERIMENTAL sched: Allow migrating kthreads into online but inactive CPUs

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-07-25 00:00 +0200
Subject[PATCH tip/core/rcu 3/5] EXPERIMENTAL sched: Allow migrating kthreads into online but inactive CPUs
Message-ID<u6Tyr-2jq-39@gated-at.bofh.it>
In reply to#1695161
From: Tejun Heo <tj@kernel.org>

Per-cpu workqueues have been tripping CPU affinity sanity checks while
a CPU is being offlined.  A per-cpu kworker ends up running on a CPU
which isn't its target CPU while the CPU is online but inactive.

While the scheduler allows kthreads to wake up on an online but
inactive CPU, it doesn't allow a running kthread to be migrated to
such a CPU, which leads to an odd situation where setting affinity on
a sleeping and running kthread leads to different results.

Each mem-reclaim workqueue has one rescuer which guarantees forward
progress and the rescuer needs to bind itself to the CPU which needs
help in making forward progress; however, due to the above issue,
while set_cpus_allowed_ptr() succeeds, the rescuer doesn't end up on
the correct CPU if the CPU is in the process of going offline,
tripping the sanity check and executing the work item on the wrong
CPU.

This patch updates __migrate_task() so that kthreads can be migrated
into an inactive but online CPU.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/sched/core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 17c667b427b4..bfee6ea7db49 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -951,8 +951,13 @@ struct migration_arg {
 static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
 				 struct task_struct *p, int dest_cpu)
 {
-	if (unlikely(!cpu_active(dest_cpu)))
-		return rq;
+	if (p->flags & PF_KTHREAD) {
+		if (unlikely(!cpu_online(dest_cpu)))
+			return rq;
+	} else {
+		if (unlikely(!cpu_active(dest_cpu)))
+			return rq;
+	}
 
 	/* Affinity changed (again). */
 	if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
-- 
2.5.2

[toc] | [prev] | [next] | [standalone]


#1695169 — [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-07-25 00:00 +0200
Subject[PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible
Message-ID<u6Tyr-2jq-45@gated-at.bofh.it>
In reply to#1695161
From: Wanpeng Li <wanpeng.li@hotmail.com>

 BUG: using smp_processor_id() in preemptible [00000000] code: 99-trinity/181
 caller is debug_smp_processor_id+0x17/0x19
 CPU: 0 PID: 181 Comm: 99-trinity Not tainted 4.12.0-01059-g2a42eb9 #1
 Call Trace:
  dump_stack+0x82/0xb8
  check_preemption_disabled+0xd1/0xe3
  debug_smp_processor_id+0x17/0x19
  vtime_delta+0xd/0x2c
  task_cputime+0x89/0xdb
  thread_group_cputime+0x11b/0x1ed
  thread_group_cputime_adjusted+0x1f/0x47
  wait_consider_task+0x2a9/0xaf9
  ? lock_acquire+0x97/0xa4
  do_wait+0xdf/0x1f4
  SYSC_wait4+0x8e/0xb5
  ? list_add+0x34/0x34
  SyS_wait4+0x9/0xb
  do_syscall_64+0x70/0x82
  entry_SYSCALL64_slow_path+0x25/0x25

As Frederic pointed out:

| Although those sched_clock_cpu() things seem to only matter when the
| sched_clock() is unstable. And that stability is a condition for nohz_full
| to work anyway. So probably sched_clock() alone would be enough.

This patch fixes it by replacing sched_clock_cpu() in vtime_delta() by
sched_clock() to avoid to call smp_processor_id() in preemptible context.

Reported-by: Xiaolong Ye <xiaolong.ye@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/sched/cputime.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 6e3ea4ac1bda..14d2dbf97c53 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -683,7 +683,7 @@ static u64 vtime_delta(struct vtime *vtime)
 {
 	unsigned long long clock;
 
-	clock = sched_clock_cpu(smp_processor_id());
+	clock = sched_clock();
 	if (clock < vtime->starttime)
 		return 0;
 
@@ -814,7 +814,7 @@ void arch_vtime_task_switch(struct task_struct *prev)
 
 	write_seqcount_begin(&vtime->seqcount);
 	vtime->state = VTIME_SYS;
-	vtime->starttime = sched_clock_cpu(smp_processor_id());
+	vtime->starttime = sched_clock();
 	write_seqcount_end(&vtime->seqcount);
 }
 
@@ -826,7 +826,7 @@ void vtime_init_idle(struct task_struct *t, int cpu)
 	local_irq_save(flags);
 	write_seqcount_begin(&vtime->seqcount);
 	vtime->state = VTIME_SYS;
-	vtime->starttime = sched_clock_cpu(cpu);
+	vtime->starttime = sched_clock();
 	write_seqcount_end(&vtime->seqcount);
 	local_irq_restore(flags);
 }
-- 
2.5.2

[toc] | [prev] | [next] | [standalone]


#1695175 — Re: [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible

FromWanpeng Li <kernellwp@gmail.com>
Date2017-07-25 00:10 +0200
SubjectRe: [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible
Message-ID<u6TI5-2Df-9@gated-at.bofh.it>
In reply to#1695169
2017-07-25 5:58 GMT+08:00 Paul E. McKenney <paulmck@linux.vnet.ibm.com>:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
>  BUG: using smp_processor_id() in preemptible [00000000] code: 99-trinity/181

What's the meaning of EXP? Btw, the patch is in linus's tree currently.

Regards,
Wanpeng Li

[toc] | [prev] | [next] | [standalone]


#1695213 — Re: [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-07-25 00:30 +0200
SubjectRe: [PATCH tip/core/rcu 5/5] EXP: sched/cputime: Fix using smp_processor_id() in preemptible
Message-ID<u6U1u-2LB-71@gated-at.bofh.it>
In reply to#1695175
On Tue, Jul 25, 2017 at 06:01:55AM +0800, Wanpeng Li wrote:
> 2017-07-25 5:58 GMT+08:00 Paul E. McKenney <paulmck@linux.vnet.ibm.com>:
> > From: Wanpeng Li <wanpeng.li@hotmail.com>
> >
> >  BUG: using smp_processor_id() in preemptible [00000000] code: 99-trinity/181
> 
> What's the meaning of EXP? Btw, the patch is in linus's tree currently.

The meaning of "EXP" is that I am not sure whether I am pushing it.
Which, since it is already in Linus's tree, I am not.  I will drop it
when I rebase onto 4.13-rc2, but I will keep it until then given that
I get rcutorture failures without it.

							Thanx, Paul

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web