Skip to contentSkip to conversation

virtual sched_clock() for s390

RFC PATCH New Jan Glauber 1 participant 1 message Oct 23, 2007 s390

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 virtual sched_clock() for s390

From: Jan Glauber <[email protected]>
From: Christian Borntraeger <[email protected]>

This patch introduces a cpu time clock for s390 (only ticking if the virtual cpu is running) and bases the s390 implementation of sched_clock() on it.

The time slice length on a virtual cpu can be anything between the calculated time slice and zero. In reality this doesn't seem to be problem, since the scheduler is fair enough to not let a single process starve but the current implementation can lead to inefficient short time slices.

By providing a 'virtual' sched_clock() we improve the scheduler fairness, regardless of scheduling decisions from the hypervisor. We also lay a foundation to base process accouting on virtual cpu time without CONFIG_VIRT_CPU_ACCOUNTING.

---
 arch/s390/kernel/time.c  |   30 +++++++++++++++++----------
 arch/s390/kernel/vtime.c |   52 ++++++++++++++++++++++++++++++++++++++++++++---
 include/asm-s390/timer.h |    2 +
 3 files changed, 70 insertions(+), 14 deletions(-)
arch/s390/kernel/time.c +19 -11
Index: linux-2.6/arch/s390/kernel/time.c
===================================================================
@@ -62,21 +62,27 @@ static u64 jiffies_timer_cc;
 static u64 xtime_cc;
 
 /*
- * Scheduler clock - returns current time in nanosec units.
+ * Monotonic_clock - returns # of nanoseconds passed since time_init()
  */
-unsigned long long sched_clock(void)
+unsigned long long monotonic_clock(void)
 {
-	return ((get_clock() - jiffies_timer_cc) * 125) >> 9;
+	return ((get_clock() - jiffies_timer_cc) >> 9) * 125;
 }
+EXPORT_SYMBOL(monotonic_clock);
 
 /*
- * Monotonic_clock - returns # of nanoseconds passed since time_init()
+ * Scheduler clock - returns current time in nanosec units.
+ * Now based on virtual cpu time to only account time the guest
+ * was actually running.
  */
-unsigned long long monotonic_clock(void)
+unsigned long long sched_clock(void)
 {
-	return sched_clock();
+#ifdef CONFIG_VIRT_TIMER
+	return s390_cpu_clock();
+#else
+	return monotonic_clock();
+#endif
 }
-EXPORT_SYMBOL(monotonic_clock);
 
 void tod_to_timeval(__u64 todval, struct timespec *xtime)
 {
@@ -348,13 +354,15 @@ void __init time_init(void)
 	/* Enable TOD clock interrupts on the boot cpu. */
 	init_cpu_timer();
 
-#ifdef CONFIG_NO_IDLE_HZ
-	nohz_init();
-#endif
-
+	/* The virtual timer must be ready on the first tick, therefore,
+	   The vtime notifier callback must be registered first */
 #ifdef CONFIG_VIRT_TIMER
 	vtime_init();
 #endif
+
+#ifdef CONFIG_NO_IDLE_HZ
+	nohz_init();
+#endif
 }
 
 /*
arch/s390/kernel/vtime.c +49 -3

89 lines not on this page · raw message

include/asm-s390/timer.h +2 -0
Index: linux-2.6/include/asm-s390/timer.h
===================================================================
@@ -48,6 +48,8 @@ extern int del_virt_timer(struct vtimer_
 extern void init_cpu_vtimer(void);
 extern void vtime_init(void);
 
+extern unsigned long long s390_cpu_clock(void);
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_S390_TIMER_H */