Commit 7fe2f639 authored by Dominik Brodowski's avatar Dominik Brodowski
Browse files

cpupowerutils - cpufrequtils extended with quite some features


CPU power consumption vs performance tuning is no longer
limited to CPU frequency switching anymore: deep sleep states,
traditional dynamic frequency scaling and hidden turbo/boost
frequencies are tied close together and depend on each other.
The first two exist on different architectures like PPC, Itanium and
ARM, the latter (so far) only on X86. On X86 the APU (CPU+GPU) will
only run most efficiently if CPU and GPU has proper power management
in place.

Users and Developers want to have *one* tool to get an overview what
their system supports and to monitor and debug CPU power management
in detail. The tool should compile and work on as many architectures
as possible.

Once this tool stabilizes a bit, it is intended to replace the
Intel-specific tools in tools/power/x86
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent 02f8c6ae
......@@ -1908,6 +1908,12 @@ S: Maintained
F: arch/x86/kernel/cpuid.c
F: arch/x86/kernel/msr.c
CPU POWER MONITORING SUBSYSTEM
M: Dominik Brodowski <linux@dominikbrodowski.net>
M: Thomas Renninger <trenn@suse.de>
S: Maintained
F: tools/power/cpupower
CPUSETS
M: Paul Menage <menage@google.com>
W: http://www.bullopensource.org/cpuset/
......
.libs
libcpufreq.so
libcpufreq.so.0
libcpufreq.so.0.0.0
build/ccdv
cpufreq-info
cpufreq-set
cpufreq-aperf
lib/.libs
lib/cpufreq.lo
lib/cpufreq.o
lib/proc.lo
lib/proc.o
lib/sysfs.lo
lib/sysfs.o
libcpufreq.la
po/cpufrequtils.pot
po/*.gmo
utils/cpufreq-info.o
utils/cpufreq-set.o
utils/cpufreq-aperf.o
\ No newline at end of file
Dominik Brodowski
<linux@brodo.de>
Mattia Dongili
via Latisana, 8
00177 Rome
Italy
<malattia@gmail.com>
Goran Koruga
Slovenia
<korugag@siol.net>
Thomas Renninger
SUSE Linux GmbH
Germany
<trenn@suse.de>
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
# Makefile for cpupowerutils
#
# Copyright (C) 2005,2006 Dominik Brodowski <linux@dominikbrodowski.net>
#
# Based largely on the Makefile for udev by:
#
# Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# --- CONFIGURATION BEGIN ---
# Set the following to `true' to make a unstripped, unoptimized
# binary. Leave this set to `false' for production use.
DEBUG ?= true
# make the build silent. Set this to something else to make it noisy again.
V ?= false
# Internationalization support (output in different languages).
# Requires gettext.
NLS ?= true
# Set the following to 'true' to build/install the
# cpufreq-bench benchmarking tool
CPUFRQ_BENCH ?= true
# Prefix to the directories we're installing to
DESTDIR ?=
# --- CONFIGURATION END ---
# Package-related definitions. Distributions can modify the version
# and _should_ modify the PACKAGE_BUGREPORT definition
VERSION = 009p1
LIB_MAJ= 0.0.0
LIB_MIN= 0
PACKAGE = cpupowerutils
PACKAGE_BUGREPORT = cpufreq@vger.kernel.org
LANGUAGES = de fr it cs pt
# Directory definitions. These are default and most probably
# do not need to be changed. Please note that DESTDIR is
# added in front of any of them
bindir ?= /usr/bin
sbindir ?= /usr/sbin
mandir ?= /usr/man
includedir ?= /usr/include
libdir ?= /usr/lib
localedir ?= /usr/share/locale
docdir ?= /usr/share/doc/packages/cpupowerutils
confdir ?= /etc/
# Toolchain: what tools do we use, and what options do they need:
CP = cp -fpR
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_SCRIPT = ${INSTALL_PROGRAM}
# If you are running a cross compiler, you may want to set this
# to something more interesting, like "arm-linux-". If you want
# to compile vs uClibc, that can be done here as well.
CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
CC = $(CROSS)gcc
LD = $(CROSS)gcc
AR = $(CROSS)ar
STRIP = $(CROSS)strip
RANLIB = $(CROSS)ranlib
HOSTCC = gcc
# Now we set up the build system
#
# set up PWD so that older versions of make will work with our build.
PWD = $(shell pwd)
export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
# check if compiler option is supported
cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
# use '-Os' optimization if available, else use -O2
OPTIMIZATION := $(call cc-supports,-Os,-O2)
WARNINGS := -Wall -Wchar-subscripts -Wpointer-arith -Wsign-compare
WARNINGS += $(call cc-supports,-Wno-pointer-sign)
WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
WARNINGS += -Wshadow
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DPACKAGE=\"$(PACKAGE)\" \
-DPACKAGE_BUGREPORT=\"$(PACKAGE_BUGREPORT)\" -D_GNU_SOURCE
UTIL_OBJS = utils/helpers/amd.o utils/helpers/topology.o utils/helpers/msr.o \
utils/helpers/sysfs.o utils/helpers/misc.o utils/helpers/cpuid.o \
utils/helpers/pci.o utils/helpers/bitmask.o \
utils/idle_monitor/nhm_idle.o utils/idle_monitor/snb_idle.o \
utils/idle_monitor/amd_fam14h_idle.o utils/idle_monitor/cpuidle_sysfs.o \
utils/idle_monitor/mperf_monitor.o utils/idle_monitor/cpupower-monitor.o \
utils/cpupower.o utils/cpufreq-info.o utils/cpufreq-set.o \
utils/cpupower-set.o utils/cpupower-info.o utils/cpuidle-info.o
UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
utils/helpers/bitmask.h \
utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def
UTIL_SRC := $(UTIL_OBJS:.o=.c)
LIB_HEADERS = lib/cpufreq.h lib/sysfs.h
LIB_SRC = lib/cpufreq.c lib/sysfs.c
LIB_OBJS = lib/cpufreq.o lib/sysfs.o
CFLAGS += -pipe
ifeq ($(strip $(NLS)),true)
INSTALL_NLS += install-gmo
COMPILE_NLS += update-gmo
endif
ifeq ($(strip $(CPUFRQ_BENCH)),true)
INSTALL_BENCH += install-bench
COMPILE_BENCH += compile-bench
endif
CFLAGS += $(WARNINGS)
ifeq ($(strip $(V)),false)
QUIET=@$(PWD)/build/ccdv
HOST_PROGS=build/ccdv
else
QUIET=
HOST_PROGS=
endif
# if DEBUG is enabled, then we do not strip or optimize
ifeq ($(strip $(DEBUG)),true)
CFLAGS += -O1 -g
CPPFLAGS += -DDEBUG
STRIPCMD = /bin/true -Since_we_are_debugging
else
CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
endif
# the actual make rules
all: ccdv libcpufreq cpupower $(COMPILE_NLS) $(COMPILE_BENCH)
ccdv: build/ccdv
build/ccdv: build/ccdv.c
@echo "Building ccdv"
@$(HOSTCC) -O1 $< -o $@
lib/%.o: $(LIB_SRC) $(LIB_HEADERS) build/ccdv
$(QUIET) $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c lib/$*.c
libcpufreq.so.$(LIB_MAJ): $(LIB_OBJS)
$(QUIET) $(CC) -shared $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
-Wl,-soname,libcpufreq.so.$(LIB_MIN) $(LIB_OBJS)
@ln -sf $@ libcpufreq.so
@ln -sf $@ libcpufreq.so.$(LIB_MIN)
libcpufreq: libcpufreq.so.$(LIB_MAJ)
# Let all .o files depend on its .c file and all headers
# Might be worth to put this into utils/Makefile at some point of time
$(UTIL_OBJS): $(UTIL_HEADERS)
.c.o:
$(QUIET) $(CC) $(CFLAGS) $(CPPFLAGS) -I./lib -I ./utils -o $@ -c $*.c
cpupower: $(UTIL_OBJS) libcpufreq
$(QUIET) $(CC) $(CFLAGS) $(LDFLAGS) -lcpufreq -lrt -lpci -L. -o $@ $(UTIL_OBJS)
$(STRIPCMD) $@
po/$(PACKAGE).pot: $(UTIL_SRC)
@xgettext --default-domain=$(PACKAGE) --add-comments \
--keyword=_ --keyword=N_ $(UTIL_SRC) && \
test -f $(PACKAGE).po && \
mv -f $(PACKAGE).po po/$(PACKAGE).pot
update-gmo: po/$(PACKAGE).pot
@for HLANG in $(LANGUAGES); do \
echo -n "Translating $$HLANG "; \
if msgmerge po/$$HLANG.po po/$(PACKAGE).pot -o \
po/$$HLANG.new.po; then \
mv -f po/$$HLANG.new.po po/$$HLANG.po; \
else \
echo "msgmerge for $$HLANG failed!"; \
rm -f po/$$HLANG.new.po; \
fi; \
msgfmt --statistics -o po/$$HLANG.gmo po/$$HLANG.po; \
done;
compile-bench: libcpufreq.so.$(LIB_MAJ)
@V=$(V) confdir=$(confdir) $(MAKE) -C bench
clean:
-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
| xargs rm -f
-rm -f $(UTIL_BINS)
-rm -f $(IDLE_OBJS)
-rm -f cpupower
-rm -f libcpufreq.so*
-rm -f build/ccdv
-rm -rf po/*.gmo po/*.pot
$(MAKE) -C bench clean
install-lib:
$(INSTALL) -d $(DESTDIR)${libdir}
$(CP) libcpufreq.so* $(DESTDIR)${libdir}/
$(INSTALL) -d $(DESTDIR)${includedir}
$(INSTALL_DATA) lib/cpufreq.h $(DESTDIR)${includedir}/cpufreq.h
install-tools:
$(INSTALL) -d $(DESTDIR)${bindir}
$(INSTALL_PROGRAM) cpupower $(DESTDIR)${bindir}
install-man:
$(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1
$(INSTALL_DATA) -D man/cpupower-frequency-set.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-set.1
$(INSTALL_DATA) -D man/cpupower-frequency-info.1 $(DESTDIR)${mandir}/man1/cpupower-frequency-info.1
$(INSTALL_DATA) -D man/cpupower-set.1 $(DESTDIR)${mandir}/man1/cpupower-set.1
$(INSTALL_DATA) -D man/cpupower-info.1 $(DESTDIR)${mandir}/man1/cpupower-info.1
$(INSTALL_DATA) -D man/cpupower-monitor.1 $(DESTDIR)${mandir}/man1/cpupower-monitor.1
install-gmo:
$(INSTALL) -d $(DESTDIR)${localedir}
for HLANG in $(LANGUAGES); do \
echo '$(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo'; \
$(INSTALL_DATA) -D po/$$HLANG.gmo $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \
done;
install-bench:
@#DESTDIR must be set from outside to survive
@sbindir=$(sbindir) bindir=$(bindir) docdir=$(docdir) confdir=$(confdir) $(MAKE) -C bench install
install: all install-lib install-tools install-man $(INSTALL_NLS) $(INSTALL_BENCH)
uninstall:
- rm -f $(DESTDIR)${libdir}/libcpufreq.*
- rm -f $(DESTDIR)${includedir}/cpufreq.h
- rm -f $(DESTDIR)${bindir}/utils/cpupower
- rm -f $(DESTDIR)${mandir}/man1/cpufreq-set.1
- rm -f $(DESTDIR)${mandir}/man1/cpufreq-info.1
- for HLANG in $(LANGUAGES); do \
rm -f $(DESTDIR)${localedir}/$$HLANG/LC_MESSAGES/cpupowerutils.mo; \
done;
.PHONY: all utils libcpufreq ccdv update-po update-gmo install-lib install-tools install-man install-gmo install uninstall \
clean
The cpufrequtils package (homepage:
http://www.kernel.org/pub/linux/utils/kernel/cpufreq/cpufrequtils.html )
consists of the following elements:
requirements
------------
On x86 pciutils is needed at runtime (-lpci).
For compilation pciutils-devel (pci/pci.h) and a gcc version
providing cpuid.h is needed.
For both it's not explicitly checked for (yet).
libcpufreq
----------
"libcpufreq" is a library which offers a unified access method for userspace
tools and programs to the cpufreq core and drivers in the Linux kernel. This
allows for code reduction in userspace tools, a clean implementation of
the interaction to the cpufreq core, and support for both the sysfs and proc
interfaces [depending on configuration, see below].
compilation and installation
----------------------------
make
su
make install
should suffice on most systems. It builds default libcpufreq,
cpufreq-set and cpufreq-info files and installs them in /usr/lib and
/usr/bin, respectively. If you want to set up the paths differently and/or
want to configure the package to your specific needs, you need to open
"Makefile" with an editor of your choice and edit the block marked
CONFIGURATION.
THANKS
------
Many thanks to Mattia Dongili who wrote the autotoolization and
libtoolization, the manpages and the italian language file for cpufrequtils;
to Dave Jones for his feedback and his dump_psb tool; to Bruno Ducrot for his
powernow-k8-decode and intel_gsic tools as well as the french language file;
and to various others commenting on the previous (pre-)releases of
cpufrequtils.
Dominik Brodowski
ToDos sorted by priority:
- Use bitmask functions to parse CPU topology more robust
(current implementation has issues on AMD)
- Try to read out boost states and frequencies on Intel
- Adjust README
- Somewhere saw the ability to read power consumption of
RAM from HW on Intel SandyBridge -> another monitor?
- Add another c1e debug idle monitor
-> Is by design racy with BIOS, but could be added
with a --force option and some "be careful" messages
LIBS = -L../ -lm -lcpufreq
OBJS = main.o parse.o system.o benchmark.o
CFLAGS += -D_GNU_SOURCE -I../lib -DDEFAULT_CONFIG_FILE=\"$(confdir)/cpufreq-bench.conf\"
ifeq ($(strip $(V)),false)
CC=@../build/ccdv gcc
else
CC=gcc
endif
cpufreq-bench: $(OBJS)
$(CC) -o $@ $(CFLAGS) $(OBJS) $(LIBS)
all: cpufreq-bench
install:
mkdir -p $(DESTDIR)/$(sbindir)
mkdir -p $(DESTDIR)/$(bindir)
mkdir -p $(DESTDIR)/$(docdir)
mkdir -p $(DESTDIR)/$(confdir)
install -m 755 cpufreq-bench $(DESTDIR)/$(sbindir)/cpufreq-bench
install -m 755 cpufreq-bench_plot.sh $(DESTDIR)/$(bindir)/cpufreq-bench_plot.sh
install -m 644 README-BENCH $(DESTDIR)/$(docdir)/README-BENCH
install -m 755 cpufreq-bench_script.sh $(DESTDIR)/$(docdir)/cpufreq-bench_script.sh
install -m 644 example.cfg $(DESTDIR)/$(confdir)/cpufreq-bench.conf
clean:
rm -f *.o
rm -f cpufreq-bench
This is cpufreq-bench, a microbenchmark for the cpufreq framework.
Purpose
=======
What is this benchmark for:
- Identify worst case performance loss when doing dynamic frequency
scaling using Linux kernel governors
- Identify average reaction time of a governor to CPU load changes
- (Stress) Testing whether a cpufreq low level driver or governor works
as expected
- Identify cpufreq related performance regressions between kernels
- Possibly Real time priority testing? -> what happens if there are
processes with a higher prio than the governor's kernel thread
- ...
What this benchmark does *not* cover:
- Power saving related regressions (In fact as better the performance
throughput is, the worse the power savings will be, but the first should
mostly count more...)
- Real world (workloads)
Description
===========
cpufreq-bench helps to test the condition of a given cpufreq governor.
For that purpose, it compares the performance governor to a configured
powersave module.
How it works
============
You can specify load (100% CPU load) and sleep (0% CPU load) times in us which
will be run X time in a row (cycles):
sleep=25000
load=25000
cycles=20
This part of the configuration file will create 25ms load/sleep turns,
repeated 20 times.
Adding this:
sleep_step=25000
load_step=25000
rounds=5
Will increase load and sleep time by 25ms 5 times.
Together you get following test:
25ms load/sleep time repeated 20 times (cycles).
50ms load/sleep time repeated 20 times (cycles).
..
100ms load/sleep time repeated 20 times (cycles).
First it is calibrated how long a specific CPU intensive calculation
takes on this machine and needs to be run in a loop using the performance
governor.
Then the above test runs are processed using the performance governor
and the governor to test. The time the calculation really needed
with the dynamic freq scaling governor is compared with the time needed
on full performance and you get the overall performance loss.
Example of expected results with ondemand governor:
This shows expected results of the first two test run rounds from
above config, you there have:
100% CPU load (load) | 0 % CPU load (sleep) | round
25 ms | 25 ms | 1
50 ms | 50 ms | 2
For example if ondemand governor is configured to have a 50ms
sampling rate you get:
In round 1, ondemand should have rather static 50% load and probably
won't ever switch up (as long as up_threshold is above).
In round 2, if the ondemand sampling times exactly match the load/sleep
trigger of the cpufreq-bench, you will see no performance loss (compare with
below possible ondemand sample kick ins (1)):
But if ondemand always kicks in in the middle of the load sleep cycles, it
will always see 50% loads and you get worst performance impact never
switching up (compare with below possible ondemand sample kick ins (2))::
50 50 50 50ms ->time
load -----| |-----| |-----| |-----|
| | | | | | |
sleep |-----| |-----| |-----| |----
|-----|-----|-----|-----|-----|-----|-----|---- ondemand sampling (1)
100 0 100 0 100 0 100 load seen by ondemand(%)
|-----|-----|-----|-----|-----|-----|-----|-- ondemand sampling (2)
50 50 50 50 50 50 50 load seen by ondemand(%)
You can easily test all kind of load/sleep times and check whether your
governor in average behaves as expected.
ToDo
====
Provide a gnuplot utility script for easy generation of plots to present
the outcome nicely.
cpufreq-bench Command Usage
===========================
-l, --load=<long int> initial load time in us
-s, --sleep=<long int> initial sleep time in us
-x, --load-step=<long int> time to be added to load time, in us
-y, --sleep-step=<long int> time to be added to sleep time, in us
-c, --cpu=<unsigned int> CPU Number to use, starting at 0
-p, --prio=<priority> scheduler priority, HIGH, LOW or DEFAULT
-g, --governor=<governor> cpufreq governor to test
-n, --cycles=<int> load/sleep cycles to get an avarage value to compare
-r, --rounds<int> load/sleep rounds
-f, --file=<configfile> config file to use
-o, --output=<dir> output dir, must exist
-v, --verbose verbose output on/off
Due to the high priority, the application may not be responsible for some time.
After the benchmark, the logfile is saved in OUTPUTDIR/benchmark_TIMESTAMP.log
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include "config.h"
#include "system.h"
#include "benchmark.h"
/* Print out progress if we log into a file */
#define show_progress(total_time, progress_time) \
if (config->output != stdout) { \
fprintf(stdout, "Progress: %02lu %%\r", \
(progress_time * 100) / total_time); \
fflush(stdout); \
}
/**
* compute how many rounds of calculation we should do
* to get the given load time
*
* @param load aimed load time in s
*
* @retval rounds of calculation
**/
unsigned int calculate_timespace(long load, struct config *config)
{
int i;
long long now, then;
unsigned int estimated = GAUGECOUNT;
unsigned int rounds = 0;
unsigned int timed = 0;
if (config->verbose)
printf("calibrating load of %lius, please wait...\n", load);
/* get the initial calculation time for a specific number of rounds */
now = get_time();
ROUNDS(estimated);
then = get_time();
timed = (unsigned int)(then - now);
/* approximation of the wanted load time by comparing with the
* initial calculation time */
for (i= 0; i < 4; i++)
{
rounds = (unsigned int)(load * estimated / timed);
dprintf("calibrating with %u rounds\n", rounds);
now = get_time();
ROUNDS(rounds);
then = get_time();
timed = (unsigned int)(then - now);
estimated = rounds;
}
if (config->verbose)
printf("calibration done\n");
return estimated;
}
/**
* benchmark
* generates a specific sleep an load time with the performance
* governor and compares the used time for same calculations done
* with the configured powersave governor
*
* @param config config values for the benchmark
*
**/
void start_benchmark(struct config *config)
{
unsigned int _round, cycle;
long long now, then;
long sleep_time = 0, load_time = 0;
long performance_time = 0, powersave_time = 0;
unsigned int calculations;
unsigned long total_time = 0, progress_time = 0;
sleep_time = config->sleep;
load_time = config->load;
/* For the progress bar */
for (_round=1; _round <= config->rounds; _round++)
total_time += _round * (config->sleep + config->load);
total_time *= 2; /* powersave and performance cycles */
for (_round=0; _round < config->rounds; _round++) {
performance_time = 0LL;
powersave_time = 0LL;
show_progress(total_time, progress_time);
/* set the cpufreq governor to "performance" which disables
* P-State switching. */
if (set_cpufreq_governor("performance", config->cpu) != 0)
return;
/* calibrate the calculation time. the resulting calculation
* _rounds should produce a load which matches the configured
* load time */
calculations = calculate_timespace(load_time, config);
if (config->verbose)
printf("_round %i: doing %u cycles with %u calculations"
" for %lius\n", _round + 1, config->cycles,
calculations, load_time);
fprintf(config->output, "%u %li %li ",
_round, load_time, sleep_time);
if (config->verbose) {
printf("avarage: %lius, rps:%li\n", load_time / calculations, 1000000 * calculations / load_time);
}
/* do some sleep/load cycles with the performance governor */
for (cycle = 0; cycle < config->cycles; cycle++) {
now = get_time();
usleep(sleep_time);
ROUNDS(calculations);
then = get_time();
performance_time += then - now - sleep_time;
if (config->verbose)
printf("performance cycle took %lius, sleep: %lius, load: %lius, rounds: %u\n",
(long)(then - now), sleep_time, load_time, calculations);
}
fprintf(config->output, "%li ", performance_time / config->cycles);
progress_time += sleep_time + load_time;
show_progress(total_time, progress_time);
/* set the powersave governor which activates P-State switching
* again */
if (set_cpufreq_governor(config->governor, config->cpu) != 0)
return;
/* again, do some sleep/load cycles with the powersave governor */
for (cycle = 0; cycle < config->cycles; cycle++) {
now = get_time();
usleep(sleep_time);
ROUNDS(calculations);
then = get_time();
powersave_time += then - now - sleep_time;
if (config->verbose)
printf("powersave cycle took %lius, sleep: %lius, load: %lius, rounds: %u\n",
(long)(then - now), sleep_time, load_time, calculations);
}
progress_time += sleep_time + load_time;
/* compare the avarage sleep/load cycles */
fprintf(config->output, "%li ", powersave_time / config->cycles);
fprintf(config->output, "%.3f\n", performance_time * 100.0 / powersave_time);
fflush(config->output);
if (config->verbose)
printf("performance is at %.2f%%\n", performance_time * 100.0 / powersave_time);
sleep_time += config->sleep_step;
load_time += config->load_step;
}
}
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* load loop, this schould take about 1 to 2ms to complete */
#define ROUNDS(x) {unsigned int rcnt; \
for (rcnt = 0; rcnt< x*1000; rcnt++) { \
(void)(((int)(pow(rcnt, rcnt) * sqrt(rcnt*7230970)) ^ 7230716) ^ (int)atan2(rcnt, rcnt)); \
}} \
void start_benchmark(struct config *config);
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* initial loop count for the load calibration */
#define GAUGECOUNT 1500
/* default scheduling policy SCHED_OTHER */
#define SCHEDULER SCHED_OTHER
#define PRIORITY_DEFAULT 0
#define PRIORITY_HIGH sched_get_priority_max(SCHEDULER)
#define PRIORITY_LOW sched_get_priority_min(SCHEDULER)
/* enable further debug messages */
#ifdef DEBUG
#define dprintf printf
#else
#define dprintf( ... ) while(0) { }
#endif
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# Author/Copyright(c): 2009, Thomas Renninger <trenn@suse.de>, Novell Inc.
# Helper script to easily create nice plots of your cpufreq-bench results
dir=`mktemp -d`
output_file="cpufreq-bench.png"
global_title="cpufreq-bench plot"
picture_type="jpeg"
file[0]=""
function usage()
{
echo "cpufreq-bench_plot.sh [OPTIONS] logfile [measure_title] [logfile [measure_title]] ...]"
echo
echo "Options"
echo " -o output_file"
echo " -t global_title"
echo " -p picture_type [jpeg|gif|png|postscript|...]"
exit 1
}
if [ $# -eq 0 ];then
echo "No benchmark results file provided"
echo
usage
fi
while getopts o:t:p: name ; do
case $name in
o)
output_file="$OPTARG".$picture_type
;;
t)
global_title="$OPTARG"
;;
p)
picture_type="$OPTARG"
;;
?)
usage
;;
esac
done
shift $(($OPTIND -1))
plots=0
while [ "$1" ];do
if [ ! -f "$1" ];then
echo "File $1 does not exist"
usage
fi
file[$plots]="$1"
title[$plots]="$2"
# echo "File: ${file[$plots]} - ${title[plots]}"
shift;shift
plots=$((plots + 1))
done
echo "set terminal $picture_type" >> $dir/plot_script.gpl
echo "set output \"$output_file\"" >> $dir/plot_script.gpl
echo "set title \"$global_title\"" >> $dir/plot_script.gpl
echo "set xlabel \"sleep/load time\"" >> $dir/plot_script.gpl
echo "set ylabel \"Performance (%)\"" >> $dir/plot_script.gpl
for((plot=0;plot<$plots;plot++));do
# Sanity check
###### I am to dump to get this redirected to stderr/stdout in one awk call... #####
cat ${file[$plot]} |grep -v "^#" |awk '{if ($2 != $3) printf("Error in measure %d:Load time %s does not equal sleep time %s, plot will not be correct\n", $1, $2, $3); ERR=1}'
###### I am to dump to get this redirected in one awk call... #####
# Parse out load time (which must be equal to sleep time for a plot), divide it by 1000
# to get ms and parse out the performance in percentage and write it to a temp file for plotting
cat ${file[$plot]} |grep -v "^#" |awk '{printf "%lu %.1f\n",$2/1000, $6}' >$dir/data_$plot
if [ $plot -eq 0 ];then
echo -n "plot " >> $dir/plot_script.gpl
fi
echo -n "\"$dir/data_$plot\" title \"${title[$plot]}\" with lines" >> $dir/plot_script.gpl
if [ $(($plot + 1)) -ne $plots ];then
echo -n ", " >> $dir/plot_script.gpl
fi
done
echo >> $dir/plot_script.gpl
gnuplot $dir/plot_script.gpl
rm -r $dir
\ No newline at end of file
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# Author/Copyright(c): 2009, Thomas Renninger <trenn@suse.de>, Novell Inc.
# Ondemand up_threshold and sampling rate test script for cpufreq-bench
# mircobenchmark.
# Modify the general variables at the top or extend or copy out parts
# if you want to test other things
#
# Default with latest kernels is 95, before micro account patches
# it was 80, cmp. with git commit 808009131046b62ac434dbc796
UP_THRESHOLD="60 80 95"
# Depending on the kernel and the HW sampling rate could be restricted
# and cannot be set that low...
# E.g. before git commit cef9615a853ebc4972084f7 one could only set
# min sampling rate of 80000 if CONFIG_HZ=250
SAMPLING_RATE="20000 80000"
function measure()
{
local -i up_threshold_set
local -i sampling_rate_set
for up_threshold in $UP_THRESHOLD;do
for sampling_rate in $SAMPLING_RATE;do
# Set values in sysfs
echo $up_threshold >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
echo $sampling_rate >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
up_threshold_set=$(cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold)
sampling_rate_set=$(cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate)
# Verify set values in sysfs
if [ ${up_threshold_set} -eq ${up_threshold} ];then
echo "up_threshold: $up_threshold, set in sysfs: ${up_threshold_set}"
else
echo "WARNING: Tried to set up_threshold: $up_threshold, set in sysfs: ${up_threshold_set}"
fi
if [ ${sampling_rate_set} -eq ${sampling_rate} ];then
echo "sampling_rate: $sampling_rate, set in sysfs: ${sampling_rate_set}"
else
echo "WARNING: Tried to set sampling_rate: $sampling_rate, set in sysfs: ${sampling_rate_set}"
fi
# Benchmark
cpufreq-bench -o /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}
done
done
}
function create_plots()
{
local command
for up_threshold in $UP_THRESHOLD;do
command="cpufreq-bench_plot.sh -o \"sampling_rate_${SAMPLING_RATE}_up_threshold_${up_threshold}\" -t \"Ondemand sampling_rate: ${SAMPLING_RATE} comparison - Up_threshold: $up_threshold %\""
for sampling_rate in $SAMPLING_RATE;do
command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"sampling_rate = $sampling_rate\""
done
echo $command
eval "$command"
echo
done
for sampling_rate in $SAMPLING_RATE;do
command="cpufreq-bench_plot.sh -o \"up_threshold_${UP_THRESHOLD}_sampling_rate_${sampling_rate}\" -t \"Ondemand up_threshold: ${UP_THRESHOLD} % comparison - sampling_rate: $sampling_rate\""
for up_threshold in $UP_THRESHOLD;do
command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"up_threshold = $up_threshold\""
done
echo $command
eval "$command"
echo
done
command="cpufreq-bench_plot.sh -o \"up_threshold_${UP_THRESHOLD}_sampling_rate_${SAMPLING_RATE}\" -t \"Ondemand up_threshold: ${UP_THRESHOLD} and sampling_rate ${SAMPLING_RATE} comparison\""
for sampling_rate in $SAMPLING_RATE;do
for up_threshold in $UP_THRESHOLD;do
command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"up_threshold = $up_threshold - sampling_rate = $sampling_rate\""
done
done
echo "$command"
eval "$command"
}
measure
create_plots
\ No newline at end of file
sleep = 50000
load = 50000
cpu = 0
priority = LOW
output = /var/log/cpufreq-bench
sleep_step = 50000
load_step = 50000
cycles = 20
rounds = 40
verbose = 0
governor = ondemand
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include "config.h"
#include "system.h"
#include "benchmark.h"
static struct option long_options[] =
{
{"output", 1, 0, 'o'},
{"sleep", 1, 0, 's'},
{"load", 1, 0, 'l'},
{"verbose", 0, 0, 'v'},
{"cpu", 1, 0, 'c'},
{"governor", 1, 0, 'g'},
{"prio", 1, 0, 'p'},
{"file", 1, 0, 'f'},
{"cycles", 1, 0, 'n'},
{"rounds", 1, 0, 'r'},
{"load-step", 1, 0, 'x'},
{"sleep-step", 1, 0, 'y'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
/*******************************************************************
usage
*******************************************************************/
void usage()
{
printf("usage: ./bench\n");
printf("Options:\n");
printf(" -l, --load=<long int>\t\tinitial load time in us\n");
printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
printf(" -f, --file=<configfile>\t\tconfig file to use\n");
printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
printf(" -h, --help\t\t\t\tPrint this help screen\n");
exit (1);
}
/*******************************************************************
main
*******************************************************************/
int main(int argc, char **argv)
{
int c;
int option_index = 0;
struct config *config = NULL;
config = prepare_default_config();
if (config == NULL)
return EXIT_FAILURE;
while (1) {
c = getopt_long (argc, argv, "hg:o:s:l:vc:p:f:n:r:x:y:",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'o':
if (config->output != NULL)
fclose(config->output);
config->output = prepare_output(optarg);
if (config->output == NULL)
return EXIT_FAILURE;
dprintf("user output path -> %s\n", optarg);
break;
case 's':
sscanf(optarg, "%li", &config->sleep);
dprintf("user sleep time -> %s\n", optarg);
break;
case 'l':
sscanf(optarg, "%li", &config->load);
dprintf("user load time -> %s\n", optarg);
break;
case 'c':
sscanf(optarg, "%u", &config->cpu);
dprintf("user cpu -> %s\n", optarg);
break;
case 'g':
strncpy(config->governor, optarg, 14);
dprintf("user governor -> %s\n", optarg);
break;
case 'p':
if (string_to_prio(optarg) != SCHED_ERR) {
config->prio = string_to_prio(optarg);
dprintf("user prio -> %s\n", optarg);
} else {
if (config != NULL) {
if (config->output != NULL)
fclose(config->output);
free(config);
}
usage();
}
break;
case 'n':
sscanf(optarg, "%u", &config->cycles);
dprintf("user cycles -> %s\n", optarg);
break;
case 'r':
sscanf(optarg, "%u", &config->rounds);
dprintf("user rounds -> %s\n", optarg);
break;
case 'x':
sscanf(optarg, "%li", &config->load_step);
dprintf("user load_step -> %s\n", optarg);
break;
case 'y':
sscanf(optarg, "%li", &config->sleep_step);
dprintf("user sleep_step -> %s\n", optarg);
break;
case 'f':
if (prepare_config(optarg, config))
return EXIT_FAILURE;
break;
case 'v':
config->verbose = 1;
dprintf("verbose output enabled\n");
break;
case 'h':
case '?':
default:
if (config != NULL) {
if (config->output != NULL)
fclose(config->output);
free(config);
}
usage();
}
}
if (config->verbose) {
printf("starting benchmark with parameters:\n");
printf("config:\n\t"
"sleep=%li\n\t"
"load=%li\n\t"
"sleep_step=%li\n\t"
"load_step=%li\n\t"
"cpu=%u\n\t"
"cycles=%u\n\t"
"rounds=%u\n\t"
"governor=%s\n\n",
config->sleep,
config->load,
config->sleep_step,
config->load_step,
config->cpu,
config->cycles,
config->rounds,
config->governor);
}
prepare_user(config);
prepare_system(config);
start_benchmark(config);
if (config->output != stdout)
fclose(config->output);
free(config);
return EXIT_SUCCESS;
}
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <dirent.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "parse.h"
#include "config.h"
/**
* converts priority string to priority
*
* @param str string that represents a scheduler priority
*
* @retval priority
* @retval SCHED_ERR when the priority doesn't exit
**/
enum sched_prio string_to_prio(const char *str)
{
if (strncasecmp("high", str, strlen(str)) == 0)
return SCHED_HIGH;
else if (strncasecmp("default", str, strlen(str)) == 0)
return SCHED_DEFAULT;
else if (strncasecmp("low", str, strlen(str)) == 0)
return SCHED_LOW;
else
return SCHED_ERR;
}
/**
* create and open logfile
*
* @param dir directory in which the logfile should be created
*
* @retval logfile on success
* @retval NULL when the file can't be created
**/
FILE *prepare_output(const char *dirname)
{
FILE *output = NULL;
int len;
char *filename;
struct utsname sysdata;
DIR *dir;
dir = opendir(dirname);
if (dir == NULL) {
if (mkdir(dirname, 0755)) {
perror("mkdir");
fprintf(stderr, "error: Cannot create dir %s\n",
dirname);
return NULL;
}
}
len = strlen(dirname) + 30;
filename = malloc(sizeof(char) * len);
if (uname(&sysdata) == 0) {
len += strlen(sysdata.nodename) + strlen(sysdata.release);
filename = realloc(filename, sizeof(char) * len);
if(filename == NULL) {
perror("realloc");
return NULL;
}
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
dirname, sysdata.nodename, sysdata.release, time(NULL));
} else {
snprintf(filename, len -1, "%s/benchmark_%li.log", dirname, time(NULL));
}
dprintf("logilename: %s\n", filename);
if ((output = fopen(filename, "w+")) == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to open logfile\n");
}
fprintf(stdout, "Logfile: %s\n", filename);
free(filename);
fprintf(output, "#round load sleep performance powersave percentage\n");
return output;
}
/**
* returns the default config
*
* @retval default config on success
* @retval NULL when the output file can't be created
**/
struct config *prepare_default_config()
{
struct config *config = malloc(sizeof(struct config));
dprintf("loading defaults\n");
config->sleep = 500000;
config->load = 500000;
config->sleep_step = 500000;
config->load_step = 500000;
config->cycles = 5;
config->rounds = 50;
config->cpu = 0;
config->prio = SCHED_HIGH;
config->verbose = 0;
strncpy(config->governor, "ondemand", 8);
config->output = stdout;
#ifdef DEFAULT_CONFIG_FILE
if (prepare_config(DEFAULT_CONFIG_FILE, config))
return NULL;
#endif
return config;
}
/**
* parses config file and returns the config to the caller
*
* @param path config file name
*
* @retval 1 on error
* @retval 0 on success
**/
int prepare_config(const char *path, struct config *config)
{
size_t len = 0;
char *opt, *val, *line = NULL;
FILE *configfile = fopen(path, "r");
if (config == NULL) {
fprintf(stderr, "error: config is NULL\n");
return 1;
}
if (configfile == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to read configfile\n");
free(config);
return 1;
}
while (getline(&line, &len, configfile) != -1)
{
if (line[0] == '#' || line[0] == ' ')
continue;
sscanf(line, "%as = %as", &opt, &val);
dprintf("parsing: %s -> %s\n", opt, val);
if (strncmp("sleep", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->sleep);
else if (strncmp("load", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->load);
else if (strncmp("load_step", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->load_step);
else if (strncmp("sleep_step", opt, strlen(opt)) == 0)
sscanf(val, "%li", &config->sleep_step);
else if (strncmp("cycles", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->cycles);
else if (strncmp("rounds", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->rounds);
else if (strncmp("verbose", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->verbose);
else if (strncmp("output", opt, strlen(opt)) == 0)
config->output = prepare_output(val);
else if (strncmp("cpu", opt, strlen(opt)) == 0)
sscanf(val, "%u", &config->cpu);
else if (strncmp("governor", opt, 14) == 0)
strncpy(config->governor, val, 14);
else if (strncmp("priority", opt, strlen(opt)) == 0) {
if (string_to_prio(val) != SCHED_ERR)
config->prio = string_to_prio(val);
}
}
free(line);
free(opt);
free(val);
return 0;
}
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* struct that holds the required config parameters */
struct config
{
long sleep; /* sleep time in µs */
long load; /* load time in µs */
long sleep_step; /* time value which changes the
* sleep time after every round in µs */
long load_step; /* time value which changes the
* load time after every round in µs */
unsigned int cycles; /* calculation cycles with the same sleep/load time */
unsigned int rounds; /* calculation rounds with iterated sleep/load time */
unsigned int cpu; /* cpu for which the affinity is set */
char governor[15]; /* cpufreq governor */
enum sched_prio /* possible scheduler priorities */
{
SCHED_ERR=-1,SCHED_HIGH, SCHED_DEFAULT, SCHED_LOW
} prio;
unsigned int verbose; /* verbose output */
FILE *output; /* logfile */
char *output_filename; /* logfile name, must be freed at the end
if output != NULL and output != stdout*/
};
enum sched_prio string_to_prio(const char *str);
FILE *prepare_output(const char *dir);
int prepare_config(const char *path, struct config *config);
struct config *prepare_default_config();
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sched.h>
#include <cpufreq.h>
#include "config.h"
#include "system.h"
/**
* returns time since epoch in s
*
* @retval time
**/
long long int get_time()
{
struct timeval now;
gettimeofday(&now, NULL);
return (long long int)(now.tv_sec * 1000000LL + now.tv_usec);
}
/**
* sets the cpufreq governor
*
* @param governor cpufreq governor name
* @param cpu cpu for which the governor should be set
*
* @retval 0 on success
* @retval -1 when failed
**/
int set_cpufreq_governor(char *governor, unsigned int cpu)
{
dprintf("set %s as cpufreq governor\n", governor);
if (cpufreq_cpu_exists(cpu) != 0) {
perror("cpufreq_cpu_exists");
fprintf(stderr, "error: cpu %u does not exist\n", cpu);
return -1;
}
if (cpufreq_modify_policy_governor(cpu, governor) != 0) {
perror("cpufreq_modify_policy_governor");
fprintf(stderr, "error: unable to set %s governor\n", governor);
return -1;
}
return 0;
}
/**
* sets cpu affinity for the process
*
* @param cpu cpu# to which the affinity should be set
*
* @retval 0 on success
* @retval -1 when setting the affinity failed
**/
int set_cpu_affinity(unsigned int cpu)
{
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
dprintf("set affinity to cpu #%u\n", cpu);
if (sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset) < 0) {
perror("sched_setaffinity");
fprintf(stderr, "warning: unable to set cpu affinity\n");
return -1;
}
return 0;
}
/**
* sets the process priority parameter
*
* @param priority priority value
*
* @retval 0 on success
* @retval -1 when setting the priority failed
**/
int set_process_priority(int priority)
{
struct sched_param param;
dprintf("set scheduler priority to %i\n", priority);
param.sched_priority = priority;
if (sched_setscheduler(0, SCHEDULER, &param) < 0) {
perror("sched_setscheduler");
fprintf(stderr, "warning: unable to set scheduler priority\n");
return -1;
}
return 0;
}
/**
* notifys the user that the benchmark may run some time
*
* @param config benchmark config values
*
**/
void prepare_user(const struct config *config)
{
unsigned long sleep_time = 0;
unsigned long load_time = 0;
unsigned int round;
for (round = 0; round < config->rounds; round++) {
sleep_time += 2 * config->cycles * (config->sleep + config->sleep_step * round);
load_time += 2 * config->cycles * (config->load + config->load_step * round) + (config->load + config->load_step * round * 4);
}
if (config->verbose || config->output != stdout)
printf("approx. test duration: %im\n",
(int)((sleep_time + load_time) / 60000000));
}
/**
* sets up the cpu affinity and scheduler priority
*
* @param config benchmark config values
*
**/
void prepare_system(const struct config *config)
{
if (config->verbose)
printf("set cpu affinity to cpu #%u\n", config->cpu);
set_cpu_affinity(config->cpu);
switch (config->prio) {
case SCHED_HIGH:
if (config->verbose)
printf("high priority condition requested\n");
set_process_priority(PRIORITY_HIGH);
break;
case SCHED_LOW:
if (config->verbose)
printf("low priority condition requested\n");
set_process_priority(PRIORITY_LOW);
break;
default:
if (config->verbose)
printf("default priority condition requested\n");
set_process_priority(PRIORITY_DEFAULT);
}
}
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "parse.h"
long long get_time();
int set_cpufreq_governor(char *governor, unsigned int cpu);
int set_cpu_affinity(unsigned int cpu);
int set_process_priority(int priority);
void prepare_user(const struct config *config);
void prepare_system(const struct config *config);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment