diff mbox series

Input: analog: Always use ktime functions

Message ID 20210907050606.2142634-1-linux@roeck-us.net (mailing list archive)
State Superseded
Headers show
Series Input: analog: Always use ktime functions | expand

Commit Message

Guenter Roeck Sept. 7, 2021, 5:06 a.m. UTC
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.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/input/joystick/analog.c | 74 ++-------------------------------
 1 file changed, 3 insertions(+), 71 deletions(-)

Comments

Dmitry Torokhov Sept. 7, 2021, 5:59 a.m. UTC | #1
Hi Guenter,

On Mon, Sep 06, 2021 at 10:06:06PM -0700, Guenter Roeck wrote:
> 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.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  drivers/input/joystick/analog.c | 74 ++-------------------------------
>  1 file changed, 3 insertions(+), 71 deletions(-)
> 
> diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
> index f798922a4598..4702982182fa 100644
> --- a/drivers/input/joystick/analog.c
> +++ b/drivers/input/joystick/analog.c
> @@ -28,10 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
>  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;

I wonder if we should get rid of these wrappers and use ktime_t and
ktime_get(), ktime_sub(), etc directly.

>  }
>  
>  /*
> @@ -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;

It seems we could get rid of port->speed.

Thanks.
Guenter Roeck Sept. 7, 2021, 6:25 a.m. UTC | #2
On 9/6/21 10:59 PM, Dmitry Torokhov wrote:
> Hi Guenter,
> 
> On Mon, Sep 06, 2021 at 10:06:06PM -0700, Guenter Roeck wrote:
>> 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.
>>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>>   drivers/input/joystick/analog.c | 74 ++-------------------------------
>>   1 file changed, 3 insertions(+), 71 deletions(-)
>>
>> diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
>> index f798922a4598..4702982182fa 100644
>> --- a/drivers/input/joystick/analog.c
>> +++ b/drivers/input/joystick/analog.c
>> @@ -28,10 +28,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
>>   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;
> 
> I wonder if we should get rid of these wrappers and use ktime_t and
> ktime_get(), ktime_sub(), etc directly.
> 

Will do.

>>   }
>>   
>>   /*
>> @@ -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;
> 
> It seems we could get rid of port->speed.
> 

Sure. I'll just use NSEC_PER_MSEC directly.

Thanks,
Guenter
diff mbox series

Patch

diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index f798922a4598..4702982182fa 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -28,10 +28,6 @@  MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 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;