Commit 6f73862f authored by Vadim Pasternak's avatar Vadim Pasternak Committed by David S. Miller

mlxsw: core: Add the hottest thermal zone detection

When multiple sensors are mapped to the same cooling device, the
cooling device should be set according the worst sensor from the
sensors associated with this cooling device.

Provide the hottest thermal zone detection and enforce cooling device
to follow the temperature trends of the hottest zone only.
Prevent competition for the cooling device control from others zones,
by "stable trend" indication. A cooling device will not perform any
actions associated with a zone with a "stable trend".

When other thermal zone is detected as a hottest, a cooling device is
to be switched to following temperature trends of new hottest zone.

Thermal zone score is represented by 32 bits unsigned integer and
calculated according to the next formula:
For T < TZ<t><i>, where t from {normal trip = 0, high trip = 1, hot
trip = 2, critical = 3}:
TZ<i> score = (T + (TZ<t><i> - T) / 2) / (TZ<t><i> - T) * 256 ** j;
Highest thermal zone score s is set as MAX(TZ<i>score);
Following this formula, if TZ<i> is in trip point higher than TZ<k>,
the higher score is to be always assigned to TZ<i>.

For two thermal zones located at the same kind of trip point, the higher
score will be assigned to the zone which is closer to the next trip
point. Thus, the highest score will always be assigned objectively to
the hottest thermal zone.

All the thermal zones initially are to be configured with mode
"enabled" with the "step_wise" governor.
Signed-off-by: default avatarVadim Pasternak <vadimp@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f14f4e62
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */ #define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */
#define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2) #define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2)
#define MLXSW_THERMAL_ZONE_MAX_NAME 16 #define MLXSW_THERMAL_ZONE_MAX_NAME 16
#define MLXSW_THERMAL_TEMP_SCORE_MAX GENMASK(31, 0)
#define MLXSW_THERMAL_MAX_STATE 10 #define MLXSW_THERMAL_MAX_STATE 10
#define MLXSW_THERMAL_MAX_DUTY 255 #define MLXSW_THERMAL_MAX_DUTY 255
/* Minimum and maximum fan allowed speed in percent: from 20% to 100%. Values /* Minimum and maximum fan allowed speed in percent: from 20% to 100%. Values
...@@ -113,6 +114,8 @@ struct mlxsw_thermal { ...@@ -113,6 +114,8 @@ struct mlxsw_thermal {
struct mlxsw_thermal_module *tz_module_arr; struct mlxsw_thermal_module *tz_module_arr;
struct mlxsw_thermal_module *tz_gearbox_arr; struct mlxsw_thermal_module *tz_gearbox_arr;
u8 tz_gearbox_num; u8 tz_gearbox_num;
unsigned int tz_highest_score;
struct thermal_zone_device *tz_highest_dev;
}; };
static inline u8 mlxsw_state_to_duty(int state) static inline u8 mlxsw_state_to_duty(int state)
...@@ -197,6 +200,34 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core, ...@@ -197,6 +200,34 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
return 0; return 0;
} }
static void mlxsw_thermal_tz_score_update(struct mlxsw_thermal *thermal,
struct thermal_zone_device *tzdev,
struct mlxsw_thermal_trip *trips,
int temp)
{
struct mlxsw_thermal_trip *trip = trips;
unsigned int score, delta, i, shift = 1;
/* Calculate thermal zone score, if temperature is above the critical
* threshold score is set to MLXSW_THERMAL_TEMP_SCORE_MAX.
*/
score = MLXSW_THERMAL_TEMP_SCORE_MAX;
for (i = MLXSW_THERMAL_TEMP_TRIP_NORM; i < MLXSW_THERMAL_NUM_TRIPS;
i++, trip++) {
if (temp < trip->temp) {
delta = DIV_ROUND_CLOSEST(temp, trip->temp - temp);
score = delta * shift;
break;
}
shift *= 256;
}
if (score > thermal->tz_highest_score) {
thermal->tz_highest_score = score;
thermal->tz_highest_dev = tzdev;
}
}
static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
struct thermal_cooling_device *cdev) struct thermal_cooling_device *cdev)
{ {
...@@ -292,6 +323,9 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, ...@@ -292,6 +323,9 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
return err; return err;
} }
mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL); mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL);
if (temp > 0)
mlxsw_thermal_tz_score_update(thermal, tzdev, thermal->trips,
temp);
*p_temp = (int) temp; *p_temp = (int) temp;
return 0; return 0;
...@@ -353,6 +387,22 @@ static int mlxsw_thermal_set_trip_hyst(struct thermal_zone_device *tzdev, ...@@ -353,6 +387,22 @@ static int mlxsw_thermal_set_trip_hyst(struct thermal_zone_device *tzdev,
return 0; return 0;
} }
static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev,
int trip, enum thermal_trend *trend)
{
struct mlxsw_thermal_module *tz = tzdev->devdata;
struct mlxsw_thermal *thermal = tz->parent;
if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS)
return -EINVAL;
if (tzdev == thermal->tz_highest_dev)
return 1;
*trend = THERMAL_TREND_STABLE;
return 0;
}
static struct thermal_zone_device_ops mlxsw_thermal_ops = { static struct thermal_zone_device_ops mlxsw_thermal_ops = {
.bind = mlxsw_thermal_bind, .bind = mlxsw_thermal_bind,
.unbind = mlxsw_thermal_unbind, .unbind = mlxsw_thermal_unbind,
...@@ -364,6 +414,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = { ...@@ -364,6 +414,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = {
.set_trip_temp = mlxsw_thermal_set_trip_temp, .set_trip_temp = mlxsw_thermal_set_trip_temp,
.get_trip_hyst = mlxsw_thermal_get_trip_hyst, .get_trip_hyst = mlxsw_thermal_get_trip_hyst,
.set_trip_hyst = mlxsw_thermal_set_trip_hyst, .set_trip_hyst = mlxsw_thermal_set_trip_hyst,
.get_trend = mlxsw_thermal_trend_get,
}; };
static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev, static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
...@@ -474,7 +525,9 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, ...@@ -474,7 +525,9 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
return 0; return 0;
/* Update trip points. */ /* Update trip points. */
mlxsw_thermal_module_trips_update(dev, thermal->core, tz); err = mlxsw_thermal_module_trips_update(dev, thermal->core, tz);
if (!err)
mlxsw_thermal_tz_score_update(thermal, tzdev, tz->trips, temp);
return 0; return 0;
} }
...@@ -539,10 +592,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, ...@@ -539,10 +592,6 @@ mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip,
return 0; return 0;
} }
static struct thermal_zone_params mlxsw_thermal_module_params = {
.governor_name = "user_space",
};
static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
.bind = mlxsw_thermal_module_bind, .bind = mlxsw_thermal_module_bind,
.unbind = mlxsw_thermal_module_unbind, .unbind = mlxsw_thermal_module_unbind,
...@@ -554,6 +603,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { ...@@ -554,6 +603,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
.set_trip_temp = mlxsw_thermal_module_trip_temp_set, .set_trip_temp = mlxsw_thermal_module_trip_temp_set,
.get_trip_hyst = mlxsw_thermal_module_trip_hyst_get, .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get,
.set_trip_hyst = mlxsw_thermal_module_trip_hyst_set, .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set,
.get_trend = mlxsw_thermal_trend_get,
}; };
static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
...@@ -574,6 +624,8 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, ...@@ -574,6 +624,8 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
return err; return err;
mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL); mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL);
if (temp > 0)
mlxsw_thermal_tz_score_update(thermal, tzdev, tz->trips, temp);
*p_temp = (int) temp; *p_temp = (int) temp;
return 0; return 0;
...@@ -590,10 +642,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { ...@@ -590,10 +642,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = {
.set_trip_temp = mlxsw_thermal_module_trip_temp_set, .set_trip_temp = mlxsw_thermal_module_trip_temp_set,
.get_trip_hyst = mlxsw_thermal_module_trip_hyst_get, .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get,
.set_trip_hyst = mlxsw_thermal_module_trip_hyst_set, .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set,
}; .get_trend = mlxsw_thermal_trend_get,
static struct thermal_zone_params mlxsw_thermal_gearbox_params = {
.governor_name = "user_space",
}; };
static int mlxsw_thermal_get_max_state(struct thermal_cooling_device *cdev, static int mlxsw_thermal_get_max_state(struct thermal_cooling_device *cdev,
...@@ -709,13 +758,13 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) ...@@ -709,13 +758,13 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
MLXSW_THERMAL_TRIP_MASK, MLXSW_THERMAL_TRIP_MASK,
module_tz, module_tz,
&mlxsw_thermal_module_ops, &mlxsw_thermal_module_ops,
&mlxsw_thermal_module_params, NULL, 0, 0);
0, 0);
if (IS_ERR(module_tz->tzdev)) { if (IS_ERR(module_tz->tzdev)) {
err = PTR_ERR(module_tz->tzdev); err = PTR_ERR(module_tz->tzdev);
return err; return err;
} }
module_tz->mode = THERMAL_DEVICE_ENABLED;
return 0; return 0;
} }
...@@ -833,11 +882,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) ...@@ -833,11 +882,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
MLXSW_THERMAL_TRIP_MASK, MLXSW_THERMAL_TRIP_MASK,
gearbox_tz, gearbox_tz,
&mlxsw_thermal_gearbox_ops, &mlxsw_thermal_gearbox_ops,
&mlxsw_thermal_gearbox_params, NULL, 0, 0);
0, 0);
if (IS_ERR(gearbox_tz->tzdev)) if (IS_ERR(gearbox_tz->tzdev))
return PTR_ERR(gearbox_tz->tzdev); return PTR_ERR(gearbox_tz->tzdev);
gearbox_tz->mode = THERMAL_DEVICE_ENABLED;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment