Input: analog: Always use ktime functions
Subsystems (2)
PATCH 1/1 Input: analog: Always use ktime functions
m68k, mips, s390, and sparc allmodconfig images fail to build with the following error.
drivers/input/joystick/analog.c:160:2: error:
#warning Precise timer not defined for this architecture.
Remove architecture specific time handling code and always use ktime functions to determine time deltas. Also remove the now useless use_ktime kernel parameter.
--- drivers/input/joystick/analog.c | 74 ++------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-)
drivers/input/joystick/analog.c +3 -71
@@ -28,10 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");MODULE_DESCRIPTION (DRIVER_DESC );MODULE_LICENSE ("GPL" ); -static bool use_ktime = true; -module_param (use_ktime, bool,0400 ); -MODULE_PARM_DESC (use_ktime,"Use ktime for measuring I/O speed" ); -/* * Option parsing. */
@@ -119,64 +115,14 @@ struct analog_port {int axtime; }; -/* -* Time macros. -*/ - -#ifdef __i386__ - -#include <linux/i8253.h> - -#define GET_TIME (x) do { if (boot_cpu_has(X86_FEATURE_TSC)) x = (unsigned int)rdtsc(); else x = get_time_pit(); } while (0) -#define DELTA (x,y) (boot_cpu_has(X86_FEATURE_TSC) ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TICK_RATE / HZ : 0))) -#define TIME_NAME (boot_cpu_has(X86_FEATURE_TSC)?"TSC":"PIT") -static unsigned int get_time_pit (void ) -{ -unsigned long flags; -unsigned int count; - -raw_spin_lock_irqsave (&i8253_lock, flags); -outb_p (0x00 ,0x43 ); - count =inb_p (0x40 ); - count |=inb_p (0x40 ) <<8 ; -raw_spin_unlock_irqrestore (&i8253_lock, flags); - -return count; -} -#elif defined(__x86_64__) -#define GET_TIME (x) do { x = (unsigned int)rdtsc(); } while (0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "TSC" -#elif defined(__alpha__) || defined(CONFIG_ARM ) || defined(CONFIG_ARM64 ) || defined(CONFIG_PPC ) || defined(CONFIG_RISCV ) -#define GET_TIME (x) do { x = get_cycles(); } while (0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "get_cycles" -#else -#define FAKE_TIME -static unsigned long analog_faketime =0 ; -#define GET_TIME (x) do { x = analog_faketime++; } while(0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "Unreliable" -#warning Precise timer not defined for this architecture. -#endif -static inline u64 get_time (void ) { -if (use_ktime) { -return ktime_get_ns (); - }else { -unsigned int x; -GET_TIME (x); -return x; - } +return ktime_get_ns (); }static inline unsigned int delta (u64 x,u64 y) { -if (use_ktime) -return y - x; -else -return DELTA ((unsigned int )x, (unsigned int )y); +return y - x; }/*
@@ -378,21 +324,7 @@ static void analog_calibrate_timer(struct analog_port *port)u64 t1, t2, t3;unsigned long flags; -if (use_ktime) { - port->speed =1000000 ; - }else { -local_irq_save (flags); - t1 =get_time (); -#ifdef FAKE_TIME - analog_faketime +=830 ; -#endif -mdelay (1 ); - t2 =get_time (); - t3 =get_time (); -local_irq_restore (flags); - - port->speed =delta (t1, t2) -delta (t2, t3); - } + port->speed =1000000 ; tx = ~0 ;
Signature · 1 line
2.33.0
Dmitry Torokhov
maintainerHi Guenter,
Quoted 84 lines · Guenter Roeck
m68k, mips, s390, and sparc allmodconfig images fail to build with the following error.
drivers/input/joystick/analog.c:160:2: error:
#warning Precise timer not defined for this architecture.Remove architecture specific time handling code and always use ktime functions to determine time deltas. Also remove the now useless
use_ktimekernel parameter.Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/joystick/analog.c | 74 ++------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-)drivers/input/joystick/analog.c +0
-52@@ -28,10 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");MODULE_DESCRIPTION (DRIVER_DESC );MODULE_LICENSE ("GPL" ); -static bool use_ktime = true; -module_param (use_ktime, bool,0400 ); -MODULE_PARM_DESC (use_ktime,"Use ktime for measuring I/O speed" ); -/* * Option parsing. */ @@ -119,64 +115,14 @@ struct analog_port {int axtime; }; -/* -* Time macros. -*/ - -#ifdef __i386__ - -#include <linux/i8253.h> - -#define GET_TIME (x) do { if (boot_cpu_has(X86_FEATURE_TSC)) x = (unsigned int)rdtsc(); else x = get_time_pit(); } while (0) -#define DELTA (x,y) (boot_cpu_has(X86_FEATURE_TSC) ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TICK_RATE / HZ : 0))) -#define TIME_NAME (boot_cpu_has(X86_FEATURE_TSC)?"TSC":"PIT") -static unsigned int get_time_pit (void ) -{ -unsigned long flags; -unsigned int count; - -raw_spin_lock_irqsave (&i8253_lock, flags); -outb_p (0x00 ,0x43 ); - count =inb_p (0x40 ); - count |=inb_p (0x40 ) <<8 ; -raw_spin_unlock_irqrestore (&i8253_lock, flags); - -return count; -} -#elif defined(__x86_64__) -#define GET_TIME (x) do { x = (unsigned int)rdtsc(); } while (0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "TSC" -#elif defined(__alpha__) || defined(CONFIG_ARM ) || defined(CONFIG_ARM64 ) || defined(CONFIG_PPC ) || defined(CONFIG_RISCV ) -#define GET_TIME (x) do { x = get_cycles(); } while (0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "get_cycles" -#else -#define FAKE_TIME -static unsigned long analog_faketime =0 ; -#define GET_TIME (x) do { x = analog_faketime++; } while(0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "Unreliable" -#warning Precise timer not defined for this architecture. -#endif -static inline u64 get_time (void ) { -if (use_ktime) { -return ktime_get_ns (); - }else { -unsigned int x; -GET_TIME (x); -return x; - }
drivers/input/joystick/analog.c struct analog_port { · line 125
Quoted 10 lines
drivers/input/joystick/analog.c +2
-4+return ktime_get_ns (); }static inline unsigned int delta (u64 x,u64 y) { -if (use_ktime) -return y - x; -else -return DELTA ((unsigned int )x, (unsigned int )y); +return y - x;
I wonder if we should get rid of these wrappers and use ktime_t and ktime_get(), ktime_sub(), etc directly.
Quoted 13 lines
drivers/input/joystick/analog.c +0
-6}/* @@ -378,21 +324,7 @@ static void analog_calibrate_timer(struct analog_port *port)u64 t1, t2, t3;unsigned long flags; -if (use_ktime) { - port->speed =1000000 ; - }else { -local_irq_save (flags); - t1 =get_time (); -#ifdef FAKE_TIME
drivers/input/joystick/analog.c static void analog_calibrate_timer(struct analog_port *port) · line 327
Quoted 10 lines
drivers/input/joystick/analog.c +1
-9- analog_faketime +=830 ; -#endif -mdelay (1 ); - t2 =get_time (); - t3 =get_time (); -local_irq_restore (flags); - - port->speed =delta (t1, t2) -delta (t2, t3); - } + port->speed =1000000 ;
It seems we could get rid of port->speed.
Thanks.
Signature · 1 line
Dmitry
Quoted 90 lines · Dmitry Torokhov
Hi Guenter,
Quoted 87 lines · Guenter Roeck
m68k, mips, s390, and sparc allmodconfig images fail to build with the following error.
drivers/input/joystick/analog.c:160:2: error:
#warning Precise timer not defined for this architecture.Remove architecture specific time handling code and always use ktime functions to determine time deltas. Also remove the now useless
use_ktimekernel parameter.Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/joystick/analog.c | 74 ++------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-)drivers/input/joystick/analog.c +1
-52@@ -28,10 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");MODULE_DESCRIPTION (DRIVER_DESC );MODULE_LICENSE ("GPL" ); -static bool use_ktime = true; -module_param (use_ktime, bool,0400 ); -MODULE_PARM_DESC (use_ktime,"Use ktime for measuring I/O speed" ); -/* * Option parsing. */ @@ -119,64 +115,14 @@ struct analog_port {int axtime; }; -/* -* Time macros. -*/ - -#ifdef __i386__ - -#include <linux/i8253.h> - -#define GET_TIME (x) do { if (boot_cpu_has(X86_FEATURE_TSC)) x = (unsigned int)rdtsc(); else x = get_time_pit(); } while (0) -#define DELTA (x,y) (boot_cpu_has(X86_FEATURE_TSC) ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TICK_RATE / HZ : 0))) -#define TIME_NAME (boot_cpu_has(X86_FEATURE_TSC)?"TSC":"PIT") -static unsigned int get_time_pit (void ) -{ -unsigned long flags; -unsigned int count; - -raw_spin_lock_irqsave (&i8253_lock, flags); -outb_p (0x00 ,0x43 ); - count =inb_p (0x40 ); - count |=inb_p (0x40 ) <<8 ; -raw_spin_unlock_irqrestore (&i8253_lock, flags); - -return count; -} -#elif defined(__x86_64__) -#define GET_TIME (x) do { x = (unsigned int)rdtsc(); } while (0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "TSC" -#elif defined(__alpha__) || defined(CONFIG_ARM ) || defined(CONFIG_ARM64 ) || defined(CONFIG_PPC ) || defined(CONFIG_RISCV ) -#define GET_TIME (x) do { x = get_cycles(); } while (0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "get_cycles" -#else -#define FAKE_TIME -static unsigned long analog_faketime =0 ; -#define GET_TIME (x) do { x = analog_faketime++; } while(0) -#define DELTA (x,y) ((y)-(x)) -#define TIME_NAME "Unreliable" -#warning Precise timer not defined for this architecture. -#endif -static inline u64 get_time (void ) { -if (use_ktime) { -return ktime_get_ns (); - }else { -unsigned int x; -GET_TIME (x); -return x; - } +return ktime_get_ns (); }
Quoted 11 lines
drivers/input/joystick/analog.c struct analog_port { · line 125
Quoted 7 lines
drivers/input/joystick/analog.c +1
-4static inline unsigned int delta (u64 x,u64 y) { -if (use_ktime) -return y - x; -else -return DELTA ((unsigned int )x, (unsigned int )y); +return y - x;I wonder if we should get rid of these wrappers and use
ktime_tandktime_get(),ktime_sub(), etc directly.
Will do.
Quoted 17 lines
Quoted 17 lines
drivers/input/joystick/analog.c +0
-10}/* @@ -378,21 +324,7 @@ static void analog_calibrate_timer(struct analog_port *port)u64 t1, t2, t3;unsigned long flags; -if (use_ktime) { - port->speed =1000000 ; - }else { -local_irq_save (flags); - t1 =get_time (); -#ifdef FAKE_TIME - analog_faketime +=830 ; -#endif -mdelay (1 ); - t2 =get_time ();
Quoted 9 lines
drivers/input/joystick/analog.c static void analog_calibrate_timer(struct analog_port *port) · line 327
Quoted 6 lines
drivers/input/joystick/analog.c +1
-5- t3 =get_time (); -local_irq_restore (flags); - - port->speed =delta (t1, t2) -delta (t2, t3); - } + port->speed =1000000 ;It seems we could get rid of
port->speed.
Sure. I'll just use NSEC_PER_MSEC directly.
Thanks,
Guenter