mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-11-04 02:32:11 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			158 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			158 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
From 036160e2bf23c43f7a7eb4482cd372c2c5983389 Mon Sep 17 00:00:00 2001
 | 
						|
From: Anna-Maria Gleixner <anna-maria@linutronix.de>
 | 
						|
Date: Wed, 20 Dec 2017 17:13:02 +0100
 | 
						|
Subject: [PATCH 029/418] hrtimer: Reduce conditional code (hres_active)
 | 
						|
 | 
						|
The hrtimer_cpu_base struct has the CONFIG_HIGH_RES_TIMERS conditional
 | 
						|
struct member hres_active. All related functions to this member are
 | 
						|
conditional as well.
 | 
						|
 | 
						|
There is no functional change, when the hres_active member is
 | 
						|
unconditional with all related functions and is set to zero during
 | 
						|
initialization.
 | 
						|
 | 
						|
The conditional code sections can be avoided by adding IS_ENABLED(HIGHRES)
 | 
						|
conditionals into common functions, which ensures dead code elimination.
 | 
						|
 | 
						|
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
 | 
						|
Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
 | 
						|
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
 | 
						|
---
 | 
						|
 include/linux/hrtimer.h | 20 ++++++++------------
 | 
						|
 kernel/time/hrtimer.c   | 31 +++++++++++++++----------------
 | 
						|
 2 files changed, 23 insertions(+), 28 deletions(-)
 | 
						|
 | 
						|
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
 | 
						|
index 56e56bcb6f0f..22627b3a33fe 100644
 | 
						|
--- a/include/linux/hrtimer.h
 | 
						|
+++ b/include/linux/hrtimer.h
 | 
						|
@@ -161,8 +161,8 @@ enum  hrtimer_base_type {
 | 
						|
  * @cpu:		cpu number
 | 
						|
  * @active_bases:	Bitfield to mark bases with active timers
 | 
						|
  * @clock_was_set_seq:	Sequence counter of clock was set events
 | 
						|
- * @in_hrtirq:		hrtimer_interrupt() is currently executing
 | 
						|
  * @hres_active:	State of high resolution mode
 | 
						|
+ * @in_hrtirq:		hrtimer_interrupt() is currently executing
 | 
						|
  * @hang_detected:	The last hrtimer interrupt detected a hang
 | 
						|
  * @expires_next:	absolute time of the next event, is required for remote
 | 
						|
  *			hrtimer enqueue
 | 
						|
@@ -182,9 +182,9 @@ struct hrtimer_cpu_base {
 | 
						|
 	unsigned int			cpu;
 | 
						|
 	unsigned int			active_bases;
 | 
						|
 	unsigned int			clock_was_set_seq;
 | 
						|
+	unsigned int			hres_active	: 1;
 | 
						|
 #ifdef CONFIG_HIGH_RES_TIMERS
 | 
						|
 	unsigned int			in_hrtirq	: 1,
 | 
						|
-					hres_active	: 1,
 | 
						|
 					hang_detected	: 1;
 | 
						|
 	ktime_t				expires_next;
 | 
						|
 	struct hrtimer			*next_timer;
 | 
						|
@@ -266,16 +266,17 @@ static inline ktime_t hrtimer_cb_get_time(struct hrtimer *timer)
 | 
						|
 	return timer->base->get_time();
 | 
						|
 }
 | 
						|
 
 | 
						|
+static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 | 
						|
+{
 | 
						|
+	return IS_ENABLED(CONFIG_HIGH_RES_TIMERS) ?
 | 
						|
+		timer->base->cpu_base->hres_active : 0;
 | 
						|
+}
 | 
						|
+
 | 
						|
 #ifdef CONFIG_HIGH_RES_TIMERS
 | 
						|
 struct clock_event_device;
 | 
						|
 
 | 
						|
 extern void hrtimer_interrupt(struct clock_event_device *dev);
 | 
						|
 
 | 
						|
-static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 | 
						|
-{
 | 
						|
-	return timer->base->cpu_base->hres_active;
 | 
						|
-}
 | 
						|
-
 | 
						|
 /*
 | 
						|
  * The resolution of the clocks. The resolution value is returned in
 | 
						|
  * the clock_getres() system call to give application programmers an
 | 
						|
@@ -298,11 +299,6 @@ extern unsigned int hrtimer_resolution;
 | 
						|
 
 | 
						|
 #define hrtimer_resolution	(unsigned int)LOW_RES_NSEC
 | 
						|
 
 | 
						|
-static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 | 
						|
-{
 | 
						|
-	return 0;
 | 
						|
-}
 | 
						|
-
 | 
						|
 static inline void clock_was_set_delayed(void) { }
 | 
						|
 
 | 
						|
 #endif
 | 
						|
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
 | 
						|
index bedfc2865901..7e0490143275 100644
 | 
						|
--- a/kernel/time/hrtimer.c
 | 
						|
+++ b/kernel/time/hrtimer.c
 | 
						|
@@ -512,6 +512,20 @@ static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
 | 
						|
 					    offs_real, offs_boot, offs_tai);
 | 
						|
 }
 | 
						|
 
 | 
						|
+/*
 | 
						|
+ * Is the high resolution mode active ?
 | 
						|
+ */
 | 
						|
+static inline int __hrtimer_hres_active(struct hrtimer_cpu_base *cpu_base)
 | 
						|
+{
 | 
						|
+	return IS_ENABLED(CONFIG_HIGH_RES_TIMERS) ?
 | 
						|
+		cpu_base->hres_active : 0;
 | 
						|
+}
 | 
						|
+
 | 
						|
+static inline int hrtimer_hres_active(void)
 | 
						|
+{
 | 
						|
+	return __hrtimer_hres_active(this_cpu_ptr(&hrtimer_bases));
 | 
						|
+}
 | 
						|
+
 | 
						|
 /* High resolution timer related functions */
 | 
						|
 #ifdef CONFIG_HIGH_RES_TIMERS
 | 
						|
 
 | 
						|
@@ -540,19 +554,6 @@ static inline int hrtimer_is_hres_enabled(void)
 | 
						|
 	return hrtimer_hres_enabled;
 | 
						|
 }
 | 
						|
 
 | 
						|
-/*
 | 
						|
- * Is the high resolution mode active ?
 | 
						|
- */
 | 
						|
-static inline int __hrtimer_hres_active(struct hrtimer_cpu_base *cpu_base)
 | 
						|
-{
 | 
						|
-	return cpu_base->hres_active;
 | 
						|
-}
 | 
						|
-
 | 
						|
-static inline int hrtimer_hres_active(void)
 | 
						|
-{
 | 
						|
-	return __hrtimer_hres_active(this_cpu_ptr(&hrtimer_bases));
 | 
						|
-}
 | 
						|
-
 | 
						|
 /*
 | 
						|
  * Reprogram the event source with checking both queues for the
 | 
						|
  * next event
 | 
						|
@@ -662,7 +663,6 @@ static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base)
 | 
						|
 {
 | 
						|
 	base->expires_next = KTIME_MAX;
 | 
						|
 	base->hang_detected = 0;
 | 
						|
-	base->hres_active = 0;
 | 
						|
 	base->next_timer = NULL;
 | 
						|
 }
 | 
						|
 
 | 
						|
@@ -722,8 +722,6 @@ void clock_was_set_delayed(void)
 | 
						|
 
 | 
						|
 #else
 | 
						|
 
 | 
						|
-static inline int __hrtimer_hres_active(struct hrtimer_cpu_base *b) { return 0; }
 | 
						|
-static inline int hrtimer_hres_active(void) { return 0; }
 | 
						|
 static inline int hrtimer_is_hres_enabled(void) { return 0; }
 | 
						|
 static inline void hrtimer_switch_to_hres(void) { }
 | 
						|
 static inline void
 | 
						|
@@ -1605,6 +1603,7 @@ int hrtimers_prepare_cpu(unsigned int cpu)
 | 
						|
 
 | 
						|
 	cpu_base->active_bases = 0;
 | 
						|
 	cpu_base->cpu = cpu;
 | 
						|
+	cpu_base->hres_active = 0;
 | 
						|
 	hrtimer_init_hres(cpu_base);
 | 
						|
 	return 0;
 | 
						|
 }
 | 
						|
-- 
 | 
						|
2.17.1
 | 
						|
 |