Skip to contentSkip to conversation

high_res_timers: precisely update_process_times; Take2

PATCH New Karsten Wiese 1 participant 1 message Jan 28, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 high_res_timers: precisely update_process_times; Take2

With NO_HZ or HIGH_RES_TIMERS update_process_times() can be called, when jiffies increments != 1 have to be acounted for. Cope with these situations by splitting update_process_times() into __update_process_times() and tick().
New in Take 2 is an attempt to make patch work for SMP also. This is done by adding

	unsigned long	update_process_times_jiffies;

to per cpu struct tick_sched.
update_process_times_jiffies is set whenever an unseen yet jiffies value is seen by a particular cpu after calls to tick_do_update_jiffies64(). Fixes cpufreq_ondemand going nuts here on an AMD64 UP running 2.6.20-rc6-rt2. Does it work on SMP? (don't have any)

include/linux/sched.h +7 -0
diff -pur rc6-rt2/include/linux/sched.h rc6-rt2-kw/include/linux/sched.h
@@ -264,6 +264,13 @@ long io_schedule_timeout(long timeout);
 extern void cpu_init (void);
 extern void trap_init(void);
 extern void update_process_times(int user);
+#ifdef CONFIG_HIGH_RES_TIMERS
+extern void __update_process_times(int user_tick, unsigned long ticks);
+extern void tick(int user_tick);
+#define NO_HIGH_RES_TIMERS_STATIC
+#else
+#define NO_HIGH_RES_TIMERS_STATIC static
+#endif
 extern void scheduler_tick(void);
 
 #ifdef CONFIG_GENERIC_HARDIRQS

Nur in rc6-rt2-kw/include/linux: sched.h~.

include/linux/tick.h +1 -0
diff -pur rc6-rt2/include/linux/tick.h rc6-rt2-kw/include/linux/tick.h
@@ -56,6 +56,7 @@ struct tick_sched {
 	unsigned long			last_jiffies;
 	unsigned long			next_jiffies;
 	ktime_t				idle_expires;
+	unsigned long			update_process_times_jiffies;
 };
 
 extern void __init tick_init(void);
kernel/time/tick-common.c +4 -0
diff -pur rc6-rt2/kernel/time/tick-common.c rc6-rt2-kw/kernel/time/tick-common.c
@@ -57,6 +57,8 @@ int tick_is_oneshot_available(void)
  */
 static void tick_periodic(int cpu)
 {
+	struct tick_sched *ts = tick_get_tick_sched(smp_processor_id());
+
 	if (tick_do_timer_cpu == cpu) {
 		write_seqlock(&xtime_lock);
 
@@ -67,6 +69,8 @@ static void tick_periodic(int cpu)
 		write_sequnlock(&xtime_lock);
 	}
 
+	ts->update_process_times_jiffies = jiffies;
+
 	update_process_times(user_mode(get_irq_regs()));
 //	profile_tick(CPU_PROFILING);
 }

Nur in rc6-rt2-kw/kernel/time: tick-common.c~.

kernel/time/tick-sched.c +52 -27

143 lines not on this page · raw message

Nur in rc6-rt2-kw/kernel/time: tick-sched.c~.

kernel/timer.c +22 -8
diff -pur rc6-rt2/kernel/timer.c rc6-rt2-kw/kernel/timer.c
@@ -1312,20 +1312,24 @@ static void update_wall_time(void)
 	update_vsyscall(&xtime, clock);
 }
 
-/*
- * Called from the timer interrupt handler to charge one tick to the current 
- * process.  user_tick is 1 if the tick is user time, 0 for system.
- */
-void update_process_times(int user_tick)
+NO_HIGH_RES_TIMERS_STATIC
+void __update_process_times(int user_tick, unsigned long ticks)
 {
-	int cpu = smp_processor_id();
 	struct task_struct *p = current;
 
 	/* Note: this timer irq context must be accounted for as well. */
 	if (user_tick)
-		account_user_time(p, jiffies_to_cputime(1));
+		account_user_time(p, jiffies_to_cputime(ticks));
 	else
-		account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1));
+		account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(ticks));
+}
+
+NO_HIGH_RES_TIMERS_STATIC
+void tick(int user_tick)
+{
+	int cpu = smp_processor_id();
+	struct task_struct *p = current;
+
 	scheduler_tick();
 	run_local_timers();
 	if (rcu_pending(cpu))
@@ -1334,6 +1338,16 @@ void update_process_times(int user_tick)
 }
 
 /*
+ * Called from the timer interrupt handler to charge one tick to the current 
+ * process.  user_tick is 1 if the tick is user time, 0 for system.
+ */
+void update_process_times(int user_tick)
+{
+	__update_process_times(user_tick, 1);
+	tick(user_tick);
+}
+
+/*
  * Nr of active tasks - counted in fixed-point numbers
  */
 static unsigned long count_active_tasks(void)