From: tip-bot for Frederic Weisbecker <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: fweisbec@gmail.com, riel@redhat.com,
linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com,
mingo@kernel.org, oleg@redhat.com, umgwanakikbuti@gmail.com,
peterz@infradead.org, davej@redhat.com,
rafael.j.wysocki@intel.com, schwidefsky@de.ibm.com, bp@alien8.de,
cmetcalf@ezchip.com, tglx@linutronix.de, hpa@zytor.com
Subject: [tip:timers/nohz] context_tracking: Inherit TIF_NOHZ through forks instead of context switches
Date: Thu, 7 May 2015 04:31:29 -0700 [thread overview]
Message-ID: <tip-fafe870f31212a72f3c2d74e7b90e4ef39e83ee1@git.kernel.org> (raw)
In-Reply-To: <1430928266-24888-3-git-send-email-fweisbec@gmail.com>
Commit-ID: fafe870f31212a72f3c2d74e7b90e4ef39e83ee1
Gitweb: http://git.kernel.org/tip/fafe870f31212a72f3c2d74e7b90e4ef39e83ee1
Author: Frederic Weisbecker <fweisbec@gmail.com>
AuthorDate: Wed, 6 May 2015 18:04:24 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 7 May 2015 12:02:51 +0200
context_tracking: Inherit TIF_NOHZ through forks instead of context switches
TIF_NOHZ is used by context_tracking to force syscall slow-path
on every task in order to track userspace roundtrips. As such,
it must be set on all running tasks.
It's currently explicitly inherited through context switches.
There is no need to do it in this fast-path though. The flag
could simply be set once for all on all tasks, whether they are
running or not.
Lets do this by setting the flag for the init task on early boot,
and let it propagate through fork inheritance.
While at it, mark context_tracking_cpu_set() as init code, we
only need it at early boot time.
Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Reviewed-by: Rik van Riel <riel@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Dave Jones <davej@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Mike Galbraith <umgwanakikbuti@gmail.com>
Cc: Paul E . McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J . Wysocki <rafael.j.wysocki@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1430928266-24888-3-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
include/linux/context_tracking.h | 10 ---------
include/linux/sched.h | 3 +++
kernel/context_tracking.c | 44 +++++++++++++++++-----------------------
kernel/sched/core.c | 1 -
4 files changed, 22 insertions(+), 36 deletions(-)
diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index 2821838..b96bd29 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -14,8 +14,6 @@ extern void context_tracking_enter(enum ctx_state state);
extern void context_tracking_exit(enum ctx_state state);
extern void context_tracking_user_enter(void);
extern void context_tracking_user_exit(void);
-extern void __context_tracking_task_switch(struct task_struct *prev,
- struct task_struct *next);
static inline void user_enter(void)
{
@@ -51,19 +49,11 @@ static inline void exception_exit(enum ctx_state prev_ctx)
}
}
-static inline void context_tracking_task_switch(struct task_struct *prev,
- struct task_struct *next)
-{
- if (context_tracking_is_enabled())
- __context_tracking_task_switch(prev, next);
-}
#else
static inline void user_enter(void) { }
static inline void user_exit(void) { }
static inline enum ctx_state exception_enter(void) { return 0; }
static inline void exception_exit(enum ctx_state prev_ctx) { }
-static inline void context_tracking_task_switch(struct task_struct *prev,
- struct task_struct *next) { }
#endif /* !CONFIG_CONTEXT_TRACKING */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 26a2e61..185a750 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2532,6 +2532,9 @@ static inline unsigned long wait_task_inactive(struct task_struct *p,
}
#endif
+#define tasklist_empty() \
+ list_empty(&init_task.tasks)
+
#define next_task(p) \
list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c
index 5b11a10..0a495ab 100644
--- a/kernel/context_tracking.c
+++ b/kernel/context_tracking.c
@@ -30,14 +30,6 @@ EXPORT_SYMBOL_GPL(context_tracking_enabled);
DEFINE_PER_CPU(struct context_tracking, context_tracking);
EXPORT_SYMBOL_GPL(context_tracking);
-void context_tracking_cpu_set(int cpu)
-{
- if (!per_cpu(context_tracking.active, cpu)) {
- per_cpu(context_tracking.active, cpu) = true;
- static_key_slow_inc(&context_tracking_enabled);
- }
-}
-
static bool context_tracking_recursion_enter(void)
{
int recursion;
@@ -193,24 +185,26 @@ void context_tracking_user_exit(void)
}
NOKPROBE_SYMBOL(context_tracking_user_exit);
-/**
- * __context_tracking_task_switch - context switch the syscall callbacks
- * @prev: the task that is being switched out
- * @next: the task that is being switched in
- *
- * The context tracking uses the syscall slow path to implement its user-kernel
- * boundaries probes on syscalls. This way it doesn't impact the syscall fast
- * path on CPUs that don't do context tracking.
- *
- * But we need to clear the flag on the previous task because it may later
- * migrate to some CPU that doesn't do the context tracking. As such the TIF
- * flag may not be desired there.
- */
-void __context_tracking_task_switch(struct task_struct *prev,
- struct task_struct *next)
+void __init context_tracking_cpu_set(int cpu)
{
- clear_tsk_thread_flag(prev, TIF_NOHZ);
- set_tsk_thread_flag(next, TIF_NOHZ);
+ static __initdata bool initialized = false;
+
+ if (!per_cpu(context_tracking.active, cpu)) {
+ per_cpu(context_tracking.active, cpu) = true;
+ static_key_slow_inc(&context_tracking_enabled);
+ }
+
+ if (initialized)
+ return;
+
+ /*
+ * Set TIF_NOHZ to init/0 and let it propagate to all tasks through fork
+ * This assumes that init is the only task at this early boot stage.
+ */
+ set_tsk_thread_flag(&init_task, TIF_NOHZ);
+ WARN_ON_ONCE(!tasklist_empty());
+
+ initialized = true;
}
#ifdef CONFIG_CONTEXT_TRACKING_FORCE
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fe22f75..54f032c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2332,7 +2332,6 @@ context_switch(struct rq *rq, struct task_struct *prev,
*/
spin_release(&rq->lock.dep_map, 1, _THIS_IP_);
- context_tracking_task_switch(prev, next);
/* Here we just switch the register state and the stack. */
switch_to(prev, next, prev);
barrier();
next prev parent reply other threads:[~2015-05-07 11:32 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 16:04 [GIT PULL] nohz: A few improvements v4 Frederic Weisbecker
2015-05-06 16:04 ` [PATCH 1/4] context_tracking: Protect against recursion Frederic Weisbecker
2015-05-07 9:58 ` Ingo Molnar
2015-05-07 11:53 ` Frederic Weisbecker
2015-05-07 11:31 ` [tip:timers/nohz] " tip-bot for Frederic Weisbecker
2015-05-06 16:04 ` [PATCH 2/4] context_tracking: Inherit TIF_NOHZ through forks instead of context switches Frederic Weisbecker
2015-05-07 11:31 ` tip-bot for Frederic Weisbecker [this message]
2015-05-06 16:04 ` [PATCH 3/4] nohz: Add tick_nohz_full_add_cpus_to() API Frederic Weisbecker
2015-05-07 11:31 ` [tip:timers/nohz] " tip-bot for Chris Metcalf
2015-05-06 16:04 ` [PATCH 4/4] nohz: Set isolcpus when nohz_full is set Frederic Weisbecker
2015-05-07 11:32 ` [tip:timers/nohz] " tip-bot for Chris Metcalf
2015-05-16 19:39 ` [PATCH 4/4] " Sasha Levin
2015-05-17 5:30 ` Mike Galbraith
2015-05-18 2:17 ` Rik van Riel
2015-05-18 3:29 ` Mike Galbraith
2015-05-18 14:07 ` Rik van Riel
2015-05-18 14:22 ` Mike Galbraith
2015-05-18 14:52 ` Rik van Riel
2015-05-19 2:30 ` Mike Galbraith
2015-06-12 19:12 ` Rik van Riel
2015-05-20 20:38 ` Afzal Mohammed
2015-05-20 21:00 ` Paul E. McKenney
2015-05-21 12:12 ` Afzal Mohammed
2015-05-21 12:57 ` Paul E. McKenney
2015-05-21 13:06 ` Frederic Weisbecker
2015-05-21 13:27 ` Paul E. McKenney
2015-05-21 13:29 ` Afzal Mohammed
2015-05-21 14:14 ` Paul E. McKenney
2015-05-21 14:46 ` Frederic Weisbecker
2015-05-21 18:59 ` Mike Galbraith
2015-05-22 14:39 ` Frederic Weisbecker
2015-05-22 15:20 ` Mike Galbraith
-- strict thread matches above, loose matches on Subject: below --
2015-04-03 16:24 [PATCH 1/2] nohz: add tick_nohz_full_set_cpus() API cmetcalf
2015-04-03 16:24 ` [PATCH 2/2] nohz: make nohz_full imply isolcpus cmetcalf
2015-04-03 17:42 ` Frederic Weisbecker
2015-04-03 19:20 ` Chris Metcalf
2015-04-04 14:10 ` Rik van Riel
2015-04-04 17:09 ` Chris Metcalf
2015-04-05 5:05 ` Ingo Molnar
2015-04-06 17:15 ` Chris Metcalf
2015-04-06 18:16 ` [PATCH v2 1/2] nohz: add tick_nohz_full_clear_cpus() and _set_cpus() APIs cmetcalf
2015-04-06 18:16 ` [PATCH v2 2/2] nohz: make nohz_full imply isolcpus cmetcalf
2015-04-07 22:29 ` Frederic Weisbecker
2015-04-08 9:41 ` Peter Zijlstra
2015-04-08 14:04 ` Chris Metcalf
2015-04-08 14:26 ` Peter Zijlstra
2015-04-08 15:21 ` Chris Metcalf
2015-04-08 17:24 ` Frederic Weisbecker
2015-04-08 19:20 ` [PATCH v3 1/2] nohz: add tick_nohz_full_clear_cpus() and _set_cpus() APIs cmetcalf
2015-04-08 19:20 ` [PATCH v3 2/2] nohz: set isolcpus when nohz_full is set cmetcalf
2015-04-08 17:27 ` [PATCH v2 2/2] nohz: make nohz_full imply isolcpus Peter Zijlstra
2015-04-08 18:12 ` Chris Metcalf
2015-04-09 8:29 ` Peter Zijlstra
2015-04-09 12:02 ` Chris Metcalf
2015-04-09 12:45 ` Frederic Weisbecker
2015-04-09 16:59 ` [PATCH v5] nohz: set isolcpus when nohz_full is set Chris Metcalf
2015-04-09 17:12 ` Peter Zijlstra
2015-04-10 1:05 ` Mike Galbraith
2015-04-10 15:33 ` Chris Metcalf
2015-04-10 15:57 ` Mike Galbraith
2015-04-09 17:00 ` [PATCH v4 1/2] nohz: add tick_nohz_full_cpumask_or() and _andnot() APIs Chris Metcalf
2015-04-09 17:00 ` [PATCH v4 2/2] nohz: set isolcpus when nohz_full is set Chris Metcalf
2015-04-09 17:07 ` [PATCH v4 1/2] nohz: add tick_nohz_full_cpumask_or() and _andnot() APIs Peter Zijlstra
2015-04-09 17:24 ` Chris Metcalf
2015-04-09 17:42 ` Peter Zijlstra
2015-04-09 18:01 ` [PATCH v6 1/2] nohz: add tick_nohz_full_add_cpus_to() and _remove_cpus_from() APIs Chris Metcalf
2015-04-09 18:01 ` [PATCH v6 2/2] nohz: set isolcpus when nohz_full is set Chris Metcalf
2015-04-10 1:37 ` Frederic Weisbecker
2015-04-10 20:53 ` [PATCH v7 1/2] nohz: add tick_nohz_full_add_cpus_to() and _remove_cpus_from() APIs Chris Metcalf
2015-04-10 20:53 ` [PATCH v7 2/2] nohz: set isolcpus when nohz_full is set Chris Metcalf
2015-04-14 0:37 ` Frederic Weisbecker
2015-04-14 15:17 ` [PATCH v8 1/2] nohz: add tick_nohz_full_add_cpus_to() API Chris Metcalf
2015-04-14 15:17 ` [PATCH v8 2/2] nohz: set isolcpus when nohz_full is set Chris Metcalf
2015-04-14 15:26 ` Frederic Weisbecker
2015-04-14 16:45 ` Peter Zijlstra
2015-04-14 0:33 ` [PATCH v7 1/2] nohz: add tick_nohz_full_add_cpus_to() and _remove_cpus_from() APIs Frederic Weisbecker
2015-04-14 0:49 ` Chris Metcalf
2015-04-14 15:34 ` Frederic Weisbecker
2015-04-10 1:34 ` [PATCH v6 " Frederic Weisbecker
2015-04-10 15:31 ` Chris Metcalf
2015-04-06 18:29 ` [PATCH v2 1/2] nohz: add tick_nohz_full_clear_cpus() and _set_cpus() APIs Frederic Weisbecker
2015-04-06 19:09 ` Chris Metcalf
2015-04-07 9:33 ` Ingo Molnar
2015-04-03 18:08 ` [PATCH 2/2] nohz: make nohz_full imply isolcpus Mike Galbraith
2015-04-03 19:21 ` Chris Metcalf
2015-04-04 2:03 ` Mike Galbraith
2015-04-04 3:43 ` Mike Galbraith
2015-04-06 19:28 ` Rik van Riel
2015-04-07 3:10 ` Mike Galbraith
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=tip-fafe870f31212a72f3c2d74e7b90e4ef39e83ee1@git.kernel.org \
--to=tipbot@zytor.com \
--cc=bp@alien8.de \
--cc=cmetcalf@ezchip.com \
--cc=davej@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rafael.j.wysocki@intel.com \
--cc=riel@redhat.com \
--cc=schwidefsky@de.ibm.com \
--cc=tglx@linutronix.de \
--cc=umgwanakikbuti@gmail.com \
/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 NNTP newsgroup(s).