Skip to contentSkip to conversation

timer: provide microaccounting for iowait in addition to idle time

RFC PATCH In review Arjan van de Ven 2 participants 2 messages Sep 24, 2009

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

RFC PATCH 1/1 timer: provide microaccounting for iowait in addition to idle time

Quoted 1 line

From f511560312467628f37578d3dd70d63849eb8c8a Mon Sep 17 00:00:00 2001

From: Arjan van de Ven <[email protected]>
Date: Thu, 24 Sep 2009 13:35:48 +0200
Subject: [PATCH] timer: provide microaccounting for iowait in addition to idle time

Today, the kernel has microaccounting for the CPU idle time, as used by cpufreq governors and other places.

For a cpufreq governor I'm working on I would also like to get access to microaccounting of iowait time.

This patch adds the iowait micro-accounting to the existing microaccounting code. In addition, I've improved the accuracy of the data by updating the totals at the time of asking for the total, rather than just reporting the total at the last schedule point.

---
 include/linux/tick.h     |    4 +++
 kernel/time/tick-sched.c |   55 ++++++++++++++++++++++++++++++++++++++++++---
 kernel/time/timer_list.c |    1 +
 3 files changed, 56 insertions(+), 4 deletions(-)
include/linux/tick.h +4 -0
index 0482229..322b3fd 100644
@@ -42,6 +42,7 @@ enum tick_nohz_mode {
  * @idle_waketime:	Time when the idle was interrupted
  * @idle_exittime:	Time when the idle state was left
  * @idle_sleeptime:	Sum of the time slept in idle with sched tick stopped
+ * @iowait_sleeptime:	Sum of the time slept in idle with sched tick stopped, with IO outstanding
  * @sleep_length:	Duration of the current idle sleep
  */
 struct tick_sched {
@@ -59,6 +60,7 @@ struct tick_sched {
 	ktime_t				idle_waketime;
 	ktime_t				idle_exittime;
 	ktime_t				idle_sleeptime;
+	ktime_t				iowait_sleeptime;
 	ktime_t				idle_lastupdate;
 	ktime_t				sleep_length;
 	unsigned long			last_jiffies;
@@ -119,6 +121,7 @@ extern void tick_nohz_stop_sched_tick(int inidle);
 extern void tick_nohz_restart_sched_tick(void);
 extern ktime_t tick_nohz_get_sleep_length(void);
 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
+extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
 # else
 static inline void tick_nohz_stop_sched_tick(int inidle) { }
 static inline void tick_nohz_restart_sched_tick(void) { }
@@ -129,6 +132,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
 	return len;
 }
 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
+static inline u64 get_cpu_iowait(int cpu, u64 *unused) { return -1; }
 # endif /* !NO_HZ */
 
 #endif
kernel/time/tick-sched.c +51 -4

82 lines not on this page · raw message

kernel/time/timer_list.c +1 -0
index fddd69d..3965f20 100644
@@ -173,6 +173,7 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
 		P_ns(idle_waketime);
 		P_ns(idle_exittime);
 		P_ns(idle_sleeptime);
+		P_ns(iowait_sleeptime);
 		P(last_jiffies);
 		P(next_jiffies);
 		P_ns(idle_expires);
Signature · 8 lines
1.6.0.6



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#1 lore raw
Quoted 23 lines · On Thu, 24 Sep 2009 13:39:38 +0200 Arjan van de Ven <[email protected]> wrote:
kernel/time/tick-sched.c +11 -4
@@ -190,19 +195,61 @@ static ktime_t tick_nohz_start_idle(struct tick_sched *ts)
 u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time)
 {
 	struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
+	ktime_t now, delta;
 
 	if (!tick_nohz_enabled)
 		return -1;
 
-	if (ts->idle_active)
-		*last_update_time = ktime_to_us(ts->idle_lastupdate);
-	else
-		*last_update_time = ktime_to_us(ktime_get());
+	now = ktime_get();
+	if (ts->idle_active) {
+		delta = ktime_sub(now, ts->idle_entrytime);
+		ts->idle_lastupdate = now;
+		ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
+		if (nr_iowait_cpu()>0)
+			ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta);
+		ts->idle_entrytime = now;
+	}
+

kernel/time/tick-sched.c static ktime_t tick_nohz_start_idle(struct tick_sched *ts) · line 222

Quoted 10 lines
kernel/time/tick-sched.c +6 -0
+	if (last_update_time) {
+		if (ts->idle_active)
+			*last_update_time = ktime_to_us(ts->idle_lastupdate);
+		else
+			*last_update_time = ktime_to_us(ktime_get());
+	}
 
 	return ktime_to_us(ts->idle_sleeptime);
 }
 EXPORT_SYMBOL_GPL(get_cpu_idle_time_us);

Is the second ktime_get() call really necessary? Why can't "now" be reused?

Quoted 18 lines
kernel/time/tick-sched.c +18 -0
+u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time)
+{
+	struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
+	ktime_t now, delta;
+
+	if (!tick_nohz_enabled)
+		return -1;
+
+	now = ktime_get();
+	if (ts->idle_active) {
+		delta = ktime_sub(now, ts->idle_entrytime);
+		ts->idle_lastupdate = now;
+		ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
+		if (nr_iowait_cpu()>0)
+			ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta);
+		ts->idle_entrytime = now;
+	}
+

kernel/time/tick-sched.c static ktime_t tick_nohz_start_idle(struct tick_sched *ts) · line 251

Quoted 10 lines
kernel/time/tick-sched.c +10 -0
+	if (last_update_time) {
+		if (ts->idle_active)
+			*last_update_time = ktime_to_us(ts->idle_lastupdate);
+		else
+			*last_update_time = ktime_to_us(ktime_get());
+	}
+
+	return ktime_to_us(ts->iowait_sleeptime);
+}
+EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us);

Same here.

But except for the superfluous ktime_gets I have no objections.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.