Fishwaldo opened a new pull request, #19893:
URL: https://github.com/apache/nuttx/pull/19893
## Summary
The thermal framework's frequency cooling device was written against a
cpufreq
framework that never landed. It includes `nuttx/cpufreq.h`, which does not
exist, and `THERMAL_CDEV_CPUFREQ` depends on `CPUFREQ`, which no Kconfig in
the
tree defines, so it has never been selectable and has never been compiled.
The
cpufreq half of the dummy driver is orphaned the same way behind
`THERMAL_DUMMY_CPUFREQ`. Upstream noticed once already and dropped cpufreq
from
the sim thermal configuration in 898a5d501f.
devfreq does the same job and is in the tree. It owns the frequency table,
arbitrates windows through QoS, and documents `DEVFREQ_CONFLICT_PREFER_LOW`
as
the policy for a device protecting a thermal budget, which is exactly a
cooling
device's claim on it. This points the cooling device at devfreq instead, so
the
thermal framework can throttle frequency again.
The first commit is a pure rename with no content change, to keep the
conversion readable.
## What changes beyond the API
**A cooling state names a ceiling, not a two entry window.** devfreq
resolves a
conflicting floor in the ceiling's favour, so the whole table becomes
reachable: `max_state` is one less than the number of usable entries, state
zero leaves the top entry available, and the highest state holds the device
at
the bottom one. An entry of `DEVFREQ_ENTRY_INVALID` is a hole the driver has
punched and cannot be installed as a ceiling, so it earns no cooling state.
**The device is found by name.** devfreq is multi instance where a cpufreq
policy was singular, so `THERMAL_CDEV_DEVFREQ_NAME` says which device to cool
and what to call the cooling device in a zone's cooling map.
`THERMAL_CDEV_CPUFREQ` and `THERMAL_DUMMY_CPUFREQ` are renamed to
`..._DEVFREQ`. Neither old symbol has any user in the tree, so no
configuration
silently loses a setting.
## Two faults this exposes
Neither could be reached while the file was uncompilable:
* `therr` and `thinfo` were called without including `nuttx/debug.h`.
* The driver was reached by casting the policy pointer, which works only
while
`driver` is the first member of the struct.
## Testing
`sim:thermal`, which this PR extends to cover the path. The dummy driver
gains
a devfreq lower half in place of its cpufreq one, giving the tree its only
devfreq lower half and making the whole path testable without hardware.
Walking the dummy zone from 45 to 90 degrees and back:
```
temp cooling state ceiling / frequency (kHz)
60 0 900
62 1 700
61 2 500
72 3 300
74 4 100
```
`/proc/devfreq/cpu` follows the ceiling to each of the five table entries and
returns to 900 as the zone cools. The fan and passive cooling devices stay
bound alongside.
The `DEVFREQ_ENTRY_INVALID` path has no in-tree producer, so it was tested by
temporarily replacing `300` with a hole in the dummy's table. Four usable
entries give `max level of cpu is 3`, `/proc/devfreq/cpu` reports
`freq_table: 100 500 700 900`, and cooling states 1 to 3 install 700, 500 and
100. Counting the hole instead would install a ceiling of `0xFFFFFFFF` at
state
3, which caps nothing while the governor believes it has throttled. The
table is
restored in what is committed here.
Full `distclean` and rebuild, no compiler warnings. `tools/checkpatch.sh`
passes on all four commits. Documentation builds with `-W` and no new
warnings.
## Notes for reviewers
* **CI compiles this**, unlike the code it replaces. The sim thermal
defconfig
gains `DEVFREQ` and `THERMAL_DUMMY_DEVFREQ`, so both the cooling device and
the dummy lower half are built.
* **One cooling device, named at build time.** Linux allows one per devfreq
device. Enough for the single frequency domain this targets, but worth
knowing before someone needs two.
* **Registration order matters, and failure is not soft.** The devfreq device
must be registered before `thermal_init()`, which returns `-ENOTSUP` if the
cooling device cannot be created, taking the rest of the thermal subsystem
down with it. A typo in `THERMAL_CDEV_DEVFREQ_NAME` therefore costs the fan
as well. The Kconfig help states the ordering requirement. Happy to make a
missing cooling device non fatal if you would prefer that.
* **The fourth commit touches `include/nuttx/devfreq.h` and is comments
only.**
The frequency table's rules were only discoverable by reading
`devfreq_table_validate()` and the other places that skip
`DEVFREQ_ENTRY_INVALID`, so they are now stated where the special values
are
defined, along with the fact that `get_table` is called once and its result
retained for the life of the device. Separate commit so it can be dropped
independently.
* No dependency on any other PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]