Skip to contentSkip to conversation

hwmon: (dell-smm) Speed up setting of fan speed

PATCH In review Armin Wolf 2 participants 2 messages Feb 12, 2022 – Feb 13, 2022

Subsystems (3)
lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

PATCH 1/1 hwmon: (dell-smm) Speed up setting of fan speed

commit c0d79987a0d82671bff374c07f2201f9bdf4aaa2 upstream.

When setting the fan speed, i8k_set_fan() calls i8k_get_fan_status(), causing an unnecessary SMM call since from the two users of this function, only i8k_ioctl_unlocked() needs to know the new fan status while dell_smm_write() ignores the new fan status.
Since SMM calls can be very slow while also making error reporting difficult for dell_smm_write(), remove the function call from i8k_set_fan() and call it separately in i8k_ioctl_unlocked().

Since this patch was backported from kernel 5.16, the data argument of i8k_set_fan and i8k_get_fan_status was omitted (it exists since kernel 5.15).

This patch was originally a performance optimization, but it turned out a user with a buggy machine requires this patch since it also fixes error reporting when i8k_get_fan_status fails.
https://github.com/lm-sensors/lm-sensors/pull/383

Tested on a Dell Inspiron 3505.

---
 drivers/hwmon/dell-smm-hwmon.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +8 -4
index 87f401100466..10c7b6295b02 100644
@@ -317,7 +317,7 @@ static int i8k_enable_fan_auto_mode(bool enable)
 }
 
 /*
- * Set the fan speed (off, low, high). Returns the new fan status.
+ * Set the fan speed (off, low, high, ...).
  */
 static int i8k_set_fan(int fan, int speed)
 {
@@ -329,7 +329,7 @@ static int i8k_set_fan(int fan, int speed)
 	speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
 	regs.ebx = (fan & 0xff) | (speed << 8);
 
-	return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
+	return i8k_smm(&regs);
 }
 
 static int i8k_get_temp_type(int sensor)
@@ -443,7 +443,7 @@ static int
 i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
 {
 	int val = 0;
-	int speed;
+	int speed, err;
 	unsigned char buff[16];
 	int __user *argp = (int __user *)arg;
 
@@ -504,7 +504,11 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
 		if (copy_from_user(&speed, argp + 1, sizeof(int)))
 			return -EFAULT;
 
-		val = i8k_set_fan(val, speed);
+		err = i8k_set_fan(val, speed);
+		if (err < 0)
+			return err;
+
+		val = i8k_get_fan_status(val);
 		break;
 
 	default:

--
2.30.2

maintainer
#1 lore raw
Quoted 21 lines · Armin Wolf

commit c0d79987a0d82671bff374c07f2201f9bdf4aaa2 upstream.

When setting the fan speed, i8k_set_fan() calls i8k_get_fan_status(), causing an unnecessary SMM call since from the two users of this function, only i8k_ioctl_unlocked() needs to know the new fan status while dell_smm_write() ignores the new fan status.
Since SMM calls can be very slow while also making error reporting difficult for dell_smm_write(), remove the function call from i8k_set_fan() and call it separately in i8k_ioctl_unlocked().

Since this patch was backported from kernel 5.16, the data argument of i8k_set_fan and i8k_get_fan_status was omitted (it exists since kernel 5.15).

This patch was originally a performance optimization, but it turned out a user with a buggy machine requires this patch since it also fixes error reporting when i8k_get_fan_status fails.
https://github.com/lm-sensors/lm-sensors/pull/383

Tested on a Dell Inspiron 3505.

Quoted 7 lines
---
 drivers/hwmon/dell-smm-hwmon.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

All now queued up, thanks!