Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thermal framework #12824

Merged
merged 19 commits into from
Sep 23, 2024
Merged

Conversation

JianyuWang0623
Copy link
Contributor

@JianyuWang0623 JianyuWang0623 commented Aug 1, 2024

Summary

  • Add thermal framework
    • governor: step_wise
    • cooling device: cpufreq
    • debug: procfs
  • For example, see: drivers/thermal/thermal_dummy.c.
  • Refs: Linux,《SoC底层软件低功耗系统设计与实现 》, ...

Please see Documentation/components/drivers/thermal/index.rst of this PR for more details

Impact

New feature, disabled by default.

Testing

Configuration & Build

./tools/configure.sh -l sim:thermal && make -j8

Runtime

  • Debug info, as Documentation/components/drivers/thermal/index.rst or drivers/thermal/thermal_procfs.c (of this PR):
z:cpu-thermal t:48 t:1 h:16 l:0 c:fan0 s:0|4294967295

z: Zone Device name
t: Temperature
t: Trip ID
h: Upper temperature
l: Lower temperature
c: Cooling Device name
s: Cooling State (current | target)
  • Start
$ ./nuttx 
thermal_register_governor: Register governor step_wise
thermal_register_governor: Default governor step_wise registered!
thermal_cooling_device_register: Registered cooling device fan0
thermal_zone_device_register: Set governor of zone cpu-thermal to step_wise.
zone_bind_cooling: Adding instance zdev:cpu-thermal cdev:fan0 h:16 l: 0 t:1
thermal_zone_device_register: Registered zone device cpu-thermal

NuttShell (NSH) NuttX-12.6.0-RC1
MOTD: username=admin password=Administrator
nsh> cat /etc/1.sh
while true; do cat /proc/thermal/cpu-thermal; sleep 2; done;
nsh> sh /etc/1.sh
z:cpu-thermal t:48 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:49 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:50 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:51 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:52 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:53 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:54 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:55 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:56 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:57 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:58 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:59 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:60 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:61 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:62 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:63 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:64 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:65 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:66 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:67 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:68 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:69 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:70 t:1 h:16 l:0 c:fan0 s:0|4294967295
z:cpu-thermal t:71 t:1 h:16 l:0 c:fan0 s:1|1
z:cpu-thermal t:72 t:1 h:16 l:0 c:fan0 s:2|2
z:cpu-thermal t:73 t:1 h:16 l:0 c:fan0 s:3|3
z:cpu-thermal t:74 t:1 h:16 l:0 c:fan0 s:4|4
z:cpu-thermal t:75 t:1 h:16 l:0 c:fan0 s:5|5
z:cpu-thermal t:76 t:1 h:16 l:0 c:fan0 s:6|6
z:cpu-thermal t:77 t:1 h:16 l:0 c:fan0 s:7|7
z:cpu-thermal t:78 t:1 h:16 l:0 c:fan0 s:8|8
z:cpu-thermal t:79 t:1 h:16 l:0 c:fan0 s:9|9
z:cpu-thermal t:80 t:1 h:16 l:0 c:fan0 s:10|10
z:cpu-thermal t:81 t:1 h:16 l:0 c:fan0 s:11|11
z:cpu-thermal t:82 t:1 h:16 l:0 c:fan0 s:12|12
z:cpu-thermal t:83 t:1 h:16 l:0 c:fan0 s:13|13
z:cpu-thermal t:84 t:1 h:16 l:0 c:fan0 s:14|14
z:cpu-thermal t:85 t:1 h:16 l:0 c:fan0 s:15|15
z:cpu-thermal t:86 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:87 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:88 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:89 t:1 h:16 l:0 c:fan0 s:16|16
thermal_zone_device_update: Thermal critical (90), resetting...
z:cpu-thermal t:90 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:89 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:88 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:87 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:86 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:85 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:84 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:83 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:82 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:81 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:80 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:79 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:78 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:77 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:76 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:75 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:74 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:73 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:72 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:71 t:1 h:16 l:0 c:fan0 s:16|16
z:cpu-thermal t:70 t:1 h:16 l:0 c:fan0 s:15|15
z:cpu-thermal t:69 t:1 h:16 l:0 c:fan0 s:14|14
z:cpu-thermal t:68 t:1 h:16 l:0 c:fan0 s:13|13
z:cpu-thermal t:67 t:1 h:16 l:0 c:fan0 s:12|12
z:cpu-thermal t:66 t:1 h:16 l:0 c:fan0 s:11|11
z:cpu-thermal t:65 t:1 h:16 l:0 c:fan0 s:10|10
z:cpu-thermal t:64 t:1 h:16 l:0 c:fan0 s:9|9
z:cpu-thermal t:63 t:1 h:16 l:0 c:fan0 s:8|8
z:cpu-thermal t:62 t:1 h:16 l:0 c:fan0 s:7|7
z:cpu-thermal t:61 t:1 h:16 l:0 c:fan0 s:6|6
z:cpu-thermal t:60 t:1 h:16 l:0 c:fan0 s:5|5
z:cpu-thermal t:59 t:1 h:16 l:0 c:fan0 s:4|4
z:cpu-thermal t:58 t:1 h:16 l:0 c:fan0 s:3|3
z:cpu-thermal t:57 t:1 h:16 l:0 c:fan0 s:2|2
z:cpu-thermal t:56 t:1 h:16 l:0 c:fan0 s:1|1
z:cpu-thermal t:55 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:54 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:53 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:52 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:51 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:50 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:49 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:48 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:47 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:46 t:1 h:16 l:0 c:fan0 s:0|0
z:cpu-thermal t:45 t:1 h:16 l:0 c:fan0 s:0|0

@acassis
Copy link
Contributor

acassis commented Aug 1, 2024

Nice work @JianyuWang0623 kudos!!!

Since it is a new subsystem we need Documentation/ to it, please submit it (on this PR or in a new one)

@acassis
Copy link
Contributor

acassis commented Aug 1, 2024

Please fix these issues:

Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Error: Process completed with exit code 1.

drivers/thermal/thermal_procfs.c Outdated Show resolved Hide resolved
drivers/thermal/thermal_dummy.c Show resolved Hide resolved
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Test: ./tools/configure.sh -l sim:thermal && make -j8

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Called by both of lpwork and Idle_Task:

[    0.000000] [ 0] [  INFO] [ap] thermal_zone_device_register: Registered zone device cpu-thermal
[    0.000000] [ 0] [ EMERG] [ap] _assert: Current Version: NuttX ap 0.0.0  Dec 11 2023 20:59:20 sim
[    0.000000] [ 0] [ EMERG] [ap] _assert: Assertion failed : at file: thermal/thermal_core.c:820 task: Idle_Task process: Kernel 0x32ade29

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Ref: I7afe1047369e91662583c8ef9c98fffcf567fbb7
```
sched: move etc romfs mount from nsh to sched/init
```
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
```
CID 1159822: (apache#1 of 2): 宏将无符号值与 0 做了比较 (NO_EFFECT)
unsigned_compare: 不带符号值的此 greater-than-or-equal-to-zero 比较总是为 true。index >= 0U。
```
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
…nd "hot" trip.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
When exec "echo 1 > /proc/thermal/cpu-thermal", procfs get "\n" after "1", treat as disable:
```
 apache#1  0x000000000040f452 in thermal_procfs_write (filep=0x7ffff3d241e8, buffer=0x7ffff3d344fc "\n", buflen=1) at thermal/thermal_procfs.c:179
```

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@acassis
Copy link
Contributor

acassis commented Aug 10, 2024

ping @JianyuWang0623

@JianyuWang0623
Copy link
Contributor Author

All got, will update later

apache#12824
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
1. cpufreq.h not found if cpufreq is not supported on some branches.
./thermal/thermal_dummy.c:25:10: fatal error: nuttx/cpufreq.h: No such file or directory
   25 | #include <nuttx/cpufreq.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.

2. debug.h is included by including <nuttx/cpufreq.h>, should not.
CC:  thermal/thermal_dummy.c thermal/thermal_dummy.c: In function ‘thermal_dummy_init’:
thermal/thermal_dummy.c:338:7: warning: implicit declaration of function ‘therr’ [-Wimplicit-function-declaration]
  338 |       therr("Register cooling device fan0 failed!\n");
      |

apache#12824
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@JianyuWang0623
Copy link
Contributor Author

Nice work @JianyuWang0623 kudos!!!

Since it is a new subsystem we need Documentation/ to it, please submit it (on this PR or in a new one)

Done, please see Add Documentation for thermal framework

@JianyuWang0623 JianyuWang0623 marked this pull request as ready for review September 18, 2024 16:58
@JianyuWang0623
Copy link
Contributor Author

Please fix these issues:

Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Remove Gerrit Change-ID's before submitting upstream
Error: Process completed with exit code 1.

Done

CPUFreq has not upstreamed to apache:nuttx

Warning/Error:
  $ make distclean
  $ ./tools/configure.sh -l sim:thermal
  $ make savedefconfig
  $ diff defconfig boards/sim/sim/sim/configs/thermal/defconfig
  18a19
  > CONFIG_CPUFREQ=y
  73a75
  > CONFIG_THERMAL_CDEV_CPUFREQ=y
  74a77
  > CONFIG_THERMAL_DUMMY_CPUFREQ=y

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@github-actions github-actions bot added the Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. label Sep 20, 2024
@xiaoxiang781216 xiaoxiang781216 merged commit 58f25a3 into apache:master Sep 23, 2024
29 checks passed
xiaoxiang781216 pushed a commit that referenced this pull request Sep 23, 2024
#12824
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
xiaoxiang781216 pushed a commit that referenced this pull request Sep 23, 2024
1. cpufreq.h not found if cpufreq is not supported on some branches.
./thermal/thermal_dummy.c:25:10: fatal error: nuttx/cpufreq.h: No such file or directory
   25 | #include <nuttx/cpufreq.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.

2. debug.h is included by including <nuttx/cpufreq.h>, should not.
CC:  thermal/thermal_dummy.c thermal/thermal_dummy.c: In function ‘thermal_dummy_init’:
thermal/thermal_dummy.c:338:7: warning: implicit declaration of function ‘therr’ [-Wimplicit-function-declaration]
  338 |       therr("Register cooling device fan0 failed!\n");
      |

#12824
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants