Commit ca56caa02182044667b680154a0550ad52726584

Authored by Eduardo Valentin
Committed by Zhang Rui
1 parent 178c2490b9

thermal: step_wise: return instance->target by default

In case the trend is not changing or when there is no
request for throttling, it is expected that the instance
would not change its requested target. This patch improves
the code implementation to cover for this expected behavior.

With current implementation, the instance will always
reset to cdev.cur_state, even in not expected cases,
like those mentioned above.

This patch changes the step_wise governor implementation
of get_target so that we accomplish:
(a) - default value will be current instance->target, so
we do not change the thermal instance target unnecessarily.
(b) - the code now it is clear about what is the intention.
There is a clear statement of what are the expected outcomes
(c) - removal of hardcoded constants, now it is put in use
the THERMAL_NO_TARGET macro.
(d) - variable names are also improved so that reader can
clearly understand the difference between instance cur target,
next target and cdev cur_state.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Durgadoss R <durgadoss.r@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reported-by: Ruslan Ruslichenko <ruslan.ruslichenko@ti.com>
Signed-of-by: Eduardo Valentin <eduardo.valentin@ti.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>

Showing 1 changed file with 18 additions and 11 deletions Side-by-side Diff

drivers/thermal/step_wise.c
... ... @@ -51,44 +51,51 @@
51 51 {
52 52 struct thermal_cooling_device *cdev = instance->cdev;
53 53 unsigned long cur_state;
  54 + unsigned long next_target;
54 55  
  56 + /*
  57 + * We keep this instance the way it is by default.
  58 + * Otherwise, we use the current state of the
  59 + * cdev in use to determine the next_target.
  60 + */
55 61 cdev->ops->get_cur_state(cdev, &cur_state);
  62 + next_target = instance->target;
56 63  
57 64 switch (trend) {
58 65 case THERMAL_TREND_RAISING:
59 66 if (throttle) {
60   - cur_state = cur_state < instance->upper ?
  67 + next_target = cur_state < instance->upper ?
61 68 (cur_state + 1) : instance->upper;
62   - if (cur_state < instance->lower)
63   - cur_state = instance->lower;
  69 + if (next_target < instance->lower)
  70 + next_target = instance->lower;
64 71 }
65 72 break;
66 73 case THERMAL_TREND_RAISE_FULL:
67 74 if (throttle)
68   - cur_state = instance->upper;
  75 + next_target = instance->upper;
69 76 break;
70 77 case THERMAL_TREND_DROPPING:
71 78 if (cur_state == instance->lower) {
72 79 if (!throttle)
73   - cur_state = -1;
  80 + next_target = THERMAL_NO_TARGET;
74 81 } else {
75   - cur_state -= 1;
76   - if (cur_state > instance->upper)
77   - cur_state = instance->upper;
  82 + next_target = cur_state - 1;
  83 + if (next_target > instance->upper)
  84 + next_target = instance->upper;
78 85 }
79 86 break;
80 87 case THERMAL_TREND_DROP_FULL:
81 88 if (cur_state == instance->lower) {
82 89 if (!throttle)
83   - cur_state = -1;
  90 + next_target = THERMAL_NO_TARGET;
84 91 } else
85   - cur_state = instance->lower;
  92 + next_target = instance->lower;
86 93 break;
87 94 default:
88 95 break;
89 96 }
90 97  
91   - return cur_state;
  98 + return next_target;
92 99 }
93 100  
94 101 static void update_passive_instance(struct thermal_zone_device *tz,