From 7fe2f6399a84760a9af8896ac152728250f82adb Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 30 Mar 2011 16:30:11 +0200 Subject: 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: Dominik Brodowski --- MAINTAINERS | 6 + tools/power/cpupower/.gitignore | 21 + tools/power/cpupower/AUTHORS | 18 + tools/power/cpupower/COPYING | 340 ++++++++ tools/power/cpupower/Makefile | 273 ++++++ tools/power/cpupower/README | 49 ++ tools/power/cpupower/ToDo | 11 + tools/power/cpupower/bench/Makefile | 30 + tools/power/cpupower/bench/README-BENCH | 124 +++ tools/power/cpupower/bench/benchmark.c | 184 ++++ tools/power/cpupower/bench/benchmark.h | 27 + tools/power/cpupower/bench/config.h | 36 + tools/power/cpupower/bench/cpufreq-bench_plot.sh | 104 +++ tools/power/cpupower/bench/cpufreq-bench_script.sh | 101 +++ tools/power/cpupower/bench/example.cfg | 11 + tools/power/cpupower/bench/main.c | 203 +++++ tools/power/cpupower/bench/parse.c | 224 +++++ tools/power/cpupower/bench/parse.h | 50 ++ tools/power/cpupower/bench/system.c | 188 ++++ tools/power/cpupower/bench/system.h | 29 + tools/power/cpupower/build/ccdv.c | 387 +++++++++ tools/power/cpupower/debug/i386/Makefile | 20 + tools/power/cpupower/debug/i386/centrino-decode.c | 113 +++ tools/power/cpupower/debug/i386/dump_psb.c | 196 +++++ tools/power/cpupower/debug/i386/intel_gsic.c | 78 ++ .../power/cpupower/debug/i386/powernow-k8-decode.c | 96 ++ tools/power/cpupower/debug/kernel/Makefile | 23 + .../power/cpupower/debug/kernel/cpufreq-test_tsc.c | 113 +++ tools/power/cpupower/debug/x86_64/Makefile | 14 + .../power/cpupower/debug/x86_64/centrino-decode.c | 1 + .../cpupower/debug/x86_64/powernow-k8-decode.c | 1 + tools/power/cpupower/lib/cpufreq.c | 190 ++++ tools/power/cpupower/lib/cpufreq.h | 215 +++++ tools/power/cpupower/lib/sysfs.c | 671 ++++++++++++++ tools/power/cpupower/lib/sysfs.h | 21 + tools/power/cpupower/man/cpupower-frequency-info.1 | 76 ++ tools/power/cpupower/man/cpupower-frequency-set.1 | 54 ++ tools/power/cpupower/man/cpupower-info.1 | 19 + tools/power/cpupower/man/cpupower-monitor.1 | 179 ++++ tools/power/cpupower/man/cpupower-set.1 | 103 +++ tools/power/cpupower/man/cpupower.1 | 72 ++ tools/power/cpupower/po/cs.po | 944 ++++++++++++++++++++ tools/power/cpupower/po/de.po | 961 +++++++++++++++++++++ tools/power/cpupower/po/fr.po | 947 ++++++++++++++++++++ tools/power/cpupower/po/it.po | 961 +++++++++++++++++++++ tools/power/cpupower/po/pt.po | 957 ++++++++++++++++++++ tools/power/cpupower/utils/builtin.h | 18 + tools/power/cpupower/utils/cpufreq-info.c | 665 ++++++++++++++ tools/power/cpupower/utils/cpufreq-set.c | 357 ++++++++ tools/power/cpupower/utils/cpuidle-info.c | 245 ++++++ tools/power/cpupower/utils/cpupower-info.c | 154 ++++ tools/power/cpupower/utils/cpupower-set.c | 153 ++++ tools/power/cpupower/utils/cpupower.c | 201 +++++ tools/power/cpupower/utils/helpers/amd.c | 137 +++ tools/power/cpupower/utils/helpers/bitmask.c | 290 +++++++ tools/power/cpupower/utils/helpers/bitmask.h | 33 + tools/power/cpupower/utils/helpers/cpuid.c | 145 ++++ tools/power/cpupower/utils/helpers/helpers.h | 180 ++++ tools/power/cpupower/utils/helpers/misc.c | 34 + tools/power/cpupower/utils/helpers/msr.c | 122 +++ tools/power/cpupower/utils/helpers/pci.c | 44 + tools/power/cpupower/utils/helpers/sysfs.c | 350 ++++++++ tools/power/cpupower/utils/helpers/sysfs.h | 23 + tools/power/cpupower/utils/helpers/topology.c | 108 +++ .../cpupower/utils/idle_monitor/amd_fam14h_idle.c | 340 ++++++++ .../cpupower/utils/idle_monitor/cpuidle_sysfs.c | 185 ++++ .../cpupower/utils/idle_monitor/cpupower-monitor.c | 446 ++++++++++ .../cpupower/utils/idle_monitor/cpupower-monitor.h | 68 ++ .../cpupower/utils/idle_monitor/idle_monitors.def | 7 + .../cpupower/utils/idle_monitor/idle_monitors.h | 18 + .../cpupower/utils/idle_monitor/mperf_monitor.c | 258 ++++++ tools/power/cpupower/utils/idle_monitor/nhm_idle.c | 212 +++++ tools/power/cpupower/utils/idle_monitor/snb_idle.c | 189 ++++ 73 files changed, 14423 insertions(+) create mode 100644 tools/power/cpupower/.gitignore create mode 100644 tools/power/cpupower/AUTHORS create mode 100644 tools/power/cpupower/COPYING create mode 100644 tools/power/cpupower/Makefile create mode 100644 tools/power/cpupower/README create mode 100644 tools/power/cpupower/ToDo create mode 100644 tools/power/cpupower/bench/Makefile create mode 100644 tools/power/cpupower/bench/README-BENCH create mode 100644 tools/power/cpupower/bench/benchmark.c create mode 100644 tools/power/cpupower/bench/benchmark.h create mode 100644 tools/power/cpupower/bench/config.h create mode 100644 tools/power/cpupower/bench/cpufreq-bench_plot.sh create mode 100644 tools/power/cpupower/bench/cpufreq-bench_script.sh create mode 100644 tools/power/cpupower/bench/example.cfg create mode 100644 tools/power/cpupower/bench/main.c create mode 100644 tools/power/cpupower/bench/parse.c create mode 100644 tools/power/cpupower/bench/parse.h create mode 100644 tools/power/cpupower/bench/system.c create mode 100644 tools/power/cpupower/bench/system.h create mode 100644 tools/power/cpupower/build/ccdv.c create mode 100644 tools/power/cpupower/debug/i386/Makefile create mode 100644 tools/power/cpupower/debug/i386/centrino-decode.c create mode 100644 tools/power/cpupower/debug/i386/dump_psb.c create mode 100644 tools/power/cpupower/debug/i386/intel_gsic.c create mode 100644 tools/power/cpupower/debug/i386/powernow-k8-decode.c create mode 100644 tools/power/cpupower/debug/kernel/Makefile create mode 100644 tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c create mode 100644 tools/power/cpupower/debug/x86_64/Makefile create mode 120000 tools/power/cpupower/debug/x86_64/centrino-decode.c create mode 120000 tools/power/cpupower/debug/x86_64/powernow-k8-decode.c create mode 100644 tools/power/cpupower/lib/cpufreq.c create mode 100644 tools/power/cpupower/lib/cpufreq.h create mode 100644 tools/power/cpupower/lib/sysfs.c create mode 100644 tools/power/cpupower/lib/sysfs.h create mode 100644 tools/power/cpupower/man/cpupower-frequency-info.1 create mode 100644 tools/power/cpupower/man/cpupower-frequency-set.1 create mode 100644 tools/power/cpupower/man/cpupower-info.1 create mode 100644 tools/power/cpupower/man/cpupower-monitor.1 create mode 100644 tools/power/cpupower/man/cpupower-set.1 create mode 100644 tools/power/cpupower/man/cpupower.1 create mode 100644 tools/power/cpupower/po/cs.po create mode 100644 tools/power/cpupower/po/de.po create mode 100644 tools/power/cpupower/po/fr.po create mode 100644 tools/power/cpupower/po/it.po create mode 100644 tools/power/cpupower/po/pt.po create mode 100644 tools/power/cpupower/utils/builtin.h create mode 100644 tools/power/cpupower/utils/cpufreq-info.c create mode 100644 tools/power/cpupower/utils/cpufreq-set.c create mode 100644 tools/power/cpupower/utils/cpuidle-info.c create mode 100644 tools/power/cpupower/utils/cpupower-info.c create mode 100644 tools/power/cpupower/utils/cpupower-set.c create mode 100644 tools/power/cpupower/utils/cpupower.c create mode 100644 tools/power/cpupower/utils/helpers/amd.c create mode 100644 tools/power/cpupower/utils/helpers/bitmask.c create mode 100644 tools/power/cpupower/utils/helpers/bitmask.h create mode 100644 tools/power/cpupower/utils/helpers/cpuid.c create mode 100644 tools/power/cpupower/utils/helpers/helpers.h create mode 100644 tools/power/cpupower/utils/helpers/misc.c create mode 100644 tools/power/cpupower/utils/helpers/msr.c create mode 100644 tools/power/cpupower/utils/helpers/pci.c create mode 100644 tools/power/cpupower/utils/helpers/sysfs.c create mode 100644 tools/power/cpupower/utils/helpers/sysfs.h create mode 100644 tools/power/cpupower/utils/helpers/topology.c create mode 100644 tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c create mode 100644 tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c create mode 100644 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c create mode 100644 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h create mode 100644 tools/power/cpupower/utils/idle_monitor/idle_monitors.def create mode 100644 tools/power/cpupower/utils/idle_monitor/idle_monitors.h create mode 100644 tools/power/cpupower/utils/idle_monitor/mperf_monitor.c create mode 100644 tools/power/cpupower/utils/idle_monitor/nhm_idle.c create mode 100644 tools/power/cpupower/utils/idle_monitor/snb_idle.c diff --git a/MAINTAINERS b/MAINTAINERS index 187282da9213..64b919667c53 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 +M: Thomas Renninger +S: Maintained +F: tools/power/cpupower + CPUSETS M: Paul Menage W: http://www.bullopensource.org/cpuset/ diff --git a/tools/power/cpupower/.gitignore b/tools/power/cpupower/.gitignore new file mode 100644 index 000000000000..f8d7b5ac2719 --- /dev/null +++ b/tools/power/cpupower/.gitignore @@ -0,0 +1,21 @@ +.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 diff --git a/tools/power/cpupower/AUTHORS b/tools/power/cpupower/AUTHORS new file mode 100644 index 000000000000..090af2cb81b1 --- /dev/null +++ b/tools/power/cpupower/AUTHORS @@ -0,0 +1,18 @@ +Dominik Brodowski + + +Mattia Dongili +via Latisana, 8 +00177 Rome +Italy + + +Goran Koruga +Slovenia + + +Thomas Renninger +SUSE Linux GmbH +Germany + + diff --git a/tools/power/cpupower/COPYING b/tools/power/cpupower/COPYING new file mode 100644 index 000000000000..d60c31a97a54 --- /dev/null +++ b/tools/power/cpupower/COPYING @@ -0,0 +1,340 @@ + 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. + + + Copyright (C) + + 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. + + , 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. diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile new file mode 100644 index 000000000000..aef1e3b41792 --- /dev/null +++ b/tools/power/cpupower/Makefile @@ -0,0 +1,273 @@ +# Makefile for cpupowerutils +# +# Copyright (C) 2005,2006 Dominik Brodowski +# +# Based largely on the Makefile for udev by: +# +# Copyright (C) 2003,2004 Greg Kroah-Hartman +# +# 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 diff --git a/tools/power/cpupower/README b/tools/power/cpupower/README new file mode 100644 index 000000000000..fd9d4c0d6688 --- /dev/null +++ b/tools/power/cpupower/README @@ -0,0 +1,49 @@ +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 diff --git a/tools/power/cpupower/ToDo b/tools/power/cpupower/ToDo new file mode 100644 index 000000000000..874b78b586ee --- /dev/null +++ b/tools/power/cpupower/ToDo @@ -0,0 +1,11 @@ +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 diff --git a/tools/power/cpupower/bench/Makefile b/tools/power/cpupower/bench/Makefile new file mode 100644 index 000000000000..3d8fa21855f6 --- /dev/null +++ b/tools/power/cpupower/bench/Makefile @@ -0,0 +1,30 @@ +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 diff --git a/tools/power/cpupower/bench/README-BENCH b/tools/power/cpupower/bench/README-BENCH new file mode 100644 index 000000000000..8093ec738170 --- /dev/null +++ b/tools/power/cpupower/bench/README-BENCH @@ -0,0 +1,124 @@ +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= initial load time in us +-s, --sleep= initial sleep time in us +-x, --load-step= time to be added to load time, in us +-y, --sleep-step= time to be added to sleep time, in us +-c, --cpu= CPU Number to use, starting at 0 +-p, --prio= scheduler priority, HIGH, LOW or DEFAULT +-g, --governor= cpufreq governor to test +-n, --cycles= load/sleep cycles to get an avarage value to compare +-r, --rounds load/sleep rounds +-f, --file= config file to use +-o, --output= 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 + diff --git a/tools/power/cpupower/bench/benchmark.c b/tools/power/cpupower/bench/benchmark.c new file mode 100644 index 000000000000..f538633b8b41 --- /dev/null +++ b/tools/power/cpupower/bench/benchmark.c @@ -0,0 +1,184 @@ +/* cpufreq-bench CPUFreq microbenchmark + * + * Copyright (C) 2008 Christian Kornacker + * + * 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 +#include +#include + +#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; + } +} + diff --git a/tools/power/cpupower/bench/benchmark.h b/tools/power/cpupower/bench/benchmark.h new file mode 100644 index 000000000000..0691f91b720b --- /dev/null +++ b/tools/power/cpupower/bench/benchmark.h @@ -0,0 +1,27 @@ +/* cpufreq-bench CPUFreq microbenchmark + * + * Copyright (C) 2008 Christian Kornacker + * + * 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); diff --git a/tools/power/cpupower/bench/config.h b/tools/power/cpupower/bench/config.h new file mode 100644 index 000000000000..9690f1be32fd --- /dev/null +++ b/tools/power/cpupower/bench/config.h @@ -0,0 +1,36 @@ +/* cpufreq-bench CPUFreq microbenchmark + * + * Copyright (C) 2008 Christian Kornacker + * + * 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 + diff --git a/tools/power/cpupower/bench/cpufreq-bench_plot.sh b/tools/power/cpupower/bench/cpufreq-bench_plot.sh new file mode 100644 index 000000000000..410021a12f40 --- /dev/null +++ b/tools/power/cpupower/bench/cpufreq-bench_plot.sh @@ -0,0 +1,104 @@ +#!/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 , 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 diff --git a/tools/power/cpupower/bench/cpufreq-bench_script.sh b/tools/power/cpupower/bench/cpufreq-bench_script.sh new file mode 100644 index 000000000000..de20d2a06879 --- /dev/null +++ b/tools/power/cpupower/bench/cpufreq-bench_script.sh @@ -0,0 +1,101 @@ +#!/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 , 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 diff --git a/tools/power/cpupower/bench/example.cfg b/tools/power/cpupower/bench/example.cfg new file mode 100644 index 000000000000..f91f64360688 --- /dev/null +++ b/tools/power/cpupower/bench/example.cfg @@ -0,0 +1,11 @@ +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 diff --git a/tools/power/cpupower/bench/main.c b/tools/power/cpupower/bench/main.c new file mod