Skip to content

Commit 47c4b0d

Browse files
committed
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. Signed-off-by: Daniel Lezcano <[email protected]> Tested-by: Srinivas Pandruvada <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bf70c57 commit 47c4b0d

File tree

14 files changed

+1348
-2
lines changed

14 files changed

+1348
-2
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19541,6 +19541,7 @@ F: drivers/thermal/
1954119541
F: include/linux/cpu_cooling.h
1954219542
F: include/linux/thermal.h
1954319543
F: include/uapi/linux/thermal.h
19544+
F: tools/lib/thermal/
1954419545
F: tools/thermal/
1954519546

1954619547
THERMAL DRIVER FOR AMLOGIC SOCS

tools/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ help:
3131
@echo ' bootconfig - boot config tool'
3232
@echo ' spi - spi tools'
3333
@echo ' tmon - thermal monitoring and tuning tool'
34+
@echo ' thermal - thermal library'
3435
@echo ' tracing - misc tracing tools'
3536
@echo ' turbostat - Intel CPU idle stats and freq reporting tool'
3637
@echo ' usb - USB testing tools'
@@ -85,6 +86,9 @@ perf: FORCE
8586
selftests: FORCE
8687
$(call descend,testing/$@)
8788

89+
thermal: FORCE
90+
$(call descend,lib/$@)
91+
8892
turbostat x86_energy_perf_policy intel-speed-select: FORCE
8993
$(call descend,power/x86/$@)
9094

@@ -101,7 +105,7 @@ all: acpi cgroup counter cpupower gpio hv firewire \
101105
perf selftests bootconfig spi turbostat usb \
102106
virtio vm bpf x86_energy_perf_policy \
103107
tmon freefall iio objtool kvm_stat wmi \
104-
pci debugging tracing
108+
pci debugging tracing thermal
105109

106110
acpi_install:
107111
$(call descend,power/$(@:_install=),install)
@@ -115,6 +119,9 @@ cgroup_install counter_install firewire_install gpio_install hv_install iio_inst
115119
selftests_install:
116120
$(call descend,testing/$(@:_install=),install)
117121

122+
thermal_install:
123+
$(call descend,lib/$(@:_install=),install)
124+
118125
turbostat_install x86_energy_perf_policy_install intel-speed-select_install:
119126
$(call descend,power/x86/$(@:_install=),install)
120127

@@ -160,6 +167,9 @@ perf_clean:
160167
selftests_clean:
161168
$(call descend,testing/$(@:_clean=),clean)
162169

170+
thermal_clean:
171+
$(call descend,lib/thermal,clean)
172+
163173
turbostat_clean x86_energy_perf_policy_clean intel-speed-select_clean:
164174
$(call descend,power/x86/$(@:_clean=),clean)
165175

@@ -177,6 +187,6 @@ clean: acpi_clean cgroup_clean counter_clean cpupower_clean hv_clean firewire_cl
177187
vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
178188
freefall_clean build_clean libbpf_clean libsubcmd_clean \
179189
gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \
180-
intel-speed-select_clean tracing_clean
190+
intel-speed-select_clean tracing_clean thermal_clean
181191

182192
.PHONY: FORCE

tools/lib/thermal/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
libthermal.so*
2+
libthermal.pc

tools/lib/thermal/Build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
libthermal-y += commands.o
2+
libthermal-y += events.o
3+
libthermal-y += thermal_nl.o
4+
libthermal-y += sampling.o
5+
libthermal-y += thermal.o

tools/lib/thermal/Makefile

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
# Most of this file is copied from tools/lib/perf/Makefile
3+
4+
LIBTHERMAL_VERSION = 0
5+
LIBTHERMAL_PATCHLEVEL = 0
6+
LIBTHERMAL_EXTRAVERSION = 1
7+
8+
MAKEFLAGS += --no-print-directory
9+
10+
ifeq ($(srctree),)
11+
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12+
srctree := $(patsubst %/,%,$(dir $(srctree)))
13+
srctree := $(patsubst %/,%,$(dir $(srctree)))
14+
# $(info Determined 'srctree' to be $(srctree))
15+
endif
16+
17+
INSTALL = install
18+
19+
# Use DESTDIR for installing into a different root directory.
20+
# This is useful for building a package. The program will be
21+
# installed in this directory as if it was the root directory.
22+
# Then the build tool can move it later.
23+
DESTDIR ?=
24+
DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25+
26+
include $(srctree)/tools/scripts/Makefile.include
27+
include $(srctree)/tools/scripts/Makefile.arch
28+
29+
ifeq ($(LP64), 1)
30+
libdir_relative = lib64
31+
else
32+
libdir_relative = lib
33+
endif
34+
35+
prefix ?=
36+
libdir = $(prefix)/$(libdir_relative)
37+
38+
# Shell quotes
39+
libdir_SQ = $(subst ','\'',$(libdir))
40+
libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41+
42+
ifeq ("$(origin V)", "command line")
43+
VERBOSE = $(V)
44+
endif
45+
ifndef VERBOSE
46+
VERBOSE = 0
47+
endif
48+
49+
ifeq ($(VERBOSE),1)
50+
Q =
51+
else
52+
Q = @
53+
endif
54+
55+
# Set compile option CFLAGS
56+
ifdef EXTRA_CFLAGS
57+
CFLAGS := $(EXTRA_CFLAGS)
58+
else
59+
CFLAGS := -g -Wall
60+
endif
61+
62+
INCLUDES = \
63+
-I/usr/include/libnl3 \
64+
-I$(srctree)/tools/lib/thermal/include \
65+
-I$(srctree)/tools/lib/ \
66+
-I$(srctree)/tools/include \
67+
-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
68+
-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
69+
-I$(srctree)/tools/include/uapi
70+
71+
# Append required CFLAGS
72+
override CFLAGS += $(EXTRA_WARNINGS)
73+
override CFLAGS += -Werror -Wall
74+
override CFLAGS += -fPIC
75+
override CFLAGS += $(INCLUDES)
76+
override CFLAGS += -fvisibility=hidden
77+
override CFGLAS += -Wl,-L.
78+
override CFGLAS += -Wl,-lthermal
79+
80+
all:
81+
82+
export srctree OUTPUT CC LD CFLAGS V
83+
export DESTDIR DESTDIR_SQ
84+
85+
include $(srctree)/tools/build/Makefile.include
86+
87+
VERSION_SCRIPT := libthermal.map
88+
89+
PATCHLEVEL = $(LIBTHERMAL_PATCHLEVEL)
90+
EXTRAVERSION = $(LIBTHERMAL_EXTRAVERSION)
91+
VERSION = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
92+
93+
LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
94+
LIBTHERMAL_A := $(OUTPUT)libthermal.a
95+
LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
96+
LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
97+
LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
98+
99+
THERMAL_UAPI := include/uapi/linux/thermal.h
100+
101+
$(THERMAL_UAPI): FORCE
102+
ln -sf $(srctree)/$@ $(srctree)/tools/$@
103+
104+
$(LIBTHERMAL_IN): FORCE
105+
$(Q)$(MAKE) $(build)=libthermal
106+
107+
$(LIBTHERMAL_A): $(LIBTHERMAL_IN)
108+
$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)
109+
110+
$(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
111+
$(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
112+
-Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
113+
@ln -sf $(@F) $(OUTPUT)libthermal.so
114+
@ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)
115+
116+
117+
libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
118+
119+
all: fixdep
120+
$(Q)$(MAKE) libs
121+
122+
clean:
123+
$(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
124+
*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC)
125+
126+
$(LIBTHERMAL_PC):
127+
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
128+
-e "s|@LIBDIR@|$(libdir_SQ)|" \
129+
-e "s|@VERSION@|$(VERSION)|" \
130+
< libthermal.pc.template > $@
131+
132+
define do_install_mkdir
133+
if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
134+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
135+
fi
136+
endef
137+
138+
define do_install
139+
if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
140+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
141+
fi; \
142+
$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
143+
endef
144+
145+
install_lib: libs
146+
$(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
147+
$(call do_install_mkdir,$(libdir_SQ)); \
148+
cp -fpR $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)
149+
150+
install_headers:
151+
$(call QUIET_INSTALL, headers) \
152+
$(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
153+
154+
install_pkgconfig: $(LIBTHERMAL_PC)
155+
$(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
156+
$(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
157+
158+
install_doc:
159+
$(Q)$(MAKE) -C Documentation install-man install-html install-examples
160+
161+
install: install_lib install_headers install_pkgconfig
162+
163+
FORCE:
164+
165+
.PHONY: all install clean FORCE

0 commit comments

Comments
 (0)