|
| 1 | +From a975f22abc2b75614f5a58ea8af843043ade782f Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Mon, 30 Mar 2020 10:05:25 +0000 |
| 4 | +Subject: [hwmon-next 04/14] mlxsw: core: Add the hottest thermal zone |
| 5 | + detection |
| 6 | + |
| 7 | +When multiple sensors are mapped to the same cooling device, the |
| 8 | +cooling device should be set according the worst sensor from the |
| 9 | +sensors associated with this cooling device. |
| 10 | + |
| 11 | +Provide the hottest thermal zone detection and enforce cooling device |
| 12 | +to follow the temperature trends of the hottest zone only. |
| 13 | +Prevent competition for the cooling device control from others zones, |
| 14 | +by "stable trend" indication. A cooling device will not perform any |
| 15 | +actions associated with a zone with a "stable trend". |
| 16 | + |
| 17 | +When other thermal zone is detected as a hottest, a cooling device is |
| 18 | +to be switched to following temperature trends of new hottest zone. |
| 19 | + |
| 20 | +Thermal zone score is represented by 32 bits unsigned integer and |
| 21 | +calculated according to the next formula: |
| 22 | +For T < TZ<t><i>, where t from {normal trip = 0, high trip = 1, hot |
| 23 | +trip = 2, critical = 3}: |
| 24 | +TZ<i> score = (T + (TZ<t><i> - T) / 2) / (TZ<t><i> - T) * 256 ** j; |
| 25 | +Highest thermal zone score s is set as MAX(TZ<i>score); |
| 26 | +Following this formula, if TZ<i> is in trip point higher than TZ<k>, |
| 27 | +the higher score is to be always assigned to TZ<i>. |
| 28 | + |
| 29 | +For two thermal zones located at the same kind of trip point, the higher |
| 30 | +score will be assigned to the zone which is closer to the next trip |
| 31 | +point. Thus, the highest score will always be assigned objectively to |
| 32 | +the hottest thermal zone. |
| 33 | + |
| 34 | +All the thermal zones initially are to be configured with mode |
| 35 | +"enabled" with the "step_wise" governor. |
| 36 | + |
| 37 | +--- |
| 38 | + drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 55 ++++++++++++++++++++++ |
| 39 | + 1 file changed, 55 insertions(+) |
| 40 | + |
| 41 | +diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c |
| 42 | +index e1e18ea..53198e2 100644 |
| 43 | +--- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c |
| 44 | ++++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c |
| 45 | +@@ -27,6 +27,7 @@ |
| 46 | + #define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */ |
| 47 | + #define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2) |
| 48 | + #define MLXSW_THERMAL_ZONE_MAX_NAME 16 |
| 49 | ++#define MLXSW_THERMAL_TEMP_SCORE_MAX GENMASK(31, 0) |
| 50 | + #define MLXSW_THERMAL_MAX_STATE 10 |
| 51 | + #define MLXSW_THERMAL_MAX_DUTY 255 |
| 52 | + /* Minimum and maximum fan allowed speed in percent: from 20% to 100%. Values |
| 53 | +@@ -205,6 +206,34 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core, |
| 54 | + return 0; |
| 55 | + } |
| 56 | + |
| 57 | ++static void mlxsw_thermal_tz_score_update(struct mlxsw_thermal *thermal, |
| 58 | ++ struct thermal_zone_device *tzdev, |
| 59 | ++ struct mlxsw_thermal_trip *trips, |
| 60 | ++ int temp) |
| 61 | ++{ |
| 62 | ++ struct mlxsw_thermal_trip *trip = trips; |
| 63 | ++ unsigned int score, delta, i, shift = 1; |
| 64 | ++ |
| 65 | ++ /* Calculate thermal zone score, if temperature is above the critical |
| 66 | ++ * threshold score is set to MLXSW_THERMAL_TEMP_SCORE_MAX. |
| 67 | ++ */ |
| 68 | ++ score = MLXSW_THERMAL_TEMP_SCORE_MAX; |
| 69 | ++ for (i = MLXSW_THERMAL_TEMP_TRIP_NORM; i < MLXSW_THERMAL_NUM_TRIPS; |
| 70 | ++ i++, trip++) { |
| 71 | ++ if (temp < trip->temp) { |
| 72 | ++ delta = DIV_ROUND_CLOSEST(temp, trip->temp - temp); |
| 73 | ++ score = delta * shift; |
| 74 | ++ break; |
| 75 | ++ } |
| 76 | ++ shift *= 256; |
| 77 | ++ } |
| 78 | ++ |
| 79 | ++ if (score > thermal->tz_highest_score) { |
| 80 | ++ thermal->tz_highest_score = score; |
| 81 | ++ thermal->tz_highest_dev = tzdev; |
| 82 | ++ } |
| 83 | ++} |
| 84 | ++ |
| 85 | + static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev, |
| 86 | + struct thermal_cooling_device *cdev) |
| 87 | + { |
| 88 | +@@ -306,6 +335,9 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, |
| 89 | + return err; |
| 90 | + } |
| 91 | + mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL); |
| 92 | ++ if (temp > 0) |
| 93 | ++ mlxsw_thermal_tz_score_update(thermal, tzdev, thermal->trips, |
| 94 | ++ temp); |
| 95 | + |
| 96 | + *p_temp = temp; |
| 97 | + return 0; |
| 98 | +@@ -367,6 +399,22 @@ static int mlxsw_thermal_set_trip_hyst(struct thermal_zone_device *tzdev, |
| 99 | + return 0; |
| 100 | + } |
| 101 | + |
| 102 | ++static int mlxsw_thermal_trend_get(struct thermal_zone_device *tzdev, |
| 103 | ++ int trip, enum thermal_trend *trend) |
| 104 | ++{ |
| 105 | ++ struct mlxsw_thermal_module *tz = tzdev->devdata; |
| 106 | ++ struct mlxsw_thermal *thermal = tz->parent; |
| 107 | ++ |
| 108 | ++ if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) |
| 109 | ++ return -EINVAL; |
| 110 | ++ |
| 111 | ++ if (tzdev == thermal->tz_highest_dev) |
| 112 | ++ return 1; |
| 113 | ++ |
| 114 | ++ *trend = THERMAL_TREND_STABLE; |
| 115 | ++ return 0; |
| 116 | ++} |
| 117 | ++ |
| 118 | + struct thermal_zone_params mlxsw_thermal_params = { |
| 119 | + .no_hwmon = true, |
| 120 | + }; |
| 121 | +@@ -382,6 +430,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = { |
| 122 | + .set_trip_temp = mlxsw_thermal_set_trip_temp, |
| 123 | + .get_trip_hyst = mlxsw_thermal_get_trip_hyst, |
| 124 | + .set_trip_hyst = mlxsw_thermal_set_trip_hyst, |
| 125 | ++ .get_trend = mlxsw_thermal_trend_get, |
| 126 | + }; |
| 127 | + |
| 128 | + static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev, |
| 129 | +@@ -499,6 +548,8 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, |
| 130 | + |
| 131 | + /* Update trip points. */ |
| 132 | + err = mlxsw_thermal_module_trips_update(dev, thermal->core, tz); |
| 133 | ++ if (!err && temp > 0) |
| 134 | ++ mlxsw_thermal_tz_score_update(thermal, tzdev, tz->trips, temp); |
| 135 | + |
| 136 | + return 0; |
| 137 | + } |
| 138 | +@@ -574,6 +625,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { |
| 139 | + .set_trip_temp = mlxsw_thermal_module_trip_temp_set, |
| 140 | + .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get, |
| 141 | + .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set, |
| 142 | ++ .get_trend = mlxsw_thermal_trend_get, |
| 143 | + }; |
| 144 | + |
| 145 | + static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, |
| 146 | +@@ -600,6 +652,8 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, |
| 147 | + return err; |
| 148 | + |
| 149 | + mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL); |
| 150 | ++ if (temp > 0) |
| 151 | ++ mlxsw_thermal_tz_score_update(thermal, tzdev, tz->trips, temp); |
| 152 | + |
| 153 | + *p_temp = temp; |
| 154 | + return 0; |
| 155 | +@@ -616,6 +670,7 @@ static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { |
| 156 | + .set_trip_temp = mlxsw_thermal_module_trip_temp_set, |
| 157 | + .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get, |
| 158 | + .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set, |
| 159 | ++ .get_trend = mlxsw_thermal_trend_get, |
| 160 | + }; |
| 161 | + |
| 162 | + static int mlxsw_thermal_get_max_state(struct thermal_cooling_device *cdev, |
| 163 | +-- |
| 164 | +2.11.0 |
| 165 | + |
0 commit comments