Re: [PATCH 5/5] hwmon: (dell-smm) Speed up setting of fan speed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 21 October 2021 19:54:47 W_Armin@xxxxxx wrote:
> From: Armin Wolf <W_Armin@xxxxxx>
> 
> When setting the fan speed, i8k_set_fan() calls i8k_get_fan_status(),
> causing an unnecessary smm call which can be very slow while also
> making error handling difficult.
> Fix that by removing the function call from i8k_set_fan() and
> call it separately when needed.

The important information which is missing in commit message is the fact
that there are only two users of i8k_set_fan() function. First is
dell_smm_write() and second is i8k_ioctl_unlocked().

First user only checks if error occurred during i8k_set_fan() call and
ignores new fan status. Second user needs to know new fan status as it
returns it to userspace.

So this change just speed up first user - dell_smm_write() function.

It would be nice to put this kind of information into commit message as
from code change itself it is not obvious.

Otherwise code change is fine,

Reviewed-by: Pali Rohár <pali@xxxxxxxxxx>

> Tested on a Dell Inspiron 3505.
> 
> Signed-off-by: Armin Wolf <W_Armin@xxxxxx>
> ---
>  drivers/hwmon/dell-smm-hwmon.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
> index 2579dd646b20..62f087f67925 100644
> --- a/drivers/hwmon/dell-smm-hwmon.c
> +++ b/drivers/hwmon/dell-smm-hwmon.c
> @@ -327,7 +327,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl
>  }
> 
>  /*
> - * Set the fan speed (off, low, high). Returns the new fan status.
> + * Set the fan speed (off, low, high, ...).
>   */
>  static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
>  {
> @@ -339,7 +339,7 @@ static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
>  	speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
>  	regs.ebx = (fan & 0xff) | (speed << 8);
> 
> -	return i8k_smm(&regs) ? : i8k_get_fan_status(data, fan);
> +	return i8k_smm(&regs);
>  }
> 
>  static int __init i8k_get_temp_type(int sensor)
> @@ -453,7 +453,7 @@ static int
>  i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd, unsigned long arg)
>  {
>  	int val = 0;
> -	int speed;
> +	int speed, err;
>  	unsigned char buff[16];
>  	int __user *argp = (int __user *)arg;
> 
> @@ -513,7 +513,11 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
>  		if (copy_from_user(&speed, argp + 1, sizeof(int)))
>  			return -EFAULT;
> 
> -		val = i8k_set_fan(data, val, speed);
> +		err = i8k_set_fan(data, val, speed);
> +		if (err < 0)
> +			return err;
> +
> +		val = i8k_get_fan_status(data, val);
>  		break;
> 
>  	default:
> --
> 2.20.1
> 



[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux