Commit 47c4b0de authored by Daniel Lezcano's avatar Daniel Lezcano
Browse files

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: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://lore.kernel.org/r/20220420160933.347088-2-daniel.lezcano@linaro.org
parent bf70c577
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+12 −2
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
libthermal.so*
libthermal.pc
+5 −0
Original line number Diff line number Diff line
libthermal-y += commands.o
libthermal-y += events.o
libthermal-y += thermal_nl.o
libthermal-y += sampling.o
libthermal-y += thermal.o
+165 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
# Most of this file is copied from tools/lib/perf/Makefile

LIBTHERMAL_VERSION = 0
LIBTHERMAL_PATCHLEVEL = 0
LIBTHERMAL_EXTRAVERSION = 1

MAKEFLAGS += --no-print-directory

ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
# $(info Determined 'srctree' to be $(srctree))
endif

INSTALL = install

# Use DESTDIR for installing into a different root directory.
# This is useful for building a package. The program will be
# installed in this directory as if it was the root directory.
# Then the build tool can move it later.
DESTDIR ?=
DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'

include $(srctree)/tools/scripts/Makefile.include
include $(srctree)/tools/scripts/Makefile.arch

ifeq ($(LP64), 1)
  libdir_relative = lib64
else
  libdir_relative = lib
endif

prefix ?=
libdir = $(prefix)/$(libdir_relative)

# Shell quotes
libdir_SQ = $(subst ','\'',$(libdir))
libdir_relative_SQ = $(subst ','\'',$(libdir_relative))

ifeq ("$(origin V)", "command line")
  VERBOSE = $(V)
endif
ifndef VERBOSE
  VERBOSE = 0
endif

ifeq ($(VERBOSE),1)
  Q =
else
  Q = @
endif

# Set compile option CFLAGS
ifdef EXTRA_CFLAGS
  CFLAGS := $(EXTRA_CFLAGS)
else
  CFLAGS := -g -Wall
endif

INCLUDES = \
-I/usr/include/libnl3 \
-I$(srctree)/tools/lib/thermal/include \
-I$(srctree)/tools/lib/ \
-I$(srctree)/tools/include \
-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
-I$(srctree)/tools/include/uapi

# Append required CFLAGS
override CFLAGS += $(EXTRA_WARNINGS)
override CFLAGS += -Werror -Wall
override CFLAGS += -fPIC
override CFLAGS += $(INCLUDES)
override CFLAGS += -fvisibility=hidden
override CFGLAS += -Wl,-L.
override CFGLAS += -Wl,-lthermal

all:

export srctree OUTPUT CC LD CFLAGS V
export DESTDIR DESTDIR_SQ

include $(srctree)/tools/build/Makefile.include

VERSION_SCRIPT := libthermal.map

PATCHLEVEL    = $(LIBTHERMAL_PATCHLEVEL)
EXTRAVERSION  = $(LIBTHERMAL_EXTRAVERSION)
VERSION       = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)

LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
LIBTHERMAL_A  := $(OUTPUT)libthermal.a
LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*

THERMAL_UAPI := include/uapi/linux/thermal.h

$(THERMAL_UAPI): FORCE
	ln -sf $(srctree)/$@ $(srctree)/tools/$@

$(LIBTHERMAL_IN): FORCE
	$(Q)$(MAKE) $(build)=libthermal

$(LIBTHERMAL_A): $(LIBTHERMAL_IN)
	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)

$(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
                                    -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
	@ln -sf $(@F) $(OUTPUT)libthermal.so
	@ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)


libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)

all: fixdep
	$(Q)$(MAKE) libs

clean:
	$(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC)

$(LIBTHERMAL_PC):
	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
		-e "s|@LIBDIR@|$(libdir_SQ)|" \
		-e "s|@VERSION@|$(VERSION)|" \
		< libthermal.pc.template > $@

define do_install_mkdir
	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
	fi
endef

define do_install
	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
	fi;                                             \
	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
endef

install_lib: libs
	$(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
		$(call do_install_mkdir,$(libdir_SQ)); \
		cp -fpR $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)

install_headers:
	$(call QUIET_INSTALL, headers) \
		$(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \

install_pkgconfig: $(LIBTHERMAL_PC)
	$(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
		$(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)

install_doc:
	$(Q)$(MAKE) -C Documentation install-man install-html install-examples

install: install_lib install_headers install_pkgconfig

FORCE:

.PHONY: all install clean FORCE
Loading