From a25ad0e4bdb7cedd2ee208e66748e27260cbd765 Mon Sep 17 00:00:00 2001 From: johnfan Date: Mon, 23 Sep 2024 00:06:22 +0200 Subject: [PATCH 01/12] fix: kernel module provides pwm hwmon interface (instead of rpm) --- kernel_module/legion-laptop.c | 266 ++++++++++++++++++++++------------ 1 file changed, 175 insertions(+), 91 deletions(-) diff --git a/kernel_module/legion-laptop.c b/kernel_module/legion-laptop.c index e1c42bdb..59c08533 100644 --- a/kernel_module/legion-laptop.c +++ b/kernel_module/legion-laptop.c @@ -1428,9 +1428,9 @@ static int acpi_process_buffer_to_ints(const char *id_name, int id_nr, goto err; } -// Reduced verbosity (only printing when ACPI result have bad parameters) -// pr_info("ACPI result for %s:%d: ACPI buffer length: %u\n", id_name, -// id_nr, out->buffer.length); + // Reduced verbosity (only printing when ACPI result have bad parameters) + // pr_info("ACPI result for %s:%d: ACPI buffer length: %u\n", id_name, + // id_nr, out->buffer.length); for (i = 0; i < ressize; ++i) res[i] = out->buffer.pointer[i]; @@ -1814,7 +1814,7 @@ static ssize_t ecram_memoryio_read(const struct ecram_memoryio *ec_memoryio, * methods to access EC RAM. */ static ssize_t ecram_memoryio_write(const struct ecram_memoryio *ec_memoryio, - u16 ec_offset, u8 value) + u16 ec_offset, u8 value) { if (ec_offset < ec_memoryio->physical_ec_start) { pr_info("Unexpected write at offset %d into EC RAM\n", @@ -2011,7 +2011,8 @@ static void ecram_write(struct ecram *ecram, u16 ecram_offset, u8 value) } err = ecram_portio_write(&ecram->portio, ecram_offset, value); if (err) - pr_info("Error writing EC RAM to 0x%x: Read-Only.\n", ecram_offset); + pr_info("Error writing EC RAM to 0x%x: Read-Only.\n", + ecram_offset); } /* =============================== */ @@ -2063,11 +2064,19 @@ enum SENSOR_ATTR { /* Data model for fan curve */ /* ============================= */ +#define MAX_RPM 10000 + +enum fan_speed_unit { + FAN_SPEED_UNIT_PERCENT = 1, + FAN_SPEED_UNIT_PWM = 2, + FAN_SPEED_UNIT_RPM_HUNDRED = 3, +}; + struct fancurve_point { // rpm1 devided by 100 - u8 rpm1_raw; + u8 speed1; // rpm2 devided by 100 - u8 rpm2_raw; + u8 speed2; // >=2 , <=5 (lower is faster); must increase by level u8 accel; // >=2 , <=5 (lower is faster); must increase by level @@ -2110,6 +2119,7 @@ static const struct fancurve_point fancurve_point_zero = { 0, 0, 0, 0, 0, struct fancurve { struct fancurve_point points[MAXFANCURVESIZE]; + enum fan_speed_unit fan_speed_unit; // number of points used; must be <= MAXFANCURVESIZE size_t size; // the point at which fans are run currently @@ -2132,22 +2142,69 @@ static bool fancurve_is_valid_max_temp(int max_temp) // - make hwmon implementation easier // - keep fancurve valid, otherwise EC will not properly control fan -static bool fancurve_set_rpm1(struct fancurve *fancurve, int point_id, int rpm) +static bool fancurve_set_speed_pwm(struct fancurve *fancurve, int point_id, + int fan_id, int value) { - bool valid = point_id == 0 ? rpm == 0 : (rpm >= 0 && rpm <= 4500); + u8 *speed; - if (valid) - fancurve->points[point_id].rpm1_raw = rpm / 100; - return valid; + if (!(point_id == 0 ? value == 0 : (value >= 0 && value <= 255))) { + pr_err("Value %d PWM not in allowed range to point with id %d", + value, point_id); + return false; + } + if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { + pr_err("Point id %d or fan id %d not valid", point_id, fan_id); + return false; + } + speed = fan_id == 0 ? &fancurve->points[point_id].speed1 : + &fancurve->points[point_id].speed2; + + switch (fancurve->fan_speed_unit) { + case FAN_SPEED_UNIT_PERCENT: + *speed = clamp_t(u8, value * 100 / 255, 0, 255); + return true; + case FAN_SPEED_UNIT_PWM: + *speed = clamp_t(u8, value, 0, 255); + return true; + case FAN_SPEED_UNIT_RPM_HUNDRED: + *speed = clamp_t(u8, value * MAX_RPM / 100 / 255, 0, 255); + return true; + default: + pr_info("No method to set for fan_speed_unit %d.", + fancurve->fan_speed_unit); + return false; + } + return false; } -static bool fancurve_set_rpm2(struct fancurve *fancurve, int point_id, int rpm) +static bool fancurve_get_speed_pwm(const struct fancurve *fancurve, + int point_id, int fan_id, int *value) { - bool valid = point_id == 0 ? rpm == 0 : (rpm >= 0 && rpm <= 4500); + const u8 *speed; - if (valid) - fancurve->points[point_id].rpm2_raw = rpm / 100; - return valid; + if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { + pr_err("Point id %d or fan id %d not valid", point_id, fan_id); + return false; + } + speed = fan_id == 0 ? &fancurve->points[point_id].speed1 : + &fancurve->points[point_id].speed2; + + switch (fancurve->fan_speed_unit) { + case FAN_SPEED_UNIT_PERCENT: + *value = *speed * 255 / 100; + return true; + case FAN_SPEED_UNIT_PWM: + *value = *speed; + return true; + case FAN_SPEED_UNIT_RPM_HUNDRED: + *value = *speed * 255 * 100 / MAX_RPM; + return true; + default: + pr_info("No method to get for fan_speed_unit %d.", + fancurve->fan_speed_unit); + return false; + } + return false; } // TODO: remove { ... } from single line if body @@ -2265,18 +2322,19 @@ static ssize_t fancurve_print_seqfile(const struct fancurve *fancurve, seq_printf( s, - "rpm1|rpm2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp\n"); + "speed1|speed2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp\n"); for (i = 0; i < fancurve->size; ++i) { const struct fancurve_point *point = &fancurve->points[i]; - seq_printf( - s, "%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n", - point->rpm1_raw * 100, point->rpm2_raw * 100, - point->accel, point->decel, point->cpu_min_temp_celsius, - point->cpu_max_temp_celsius, - point->gpu_min_temp_celsius, - point->gpu_max_temp_celsius, point->ic_min_temp_celsius, - point->ic_max_temp_celsius); + seq_printf(s, + "%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n", + point->speed1, point->speed2, point->accel, + point->decel, point->cpu_min_temp_celsius, + point->cpu_max_temp_celsius, + point->gpu_min_temp_celsius, + point->gpu_max_temp_celsius, + point->ic_min_temp_celsius, + point->ic_max_temp_celsius); } return 0; } @@ -2807,17 +2865,18 @@ static ssize_t wmi_read_fancurve_custom(const struct model_config *model, (struct WMIFanTableRead *)&buffer[0]; fancurve->current_point_i = 0; fancurve->size = 10; - fancurve->points[0].rpm1_raw = fantable->FSS0; - fancurve->points[1].rpm1_raw = fantable->FSS1; - fancurve->points[2].rpm1_raw = fantable->FSS2; - fancurve->points[3].rpm1_raw = fantable->FSS3; - fancurve->points[4].rpm1_raw = fantable->FSS4; - fancurve->points[5].rpm1_raw = fantable->FSS5; - fancurve->points[6].rpm1_raw = fantable->FSS6; - fancurve->points[7].rpm1_raw = fantable->FSS7; - fancurve->points[8].rpm1_raw = fantable->FSS8; - fancurve->points[9].rpm1_raw = fantable->FSS9; - //fancurve->points[10].rpm1_raw = fantable->FSSA; + fancurve->fan_speed_unit = FAN_SPEED_UNIT_PERCENT; + fancurve->points[0].speed1 = fantable->FSS0; + fancurve->points[1].speed1 = fantable->FSS1; + fancurve->points[2].speed1 = fantable->FSS2; + fancurve->points[3].speed1 = fantable->FSS3; + fancurve->points[4].speed1 = fantable->FSS4; + fancurve->points[5].speed1 = fantable->FSS5; + fancurve->points[6].speed1 = fantable->FSS6; + fancurve->points[7].speed1 = fantable->FSS7; + fancurve->points[8].speed1 = fantable->FSS8; + fancurve->points[9].speed1 = fantable->FSS9; + //fancurve->points[10].speed1 = fantable->FSSA; } return err; } @@ -2845,16 +2904,16 @@ static ssize_t wmi_write_fancurve_custom(const struct model_config *model, // CreateByteField (Arg2, 0x18, FSS9) memset(buffer, 0, sizeof(buffer)); - buffer[0x06] = fancurve->points[0].rpm1_raw; - buffer[0x08] = fancurve->points[1].rpm1_raw; - buffer[0x0A] = fancurve->points[2].rpm1_raw; - buffer[0x0C] = fancurve->points[3].rpm1_raw; - buffer[0x0E] = fancurve->points[4].rpm1_raw; - buffer[0x10] = fancurve->points[5].rpm1_raw; - buffer[0x12] = fancurve->points[6].rpm1_raw; - buffer[0x14] = fancurve->points[7].rpm1_raw; - buffer[0x16] = fancurve->points[8].rpm1_raw; - buffer[0x18] = fancurve->points[9].rpm1_raw; + buffer[0x06] = fancurve->points[0].speed1; + buffer[0x08] = fancurve->points[1].speed1; + buffer[0x0A] = fancurve->points[2].speed1; + buffer[0x0C] = fancurve->points[3].speed1; + buffer[0x0E] = fancurve->points[4].speed1; + buffer[0x10] = fancurve->points[5].speed1; + buffer[0x12] = fancurve->points[6].speed1; + buffer[0x14] = fancurve->points[7].speed1; + buffer[0x16] = fancurve->points[8].speed1; + buffer[0x18] = fancurve->points[9].speed1; print_hex_dump(KERN_INFO, "legion_laptop fan table wmi write buffer", DUMP_PREFIX_ADDRESS, 16, 1, buffer, sizeof(buffer), @@ -2879,12 +2938,13 @@ static int ec_read_fancurve_legion(struct ecram *ecram, { size_t i = 0; + fancurve->fan_speed_unit = FAN_SPEED_UNIT_RPM_HUNDRED; for (i = 0; i < MAXFANCURVESIZE; ++i) { struct fancurve_point *point = &fancurve->points[i]; - point->rpm1_raw = + point->speed1 = ecram_read(ecram, model->registers->EXT_FAN1_BASE + i); - point->rpm2_raw = + point->speed2 = ecram_read(ecram, model->registers->EXT_FAN2_BASE + i); point->accel = ecram_read( @@ -2936,9 +2996,9 @@ static int ec_write_fancurve_legion(struct ecram *ecram, &fancurve_point_zero; ecram_write(ecram, model->registers->EXT_FAN1_BASE + i, - point->rpm1_raw); + point->speed1); ecram_write(ecram, model->registers->EXT_FAN2_BASE + i, - point->rpm2_raw); + point->speed2); ecram_write(ecram, model->registers->EXT_FAN_ACC_BASE + i, point->accel); @@ -2985,12 +3045,13 @@ static int ec_read_fancurve_ideapad(struct ecram *ecram, { size_t i = 0; + fancurve->fan_speed_unit = FAN_SPEED_UNIT_RPM_HUNDRED; for (i = 0; i < FANCURVESIZE_IDEAPDAD; ++i) { struct fancurve_point *point = &fancurve->points[i]; - point->rpm1_raw = + point->speed1 = ecram_read(ecram, model->registers->EXT_FAN1_BASE + i); - point->rpm2_raw = + point->speed2 = ecram_read(ecram, model->registers->EXT_FAN2_BASE + i); point->accel = 0; @@ -3035,14 +3096,14 @@ static int ec_write_fancurve_ideapad(struct ecram *ecram, const struct fancurve_point *point = &fancurve->points[i]; ecram_write(ecram, model->registers->EXT_FAN1_BASE + i, - point->rpm1_raw); + point->speed1); valr1 = ecram_read(ecram, model->registers->EXT_FAN1_BASE + i); ecram_write(ecram, model->registers->EXT_FAN2_BASE + i, - point->rpm2_raw); + point->speed2); valr2 = ecram_read(ecram, model->registers->EXT_FAN2_BASE + i); - pr_info("Writing fan1: %d; reading fan1: %d\n", point->rpm1_raw, + pr_info("Writing fan1: %d; reading fan1: %d\n", point->speed1, valr1); - pr_info("Writing fan2: %d; reading fan2: %d\n", point->rpm2_raw, + pr_info("Writing fan2: %d; reading fan2: %d\n", point->speed2, valr2); // write to memory and repeat 8 bytes later again @@ -3086,26 +3147,31 @@ static int ec_write_fancurve_ideapad(struct ecram *ecram, #define FANCURVESIZE_LOQ 10 static int ec_read_fancurve_loq(struct ecram *ecram, - const struct model_config *model, - struct fancurve *fancurve) + const struct model_config *model, + struct fancurve *fancurve) { size_t i = 0; size_t struct_offset = 3; // {cpu_temp: u8, rpm: u8, gpu_temp?: u8} + fancurve->fan_speed_unit = FAN_SPEED_UNIT_RPM_HUNDRED; for (i = 0; i < FANCURVESIZE_LOQ; ++i) { struct fancurve_point *point = &fancurve->points[i]; - point->rpm1_raw = - ecram_read(ecram, model->registers->EXT_FAN1_BASE + (i * struct_offset)); - point->rpm2_raw = - ecram_read(ecram, model->registers->EXT_FAN2_BASE + (i * struct_offset)); + point->speed1 = + ecram_read(ecram, model->registers->EXT_FAN1_BASE + + (i * struct_offset)); + point->speed2 = + ecram_read(ecram, model->registers->EXT_FAN2_BASE + + (i * struct_offset)); point->accel = 0; point->decel = 0; point->cpu_max_temp_celsius = - ecram_read(ecram, model->registers->EXT_CPU_TEMP + (i * struct_offset)); + ecram_read(ecram, model->registers->EXT_CPU_TEMP + + (i * struct_offset)); point->gpu_max_temp_celsius = - ecram_read(ecram, model->registers->EXT_GPU_TEMP + (i * struct_offset)); + ecram_read(ecram, model->registers->EXT_GPU_TEMP + + (i * struct_offset)); point->cpu_min_temp_celsius = 0; point->gpu_min_temp_celsius = 0; point->ic_max_temp_celsius = 0; @@ -3121,8 +3187,8 @@ static int ec_read_fancurve_loq(struct ecram *ecram, } static int ec_write_fancurve_loq(struct ecram *ecram, - const struct model_config *model, - const struct fancurve *fancurve) + const struct model_config *model, + const struct fancurve *fancurve) { size_t i; int valr1; @@ -3132,22 +3198,32 @@ static int ec_write_fancurve_loq(struct ecram *ecram, for (i = 0; i < FANCURVESIZE_LOQ; ++i) { const struct fancurve_point *point = &fancurve->points[i]; - ecram_write(ecram, model->registers->EXT_FAN1_BASE + (i * struct_offset), - point->rpm1_raw); - valr1 = ecram_read(ecram, model->registers->EXT_FAN1_BASE + (i * struct_offset)); - ecram_write(ecram, model->registers->EXT_FAN2_BASE + (i * struct_offset), - point->rpm2_raw); - valr2 = ecram_read(ecram, model->registers->EXT_FAN2_BASE + (i * struct_offset)); - pr_info("Writing fan1: %d; reading fan1: %d\n", point->rpm1_raw, + ecram_write(ecram, + model->registers->EXT_FAN1_BASE + + (i * struct_offset), + point->speed1); + valr1 = ecram_read(ecram, model->registers->EXT_FAN1_BASE + + (i * struct_offset)); + ecram_write(ecram, + model->registers->EXT_FAN2_BASE + + (i * struct_offset), + point->speed2); + valr2 = ecram_read(ecram, model->registers->EXT_FAN2_BASE + + (i * struct_offset)); + pr_info("Writing fan1: %d; reading fan1: %d\n", point->speed1, valr1); - pr_info("Writing fan2: %d; reading fan2: %d\n", point->rpm2_raw, + pr_info("Writing fan2: %d; reading fan2: %d\n", point->speed2, valr2); // write to memory and repeat 8 bytes later again - ecram_write(ecram, model->registers->EXT_CPU_TEMP + (i * struct_offset), + ecram_write(ecram, + model->registers->EXT_CPU_TEMP + + (i * struct_offset), point->cpu_max_temp_celsius); // write to memory and repeat 8 bytes later again - ecram_write(ecram, model->registers->EXT_GPU_TEMP + (i * struct_offset), + ecram_write(ecram, + model->registers->EXT_GPU_TEMP + + (i * struct_offset), point->gpu_max_temp_celsius); } @@ -3165,8 +3241,7 @@ static int read_fancurve(struct legion_private *priv, struct fancurve *fancurve) return ec_read_fancurve_ideapad(&priv->ecram, priv->conf, fancurve); case ACCESS_METHOD_EC3: - return ec_read_fancurve_loq(&priv->ecram, priv->conf, - fancurve); + return ec_read_fancurve_loq(&priv->ecram, priv->conf, fancurve); case ACCESS_METHOD_WMI3: return wmi_read_fancurve_custom(priv->conf, fancurve); default: @@ -3189,7 +3264,7 @@ static int write_fancurve(struct legion_private *priv, fancurve); case ACCESS_METHOD_EC3: return ec_write_fancurve_loq(&priv->ecram, priv->conf, - fancurve); + fancurve); case ACCESS_METHOD_WMI3: return wmi_write_fancurve_custom(priv->conf, fancurve); default: @@ -3380,7 +3455,8 @@ static enum legion_wmi_powermode ec_to_wmi_powermode(int ec_mode) } } -static enum legion_ec_powermode wmi_to_ec_powermode(enum legion_wmi_powermode wmi_mode) +static enum legion_ec_powermode +wmi_to_ec_powermode(enum legion_wmi_powermode wmi_mode) { switch (wmi_mode) { case LEGION_WMI_POWERMODE_QUIET: @@ -5005,6 +5081,12 @@ static struct attribute *sensor_hwmon_attributes[] = { NULL }; +static ssize_t fan_max_show(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + return sprintf(buf, "%d\n", MAX_RPM); +} + static ssize_t autopoint_show(struct device *dev, struct device_attribute *devattr, char *buf) { @@ -5031,10 +5113,10 @@ static ssize_t autopoint_show(struct device *dev, switch (fancurve_attr_id) { case FANCURVE_ATTR_PWM1: - value = fancurve.points[point_id].rpm1_raw * 100; + fancurve_get_speed_pwm(&fancurve, point_id, 0, &value); break; case FANCURVE_ATTR_PWM2: - value = fancurve.points[point_id].rpm2_raw * 100; + fancurve_get_speed_pwm(&fancurve, point_id, 1, &value); break; case FANCURVE_ATTR_CPU_TEMP: value = fancurve.points[point_id].cpu_max_temp_celsius; @@ -5110,10 +5192,10 @@ static ssize_t autopoint_store(struct device *dev, switch (fancurve_attr_id) { case FANCURVE_ATTR_PWM1: - valid = fancurve_set_rpm1(&fancurve, point_id, value); + valid = fancurve_set_speed_pwm(&fancurve, point_id, 0, value); break; case FANCURVE_ATTR_PWM2: - valid = fancurve_set_rpm2(&fancurve, point_id, value); + valid = fancurve_set_speed_pwm(&fancurve, point_id, 1, value); break; case FANCURVE_ATTR_CPU_TEMP: valid = fancurve_set_cpu_temp_max(&fancurve, point_id, value); @@ -5174,7 +5256,8 @@ static ssize_t autopoint_store(struct device *dev, return count; } -// rpm1 +// pwm1 +static SENSOR_DEVICE_ATTR_RO(fan1_max, fan_max, 0); static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point1_pwm, autopoint, FANCURVE_ATTR_PWM1, 0); static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point2_pwm, autopoint, @@ -5195,7 +5278,8 @@ static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point9_pwm, autopoint, FANCURVE_ATTR_PWM1, 8); static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point10_pwm, autopoint, FANCURVE_ATTR_PWM1, 9); -// rpm2 +// pwm2 +static SENSOR_DEVICE_ATTR_RO(fan2_max, fan_max, 0); static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point1_pwm, autopoint, FANCURVE_ATTR_PWM2, 0); static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point2_pwm, autopoint, @@ -5420,8 +5504,7 @@ static ssize_t minifancurve_store(struct device *dev, err = kstrtoint(buf, 0, &value); if (err) { err = -1; - pr_info("Parsing hwmon store failed: error:%d\n", - err); + pr_info("Parsing hwmon store failed: error:%d\n", err); goto error; } @@ -5478,8 +5561,7 @@ static ssize_t pwm1_mode_store(struct device *dev, err = kstrtoint(buf, 0, &value); if (err) { err = -1; - pr_info("Parsing hwmon store failed: error:%d\n", - err); + pr_info("Parsing hwmon store failed: error:%d\n", err); goto error; } is_maximumfanspeed = value == 0; @@ -5504,6 +5586,8 @@ static ssize_t pwm1_mode_store(struct device *dev, static SENSOR_DEVICE_ATTR_RW(pwm1_mode, pwm1_mode, 0); static struct attribute *fancurve_hwmon_attributes[] = { + &sensor_dev_attr_fan1_max.dev_attr.attr, + &sensor_dev_attr_fan2_max.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, From 08ff2a6fc4f4df1308756e061f782f5572c98b46 Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 23 Sep 2023 01:02:00 +0200 Subject: [PATCH 02/12] chore: Use PWM kernel interface in Ptyhon but keep RPM for user anf file --- python/legion_linux/legion_linux/legion.py | 42 ++++++++++++++----- .../legion_linux/legion_linux/legion_gui.py | 4 +- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/python/legion_linux/legion_linux/legion.py b/python/legion_linux/legion_linux/legion.py index 906ac475..78cb165c 100755 --- a/python/legion_linux/legion_linux/legion.py +++ b/python/legion_linux/legion_linux/legion.py @@ -42,8 +42,8 @@ def get_dmesg(only_tail=False, filter_log=True): @dataclass(order=True) class FanCurveEntry: - fan1_speed: int - fan2_speed: int + fan1_speed: float # fan speed in rpm + fan2_speed: float # fan speed in rpm cpu_lower_temp: int cpu_upper_temp: int gpu_lower_temp: int @@ -743,6 +743,8 @@ class FanCurveIO(Feature): pwm1_accel = "pwm1_auto_point{}_accel" pwm1_decel = "pwm1_auto_point{}_decel" minifancurve = "minifancurve" + fan1_max = "fan1_max" + fan2_max = "fan2_max" encoding = DEFAULT_ENCODING @@ -791,17 +793,31 @@ def _write_file(file_path, value): def _write_file_or(file_path, value): if os.path.exists(file_path): FanCurveIO._write_file(file_path, value) + + def get_fan_1_max_rpm(self): + file_path = self.hwmon_path + self.fan1_max + return int(self._read_file(file_path)) - def set_fan_1_speed(self, point_id, value): + def get_fan_2_max_rpm(self): + file_path = self.hwmon_path + self.fan2_max + return int(self._read_file(file_path)) + + def set_fan_1_speed_pwm(self, point_id, value): point_id = self._validate_point_id(point_id) file_path = self.hwmon_path + self.pwm1_fan_speed.format(point_id) self._write_file(file_path, value) - def set_fan_2_speed(self, point_id, value): + def set_fan_2_speed_pwm(self, point_id, value): point_id = self._validate_point_id(point_id) file_path = self.hwmon_path + self.pwm2_fan_speed.format(point_id) self._write_file(file_path, value) + def set_fan_1_speed_rpm(self, point_id, value): + return self.set_fan_1_speed_pwm(point_id, round(value/self.get_fan_1_max_rpm()*255.0)) + + def set_fan_2_speed_rpm(self, point_id, value): + return self.set_fan_2_speed_pwm(point_id, round(value/self.get_fan_2_max_rpm()*255.0)) + def set_lower_cpu_temperature(self, point_id, value): point_id = self._validate_point_id(point_id) file_path = self.hwmon_path + self.pwm1_temp_hyst.format(point_id) @@ -842,16 +858,22 @@ def set_deceleration(self, point_id, value): file_path = self.hwmon_path + self.pwm1_decel.format(point_id) self._write_file(file_path, value) - def get_fan_1_speed(self, point_id): + def get_fan_1_speed_pwm(self, point_id): point_id = self._validate_point_id(point_id) file_path = self.hwmon_path + self.pwm1_fan_speed.format(point_id) return self._read_file(file_path) - def get_fan_2_speed(self, point_id): + def get_fan_2_speed_pwm(self, point_id): point_id = self._validate_point_id(point_id) file_path = self.hwmon_path + self.pwm2_fan_speed.format(point_id) return self._read_file(file_path) + def get_fan_1_speed_rpm(self, point_id): + return round(self.get_fan_1_speed_pwm(point_id)/255.0*self.get_fan_1_max_rpm(), ndigits=2) + + def get_fan_2_speed_rpm(self, point_id): + return round(self.get_fan_2_speed_pwm(point_id)/255.0*self.get_fan_2_max_rpm(), ndigits=2) + def get_lower_cpu_temperature(self, point_id): point_id = self._validate_point_id(point_id) file_path = self.hwmon_path + self.pwm1_temp_hyst.format(point_id) @@ -924,8 +946,8 @@ def write_fan_curve(self, fan_curve: FanCurve, _=False): log.error(str(error)) for index, entry in enumerate(fan_curve.entries): point_id = index + 1 - self.set_fan_1_speed(point_id, entry.fan1_speed) - self.set_fan_2_speed(point_id, entry.fan2_speed) + self.set_fan_1_speed_rpm(point_id, entry.fan1_speed) + self.set_fan_2_speed_rpm(point_id, entry.fan2_speed) self.set_lower_cpu_temperature(point_id, entry.cpu_lower_temp) self.set_upper_cpu_temperature(point_id, entry.cpu_upper_temp) self.set_lower_gpu_temperature(point_id, entry.gpu_lower_temp) @@ -939,8 +961,8 @@ def read_fan_curve(self) -> FanCurve: """Reads a fan curve object from the file system""" entries = [] for point_id in range(1, 11): - fan1_speed = self.get_fan_1_speed(point_id) - fan2_speed = self.get_fan_2_speed(point_id) + fan1_speed = self.get_fan_1_speed_rpm(point_id) + fan2_speed = self.get_fan_2_speed_rpm(point_id) cpu_lower_temp = self.get_lower_cpu_temperature(point_id) cpu_upper_temp = self.get_upper_cpu_temperature(point_id) gpu_lower_temp = self.get_lower_gpu_temperature(point_id) diff --git a/python/legion_linux/legion_linux/legion_gui.py b/python/legion_linux/legion_linux/legion_gui.py index 227f4dfb..c107fc76 100755 --- a/python/legion_linux/legion_linux/legion_gui.py +++ b/python/legion_linux/legion_linux/legion_gui.py @@ -977,8 +977,8 @@ def set_disabled(self, value: bool): self.decel_edit.setDisabled(value) def get(self) -> FanCurveEntry: - fan1_speed = int(self.fan_speed1_edit.text()) - fan2_speed = int(self.fan_speed2_edit.text()) + fan1_speed = float(self.fan_speed1_edit.text()) + fan2_speed = float(self.fan_speed2_edit.text()) cpu_lower_temp = int(self.cpu_lower_temp_edit.text()) cpu_upper_temp = int(self.cpu_upper_temp_edit.text()) gpu_lower_temp = int(self.gpu_lower_temp_edit.text()) From 91527102a8f964ff0123c27b8d53125ecc49129d Mon Sep 17 00:00:00 2001 From: johnfan Date: Thu, 3 Oct 2024 22:49:57 +0200 Subject: [PATCH 03/12] fix: Debug crash in rpm speed output --- kernel_module/legion-laptop.c | 41 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/kernel_module/legion-laptop.c b/kernel_module/legion-laptop.c index 59c08533..2ff1b86b 100644 --- a/kernel_module/legion-laptop.c +++ b/kernel_module/legion-laptop.c @@ -97,8 +97,9 @@ MODULE_PARM_DESC( enable_platformprofile, "Enable the platform profile sysfs API to read and write the power mode."); +// TODO: remove this? #define LEGIONFEATURES \ - "fancurve powermode platformprofile platformprofilenotify minifancurve" + "fancurve powermode platformprofile platformprofilenotify minifancurve fancurve_pmw_speed fancurve_rpm_speed" //Size of fancurve stored in embedded controller #define MAXFANCURVESIZE 10 @@ -2153,7 +2154,7 @@ static bool fancurve_set_speed_pwm(struct fancurve *fancurve, int point_id, return false; } if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { - pr_err("Point id %d or fan id %d not valid", point_id, fan_id); + pr_err("Setting point id %d, fan id %d not valid for fancurve with size %ld", point_id, fan_id, fancurve->size); return false; } speed = fan_id == 0 ? &fancurve->points[point_id].speed1 : @@ -2180,24 +2181,24 @@ static bool fancurve_set_speed_pwm(struct fancurve *fancurve, int point_id, static bool fancurve_get_speed_pwm(const struct fancurve *fancurve, int point_id, int fan_id, int *value) { - const u8 *speed; + int speed; if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { - pr_err("Point id %d or fan id %d not valid", point_id, fan_id); + pr_err("Reading point id %d, fan id %d not valid for fancurve with size %ld", point_id, fan_id, fancurve->size); return false; } - speed = fan_id == 0 ? &fancurve->points[point_id].speed1 : - &fancurve->points[point_id].speed2; + speed = fan_id == 0 ? fancurve->points[point_id].speed1 : + fancurve->points[point_id].speed2; switch (fancurve->fan_speed_unit) { case FAN_SPEED_UNIT_PERCENT: - *value = *speed * 255 / 100; + *value = speed * 255 / 100; return true; case FAN_SPEED_UNIT_PWM: - *value = *speed; + *value = speed; return true; case FAN_SPEED_UNIT_RPM_HUNDRED: - *value = *speed * 255 * 100 / MAX_RPM; + *value = speed * 255 * 100 / MAX_RPM; return true; default: pr_info("No method to get for fan_speed_unit %d.", @@ -2320,15 +2321,26 @@ static ssize_t fancurve_print_seqfile(const struct fancurve *fancurve, { int i; + seq_printf(s, "Fan curve current point id: %ld\n", fancurve->current_point_i); + seq_printf(s, "Fan curve points size: %ld\n", fancurve->size); + seq_printf( s, - "speed1|speed2|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp\n"); + "u(speed_of_unit)|speed1[u]|speed2[u]|speed1[pwm]|speed2[pwm]|acceleration|deceleration|cpu_min_temp|cpu_max_temp|gpu_min_temp|gpu_max_temp|ic_min_temp|ic_max_temp\n"); for (i = 0; i < fancurve->size; ++i) { + int speed_pwm1 = -1; + int speed_pwm2 = -1; const struct fancurve_point *point = &fancurve->points[i]; + fancurve_get_speed_pwm(fancurve, i, 0, &speed_pwm1); + fancurve_get_speed_pwm(fancurve, i, 0, &speed_pwm2); + seq_printf(s, - "%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n", - point->speed1, point->speed2, point->accel, + "%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n", + fancurve->fan_speed_unit, + point->speed1, point->speed2, + speed_pwm1, speed_pwm2, + point->accel, point->decel, point->cpu_min_temp_celsius, point->cpu_max_temp_celsius, point->gpu_min_temp_celsius, @@ -3233,6 +3245,7 @@ static int ec_write_fancurve_loq(struct ecram *ecram, static int read_fancurve(struct legion_private *priv, struct fancurve *fancurve) { // TODO: use enums or function pointers? + pr_info("Reading fancurve"); // TODO: remove that switch (priv->conf->access_method_fancurve) { case ACCESS_METHOD_EC: return ec_read_fancurve_legion(&priv->ecram, priv->conf, @@ -3909,11 +3922,9 @@ static int debugfs_fancurve_show(struct seq_file *s, void *unused) &is_maximumfanspeed); seq_file_print_with_error(s, "fanfullspeed EC", err, is_maximumfanspeed); + seq_printf(s, "Max speed for fancurve: %d\n", MAX_RPM); read_fancurve(priv, &priv->fancurve); - seq_printf(s, "EC fan curve current point id: %ld\n", - priv->fancurve.current_point_i); - seq_printf(s, "EC fan curve points size: %ld\n", priv->fancurve.size); seq_puts(s, "Current fan curve in hardware:\n"); fancurve_print_seqfile(&priv->fancurve, s); From 86a85046f1866db355fb607f8e902d63af0a472f Mon Sep 17 00:00:00 2001 From: johnfan Date: Sun, 6 Oct 2024 05:32:33 +0200 Subject: [PATCH 04/12] fix: Add more debug output to autpoint show --- kernel_module/legion-laptop.c | 55 +++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/kernel_module/legion-laptop.c b/kernel_module/legion-laptop.c index 2ff1b86b..27311374 100644 --- a/kernel_module/legion-laptop.c +++ b/kernel_module/legion-laptop.c @@ -2154,7 +2154,8 @@ static bool fancurve_set_speed_pwm(struct fancurve *fancurve, int point_id, return false; } if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { - pr_err("Setting point id %d, fan id %d not valid for fancurve with size %ld", point_id, fan_id, fancurve->size); + pr_err("Setting point id %d, fan id %d not valid for fancurve with size %ld", + point_id, fan_id, fancurve->size); return false; } speed = fan_id == 0 ? &fancurve->points[point_id].speed1 : @@ -2183,22 +2184,31 @@ static bool fancurve_get_speed_pwm(const struct fancurve *fancurve, { int speed; + pr_info("%s 1 point id=%d, fancurve=%p, fancurve.fan_speed_unit=%d, fancurve.size=%ld", + __func__, point_id, (void*) fancurve, fancurve->fan_speed_unit, fancurve->size); + if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { - pr_err("Reading point id %d, fan id %d not valid for fancurve with size %ld", point_id, fan_id, fancurve->size); + pr_err("Reading point id %d, fan id %d not valid for fancurve with size %ld", + point_id, fan_id, fancurve->size); return false; } + pr_info("%s 2", __func__); + speed = fan_id == 0 ? fancurve->points[point_id].speed1 : fancurve->points[point_id].speed2; switch (fancurve->fan_speed_unit) { case FAN_SPEED_UNIT_PERCENT: *value = speed * 255 / 100; + pr_info("%s 3a", __func__); return true; case FAN_SPEED_UNIT_PWM: *value = speed; + pr_info("%s 3b", __func__); return true; case FAN_SPEED_UNIT_RPM_HUNDRED: *value = speed * 255 * 100 / MAX_RPM; + pr_info("%s 3c", __func__); return true; default: pr_info("No method to get for fan_speed_unit %d.", @@ -2321,7 +2331,8 @@ static ssize_t fancurve_print_seqfile(const struct fancurve *fancurve, { int i; - seq_printf(s, "Fan curve current point id: %ld\n", fancurve->current_point_i); + seq_printf(s, "Fan curve current point id: %ld\n", + fancurve->current_point_i); seq_printf(s, "Fan curve points size: %ld\n", fancurve->size); seq_printf( @@ -2335,18 +2346,16 @@ static ssize_t fancurve_print_seqfile(const struct fancurve *fancurve, fancurve_get_speed_pwm(fancurve, i, 0, &speed_pwm1); fancurve_get_speed_pwm(fancurve, i, 0, &speed_pwm2); - seq_printf(s, - "%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n", - fancurve->fan_speed_unit, - point->speed1, point->speed2, - speed_pwm1, speed_pwm2, - point->accel, - point->decel, point->cpu_min_temp_celsius, - point->cpu_max_temp_celsius, - point->gpu_min_temp_celsius, - point->gpu_max_temp_celsius, - point->ic_min_temp_celsius, - point->ic_max_temp_celsius); + seq_printf( + s, + "%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n", + fancurve->fan_speed_unit, point->speed1, point->speed2, + speed_pwm1, speed_pwm2, point->accel, point->decel, + point->cpu_min_temp_celsius, + point->cpu_max_temp_celsius, + point->gpu_min_temp_celsius, + point->gpu_max_temp_celsius, point->ic_min_temp_celsius, + point->ic_max_temp_celsius); } return 0; } @@ -5108,10 +5117,18 @@ static ssize_t autopoint_show(struct device *dev, int fancurve_attr_id = to_sensor_dev_attr_2(devattr)->nr; int point_id = to_sensor_dev_attr_2(devattr)->index; + pr_info("%s 1 point id=%d, fancurve_attr_id id=%d, fancurve.fan_speed_unit=%d, fancurve.size=%ld", + __func__, point_id, fancurve_attr_id, + fancurve.fan_speed_unit, fancurve.size); + mutex_lock(&priv->fancurve_mutex); err = read_fancurve(priv, &fancurve); mutex_unlock(&priv->fancurve_mutex); + pr_info("%s 2 point id=%d, fancurve_attr_id id=%d, err=%d, fancurve.fan_speed_unit=%d, fancurve.size=%ld", + __func__, point_id, fancurve_attr_id, err, + fancurve.fan_speed_unit, fancurve.size); + if (err) { pr_info("Failed to read fancurve\n"); return -EOPNOTSUPP; @@ -5124,10 +5141,16 @@ static ssize_t autopoint_show(struct device *dev, switch (fancurve_attr_id) { case FANCURVE_ATTR_PWM1: + pr_info("%s ->3a pwm1 point id=%d, fancurve_attr_id id=%d", + __func__, point_id, fancurve_attr_id); fancurve_get_speed_pwm(&fancurve, point_id, 0, &value); + pr_info("%s ->3a2", __func__); break; case FANCURVE_ATTR_PWM2: + pr_info("%s ->3b pwm2 point id=%d, fancurve_attr_id id=%d", + __func__, point_id, fancurve_attr_id); fancurve_get_speed_pwm(&fancurve, point_id, 1, &value); + pr_info("%s ->3b2", __func__); break; case FANCURVE_ATTR_CPU_TEMP: value = fancurve.points[point_id].cpu_max_temp_celsius; @@ -5161,7 +5184,7 @@ static ssize_t autopoint_show(struct device *dev, fancurve_attr_id); return -EOPNOTSUPP; } - + pr_info("%s 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", __func__); return sprintf(buf, "%d\n", value); } From ae080816916634b9516e68d17c906973cc59992f Mon Sep 17 00:00:00 2001 From: johnfan Date: Sun, 13 Oct 2024 16:00:59 +0200 Subject: [PATCH 05/12] fix: Output 0 if point id not in curve --- kernel_module/legion-laptop.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kernel_module/legion-laptop.c b/kernel_module/legion-laptop.c index 27311374..49230cfe 100644 --- a/kernel_module/legion-laptop.c +++ b/kernel_module/legion-laptop.c @@ -2185,7 +2185,7 @@ static bool fancurve_get_speed_pwm(const struct fancurve *fancurve, int speed; pr_info("%s 1 point id=%d, fancurve=%p, fancurve.fan_speed_unit=%d, fancurve.size=%ld", - __func__, point_id, (void*) fancurve, fancurve->fan_speed_unit, fancurve->size); + __func__, point_id, (void *) fancurve, fancurve->fan_speed_unit, fancurve->size); if (!(point_id < fancurve->size && fan_id >= 0 && fan_id < 2)) { pr_err("Reading point id %d, fan id %d not valid for fancurve with size %ld", @@ -5116,6 +5116,7 @@ static ssize_t autopoint_show(struct device *dev, struct legion_private *priv = dev_get_drvdata(dev); int fancurve_attr_id = to_sensor_dev_attr_2(devattr)->nr; int point_id = to_sensor_dev_attr_2(devattr)->index; + bool ok = true; pr_info("%s 1 point id=%d, fancurve_attr_id id=%d, fancurve.fan_speed_unit=%d, fancurve.size=%ld", __func__, point_id, fancurve_attr_id, @@ -5143,14 +5144,14 @@ static ssize_t autopoint_show(struct device *dev, case FANCURVE_ATTR_PWM1: pr_info("%s ->3a pwm1 point id=%d, fancurve_attr_id id=%d", __func__, point_id, fancurve_attr_id); - fancurve_get_speed_pwm(&fancurve, point_id, 0, &value); - pr_info("%s ->3a2", __func__); + ok = fancurve_get_speed_pwm(&fancurve, point_id, 0, &value); + pr_info("%s ok: %d->3a2", __func__, ok); break; case FANCURVE_ATTR_PWM2: pr_info("%s ->3b pwm2 point id=%d, fancurve_attr_id id=%d", __func__, point_id, fancurve_attr_id); - fancurve_get_speed_pwm(&fancurve, point_id, 1, &value); - pr_info("%s ->3b2", __func__); + ok = fancurve_get_speed_pwm(&fancurve, point_id, 1, &value); + pr_info("%s ok: %d->3b2", __func__, ok); break; case FANCURVE_ATTR_CPU_TEMP: value = fancurve.points[point_id].cpu_max_temp_celsius; @@ -5184,7 +5185,11 @@ static ssize_t autopoint_show(struct device *dev, fancurve_attr_id); return -EOPNOTSUPP; } - pr_info("%s 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", __func__); + if (!ok) { + pr_info("%s 4a: error!", __func__); + value = 0; + } + pr_info("%s 4b XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", __func__); return sprintf(buf, "%d\n", value); } From 6b66259943693dbcd7741c1378ab806850d5252f Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:03:25 +0200 Subject: [PATCH 06/12] fix: Fix build dependencies --- .github/workflows/build.yml | 6 +-- .github/workflows/build_PR.yml | 6 +-- .github/workflows/extra.yaml | 2 +- .github/workflows/manual_test.yaml | 6 +-- ...kerfile.ubuntu => Dockerfile.ubuntu.22.04} | 6 +-- deploy/Dockerfile.ubuntu.24.04 | 38 +++++++++++++++++++ ...h => install_dependencies_ubuntu_22_04.sh} | 0 .../install_dependencies_ubuntu_24_04.sh | 5 +++ ..._development_dependencies_ubuntu_22_04.sh} | 2 +- ...l_development_dependencies_ubuntu_24_04.sh | 16 ++++++++ deploy/docker-compose.yaml | 8 +++- 11 files changed, 79 insertions(+), 16 deletions(-) rename deploy/{Dockerfile.ubuntu => Dockerfile.ubuntu.22.04} (78%) create mode 100644 deploy/Dockerfile.ubuntu.24.04 rename deploy/dependencies/{install_dependencies_ubuntu.sh => install_dependencies_ubuntu_22_04.sh} (100%) create mode 100755 deploy/dependencies/install_dependencies_ubuntu_24_04.sh rename deploy/dependencies/{install_development_dependencies_ubuntu.sh => install_development_dependencies_ubuntu_22_04.sh} (90%) create mode 100755 deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a07b9cb1..6d7cced8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kernel_build.sh @@ -36,7 +36,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Test Install run: ./tests/test_kernel_install.sh @@ -54,7 +54,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kenel_dkms_install.sh || true diff --git a/.github/workflows/build_PR.yml b/.github/workflows/build_PR.yml index 777e8c0e..1930dae7 100644 --- a/.github/workflows/build_PR.yml +++ b/.github/workflows/build_PR.yml @@ -10,7 +10,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kernel_build.sh @@ -25,7 +25,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Test Install run: ./tests/test_kernel_install.sh @@ -43,7 +43,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kenel_dkms_install.sh || true diff --git a/.github/workflows/extra.yaml b/.github/workflows/extra.yaml index 0c0c982b..dd5791b9 100644 --- a/.github/workflows/extra.yaml +++ b/.github/workflows/extra.yaml @@ -9,7 +9,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kernel_build.sh diff --git a/.github/workflows/manual_test.yaml b/.github/workflows/manual_test.yaml index a6b17cfc..67699d54 100644 --- a/.github/workflows/manual_test.yaml +++ b/.github/workflows/manual_test.yaml @@ -19,7 +19,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kernel_build.sh @@ -34,7 +34,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Test Install run: ./tests/test_kernel_install.sh @@ -52,7 +52,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install Dependencies - run: ./deploy/dependencies/install_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh shell: bash - name: Build run: ./tests/test_kenel_dkms_install.sh || true diff --git a/deploy/Dockerfile.ubuntu b/deploy/Dockerfile.ubuntu.22.04 similarity index 78% rename from deploy/Dockerfile.ubuntu rename to deploy/Dockerfile.ubuntu.22.04 index 4b2e16b8..df054d6a 100644 --- a/deploy/Dockerfile.ubuntu +++ b/deploy/Dockerfile.ubuntu.22.04 @@ -20,11 +20,11 @@ RUN apt-get install -y gcc-12 RUN mkdir /opt/LinuxLegionLaptop WORKDIR /opt/LinuxLegionLaptop -COPY ./deploy/dependencies/install_dependencies_ubuntu.sh ./deploy/dependencies/install_dependencies_ubuntu.sh -RUN deploy/dependencies/install_dependencies_ubuntu.sh +COPY ./deploy/dependencies/install_dependencies_ubuntu_22_04.sh ./deploy/dependencies/install_dependencies_ubuntu_22_04.sh +RUN ./deploy/dependencies/install_dependencies_ubuntu_22_04.sh COPY ./deploy/dependencies ./deploy/dependencies -RUN deploy/dependencies/install_development_dependencies_ubuntu.sh +RUN ./deploy/dependencies/install_development_dependencies_ubuntu_22_04.sh COPY . /opt/LinuxLegionLaptop diff --git a/deploy/Dockerfile.ubuntu.24.04 b/deploy/Dockerfile.ubuntu.24.04 new file mode 100644 index 00000000..6786b3e9 --- /dev/null +++ b/deploy/Dockerfile.ubuntu.24.04 @@ -0,0 +1,38 @@ +FROM ubuntu:24.04 +ARG DEBIAN_FRONTEND=noninteractive + +# Install sudo (used in scripts that are tested) +RUN apt-get update && \ + apt-get -y install sudo + +# Set timezone (used by pylint) and locale +ENV LANG=en_US.UTF-8 +ENV LANGUAGE=en_US:en +ENV LC_ALL=en_US.UTF-8 +RUN ln -snf /usr/share/zoneinfo/US/Central /etc/localtime && echo US/Central > /etc/timezone && \ + apt-get -y install locales tzdata && \ + sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \ + locale-gen + + +RUN apt-get install -y gcc-12 + +RUN mkdir /opt/LinuxLegionLaptop +WORKDIR /opt/LinuxLegionLaptop + +COPY ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh +RUN ./deploy/dependencies/install_dependencies_ubuntu_24_04.sh + +COPY ./deploy/dependencies ./deploy/dependencies +RUN ./deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh + +COPY . /opt/LinuxLegionLaptop + +RUN tests/test_kernel_build.sh \ + && tests/test_kernel_install.sh +RUN tests/test_python_cli.sh +# && tests/test_python_gui.sh +RUN deploy/python_install_pip_pkg.sh \ + && tests/test_python_cli_installed.sh +# && tests/test_python_gui_installed.sh +#RUN tests/test_python_run_gui_root.sh diff --git a/deploy/dependencies/install_dependencies_ubuntu.sh b/deploy/dependencies/install_dependencies_ubuntu_22_04.sh similarity index 100% rename from deploy/dependencies/install_dependencies_ubuntu.sh rename to deploy/dependencies/install_dependencies_ubuntu_22_04.sh diff --git a/deploy/dependencies/install_dependencies_ubuntu_24_04.sh b/deploy/dependencies/install_dependencies_ubuntu_24_04.sh new file mode 100755 index 00000000..d4213713 --- /dev/null +++ b/deploy/dependencies/install_dependencies_ubuntu_24_04.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -ex +sudo apt-get update +sudo apt-get install -y make gcc clang linux-headers-$(uname -r) build-essential git lm-sensors wget python3-pyqt6 python3-yaml python3-venv python3-pip python3-wheel python3-argcomplete policykit-1 +sudo apt-get install -y dkms openssl mokutil diff --git a/deploy/dependencies/install_development_dependencies_ubuntu.sh b/deploy/dependencies/install_development_dependencies_ubuntu_22_04.sh similarity index 90% rename from deploy/dependencies/install_development_dependencies_ubuntu.sh rename to deploy/dependencies/install_development_dependencies_ubuntu_22_04.sh index 8d204717..e2228e13 100755 --- a/deploy/dependencies/install_development_dependencies_ubuntu.sh +++ b/deploy/dependencies/install_development_dependencies_ubuntu_22_04.sh @@ -14,5 +14,5 @@ sudo apt-get -y -qq install \ sudo pip install pyqt6-tools PyQt6 -${DIR}/install_dependencies_ubuntu.sh +${DIR}/install_dependencies_ubuntu_22_04.sh ${DIR}/linux_kernel/install_checkpath.sh diff --git a/deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh b/deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh new file mode 100755 index 00000000..b34f8245 --- /dev/null +++ b/deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -ex +DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# Needed in CI +sudo apt-get update + +# Linter +# Tools for running GUI tests headless +sudo apt-get -y -qq install \ + wget \ + pylint python3-venv python3-pip python3-build \ + python3-installer xvfb libxcb-xinerama0 pyqt6-dev-tools + +${DIR}/install_dependencies_ubuntu_24_04.sh +${DIR}/linux_kernel/install_checkpath.sh diff --git a/deploy/docker-compose.yaml b/deploy/docker-compose.yaml index 3e6fa295..ce01125d 100644 --- a/deploy/docker-compose.yaml +++ b/deploy/docker-compose.yaml @@ -18,10 +18,14 @@ services: # build: # context: .. # dockerfile: deploy/Dockerfile.suse - legion-ubuntu: + legion-ubuntu-22-04: build: context: .. - dockerfile: deploy/Dockerfile.ubuntu + dockerfile: deploy/Dockerfile.ubuntu.22.04 + legion-ubuntu-24-04: + build: + context: .. + dockerfile: deploy/Dockerfile.ubuntu.24.04 ubuntu: image: ubuntu:latest volumes: From 7db6754b5730a56eb6aba817572b295ced29b1e5 Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:08:18 +0200 Subject: [PATCH 07/12] fix: Fix CI ubuntu version --- .github/workflows/build.yml | 16 ++++++++-------- .github/workflows/build_PR.yml | 14 +++++++------- .github/workflows/extra.yaml | 4 ++-- .github/workflows/manual_test.yaml | 12 ++++++------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d7cced8..fd7ed25e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ on: branches: [ main, develop ] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu:24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -31,7 +31,7 @@ jobs: shell: bash run-kernel-module-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -49,7 +49,7 @@ jobs: shell: bash run-kernel-dkms-install-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -62,7 +62,7 @@ jobs: run-tests: name: Run Tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out Git repository uses: actions/checkout@v4 @@ -92,7 +92,7 @@ jobs: check-kernel-module-change: needs: [build, run-kernel-module-test, run-kernel-dkms-install-test, run-tests] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 outputs: output1: ${{ steps.filter.outputs.workflows }} steps: @@ -106,7 +106,7 @@ jobs: release-kernel-patch: needs: [check-kernel-module-change] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 with: @@ -166,7 +166,7 @@ jobs: test-in-docker-container: needs: [build, run-tests] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -175,7 +175,7 @@ jobs: shell: bash test-packages: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/build_PR.yml b/.github/workflows/build_PR.yml index 1930dae7..16fab8af 100644 --- a/.github/workflows/build_PR.yml +++ b/.github/workflows/build_PR.yml @@ -5,7 +5,7 @@ on: branches: [ main ] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -20,7 +20,7 @@ jobs: shell: bash run-kernel-module-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -38,7 +38,7 @@ jobs: shell: bash run-kernel-dkms-install-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -51,7 +51,7 @@ jobs: run-tests: name: Run Tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out Git repository uses: actions/checkout@v4 @@ -81,7 +81,7 @@ jobs: check-kernel-module-change: needs: [build, run-kernel-module-test, run-kernel-dkms-install-test, run-tests] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 outputs: output1: ${{ steps.filter.outputs.workflows }} steps: @@ -95,7 +95,7 @@ jobs: release-kernel-patch: needs: [check-kernel-module-change] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 with: @@ -107,7 +107,7 @@ jobs: test-in-docker-container: needs: [build, run-tests] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/extra.yaml b/.github/workflows/extra.yaml index dd5791b9..616b9b7f 100644 --- a/.github/workflows/extra.yaml +++ b/.github/workflows/extra.yaml @@ -4,7 +4,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -18,7 +18,7 @@ jobs: run: ./tests/test_kernel_install.sh shell: bash test-ci-env: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - name: Setup upterm session diff --git a/.github/workflows/manual_test.yaml b/.github/workflows/manual_test.yaml index 67699d54..66066a84 100644 --- a/.github/workflows/manual_test.yaml +++ b/.github/workflows/manual_test.yaml @@ -14,7 +14,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -29,7 +29,7 @@ jobs: shell: bash run-kernel-module-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -47,7 +47,7 @@ jobs: shell: bash run-kernel-dkms-install-test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -60,7 +60,7 @@ jobs: run-tests: name: Run Tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out Git repository uses: actions/checkout@v4 @@ -91,7 +91,7 @@ jobs: # Use to test kernel patch build if needed release-kernel-patch: needs: [build, run-kernel-module-test, run-kernel-dkms-install-test, run-tests] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: ${{ github.event.inputs.BUILD_KERNEL_PATCH == 'true' }} steps: - uses: actions/checkout@v4 @@ -103,7 +103,7 @@ jobs: test-in-docker-container: needs: [build, run-tests] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout uses: actions/checkout@v4 From 077017184a696d296e6ee7fcdf615c42999fb2f5 Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:12:00 +0200 Subject: [PATCH 08/12] fix: Fix installing dev dependencies in CI --- .github/workflows/build.yml | 2 +- .github/workflows/build_PR.yml | 2 +- .github/workflows/manual_test.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fd7ed25e..36867ba3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,7 @@ jobs: - name: Check out Git repository uses: actions/checkout@v4 - name: Install Development Dependencies - run: ./deploy/dependencies/install_development_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh shell: bash - name: Lint with Linux checkpath if: always() diff --git a/.github/workflows/build_PR.yml b/.github/workflows/build_PR.yml index 16fab8af..26b1e657 100644 --- a/.github/workflows/build_PR.yml +++ b/.github/workflows/build_PR.yml @@ -56,7 +56,7 @@ jobs: - name: Check out Git repository uses: actions/checkout@v4 - name: Install Development Dependencies - run: ./deploy/dependencies/install_development_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh shell: bash - name: Lint with Linux checkpath if: always() diff --git a/.github/workflows/manual_test.yaml b/.github/workflows/manual_test.yaml index 66066a84..51651f50 100644 --- a/.github/workflows/manual_test.yaml +++ b/.github/workflows/manual_test.yaml @@ -65,7 +65,7 @@ jobs: - name: Check out Git repository uses: actions/checkout@v4 - name: Install Development Dependencies - run: ./deploy/dependencies/install_development_dependencies_ubuntu.sh + run: ./deploy/dependencies/install_development_dependencies_ubuntu_24_04.sh shell: bash - name: Lint with Linux checkpath if: always() From 01bdb6e7adf311b017676f0c012cb7e663b8e376 Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:40:08 +0200 Subject: [PATCH 09/12] fix: Fix pylint errors because no-self-use was disabled in new pytlint --- python/legion_linux/pylintrc | 2 +- tests/test_python.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/legion_linux/pylintrc b/python/legion_linux/pylintrc index 662f00d1..8446379f 100644 --- a/python/legion_linux/pylintrc +++ b/python/legion_linux/pylintrc @@ -2,7 +2,7 @@ init-hook='import sys; sys.path.append("python/legion_linux")' [MESSAGES CONTROL] -disable=missing-docstring,too-many-arguments,too-many-locals, import-error, duplicate-code, missing-module-docstring, too-many-instance-attributes, too-many-public-methods, no-name-in-module +disable=missing-docstring,no-self-use,too-many-arguments,too-many-locals, import-error, duplicate-code, missing-module-docstring, too-many-instance-attributes, too-many-public-methods, no-name-in-module [FORMAT] max-line-length=120 diff --git a/tests/test_python.sh b/tests/test_python.sh index 33c1995a..f5b1fec9 100755 --- a/tests/test_python.sh +++ b/tests/test_python.sh @@ -2,4 +2,4 @@ set -ex DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -pylint --ignore-patterns=legion_gui_qt6.py,legion_version.py --rcfile ${DIR}/../python/legion_linux/pylintrc ${DIR}/../python/legion_linux/legion_linux \ No newline at end of file +pylint --ignore-patterns=legion_gui_qt6.py,legion_version.py --disable no-self-use --rcfile ${DIR}/../python/legion_linux/pylintrc ${DIR}/../python/legion_linux/legion_linux \ No newline at end of file From 2d0eb103937cc615f6535ab5a21eef398da739d9 Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:41:07 +0200 Subject: [PATCH 10/12] fix: Fix linter errors --- python/legion_linux/legion_linux/legion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/legion_linux/legion_linux/legion.py b/python/legion_linux/legion_linux/legion.py index 78cb165c..fc29d801 100755 --- a/python/legion_linux/legion_linux/legion.py +++ b/python/legion_linux/legion_linux/legion.py @@ -752,7 +752,7 @@ def __init__(self, expect_hwmon=True): super().__init__() self.hwmon_path = self._find_hwmon_dir() if (not self.hwmon_path) and expect_hwmon: - raise Exception("hwmon dir not found") + raise FileNotFoundError("hwmon dir not found") def exists(self): if self.hwmon_path is not None: @@ -793,7 +793,7 @@ def _write_file(file_path, value): def _write_file_or(file_path, value): if os.path.exists(file_path): FanCurveIO._write_file(file_path, value) - + def get_fan_1_max_rpm(self): file_path = self.hwmon_path + self.fan1_max return int(self._read_file(file_path)) From 18ae74c2fa68386ff82043584cc5095d47e4cd9a Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:49:12 +0200 Subject: [PATCH 11/12] fix: Remove disabling no-self-use lint check --- python/legion_linux/legion_linux/legion.py | 5 ----- python/legion_linux/legion_linux/legion_cli.py | 4 ---- python/legion_linux/pylintrc | 2 +- tests/test_python.sh | 2 +- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/python/legion_linux/legion_linux/legion.py b/python/legion_linux/legion_linux/legion.py index fc29d801..51c3969a 100755 --- a/python/legion_linux/legion_linux/legion.py +++ b/python/legion_linux/legion_linux/legion.py @@ -165,11 +165,9 @@ def _notify(self): for func in self.callbacks: func(self) - # pylint: disable=no-self-use def exists(self): return True - # pylint: disable=no-self-use def get_values(self) -> List[NamedValue]: return [] @@ -299,7 +297,6 @@ def _find_by_file_pattern(pattern): return matches[0] return None - # pylint: disable=no-self-use def get_values(self) -> List[NamedValue]: return [] @@ -667,7 +664,6 @@ def _exec_cmd(self, cmd, timeout=None) -> Tuple[str, int]: def name(self): return type(self).__name__ - # pylint: disable=no-self-use def get_values(self) -> List[NamedValue]: return [] @@ -1050,7 +1046,6 @@ def get_settings(self) -> Settings: settings.setting_entries[name] = value return settings - # pylint: disable=no-self-use def apply_settings(self, preset: Settings): for name, value in preset.setting_entries.items(): log.error("Try seting %s from preset to %s", name, value) diff --git a/python/legion_linux/legion_linux/legion_cli.py b/python/legion_linux/legion_linux/legion_cli.py index c0c6dc87..655de67a 100755 --- a/python/legion_linux/legion_linux/legion_cli.py +++ b/python/legion_linux/legion_linux/legion_cli.py @@ -66,19 +66,15 @@ def command_disable_cli(self, **_) -> int: return self.command_disable() return -10 - # pylint: disable=no-self-use def exists(self) -> bool: return False - # pylint: disable=no-self-use def command_status(self, **_) -> int: return 0 - # pylint: disable=no-self-use def command_enable(self, **_) -> int: return -1 - # pylint: disable=no-self-use def command_disable(self, **_) -> int: return -1 diff --git a/python/legion_linux/pylintrc b/python/legion_linux/pylintrc index 8446379f..662f00d1 100644 --- a/python/legion_linux/pylintrc +++ b/python/legion_linux/pylintrc @@ -2,7 +2,7 @@ init-hook='import sys; sys.path.append("python/legion_linux")' [MESSAGES CONTROL] -disable=missing-docstring,no-self-use,too-many-arguments,too-many-locals, import-error, duplicate-code, missing-module-docstring, too-many-instance-attributes, too-many-public-methods, no-name-in-module +disable=missing-docstring,too-many-arguments,too-many-locals, import-error, duplicate-code, missing-module-docstring, too-many-instance-attributes, too-many-public-methods, no-name-in-module [FORMAT] max-line-length=120 diff --git a/tests/test_python.sh b/tests/test_python.sh index f5b1fec9..33c1995a 100755 --- a/tests/test_python.sh +++ b/tests/test_python.sh @@ -2,4 +2,4 @@ set -ex DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -pylint --ignore-patterns=legion_gui_qt6.py,legion_version.py --disable no-self-use --rcfile ${DIR}/../python/legion_linux/pylintrc ${DIR}/../python/legion_linux/legion_linux \ No newline at end of file +pylint --ignore-patterns=legion_gui_qt6.py,legion_version.py --rcfile ${DIR}/../python/legion_linux/pylintrc ${DIR}/../python/legion_linux/legion_linux \ No newline at end of file From 444e6c5171a04e9440b3b30d7d4bed088c234ff5 Mon Sep 17 00:00:00 2001 From: johnfan Date: Sat, 19 Oct 2024 19:57:19 +0200 Subject: [PATCH 12/12] fix: Disable testing in ubuntu 22.04 container on 24.04 host in CI --- deploy/docker-compose.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy/docker-compose.yaml b/deploy/docker-compose.yaml index ce01125d..6a72929d 100644 --- a/deploy/docker-compose.yaml +++ b/deploy/docker-compose.yaml @@ -18,10 +18,10 @@ services: # build: # context: .. # dockerfile: deploy/Dockerfile.suse - legion-ubuntu-22-04: - build: - context: .. - dockerfile: deploy/Dockerfile.ubuntu.22.04 + # legion-ubuntu-22-04: + # build: + # context: .. + # dockerfile: deploy/Dockerfile.ubuntu.22.04 legion-ubuntu-24-04: build: context: ..