lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1437669735-8786-9-git-send-email-fweisbec@gmail.com>
Date:	Thu, 23 Jul 2015 18:42:13 +0200
From:	Frederic Weisbecker <fweisbec@...il.com>
To:	LKML <linux-kernel@...r.kernel.org>
Cc:	Frederic Weisbecker <fweisbec@...il.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Preeti U Murthy <preeti@...ux.vnet.ibm.com>,
	Christoph Lameter <cl@...ux.com>,
	Ingo Molnar <mingo@...nel.org>,
	Viresh Kumar <viresh.kumar@...aro.org>,
	Rik van Riel <riel@...hat.com>
Subject: [PATCH 08/10] posix-cpu-timers: Migrate to use new tick dependency mask model

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@...ux.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Preeti U Murthy <preeti@...ux.vnet.ibm.com>
Cc: Rik van Riel <riel@...hat.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Viresh Kumar <viresh.kumar@...aro.org>
Signed-off-by: Frederic Weisbecker <fweisbec@...il.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ