Skip to content

Commit ba64e51

Browse files
committed
Merge: cpupower update
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6422 JIRA: https://issues.redhat.com/browse/RHEL-80660 Signed-off-by: David Arcari <[email protected]> Approved-by: Steve Best <[email protected]> Approved-by: Tony Camuso <[email protected]> Approved-by: Lenny Szubowicz <[email protected]> Approved-by: CKI KWF Bot <[email protected]> Merged-by: Augusto Caringi <[email protected]>
2 parents 0790a3a + a9a9b6d commit ba64e51

24 files changed

+1746
-56
lines changed

tools/power/cpupower/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ debug/i386/intel_gsic
2727
debug/i386/powernow-k8-decode
2828
debug/x86_64/centrino-decode
2929
debug/x86_64/powernow-k8-decode
30+
31+
# Clang's compilation database file
32+
compile_commands.json

tools/power/cpupower/Makefile

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ LIB_MIN= 1
5757

5858
PACKAGE = cpupower
5959
PACKAGE_BUGREPORT = [email protected]
60-
LANGUAGES = de fr it cs pt ka
60+
LANGUAGES = de fr it cs pt ka zh_CN
6161

6262

6363
# Directory definitions. These are default and most probably
@@ -67,6 +67,7 @@ LANGUAGES = de fr it cs pt ka
6767
bindir ?= /usr/bin
6868
sbindir ?= /usr/sbin
6969
mandir ?= /usr/man
70+
libdir ?= /usr/lib
7071
includedir ?= /usr/include
7172
localedir ?= /usr/share/locale
7273
docdir ?= /usr/share/doc/packages/cpupower
@@ -85,23 +86,22 @@ INSTALL_SCRIPT = ${INSTALL} -m 644
8586
# If you are running a cross compiler, you may want to set this
8687
# to something more interesting, like "arm-linux-". If you want
8788
# to compile vs uClibc, that can be done here as well.
88-
CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
89+
CROSS ?= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
90+
ifneq ($(CROSS), )
8991
CC = $(CROSS)gcc
9092
LD = $(CROSS)gcc
9193
AR = $(CROSS)ar
9294
STRIP = $(CROSS)strip
9395
RANLIB = $(CROSS)ranlib
94-
HOSTCC = gcc
95-
MKDIR = mkdir
96-
97-
# 64bit library detection
98-
include ../../scripts/Makefile.arch
99-
100-
ifeq ($(IS_64_BIT), 1)
101-
libdir ?= /usr/lib64
10296
else
103-
libdir ?= /usr/lib
97+
CC ?= $(CROSS)gcc
98+
LD ?= $(CROSS)gcc
99+
AR ?= $(CROSS)ar
100+
STRIP ?= $(CROSS)strip
101+
RANLIB ?= $(CROSS)ranlib
104102
endif
103+
HOSTCC = gcc
104+
MKDIR = mkdir
105105

106106
# Now we set up the build system
107107
#
@@ -226,17 +226,28 @@ else
226226
endif
227227
$(QUIET) $(STRIPCMD) $@
228228

229+
ifeq (, $(shell which xgettext))
230+
$(warning "Install xgettext to extract translatable strings.")
231+
else
229232
$(OUTPUT)po/$(PACKAGE).pot: $(UTIL_SRC)
230233
$(ECHO) " GETTEXT " $@
231234
$(QUIET) xgettext --default-domain=$(PACKAGE) --add-comments \
232235
--keyword=_ --keyword=N_ $(UTIL_SRC) -p $(@D) -o $(@F)
236+
endif
233237

238+
ifeq (, $(shell which msgfmt))
239+
$(warning "Install msgfmt to generate binary message catalogs.")
240+
else
234241
$(OUTPUT)po/%.gmo: po/%.po
235242
$(ECHO) " MSGFMT " $@
236243
$(QUIET) msgfmt -o $@ po/$*.po
244+
endif
237245

238246
create-gmo: ${GMO_FILES}
239247

248+
ifeq (, $(shell which msgmerge))
249+
$(warning "Install msgmerge to merge translations.")
250+
else
240251
update-po: $(OUTPUT)po/$(PACKAGE).pot
241252
$(ECHO) " MSGMRG " $@
242253
$(QUIET) @for HLANG in $(LANGUAGES); do \
@@ -249,6 +260,7 @@ update-po: $(OUTPUT)po/$(PACKAGE).pot
249260
rm -f $(OUTPUT)po/$$HLANG.new.po; \
250261
fi; \
251262
done;
263+
endif
252264

253265
compile-bench: $(OUTPUT)libcpupower.so.$(LIB_MAJ)
254266
@V=$(V) confdir=$(confdir) $(MAKE) -C bench O=$(OUTPUT)
@@ -332,4 +344,39 @@ uninstall:
332344
rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupower.mo; \
333345
done;
334346

335-
.PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean
347+
help:
348+
@echo 'Building targets:'
349+
@echo ' all - Default target. Could be omitted. Put build artifacts'
350+
@echo ' to "O" cmdline option dir (default: current dir)'
351+
@echo ' install - Install previously built project files from the output'
352+
@echo ' dir defined by "O" cmdline option (default: current dir)'
353+
@echo ' to the install dir defined by "DESTDIR" cmdline or'
354+
@echo ' Makefile config block option (default: "")'
355+
@echo ' install-lib - Install previously built library binary from the output'
356+
@echo ' dir defined by "O" cmdline option (default: current dir)'
357+
@echo ' and library headers from "lib/" for userspace to the install'
358+
@echo ' dir defined by "DESTDIR" cmdline (default: "")'
359+
@echo ' install-tools - Install previously built "cpupower" util from the output'
360+
@echo ' dir defined by "O" cmdline option (default: current dir) and'
361+
@echo ' "cpupower-completion.sh" script from the src dir to the'
362+
@echo ' install dir defined by "DESTDIR" cmdline or Makefile'
363+
@echo ' config block option (default: "")'
364+
@echo ' install-man - Install man pages from the "man" src subdir to the'
365+
@echo ' install dir defined by "DESTDIR" cmdline or Makefile'
366+
@echo ' config block option (default: "")'
367+
@echo ' install-gmo - Install previously built language files from the output'
368+
@echo ' dir defined by "O" cmdline option (default: current dir)'
369+
@echo ' to the install dir defined by "DESTDIR" cmdline or Makefile'
370+
@echo ' config block option (default: "")'
371+
@echo ' install-bench - Install previously built "cpufreq-bench" util files from the'
372+
@echo ' output dir defined by "O" cmdline option (default: current dir)'
373+
@echo ' to the install dir defined by "DESTDIR" cmdline or Makefile'
374+
@echo ' config block option (default: "")'
375+
@echo ''
376+
@echo 'Cleaning targets:'
377+
@echo ' clean - Clean build artifacts from the dir defined by "O" cmdline'
378+
@echo ' option (default: current dir)'
379+
@echo ' uninstall - Remove previously installed files from the dir defined by "DESTDIR"'
380+
@echo ' cmdline or Makefile config block option (default: "")'
381+
382+
.PHONY: all utils libcpupower update-po create-gmo install-lib install-tools install-man install-gmo install uninstall clean help

tools/power/cpupower/README

Lines changed: 150 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,156 @@ interfaces [depending on configuration, see below].
2222
compilation and installation
2323
----------------------------
2424

25-
make
26-
su
27-
make install
28-
29-
should suffice on most systems. It builds libcpupower to put in
30-
/usr/lib; cpupower, cpufreq-bench_plot.sh to put in /usr/bin; and
31-
cpufreq-bench to put in /usr/sbin. If you want to set up the paths
32-
differently and/or want to configure the package to your specific
33-
needs, you need to open "Makefile" with an editor of your choice and
34-
edit the block marked CONFIGURATION.
25+
There are 2 output directories - one for the build output and another for
26+
the installation of the build results, that is the utility, library,
27+
man pages, etc...
28+
29+
default directory
30+
-----------------
31+
32+
In the case of default directory, build and install process requires no
33+
additional parameters:
34+
35+
build
36+
-----
37+
38+
$ make
39+
40+
The output directory for the 'make' command is the current directory and
41+
its subdirs in the kernel tree:
42+
tools/power/cpupower
43+
44+
install
45+
-------
46+
47+
$ sudo make install
48+
49+
'make install' command puts targets to default system dirs:
50+
51+
-----------------------------------------------------------------------
52+
| Installing file | System dir |
53+
-----------------------------------------------------------------------
54+
| libcpupower | /usr/lib |
55+
-----------------------------------------------------------------------
56+
| cpupower | /usr/bin |
57+
-----------------------------------------------------------------------
58+
| cpufreq-bench_plot.sh | /usr/bin |
59+
-----------------------------------------------------------------------
60+
| man pages | /usr/man |
61+
-----------------------------------------------------------------------
62+
63+
To put it in other words it makes build results available system-wide,
64+
enabling any user to simply start using it without any additional steps
65+
66+
custom directory
67+
----------------
68+
69+
There are 2 make's command-line variables 'O' and 'DESTDIR' that setup
70+
appropriate dirs:
71+
'O' - build directory
72+
'DESTDIR' - installation directory. This variable could also be setup in
73+
the 'CONFIGURATION' block of the "Makefile"
74+
75+
build
76+
-----
77+
78+
$ make O=<your_custom_build_catalog>
79+
80+
Example:
81+
$ make O=/home/hedin/prj/cpupower/build
82+
83+
install
84+
-------
85+
86+
$ make O=<your_custom_build_catalog> DESTDIR=<your_custom_install_catalog>
87+
88+
Example:
89+
$ make O=/home/hedin/prj/cpupower/build DESTDIR=/home/hedin/prj/cpupower \
90+
> install
91+
92+
Notice that both variables 'O' and 'DESTDIR' have been provided. The reason
93+
is that the build results are saved in the custom output dir defined by 'O'
94+
variable. So, this dir is the source for the installation step. If only
95+
'DESTDIR' were provided then the 'install' target would assume that the
96+
build directory is the current one, build everything there and install
97+
from the current dir.
98+
99+
The files will be installed to the following dirs:
100+
101+
-----------------------------------------------------------------------
102+
| Installing file | System dir |
103+
-----------------------------------------------------------------------
104+
| libcpupower | ${DESTDIR}/usr/lib |
105+
-----------------------------------------------------------------------
106+
| cpupower | ${DESTDIR}/usr/bin |
107+
-----------------------------------------------------------------------
108+
| cpufreq-bench_plot.sh | ${DESTDIR}/usr/bin |
109+
-----------------------------------------------------------------------
110+
| man pages | ${DESTDIR}/usr/man |
111+
-----------------------------------------------------------------------
112+
113+
If you look at the table for the default 'make' output dirs you will
114+
notice that the only difference with the non-default case is the
115+
${DESTDIR} prefix. So, the structure of the output dirs remains the same
116+
regardles of the root output directory.
117+
118+
119+
clean and uninstall
120+
-------------------
121+
122+
'clean' target is intended for cleanup the build catalog from build results
123+
'uninstall' target is intended for removing installed files from the
124+
installation directory
125+
126+
default directory
127+
-----------------
128+
129+
This case is a straightforward one:
130+
$ make clean
131+
$ make uninstall
132+
133+
custom directory
134+
----------------
135+
136+
Use 'O' command line variable to remove previously built files from the
137+
build dir:
138+
$ make O=<your_custom_build_catalog> clean
139+
140+
Example:
141+
$ make O=/home/hedin/prj/cpupower/build clean
142+
143+
Use 'DESTDIR' command line variable to uninstall previously installed files
144+
from the given dir:
145+
$ make DESTDIR=<your_custom_install_catalog>
146+
147+
Example:
148+
make DESTDIR=/home/hedin/prj/cpupower uninstall
149+
150+
151+
running the tool
152+
----------------
153+
154+
default directory
155+
-----------------
156+
157+
$ sudo cpupower
158+
159+
custom directory
160+
----------------
161+
162+
When it comes to run the utility from the custom build catalog things
163+
become a little bit complicated as 'just run' approach doesn't work.
164+
Assuming that the current dir is '<your_custom_install_catalog>/usr',
165+
issuing the following command:
166+
167+
$ sudo ./bin/cpupower
168+
will produce the following error output:
169+
./bin/cpupower: error while loading shared libraries: libcpupower.so.1:
170+
cannot open shared object file: No such file or directory
171+
172+
The issue is that binary cannot find the 'libcpupower' library. So, we
173+
shall point to the lib dir:
174+
sudo LD_LIBRARY_PATH=lib64/ ./bin/cpupower
35175

36176

37177
THANKS

tools/power/cpupower/bench/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
ifeq ($(MAKELEVEL),0)
3+
$(error This Makefile is not intended to be run standalone, but only as a part \
4+
of the main one in the parent dir)
5+
endif
6+
27
OUTPUT := ./
38
ifeq ("$(origin O)", "command line")
49
ifneq ($(O),)
@@ -15,7 +20,7 @@ LIBS = -L../ -L$(OUTPUT) -lm -lcpupower
1520
OBJS = $(OUTPUT)main.o $(OUTPUT)parse.o $(OUTPUT)system.o $(OUTPUT)benchmark.o
1621
endif
1722

18-
CFLAGS += -D_GNU_SOURCE -I../lib -DDEFAULT_CONFIG_FILE=\"$(confdir)/cpufreq-bench.conf\"
23+
override CFLAGS += -D_GNU_SOURCE -I../lib -DDEFAULT_CONFIG_FILE=\"$(confdir)/cpufreq-bench.conf\"
1924

2025
$(OUTPUT)%.o : %.c
2126
$(ECHO) " CC " $@

tools/power/cpupower/bench/parse.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (C) 2008 Christian Kornacker <[email protected]>
55
*/
66

7+
#include <errno.h>
78
#include <stdio.h>
89
#include <stdlib.h>
910
#include <stdarg.h>
@@ -165,8 +166,8 @@ int prepare_config(const char *path, struct config *config)
165166

166167
configfile = fopen(path, "r");
167168
if (configfile == NULL) {
168-
perror("fopen");
169-
fprintf(stderr, "error: unable to read configfile\n");
169+
fprintf(stderr, "error: unable to read configfile: %s, %s\n",
170+
path, strerror(errno));
170171
free(config);
171172
return 1;
172173
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
__pycache__/
3+
raw_pylibcpupower_wrap.c
4+
*.o
5+
*.so
6+
*.py
7+
!test_raw_pylibcpupower.py
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
# Makefile for libcpupower's Python bindings
3+
#
4+
# This Makefile expects you have already run the makefile for cpupower to build
5+
# the .o files in the lib directory for the bindings to be created.
6+
7+
CC := gcc
8+
HAVE_SWIG := $(shell if which swig >/dev/null 2>&1; then echo 1; else echo 0; fi)
9+
HAVE_PYCONFIG := $(shell if which python-config >/dev/null 2>&1; then echo 1; else echo 0; fi)
10+
11+
LIB_DIR := ../../lib
12+
PY_INCLUDE = $(firstword $(shell python-config --includes))
13+
OBJECTS_LIB = $(wildcard $(LIB_DIR)/*.o)
14+
INSTALL_DIR = $(shell python3 -c "import site; print(site.getsitepackages()[0])")
15+
16+
all: _raw_pylibcpupower.so
17+
18+
_raw_pylibcpupower.so: raw_pylibcpupower_wrap.o
19+
$(CC) -shared $(OBJECTS_LIB) raw_pylibcpupower_wrap.o -o _raw_pylibcpupower.so
20+
21+
raw_pylibcpupower_wrap.o: raw_pylibcpupower_wrap.c
22+
$(CC) -fPIC -c raw_pylibcpupower_wrap.c $(PY_INCLUDE)
23+
24+
raw_pylibcpupower_wrap.c: raw_pylibcpupower.swg
25+
ifeq ($(HAVE_SWIG),0)
26+
$(error "swig was not found. Make sure you have it installed and in the PATH to generate the bindings.")
27+
else ifeq ($(HAVE_PYCONFIG),0)
28+
$(error "python-config was not found. Make sure you have it installed and in the PATH to generate the bindings.")
29+
endif
30+
swig -python raw_pylibcpupower.swg
31+
32+
# Only installs the Python bindings
33+
install: _raw_pylibcpupower.so
34+
install -D _raw_pylibcpupower.so $(INSTALL_DIR)/_raw_pylibcpupower.so
35+
install -D raw_pylibcpupower.py $(INSTALL_DIR)/raw_pylibcpupower.py
36+
37+
uninstall:
38+
rm -f $(INSTALL_DIR)/_raw_pylibcpupower.so
39+
rm -f $(INSTALL_DIR)/raw_pylibcpupower.py
40+
41+
# Will only clean the bindings folder; will not clean the actual cpupower folder
42+
clean:
43+
rm -f raw_pylibcpupower.py raw_pylibcpupower_wrap.c raw_pylibcpupower_wrap.o _raw_pylibcpupower.so

0 commit comments

Comments
 (0)