From: Frederic Weisbecker <fweisbec@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Preeti U Murthy <preeti@linux.vnet.ibm.com>,
Christoph Lameter <cl@linux.com>, Ingo Molnar <mingo@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Rik van Riel <riel@redhat.com>
Subject: [PATCH 08/10] posix-cpu-timers: Migrate to use new tick dependency mask model
Date: Thu, 23 Jul 2015 18:42:13 +0200 [thread overview]
Message-ID: <1437669735-8786-9-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1437669735-8786-1-git-send-email-fweisbec@gmail.com>
Instead of providing asynchronous checks for the nohz subsystem to verify
posix cpu timers tick dependency, migrate the latter to the new mask.
In order to keep track of the running timers and expose the tick
dependency accordingly, we must probe the timers queuing and dequeuing
on threads and process lists.
Cc: Christoph Lameter <cl@linux.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
include/linux/posix-timers.h | 3 --
kernel/time/posix-cpu-timers.c | 92 +++++++++++++++++++++---------------------
kernel/time/tick-sched.c | 5 ---
3 files changed, 47 insertions(+), 53 deletions(-)
diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index 907f3fd..62d44c1 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -128,9 +128,6 @@ void posix_cpu_timer_schedule(struct k_itimer *timer);
void run_posix_cpu_timers(struct task_struct *task);
void posix_cpu_timers_exit(struct task_struct *task);
void posix_cpu_timers_exit_group(struct task_struct *task);
-
-bool posix_cpu_timers_can_stop_tick(struct task_struct *tsk);
-
void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,
cputime_t *newval, cputime_t *oldval);
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 892e3da..d343c39 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -333,6 +333,46 @@ static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
return err;
}
+#ifdef CONFIG_NO_HZ_FULL
+static atomic_t cpu_timer_active;
+
+static void cpu_timer_inc_tick_dependency(void)
+{
+ if (atomic_inc_return(&cpu_timer_active) == 1)
+ tick_nohz_set_tick_dependency_delayed(TICK_POSIX_TIMER_BIT);
+}
+
+static void cpu_timer_dec_tick_dependency(void)
+{
+ if (atomic_dec_and_test(&cpu_timer_active))
+ tick_nohz_clear_tick_dependency(TICK_POSIX_TIMER_BIT);
+}
+#else
+static void cpu_timer_inc_tick_dependency(void) { }
+static void cpu_timer_dec_tick_dependency(void) { }
+#endif
+
+static void cpu_timer_list_prepare_firing(struct cpu_timer_list *t,
+ struct list_head *firing)
+{
+ list_move_tail(&t->entry, firing);
+ cpu_timer_dec_tick_dependency();
+}
+
+static void cpu_timer_list_dequeue(struct cpu_timer_list *t)
+{
+ if (!list_empty(&t->entry))
+ cpu_timer_dec_tick_dependency();
+ list_del_init(&t->entry);
+}
+
+static void cpu_timer_list_enqueue(struct cpu_timer_list *t,
+ struct list_head *head)
+{
+ list_add(&t->entry, head);
+ cpu_timer_inc_tick_dependency();
+}
+
/*
* Validate the clockid_t for a new CPU-clock timer, and initialize the timer.
@@ -409,7 +449,7 @@ static int posix_cpu_timer_del(struct k_itimer *timer)
if (timer->it.cpu.firing)
ret = TIMER_RETRY;
else
- list_del(&timer->it.cpu.entry);
+ cpu_timer_list_dequeue(&timer->it.cpu);
unlock_task_sighand(p, &flags);
}
@@ -425,7 +465,7 @@ static void cleanup_timers_list(struct list_head *head)
struct cpu_timer_list *timer, *next;
list_for_each_entry_safe(timer, next, head, entry)
- list_del_init(&timer->entry);
+ cpu_timer_list_dequeue(timer);
}
/*
@@ -490,7 +530,7 @@ static void arm_timer(struct k_itimer *timer)
break;
listpos = &next->entry;
}
- list_add(&nt->entry, listpos);
+ cpu_timer_list_enqueue(nt, listpos);
if (listpos == head) {
unsigned long long exp = nt->expires;
@@ -582,39 +622,6 @@ static int cpu_timer_sample_group(const clockid_t which_clock,
return 0;
}
-#ifdef CONFIG_NO_HZ_FULL
-static void nohz_kick_work_fn(struct work_struct *work)
-{
- tick_nohz_full_kick_all();
-}
-
-static DECLARE_WORK(nohz_kick_work, nohz_kick_work_fn);
-
-/*
- * We need the IPIs to be sent from sane process context.
- * The posix cpu timers are always set with irqs disabled.
- */
-static void posix_cpu_timer_kick_nohz(void)
-{
- if (context_tracking_is_enabled())
- schedule_work(&nohz_kick_work);
-}
-
-bool posix_cpu_timers_can_stop_tick(struct task_struct *tsk)
-{
- if (!task_cputime_zero(&tsk->cputime_expires))
- return false;
-
- /* Check if cputimer is running. This is accessed without locking. */
- if (READ_ONCE(tsk->signal->cputimer.running))
- return false;
-
- return true;
-}
-#else
-static inline void posix_cpu_timer_kick_nohz(void) { }
-#endif
-
/*
* Guts of sys_timer_settime for CPU timers.
* This is called with the timer locked and interrupts disabled.
@@ -659,7 +666,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
timer->it.cpu.firing = -1;
ret = TIMER_RETRY;
} else
- list_del_init(&timer->it.cpu.entry);
+ cpu_timer_list_dequeue(&timer->it.cpu);
/*
* We need to sample the current value to convert the new
@@ -761,8 +768,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
sample_to_timespec(timer->it_clock,
old_incr, &old->it_interval);
}
- if (!ret)
- posix_cpu_timer_kick_nohz();
+
return ret;
}
@@ -844,7 +850,7 @@ check_timers_list(struct list_head *timers,
return t->expires;
t->firing = 1;
- list_move_tail(&t->entry, firing);
+ cpu_timer_list_prepare_firing(t, firing);
}
return 0;
@@ -1073,8 +1079,6 @@ void posix_cpu_timer_schedule(struct k_itimer *timer)
arm_timer(timer);
unlock_task_sighand(p, &flags);
- /* Kick full dynticks CPUs in case they need to tick on the new timer */
- posix_cpu_timer_kick_nohz();
out:
timer->it_overrun_last = timer->it_overrun;
timer->it_overrun = -1;
@@ -1243,7 +1247,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
}
if (!*newval)
- goto out;
+ return;
*newval += now;
}
@@ -1261,8 +1265,6 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
tsk->signal->cputime_expires.virt_exp = *newval;
break;
}
-out:
- posix_cpu_timer_kick_nohz();
}
static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index e6447bd..4805f4e 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -192,11 +192,6 @@ static bool can_stop_full_tick(struct tick_sched *ts)
return false;
}
- if (!posix_cpu_timers_can_stop_tick(current)) {
- trace_tick_stop(0, "posix timers running\n");
- return false;
- }
-
#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
/*
* sched_clock_tick() needs us?
--
2.1.4
next prev parent reply other threads:[~2015-07-23 16:45 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 16:42 [PATCH 00/10] nohz: Tick dependency mask v2 Frederic Weisbecker
2015-07-23 16:42 ` [PATCH 01/10] nohz: Remove idle task special case Frederic Weisbecker
2015-07-23 16:42 ` [PATCH 02/10] nohz: Restart nohz full tick from irq exit Frederic Weisbecker
2015-07-23 16:42 ` [PATCH 03/10] nohz: Move tick_nohz_restart_sched_tick() above its users Frederic Weisbecker
2015-07-23 16:42 ` [PATCH 04/10] nohz: Remove useless argument on tick_nohz_task_switch() Frederic Weisbecker
2015-08-03 12:39 ` Peter Zijlstra
2015-08-03 12:49 ` Frederic Weisbecker
2015-08-03 13:04 ` Peter Zijlstra
2015-07-23 16:42 ` [PATCH 05/10] nohz: New tick dependency mask Frederic Weisbecker
2015-07-24 16:55 ` Chris Metcalf
2015-07-24 17:16 ` Frederic Weisbecker
2015-07-24 17:43 ` Chris Metcalf
2015-08-03 12:48 ` Peter Zijlstra
2015-08-03 12:43 ` Peter Zijlstra
2015-08-03 13:05 ` Frederic Weisbecker
2015-08-03 13:24 ` Peter Zijlstra
2015-08-03 13:49 ` Frederic Weisbecker
2015-08-03 12:57 ` Peter Zijlstra
2015-08-03 13:09 ` Frederic Weisbecker
2015-08-03 13:29 ` Peter Zijlstra
2015-08-03 13:55 ` Frederic Weisbecker
2015-08-03 14:11 ` Peter Zijlstra
2015-07-23 16:42 ` [PATCH 06/10] perf: Migrate perf to use new tick dependency mask model Frederic Weisbecker
2015-07-23 16:42 ` [PATCH 07/10] sched: Migrate sched " Frederic Weisbecker
2015-07-23 16:55 ` Frederic Weisbecker
2015-07-24 16:56 ` Chris Metcalf
2015-07-29 13:01 ` Frederic Weisbecker
2015-08-03 14:00 ` Peter Zijlstra
2015-08-03 14:50 ` Frederic Weisbecker
2015-08-03 17:09 ` Peter Zijlstra
2015-08-03 17:30 ` Frederic Weisbecker
2015-08-04 7:41 ` Peter Zijlstra
2015-08-10 14:02 ` Juri Lelli
2015-08-10 14:16 ` Frederic Weisbecker
2015-08-10 14:28 ` Peter Zijlstra
2015-08-10 15:11 ` Peter Zijlstra
2015-08-10 15:29 ` Frederic Weisbecker
2015-08-10 15:43 ` Juri Lelli
2015-08-10 16:41 ` Peter Zijlstra
2015-08-10 15:33 ` Christoph Lameter
2015-07-23 16:42 ` Frederic Weisbecker [this message]
2015-07-24 16:57 ` [PATCH 08/10] posix-cpu-timers: Migrate " Chris Metcalf
2015-07-29 13:23 ` Frederic Weisbecker
2015-07-29 17:24 ` Chris Metcalf
2015-07-30 0:44 ` Frederic Weisbecker
2015-07-30 14:31 ` Luiz Capitulino
2015-07-30 14:46 ` Frederic Weisbecker
2015-07-30 19:35 ` Chris Metcalf
2015-07-30 19:45 ` Frederic Weisbecker
2015-07-30 19:52 ` Chris Metcalf
2015-07-31 14:49 ` Frederic Weisbecker
2015-08-03 15:59 ` Chris Metcalf
2015-08-03 18:01 ` Frederic Weisbecker
2015-08-03 17:12 ` Peter Zijlstra
2015-08-03 17:39 ` Frederic Weisbecker
2015-08-03 19:07 ` Peter Zijlstra
2015-08-06 17:13 ` Chris Metcalf
2015-07-23 16:42 ` [PATCH 09/10] sched-clock: " Frederic Weisbecker
2015-07-23 16:42 ` [PATCH 10/10] nohz: Remove task switch obsolete tick dependency check Frederic Weisbecker
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=1437669735-8786-9-git-send-email-fweisbec@gmail.com \
--to=fweisbec@gmail.com \
--cc=cl@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=preeti@linux.vnet.ibm.com \
--cc=riel@redhat.com \
--cc=tglx@linutronix.de \
--cc=viresh.kumar@linaro.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®