tools/thermal: thermal library and tools
v3 cover tools/thermal: thermal library and tools
These changes are providing the following tools and library:
- A thermal library doing the netlink abstraction from the kernel in order to make the userspace thermal implementation easier. Having the library integrated with the kernel tree is also a guarantee to keep the message format and their encoding/decoding aligned
- A thermal tools library providing a set of functions to deal with usual features like the log, the mainloop and the time. This library is used by the provided tools below
- An data acquisition program to capture the temperature of the different thermal zone during an amount of time or during the execution of an application. The output is formated to be easily parsed by gnuplot, a spreadsheet program or a statistical command line utility. The timestamp is based on the system uptime, thus giving an indication of when a thermal event happened, that can help to spot or reproduce thermal issue in the long run
- A thermal monitoring program based on the thermal library. It gives a skeleton to build any logic on top of it and shows how to use the thermal library. It does nothing except discovering the thermal zones, their trip points and listening for events like cooling devices state changes or trip point crossed
Changelog:
v3:
- Fixed NULL pointer reference when there is no thermal zones, trip points or cooling device
- Kill the child process when the duration ends or if there is an interruption in the thermometer
- Add error messages in the main body for the thermal-engine
v2:
- Fixed all trailing whitespaces and some other checkpatch warnings. Some warnings remain but they can be considered as false positive
- Added in the thermometer tool:
- Usage/help option as well as a man page
- The ability to execute a program
- The capture duration
- Create the output directory if it does not exist
- Add in the thermal-engine tool:
- A usage/help option
- A message telling the userspace it is waiting for events
- A daemonize option
- Minor bug fixes here and there, as well as typos
v1: Initial post after a RFC
Daniel Lezcano (4):
tools/lib/thermal: Add a thermal library
tools/thermal: Add util library
tools/thermal: Add a temperature capture tool
tools/thermal: Add thermal daemon skeleton
MAINTAINERS | 1 + tools/Makefile | 36 +- tools/lib/thermal/.gitignore | 2 + tools/lib/thermal/Build | 5 + tools/lib/thermal/Makefile | 165 +++++ tools/lib/thermal/commands.c | 349 +++++++++++ tools/lib/thermal/events.c | 164 +++++ tools/lib/thermal/include/thermal.h | 142 +++++ tools/lib/thermal/libthermal.map | 25 + tools/lib/thermal/libthermal.pc.template | 12 + tools/lib/thermal/sampling.c | 75 +++ tools/lib/thermal/thermal.c | 135 +++++ tools/lib/thermal/thermal_nl.c | 215 +++++++ tools/lib/thermal/thermal_nl.h | 46 ++ tools/thermal/lib/Build | 3 + tools/thermal/lib/Makefile | 158 +++++ .../thermal/lib/libthermal_tools.pc.template | 12 + tools/thermal/lib/log.c | 77 +++ tools/thermal/lib/log.h | 31 + tools/thermal/lib/mainloop.c | 120 ++++ tools/thermal/lib/mainloop.h | 15 + tools/thermal/lib/thermal-tools.h | 10 + tools/thermal/lib/uptimeofday.c | 40 ++ tools/thermal/lib/uptimeofday.h | 12 + tools/thermal/thermal-engine/Build | 2 + tools/thermal/thermal-engine/Makefile | 28 + tools/thermal/thermal-engine/thermal-engine.c | 341 +++++++++++ tools/thermal/thermometer/Build | 2 + tools/thermal/thermometer/Makefile | 26 + tools/thermal/thermometer/thermometer.8 | 93 +++ tools/thermal/thermometer/thermometer.c | 573 ++++++++++++++++++ tools/thermal/thermometer/thermometer.conf | 5 + 32 files changed, 2917 insertions(+), 3 deletions(-) create mode 100644 tools/lib/thermal/.gitignore create mode 100644 tools/lib/thermal/Build create mode 100644 tools/lib/thermal/Makefile create mode 100644 tools/lib/thermal/commands.c create mode 100644 tools/lib/thermal/events.c create mode 100644 tools/lib/thermal/include/thermal.h create mode 100644 tools/lib/thermal/libthermal.map create mode 100644 tools/lib/thermal/libthermal.pc.template create mode 100644 tools/lib/thermal/sampling.c create mode 100644 tools/lib/thermal/thermal.c create mode 100644 tools/lib/thermal/thermal_nl.c create mode 100644 tools/lib/thermal/thermal_nl.h create mode 100644 tools/thermal/lib/Build create mode 100644 tools/thermal/lib/Makefile create mode 100644 tools/thermal/lib/libthermal_tools.pc.template create mode 100644 tools/thermal/lib/log.c create mode 100644 tools/thermal/lib/log.h create mode 100644 tools/thermal/lib/mainloop.c create mode 100644 tools/thermal/lib/mainloop.h create mode 100644 tools/thermal/lib/thermal-tools.h create mode 100644 tools/thermal/lib/uptimeofday.c create mode 100644 tools/thermal/lib/uptimeofday.h create mode 100644 tools/thermal/thermal-engine/Build create mode 100644 tools/thermal/thermal-engine/Makefile create mode 100644 tools/thermal/thermal-engine/thermal-engine.c create mode 100644 tools/thermal/thermometer/Build create mode 100644 tools/thermal/thermometer/Makefile create mode 100644 tools/thermal/thermometer/thermometer.8 create mode 100644 tools/thermal/thermometer/thermometer.c create mode 100644 tools/thermal/thermometer/thermometer.conf
Signature · 1 line
2.25.1
PATCH v3 1/4 tools/lib/thermal: Add a thermal library
The thermal framework implements a netlink notification mechanism to be used by the userspace to have a thermal configuration discovery, trip point changes or violation, cooling device changes notifications, etc...
This library provides a level of abstraction for the thermal netlink notification allowing the userspace to connect to the notification mechanism more easily. The library is callback oriented.
--- MAINTAINERS | 1 + tools/Makefile | 14 +- tools/lib/thermal/.gitignore | 2 + tools/lib/thermal/Build | 5 + tools/lib/thermal/Makefile | 165 +++++++++++ tools/lib/thermal/commands.c | 349 +++++++++++++++++++++++ tools/lib/thermal/events.c | 164 +++++++++++ tools/lib/thermal/include/thermal.h | 142 +++++++++ tools/lib/thermal/libthermal.map | 25 ++ tools/lib/thermal/libthermal.pc.template | 12 + tools/lib/thermal/sampling.c | 75 +++++ tools/lib/thermal/thermal.c | 135 +++++++++ tools/lib/thermal/thermal_nl.c | 215 ++++++++++++++ tools/lib/thermal/thermal_nl.h | 46 +++ 14 files changed, 1348 insertions(+), 2 deletions(-) create mode 100644 tools/lib/thermal/.gitignore create mode 100644 tools/lib/thermal/Build create mode 100644 tools/lib/thermal/Makefile create mode 100644 tools/lib/thermal/commands.c create mode 100644 tools/lib/thermal/events.c create mode 100644 tools/lib/thermal/include/thermal.h create mode 100644 tools/lib/thermal/libthermal.map create mode 100644 tools/lib/thermal/libthermal.pc.template create mode 100644 tools/lib/thermal/sampling.c create mode 100644 tools/lib/thermal/thermal.c create mode 100644 tools/lib/thermal/thermal_nl.c create mode 100644 tools/lib/thermal/thermal_nl.h
MAINTAINERS +1 -0
@@ -19129,6 +19129,7 @@ F: drivers/thermal/ F: include/linux/cpu_cooling.h F: include/linux/thermal.h F: include/uapi/linux/thermal.h +F: tools/lib/thermal/ F: tools/thermal/ THERMAL DRIVER FOR AMLOGIC SOCS
tools/Makefile +12 -2
@@ -31,6 +31,7 @@ help: @echo ' bootconfig - boot config tool' @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' + @echo ' thermal - thermal library' @echo ' tracing - misc tracing tools' @echo ' turbostat - Intel CPU idle stats and freq reporting tool' @echo ' usb - USB testing tools'
@@ -85,6 +86,9 @@ perf: FORCE selftests: FORCE $(call descend,testing/$@) +thermal: FORCE + $(call descend,lib/$@) + turbostat x86_energy_perf_policy intel-speed-select: FORCE $(call descend,power/x86/$@)
@@ -101,7 +105,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \ perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ - pci debugging tracing + pci debugging tracing thermal acpi_install: $(call descend,power/$(@:_install=),install)
@@ -115,6 +119,9 @@ cgroup_install counter_install firewire_install gpio_install hv_install iio_inst selftests_install: $(call descend,testing/$(@:_install=),install) +thermal_install: + $(call descend,lib/$(@:_install=),install) + turbostat_install x86_energy_perf_policy_install intel-speed-select_install: $(call descend,power/x86/$(@:_install=),install)
@@ -160,6 +167,9 @@ perf_clean: selftests_clean: $(call descend,testing/$(@:_clean=),clean) +thermal_clean: + $(call descend,lib/thermal,clean) + turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean: $(call descend,power/x86/$(@:_clean=),clean)
@@ -177,6 +187,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \ - intel-speed-select_clean tracing_clean + intel-speed-select_clean tracing_clean thermal_clean .PHONY: FORCE
tools/lib/thermal/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +libthermal.so* +libthermal.pc
tools/lib/thermal/Build new file +5 -0
@@ -0,0 +1,5 @@ +libthermal-y += commands.o +libthermal-y += events.o +libthermal-y += thermal_nl.o +libthermal-y += sampling.o +libthermal-y += thermal.o
tools/lib/thermal/Makefile new file +165 -0
165 lines not on this page · raw message
tools/lib/thermal/commands.c new file +349 -0
349 lines not on this page · raw message
tools/lib/thermal/events.c new file +164 -0
164 lines not on this page · raw message
tools/lib/thermal/include/thermal.h new file +142 -0
142 lines not on this page · raw message
tools/lib/thermal/libthermal.map new file +25 -0
@@ -0,0 +1,25 @@ +LIBTHERMAL_0.0.1 { + global: + thermal_init; + for_each_thermal_zone; + for_each_thermal_trip; + for_each_thermal_cdev; + thermal_zone_find_by_name; + thermal_zone_find_by_id; + thermal_zone_discover; + thermal_init; + thermal_events_init; + thermal_events_handle; + thermal_events_fd; + thermal_cmd_init; + thermal_cmd_get_tz; + thermal_cmd_get_cdev; + thermal_cmd_get_trip; + thermal_cmd_get_governor; + thermal_cmd_get_temp; + thermal_sampling_init; + thermal_sampling_handle; + thermal_sampling_fd; +local: + *; +};
tools/lib/thermal/libthermal.pc.template new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: libthermal +Description: thermal library +Requires: libnl-3.0 libnl-genl-3.0 +Version: @VERSION@ +Libs: -L${libdir} -lnl-genl-3 -lnl-3 +Cflags: -I${includedir} -I{include}/libnl3
tools/lib/thermal/sampling.c new file +75 -0
75 lines not on this page · raw message
tools/lib/thermal/thermal.c new file +135 -0
135 lines not on this page · raw message
tools/lib/thermal/thermal_nl.c new file +215 -0
215 lines not on this page · raw message
tools/lib/thermal/thermal_nl.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.25.1
[thermal: thermal/next] tools/lib/thermal: Add a thermal library
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 47c4b0de080adc125526aa80221c4e3ffbf97b6d Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//47c4b0de080adc125526aa80221c4e3ffbf97b6d Author: Daniel Lezcano <[email protected]> AuthorDate: Wed, 20 Apr 2022 18:09:29 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 19 May 2022 12:11:51 +02:00
tools/lib/thermal: Add a thermal library
The thermal framework implements a netlink notification mechanism to be used by the userspace to have a thermal configuration discovery, trip point changes or violation, cooling device changes notifications, etc...
This library provides a level of abstraction for the thermal netlink notification allowing the userspace to connect to the notification mechanism more easily. The library is callback oriented.
--- MAINTAINERS | 1 +- tools/Makefile | 14 +- tools/lib/thermal/.gitignore | 2 +- tools/lib/thermal/Build | 5 +- tools/lib/thermal/Makefile | 165 ++++++++++- tools/lib/thermal/commands.c | 349 ++++++++++++++++++++++- tools/lib/thermal/events.c | 164 ++++++++++- tools/lib/thermal/include/thermal.h | 142 +++++++++- tools/lib/thermal/libthermal.map | 25 ++- tools/lib/thermal/libthermal.pc.template | 12 +- tools/lib/thermal/sampling.c | 75 +++++- tools/lib/thermal/thermal.c | 135 +++++++++- tools/lib/thermal/thermal_nl.c | 215 ++++++++++++++- tools/lib/thermal/thermal_nl.h | 46 +++- 14 files changed, 1348 insertions(+), 2 deletions(-) create mode 100644 tools/lib/thermal/.gitignore create mode 100644 tools/lib/thermal/Build create mode 100644 tools/lib/thermal/Makefile create mode 100644 tools/lib/thermal/commands.c create mode 100644 tools/lib/thermal/events.c create mode 100644 tools/lib/thermal/include/thermal.h create mode 100644 tools/lib/thermal/libthermal.map create mode 100644 tools/lib/thermal/libthermal.pc.template create mode 100644 tools/lib/thermal/sampling.c create mode 100644 tools/lib/thermal/thermal.c create mode 100644 tools/lib/thermal/thermal_nl.c create mode 100644 tools/lib/thermal/thermal_nl.h
MAINTAINERS +1 -0
@@ -19541,6 +19541,7 @@ F: drivers/thermal/ F: include/linux/cpu_cooling.h F: include/linux/thermal.h F: include/uapi/linux/thermal.h +F: tools/lib/thermal/ F: tools/thermal/ THERMAL DRIVER FOR AMLOGIC SOCS
tools/Makefile +12 -2
@@ -31,6 +31,7 @@ help: @echo ' bootconfig - boot config tool' @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' + @echo ' thermal - thermal library' @echo ' tracing - misc tracing tools' @echo ' turbostat - Intel CPU idle stats and freq reporting tool' @echo ' usb - USB testing tools'
@@ -85,6 +86,9 @@ perf: FORCE selftests: FORCE $(call descend,testing/$@) +thermal: FORCE + $(call descend,lib/$@) + turbostat x86_energy_perf_policy intel-speed-select: FORCE $(call descend,power/x86/$@)
@@ -101,7 +105,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \ perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ - pci debugging tracing + pci debugging tracing thermal acpi_install: $(call descend,power/$(@:_install=),install)
@@ -115,6 +119,9 @@ cgroup_install counter_install firewire_install gpio_install hv_install iio_inst selftests_install: $(call descend,testing/$(@:_install=),install) +thermal_install: + $(call descend,lib/$(@:_install=),install) + turbostat_install x86_energy_perf_policy_install intel-speed-select_install: $(call descend,power/x86/$(@:_install=),install)
@@ -160,6 +167,9 @@ perf_clean: selftests_clean: $(call descend,testing/$(@:_clean=),clean) +thermal_clean: + $(call descend,lib/thermal,clean) + turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean: $(call descend,power/x86/$(@:_clean=),clean)
@@ -177,6 +187,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \ - intel-speed-select_clean tracing_clean + intel-speed-select_clean tracing_clean thermal_clean .PHONY: FORCE
tools/lib/thermal/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +libthermal.so* +libthermal.pc
tools/lib/thermal/Build new file +5 -0
@@ -0,0 +1,5 @@ +libthermal-y += commands.o +libthermal-y += events.o +libthermal-y += thermal_nl.o +libthermal-y += sampling.o +libthermal-y += thermal.o
tools/lib/thermal/Makefile new file +165 -0
165 lines not on this page · raw message
tools/lib/thermal/commands.c new file +349 -0
349 lines not on this page · raw message
tools/lib/thermal/events.c new file +164 -0
164 lines not on this page · raw message
tools/lib/thermal/include/thermal.h new file +142 -0
142 lines not on this page · raw message
tools/lib/thermal/libthermal.map new file +25 -0
@@ -0,0 +1,25 @@ +LIBTHERMAL_0.0.1 { + global: + thermal_init; + for_each_thermal_zone; + for_each_thermal_trip; + for_each_thermal_cdev; + thermal_zone_find_by_name; + thermal_zone_find_by_id; + thermal_zone_discover; + thermal_init; + thermal_events_init; + thermal_events_handle; + thermal_events_fd; + thermal_cmd_init; + thermal_cmd_get_tz; + thermal_cmd_get_cdev; + thermal_cmd_get_trip; + thermal_cmd_get_governor; + thermal_cmd_get_temp; + thermal_sampling_init; + thermal_sampling_handle; + thermal_sampling_fd; +local: + *; +};
tools/lib/thermal/libthermal.pc.template new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: libthermal +Description: thermal library +Requires: libnl-3.0 libnl-genl-3.0 +Version: @VERSION@ +Libs: -L${libdir} -lnl-genl-3 -lnl-3 +Cflags: -I${includedir} -I{include}/libnl3
tools/lib/thermal/sampling.c new file +75 -0
75 lines not on this page · raw message
tools/lib/thermal/thermal.c new file +135 -0
135 lines not on this page · raw message
tools/lib/thermal/thermal_nl.c new file +215 -0
215 lines not on this page · raw message
tools/lib/thermal/thermal_nl.h new file +46 -0
46 lines not on this page · raw message
PATCH v3 2/4 tools/thermal: Add util library
In reply to Daniel LezcanoThe next changes will provide a couple of tools using some common functions provided by this library.
It provides basic wrappers for:
- mainloop
- logging
- timestamp
--- tools/thermal/lib/Build | 3 + tools/thermal/lib/Makefile | 158 ++++++++++++++++++ .../thermal/lib/libthermal_tools.pc.template | 12 ++ tools/thermal/lib/log.c | 77 +++++++++ tools/thermal/lib/log.h | 31 ++++ tools/thermal/lib/mainloop.c | 120 +++++++++++++ tools/thermal/lib/mainloop.h | 15 ++ tools/thermal/lib/thermal-tools.h | 10 ++ tools/thermal/lib/uptimeofday.c | 40 +++++ tools/thermal/lib/uptimeofday.h | 12 ++ 10 files changed, 478 insertions(+) create mode 100644 tools/thermal/lib/Build create mode 100644 tools/thermal/lib/Makefile create mode 100644 tools/thermal/lib/libthermal_tools.pc.template create mode 100644 tools/thermal/lib/log.c create mode 100644 tools/thermal/lib/log.h create mode 100644 tools/thermal/lib/mainloop.c create mode 100644 tools/thermal/lib/mainloop.h create mode 100644 tools/thermal/lib/thermal-tools.h create mode 100644 tools/thermal/lib/uptimeofday.c create mode 100644 tools/thermal/lib/uptimeofday.h
tools/thermal/lib/Build new file +3 -0
@@ -0,0 +1,3 @@ +libthermal_tools-y += mainloop.o +libthermal_tools-y += log.o +libthermal_tools-y += uptimeofday.o
tools/thermal/lib/Makefile new file +158 -0
158 lines not on this page · raw message
tools/thermal/lib/libthermal_tools.pc.template new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: libthermal +Description: thermal library +Requires: libnl-3.0 libnl-genl-3.0 +Version: @VERSION@ +Libs: -L${libdir} -lnl-genl-3 -lnl-3 +Cflags: -I${includedir} -I{include}/libnl3
tools/thermal/lib/log.c new file +77 -0
77 lines not on this page · raw message
tools/thermal/lib/log.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS_LOG_H +#define __THERMAL_TOOLS_LOG_H + +#include <syslog.h> + +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) +#endif + +#define TO_SYSLOG 0x1 +#define TO_STDOUT 0x2 +#define TO_STDERR 0x4 + +extern void logit (int level,const char *format, ...); + +#define DEBUG (fmt, ...) logit(LOG_DEBUG, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__) +#define INFO (fmt, ...) logit(LOG_INFO, fmt, ##__VA_ARGS__) +#define NOTICE (fmt, ...) logit(LOG_NOTICE, fmt, ##__VA_ARGS__) +#define WARN (fmt, ...) logit(LOG_WARNING, fmt, ##__VA_ARGS__) +#define ERROR (fmt, ...) logit(LOG_ERR, fmt, ##__VA_ARGS__) +#define CRITICAL (fmt, ...) logit(LOG_CRIT, fmt, ##__VA_ARGS__) +#define ALERT (fmt, ...) logit(LOG_ALERT, fmt, ##__VA_ARGS__) +#define EMERG (fmt, ...) logit(LOG_EMERG, fmt, ##__VA_ARGS__) + +int log_init (int level,const char *ident,int options); +int log_str2level (const char *lvl); +void log_exit (void ); + +#endif
tools/thermal/lib/mainloop.c new file +120 -0
120 lines not on this page · raw message
tools/thermal/lib/mainloop.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS_MAINLOOP_H +#define __THERMAL_TOOLS_MAINLOOP_H + +typedef int (*mainloop_callback_t )(int fd,void *data); + +extern int mainloop (unsigned int timeout); +extern int mainloop_add (int fd,mainloop_callback_t cb,void *data); +extern int mainloop_del (int fd); +extern void mainloop_exit (void ); +extern int mainloop_init (void ); +extern void mainloop_fini (void ); + +#endif
tools/thermal/lib/thermal-tools.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS +#define __THERMAL_TOOLS + +#include "log.h" +#include "mainloop.h" +#include "uptimeofday.h" + +#endif
tools/thermal/lib/uptimeofday.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: LGPL-2.1+ +// Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> +#include <stdio.h> +#include <sys/time.h> +#include <linux/sysinfo.h> +#include "thermal-tools.h" + +static unsigned long __offset; +static struct timeval __tv; + +int uptimeofday_init (void ) +{ +struct sysinfo info; + +if (sysinfo (&info)) +return -1 ; + +gettimeofday (&__tv,NULL ); + + __offset = __tv.tv_sec - info.uptime; + +return 0 ; +} + +unsigned long getuptimeofday_ms (void ) +{ +gettimeofday (&__tv,NULL ); + +return ((__tv.tv_sec - __offset) *1000 ) + (__tv.tv_usec /1000 ); +} + +struct timespec msec_to_timespec (int msec) +{ +struct timespec tv = { + .tv_sec = (msec /1000 ), + .tv_nsec = (msec %1000 ) *1000000 , + }; + +return tv; +}
tools/thermal/lib/uptimeofday.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS_UPTIMEOFDAY_H +#define __THERMAL_TOOLS_UPTIMEOFDAY_H +#include <sys/sysinfo.h> +#include <sys/time.h> + +int uptimeofday_init (void ); +unsigned long getuptimeofday_ms (void ); +struct timespec msec_to_timespec (int msec); + +#endif
Signature · 1 line
2.25.1
[thermal: thermal/next] tools/thermal: Add util library
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 3b7c5e8adf9ca64f8dd70279076de085ea6369d7 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//3b7c5e8adf9ca64f8dd70279076de085ea6369d7 Author: Daniel Lezcano <[email protected]> AuthorDate: Wed, 20 Apr 2022 18:09:30 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 19 May 2022 12:11:51 +02:00
tools/thermal: Add util library
The next changes will provide a couple of tools using some common functions provided by this library.
It provides basic wrappers for:
- mainloop
- logging
- timestamp
--- tools/thermal/lib/Build | 3 +- tools/thermal/lib/Makefile | 158 ++++++++++++++++- tools/thermal/lib/libthermal_tools.pc.template | 12 +- tools/thermal/lib/log.c | 77 ++++++++- tools/thermal/lib/log.h | 31 +++- tools/thermal/lib/mainloop.c | 120 ++++++++++++- tools/thermal/lib/mainloop.h | 15 ++- tools/thermal/lib/thermal-tools.h | 10 +- tools/thermal/lib/uptimeofday.c | 40 ++++- tools/thermal/lib/uptimeofday.h | 12 +- 10 files changed, 478 insertions(+) create mode 100644 tools/thermal/lib/Build create mode 100644 tools/thermal/lib/Makefile create mode 100644 tools/thermal/lib/libthermal_tools.pc.template create mode 100644 tools/thermal/lib/log.c create mode 100644 tools/thermal/lib/log.h create mode 100644 tools/thermal/lib/mainloop.c create mode 100644 tools/thermal/lib/mainloop.h create mode 100644 tools/thermal/lib/thermal-tools.h create mode 100644 tools/thermal/lib/uptimeofday.c create mode 100644 tools/thermal/lib/uptimeofday.h
tools/thermal/lib/Build new file +3 -0
@@ -0,0 +1,3 @@ +libthermal_tools-y += mainloop.o +libthermal_tools-y += log.o +libthermal_tools-y += uptimeofday.o
tools/thermal/lib/Makefile new file +158 -0
158 lines not on this page · raw message
tools/thermal/lib/libthermal_tools.pc.template new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: libthermal +Description: thermal library +Requires: libnl-3.0 libnl-genl-3.0 +Version: @VERSION@ +Libs: -L${libdir} -lnl-genl-3 -lnl-3 +Cflags: -I${includedir} -I{include}/libnl3
tools/thermal/lib/log.c new file +77 -0
77 lines not on this page · raw message
tools/thermal/lib/log.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS_LOG_H +#define __THERMAL_TOOLS_LOG_H + +#include <syslog.h> + +#ifndef __maybe_unused +#define __maybe_unused __attribute__((__unused__)) +#endif + +#define TO_SYSLOG 0x1 +#define TO_STDOUT 0x2 +#define TO_STDERR 0x4 + +extern void logit (int level,const char *format, ...); + +#define DEBUG (fmt, ...) logit(LOG_DEBUG, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__) +#define INFO (fmt, ...) logit(LOG_INFO, fmt, ##__VA_ARGS__) +#define NOTICE (fmt, ...) logit(LOG_NOTICE, fmt, ##__VA_ARGS__) +#define WARN (fmt, ...) logit(LOG_WARNING, fmt, ##__VA_ARGS__) +#define ERROR (fmt, ...) logit(LOG_ERR, fmt, ##__VA_ARGS__) +#define CRITICAL (fmt, ...) logit(LOG_CRIT, fmt, ##__VA_ARGS__) +#define ALERT (fmt, ...) logit(LOG_ALERT, fmt, ##__VA_ARGS__) +#define EMERG (fmt, ...) logit(LOG_EMERG, fmt, ##__VA_ARGS__) + +int log_init (int level,const char *ident,int options); +int log_str2level (const char *lvl); +void log_exit (void ); + +#endif
tools/thermal/lib/mainloop.c new file +120 -0
120 lines not on this page · raw message
tools/thermal/lib/mainloop.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS_MAINLOOP_H +#define __THERMAL_TOOLS_MAINLOOP_H + +typedef int (*mainloop_callback_t )(int fd,void *data); + +extern int mainloop (unsigned int timeout); +extern int mainloop_add (int fd,mainloop_callback_t cb,void *data); +extern int mainloop_del (int fd); +extern void mainloop_exit (void ); +extern int mainloop_init (void ); +extern void mainloop_fini (void ); + +#endif
tools/thermal/lib/thermal-tools.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS +#define __THERMAL_TOOLS + +#include "log.h" +#include "mainloop.h" +#include "uptimeofday.h" + +#endif
tools/thermal/lib/uptimeofday.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: LGPL-2.1+ +// Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> +#include <stdio.h> +#include <sys/time.h> +#include <linux/sysinfo.h> +#include "thermal-tools.h" + +static unsigned long __offset; +static struct timeval __tv; + +int uptimeofday_init (void ) +{ +struct sysinfo info; + +if (sysinfo (&info)) +return -1 ; + +gettimeofday (&__tv,NULL ); + + __offset = __tv.tv_sec - info.uptime; + +return 0 ; +} + +unsigned long getuptimeofday_ms (void ) +{ +gettimeofday (&__tv,NULL ); + +return ((__tv.tv_sec - __offset) *1000 ) + (__tv.tv_usec /1000 ); +} + +struct timespec msec_to_timespec (int msec) +{ +struct timespec tv = { + .tv_sec = (msec /1000 ), + .tv_nsec = (msec %1000 ) *1000000 , + }; + +return tv; +}
tools/thermal/lib/uptimeofday.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */ +#ifndef __THERMAL_TOOLS_UPTIMEOFDAY_H +#define __THERMAL_TOOLS_UPTIMEOFDAY_H +#include <sys/sysinfo.h> +#include <sys/time.h> + +int uptimeofday_init (void ); +unsigned long getuptimeofday_ms (void ); +struct timespec msec_to_timespec (int msec); + +#endif
PATCH v3 3/4 tools/thermal: Add a temperature capture tool
In reply to Daniel LezcanoThe 'thermometer' tool allows to capture the temperature of a set of thermal zones defined in a configuration file at a specified rate.
It is designed to have the lowest possible overhead. It will write the captured temperature per thermal zone per file so making easier to write a gnuplot script.
--- tools/Makefile | 16 +- tools/thermal/thermometer/Build | 2 + tools/thermal/thermometer/Makefile | 26 + tools/thermal/thermometer/thermometer.8 | 93 ++++ tools/thermal/thermometer/thermometer.c | 572 +++++++++++++++++++++ tools/thermal/thermometer/thermometer.conf | 5 + 6 files changed, 711 insertions(+), 3 deletions(-) create mode 100644 tools/thermal/thermometer/Build create mode 100644 tools/thermal/thermometer/Makefile create mode 100644 tools/thermal/thermometer/thermometer.8 create mode 100644 tools/thermal/thermometer/thermometer.c create mode 100644 tools/thermal/thermometer/thermometer.conf
tools/Makefile +13 -3
@@ -31,6 +31,7 @@ help: @echo ' bootconfig - boot config tool' @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' + @echo ' thermometer - temperature capture tool' @echo ' thermal - thermal library' @echo ' tracing - misc tracing tools' @echo ' turbostat - Intel CPU idle stats and freq reporting tool'
@@ -95,6 +96,9 @@ turbostat x86_energy_perf_policy intel-speed-select: FORCE tmon: FORCE $(call descend,thermal/$@) +thermometer: FORCE + $(call descend,thermal/$@) + freefall: FORCE $(call descend,laptop/$@)
@@ -105,7 +109,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \ perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ - pci debugging tracing thermal + pci debugging tracing thermal thermometer acpi_install: $(call descend,power/$(@:_install=),install)
@@ -128,6 +132,9 @@ turbostat_install x86_energy_perf_policy_install intel-speed-select_install: tmon_install: $(call descend,thermal/$(@:_install=),install) +thermometer_install: + $(call descend,thermal/$(@:_install=),install) + freefall_install: $(call descend,laptop/$(@:_install=),install)
@@ -140,7 +147,7 @@ install: acpi_install cgroup_install counter_install cpupower_install gpio_insta virtio_install vm_install bpf_install x86_energy_perf_policy_install \ tmon_install freefall_install objtool_install kvm_stat_install \ wmi_install pci_install debugging_install intel-speed-select_install \ - tracing_install + tracing_install thermometer_install acpi_clean: $(call descend,power/acpi,clean)
@@ -173,6 +180,9 @@ thermal_clean: turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean: $(call descend,power/x86/$(@:_clean=),clean) +thermometer_clean: + $(call descend,thermal/thermometer,clean) + tmon_clean: $(call descend,thermal/tmon,clean)
@@ -187,6 +197,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \ - intel-speed-select_clean tracing_clean thermal_clean + intel-speed-select_clean tracing_clean thermal_clean thermometer_clean .PHONY: FORCE
tools/thermal/thermometer/Build new file +2 -0
@@ -0,0 +1,2 @@ +thermometer-y += thermometer.o +
tools/thermal/thermometer/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for cgroup tools + +ifeq ($(srctree),) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +# $(info Determined 'srctree' to be $(srctree)) +endif + +CFLAGS = -Wall -Wextra +CFLAGS += -I$(srctree)/tools/thermal/lib + +LDFLAGS = -L$(srctree)/tools/thermal/lib +LDFLAGS += -lthermal_tools +LDFLAGS += -lconfig + +VERSION = 0.0.1 +TARGET=thermometer + +all: $(TARGET) +%: %.c + $(CC) $(CFLAGS) -D VERSION=\"$(VERSION)\" -o $@ $^ $(LDFLAGS) + +clean: + $(RM) $(TARGET)
tools/thermal/thermometer/thermometer.8 new file +93 -0
93 lines not on this page · raw message
tools/thermal/thermometer/thermometer.c new file +572 -0
572 lines not on this page · raw message
tools/thermal/thermometer/thermometer.conf new file +5 -0
@@ -0,0 +1,5 @@ + +thermal-zones = ( + { name = "cpu[0-9]-thermal"; + polling = 100; } + )
Signature · 1 line
2.25.1
[thermal: thermal/next] tools/thermal: Add a temperature capture tool
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 110acbc6a4518145db3a1a9c0686d730bb258bf1 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//110acbc6a4518145db3a1a9c0686d730bb258bf1 Author: Daniel Lezcano <[email protected]> AuthorDate: Wed, 20 Apr 2022 18:09:31 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 19 May 2022 12:11:52 +02:00
tools/thermal: Add a temperature capture tool
The 'thermometer' tool allows to capture the temperature of a set of thermal zones defined in a configuration file at a specified rate.
It is designed to have the lowest possible overhead. It will write the captured temperature per thermal zone per file so making easier to write a gnuplot script.
--- tools/Makefile | 16 +- tools/thermal/thermometer/Build | 1 +- tools/thermal/thermometer/Makefile | 26 +- tools/thermal/thermometer/thermometer.8 | 92 +++- tools/thermal/thermometer/thermometer.c | 572 ++++++++++++++++++++- tools/thermal/thermometer/thermometer.conf | 5 +- 6 files changed, 709 insertions(+), 3 deletions(-) create mode 100644 tools/thermal/thermometer/Build create mode 100644 tools/thermal/thermometer/Makefile create mode 100644 tools/thermal/thermometer/thermometer.8 create mode 100644 tools/thermal/thermometer/thermometer.c create mode 100644 tools/thermal/thermometer/thermometer.conf
tools/Makefile +13 -3
@@ -31,6 +31,7 @@ help: @echo ' bootconfig - boot config tool' @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' + @echo ' thermometer - temperature capture tool' @echo ' thermal - thermal library' @echo ' tracing - misc tracing tools' @echo ' turbostat - Intel CPU idle stats and freq reporting tool'
@@ -95,6 +96,9 @@ turbostat x86_energy_perf_policy intel-speed-select: FORCE tmon: FORCE $(call descend,thermal/$@) +thermometer: FORCE + $(call descend,thermal/$@) + freefall: FORCE $(call descend,laptop/$@)
@@ -105,7 +109,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \ perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ - pci debugging tracing thermal + pci debugging tracing thermal thermometer acpi_install: $(call descend,power/$(@:_install=),install)
@@ -128,6 +132,9 @@ turbostat_install x86_energy_perf_policy_install intel-speed-select_install: tmon_install: $(call descend,thermal/$(@:_install=),install) +thermometer_install: + $(call descend,thermal/$(@:_install=),install) + freefall_install: $(call descend,laptop/$(@:_install=),install)
@@ -140,7 +147,7 @@ install: acpi_install cgroup_install counter_install cpupower_install gpio_insta virtio_install vm_install bpf_install x86_energy_perf_policy_install \ tmon_install freefall_install objtool_install kvm_stat_install \ wmi_install pci_install debugging_install intel-speed-select_install \ - tracing_install + tracing_install thermometer_install acpi_clean: $(call descend,power/acpi,clean)
@@ -173,6 +180,9 @@ thermal_clean: turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean: $(call descend,power/x86/$(@:_clean=),clean) +thermometer_clean: + $(call descend,thermal/thermometer,clean) + tmon_clean: $(call descend,thermal/tmon,clean)
@@ -187,6 +197,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \ - intel-speed-select_clean tracing_clean thermal_clean + intel-speed-select_clean tracing_clean thermal_clean thermometer_clean .PHONY: FORCE
tools/thermal/thermometer/Build new file +1 -0
@@ -0,0 +1 @@ +thermometer-y += thermometer.o
tools/thermal/thermometer/Makefile new file +26 -0
@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for cgroup tools + +ifeq ($(srctree),) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +# $(info Determined 'srctree' to be $(srctree)) +endif + +CFLAGS = -Wall -Wextra +CFLAGS += -I$(srctree)/tools/thermal/lib + +LDFLAGS = -L$(srctree)/tools/thermal/lib +LDFLAGS += -lthermal_tools +LDFLAGS += -lconfig + +VERSION = 0.0.1 +TARGET=thermometer + +all: $(TARGET) +%: %.c + $(CC) $(CFLAGS) -D VERSION=\"$(VERSION)\" -o $@ $^ $(LDFLAGS) + +clean: + $(RM) $(TARGET)
tools/thermal/thermometer/thermometer.8 new file +92 -0
92 lines not on this page · raw message
tools/thermal/thermometer/thermometer.c new file +572 -0
572 lines not on this page · raw message
tools/thermal/thermometer/thermometer.conf new file +5 -0
@@ -0,0 +1,5 @@ + +thermal-zones = ( + { name = "cpu[0-9]-thermal"; + polling = 100; } + )
PATCH v3 4/4 tools/thermal: Add thermal daemon skeleton
In reply to Daniel LezcanoThis change provides a simple daemon skeleton. It is an example of how to use the thermal library which wraps all the complex code related to the netlink and transforms it into a callback oriented code.
The goal of this skeleton is to give a base brick for anyone interested in writing its own thermal engine or as an example to rely on to write its own thermal monitoring implementation.
In the future, it will evolve with more features and hopefully more logic.
--- tools/Makefile | 16 +- tools/thermal/thermal-engine/Build | 2 + tools/thermal/thermal-engine/Makefile | 28 ++ tools/thermal/thermal-engine/thermal-engine.c | 341 ++++++++++++++++++ 4 files changed, 384 insertions(+), 3 deletions(-) create mode 100644 tools/thermal/thermal-engine/Build create mode 100644 tools/thermal/thermal-engine/Makefile create mode 100644 tools/thermal/thermal-engine/thermal-engine.c
tools/Makefile +13 -3
@@ -32,6 +32,7 @@ help: @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' @echo ' thermometer - temperature capture tool' + @echo ' thermal-engine - thermal monitoring tool' @echo ' thermal - thermal library' @echo ' tracing - misc tracing tools' @echo ' turbostat - Intel CPU idle stats and freq reporting tool'
@@ -99,6 +100,9 @@ tmon: FORCE thermometer: FORCE $(call descend,thermal/$@) +thermal-engine: FORCE thermal + $(call descend,thermal/$@) + freefall: FORCE $(call descend,laptop/$@)
@@ -109,7 +113,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \ perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ - pci debugging tracing thermal thermometer + pci debugging tracing thermal thermometer thermal-engine acpi_install: $(call descend,power/$(@:_install=),install)
@@ -135,6 +139,9 @@ tmon_install: thermometer_install: $(call descend,thermal/$(@:_install=),install) +thermal-engine_install: + $(call descend,thermal/$(@:_install=),install) + freefall_install: $(call descend,laptop/$(@:_install=),install)
@@ -147,7 +154,7 @@ install: acpi_install cgroup_install counter_install cpupower_install gpio_insta virtio_install vm_install bpf_install x86_energy_perf_policy_install \ tmon_install freefall_install objtool_install kvm_stat_install \ wmi_install pci_install debugging_install intel-speed-select_install \ - tracing_install thermometer_install + tracing_install thermometer_install thermal-engine_install acpi_clean: $(call descend,power/acpi,clean)
@@ -183,6 +190,9 @@ turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean: thermometer_clean: $(call descend,thermal/thermometer,clean) +thermal-engine_clean: + $(call descend,thermal/thermal-engine,clean) + tmon_clean: $(call descend,thermal/tmon,clean)
@@ -197,6 +207,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \ - intel-speed-select_clean tracing_clean thermal_clean thermometer_clean + intel-speed-select_clean tracing_clean thermal_clean thermometer_clean thermal-engine_clean .PHONY: FORCE
tools/thermal/thermal-engine/Build new file +2 -0
@@ -0,0 +1,2 @@ +thermal-engine-y += thermal-engine.o +
tools/thermal/thermal-engine/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for thermal tools + +ifeq ($(srctree),) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +# $(info Determined 'srctree' to be $(srctree)) +endif + +CFLAGS = -Wall -Wextra +CFLAGS += -I$(srctree)/tools/thermal/lib +CFLAGS += -I$(srctree)/tools/lib/thermal/include + +LDFLAGS = -L$(srctree)/tools/thermal/lib +LDFLAGS += -L$(srctree)/tools/lib/thermal +LDFLAGS += -lthermal_tools +LDFLAGS += -lthermal +LDFLAGS += -lconfig +LDFLAGS += -lnl-genl-3 -lnl-3 + +VERSION = 0.0.1 + +all: thermal-engine +%: %.c + $(CC) $(CFLAGS) -D VERSION=\"$(VERSION)\" -o $@ $^ $(LDFLAGS) +clean: + $(RM) thermal-engine
tools/thermal/thermal-engine/thermal-engine.c new file +341 -0
341 lines not on this page · raw message
Signature · 1 line
2.25.1
[thermal: thermal/next] tools/thermal: Add thermal daemon skeleton
The following commit has been merged into the thermal/next branch of thermal:
The following commit has been merged into the thermal/next branch of thermal:
Commit-ID: 077df623c8344e4b50a7ba6c433f9d6857a94d6b Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//077df623c8344e4b50a7ba6c433f9d6857a94d6b Author: Daniel Lezcano <[email protected]> AuthorDate: Wed, 20 Apr 2022 18:09:32 +02:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Thu, 19 May 2022 12:11:52 +02:00
tools/thermal: Add thermal daemon skeleton
This change provides a simple daemon skeleton. It is an example of how to use the thermal library which wraps all the complex code related to the netlink and transforms it into a callback oriented code.
The goal of this skeleton is to give a base brick for anyone interested in writing its own thermal engine or as an example to rely on to write its own thermal monitoring implementation.
In the future, it will evolve with more features and hopefully more logic.
--- tools/Makefile | 16 +- tools/thermal/thermal-engine/Build | 1 +- tools/thermal/thermal-engine/Makefile | 28 +- tools/thermal/thermal-engine/thermal-engine.c | 341 +++++++++++++++++- 4 files changed, 383 insertions(+), 3 deletions(-) create mode 100644 tools/thermal/thermal-engine/Build create mode 100644 tools/thermal/thermal-engine/Makefile create mode 100644 tools/thermal/thermal-engine/thermal-engine.c
tools/Makefile +13 -3
@@ -32,6 +32,7 @@ help: @echo ' spi - spi tools' @echo ' tmon - thermal monitoring and tuning tool' @echo ' thermometer - temperature capture tool' + @echo ' thermal-engine - thermal monitoring tool' @echo ' thermal - thermal library' @echo ' tracing - misc tracing tools' @echo ' turbostat - Intel CPU idle stats and freq reporting tool'
@@ -99,6 +100,9 @@ tmon: FORCE thermometer: FORCE $(call descend,thermal/$@) +thermal-engine: FORCE thermal + $(call descend,thermal/$@) + freefall: FORCE $(call descend,laptop/$@)
@@ -109,7 +113,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \ perf selftests bootconfig spi turbostat usb \ virtio vm bpf x86_energy_perf_policy \ tmon freefall iio objtool kvm_stat wmi \ - pci debugging tracing thermal thermometer + pci debugging tracing thermal thermometer thermal-engine acpi_install: $(call descend,power/$(@:_install=),install)
@@ -135,6 +139,9 @@ tmon_install: thermometer_install: $(call descend,thermal/$(@:_install=),install) +thermal-engine_install: + $(call descend,thermal/$(@:_install=),install) + freefall_install: $(call descend,laptop/$(@:_install=),install)
@@ -147,7 +154,7 @@ install: acpi_install cgroup_install counter_install cpupower_install gpio_insta virtio_install vm_install bpf_install x86_energy_perf_policy_install \ tmon_install freefall_install objtool_install kvm_stat_install \ wmi_install pci_install debugging_install intel-speed-select_install \ - tracing_install thermometer_install + tracing_install thermometer_install thermal-engine_install acpi_clean: $(call descend,power/acpi,clean)
@@ -183,6 +190,9 @@ turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean: thermometer_clean: $(call descend,thermal/thermometer,clean) +thermal-engine_clean: + $(call descend,thermal/thermal-engine,clean) + tmon_clean: $(call descend,thermal/tmon,clean)
@@ -197,6 +207,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ freefall_clean build_clean libbpf_clean libsubcmd_clean \ gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \ - intel-speed-select_clean tracing_clean thermal_clean thermometer_clean + intel-speed-select_clean tracing_clean thermal_clean thermometer_clean thermal-engine_clean .PHONY: FORCE
tools/thermal/thermal-engine/Build new file +1 -0
@@ -0,0 +1 @@ +thermal-engine-y += thermal-engine.o
tools/thermal/thermal-engine/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for thermal tools + +ifeq ($(srctree),) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +srctree := $(patsubst %/,%,$(dir $(srctree))) +# $(info Determined 'srctree' to be $(srctree)) +endif + +CFLAGS = -Wall -Wextra +CFLAGS += -I$(srctree)/tools/thermal/lib +CFLAGS += -I$(srctree)/tools/lib/thermal/include + +LDFLAGS = -L$(srctree)/tools/thermal/lib +LDFLAGS += -L$(srctree)/tools/lib/thermal +LDFLAGS += -lthermal_tools +LDFLAGS += -lthermal +LDFLAGS += -lconfig +LDFLAGS += -lnl-genl-3 -lnl-3 + +VERSION = 0.0.1 + +all: thermal-engine +%: %.c + $(CC) $(CFLAGS) -D VERSION=\"$(VERSION)\" -o $@ $^ $(LDFLAGS) +clean: + $(RM) thermal-engine
tools/thermal/thermal-engine/thermal-engine.c new file +341 -0
341 lines not on this page · raw message
Quoted 22 lines · Daniel Lezcano
These changes are providing the following tools and library:
- A thermal library doing the netlink abstraction from the kernel in order to make the userspace thermal implementation easier. Having the library integrated with the kernel tree is also a guarantee to keep the message format and their encoding/decoding aligned
- A thermal tools library providing a set of functions to deal with usual features like the log, the mainloop and the time. This library is used by the provided tools below- An data acquisition program to capture the temperature of the different thermal zone during an amount of time or during the execution of an application. The output is formated to be easily parsed by gnuplot, a spreadsheet program or a statistical command line utility. The timestamp is based on the system uptime, thus giving an indication of when a thermal event happened, that can help to spot or reproduce thermal issue in the long run
Quoted 6 lines
- A thermal monitoring program based on the thermal library. It gives a skeleton to build any logic on top of it and shows how to use the thermal library. It does nothing except discovering the thermal zones, their trip points and listening for events like cooling devices state changes or trip point crossed
But I still see these errors in applying patches:
Applying: tools/lib/thermal: Add a thermal library
Applying: tools/thermal: Add util library
Applying: tools/thermal: Add a temperature capture tool .git/rebase-apply/patch:809: space before tab in indent.
polling = 100; }
.git/rebase-apply/patch:90: new blank line at EOF. +
.git/rebase-apply/patch:221: new blank line at EOF. +
warning: 3 lines add whitespace errors.
Applying: tools/thermal: Add thermal daemon skeleton .git/rebase-apply/patch:86: new blank line at EOF. +
warning: 1 line adds whitespace errors.
Thanks,
Srinivas
Quoted 101 lines
Changelog:
v3:
- Fixed NULL pointer reference when there is no thermal zones, trip points or cooling device
- Kill the child process when the duration ends or if there is an interruption in the thermometer
- Add error messages in the main body for the thermal-enginev2:
- Fixed all trailing whitespaces and some other checkpatch warnings. Some warnings remain but they can be considered as false positive
- Added in the thermometer tool:
- Usage/help option as well as a man page
- The ability to execute a program
- The capture duration
- Create the output directory if it does not exist- Add in the thermal-engine tool:
- A usage/help option
- A message telling the userspace it is waiting for events
- A daemonize option- Minor bug fixes here and there, as well as typos
v1: Initial post after a RFC
Daniel Lezcano (4):
tools/lib/thermal: Add a thermal library
tools/thermal: Add util library
tools/thermal: Add a temperature capture tool
tools/thermal: Add thermal daemon skeletonMAINTAINERS | 1 + tools/Makefile | 36 +- tools/lib/thermal/.gitignore | 2 + tools/lib/thermal/Build | 5 + tools/lib/thermal/Makefile | 165 +++++ tools/lib/thermal/commands.c | 349 +++++++++++ tools/lib/thermal/events.c | 164 +++++ tools/lib/thermal/include/thermal.h | 142 +++++ tools/lib/thermal/libthermal.map | 25 + tools/lib/thermal/libthermal.pc.template | 12 + tools/lib/thermal/sampling.c | 75 +++ tools/lib/thermal/thermal.c | 135 +++++ tools/lib/thermal/thermal_nl.c | 215 +++++++ tools/lib/thermal/thermal_nl.h | 46 ++ tools/thermal/lib/Build | 3 + tools/thermal/lib/Makefile | 158 +++++ .../thermal/lib/libthermal_tools.pc.template | 12 + tools/thermal/lib/log.c | 77 +++ tools/thermal/lib/log.h | 31 + tools/thermal/lib/mainloop.c | 120 ++++ tools/thermal/lib/mainloop.h | 15 + tools/thermal/lib/thermal-tools.h | 10 + tools/thermal/lib/uptimeofday.c | 40 ++ tools/thermal/lib/uptimeofday.h | 12 + tools/thermal/thermal-engine/Build | 2 + tools/thermal/thermal-engine/Makefile | 28 +
tools/thermal/thermal-engine/thermal-engine.c| 341 +++++++++++ tools/thermal/thermometer/Build | 2 + tools/thermal/thermometer/Makefile | 26 + tools/thermal/thermometer/thermometer.8 | 93 +++ tools/thermal/thermometer/thermometer.c | 573 ++++++++++++++++++ tools/thermal/thermometer/thermometer.conf | 5 +32 files changed, 2917 insertions(+), 3 deletions(-)create mode 100644
tools/lib/thermal/.gitignore
create mode 100644tools/lib/thermal/Build
create mode 100644tools/lib/thermal/Makefile
create mode 100644tools/lib/thermal/commands.c
create mode 100644tools/lib/thermal/events.c
create mode 100644tools/lib/thermal/include/thermal.hcreate mode 100644tools/lib/thermal/libthermal.mapcreate mode 100644tools/lib/thermal/libthermal.pc.templatecreate mode 100644tools/lib/thermal/sampling.c
create mode 100644tools/lib/thermal/thermal.c
create mode 100644tools/lib/thermal/thermal_nl.ccreate mode 100644tools/lib/thermal/thermal_nl.hcreate mode 100644tools/thermal/lib/Build
create mode 100644tools/thermal/lib/Makefile
create mode 100644tools/thermal/lib/libthermal_tools.pc.templatecreate mode 100644tools/thermal/lib/log.c
create mode 100644tools/thermal/lib/log.h
create mode 100644tools/thermal/lib/mainloop.c
create mode 100644tools/thermal/lib/mainloop.h
create mode 100644tools/thermal/lib/thermal-tools.hcreate mode 100644tools/thermal/lib/uptimeofday.ccreate mode 100644tools/thermal/lib/uptimeofday.hcreate mode 100644tools/thermal/thermal-engine/Buildcreate mode 100644tools/thermal/thermal-engine/Makefilecreate mode 100644tools/thermal/thermal-engine/thermal-engine.ccreate mode 100644tools/thermal/thermometer/Buildcreate mode 100644tools/thermal/thermometer/Makefilecreate mode 100644tools/thermal/thermometer/thermometer.8create mode 100644tools/thermal/thermometer/thermometer.ccreate mode 100644tools/thermal/thermometer/thermometer.conf
Quoted 1 line · srinivas pandruvada
On Wed, 2022-04-20 at 18:09 +0200, Daniel Lezcano wrote:
[ ... ]
Quoted 7 lines
But I still see these errors in applying patches:
Applying:
tools/lib/thermal: Add a thermal library
Applying:tools/thermal: Add util library
Applying:tools/thermal: Add a temperature capture tool .git/rebase-apply/patch:809: space before tab in indent.polling = 100; }
Quoted 9 lines
.git/rebase-apply/patch:90: new blank line at EOF. +
.git/rebase-apply/patch:221: new blank line at EOF. +
warning: 3 lines add whitespace errors.
Applying:tools/thermal: Add thermal daemon skeleton .git/rebase-apply/patch:86: new blank line at EOF. +
warning: 1 line adds whitespace errors.
Ok, I'll apply it with --whitespace=fix
I did a try and it fixes the trailing whitespace
Is ok for you Rafael ?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Rafael J. Wysocki
maintainerQuoted 25 lines · Daniel Lezcano
Quoted 1 line · srinivas pandruvada
On Wed, 2022-04-20 at 18:09 +0200, Daniel Lezcano wrote:
[ ... ]
Quoted 7 lines
But I still see these errors in applying patches:
Applying:
tools/lib/thermal: Add a thermal library
Applying:tools/thermal: Add util library
Applying:tools/thermal: Add a temperature capture tool .git/rebase-apply/patch:809: space before tab in indent.polling = 100; }Quoted 9 lines
.git/rebase-apply/patch:90: new blank line at EOF. +
.git/rebase-apply/patch:221: new blank line at EOF. +
warning: 3 lines add whitespace errors.
Applying:tools/thermal: Add thermal daemon skeleton .git/rebase-apply/patch:86: new blank line at EOF. +
warning: 1 line adds whitespace errors.Ok, I'll apply it with --whitespace=fix
Quoted 3 lines
I did a try and it fixes the trailing whitespace
Is ok for you Rafael ?
Sounds good.