├── LICENSE ├── Makefile ├── README ├── README.md ├── api ├── Makefile ├── xfreq-api.c ├── xfreq-api.h ├── xfreq-smbios.c ├── xfreq-smbios.h └── xfreq-types.h ├── cli ├── Makefile ├── XFreq-Cli-FreeBSD.cbp ├── XFreq-Cli.cbp ├── xfreq-cli.c └── xfreq-cli.h ├── gui ├── Makefile ├── XFreq-Gui-FreeBSD.cbp ├── XFreq-Gui.cbp ├── xfreq-gui.c └── xfreq-gui.h └── svr ├── Makefile ├── XFreq-Intel-FreeBSD.cbp ├── XFreq-Intel.cbp ├── xfreq-intel.c ├── xfreq-intel.h └── xfreq-intel.service /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | export CC 2 | APP_NAME=xfreq-api xfreq-intel xfreq-gui xfreq-cli 3 | # 4 | all : $(APP_NAME) 5 | # 6 | help : 7 | @echo 'make [all] : Compile and link files {'$(APP_NAME)'}' 8 | @echo 'make clean[-all] : Remove object and binary sub-directories.' 9 | # 10 | xfreq-api: 11 | $(MAKE) -C api 12 | xfreq-intel : 13 | $(MAKE) -C svr 14 | xfreq-gui : 15 | $(MAKE) -C gui 16 | xfreq-cli : 17 | $(MAKE) -C cli 18 | # 19 | clean: 20 | @echo 'Cleaning ...' 21 | $(MAKE) clean -C api 22 | $(MAKE) clean -C svr 23 | $(MAKE) clean -C gui 24 | $(MAKE) clean -C cli 25 | # 26 | clean-all: 27 | @echo 'Cleaning all ...' 28 | $(MAKE) clean-all -C api 29 | $(MAKE) clean-all -C svr 30 | $(MAKE) clean-all -C gui 31 | $(MAKE) clean-all -C cli 32 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | /* 2 | * XFreq by CyrIng 3 | * 4 | * 5 | * [PURPOSE] 6 | * 7 | * XFreq provides some Widgets to display the frequency (including turbo boost), the temperature, C-States and other features of the Intel Core i7, i5 processors. 8 | * It also works with Core 2 architectures. 9 | * 10 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 11 | * http://blog.cyring.fr 12 | * 13 | * Licenses: GPL2 14 | * 15 | * 16 | * 17 | * [BUILD] 18 | * 19 | * 1- download the source code into a working directory 20 | * 21 | * Makefile 22 | * api/Makefile 23 | * api/xfreq-api.c 24 | * api/xfreq-api.h 25 | * api/xfreq-smbios.c 26 | * api/xfreq-smbios.h 27 | * api/xfreq-types.h 28 | * cli/Makefile 29 | * cli/xfreq-cli.c 30 | * cli/xfreq-cli.h 31 | * gui/Makefile 32 | * gui/xfreq-gui.c 33 | * gui/xfreq-gui.h 34 | * svr/Makefile 35 | * svr/xfreq-intel.c 36 | * svr/xfreq-intel.h 37 | * 38 | * 39 | * 2- compile the source code 40 | * 41 | * make -j 1 42 | * 43 | * 44 | * 3- the following output will be displayed 45 | * 46 | * make -C api 47 | * make[1]: Entering directory './api' 48 | * cc -D`uname -s` -Wall -x c -c xfreq-api.c -I . -o ./obj/xfreq-api.o 49 | * cc -D`uname -s` -Wall -x c -c xfreq-smbios.c -I . -o ./obj/xfreq-smbios.o 50 | * make[1]: Leaving directory './api' 51 | * make -C svr 52 | * make[1]: Entering directory './svr' 53 | * cc -D`uname -s` -Wall -pthread -x c -c xfreq-intel.c -I ../api -o ./obj/xfreq-intel.o 54 | * cc ./obj/xfreq-intel.o -lpthread -lrt ../api/obj/xfreq-api.o ../api/obj/xfreq-smbios.o -o ./bin/xfreq-intel 55 | * make[1]: Leaving directory './svr' 56 | * make -C gui 57 | * make[1]: Entering directory './gui' 58 | * cc -D`uname -s` -Wall -pthread -x c -c xfreq-gui.c -I ../api -o ./obj/xfreq-gui.o 59 | * cc ./obj/xfreq-gui.o -lX11 -lpthread -lrt ../api/obj/xfreq-api.o -o ./bin/xfreq-gui 60 | * make[1]: Leaving directory './gui' 61 | * make -C cli 62 | * make[1]: Entering directory './cli' 63 | * cc -D`uname -s` -Wall -pthread -x c -c xfreq-cli.c -I ../api -o ./obj/xfreq-cli.o 64 | * cc ./obj/xfreq-cli.o -lpthread -lrt ../api/obj/xfreq-api.o -o ./bin/xfreq-cli 65 | * make[1]: Leaving directory './cli' 66 | * 67 | * 68 | * 4- depending of your packages distribution, the libraries required to compile the source code are the following 69 | * 70 | * XLIB developer (libX11) 71 | * 72 | * POSIX threads (pthreads) 73 | * 74 | * 75 | * 76 | * [RUN] 77 | * 78 | * 1- the following kernel modules and file systems are prerequisites to run XFreq 79 | * 80 | * +---------------------------+-----------+--------------------------------------+ 81 | * | msr.ko | mandatory | model specific registers driver (1) | 82 | * +---------------------------+-----------+--------------------------------------+ 83 | * | dmi-sysfs.ko | optional | DMI tables driver (2) | 84 | * +---------------------------+-----------+--------------------------------------+ 85 | * | acpi-cpufreq.ko | optional | ACPI Processor P-States driver | 86 | * +---------------------------+-----------+--------------------------------------+ 87 | * | /proc/sched_debug | optional | reference: kernel/sched/debug.c | 88 | * +---------------------------+-----------+--------------------------------------+ 89 | * | /proc//* | optional | reference: linux/fs/proc/base.c | 90 | * +---------------------------+-----------+--------------------------------------+ 91 | * | iopl | optional | change I/O privilege level | 92 | * +---------------------------+-----------+--------------------------------------+ 93 | * 94 | * 95 | * 2- as root, start the XFreq server. 96 | * 97 | * ./svr/bin/xfreq-intel 98 | * 99 | * 100 | * 3- as a regular user, start one of the XFreq clients (GUI, console) 101 | * 102 | * ./gui/bin/xfreq-gui 103 | * 104 | * ./cli/bin/xfreq-cli 105 | * 106 | * 107 | * 108 | * [TESTBED] 109 | * 110 | * +-------------------+---------------------------+--------+-------+---------+ 111 | * | Intel Processors | System [Desktop/Laptop] | Status | Date | Release | 112 | * +-------------------+---------------------------+--------+-------+---------+ 113 | * | Core i7-920 | Asus Rampage II Gene [D] | OK |Nightly| Nightly | 114 | * +-------------------+---------------------------+--------+-------+---------+ 115 | * | Core 2 Duo T5500 | Acer Aspire 5633 [L] | OK | 04/30 | 0.25-2 | 116 | * +-------------------+---------------------------+--------+-------+---------+ 117 | * + Core 2 Quad Q8200 | Unknown [L] | OK | 05/02 + 0.25-2 | 118 | * +-------------------+---------------------------+--------+-------+---------+ 119 | * 120 | * 121 | * 122 | * [ISSUES] 123 | * 124 | * + The temperature thresholds MSR does not return any value. 125 | * Need to investigate ACPI. 126 | * 127 | * + Fast-Strings reported as not available in CPUID but enabled in MSR. 128 | * 129 | * + The RAM timings are wrong when running with FreeBSD. 130 | * 131 | * 132 | * 133 | * [TODO] 134 | * 135 | * Hardware 136 | * ---------- 137 | * 138 | * + power energy performance counters : Postponed. 139 | * 140 | * + kernel module : to reduce cpu usage near to 0.01% : Merge with CoreFreq Linux driver. 141 | * 142 | * + memory fetch : to remove dependancies with the dmi_sysfs & msr Linux modules : Canceled. 143 | * using a R/O mmap to "/dev/mem". 144 | * rather use the msr assembler instruction. 145 | * 146 | * + GPU sensors. 147 | * compile with the NVIDIA (first), the AMD & Intel frameworks (seconds) : Postponed. 148 | * 149 | * + scripting, editor, push alarms : write user defined bit values in MSR : Terminated. 150 | * 151 | * 152 | * Graphical 153 | * ----------- 154 | * 155 | * + power energy Widget using a slider to: 156 | * select a Policy Preference in IA32_ENERGY_PERF_BIAS , MSR_MISC_PWR_MGMT(0x1aa), 157 | * set On-Demand Clock Modulation in IA32_CLOCK_MODULATION(0x19a) (duplicated for each Thread), 158 | * enable / disable C1E in MSR_POWER_CTL(0x1fc): Done, 159 | * C-State auto demotion with MSR_PKG_CST_CONFIG_CONTROL(0xe2): Done. 160 | * + some button-switchs & sliders to enable/disable/set the PKG/Core features in the System Info Widget. 161 | * + resize footer separator w/ MDI : Postponed. 162 | * 163 | * 164 | * Source code 165 | * ------------- 166 | * + provide some configure and install scripts, 167 | * ArchLinux PKGBUILD : Done. 168 | * FreeBSD port: Partial. 169 | * 170 | * 171 | * [HISTORY] 172 | * 173 | * R 2.1.65 : 12/28/2015 174 | * - GUI: added the screenshot of the focused widget w/ [Ctrl]+[s] 175 | * and the command argument '-S' to specify the output path. 176 | * 177 | * R 2.1.64 : 12/27/2015 178 | * - GUI: Fix colors mgnt. 179 | * 180 | * R 2.1.63 : 12/25/2015 181 | * - GUI: Font mgnt improved. 182 | * 183 | * R 2.1.62 : 12/23/2015 184 | * - Bug fixes 185 | * 186 | * R 2.1.61 : 12/21/2015 187 | * - GUI: improved management of colors and fonts. 188 | * 189 | * R 2.1.60 : 12/11/2015 190 | * - GUI: geometry is able of such position -0-0 191 | * 192 | * R 2.1.59 : 11/28/2015 193 | * - GUI: improved the geometry option. 194 | * 195 | * R 2.1.58 : 11/14/2015 196 | * - Caches topology. 197 | * 198 | * R 2.1.57 : 10/17/2015 199 | * - GUI: fixed warning [-Wlogical-not-parentheses] 200 | * 201 | * R 2.1.55 : 09/13/2015 202 | * - Core2/Conroe/Yonah architecture added into database. 203 | * 204 | * R 2.1.54 : 09/12/2015 205 | * - Architectures added into database: 206 | * Atom_Airmont, Atom_Goldmont, Atom_Sofia, Atom_Merrifield, Atom_Moorefield, 207 | * Broadwell, Broadwell_EP, Broadwell_H, Broadwell_EX, 208 | * Skylake_UY, Skylake_S, Skylake_E 209 | * - Default Atom base clock speed set to 100 MHz 210 | * 211 | * R 2.1.53-a: 07/13/2015 212 | * - Fixed C7 average. 213 | * - Fixed offline Cores in the TEMPS widget. 214 | * - Left aligned topology list in the SYSINFO widget. 215 | * 216 | * R 2.1.52: 05/16/2015 217 | * - Bit set calculator. 218 | * 219 | * R 2.1.51-a: 03/21/2015 220 | * - Centered the header of the CORE widget. 221 | * 222 | * R 2.1.51: 03/21/2015 223 | * - Fixed angles in XDrawArc(). 224 | * - Allow to redraw the SYSINFO widget with a [Refresh] button. 225 | * - Changed the [Pause] button to a Decoration button. 226 | * - Red theme. 227 | * - Added Operating System data in the SYSINFO widget. 228 | * - Redefined the footer in the CSTATES widget. 229 | * 230 | * R 2.1.50: 03/16/2015 231 | * - New '-B' argument to enable SmBIOS. (default is disable in the server). 232 | * - Redesigned the System Information as a tree. 233 | * - Added C-States Auto Demotion & UnDemotion states into the SysInfo widget. 234 | * 235 | * R 2.1.49: 03/15/2015 236 | * - Added Performance Monitoring details into the SYSINFO widget. 237 | * - Implemented the CPUID MONITOR MWAIT Leaf. 238 | * - Allow to enable, disable C3 and C1 auto demotion. 239 | * - Enhanced the DUMP Widget w/ a list of MSR names. 240 | * 241 | * R 2.1.48-b: 03/08/2015 242 | * - Because of FreeBSD, sscanf("%ms") are changed to "%s" 243 | * - Modified the header in xfreq-cli 244 | * 245 | * R 2.1.48-a: 03/07/2015 246 | * - Server: realigned the sched_debug parsing. 247 | * - GUI: insufficient memory allocation storage fixed. 248 | * 249 | * R 2.1.48: 03/07/2015 250 | * - Added header strings in CORE Widget. 251 | * - Increase the MSR address field length in DUMP Widget. 252 | * - Implemented the C7 state in Sandy Bridge and above. (remain ZERO with others). 253 | * - Implemented the INST counter in Core architecture. 254 | * 255 | * R 2.1.47-a: 03/05/2015 256 | * - Corrected IPC & CPI formulas using Non-halted reference cycles [URC] counter. 257 | * 258 | * R 2.1.47: 03/01/2015 259 | * - Fixed few GUI issues and README file. 260 | * - New counters & ratios outputs are available in xfreq-cli. 261 | * - Added 3 performance ratios: 262 | * IPS (Instructions Per Second), 263 | * IPC (Instructions Per Cycle), 264 | * CPI (Cycles Per Instruction), 265 | * - Programmed the Instructions Retired counter. (Nehalem and above) 266 | * 267 | * R 2.1.46: 02/21/2015 268 | * - Derive C1 state from others. 269 | * - 64-bit Aux TSC can be now selected as a source to estimate clock frequency. 270 | * 271 | * R 2.1.45: 02/15/2015 272 | * - Added new commands to "safely" enable, disable: 273 | * EIST, 274 | * C1E, 275 | * TCC 276 | * 277 | * R 2.1.44-c: 02/14/2015 278 | * - If MDI, fixed the buttons flashing color. 279 | * - Added the Widget number in the geometry string option. 280 | * - Changed the default Widgets layout to fit a 1280x1024 screen resolution. 281 | * - The MSR dump Widget now defaults to non pageable. 282 | * 283 | * R 2.1.44-b: 02/09/2015 284 | * - Fixed the buttons flashing color. 285 | * 286 | * R 2.1.44-a: 02/08/2015 287 | * - The SysInfo refresh is more complete. 288 | * - Commands lexicon changed to 'enable', 'disable' future features. 289 | * 290 | * R 2.1.44: 02/07/2015 291 | * - Added new commands to engage, disengage processor features: 292 | * turbo 293 | * 294 | * R 2.1.43-d: 02/01/2015 295 | * - Fixed the MDI. 296 | * - Refreshing the SysInfo Widget with [Ctrl]+[l] updates the msr in the Server. 297 | * 298 | * R 2.1.43-c: 01/31/2015 299 | * - Added the serial # of the Motherboard in the SysInfo Widget. 300 | * - Fixed the GUI synchronism with data returned by Server. 301 | * - The History substitution is now activated by the [F12] key. 302 | * - Enhanced the command line and its cursor. 303 | * - Reverted changes to the Turbo Boost status: bit 38: 1=disable , 0=enable 304 | * 305 | * R 2.1.43-b: 01/30/2015 306 | * - Fixed history & command line expansion; keys mgnt; menu. 307 | * 308 | * R 2.1.43-a: 01/29/2015 309 | * - Keys management enhanced. 310 | * - Fixed the Turbo Boost status. 311 | * 312 | * R 2.1.43: 01/28/2015 313 | * - Provide an history of commands. 314 | * - Added keys to the commands menu. 315 | * - Added commands to read and write msr. 316 | * - Added a command to change the msr dump array and the associated Core. 317 | * - Resize the Widgets. 318 | * - Fixed the C-state averages with the online CPU count. 319 | * 320 | * R 2.1.42-b: 01/20/2015 321 | * - Now trace errors if compiled with DEBUG. 322 | * 323 | * R 2.1.42-a: 01/19/2015 324 | * - Fixed boolean command line arguments. 325 | * - Limit to one job the build process. 326 | * 327 | * R 2.1.42: 01/16/2015 328 | * - Integrated SmBIOS using a fixed shared memory. 329 | * 330 | * R 2.1.41-b: 01/04/2015 331 | * - Fixed threads synchronism timeout. 332 | * - Provided a global Makefile. 333 | * - Copied the frequency values​​ of the Atom from the Kernel source code. 334 | * 335 | * R 2.1.41-a: 01/03/2015 336 | * - Preserve the MSR Counters in a Save Area. 337 | * - Apply an atomic variable to server requests. 338 | * 339 | * R 2.1.41: 01/01/2015 340 | * - Allow up to 64 clients 341 | * - Fixed 64 bits atomic var. 342 | * 343 | * R 2.1.40: 12/28/2014 344 | * - Threads synchronism is now managed with atomics variables. 345 | * - Ported to FreeBSD. 346 | * 347 | * R 0.37 : 07/20/2014 348 | * - Adding commands: 349 | * get & set colors. 350 | * - Allow to use numpad keys. 351 | * 352 | * R 0.36 : 07/14/2014 353 | * - Display the Thermal Monitor activated state. 354 | * - Fixed the buttons state. 355 | * 356 | * R 0.35 : 07/06/2014 357 | * - Highlight buttons depending on state. 358 | * 359 | * R 0.34 : 07/05/2014 360 | * - Added Thread buttons in the TEMP Widget to draw or not discrete temperature. 361 | * 362 | * R 0.33 : 06/26/2014 363 | * - Draw the temperature per logical core. 364 | * 365 | * R 0.32 : 06/09/2014 366 | * - New flags added to the System Information Widget: 367 | * SYSCALL/SYSRET instructions enabled 368 | * MTRR Default Type enabled 369 | * 370 | * R 0.31 : 06/04/2014 [unpublished] 371 | * - XFreq for X11 is renamed to XFreq-Gui: 372 | * it has been ported to the SHM and since runs with the regular user permissions. 373 | * - Create a client as a code template. XFreq-Cli is a text mode client. 374 | * - The XFreq-Intel server is the only process which now requires the root permissions. 375 | * - Synchronization of the SHM using mutex and condition wait. 376 | * 377 | * R 0.30 : 05/29/2014 [unpublished] 378 | * - Split the code into Client/Server. 379 | * - Create a shared memory. 380 | * - Un/serialize the data into the SHM. 381 | * 382 | * R 0.29 : 05/28/2014 [unpublished] 383 | * - Mutex correction before rewriting the all part of the asynchronism. 384 | * - Enhanced the Help banner. 385 | * 386 | * R 0.28 : 05/26/2014 SR-1 [RC1] 387 | * - Fixed some typos. 388 | * 389 | * R 0.28 : 05/26/2014 SR-0 390 | * - Added the '-v' option to print the version number. 391 | * - Enhanced the '-i' option with a Splash attributes argument which allows to hide the Window and to defer the startup time. 392 | * - Changed the bit field tests to avoid a potential stack overflow. 393 | * 394 | * R 0.27 : 05/24/2014 SR-2 395 | * - While reinforcing integer data type variables, then scanning for errors with Valgrind, raised a duplicated definition of 'Status' 396 | * with the header file X11/Xlib.h. Thus in the THERM_STATUS structure, the field has been renamed to 'StatusBit'. 397 | * 398 | * R 0.27 : 05/22/2014 SR-1 399 | * - Fix: pointer to configFile and scanning options. 400 | * - Fix: adjust space between task names when reverse sorting. 401 | * - Fix: startup of task monitoring from settings file if no field defined. 402 | * 403 | * R 0.27 : 05/21/2014 404 | * - Swap the arguments '-x' and '-a' associated with the option to disable the X ACL. 405 | * - Recode the Widgets layout using geometries. 406 | * use the option -g '[cols]x[rows]+[x]+[y], .. ,[cols]x[rows]+[x]+[y]' 407 | * - Swap the arguments '-y', '-l' (Show the Core cycles) and '-g' (Fill the graphics). 408 | * - Removed the '-x' and '-y' arguments which were used to set the initial position of the MAIN Widget. 409 | * - Allow to sort the task monitoring using the '-t' option followed by the field number. 410 | * argument is like 0x{R}0{N} from [0x000 / 0x101 .. 0x10b] 411 | * where {R} to reverse sorting and {N} is the field number in the /proc/sched_debug file. 412 | * 413 | * R 0.26 : 05/15/2014 SR-2 414 | * - Display tasks with the highest execution time. 415 | * 416 | * R 0.26 : 05/10/2014 417 | * - Simplify the Task Scheduler Monitoring thread to process only one file: "/proc/sched_debug" 418 | * 419 | * R 0.25 : 05/07/2014 SR-4 420 | * - The feature 'Always on top' is implemented by invoking the Window Manager. 421 | * - Widgets can be skipped from the WM taskbar using the option '-N' 422 | * - The Window Manager decorations can be removed using the option '-n' 423 | * - Added an icon to all windows, including the Splash one. 424 | * - Fix the missing application class and title name required by the Gnome 3 task bar. 425 | * - Fix "XIO: fatal IO error 11 ..." 426 | * - After moving a paused Widget the Cursor is restored to its previous shape. 427 | * - The MAIN Widget is the only window which buffers the input keys. 428 | * 429 | * R 0.25 : 05/01/2014 SR-3 430 | * - Written more details into the README file. 431 | * - Fix few errors mentioned by Valgrind -;) 432 | * - Fix some command line arguments: 433 | * '-t' was a duplicate and has been replaced by '-o' to keep Widgets always on top; 434 | * '-t' to boot the task scheduling monitor is now correctly saved into the settings file. 435 | * 436 | * R 0.25 : 04/30/2014 SR-2 437 | * - When pressed, flash buttons with the COLOR_PULSE during a usleep of 50000. 438 | * could be enhanced with a dedicated pixmap loop running its own thread. 439 | * - Changed the default RGB value of _COLOR_GRAPH1 to 0xadadff , _COLOR_GRAPH2 to 0x50508a and _COLOR_GRAPH3 to 0x515172 440 | * - With the none filled graphic mode activated: 441 | * added the PID number instead of the ratio value if the [Ratio] button is pressed; 442 | * modified the disposal and the scalling of the task command names; 443 | * fix the text foreground color inside the Core usage rectangles. 444 | * 445 | * R 0.25 : 04/29/2014 SR-1 446 | * - In the Core Widget, a button allows to switch graphic mode between filled or not. 447 | * - Prints some perror(). 448 | * - Outputs a warning if file '/proc/sched_debug' cannot be opened. 449 | * 450 | * R 0.25 : 04/28/2014 451 | * - Display the Task Scheduling in the Core Widget. 452 | * start XFreq with the '-t' argument or click the [Task] button, 453 | * then adjust the polling loop with buttons [+] and [-] 454 | * 455 | * R 0.24 : 04/25/2014 456 | * - Added 2 arguments: 457 | * '-C' to load and store settings from an alternate configuration file. 458 | * '-U' with a bitmask of unmap Widgets. 459 | * 460 | * R 0.23 : 04/03/2014 SR-4 461 | * - Store all Ratios in a Boost array which is also display at the section Boost of the Widget SysInfo. 462 | * - Change the Code::Blocks project to be like the Makefile. Thus 'xfreq' is the only binary produced. 463 | * - Check if an invariant TSC is available and display result in the SysInfo Widget. 464 | * - Fixed some major memory leak. 465 | * pthread : OK 466 | * font : OK 467 | * display : OK 468 | * xrm database : still an issue 469 | * - Change the argument '-h' to '-z' to show the frequencies in the Core Widget. the menu key is modified the same way. 470 | * - Change the architecture detection to handle the processors of generation Core and above. 471 | * So far, 3 arlgorithms are implemented in the following functions. 472 | * uCycle_GenuineIntel(): C0 state only. Based on MSR IA32_APERF / IA32_MPERF 473 | * uCycle_Core() : C0 state only. Based on MSR IA32_FIXED_CTR1 / IA32_FIXED_CTR2 474 | * uCycle_Nehalem() : C0, C3, C6 states. Based on the fixed counters. 475 | * 476 | * R 0.23 : 03/30 2014 SR-3 477 | * - Added an emergency exit function if a POSIX signal is caught. 478 | * 479 | * R 0.23 : 03/29 2014 SR-2 480 | * - For any disable CPU: 481 | * fixed the chart drawing in the CStates Widget 482 | * change some texts in the SysInfo Widget. 483 | * - Auto adjusting the width of the Widgets & the positions of Ratios & Temps values. 484 | * 485 | * R 0.23 : 03/28 2014 SR-1 486 | * - Added the '-A' program argument to dump the list of compiled Architectures. 487 | * - Fixed an infinite loop in uReadAPIC() which locks when processing with Core2 architectures. 488 | * 489 | * R 0.23 : 03/27 2014 490 | * - Added the '-c' program argument to force specifications of another architecture. 491 | * - Redefined the Architecture table to allow the addition of other Processors and their associated processing loop, 492 | * 493 | * R 0.22 : 03/26 2014 SR-5 494 | * - Fixed a bug in uLoop() if G >= WIDGETS. 495 | * 496 | * R 0.22 : 03/25 2014 SR-4 497 | * - Save & load colors from the settings file. 498 | * 499 | * R 0.22 : 03/24 2014 SR-3 500 | * - Save settings into the '.xfreq' file in home directory. 501 | * 502 | * R 0.22 : 03/23 2014 SR-2 503 | * - Load settings from .xfreq file in home directory. 504 | * - Provid a new button to Reset the coldest temperature. 505 | * - Added the '-i' command line argument to hide the Splash screen. 506 | * - Fixed margins when in non MDI. 507 | * - Fixed the scale of the Cold Temperature. 508 | * 509 | * R 0.22 : 03/20 2014 SR-1 510 | * - Fixed the Splash startup. 511 | * 512 | * R 0.22 : 03/19 2014 513 | * - The initial disposal of the Widgets is corrected. 514 | * - Change the scale of the temperature graphic. 515 | * - Added a splash screen during the initialization. 516 | * - Postponed the Thermal thresholds treatment. 517 | * - Display the followings into the System Info Widget: 518 | * Hardware Lock Elision (HLE) 519 | * Restricted Transactional Memory (RTE) 520 | * All Turbo Boost Ratios 521 | * BM1 / BM2 522 | * Topology & State of CPU 523 | * Performance Counters matrix 524 | * - Removed the '-c' (per Core) argument. 525 | * AnyThread Counters are now automatically set just after the Processor topology enumeration function. 526 | * 527 | * R 0.21 : 03/15 2014 SR-2 528 | * - Allows to read the Base Clock frequency at a user's specified address in ROM memory. 529 | * use the new command line argument '-M' 530 | * defaults to 0xf08d9 + 0x12 which is the ASUS Rampage II GENE motherboard address. 531 | * 532 | * R 0.21 : 03/14 2014 SR-1 533 | * - Fix the Topology algorithm to get a list of enabled CPU and show if HTT is enabled. 534 | * - Fix a Graphic regression in the Widget Temperature. Now displays the coldest value. 535 | * 536 | * R 0.21 : 03/12 2014 537 | * - Implemented an enumeration of the Processor topology to get a list of the activated Threads and Cores; 538 | * and conclude if Hyperthreading is actually enabled. 539 | * 540 | * R 0.20 : 03/07 2014 541 | * - Provide an option to select the Clock source between the TSC, BIOS, Specifications, ROM, and an user defined value. 542 | * Use the '-S' command line argument or one of the buttons in the System Info Widget. 543 | * The current source is displayed beside the Base Clock. 544 | * 545 | * R 0.19 : 03/06 2014 SR-2 546 | * - Added a new Quit decoration button. 547 | * - Modified the Minimize decoration button. 548 | * - Fix the scrolling boundaries & the icon names updates. 549 | * 550 | * R 0.19 : 03/05 2014 SR-1 551 | * - Fix the icons size & position. 552 | * - To get a smoother motion, the Scrolling code has been reprogrammed using an additional pixmap. 553 | * 554 | * R 0.19 : 03/01 2014 555 | * - Allow the Widget title to be still refreshed when the window is minimized, iconified or paused. 556 | * By the way, when MDI is enabled, the title of the main window is updated with the top frequency & temperature. 557 | * - Solved the Widgets moving issue using the 'ConfigureNotify' event. 558 | * However the top frame border added by the WM is not counted in the Window position. 559 | * 560 | * R 0.18 : 02/27 2014 SR-3 561 | * - Kernel NMI Watchdog must be disabled because it interferes XFreq when reading UNC & URC counters. 562 | * to disable the watchdog, append the Kernel parameter nmi_watchdog=0 563 | * or into Shell, echo "0" > /proc/sys/kernel/nmi_watchdog before starting XFreq. 564 | * 565 | * - The semaphore locks the drawing thread when increasing, decreasing the loop idle time. 566 | * - The loop idle time is displayed in the System Info Widget. 567 | * - The Processor Brand name is now shown beside the System Info title : 568 | * a new button [Brand] starts and stops this wallboard. 569 | * - An new argument "-a" is provided to enable or disable X Access Control List". 570 | * 571 | * R 0.18 : 02/26 2014 SR-2 572 | * - The decoration is now put on the top-right corner. 573 | * - A message is output when Counters are reset. 574 | * 575 | * R 0.18 : 02/24 2014 SR-1 576 | * - In case of counters overflowed, reset them. 577 | * - In the System Info Widget, two buttons are added to increase, decrease the sleep time. 578 | * - A "ReClock" button in the System Info Widget allows to re-estimate the Base Clock. 579 | * - The Mouse Cursors are implemented. 580 | * - Moving the Widgets is managed in both cases, with or without the MDI mode. 581 | * Thus, no Window Manager is required. Use right mouse button to move a Widget. 582 | * 583 | * R 0.17 : 02/22 2014 SR-5 584 | * - Clean up some code. 585 | * - Added to System Info Widget the CPUID functions : 586 | * leaf (0x6) Digital Thermal Sensor & Power Management 587 | * leaf (0x7) Extended Feature Flags 588 | * leaf (0xa) Performance Monitoring 589 | * 590 | * R 0.17 : 02/20 2014 SR-4 591 | * - Display Ratio formula : 592 | * 593 | * DisplayRatio=TurboRatio x State(C0) * MaxNonTurboRatio 594 | * where 595 | * TurboRatio=Delta(UCC) / Delta(URC) 596 | * and State(C0)=Delta(URC) / Delta(TSC) 597 | * and MaxNonTurboRatio=MSR_PLATFORM_INFO[15-8] 598 | * 599 | * R 0.17 : 02/18 2014 SR-3 600 | * - In Cycles calculation, test for 64 bits overflow. 601 | * 602 | * R 0.17 : 02/16 2014 SR-2 603 | * - Added Decoration buttons. 604 | * - Highlight button when clicked. 605 | * 606 | * R 0.17 : 02/15 2014 SR-1 607 | * - Corrected the Turbo ratio calculation. 608 | * - A Core frequency is displayed when the ratio is greater or equal 5 609 | * - A minimized Widget has an associated icon button in the Main Widget right bar. 610 | * - Cycle and C-State options are now dissociated. 611 | * 612 | * R 0.16 : 02/12 2014 SR-5 613 | * - Registers Dump Widget is now auto refreshed. 614 | * - [CTRL]+[P] or startup option '-p 1'prints the following : 615 | * Raw Cycles values in the Core Widget. 616 | * C-States % in its own Widget. 617 | * - In the System Info Widget the Base Clock frequency is now printed below the Processor brand string. 618 | * 619 | * R 0.16 : 02/11 2014 SR-4 620 | * - In main() provide a none stop program startup and log any missing prerequisites. 621 | * - Modified Ratio & Frequency computation to Relative values. 622 | * 623 | * R 0.16 : 02/10 2014 SR-3 624 | * - A few scripting commands are implemented. 625 | * - The mouse is supported for some functions such as scrolling buttons and moving Widget. 626 | * - Rolling back to an unique input buffer located in the MAIN Widget: 627 | * some option keys need to be pressed with the [Control] key. 628 | * - Simplify all code using macros: 629 | * [Quarter][Half][One][Twice][Twice_Half]_Char_Width 630 | * [Quarter][Half][One][Twice][Twice_Half]_Char_Height 631 | * 632 | * R 0.16 : 02/01 2014 SR-2 633 | * - Implemented a global handling of input characters string. 634 | * 635 | * R 0.16 : 01/31 2014 SR-1 636 | * - Added a new Widget to dump MSR registers in binary. 637 | * 638 | * R 0.16 : 01/29 2014 639 | * - Read the TSC per logical Core using IA32_TIME_STAMP_COUNTER(0x10) rather than RDTSC instruction. 640 | * - Integrate the Misc Processor Features into the System Info Widget. See IA32_MISC_ENABLE(0x1a0). 641 | * - Attempt to handle the temperature Threshold values with IA32_THERM_INTERRUPT(0x19b) : no data ! 642 | * 643 | * R 0.15 : 01/28 2014 SR-4 644 | * - Reorganized the time critical part in the uCycle thread. 645 | * - Reduced the CPU overhead in Events loop and the Drawing thread. 646 | * 647 | * R 0.15 : 01/24 2014 SR-3 648 | * - Cosmetic changes with the MDI window. Use '-D 1' to enable the MDI. 649 | * - Minimizing or unmapping a widget stops its drawing. 650 | * - The command argument '-D' enables the Multiple Document Interface management mode. 651 | * - The Widgets are now gracefully disposed. 652 | * - Added an architecture table with default processors values. 653 | * - Implemented the C3 and C6 C-States counters. 654 | * - Create 2 new Widgets: 655 | * C-States per Core and in Processor average. 656 | * Temperature per Core and hottest. 657 | * - Protect the drawing thread with a mutex. 658 | * - Scroll the Processor brand name (Wallboard). 659 | * - Changed the action associated with [Page Down] & [Page Up] keys. 660 | * - The [+] and [-] keys of the NumPad allow to decrase or increase the idle time. 661 | * - In the Core Widget : 662 | * the [H] key hide / unhide the frequencies. 663 | * the [P] key hide / unhide the C-States counters. 664 | * - The System Information Widget now gathers all detail about Processor, RAM and BIOS. 665 | * 666 | * R 0.14 : 01/19 2014 667 | * - Added the option '-c' to monitor the processor either per threads, either per cores. 668 | * - The Cores load is now based on the C0 performance counter and relatively to the TSC. 669 | * 670 | * R 0.13 : 01/14 2014 SR-1 671 | * - The program is changed from 2 to 3 threads: 672 | * uCycle to compute the actual frequency. 673 | * uDraw to paint the foreground. 674 | * uLoop to handle X events. (called by the main thread) 675 | * - The calculation of the Cores frequency is now as follow : 676 | * (Base Operating Ratio) x (Delta of Unhalted Cycles) x (Bus CLOCK frequency) 677 | * 678 | * R 0.12 : 01/14 2014 679 | * - Use the MSR performance counters to provide a better computation accuracy of the Cores frequency multiplier. 680 | * - Intel Core Architecture detected. 681 | * - Blink yellow when in pause mode. 682 | * 683 | * R 0.11 : 01/09 2014 684 | * - add specifications pages for Processor (features), RAM (timings & channels count) and BIOS (BCLK). 685 | * press [F1] to get help and scroll with arrow keys. 686 | * - provide a compact string for processor brand. 687 | * - better font support. 688 | * layout scaling is based on loaded font. 689 | * "fixed" font as a default. 690 | * 691 | * R 0.10 : 01/04 2014 692 | * - the MSR readings are optimized a little bit, however turbo ratios don't show up yet. 693 | * - drawing is now done with 2 pixmaps : 694 | * B, for the background layout, 695 | * F, to display the dynamics. 696 | * - the event loop does not sleep anymore but waits for any event on the socket. 697 | * - the '-a' argument allows to show the activity of the loop. 698 | * - transparency only works with a composite manager. 699 | * - the project is ported to Code::Blocks, however not delivered yet. 700 | * - semaphore lock is still questioned ? 701 | * R 0.09 : 01/01 2014 702 | * - PAUSE key to suspend drawing. 703 | * - double buffering. 704 | * - pseudo transparency with any window id (see option -D[esktop]). 705 | * - read SMBIOS @ 0x24 to get the true number of active Core threads (instead of CPUID). 706 | * - some drawing alignment; text scaling; coloring based on the ratios. 707 | * - add the temperature & a few spaces in the application title name. 708 | * - inform the WM of the Widget fixed size : no resize faisable. 709 | * - new option -s to set the idle time (micro-seconds) inside function uExec(). 710 | * - leave Event Loop, uLoop() as the main thread. 711 | * R 0.08 : Widget ready as a beta release. 712 | * R 0.01 to 0.07 : initial source code. 713 | * 714 | * 715 | * 716 | * [DOCUMENTATION] 717 | * 718 | * +-----+--------------------------------------------------------------------------------------------+ 719 | * | (1) | Intel 64 and IA-32 Software Developer Manual Vol 3A 3B 3C | 720 | * +-----+--------------------------------------------------------------------------------------------+ 721 | * | (2) | DMTF: System Management BIOS (SMBIOS) Reference Specification | 722 | * +-----+--------------------------------------------------------------------------------------------+ 723 | * | (3) | Intel Turbo Boost Technology in Intel CoreTM Microarchitecture (Nehalem) Based Processors | 724 | * +-----+--------------------------------------------------------------------------------------------+ 725 | * | (4) | Micron Technology: Technical Note DDR3 Power-Up, Initialization, and Reset | 726 | * +-----+--------------------------------------------------------------------------------------------+ 727 | * 728 | */ 729 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XFreq 2 | ## Purpose 3 | XFreq provides a GUI to monitor the Processor frequencies (including Turbo Boost), the temperatures, C-States, and to alter the operational features of the Intel Core i7 processor. 4 | XFreq is also programmed for Core 2 and other Intel 64-bits architectures. 5 | 6 | ![alt text](http://blog.cyring.free.fr/images/XFreq-core-R2151.png "CORE") 7 | 8 | ![alt text](http://blog.cyring.free.fr/images/XFreq-temps-R2151.png "TEMPS") 9 | 10 | ![alt text](http://blog.cyring.free.fr/images/XFreq-cstates-R2151.png "CSTATES") 11 | 12 | 13 | ### Features 14 | XFreq provides functionalities to play with: 15 | * Core Frequencies, Ratios and *Turbo Boost* 16 | * CPU Cycles, IPS, IPC, CPI 17 | * CPU C-States `C0 C1 C3 C6 C7` 18 | * Discrete Temperature per thread core 19 | * Processor features `[Yes]|[No]` and their activation state `[ON]|[OFF]` 20 | * Read and write MSR registers 21 | * DRAM controller & timings 22 | * Base Clock (from TSC, BIOS, factory value or a user defined memory address) 23 | * State of `[de]activated` Core by the OS or the BIOS 24 | * The xAPIC topology map 25 | * The Intel Performance counters 26 | * The Linux tasks scheduling monitoring. 27 | 28 | ### The GUI 29 | * The GUI Gadgets can be started as one MDI window or spanned in several Widgets, using the built-in window manager: 30 | * Right mouse button to move the Widgets on screen. 31 | * Left, to scroll Widgets, or push the GUI buttons and run the associated command. 32 | * A commands set allows to drive the Processor features, such as enabling, disabling `SpeedStep`, `Turbo Boost`, `Thermal Control`; 33 | but also, miscellaneous XFreq functionalities, such as setting the RGB colors, font and layout; save and load from the configuration file. 34 | * The Widgets disposal is specified with the program options. See the help below. 35 | * The tasks scheduled by the kernel among the CPU Cores are shown in real time. 36 | ![alt text](http://blog.cyring.free.fr/images/xfreq-task-scheduling.png "TASKS, lets you know what's going on in your system !") 37 | 38 | * XFreq's editor. 39 | ![alt text](http://blog.cyring.free.fr/images/xfreq-main-R2143.png "Full editor with a command line history") 40 | 41 | * Enter an address and a CPU Core number, XFreq will monitor its register bits. 42 | ![alt text](http://blog.cyring.free.fr/images/xfreq-dump-R2143.png "REGISTERS") 43 | 44 | ## Build & Run 45 | *Prerequisites*: as root, load the MSR Kernel driver. 46 | - if _Linux_ then enter: 47 | ``` 48 | modprobe msr 49 | ``` 50 | - if _FreeBSD_ then enter: 51 | ``` 52 | kldload cpuctl 53 | ``` 54 | 1- Download the [source code](https://github.com/cyring/xfreq/archive/master.zip) into a working directory 55 | 56 | 2- Build the programs: 57 | ``` 58 | make 59 | ``` 60 | 3- Run the server, as root: 61 | ``` 62 | ./XFreq/svr/bin/xfreq-intel 63 | ``` 64 | 4- ... and the GUI client, as a regular user: 65 | ``` 66 | ./XFreq/gui/bin/xfreq-gui 67 | ``` 68 | 5- start the console client with: 69 | ``` 70 | ./XFreq/cli/bin/xfreq-cli 71 | ``` 72 | 73 | 6- To display the help, enter: 74 | ``` 75 | $ xfreq-gui -h 76 | XFreq-Gui usage: 77 | xfreq-gui [-option argument] .. [-option argument] 78 | 79 | where options include: 80 | -C Path & file configuration name (String) 81 | this option must be first 82 | default is '$HOME/.xfreq' 83 | -D Run as a MDI Window (Bool) [0/1] 84 | -U Bitmap of unmap Widgets (Hex) eq. 0b00111111 85 | where each bit set in the argument is a hidden Widget 86 | -u Set the cursor shape (Bool) [0/1] 87 | -F Font name (String) 88 | default font is 'Fixed' 89 | -x Enable or disable the X ACL (Char) ['Y'/'N'] 90 | -g Widgets geometries (String) 91 | argument is a series of '#:[cols]x[rows]+[x]+[y], .. ,' 92 | -b Background color (Hex) {RGB} 93 | argument is coded with primary colors 0xRRGGBB 94 | -f Foreground color (Hex) {RGB} 95 | -l Fill or not the graphics (Bool) [0/1] 96 | -z Show the Core frequency (Bool) [0/1] 97 | -y Show the Core Cycles (Bool) [0/1] 98 | -j Show the Instructions Per Second (Bool) [0/1] 99 | -J Show the Instructions Per Cycle (Bool) [0/1] 100 | -i Show the Cycles Per Instructions (Bool) [0/1] 101 | -r Show the Core Ratio (Bool) [0/1] 102 | -p Show the Core C-State percentage (Bool) [0/1] 103 | -w Scroll the Processor brand wallboard (Bool) [0/1] 104 | -o Keep the Widgets always on top of the screen (Bool) [0/1] 105 | -n Remove the Window Manager decorations (Bool) [0/1] 106 | -N Remove the Widgets title name from the WM taskbar (Bool) [0/1] 107 | -I Splash screen attributes 0x{H}{NNN} (Hex) 108 | where {H} bit:13 hides Splash and {NNN} (usec) defers start-up 109 | -S Screenshot path (String) 110 | default is '$HOME' 111 | -v Print version information 112 | -h Print out this message 113 | 114 | Exit status: 115 | 0 if OK, 116 | 1 if problems, 117 | 2 if serious trouble. 118 | ``` 119 | ``` 120 | # xfreq-intel -h 121 | XFreq-Intel usage: 122 | xfreq-intel [-option argument] .. [-option argument] 123 | 124 | where options include: 125 | -c Pick up an architecture # (Int) 126 | refer to the '-A' option 127 | -S Clock source (Int) 128 | argument is one of the [0]TSC [1]BIOS [2]SPEC [3]ROM [4]USER 129 | -M ROM address of the Base Clock (Hex) 130 | argument is the BCLK memory address to read from 131 | -s Idle time multiplier (Int) 132 | argument is a coefficient multiplied by 50000 usec 133 | -d Registers dump enablement (Bool) 134 | -t Task scheduling monitoring sorted by 0x{R}0{N} (Hex) 135 | where {R} bit:8 is set to reverse sorting 136 | and {N} is one '/proc/sched_debug' field# from [0x1] to [0xb] 137 | -z Reset the MSR counters (Bool) 138 | -B Enable SmBIOS (Bool) 139 | -A Print out the built-in architectures 140 | -v Print version information 141 | -h Print out this message 142 | 143 | Exit status: 144 | 0 if OK, 145 | 1 if problems, 146 | 2 if serious trouble. 147 | ``` 148 | ### Algorithms 149 | The algorithms employed are introduced in the [Algorithms Wiki] 150 | 151 | ### Architectures 152 | `xfreq-intel -A` lists the built-in architectures and their default clock. 153 | ``` 154 | Architecture Family CPU FSB Clock 155 | # _Model [max] [ MHz ] 156 | 157 | 0 GenuineIntel 00_00 2 100.00 158 | 1 Core/Yonah 06_0E 2 100.00 159 | 2 Core2/Conroe 06_0F 2 266.67 160 | 3 Core2/Kentsfield 06_15 4 266.67 161 | 4 Core2/Conroe/Yonah 06_16 4 266.67 162 | 5 Core2/Yorkfield 06_17 4 266.67 163 | 6 Xeon/Dunnington 06_1D 6 266.67 164 | 7 Atom/Bonnell 06_1C 2 100.00 165 | 8 Atom/Silvermont 06_26 8 100.00 166 | 9 Atom/Lincroft 06_27 1 100.00 167 | 10 Atom/Clovertrail 06_35 2 100.00 168 | 11 Atom/Saltwell 06_36 2 100.00 169 | 12 Silvermont 06_37 4 83.30 170 | 13 Silvermont 06_4D 4 83.30 171 | 14 Atom/Airmont 06_4C 4 100.00 172 | 15 Atom/Goldmont 06_5C 4 100.00 173 | 16 Atom/Sofia 06_5D 4 100.00 174 | 17 Atom/Merrifield 06_4A 2 100.00 175 | 18 Atom/Moorefield 06_5A 4 100.00 176 | 19 Nehalem/Bloomfield 06_1A 4 133.33 177 | 20 Nehalem/Lynnfield 06_1E 4 133.33 178 | 21 Nehalem/Mobile 06_1F 2 133.33 179 | 22 Nehalem/eXtreme.EP 06_2E 8 133.33 180 | 23 Westmere 06_25 2 133.33 181 | 24 Westmere/EP 06_2C 6 133.33 182 | 25 Westmere/eXtreme 06_2F 10 133.33 183 | 26 SandyBridge 06_2A 4 100.00 184 | 27 SandyBridge/eXtreme.EP 06_2D 6 100.00 185 | 28 IvyBridge 06_3A 4 100.00 186 | 29 IvyBridge/EP 06_3E 6 100.00 187 | 30 Haswell/Desktop 06_3C 4 100.00 188 | 31 Haswell/Mobile 06_3F 4 100.00 189 | 32 Haswell/Ultra Low TDP 06_45 2 100.00 190 | 33 Haswell/Ultra Low eXtreme 06_46 2 100.00 191 | 34 Broadwell/Mobile 06_3D 2 100.00 192 | 35 Broadwell/EP 06_56 22 100.00 193 | 36 Broadwell/H 06_47 4 100.00 194 | 37 Broadwell/EX 06_4F 24 100.00 195 | 38 Skylake/UY 06_4E 2 100.00 196 | 39 Skylake/S 06_5E 4 100.00 197 | 40 Skylake/E 06_55 4 100.00 198 | ``` 199 | _Tips_: you can force an architecture with the `-c` option. 200 | 201 | #### Notes 202 | * XFreq is programmed in C and inline ASM, using the [Code::Blocks](http://www.codeblocks.org) IDE and the _complete_ X11 developer packages and this [Workstation] 203 | * The very last development snapshot can be cloned from the git [repository](https://github.com/cyring/xfreq.git) 204 | * Based on the Xlib and the GNU libc, XFreq runs with any desktop environment. 205 | * I will be thankful for your testing results, including your processor specs and the facing XFreq data. 206 | 207 | ### Development 208 | XFreq is a Clients-Server model based software. 209 | 210 | #### API 211 | A shared memory interface `[SHM]` to exchange data with the server. 212 | 213 | #### Server 214 | A daemon program which monitors the hardware and fills the `SHM` with the collected data. 215 | 216 | The server which requires the superuser privileges of root, receives and processes Client commands. 217 | 218 | #### Clients 219 | Gui and text programs which connect to the server through the `SHM` and display the hardware activity. 220 | 221 | Clients *do not* require the root permissions. 222 | 223 | ### Screenshots 224 | * Intel Processors Server 225 | 226 | ![alt text](http://blog.cyring.free.fr/images/XFreq-Intel.png "Server") 227 | 228 | * Console Client 229 | 230 | ![alt text](http://blog.cyring.free.fr/images/XFreq-Client.png "Console") 231 | 232 | * GUI Client 233 | 234 | ![alt text](http://blog.cyring.free.fr/images/xfreq-core.png "GUI") 235 | 236 | ### v2.1 237 | The files repository is the following: 238 | ``` 239 | ./Makefile 240 | 241 | ./api/Makefile 242 | ./api/xfreq-api.h 243 | ./api/xfreq-api.c 244 | ./api/xfreq-smbios.h 245 | ./api/xfreq-smbios.c 246 | ./api/xfreq-types.h 247 | 248 | ./cli/Makefile 249 | ./cli/XFreq-Cli.cbp 250 | ./cli/XFreq-Cli-FreeBSD.cbp 251 | ./cli/xfreq-cli.c 252 | ./cli/xfreq-cli.h 253 | 254 | ./gui/Makefile 255 | ./gui/XFreq-Gui.cbp 256 | ./gui/XFreq-Gui-FreeBSD.cbp 257 | ./gui/xfreq-gui.c 258 | ./gui/xfreq-gui.h 259 | 260 | ./svr/Makefile 261 | ./svr/XFreq-Intel.cbp 262 | ./svr/XFreq-Intel-FreeBSD.cbp 263 | ./svr/xfreq-intel.c 264 | ./svr/xfreq-intel.h 265 | ``` 266 | ### Build 267 | The v2.1 is delivered with [Code::Blocks](http://www.codeblocks.org) project files. 268 | 269 | An Arch Linux PKGBUILD is available in the [aur](http://aur.archlinux.org/packages/xfreq-git) repository. 270 | 271 | Package is systemd compliant. 272 | 273 | ### Run 274 | Processes must be run in the following order ... 275 | - as root 276 | ``` 277 | # xfreq-intel 278 | ```` 279 | - as a user 280 | ``` 281 | $ xfreq-gui 282 | ``` 283 | ... and in the reverse order to shutdown. 284 | 285 | ## News 286 | * Added a [Ctrl]+[s] hotkey to screen shot the focused widget. 287 | * Improved the fonts and colors management, and the integrated help. 288 | * New architectures implemented: Skylake, Broadwell 289 | * Web UI alpha release preview. [_Canceled_] 290 | * ![alt text](http://blog.cyring.free.fr/images/XFreq-WebUI.png "XFreq Web UI") 291 | * Bit set calculator. 292 | * Added Performance Monitor Features. 293 | * New commands to enable, disable C3 and C1 auto demotion. 294 | * C7 state is implemented. 295 | * ![alt text](http://blog.cyring.free.fr/images/xfreq-cstates-R2148.png "CSTATES") 296 | * 3 performance ratios: 297 | * IPS (Instructions Per Second) 298 | * IPC (Instructions Per Cycle), 299 | * CPI (Cycles Per Instruction), 300 | * C1 state is now available . 301 | * 3 new commands to "safely" enable, disable: 302 | * EIST ( `SpeedStep` ) 303 | * C1E ( `Extended Halt` ) 304 | * TCC ( `Thermal Control` ) 305 | * 5 new commands: 306 | * to enable, disable, the Intel Turbo Boost. 307 | * to read, write, and dump msr registers from any Core. 308 | * Integrated SmBIOS. 309 | * ![alt text](http://blog.cyring.free.fr/images/XFreq-SmBIOS.png "System Management BIOS") 310 | * Ported to FreeBSD. 311 | * Up to 64 simultaneous clients. 312 | * ![alt text](http://blog.cyring.free.fr/images/XFreq-64cli.png "64 Clients in action !") 313 | # Regards 314 | _`CyrIng`_ 315 | 316 | Paris ;-) 317 | 318 | -------------------------------------------------------------------------------- /api/Makefile: -------------------------------------------------------------------------------- 1 | export CC 2 | CFLAGS = -Wall -x c 3 | KERNEL = `uname -s` 4 | SRC_PATH=. 5 | OBJ_PATH=./obj 6 | INC4x86_PATH=-I . 7 | # 8 | all : xfreq-smbios.o xfreq-api.o 9 | # 10 | help : 11 | @echo 'make [all] : Compile and link files in' $(OBJ_PATH)/ 12 | @echo 'make clean : Remove object files.' 13 | @echo 'make clean-all : Remove object sub-directories.' 14 | # 15 | clean : 16 | @echo 'Cleaning ...' 17 | @if [ -e $(OBJ_PATH)/xfreq-api.o ]; then rm -v $(OBJ_PATH)/xfreq-api.o; else echo 'Nothing to do in '$(OBJ_PATH); fi 18 | @if [ -e $(OBJ_PATH)/xfreq-smbios.o ]; then rm -v $(OBJ_PATH)/xfreq-smbios.o; else echo 'Nothing to do in '$(OBJ_PATH); fi 19 | # 20 | clean-all: 21 | @echo 'Cleaning all ...' 22 | @if [ -d $(OBJ_PATH) ]; then rm -vr $(OBJ_PATH); else echo 'Nothing to do in '$(OBJ_PATH); fi 23 | # 24 | xfreq-api.o : xfreq-api.c 25 | @if [ ! -d $(OBJ_PATH) ]; then mkdir $(OBJ_PATH); fi 26 | $(CC) -D$(KERNEL) $(CFLAGS) -c xfreq-api.c $(INC4x86_PATH) -o $(OBJ_PATH)/xfreq-api.o 27 | xfreq-smbios.o : xfreq-smbios.c 28 | @if [ ! -d $(OBJ_PATH) ]; then mkdir $(OBJ_PATH); fi 29 | $(CC) -D$(KERNEL) $(CFLAGS) -c xfreq-smbios.c $(INC4x86_PATH) -o $(OBJ_PATH)/xfreq-smbios.o 30 | -------------------------------------------------------------------------------- /api/xfreq-api.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-api.c by CyrIng 3 | * 4 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 5 | * Licenses: GPL2 6 | */ 7 | 8 | 9 | #include 10 | 11 | #include "xfreq-smbios.h" 12 | #include "xfreq-api.h" 13 | 14 | unsigned int ROL32(unsigned int r32, unsigned short int m16) 15 | { 16 | __asm__ volatile 17 | ( 18 | "mov %0, %%eax \n\t" 19 | "movw %1, %%cx \n\t" 20 | "rol %%cl,%%eax \n\t" 21 | "mov %%eax, %0 " 22 | : "=m" (r32), "=m" (m16) 23 | : "m" (r32) 24 | ); 25 | return(r32); 26 | } 27 | 28 | unsigned int ROR32(unsigned int r32, unsigned short int m16) 29 | { 30 | __asm__ volatile 31 | ( 32 | "mov %0, %%eax \n\t" 33 | "movw %1, %%cx \n\t" 34 | "ror %%cl, %%eax \n\t" 35 | "mov %%eax, %0 " 36 | : "=m" (r32), "=m" (m16) 37 | : "m" (r32) 38 | ); 39 | return(r32); 40 | } 41 | /* 42 | unsigned long long int BT64(unsigned long long int r64, unsigned long long int i64) 43 | { 44 | unsigned long long int f64; 45 | __asm__ volatile 46 | ( 47 | "mov %1, %%rax \n\t" 48 | "mov %2, %%rdx \n\t" 49 | "bt %%rdx, %%rax \n\t" 50 | "jc One \n\t" 51 | "mov %%rax, 0x0 \n\t" 52 | "jmp Over \n\t" 53 | "One: \n\t" 54 | "mov %%rax, 0x1 \n\t" 55 | "Over: \n\t" 56 | "mov %%rax, %0" 57 | : "=m" (f64) 58 | : "m" (r64), "m" (i64) 59 | ); 60 | return(f64); 61 | } 62 | */ 63 | void abstimespec(useconds_t usec, struct timespec *tsec) 64 | { 65 | tsec->tv_sec=usec / 1000000L; 66 | tsec->tv_nsec=(usec % 1000000L) * 1000; 67 | } 68 | 69 | int addtimespec(struct timespec *asec, const struct timespec *tsec) 70 | { 71 | int rc=0; 72 | if((rc=clock_gettime(CLOCK_REALTIME, asec)) != -1) 73 | { 74 | if((asec->tv_nsec += tsec->tv_nsec) >= 1000000000L) 75 | { 76 | asec->tv_nsec -= 1000000000L; 77 | asec->tv_sec += 1; 78 | } 79 | asec->tv_sec += tsec->tv_sec; 80 | 81 | return(0); 82 | } 83 | else 84 | return(errno); 85 | } 86 | 87 | void Sync_Init(SYNCHRONIZATION *sync) 88 | { 89 | XCHG_MAP XChange={.Map={.Addr=0, .Core=0, .Arg=0, .ID=ID_NULL}}; 90 | atomic_init(&sync->IF, 0x0); 91 | atomic_init(&sync->Rooms, 0x1); 92 | atomic_init(&sync->Play, XChange.Map64); 93 | atomic_init(&sync->Data, 0); 94 | } 95 | 96 | void Sync_Destroy(SYNCHRONIZATION *sync) 97 | { 98 | atomic_store(&sync->IF, 0x0); 99 | } 100 | 101 | unsigned int Sync_Open(SYNCHRONIZATION *sync) 102 | { 103 | unsigned int room; 104 | for(room=63; room > 0; room--) 105 | { 106 | const unsigned long long int roomBit=(unsigned long long int) 1<Rooms) & roomBit)) 109 | { 110 | atomic_fetch_or(&sync->Rooms, roomBit); 111 | break; 112 | } 113 | } 114 | return(room); 115 | } 116 | 117 | void Sync_Close(unsigned int room, SYNCHRONIZATION *sync) 118 | { 119 | const unsigned long long int roomCmp=(unsigned long long int) ~(1<Rooms, roomCmp); 122 | } 123 | 124 | long int Sync_Wait(unsigned int room, SYNCHRONIZATION *sync, useconds_t idleTime) 125 | { 126 | const unsigned long int roomBit=(unsigned long long int) 1<IF) & roomBit) && idleRemaining) 130 | { 131 | usleep(IDLE_BASE_USEC); 132 | idleRemaining--; 133 | } 134 | atomic_fetch_and(&sync->IF, roomCmp); 135 | return(idleRemaining); 136 | } 137 | 138 | void Sync_Signal(unsigned int room, SYNCHRONIZATION *sync) 139 | { 140 | atomic_fetch_or(&sync->IF, (!room) ? 0x1 : 0xfffffffffffffffe); 141 | } 142 | 143 | char *Smb_Find_String(struct STRUCTINFO *smb, int ID) 144 | { 145 | struct STRING *pstr=NULL; 146 | 147 | if(smb != NULL) 148 | { 149 | pstr=smb->String; 150 | while((pstr != NULL) && (pstr->ID != ID)) 151 | pstr=pstr->Link; 152 | } 153 | return((pstr != NULL) ? pstr->Buffer : ""); 154 | } 155 | -------------------------------------------------------------------------------- /api/xfreq-api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-api.h by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define _MAJOR "2" 15 | #define _MINOR "1" 16 | #define _NIGHTLY "66" 17 | #define AutoDate _APPNAME" "_MAJOR"."_MINOR"-"_NIGHTLY" (C) CYRIL INGENIERIE "__DATE__"\n" 18 | 19 | #if defined(Linux) 20 | #define SHM_FILENAME "xfreq-shm" 21 | #define SMB_FILENAME "xfreq-smb" 22 | #else 23 | #define SHM_FILENAME "/xfreq-shm" 24 | #define SMB_FILENAME "/xfreq-smb" 25 | #endif 26 | 27 | 28 | enum {SRC_TSC, SRC_BIOS, SRC_SPEC, SRC_ROM, SRC_TSC_AUX, SRC_COUNT}; 29 | 30 | typedef struct 31 | { 32 | char VendorID[16]; 33 | struct 34 | { 35 | struct SIGNATURE 36 | { 37 | unsigned int 38 | Stepping : 4-0, 39 | Model : 8-4, 40 | Family : 12-8, 41 | ProcType : 14-12, 42 | Unused1 : 16-14, 43 | ExtModel : 20-16, 44 | ExtFamily : 28-20, 45 | Unused2 : 32-28; 46 | } AX; 47 | struct 48 | { 49 | unsigned int 50 | Brand_ID : 8-0, 51 | CLFSH_Size : 16-8, 52 | MaxThread : 24-16, 53 | APIC_ID : 32-24; 54 | } BX; 55 | struct 56 | { 57 | unsigned int 58 | SSE3 : 1-0, 59 | PCLMULDQ: 2-1, 60 | DTES64 : 3-2, 61 | MONITOR : 4-3, 62 | DS_CPL : 5-4, 63 | VMX : 6-5, 64 | SMX : 7-6, 65 | EIST : 8-7, 66 | TM2 : 9-8, 67 | SSSE3 : 10-9, 68 | CNXT_ID : 11-10, 69 | Unused1 : 12-11, 70 | FMA : 13-12, 71 | CX16 : 14-13, 72 | xTPR : 15-14, 73 | PDCM : 16-15, 74 | Unused2 : 17-16, 75 | PCID : 18-17, 76 | DCA : 19-18, 77 | SSE41 : 20-19, 78 | SSE42 : 21-20, 79 | x2APIC : 22-21, 80 | MOVBE : 23-22, 81 | POPCNT : 24-23, 82 | TSCDEAD : 25-24, 83 | AES : 26-25, 84 | XSAVE : 27-26, 85 | OSXSAVE : 28-27, 86 | AVX : 29-28, 87 | F16C : 30-29, 88 | RDRAND : 31-30, 89 | Unused3 : 32-31; 90 | } CX; 91 | struct 92 | { 93 | unsigned int 94 | FPU : 1-0, 95 | VME : 2-1, 96 | DE : 3-2, 97 | PSE : 4-3, 98 | TSC : 5-4, 99 | MSR : 6-5, 100 | PAE : 7-6, 101 | MCE : 8-7, 102 | CX8 : 9-8, 103 | APIC : 10-9, 104 | Unused1 : 11-10, 105 | SEP : 12-11, 106 | MTRR : 13-12, 107 | PGE : 14-13, 108 | MCA : 15-14, 109 | CMOV : 16-15, 110 | PAT : 17-16, 111 | PSE36 : 18-17, 112 | PSN : 19-18, 113 | CLFSH : 20-19, 114 | Unused2 : 21-20, 115 | DS_PEBS : 22-21, 116 | ACPI : 23-22, 117 | MMX : 24-23, 118 | FXSR : 25-24, 119 | SSE : 26-25, 120 | SSE2 : 27-26, 121 | SS : 28-27, 122 | HTT : 29-28, 123 | TM1 : 30-29, 124 | Unused3 : 31-30, 125 | PBE : 32-31; 126 | } DX; 127 | } Std; 128 | unsigned int ThreadCount; 129 | struct 130 | { 131 | struct 132 | { 133 | unsigned int 134 | SmallestSize : 16-0, 135 | ReservedBits : 32-16; 136 | } AX; 137 | struct 138 | { 139 | unsigned int 140 | LargestSize : 16-0, 141 | ReservedBits : 32-16; 142 | } BX; 143 | struct 144 | { 145 | unsigned int 146 | ExtSupported : 1-0, 147 | BK_Int_MWAIT : 2-1, 148 | ReservedBits : 32-2; 149 | } CX; 150 | struct 151 | { 152 | unsigned int 153 | Num_C0_MWAIT : 4-0, 154 | Num_C1_MWAIT : 8-4, 155 | Num_C2_MWAIT : 12-8, 156 | Num_C3_MWAIT : 16-12, 157 | Num_C4_MWAIT : 20-16, 158 | ReservedBits : 32-20; 159 | } DX; 160 | } MONITOR_MWAIT_Leaf; 161 | struct 162 | { 163 | struct 164 | { 165 | unsigned int 166 | DTS : 1-0, 167 | TurboIDA: 2-1, 168 | ARAT : 3-2, 169 | Unused1 : 4-3, 170 | PLN : 5-4, 171 | ECMD : 6-5, 172 | PTM : 7-6, 173 | Unused2 : 32-7; 174 | } AX; 175 | struct 176 | { 177 | unsigned int 178 | Threshld: 4-0, 179 | Unused1 : 32-4; 180 | } BX; 181 | struct 182 | { 183 | unsigned int 184 | HCF_Cap : 1-0, 185 | ACNT_Cap: 2-1, 186 | Unused1 : 3-2, 187 | PEB_Cap : 4-3, 188 | Unused2 : 32-4; 189 | } CX; 190 | struct 191 | { 192 | unsigned int 193 | Unused1 : 32-0; 194 | } DX; 195 | } Thermal_Power_Leaf; 196 | struct 197 | { 198 | struct 199 | { 200 | unsigned int 201 | Version : 8-0, 202 | MonCtrs : 16-8, 203 | MonWidth: 24-16, 204 | VectorSz: 32-24; 205 | } AX; 206 | struct 207 | { 208 | unsigned int 209 | CoreCycles : 1-0, 210 | InstrRetired : 2-1, 211 | RefCycles : 3-2, 212 | LLC_Ref : 4-3, 213 | LLC_Misses : 5-4, 214 | BranchRetired : 6-5, 215 | BranchMispred : 7-6, 216 | ReservedBits : 32-7; 217 | } BX; 218 | struct 219 | { 220 | unsigned int 221 | Unused1 : 32-0; 222 | } CX; 223 | struct 224 | { 225 | unsigned int 226 | FixCtrs : 5-0, 227 | FixWidth: 13-5, 228 | Unused1 : 32-13; 229 | } DX; 230 | } Perf_Monitoring_Leaf; 231 | struct 232 | { 233 | struct 234 | { 235 | unsigned int 236 | MaxSubLeaf : 32-0; 237 | } AX; 238 | struct 239 | { 240 | unsigned int 241 | FSGSBASE : 1-0, 242 | TSC_ADJUST : 2-1, 243 | Unused1 : 3-2, 244 | BMI1 : 4-3, 245 | HLE : 5-4, 246 | AVX2 : 6-5, 247 | Unused2 : 7-6, 248 | SMEP : 8-7, 249 | BMI2 : 9-8, 250 | FastStrings : 10-9, 251 | INVPCID : 11-10, 252 | RTM : 12-11, 253 | QM : 13-12, 254 | FPU_CS_DS : 14-13, 255 | Unused3 : 32-14; 256 | } BX; 257 | unsigned int 258 | CX : 32-0, 259 | DX : 32-0; 260 | 261 | } ExtFeature; 262 | unsigned int LargestExtFunc; 263 | struct 264 | { 265 | struct 266 | { 267 | unsigned int 268 | LAHFSAHF: 1-0, 269 | Unused1 : 32-1; 270 | } CX; 271 | struct 272 | { 273 | unsigned int 274 | Unused1 : 11-0, 275 | SYSCALL : 12-11, 276 | Unused2 : 20-12, 277 | XD_Bit : 21-20, 278 | Unused3 : 26-21, 279 | PG_1GB : 27-26, 280 | RDTSCP : 28-27, 281 | Unused4 : 29-28, 282 | IA64 : 30-29, 283 | Unused5 : 32-30; 284 | } DX; 285 | } ExtFunc; 286 | unsigned int InvariantTSC, 287 | HTT_enabled; 288 | char BrandString[48]; 289 | } FEATURES; 290 | 291 | #define IA32_TIME_STAMP_COUNTER 0x10 292 | #define IA32_PLATFORM_ID 0x17 293 | #define IA32_MPERF 0xe7 294 | #define IA32_APERF 0xe8 295 | #define IA32_PERF_STATUS 0x198 296 | #define IA32_PERF_CTL 0x199 297 | #define IA32_CLOCK_MODULATION 0x19a 298 | #define IA32_THERM_INTERRUPT 0x19b 299 | #define IA32_THERM_STATUS 0x19c 300 | #define IA32_MISC_ENABLE 0x1a0 301 | #define IA32_ENERGY_PERF_BIAS 0x1b0 302 | #define IA32_PKG_THERM_STATUS 0x1b1 303 | #define IA32_PKG_THERM_INTERRUPT 0x1b2 304 | #define IA32_MTRR_DEF_TYPE 0x2ff 305 | #define IA32_FIXED_CTR0 0x309 306 | #define IA32_FIXED_CTR1 0x30a 307 | #define IA32_FIXED_CTR2 0x30b 308 | #define IA32_FIXED_CTR_CTRL 0x38d 309 | #define IA32_PERF_GLOBAL_STATUS 0x38e 310 | #define IA32_PERF_GLOBAL_CTRL 0x38f 311 | #define IA32_PERF_GLOBAL_OVF_CTRL 0x390 312 | #define IA32_EFER 0xc0000080 313 | #define MSR_CORE_C3_RESIDENCY 0x3fc 314 | #define MSR_CORE_C6_RESIDENCY 0x3fd 315 | #define MSR_CORE_C7_RESIDENCY 0x3fe 316 | #define MSR_FSB_FREQ 0xcd 317 | #define MSR_PLATFORM_INFO 0xce 318 | #define MSR_PKG_CST_CONFIG_CTRL 0xe2 319 | #define MSR_TURBO_RATIO_LIMIT 0x1ad 320 | #define MSR_TEMPERATURE_TARGET 0x1a2 321 | #define MSR_POWER_CTL 0x1fc 322 | 323 | typedef struct 324 | { 325 | unsigned long long int 326 | ReservedBits1 : 8-0, 327 | MaxBusRatio : 13-8, 328 | ReservedBits2 : 50-13, 329 | PlatformId : 53-50, 330 | ReservedBits3 : 64-53; 331 | } PLATFORM_ID; 332 | 333 | typedef struct 334 | { 335 | unsigned long long int 336 | Bus_Speed : 3-0, 337 | ReservedBits : 64-3; 338 | } FSB_FREQ; 339 | 340 | typedef struct 341 | { 342 | unsigned long long int 343 | CurrentRatio : 16-0, 344 | ReservedBits1 : 31-16, 345 | XE : 32-31, 346 | ReservedBits2 : 40-32, 347 | MaxBusRatio : 45-40, 348 | ReservedBits3 : 46-45, 349 | NonInt_BusRatio : 47-46, 350 | ReservedBits4 : 64-47; 351 | } PERF_STATUS; 352 | 353 | typedef struct 354 | { 355 | unsigned long long int 356 | EIST_Target : 16-0, 357 | ReservedBits1 : 32-16, 358 | Turbo_IDA : 33-32, 359 | ReservedBits2 : 64-33; 360 | } PERF_CONTROL; 361 | 362 | typedef struct 363 | { 364 | unsigned long long int 365 | ReservedBits1 : 8-0, 366 | MaxNonTurboRatio: 16-8, 367 | ReservedBits2 : 28-16, 368 | Ratio_Limited : 29-28, 369 | TDC_TDP_Limited : 30-29, 370 | ReservedBits3 : 32-30, 371 | LowPowerMode : 33-32, 372 | ConfigTDPlevels : 35-33, 373 | ReservedBits4 : 40-35, 374 | MinimumRatio : 48-40, 375 | MinOpeRatio : 56-48, 376 | ReservedBits5 : 64-56; 377 | } PLATFORM_INFO; 378 | 379 | typedef struct 380 | { 381 | unsigned long long int 382 | Pkg_CST_Limit : 3-0, 383 | ReservedBits1 : 10-3, 384 | IO_MWAIT_Redir : 11-10, 385 | ReservedBits2 : 15-11, 386 | CFG_Lock : 16-15, 387 | ReservedBits3 : 24-16, 388 | Int_Filtering : 25-24, // Nehalem 389 | C3autoDemotion : 26-25, 390 | C1autoDemotion : 27-26, 391 | C3undemotion : 28-27, // Sandy Bridge 392 | C1undemotion : 29-28, // Sandy Bridge 393 | ReservedBits4 : 64-29; 394 | } CSTATE_CONFIG; 395 | 396 | typedef struct 397 | { 398 | unsigned long long int 399 | MaxRatio_1C : 8-0, 400 | MaxRatio_2C : 16-8, 401 | MaxRatio_3C : 24-16, 402 | MaxRatio_4C : 32-24, 403 | MaxRatio_5C : 40-32, 404 | MaxRatio_6C : 48-40, 405 | MaxRatio_7C : 56-48, 406 | MaxRatio_8C : 64-56; 407 | } TURBO; 408 | 409 | typedef struct 410 | { 411 | unsigned long long int 412 | FastStrings : 1-0, 413 | ReservedBits1 : 3-1, 414 | TCC : 4-3, 415 | ReservedBits2 : 7-4, 416 | PerfMonitoring : 8-7, 417 | ReservedBits3 : 11-8, 418 | BTS : 12-11, 419 | PEBS : 13-12, 420 | TM2_Enable : 14-13, 421 | ReservedBits4 : 16-14, 422 | EIST : 17-16, 423 | ReservedBits5 : 18-17, 424 | FSM : 19-18, 425 | ReservedBits6 : 22-19, 426 | CPUID_MaxVal : 23-22, 427 | xTPR : 24-23, 428 | ReservedBits7 : 34-24, 429 | XD_Bit : 35-34, 430 | ReservedBits8 : 37-35, 431 | DCU_Prefetcher : 38-37, 432 | Turbo_IDA : 39-38, 433 | IP_Prefetcher : 40-39, 434 | ReservedBits9 : 64-40; 435 | } MISC_PROC_FEATURES; 436 | 437 | typedef struct 438 | { 439 | unsigned long long int 440 | Type : 8-0, 441 | ReservedBits1 : 10-8, 442 | FixeRange : 11-10, 443 | Enable : 12-11, 444 | ReservedBits2 : 64-12; 445 | } MTRR_DEF_TYPE; 446 | 447 | typedef struct 448 | { 449 | unsigned long long int 450 | EN_PMC0 : 1-0, 451 | EN_PMC1 : 2-1, 452 | EN_PMC2 : 3-2, 453 | EN_PMC3 : 4-3, 454 | EN_PMCn : 32-4, 455 | EN_FIXED_CTR0 : 33-32, 456 | EN_FIXED_CTR1 : 34-33, 457 | EN_FIXED_CTR2 : 35-34, 458 | ReservedBits2 : 64-35; 459 | } GLOBAL_PERF_COUNTER; 460 | 461 | typedef struct 462 | { 463 | unsigned long long int 464 | EN0_OS : 1-0, 465 | EN0_Usr : 2-1, 466 | AnyThread_EN0 : 3-2, 467 | EN0_PMI : 4-3, 468 | EN1_OS : 5-4, 469 | EN1_Usr : 6-5, 470 | AnyThread_EN1 : 7-6, 471 | EN1_PMI : 8-7, 472 | EN2_OS : 9-8, 473 | EN2_Usr : 10-9, 474 | AnyThread_EN2 : 11-10, 475 | EN2_PMI : 12-11, 476 | ReservedBits : 64-12; 477 | } FIXED_PERF_COUNTER; 478 | 479 | typedef struct 480 | { 481 | unsigned long long int 482 | Overflow_PMC0 : 1-0, 483 | Overflow_PMC1 : 2-1, 484 | Overflow_PMC2 : 3-2, 485 | Overflow_PMC3 : 4-3, 486 | Overflow_PMCn : 32-4, 487 | Overflow_CTR0 : 33-32, 488 | Overflow_CTR1 : 34-33, 489 | Overflow_CTR2 : 35-34, 490 | ReservedBits2 : 61-35, 491 | Overflow_UNC : 62-61, 492 | Overflow_Buf : 63-62, 493 | Ovf_CondChg : 64-63; 494 | } GLOBAL_PERF_STATUS; 495 | 496 | typedef struct 497 | { 498 | unsigned long long int 499 | Clear_Ovf_PMC0 : 1-0, 500 | Clear_Ovf_PMC1 : 2-1, 501 | Clear_Ovf_PMC2 : 3-2, 502 | Clear_Ovf_PMC3 : 4-3, 503 | Clear_Ovf_PMCn : 32-2, 504 | Clear_Ovf_CTR0 : 33-32, 505 | Clear_Ovf_CTR1 : 34-33, 506 | Clear_Ovf_CTR2 : 35-34, 507 | ReservedBits2 : 61-35, 508 | Clear_Ovf_UNC : 62-61, 509 | Clear_Ovf_Buf : 63-62, 510 | Clear_CondChg : 64-63; 511 | } GLOBAL_PERF_OVF_CTRL; 512 | 513 | typedef struct 514 | { 515 | unsigned long long int 516 | SCE : 1-0, 517 | ReservedBits1 : 8-1, 518 | LME : 9-8, 519 | ReservedBits2 : 10-9, 520 | LMA : 11-10, 521 | NXE : 12-11, 522 | ReservedBits3 : 64-12; 523 | } EXT_FEATURE_ENABLE; 524 | 525 | typedef struct 526 | { 527 | unsigned long long int 528 | HighTempEnable : 1-0, 529 | LowTempEnable : 2-1, 530 | PROCHOTEnable : 3-2, 531 | FORCEPREnable : 4-3, 532 | OverheatEnable : 5-4, 533 | ReservedBits1 : 8-5, 534 | Threshold1 : 15-8, 535 | Threshold1Enable: 16-15, 536 | Threshold2 : 23-16, 537 | Threshold2Enable: 24-23, 538 | PowerLimitEnable: 25-24, 539 | ReservedBits2 : 64-25; 540 | } THERM_INTERRUPT; 541 | 542 | typedef struct 543 | { 544 | unsigned long long int 545 | StatusBit : 1-0, 546 | StatusLog : 2-1, 547 | PROCHOT : 3-2, 548 | PROCHOTLog : 4-3, 549 | CriticalTemp : 5-4, 550 | CriticalTempLog : 6-5, 551 | Threshold1 : 7-6, 552 | Threshold1Log : 8-7, 553 | Threshold2 : 9-8, 554 | Threshold2Log : 10-9, 555 | PowerLimit : 11-10, 556 | PowerLimitLog : 12-11, 557 | ReservedBits1 : 16-12, 558 | DTS : 23-16, 559 | ReservedBits2 : 27-23, 560 | Resolution : 31-27, 561 | ReadingValid : 32-31, 562 | ReservedBits3 : 64-32; 563 | } THERM_STATUS; 564 | 565 | typedef struct 566 | { 567 | unsigned long long int 568 | ReservedBits1 : 16-0, 569 | Target : 24-16, 570 | ReservedBits2 : 64-24; 571 | } TJMAX; 572 | 573 | typedef struct 574 | { 575 | unsigned long long int 576 | ReservedBits1 : 1-0, 577 | C1E : 2-1, 578 | ReservedBits2 : 64-2; 579 | } POWER_CONTROL; 580 | 581 | #define IDLE_BASE_USEC 50000 582 | #define IDLE_SCHED_DEF 19 583 | #define IDLE_COEF_DEF 20 584 | #define IDLE_COEF_MAX 80 585 | #define IDLE_COEF_MIN 2 586 | 587 | typedef struct 588 | { 589 | signed long int ArchID; 590 | FEATURES Features; 591 | PLATFORM_ID PlatformId; 592 | PERF_STATUS PerfStatus; 593 | PERF_CONTROL PerfControl; 594 | MISC_PROC_FEATURES MiscFeatures; 595 | MTRR_DEF_TYPE MTRRdefType; 596 | EXT_FEATURE_ENABLE ExtFeature; 597 | PLATFORM_INFO PlatformInfo; 598 | CSTATE_CONFIG CStateConfig; 599 | TURBO Turbo; 600 | POWER_CONTROL PowerControl; 601 | off_t BClockROMaddr; 602 | double ClockSpeed; 603 | unsigned int CPU, 604 | OnLine; 605 | unsigned int Boost[1+1+8]; 606 | 607 | struct { 608 | double Turbo, 609 | C0, 610 | C3, 611 | C6, 612 | C7, 613 | C1; 614 | } Avg; 615 | unsigned int Top, 616 | Hot, 617 | Cold, 618 | PerCore, 619 | ClockSrc; 620 | useconds_t IdleTime; 621 | } PROCESSOR; 622 | 623 | #define ARCHITECTURE_LEN 32 624 | typedef struct 625 | { 626 | struct SIGNATURE Signature; 627 | unsigned int MaxOfCores; 628 | double ClockSpeed; 629 | char Architecture[ARCHITECTURE_LEN]; 630 | } ARCHITECTURE; 631 | 632 | #define DUMP_ARRAY_DIMENSION 16 633 | #define DUMP_REG_ALIGN 24 634 | typedef struct 635 | { 636 | unsigned int Core; 637 | char Name[DUMP_REG_ALIGN]; 638 | unsigned int Addr; 639 | unsigned long long int Value; 640 | } DUMP_ARRAY; 641 | 642 | #define DUMP_LOADER \ 643 | { \ 644 | { 0, "IA32_PLATFORM_ID", IA32_PLATFORM_ID, 0}, \ 645 | { 0, "MSR_PLATFORM_INFO", MSR_PLATFORM_INFO, 0}, \ 646 | { 0, "IA32_MISC_ENABLE", IA32_MISC_ENABLE, 0}, \ 647 | { 0, "IA32_PERF_STATUS", IA32_PERF_STATUS, 0}, \ 648 | { 0, "IA32_THERM_STATUS", IA32_THERM_STATUS, 0}, \ 649 | { 0, "MSR_TURBO_RATIO_LIMIT", MSR_TURBO_RATIO_LIMIT, 0}, \ 650 | { 0, "MSR_TEMPERATURE_TARGET", MSR_TEMPERATURE_TARGET, 0}, \ 651 | { 0, "IA32_FIXED_CTR1", IA32_FIXED_CTR1, 0}, \ 652 | { 0, "IA32_FIXED_CTR2", IA32_FIXED_CTR2, 0}, \ 653 | { 0, "MSR_CORE_C3_RESIDENCY", MSR_CORE_C3_RESIDENCY, 0}, \ 654 | { 1, "IA32_FIXED_CTR1", IA32_FIXED_CTR1, 0}, \ 655 | { 1, "IA32_FIXED_CTR2", IA32_FIXED_CTR2, 0}, \ 656 | { 2, "IA32_FIXED_CTR1", IA32_FIXED_CTR1, 0}, \ 657 | { 2, "IA32_FIXED_CTR2", IA32_FIXED_CTR2, 0}, \ 658 | { 3, "IA32_FIXED_CTR1", IA32_FIXED_CTR1, 0}, \ 659 | { 3, "IA32_FIXED_CTR2", IA32_FIXED_CTR2, 0}, \ 660 | } 661 | 662 | typedef struct 663 | { 664 | Bool64 Monitor; 665 | DUMP_ARRAY Array[DUMP_ARRAY_DIMENSION]; 666 | } DUMP_STRUCT; 667 | 668 | #define IMC_MAX 16 669 | typedef struct 670 | { 671 | unsigned int ChannelCount; 672 | struct CHANNEL 673 | { 674 | struct 675 | { 676 | unsigned int 677 | tCL, 678 | tRCD, 679 | tRP, 680 | tRAS, 681 | tRRD, 682 | tRFC, 683 | tWR, 684 | tRTPr, 685 | tWTPr, 686 | tFAW, 687 | B2B; 688 | } Timing; 689 | } Channel[IMC_MAX]; 690 | } IMC_INFO; 691 | 692 | enum { GenuineIntel, \ 693 | Core_Yonah, \ 694 | Core_Conroe, \ 695 | Core_Kentsfield, \ 696 | Core_Conroe_616, \ 697 | Core_Yorkfield, \ 698 | Core_Dunnington, \ 699 | Atom_Bonnell, \ 700 | Atom_Silvermont, \ 701 | Atom_Lincroft, \ 702 | Atom_Clovertrail, \ 703 | Atom_Saltwell, \ 704 | Silvermont_637, \ 705 | Silvermont_64D, \ 706 | Atom_Airmont, \ 707 | Atom_Goldmont, \ 708 | Atom_Sofia, \ 709 | Atom_Merrifield, \ 710 | Atom_Moorefield, \ 711 | Nehalem_Bloomfield, \ 712 | Nehalem_Lynnfield, \ 713 | Nehalem_MB, \ 714 | Nehalem_EX, \ 715 | Westmere, \ 716 | Westmere_EP, \ 717 | Westmere_EX, \ 718 | SandyBridge, \ 719 | SandyBridge_EP, \ 720 | IvyBridge, \ 721 | IvyBridge_EP, \ 722 | Haswell_DT, \ 723 | Haswell_MB, \ 724 | Haswell_ULT, \ 725 | Haswell_ULX, \ 726 | Broadwell, \ 727 | Broadwell_EP, \ 728 | Broadwell_H, \ 729 | Broadwell_EX, \ 730 | Skylake_UY, \ 731 | Skylake_S, \ 732 | Skylake_E, \ 733 | ARCHITECTURES 734 | }; 735 | 736 | typedef enum 737 | { 738 | SORT_FIELD_NONE = 0x0, 739 | SORT_FIELD_STATE = 0x1, 740 | SORT_FIELD_COMM = 0x2, 741 | SORT_FIELD_PID = 0x3, 742 | SORT_FIELD_RUNTIME = 0x4, 743 | SORT_FIELD_CTX_SWITCH = 0x5, 744 | SORT_FIELD_PRIORITY = 0x6, 745 | SORT_FIELD_EXEC = 0x7, 746 | SORT_FIELD_SUM_EXEC = 0x8, 747 | SORT_FIELD_SUM_SLEEP = 0x9, 748 | SORT_FIELD_NODE = 0xa, 749 | SORT_FIELD_GROUP = 0xb 750 | } SORT_FIELDS; 751 | 752 | #define TASK_COMM_LEN 16 753 | #define TASK_PIPE_DEPTH 10 754 | typedef struct 755 | { 756 | Bool32 Monitor; 757 | unsigned int Attributes; 758 | } SCHEDULE; 759 | 760 | typedef struct 761 | { 762 | long long int nsec_high, 763 | nsec_low; 764 | } RUNTIME; 765 | 766 | #define CACHE_MAX_LEVEL 3 767 | typedef struct 768 | { 769 | Bool32 Offline; 770 | unsigned 771 | APIC_ID : 32-0, 772 | Core_ID : 32-0, 773 | Thread_ID: 32-0; 774 | struct 775 | { 776 | union 777 | { 778 | struct 779 | { 780 | unsigned int 781 | Type: 5-0, 782 | Level: 8-5, 783 | Init: 9-8, 784 | Assoc: 10-9, 785 | Unused: 14-10, 786 | MaxID: 26-14, 787 | PerPkg: 32-26; 788 | }; 789 | unsigned int AX; 790 | }; 791 | union 792 | { 793 | struct 794 | { 795 | unsigned int 796 | Linez: 12-0, 797 | Parts: 22-12, 798 | Ways: 32-22; 799 | }; 800 | unsigned int BX; 801 | }; 802 | unsigned int Sets; 803 | union 804 | { 805 | struct 806 | { 807 | unsigned int 808 | WrBack: 1-0, 809 | Inclus: 2-1, 810 | Direct: 3-2, 811 | Resrvd: 32-3; 812 | }; 813 | unsigned int DX; 814 | }; 815 | unsigned int Size; 816 | } Cache[CACHE_MAX_LEVEL]; 817 | } TOPOLOGY; 818 | 819 | typedef struct { 820 | TOPOLOGY T; 821 | GLOBAL_PERF_COUNTER GlobalPerfCounter; 822 | FIXED_PERF_COUNTER FixedPerfCounter; 823 | struct { 824 | unsigned long long int 825 | INST[2]; 826 | struct 827 | { 828 | unsigned long long int 829 | UCC, 830 | URC; 831 | } C0[2]; 832 | unsigned long long int 833 | C3[2], 834 | C6[2], 835 | C7[2], 836 | TSC[2], 837 | C1[2]; 838 | } Cycles; 839 | struct { 840 | unsigned long long int 841 | INST; 842 | struct 843 | { 844 | unsigned long long int 845 | UCC, 846 | URC; 847 | } C0; 848 | unsigned long long int 849 | C3, 850 | C6, 851 | C7, 852 | TSC, 853 | C1; 854 | } Delta; 855 | double IPS, 856 | IPC, 857 | CPI; 858 | struct { 859 | double Turbo, 860 | C0, 861 | C3, 862 | C6, 863 | C7, 864 | C1; 865 | } State; 866 | double RelativeRatio, 867 | RelativeFreq; 868 | TJMAX TjMax; 869 | THERM_INTERRUPT ThermIntr; 870 | THERM_STATUS ThermStat; 871 | 872 | struct TASK_STRUCT 873 | { 874 | char state[8]; 875 | char comm[TASK_COMM_LEN]; 876 | long int pid; 877 | RUNTIME vruntime; 878 | long long int nvcsw; // sum of [non]voluntary context switch counts 879 | long int prio; 880 | RUNTIME exec_vruntime; // a duplicate of vruntime ? 881 | RUNTIME sum_exec_runtime; 882 | RUNTIME sum_sleep_runtime; 883 | long int node; 884 | char group_path[32]; // #define PATH_MAX 4096 # chars in a path name including nul 885 | } Task[TASK_PIPE_DEPTH]; 886 | 887 | signed int FD, 888 | Align64; 889 | } CPU_STRUCT; 890 | 891 | typedef struct 892 | { 893 | Bool64 MSR, 894 | RESET, 895 | SMBIOS, 896 | IMC, 897 | PROC; 898 | } PRIVILEGE_LEVEL; 899 | 900 | typedef struct 901 | { 902 | atomic_ullong IF; 903 | atomic_ullong Rooms; 904 | atomic_ullong Play; 905 | atomic_ullong Data; 906 | } SYNCHRONIZATION; 907 | 908 | typedef union 909 | { 910 | unsigned long long int Map64; 911 | struct { 912 | unsigned int Addr; 913 | unsigned short int Core; 914 | unsigned char Arg; 915 | unsigned char ID; 916 | } Map; 917 | } XCHG_MAP; 918 | 919 | typedef struct 920 | { 921 | char AppName[TASK_COMM_LEN]; 922 | SYNCHRONIZATION Sync; 923 | PRIVILEGE_LEVEL CPL; 924 | PROCESSOR P; 925 | ARCHITECTURE H; 926 | DUMP_STRUCT D; 927 | IMC_INFO M; 928 | SCHEDULE S; 929 | SMBIOS_TREE *B; 930 | CPU_STRUCT C[]; 931 | } SHM_STRUCT; 932 | 933 | #define ID_NULL 0x00 934 | #define ID_DONE 0x80 935 | #define ID_QUIT 0x7f 936 | #define ID_SCHED 0x7e 937 | #define ID_RESET 0x7d 938 | #define ID_TSC 0x7c 939 | #define ID_BIOS 0x7b 940 | #define ID_SPEC 0x7a 941 | #define ID_ROM 0x79 942 | #define ID_TSC_AUX 0x78 943 | #define ID_REFRESH 0x77 944 | #define ID_INCLOOP 0x76 945 | #define ID_DECLOOP 0x75 946 | #define ID_DUMPMSR 0x74 947 | #define ID_READMSR 0x73 948 | #define ID_WRITEMSR 0x72 949 | #define ID_CTLFEATURE 0x71 950 | 951 | #define CTL_NOP 0b00000000 952 | #define CTL_ENABLE 0b00000001 953 | #define CTL_DISABLE 0b10000000 954 | #define CTL_TURBO 0b00000010 955 | #define CTL_EIST 0b00000100 956 | #define CTL_C1E 0b00001000 957 | #define CTL_C3A 0b00010000 958 | #define CTL_C1A 0b00100000 959 | #define CTL_TCC 0b01000000 960 | 961 | #define SIG_EMERGENCY_FMT "\nShutdown(%02d)" 962 | #define TASK_PID_FMT "%5ld" 963 | 964 | extern unsigned int ROL32(unsigned int r32, unsigned short int m16); 965 | extern unsigned int ROR32(unsigned int r32, unsigned short int m16); 966 | /* extern unsigned long long int BT64(unsigned long long int r64, unsigned long long int i64); */ 967 | extern void abstimespec(useconds_t usec, struct timespec *tsec); 968 | extern int addtimespec(struct timespec *asec, const struct timespec *tsec); 969 | extern void Sync_Init(SYNCHRONIZATION *sync); 970 | extern void Sync_Destroy(SYNCHRONIZATION *sync); 971 | extern unsigned int Sync_Open(SYNCHRONIZATION *sync); 972 | extern void Sync_Close(unsigned int room, SYNCHRONIZATION *sync); 973 | extern long int Sync_Wait(unsigned int room, SYNCHRONIZATION *sync, useconds_t idleTime); 974 | extern void Sync_Signal(unsigned int room, SYNCHRONIZATION *sync); 975 | 976 | extern char *Smb_Find_String(struct STRUCTINFO *smb, int ID); 977 | -------------------------------------------------------------------------------- /api/xfreq-smbios.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-smbios.c by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2012-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "xfreq-smbios.h" 15 | 16 | struct STRING *SMB_Dig_Strings(struct PACKED *packed, int ID) 17 | { 18 | char *buffer=NULL; 19 | size_t rbyte=0; 20 | 21 | if(getdelim(&buffer, &rbyte, STRING_DELIMITER, packed->File) > 1) 22 | { 23 | unsigned int NodeSize=sizeof(struct STRING); 24 | struct STRING *pstr=malloc(NodeSize); 25 | 26 | pstr->Buffer=buffer; 27 | pstr->ID=++ID; 28 | pstr->Node.MemSize=NodeSize + strlen(pstr->Buffer) + 1; 29 | /* Verify sum */ 30 | if((pstr->Link=SMB_Dig_Strings(packed, ID)) == NULL) 31 | pstr->Node.MemSum=pstr->Node.MemSize; 32 | else 33 | pstr->Node.MemSum=pstr->Node.MemSize + pstr->Link->Node.MemSum; 34 | /* End of sum */ 35 | return(pstr); 36 | } 37 | else { 38 | free(buffer); 39 | return(NULL); 40 | } 41 | } 42 | 43 | struct STRING *SMB_Read_Strings(struct PACKED *packed) 44 | { 45 | return((packed->Length == 0) ? SMB_Dig_Strings(packed, 0) : NULL); 46 | } 47 | 48 | int SMB_Read_Length(struct PACKED *packed) 49 | { 50 | char pathName[]="/sys/firmware/dmi/entries/999-99/file1234567890"; 51 | 52 | sprintf(pathName, "/sys/firmware/dmi/entries/%d-%d/length", packed->Type, packed->Instance); 53 | if((packed->File=fopen(pathName, "r")) != NULL) 54 | { 55 | fscanf(packed->File, "%zd\n", &packed->Length); 56 | fclose(packed->File); 57 | packed->Length-=sizeof(struct HEADER); 58 | return(0); 59 | } 60 | else 61 | return(errno); 62 | } 63 | 64 | int SMB_Open_Structure(struct PACKED *packed) 65 | { 66 | char pathName[]="/sys/firmware/dmi/entries/999-99/file1234567890"; 67 | 68 | sprintf(pathName, "/sys/firmware/dmi/entries/%d-%d/raw", packed->Type, packed->Instance); 69 | if((packed->File=fopen(pathName, "rb")) == NULL) 70 | return(errno); 71 | else 72 | return(0); 73 | } 74 | 75 | int SMB_Close_Structure(struct PACKED *packed) 76 | { 77 | if(packed->File) 78 | { 79 | fclose(packed->File); 80 | packed->File=NULL; 81 | } 82 | return(errno); 83 | } 84 | 85 | struct STRUCTINFO *SMB_Read_Structure(struct PACKED *packed) 86 | { 87 | struct STRUCTINFO *smb=NULL; 88 | unsigned int StructSize=sizeof(struct STRUCTINFO), HeaderSize=sizeof(struct HEADER), AttribSize=0; 89 | 90 | if((smb=calloc(1, StructSize)) != NULL) 91 | { 92 | unsigned int head=0; 93 | 94 | fread(&smb->Header, HeaderSize, 1, packed->File); 95 | 96 | while(packed->Tape[head] != _EOT_) 97 | { 98 | unsigned long long int poly=0; 99 | 100 | AttribSize=(head + 1) * sizeof(unsigned long long int); 101 | smb->Attrib=realloc(smb->Attrib, AttribSize); 102 | fread(&poly, 0b0001 << packed->Tape[head], 1, packed->File); 103 | smb->Attrib[head]=poly; 104 | packed->Length-=0b0001 << packed->Tape[head]; 105 | poly=0; 106 | head++ ; 107 | } 108 | smb->Dimension=head; 109 | } 110 | /* Verify sum */ 111 | smb->Node.MemSize=StructSize + AttribSize; 112 | /* End of sum */ 113 | return(smb); 114 | } 115 | 116 | void SMB_Read_Extension(struct PACKED *packed, struct STRUCTINFO *smb) 117 | { 118 | unsigned int head=0; 119 | unsigned int StructSize=sizeof(struct STRUCTINFO), AttribSize=0; 120 | 121 | while((smb != NULL) && (packed->Tape[head] != _EOT_)) 122 | { 123 | unsigned long long int poly=0; 124 | 125 | AttribSize=(smb->Dimension + head + 1) * sizeof(unsigned long long int); 126 | smb->Attrib=realloc(smb->Attrib, AttribSize); 127 | fread(&poly, 0b0001 << packed->Tape[head], 1, packed->File); 128 | smb->Attrib[smb->Dimension + head]=poly; 129 | packed->Length-=0b0001 << packed->Tape[head]; 130 | poly=0; 131 | head++ ; 132 | } 133 | smb->Dimension+=head; 134 | /* Verify sum */ 135 | smb->Node.MemSize=StructSize + AttribSize; 136 | /* End of sum */ 137 | } 138 | 139 | void BIOS_Free_Structure(struct STRUCTINFO *smb) 140 | { 141 | if(smb != NULL) 142 | { 143 | struct STRING *Link=NULL, *pstr=NULL; 144 | 145 | pstr=smb->String; 146 | while(pstr != NULL) 147 | { 148 | Link=pstr->Link; 149 | free(pstr->Buffer); 150 | free(pstr); 151 | pstr=Link; 152 | }; 153 | smb->String=NULL; 154 | if(smb->Attrib) 155 | { 156 | free(smb->Attrib); 157 | smb->Attrib=NULL; 158 | } 159 | free(smb); 160 | smb=NULL; 161 | } 162 | } 163 | 164 | struct BIOSINFO *BIOS_Read_Info(void) 165 | { 166 | const int tape[]=SMBIOS_BIOSINFO_PACKED; 167 | struct PACKED packed={SMBIOS_BIOSINFO_TYPE, SMBIOS_BIOSINFO_INSTANCE, NULL, 0, &tape[0]}; 168 | struct STRUCTINFO *smb=NULL; 169 | 170 | if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed)) 171 | { 172 | smb=SMB_Read_Structure(&packed); 173 | smb->String=SMB_Read_Strings(&packed); 174 | SMB_Close_Structure(&packed); 175 | /* Verify sum */ 176 | if(smb->String == NULL) 177 | smb->Node.MemSum=smb->Node.MemSize; 178 | else 179 | smb->Node.MemSum=smb->Node.MemSize + smb->String->Node.MemSum; 180 | /* End of sum */ 181 | } 182 | return((struct BIOSINFO*) smb); 183 | } 184 | 185 | struct BOARDINFO *BOARD_Read_Info(void) 186 | { 187 | const int tape[]=SMBIOS_BOARDINFO_PACKED, 188 | extens[]=SMBIOS_BOARDINFO_EXTENS; 189 | struct PACKED packed={SMBIOS_BOARDINFO_TYPE, SMBIOS_BOARDINFO_INSTANCE, NULL, 0, &tape[0]}; 190 | struct STRUCTINFO *smb=NULL; 191 | 192 | if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed)) 193 | { 194 | smb=SMB_Read_Structure(&packed); 195 | if(smb->Attrib[9] > 0) 196 | { 197 | packed.Tape=&extens[0]; 198 | while(packed.Length > 0) 199 | SMB_Read_Extension(&packed, smb); 200 | } 201 | smb->String=SMB_Read_Strings(&packed); 202 | SMB_Close_Structure(&packed); 203 | /* Verify sum */ 204 | if(smb->String == NULL) 205 | smb->Node.MemSum=smb->Node.MemSize; 206 | else 207 | smb->Node.MemSum=smb->Node.MemSize + smb->String->Node.MemSum; 208 | /* End of sum */ 209 | } 210 | return((struct BOARDINFO*) smb); 211 | } 212 | 213 | struct PROCINFO *PROC_Read_Info(void) 214 | { 215 | const int tape[]=SMBIOS_PROCINFO_PACKED, 216 | extens[]=SMBIOS_PROCINFO_EXTENS; 217 | struct PACKED packed={SMBIOS_PROCINFO_TYPE, SMBIOS_PROCINFO_INSTANCE, NULL, 0, &tape[0]}; 218 | struct STRUCTINFO *smb=NULL; 219 | 220 | if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed)) 221 | { 222 | smb=SMB_Read_Structure(&packed); 223 | if(packed.Length > 0) 224 | { 225 | packed.Tape=&extens[0]; 226 | SMB_Read_Extension(&packed, smb); 227 | } 228 | smb->String=SMB_Read_Strings(&packed); 229 | SMB_Close_Structure(&packed); 230 | /* Verify sum */ 231 | if(smb->String == NULL) 232 | smb->Node.MemSum=smb->Node.MemSize; 233 | else 234 | smb->Node.MemSum=smb->Node.MemSize + smb->String->Node.MemSum; 235 | /* End of sum */ 236 | } 237 | return((struct PROCINFO*) smb); 238 | } 239 | 240 | struct CACHEINFO *CACHE_Read_Info(int instance) 241 | { 242 | const int tape[]=SMBIOS_CACHEINFO_PACKED; 243 | struct PACKED packed={SMBIOS_CACHEINFO_TYPE, instance, NULL, 0, &tape[0]}; 244 | struct STRUCTINFO *smb=NULL; 245 | 246 | if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed)) 247 | { 248 | smb=SMB_Read_Structure(&packed); 249 | smb->String=SMB_Read_Strings(&packed); 250 | SMB_Close_Structure(&packed); 251 | /* Verify sum */ 252 | if(smb->String == NULL) 253 | smb->Node.MemSum=smb->Node.MemSize; 254 | else 255 | smb->Node.MemSum=smb->Node.MemSize + smb->String->Node.MemSum; 256 | /* End of sum */ 257 | } 258 | return((struct CACHEINFO*) smb); 259 | } 260 | 261 | struct MEMARRAY *MEM_Read_Array(void) 262 | { 263 | const int tape[]=SMBIOS_MEMARRAY_PACKED, 264 | extens[]=SMBIOS_MEMARRAY_EXTENS; 265 | struct PACKED packed={SMBIOS_MEMARRAY_TYPE, SMBIOS_MEMARRAY_INSTANCE, NULL, 0, &tape[0]}; 266 | struct STRUCTINFO *smb=NULL; 267 | 268 | if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed)) 269 | { 270 | smb=SMB_Read_Structure(&packed); 271 | if(packed.Length > 0) 272 | { 273 | packed.Tape=&extens[0]; 274 | SMB_Read_Extension(&packed, smb); 275 | } 276 | smb->String=SMB_Read_Strings(&packed); 277 | SMB_Close_Structure(&packed); 278 | /* Verify sum */ 279 | if(smb->String == NULL) 280 | smb->Node.MemSum=smb->Node.MemSize; 281 | else 282 | smb->Node.MemSum=smb->Node.MemSize + smb->String->Node.MemSum; 283 | /* End of sum */ 284 | } 285 | return((struct MEMARRAY*) smb); 286 | } 287 | 288 | struct MEMDEV *MEM_Read_Device(int instance) 289 | { 290 | const int tape[]=SMBIOS_MEMDEV_PACKED, 291 | extens[]=SMBIOS_MEMDEV_EXTENS; 292 | struct PACKED packed={SMBIOS_MEMDEV_TYPE, instance, NULL, 0, &tape[0]}; 293 | struct STRUCTINFO *smb=NULL; 294 | 295 | if(!SMB_Read_Length(&packed) && !SMB_Open_Structure(&packed)) 296 | { 297 | smb=SMB_Read_Structure(&packed); 298 | if(packed.Length > 0) 299 | { 300 | packed.Tape=&extens[0]; 301 | SMB_Read_Extension(&packed, smb); 302 | } 303 | smb->String=SMB_Read_Strings(&packed); 304 | SMB_Close_Structure(&packed); 305 | /* Verify sum */ 306 | if(smb->String == NULL) 307 | smb->Node.MemSum=smb->Node.MemSize; 308 | else 309 | smb->Node.MemSum=smb->Node.MemSize + smb->String->Node.MemSum; 310 | /* End of sum */ 311 | } 312 | return((struct MEMDEV*) smb); 313 | } 314 | 315 | struct MEMDEV **MEM_ReadAll_Devices(struct MEMARRAY *memArray) 316 | { 317 | struct MEMDEV **memory=NULL; 318 | 319 | if(memArray != NULL) 320 | { 321 | unsigned int arraySize=sizeof(struct MEMDEV*) * memArray->Attrib->Number_Devices; 322 | memory=malloc(arraySize); 323 | 324 | int stick=0; 325 | for(stick=0; stick < memArray->Attrib->Number_Devices; stick++) 326 | memory[stick]=MEM_Read_Device(stick); 327 | } 328 | return(memory); 329 | } 330 | 331 | void MEM_FreeAll_Devices(struct MEMDEV **memory, struct MEMARRAY *memArray) 332 | { 333 | if(memArray != NULL) 334 | { 335 | int stick=0; 336 | for(stick=0; stick < memArray->Attrib->Number_Devices; stick++) 337 | BIOS_Free_Structure((struct STRUCTINFO*) memory[stick]); 338 | 339 | free(memory); 340 | memory=NULL; 341 | } 342 | } 343 | 344 | Bool32 Init_SMBIOS(SMBIOS_TREE *Smb) 345 | { 346 | if(Smb != NULL) 347 | { 348 | /* Verify sum */ 349 | Smb->Node.MemSize=sizeof(SMBIOS_TREE); 350 | /* End of sum */ 351 | // Read the full SMBIOS tree. 352 | if((Smb->Bios=BIOS_Read_Info()) 353 | && (Smb->Board=BOARD_Read_Info()) 354 | && (Smb->Proc=PROC_Read_Info()) 355 | && (Smb->Cache[0]=CACHE_Read_Info(0)) && (Smb->Cache[1]=CACHE_Read_Info(1)) && (Smb->Cache[2]=CACHE_Read_Info(2)) 356 | && (Smb->MemArray=MEM_Read_Array()) 357 | && (Smb->Memory=MEM_ReadAll_Devices(Smb->MemArray))) 358 | { 359 | /* Verify sum */ 360 | Smb->Node.MemSize+=sizeof(struct MEMDEV*) * Smb->MemArray->Attrib->Number_Devices; 361 | Smb->Node.MemSum= Smb->Node.MemSize \ 362 | + Smb->Bios->Node.MemSum \ 363 | + Smb->Board->Node.MemSum \ 364 | + Smb->Proc->Node.MemSum \ 365 | + Smb->Cache[0]->Node.MemSum \ 366 | + Smb->Cache[1]->Node.MemSum \ 367 | + Smb->Cache[2]->Node.MemSum \ 368 | + Smb->MemArray->Node.MemSum; 369 | int stick=0; 370 | for(stick=0; stick < Smb->MemArray->Attrib->Number_Devices; stick++) 371 | Smb->Node.MemSum+=Smb->Memory[stick]->Node.MemSum; 372 | /* End of sum */ 373 | return(TRUE); 374 | } 375 | else 376 | return(FALSE); 377 | } 378 | else 379 | return(FALSE); 380 | } 381 | 382 | Bool32 Close_SMBIOS(SMBIOS_TREE *Smb) 383 | { 384 | if(Smb != NULL) 385 | { // Release the SMBIOS tree. 386 | MEM_FreeAll_Devices(Smb->Memory, Smb->MemArray); 387 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->MemArray); 388 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->Cache[2]); 389 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->Cache[1]); 390 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->Cache[0]); 391 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->Proc); 392 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->Board); 393 | BIOS_Free_Structure((struct STRUCTINFO*) Smb->Bios); 394 | return(TRUE); 395 | } 396 | else 397 | return(FALSE); 398 | } 399 | 400 | PADDR Copy_SmbString(PADDR pSrc, PADDR pAddr) 401 | { 402 | struct STRING *pStrSrc=pSrc, 403 | *pStrDest=pAddr; 404 | PADDR retAddr=pAddr; 405 | 406 | const unsigned int op1=sizeof(struct STRING); 407 | 408 | pStrDest->ID=pStrSrc->ID; 409 | 410 | retAddr+=op1; 411 | 412 | if(pStrSrc->Buffer != NULL) 413 | { 414 | const unsigned int op2=strlen(pStrSrc->Buffer) + 1; 415 | 416 | pStrDest->Buffer=retAddr; 417 | strncpy(pStrDest->Buffer, pStrSrc->Buffer, op2); 418 | 419 | retAddr+=op2; 420 | } 421 | else 422 | { 423 | pStrDest->Buffer=NULL; 424 | } 425 | /* Verify sum */ 426 | pStrDest->Node.MemSize=retAddr - pAddr; 427 | /* End of sum */ 428 | if(pStrSrc->Link != NULL) 429 | { 430 | pStrDest->Link=retAddr; 431 | retAddr=Copy_SmbString(pStrSrc->Link, retAddr); 432 | /* Verify sum */ 433 | pStrDest->Node.MemSum=pStrDest->Node.MemSize + pStrDest->Link->Node.MemSum; 434 | /* End of sum */ 435 | } 436 | else 437 | { 438 | pStrDest->Link=NULL; 439 | /* Verify sum */ 440 | pStrDest->Node.MemSum=pStrDest->Node.MemSize; 441 | /* End of sum */ 442 | } 443 | return(retAddr); 444 | } 445 | 446 | PADDR Copy_SmbStruct(PADDR pSrc, PADDR pAddr) 447 | { 448 | struct STRUCTINFO *pSiSrc=pSrc, 449 | *pSiDest=pAddr; 450 | PADDR retAddr=pAddr; 451 | 452 | const unsigned int op1=sizeof(struct STRUCTINFO); 453 | 454 | pSiDest->Header.Type=pSiSrc->Header.Type; 455 | pSiDest->Header.Length=pSiSrc->Header.Length; 456 | pSiDest->Header.Handle=pSiSrc->Header.Handle; 457 | pSiDest->Dimension=pSiSrc->Dimension; 458 | 459 | retAddr+=op1; 460 | 461 | if(pSiSrc->Attrib != NULL) 462 | { 463 | const unsigned int op2=sizeof(PADDR), op3=pSiSrc->Dimension * op2; 464 | 465 | pSiDest->Attrib=retAddr; 466 | 467 | unsigned int ix=0; 468 | for(ix=0; ix < pSiSrc->Dimension; ix++) 469 | pSiDest->Attrib[ix]=pSiSrc->Attrib[ix]; 470 | 471 | retAddr+=op3; 472 | } 473 | else 474 | { 475 | pSiDest->Attrib=NULL; 476 | } 477 | /* Verify sum */ 478 | pSiDest->Node.MemSize=retAddr - pAddr; 479 | /* End of sum */ 480 | if(pSiSrc->String != NULL) 481 | { 482 | pSiDest->String=retAddr; 483 | retAddr=Copy_SmbString(pSiSrc->String, retAddr); 484 | /* Verify sum */ 485 | pSiDest->Node.MemSum=pSiDest->Node.MemSize + pSiDest->String->Node.MemSum; 486 | /* End of sum */ 487 | } 488 | else 489 | { 490 | pSiDest->String=NULL; 491 | /* Verify sum */ 492 | pSiDest->Node.MemSum=pSiDest->Node.MemSize; 493 | /* End of sum */ 494 | } 495 | return(retAddr); 496 | } 497 | 498 | Bool32 Copy_SmbTree(SMBIOS_TREE *SmbSrc, SMBIOS_TREE *SmbDest) 499 | { 500 | if((SmbSrc != NULL) && (SmbDest != NULL)) 501 | { 502 | PADDR pAddr=(PADDR) &SmbDest[1]; 503 | 504 | /* Verify sum */ 505 | SmbDest->Node.MemSize=pAddr - (PADDR) SmbDest; 506 | /* End of sum */ 507 | 508 | SmbDest->Bios=(struct BIOSINFO *) pAddr; 509 | pAddr=Copy_SmbStruct((PADDR) SmbSrc->Bios, pAddr); 510 | 511 | SmbDest->Board=(struct BOARDINFO *) pAddr; 512 | pAddr=Copy_SmbStruct((PADDR) SmbSrc->Board, pAddr); 513 | 514 | SmbDest->Proc=(struct PROCINFO *) pAddr; 515 | pAddr=Copy_SmbStruct((PADDR) SmbSrc->Proc, pAddr); 516 | 517 | SmbDest->Cache[0]=(struct CACHEINFO *) pAddr; 518 | pAddr=Copy_SmbStruct((struct STRUCTINFO *) SmbSrc->Cache[0], pAddr); 519 | 520 | SmbDest->Cache[1]=(struct CACHEINFO *) pAddr; 521 | pAddr=Copy_SmbStruct((struct STRUCTINFO *) SmbSrc->Cache[1], pAddr); 522 | 523 | SmbDest->Cache[2]=(struct CACHEINFO *) pAddr; 524 | pAddr=Copy_SmbStruct((struct STRUCTINFO *) SmbSrc->Cache[2], pAddr); 525 | 526 | SmbDest->MemArray=(struct MEMARRAY *) pAddr; 527 | pAddr=Copy_SmbStruct((struct STRUCTINFO *) SmbSrc->MemArray, pAddr); 528 | 529 | SmbDest->Memory=(struct MEMDEV **) pAddr; 530 | if(SmbSrc->MemArray->Attrib->Number_Devices > 0) 531 | { 532 | const unsigned int op1=sizeof(PADDR), op2=op1 * SmbSrc->MemArray->Attrib->Number_Devices; 533 | pAddr+=op2; 534 | 535 | unsigned int stick=0; 536 | for(stick=0; stick < SmbSrc->MemArray->Attrib->Number_Devices; stick++) 537 | { 538 | SmbDest->Memory[stick]=(struct MEMDEV *) pAddr; 539 | pAddr=Copy_SmbStruct((struct STRUCTINFO *) SmbSrc->Memory[stick], pAddr); 540 | } 541 | /* Verify sum */ 542 | SmbDest->Node.MemSize+=op2; 543 | /* End of sum */ 544 | } 545 | /* Verify sum */ 546 | SmbDest->Node.MemSum = SmbDest->Node.MemSize \ 547 | + SmbDest->Bios->Node.MemSum \ 548 | + SmbDest->Board->Node.MemSum \ 549 | + SmbDest->Proc->Node.MemSum \ 550 | + SmbDest->Cache[0]->Node.MemSum \ 551 | + SmbDest->Cache[1]->Node.MemSum \ 552 | + SmbDest->Cache[2]->Node.MemSum \ 553 | + SmbDest->MemArray->Node.MemSum; 554 | int stick=0; 555 | for(stick=0; stick < SmbDest->MemArray->Attrib->Number_Devices; stick++) 556 | SmbDest->Node.MemSum+=SmbDest->Memory[stick]->Node.MemSum; 557 | /* End of sum */ 558 | return(SmbDest->Node.MemSum == SmbSrc->Node.MemSum); 559 | } 560 | else 561 | return(FALSE); 562 | } 563 | -------------------------------------------------------------------------------- /api/xfreq-smbios.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-smbios.h by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2012-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | 10 | #include 11 | 12 | #include "xfreq-types.h" 13 | 14 | // System Management BIOS (SMBIOS) Reference Specification 15 | // Version: 2.7.1 § 7.5 16 | 17 | struct HEADER 18 | { 19 | unsigned int 20 | Type : 8, 21 | Length : 8, 22 | Handle : 16; 23 | }; 24 | 25 | struct NODE 26 | { 27 | unsigned int MemSize, 28 | MemSum; 29 | }; 30 | 31 | #define STRING_DELIMITER 0 32 | 33 | struct STRING 34 | { 35 | long int ID; 36 | char *Buffer; 37 | struct STRING *Link; 38 | struct NODE Node; 39 | }; 40 | 41 | struct STRUCTINFO 42 | { 43 | struct HEADER Header; 44 | unsigned int Dimension; 45 | unsigned long long int *Attrib; 46 | struct STRING *String; 47 | struct NODE Node; 48 | }; 49 | 50 | struct PACKED 51 | { 52 | const int Type; 53 | const int Instance; 54 | FILE *File; 55 | size_t Length; 56 | const int *Tape; 57 | }; 58 | 59 | #define _B_ 0 60 | #define _W_ 1 61 | #define _D_ 2 62 | #define _Q_ 3 63 | #define _S_ , 64 | #define _EOT_ -1 65 | 66 | #define SMBIOS_BIOSINFO_TYPE 0 67 | #define SMBIOS_BIOSINFO_INSTANCE 0 68 | 69 | #define SMBIOS_BIOSINFO_PACKED {_B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_} 70 | 71 | struct SMBIOS0 72 | { 73 | unsigned long long int 74 | Vendor, 75 | Version, 76 | Address, 77 | Release_Date, 78 | ROM_Size, 79 | Characteristics, 80 | Extension_Bytes, 81 | Major_Release, 82 | Minor_Release, 83 | Firmware_Major, 84 | Firmware_Minor; 85 | }; 86 | 87 | struct BIOSINFO 88 | { 89 | struct HEADER Header; 90 | unsigned int Dimension; 91 | struct SMBIOS0 *Attrib; 92 | struct STRING *String; 93 | struct NODE Node; 94 | }; 95 | 96 | 97 | #define SMBIOS_BOARDINFO_TYPE 2 98 | #define SMBIOS_BOARDINFO_INSTANCE 0 99 | /* 100 | * Spec. for a multi motherboard 101 | #define SMBIOS_BOARDINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _EOT_} 102 | 103 | * The ASUS Rampage II Gene is a single motherboard 104 | */ 105 | #define SMBIOS_BOARDINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _EOT_} 106 | #define SMBIOS_BOARDINFO_EXTENS {_W_ _S_ _EOT_} 107 | 108 | struct SMBIOS2 109 | { 110 | unsigned long long int 111 | Manufacturer, 112 | Product, 113 | Version, 114 | Serial, 115 | AssetTag, 116 | Feature, 117 | Location, 118 | Chassis_Handle, 119 | Board_Type, 120 | Number_Object, 121 | Object_Handles; 122 | // Use Attrib[10] to Attrib[265] to read the list of the 255 object handles 123 | }; 124 | 125 | struct BOARDINFO 126 | { 127 | struct HEADER Header; 128 | unsigned int Dimension; 129 | struct SMBIOS2 *Attrib; 130 | struct STRING *String; 131 | struct NODE Node; 132 | }; 133 | 134 | 135 | #define SMBIOS_PROCINFO_TYPE 4 136 | #define SMBIOS_PROCINFO_INSTANCE 0 137 | /* 138 | * Spec. Version 2.6+ 139 | #define SMBIOS_PROCINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _EOT_} 140 | 141 | * The SMBIOS version of the ASUS Rampage II Gene is a 2.5 142 | */ 143 | #define SMBIOS_PROCINFO_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _Q_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _EOT_} 144 | #define SMBIOS_PROCINFO_EXTENS {_W_ _S_ _EOT_} 145 | 146 | struct SMBIOS4 147 | { 148 | unsigned long long int 149 | Socket, 150 | ProcType, 151 | Family, 152 | Manufacturer; 153 | struct 154 | { 155 | unsigned int 156 | EAX : 32-0, 157 | EDX : 64-32; 158 | } CPUID_0x01; 159 | unsigned long long int 160 | Version; 161 | struct 162 | { 163 | unsigned long int 164 | Tension : 7-0, 165 | Mode : 8-7, 166 | Unused : 64-8; 167 | } Voltage; 168 | unsigned long long int 169 | Clock, 170 | MaxSpeed, 171 | CurrentSpeed, 172 | Populated, 173 | Upgrade, 174 | L1_Cache_Handle, 175 | L2_Cache_Handle, 176 | L3_Cache_Handle, 177 | Serial, 178 | AssetTag, 179 | PartNumber, 180 | CoreCount, 181 | CoreEnabled, 182 | ThreadCount, 183 | Characteristics, 184 | Family2; 185 | }; 186 | 187 | struct PROCINFO 188 | { 189 | struct HEADER Header; 190 | unsigned int Dimension; 191 | struct SMBIOS4 *Attrib; 192 | struct STRING *String; 193 | struct NODE Node; 194 | }; 195 | 196 | 197 | #define SMBIOS_CACHEINFO_TYPE 7 198 | 199 | #define SMBIOS_CACHEINFO_PACKED {_B_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_} 200 | 201 | struct SMBIOS7 202 | { 203 | unsigned long long int 204 | Socket, 205 | Configuration, 206 | Maximum_Size, 207 | Installed_Size, 208 | Supported_SRAM, 209 | Current_SRAM, 210 | Cache_Speed, 211 | Error_Correction, 212 | System_Cache, 213 | Associativity; 214 | }; 215 | 216 | struct CACHEINFO 217 | { 218 | struct HEADER Header; 219 | unsigned int Dimension; 220 | struct SMBIOS7 *Attrib; 221 | struct STRING *String; 222 | struct NODE Node; 223 | }; 224 | 225 | 226 | #define SMBIOS_MEMARRAY_TYPE 16 227 | #define SMBIOS_MEMARRAY_INSTANCE 0 228 | 229 | #define SMBIOS_MEMARRAY_PACKED {_B_ _S_ _B_ _S_ _B_ _S_ _D_ _S_ _W_ _S_ _W_ _S_ _EOT_} 230 | #define SMBIOS_MEMARRAY_EXTENS {_Q_ _S_ _EOT_} 231 | 232 | struct SMBIOS16 233 | { 234 | unsigned long long int 235 | Location, 236 | Use, 237 | Error_Correction, 238 | Maximum_Capacity, 239 | Error_Handle, 240 | Number_Devices, 241 | Extended_Capacity; 242 | }; 243 | 244 | struct MEMARRAY 245 | { 246 | struct HEADER Header; 247 | unsigned int Dimension; 248 | struct SMBIOS16 *Attrib; 249 | struct STRING *String; 250 | struct NODE Node; 251 | }; 252 | 253 | 254 | #define SMBIOS_MEMDEV_TYPE 17 255 | 256 | #define SMBIOS_MEMDEV_PACKED {_W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _W_ _S_ _W_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _B_ _S_ _EOT_} 257 | #define SMBIOS_MEMDEV_EXTENS {_B_ _S_ _D_ _S_ _W_ _S_ _EOT_} 258 | 259 | struct SMBIOS17 260 | { 261 | unsigned long long int 262 | MemArray_Handle, 263 | Error_Handle, 264 | Total_Width, 265 | Data_Width, 266 | Size, 267 | Form_Factor, 268 | Set, 269 | Socket, 270 | Bank, 271 | Mem_Type, 272 | Mem_Detail, 273 | Speed, 274 | Manufacturer, 275 | Serial, 276 | AssetTag, 277 | PartNumber, 278 | Attributes, 279 | Extended_Size, 280 | Clock_Speed; 281 | }; 282 | 283 | struct MEMDEV 284 | { 285 | struct HEADER Header; 286 | unsigned int Dimension; 287 | struct SMBIOS17 *Attrib; 288 | struct STRING *String; 289 | struct NODE Node; 290 | }; 291 | 292 | 293 | typedef struct 294 | { 295 | struct BIOSINFO *Bios; 296 | struct BOARDINFO *Board; 297 | struct PROCINFO *Proc; 298 | struct CACHEINFO *Cache[3]; 299 | struct MEMARRAY *MemArray; 300 | struct MEMDEV **Memory; 301 | struct NODE Node; 302 | } SMBIOS_TREE; 303 | 304 | typedef void* PADDR; 305 | 306 | extern Bool32 Init_SMBIOS(SMBIOS_TREE *Smb); 307 | extern Bool32 Close_SMBIOS(SMBIOS_TREE *Smb); 308 | extern Bool32 Copy_SmbTree(SMBIOS_TREE *SmbSrc, SMBIOS_TREE *SmbDest); 309 | -------------------------------------------------------------------------------- /api/xfreq-types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-types.h by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | 10 | #define TRUE 1 11 | #define FALSE 0 12 | 13 | typedef unsigned long long int Bool64; 14 | typedef unsigned int Bool32; 15 | 16 | #define ToStr(_inst) _ToStr(_inst) 17 | #define _ToStr(_inst) #_inst 18 | 19 | #if defined(DEBUG) 20 | #define tracerr(anystr) fprintf(stderr, "%s\n", anystr); 21 | #else 22 | #define tracerr(anystr) 23 | #endif 24 | 25 | #if defined(Linux) 26 | #define MAX(M, m) ((M) > (m) ? (M) : (m)) 27 | #define MIN(m, M) ((m) < (M) ? (m) : (M)) 28 | #endif 29 | 30 | #define BT64(r64, i32) ((r64 & (unsigned long long int) 1 << i32) >> i32) 31 | -------------------------------------------------------------------------------- /cli/Makefile: -------------------------------------------------------------------------------- 1 | export CC 2 | CFLAGS = -Wall -pthread -x c 3 | KERNEL = `uname -s` 4 | APP_NAME=xfreq-cli 5 | SRC_PATH=. 6 | OBJ_PATH=./obj 7 | BIN_PATH=./bin 8 | INC4x86_PATH=-I ../api 9 | LIB4x86_FLAGS=-lpthread -lrt ../api/obj/xfreq-api.o 10 | # 11 | all : $(APP_NAME) 12 | # 13 | help : 14 | @echo 'make [all] : Compile, link and store executable file in' $(BIN_PATH)/$(APP_NAME) 15 | @echo 'make clean : Remove object and binary files.' 16 | @echo 'make clean-all : Remove object and binary sub-directories.' 17 | # 18 | clean : 19 | @echo 'Cleaning ...' 20 | @if [ -e $(BIN_PATH)/$(APP_NAME) ]; then rm -v $(BIN_PATH)/$(APP_NAME); else echo 'Nothing to do in '$(BIN_PATH); fi 21 | @if [ -e $(OBJ_PATH)/$(APP_NAME).o ]; then rm -v $(OBJ_PATH)/$(APP_NAME).o; else echo 'Nothing to do in '$(OBJ_PATH); fi 22 | # 23 | clean-all: 24 | @echo 'Cleaning all ...' 25 | @if [ -d $(BIN_PATH) ]; then rm -vr $(BIN_PATH); else echo 'Nothing to do in '$(BIN_PATH); fi 26 | @if [ -d $(OBJ_PATH) ]; then rm -vr $(OBJ_PATH); else echo 'Nothing to do in '$(OBJ_PATH); fi 27 | # 28 | $(APP_NAME) : $(APP_NAME).o 29 | @if [ ! -d $(BIN_PATH) ]; then mkdir $(BIN_PATH); fi 30 | $(CC) $(OBJ_PATH)/$(APP_NAME).o $(LIB4x86_FLAGS) -o $(BIN_PATH)/$(APP_NAME) 31 | # 32 | $(APP_NAME).o : $(APP_NAME).c 33 | @if [ ! -d $(OBJ_PATH) ]; then mkdir $(OBJ_PATH); fi 34 | $(CC) -D$(KERNEL) $(CFLAGS) -c $(APP_NAME).c $(INC4x86_PATH) -o $(OBJ_PATH)/$(APP_NAME).o 35 | -------------------------------------------------------------------------------- /cli/XFreq-Cli-FreeBSD.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 45 | 46 | -------------------------------------------------------------------------------- /cli/XFreq-Cli.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 46 | 47 | -------------------------------------------------------------------------------- /cli/xfreq-cli.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-cli.c by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | #define _GNU_SOURCE 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #if defined(FreeBSD) 27 | #include 28 | #endif 29 | 30 | #define _APPNAME "XFreq-Client" 31 | 32 | #include "xfreq-types.h" 33 | #include "xfreq-smbios.h" 34 | #include "xfreq-api.h" 35 | #include "xfreq-cli.h" 36 | 37 | static char Version[] = AutoDate; 38 | 39 | 40 | void Play(uARG *A, char ID) 41 | { 42 | switch(ID) 43 | { 44 | case ID_QUIT: 45 | { 46 | A->LOOP=FALSE; 47 | } 48 | break; 49 | } 50 | } 51 | 52 | static void *uRead_Freq(void *uArg) 53 | { 54 | uARG *A=(uARG *) uArg; 55 | pthread_setname_np(A->TID_Read, "xfreq-cli-read"); 56 | 57 | long int idleRemaining; 58 | while(A->LOOP) 59 | if((idleRemaining=Sync_Wait(A->Room, &A->SHM->Sync, IDLE_COEF_MAX + IDLE_COEF_DEF + IDLE_COEF_MIN))) 60 | { 61 | printf("\nCPU# F=%6.2f x R Temp IPS IPC CPI\tTask scheduling\n", A->SHM->P.ClockSpeed); 62 | int cpu=0; 63 | for(cpu=0; cpu < A->SHM->P.CPU; cpu++) 64 | if(A->SHM->C[cpu].T.Offline != TRUE) 65 | printf( "%3d %7.2f %5.2f %3d %5.2f %5.2f %5.2f %15s(%5ld)\n", 66 | cpu, 67 | A->SHM->C[cpu].RelativeFreq, 68 | A->SHM->C[cpu].RelativeRatio, 69 | A->SHM->C[cpu].TjMax.Target - A->SHM->C[cpu].ThermStat.DTS, 70 | A->SHM->C[cpu].IPS, 71 | A->SHM->C[cpu].IPC, 72 | A->SHM->C[cpu].CPI, 73 | A->SHM->C[cpu].Task[0].comm, A->SHM->C[cpu].Task[0].pid); 74 | 75 | printf( "\nAverage C-states\n" \ 76 | "Turbo\t C0\t C1\t C3\t C6\t C7\n" \ 77 | "%6.2f%%\t%6.2f%%\t%6.2f%%\t%6.2f\t%6.2f%%\t%6.2f%%\n", 78 | 100.f * A->SHM->P.Avg.Turbo, 79 | 100.f * A->SHM->P.Avg.C0, 80 | 100.f * A->SHM->P.Avg.C1, 81 | 100.f * A->SHM->P.Avg.C3, 82 | 100.f * A->SHM->P.Avg.C6, 83 | 100.f * A->SHM->P.Avg.C7); 84 | } 85 | else 86 | Play(A, ID_QUIT); 87 | return(NULL); 88 | } 89 | 90 | static void *uRead_States(void *uArg) 91 | { 92 | uARG *A=(uARG *) uArg; 93 | pthread_setname_np(A->TID_Read, "xfreq-cli-read"); 94 | 95 | long int idleRemaining; 96 | while(A->LOOP) 97 | if((idleRemaining=Sync_Wait(A->Room, &A->SHM->Sync, IDLE_COEF_MAX + IDLE_COEF_DEF + IDLE_COEF_MIN))) 98 | { 99 | printf("\nCPU# UCC URC C1 C3 C6 C7 TSC\n"); 100 | 101 | int cpu=0; 102 | for(cpu=0; cpu < A->SHM->P.CPU; cpu++) 103 | if(A->SHM->C[cpu].T.Offline != TRUE) 104 | printf( "%-3d %20lld %20lld %20lld %20lld %20lld %20lld %20lld\n", 105 | cpu, 106 | A->SHM->C[cpu].Delta.C0.UCC, 107 | A->SHM->C[cpu].Delta.C0.URC, 108 | A->SHM->C[cpu].Delta.C1, 109 | A->SHM->C[cpu].Delta.C3, 110 | A->SHM->C[cpu].Delta.C6, 111 | A->SHM->C[cpu].Delta.C7, 112 | A->SHM->C[cpu].Delta.TSC); 113 | } 114 | else 115 | Play(A, ID_QUIT); 116 | return(NULL); 117 | } 118 | 119 | static void *uRead_Inst(void *uArg) 120 | { 121 | uARG *A=(uARG *) uArg; 122 | pthread_setname_np(A->TID_Read, "xfreq-cli-read"); 123 | 124 | long int idleRemaining; 125 | while(A->LOOP) 126 | if((idleRemaining=Sync_Wait(A->Room, &A->SHM->Sync, IDLE_COEF_MAX + IDLE_COEF_DEF + IDLE_COEF_MIN))) 127 | { 128 | printf("\nCPU# INST UCC URC TSC\n"); 129 | 130 | int cpu=0; 131 | for(cpu=0; cpu < A->SHM->P.CPU; cpu++) 132 | if(A->SHM->C[cpu].T.Offline != TRUE) 133 | printf( "%-3d %20lld %20lld %20lld %20lld\n", 134 | cpu, 135 | A->SHM->C[cpu].Delta.INST, 136 | A->SHM->C[cpu].Delta.C0.UCC, 137 | A->SHM->C[cpu].Delta.C0.URC, 138 | A->SHM->C[cpu].Delta.TSC); 139 | } 140 | else 141 | Play(A, ID_QUIT); 142 | return(NULL); 143 | } 144 | 145 | // Load settings 146 | char *FQN_Settings(const char *fName) 147 | { 148 | char *Home=getenv("HOME"); 149 | if(Home != NULL) 150 | { 151 | char *lHome=strdup(Home), 152 | *rHome=strdup(Home), 153 | *dName=dirname(lHome), 154 | *bName=basename(rHome), 155 | *FQN=malloc(4096); 156 | 157 | if(!strcmp(dName, "/")) 158 | sprintf(FQN, "%s%s/%s", dName, bName, fName); 159 | else 160 | sprintf(FQN, "%s/%s/%s", dName, bName, fName); 161 | 162 | free(lHome); 163 | free(rHome); 164 | 165 | return(FQN); 166 | } 167 | return(NULL); 168 | } 169 | 170 | int ScanOptions(uARG *A, int argc, char *argv[]) 171 | { 172 | int i=0, j=0; 173 | Bool32 noerr=TRUE; 174 | 175 | // Parse the command line options which may override settings. 176 | if( (argc - ((argc >> 1) << 1)) ) 177 | { 178 | for(j=1; j < argc; j+=2) 179 | { 180 | for(i=0; i < OPTIONS_COUNT; i++) 181 | if(A->Options[i].pointer && !strcmp(argv[j], A->Options[i].argument)) 182 | { 183 | sscanf(argv[j+1], A->Options[i].format, A->Options[i].pointer); 184 | break; 185 | } 186 | if(i == OPTIONS_COUNT) 187 | { 188 | noerr=FALSE; 189 | break; 190 | } 191 | } 192 | } 193 | else 194 | noerr=FALSE; 195 | 196 | if(noerr == FALSE) 197 | { 198 | char *program=strdup(argv[0]), 199 | *progName=basename(program); 200 | 201 | if(!strcmp(argv[1], "-h")) 202 | { 203 | printf( _APPNAME" ""usage:\n\t%s [-option argument] .. [-option argument]\n\nwhere options include:\n", progName); 204 | 205 | for(i=0; i < OPTIONS_COUNT; i++) 206 | printf("\t%s\t%s\n", A->Options[i].argument, A->Options[i].manual); 207 | 208 | printf( "\t-v\tPrint version information\n" \ 209 | "\t-h\tPrint out this message\n" \ 210 | "\nExit status:\n0\tif OK,\n1\tif problems,\n2\tif serious trouble.\n" \ 211 | "\nReport bugs to xfreq[at]cyring.fr\n"); 212 | } 213 | else if(!strcmp(argv[1], "-v")) 214 | printf(Version); 215 | else 216 | { 217 | if(j > 0) 218 | printf("%s: unrecognized option '%s'\nTry '%s -h' for more information.\n", progName, argv[j], progName); 219 | else 220 | printf("%s: malformed options.\nTry '%s -h' for more information.\n", progName, progName); 221 | } 222 | free(program); 223 | } 224 | return(noerr); 225 | } 226 | 227 | static void *uEmergency(void *uArg) 228 | { 229 | uARG *A=(uARG *) uArg; 230 | pthread_setname_np(A->TID_SigHandler, "xfreq-cli-kill"); 231 | 232 | int caught=0; 233 | while(A->LOOP && !sigwait(&A->Signal, &caught)) 234 | switch(caught) 235 | { 236 | case SIGINT: 237 | case SIGQUIT: 238 | case SIGUSR1: 239 | case SIGTERM: 240 | { 241 | char str[sizeof(SIG_EMERGENCY_FMT)]; 242 | sprintf(str, SIG_EMERGENCY_FMT, caught); 243 | tracerr(str); 244 | Play(A, ID_QUIT); 245 | } 246 | break; 247 | case SIGCONT: 248 | { 249 | } 250 | break; 251 | case SIGUSR2: 252 | // case SIGTSTP: 253 | { 254 | } 255 | } 256 | return(NULL); 257 | } 258 | 259 | // Verify the prerequisites & start the threads. 260 | int main(int argc, char *argv[]) 261 | { 262 | pthread_setname_np(pthread_self(), "xfreq-cli-main"); 263 | 264 | uARG A={ 265 | .FD={.Shm=0, .SmBIOS=0}, .SHM=MAP_FAILED, .SmBIOS=MAP_FAILED, 266 | .TID_SigHandler=0, 267 | .TID_Read=0, 268 | .iFunc=0, 269 | .uFunc=uRead_Freq, 270 | .LOOP=TRUE, 271 | .Options= 272 | { 273 | {"-f", "%u", &A.iFunc, "Function thread (Int)\n" \ 274 | "\t\t argument is one of the [0]Freq [1]States [2]Inst" }, 275 | {"-B", "%s", NULL, "(n/a) Print the SmBIOS tree (Bool) [0/1]" }, 276 | {"-l", "%s", NULL, "(n/a) Log to a file (String)\n" \ 277 | "\t\t argument is the log file path" }, 278 | } 279 | }; 280 | uid_t UID=geteuid(); 281 | Bool32 ROOT=(UID == 0), // Check root access. 282 | fEmergencyThread=FALSE; 283 | int rc=0; 284 | 285 | if(ScanOptions(&A, argc, argv)) 286 | { 287 | switch(A.iFunc) 288 | { 289 | case 2: 290 | A.uFunc=uRead_Inst; 291 | break; 292 | case 1: 293 | A.uFunc=uRead_States; 294 | break; 295 | case 0: 296 | default: 297 | A.uFunc=uRead_Freq; 298 | break; 299 | } 300 | sigemptyset(&A.Signal); 301 | sigaddset(&A.Signal, SIGINT); // [CTRL] + [C] 302 | sigaddset(&A.Signal, SIGQUIT); 303 | sigaddset(&A.Signal, SIGUSR1); 304 | sigaddset(&A.Signal, SIGUSR2); 305 | sigaddset(&A.Signal, SIGTERM); 306 | sigaddset(&A.Signal, SIGCONT); 307 | // sigaddset(&A.Signal, SIGTSTP); // [CTRL] + [Z] 308 | 309 | if(!pthread_sigmask(SIG_BLOCK, &A.Signal, NULL) 310 | && !pthread_create(&A.TID_SigHandler, NULL, uEmergency, &A)) 311 | fEmergencyThread=TRUE; 312 | else 313 | tracerr("Remark: cannot start the signal handler"); 314 | 315 | if(ROOT) 316 | tracerr("Warning: running as root"); 317 | 318 | struct stat shmStat={0}, smbStat={0}; 319 | if(((A.FD.Shm=shm_open(SHM_FILENAME, O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != -1) 320 | && ((fstat(A.FD.Shm, &shmStat) != -1) 321 | && ((A.SHM=mmap(0, shmStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, A.FD.Shm, 0)) != MAP_FAILED)) 322 | && ((A.Room=Sync_Open(&A.SHM->Sync)) != 0)) 323 | { 324 | if(((A.FD.SmBIOS=shm_open(SMB_FILENAME, O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == -1) 325 | || ((fstat(A.FD.Shm, &smbStat) == -1)) 326 | || ((A.SmBIOS=mmap(A.SHM->B, smbStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, A.FD.SmBIOS, 0)) == MAP_FAILED)) 327 | tracerr("Error: opening the SmBIOS shared memory"); 328 | #if defined(DEBUG) 329 | printf( "\n--- SHM Map ---\n" 330 | "A.SHM[%p]\n" \ 331 | "A.SHM->P[%p]\n" \ 332 | "A.SHM->H[%p]\n" \ 333 | "A.SHM->D[%p]\n" \ 334 | "A.SHM->M[%p]\n" \ 335 | "A.SHM->S[%p]\n" \ 336 | "A.SHM->B[%p]\n" \ 337 | "A.SHM->C[%p]\n", \ 338 | A.SHM, \ 339 | &A.SHM->P, \ 340 | &A.SHM->H, \ 341 | &A.SHM->D, \ 342 | &A.SHM->M, \ 343 | &A.SHM->S, \ 344 | A.SHM->B, \ 345 | &A.SHM->C); 346 | #endif 347 | if(!pthread_create(&A.TID_Read, NULL, A.uFunc, &A)) 348 | { 349 | printf("\n%s Ready with [%s]\n\n", _APPNAME, A.SHM->AppName); 350 | 351 | while(A.LOOP) 352 | { 353 | usleep(IDLE_BASE_USEC * A.SHM->P.IdleTime); 354 | } 355 | 356 | // shutting down 357 | struct timespec absoluteTime={.tv_sec=0, .tv_nsec=0}, gracePeriod={.tv_sec=0, .tv_nsec=0}; 358 | abstimespec(IDLE_BASE_USEC * IDLE_COEF_MAX, &absoluteTime); 359 | if(!addtimespec(&gracePeriod, &absoluteTime) 360 | && pthread_timedjoin_np(A.TID_Read, NULL, &gracePeriod)) 361 | { 362 | rc=pthread_kill(A.TID_Read, SIGKILL); 363 | rc=pthread_join(A.TID_Read, NULL); 364 | } 365 | } 366 | else 367 | { 368 | tracerr("Error: cannot start the thread uRead()"); 369 | rc=2; 370 | } 371 | if((A.SmBIOS != MAP_FAILED) && (munmap(A.SmBIOS, smbStat.st_size) == -1)) 372 | tracerr("Error: unmapping the SmBIOS shared memory"); 373 | } 374 | else 375 | { 376 | tracerr("Error: opening the shared memory"); 377 | rc=2; 378 | } 379 | // Release the ressources. 380 | if(A.Room) 381 | Sync_Close(A.Room, &A.SHM->Sync); 382 | if((A.SHM != MAP_FAILED) && (munmap(A.SHM, shmStat.st_size) == -1)) 383 | tracerr("Error: unmapping the shared memory"); 384 | if((A.FD.Shm != -1) && (close(A.FD.Shm) == -1)) 385 | tracerr("Error: closing the shared memory"); 386 | 387 | if(fEmergencyThread) 388 | { 389 | pthread_kill(A.TID_SigHandler, SIGUSR1); 390 | pthread_join(A.TID_SigHandler, NULL); 391 | } 392 | } 393 | else 394 | rc=1; 395 | 396 | return(rc); 397 | } 398 | -------------------------------------------------------------------------------- /cli/xfreq-cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-cli.h by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | 10 | #if defined(FreeBSD) 11 | // Posix fix. 12 | #define pthread_setname_np pthread_set_name_np 13 | #define pthread_tryjoin_np(t, r) pthread_timedjoin_np(t, r, 0) 14 | #endif 15 | 16 | #define OPTIONS_COUNT 3 17 | typedef struct 18 | { 19 | char *argument; 20 | char *format; 21 | void *pointer; 22 | char *manual; 23 | } OPTIONS; 24 | 25 | typedef struct 26 | { 27 | struct 28 | { 29 | int Shm, 30 | SmBIOS; 31 | } FD; 32 | 33 | SHM_STRUCT *SHM; 34 | SMBIOS_TREE *SmBIOS; 35 | 36 | sigset_t Signal; 37 | pthread_t TID_SigHandler, 38 | TID_Read; 39 | 40 | unsigned int Room; 41 | 42 | unsigned int iFunc; 43 | void *(*uFunc)(void *uArg); 44 | 45 | Bool32 LOOP; 46 | OPTIONS Options[OPTIONS_COUNT]; 47 | } uARG; 48 | -------------------------------------------------------------------------------- /gui/Makefile: -------------------------------------------------------------------------------- 1 | export CC 2 | CFLAGS = -Wall -pthread -x c 3 | KERNEL = `uname -s` 4 | APP_NAME=xfreq-gui 5 | SRC_PATH=. 6 | OBJ_PATH=./obj 7 | BIN_PATH=./bin 8 | INC4x86_PATH=-I ../api 9 | LIB4x86_FLAGS=-lX11 -lpthread -lrt ../api/obj/xfreq-api.o 10 | # 11 | all : $(APP_NAME) 12 | # 13 | help : 14 | @echo 'make [all] : Compile, link and store executable file in' $(BIN_PATH)/$(APP_NAME) 15 | @echo 'make clean : Remove object and binary files.' 16 | @echo 'make clean-all : Remove object and binary sub-directories.' 17 | # 18 | clean : 19 | @echo 'Cleaning ...' 20 | @if [ -e $(BIN_PATH)/$(APP_NAME) ]; then rm -v $(BIN_PATH)/$(APP_NAME); else echo 'Nothing to do in '$(BIN_PATH); fi 21 | @if [ -e $(OBJ_PATH)/$(APP_NAME).o ]; then rm -v $(OBJ_PATH)/$(APP_NAME).o; else echo 'Nothing to do in '$(OBJ_PATH); fi 22 | # 23 | clean-all: 24 | @echo 'Cleaning all ...' 25 | @if [ -d $(BIN_PATH) ]; then rm -vr $(BIN_PATH); else echo 'Nothing to do in '$(BIN_PATH); fi 26 | @if [ -d $(OBJ_PATH) ]; then rm -vr $(OBJ_PATH); else echo 'Nothing to do in '$(OBJ_PATH); fi 27 | # 28 | $(APP_NAME) : $(APP_NAME).o 29 | @if [ ! -d $(BIN_PATH) ]; then mkdir $(BIN_PATH); fi 30 | $(CC) $(OBJ_PATH)/$(APP_NAME).o $(LIB4x86_FLAGS) -o $(BIN_PATH)/$(APP_NAME) 31 | # 32 | $(APP_NAME).o : $(APP_NAME).c 33 | @if [ ! -d $(OBJ_PATH) ]; then mkdir $(OBJ_PATH); fi 34 | $(CC) -D$(KERNEL) $(CFLAGS) -c $(APP_NAME).c $(INC4x86_PATH) -o $(OBJ_PATH)/$(APP_NAME).o 35 | -------------------------------------------------------------------------------- /gui/XFreq-Gui-FreeBSD.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 47 | 48 | -------------------------------------------------------------------------------- /gui/XFreq-Gui.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 45 | 46 | -------------------------------------------------------------------------------- /gui/xfreq-gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-gui.h by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | #if defined(FreeBSD) 10 | // Posix fix. 11 | #define pthread_setname_np pthread_set_name_np 12 | #define pthread_tryjoin_np(t, r) pthread_timedjoin_np(t, r, 0) 13 | #endif 14 | 15 | #define LOW_TEMP_VALUE 35 16 | #define MED_TEMP_VALUE 45 17 | #define HIGH_TEMP_VALUE 65 18 | 19 | enum { 20 | BACKGROUND_MAIN, 21 | FOREGROUND_MAIN, 22 | BACKGROUND_CORES, 23 | FOREGROUND_CORES, 24 | BACKGROUND_CSTATES, 25 | FOREGROUND_CSTATES, 26 | BACKGROUND_TEMPS, 27 | FOREGROUND_TEMPS, 28 | BACKGROUND_SYSINFO, 29 | FOREGROUND_SYSINFO, 30 | BACKGROUND_DUMP, 31 | FOREGROUND_DUMP, 32 | COLOR_AXES, 33 | COLOR_LABEL, 34 | COLOR_PRINT, 35 | COLOR_PROMPT, 36 | COLOR_CURSOR, 37 | COLOR_DYNAMIC, 38 | COLOR_GRAPH1, 39 | COLOR_GRAPH2, 40 | COLOR_GRAPH3, 41 | COLOR_INIT_VALUE, 42 | COLOR_LOW_VALUE, 43 | COLOR_MED_VALUE, 44 | COLOR_HIGH_VALUE, 45 | COLOR_PULSE, 46 | COLOR_FOCUS, 47 | COLOR_MDI_SEP, 48 | COLOR_COUNT 49 | }; 50 | 51 | #define _BACKGROUND_GLOBAL 0x2a0308 52 | #define _FOREGROUND_GLOBAL 0x8fcefa 53 | #define _BACKGROUND_SPLASH 0x000000 54 | #define _FOREGROUND_SPLASH 0xa00b1f 55 | 56 | #define _BACKGROUND_MAIN 0x2a0308 57 | #define _FOREGROUND_MAIN 0x8fcefa 58 | #define _BACKGROUND_CORES 0x2a0308 59 | #define _FOREGROUND_CORES 0x8fcefa 60 | #define _BACKGROUND_CSTATES 0x2a0308 61 | #define _FOREGROUND_CSTATES 0x8fcefa 62 | #define _BACKGROUND_TEMPS 0x2a0308 63 | #define _FOREGROUND_TEMPS 0x8fcefa 64 | #define _BACKGROUND_SYSINFO 0x2a0308 65 | #define _FOREGROUND_SYSINFO 0x8fcefa 66 | #define _BACKGROUND_DUMP 0x2a0308 67 | #define _FOREGROUND_DUMP 0x8fcefa 68 | 69 | #define _COLOR_AXES 0x404040 70 | #define _COLOR_LABEL 0xc0c0c0 71 | #define _COLOR_PRINT 0xf0f0f0 72 | #define _COLOR_PROMPT 0xffff00 73 | #define _COLOR_CURSOR 0xfd0000 74 | #define _COLOR_DYNAMIC 0xdddddd 75 | #define _COLOR_GRAPH1 0xadadff 76 | #define _COLOR_GRAPH2 0x50508a 77 | #define _COLOR_GRAPH3 0x515172 78 | #define _COLOR_INIT_VALUE 0x6666b0 79 | #define _COLOR_LOW_VALUE 0x00aa66 80 | #define _COLOR_MED_VALUE 0xe49400 81 | #define _COLOR_HIGH_VALUE 0xfd0000 82 | #define _COLOR_PULSE 0xf0f000 83 | #define _COLOR_FOCUS 0xffffff 84 | #define _COLOR_MDI_SEP 0x737373 85 | 86 | typedef struct 87 | { 88 | unsigned long int RGB; 89 | char *xrmClass, 90 | *xrmKey; 91 | } COLORS; 92 | 93 | enum {MC_DEFAULT, MC_MOVE, MC_WAIT, MC_COUNT}; 94 | 95 | #define ID_MIN 0x3f 96 | #define ID_SAVE 0x3e 97 | #define ID_NORTH 0x3d 98 | #define ID_SOUTH 0x3c 99 | #define ID_EAST 0x3b 100 | #define ID_WEST 0x3a 101 | #define ID_PGUP 0x39 102 | #define ID_PGDW 0x38 103 | #define ID_PGHOME 0x37 104 | #define ID_PGEND 0x36 105 | #define ID_CTRLHOME 0x35 106 | #define ID_CTRLEND 0x34 107 | #define ID_PAUSE 0x33 108 | #define ID_STOP 0x32 109 | #define ID_RESUME 0x31 110 | #define ID_WALLBOARD 0x30 111 | #define ID_CHART 0x2f 112 | #define ID_CYCLE 0x2e 113 | #define ID_IPS 0x2d 114 | #define ID_IPC 0x2c 115 | #define ID_CPI 0x2b 116 | #define ID_FREQ 0x2a 117 | #define ID_RATIO 0x29 118 | #define ID_CSTATE 0x28 119 | #define ID_PSTATE 0x27 120 | #define ID_TEMP 0x26 121 | #define ID_DUMP 0x25 122 | #define ID_TOGGLEBIT 0x24 123 | #define ID_WRITEBITS 0x23 124 | // ID_NULL + 5 DUMP 125 | // ID_NULL + 4 SYSINFO 126 | // ID_NULL + 3 TEMPS 127 | // ID_NULL + 2 CSTATES 128 | // ID_NULL + 1 CORES 129 | // ID_NULL + 0 MAIN 130 | 131 | #define RSC_RESET "Reset" 132 | #define RSC_FREQ "Freq" 133 | #define RSC_CYCLE "Cycle" 134 | #define RSC_IPS "IPS" 135 | #define RSC_IPC "IPC" 136 | #define RSC_CPI "CPI" 137 | #define RSC_RATIO "Ratio" 138 | #define RSC_SCHED "Task" 139 | #define RSC_CSTATE "C-States" 140 | #define RSC_PSTATE "P-States" 141 | #define RSC_TSC "TSC" 142 | #define RSC_TSC_AUX "AUX" 143 | #define RSC_BIOS "BIOS" 144 | #define RSC_SPEC "SPEC" 145 | #define RSC_ROM "ROM" 146 | #define RSC_INCLOOP "<<" 147 | #define RSC_DECLOOP ">>" 148 | #define RSC_WALLBOARD "Brand" 149 | #define RSC_WRITEBITS "Write" 150 | 151 | #define ICON_LABELS {{.Label='M'}, {.Label='C'}, {.Label='S'}, {.Label='T'}, {.Label='I'}, {.Label='D'}} 152 | 153 | typedef enum {DECORATION, SCROLLING, TEXT, ICON} WBTYPE; 154 | 155 | typedef union 156 | { 157 | char *Text; 158 | char Label; 159 | } RESOURCE; 160 | 161 | typedef struct 162 | { 163 | Bool32 (*Func)(); 164 | Bool32 *Key; 165 | } WBSTATE; 166 | 167 | struct WButton 168 | { 169 | WBTYPE Type; 170 | int Target; 171 | int x, 172 | y; 173 | unsigned int w, 174 | h; 175 | void (*CallBack)(); 176 | void (*DrawFunc)(); 177 | RESOURCE Resource; 178 | WBSTATE WBState; 179 | 180 | struct WButton *Chain; 181 | char ID; 182 | }; 183 | 184 | typedef struct WButton WBUTTON; 185 | 186 | enum {HEAD, TAIL, CHAINS}; 187 | 188 | #define WBUTTON_PULSE_US 75000 189 | 190 | typedef struct 191 | { 192 | Window window; 193 | struct { 194 | Pixmap B, 195 | F, 196 | I; 197 | } pixmap; 198 | GC gc; 199 | int x, 200 | y, 201 | width, 202 | height, 203 | border_width; 204 | struct 205 | { 206 | int bitmask, 207 | xoffset, 208 | yoffset; 209 | } Position; 210 | struct 211 | { 212 | XCharStruct overall; 213 | int dir, 214 | ascent, 215 | descent, 216 | charWidth, 217 | charHeight; 218 | } extents; 219 | unsigned long background, 220 | foreground; 221 | WBUTTON *wButton[CHAINS]; 222 | } XWINDOW; 223 | 224 | typedef struct 225 | { 226 | Window window; 227 | GC gc; 228 | Pixmap bitmap, 229 | icon; 230 | int x, y, 231 | w, h; 232 | short int attributes; 233 | } XSPLASH; 234 | 235 | // L-CTRL L-ALT R-CTRL L-WIN R-ALTGR 236 | #define AllModMask (ControlMask | Mod1Mask | Mod3Mask | Mod4Mask | Mod5Mask) 237 | #define BASE_EVENTS (KeyPressMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | FocusChangeMask) 238 | #define MOVE_EVENTS (ButtonReleaseMask | Button3MotionMask) 239 | #define CLICK_EVENTS ButtonPressMask 240 | 241 | typedef struct 242 | { 243 | Bool32 Locked; 244 | int S, 245 | dx, 246 | dy; 247 | } XTARGET; 248 | 249 | #define DEFAULT_FONT_ASCENT 11 250 | #define DEFAULT_FONT_DESCENT 2 251 | #define DEFAULT_FONT_CHAR_WIDTH 6 252 | #define DEFAULT_FONT_CHAR_HEIGHT (DEFAULT_FONT_ASCENT + DEFAULT_FONT_DESCENT) 253 | #define DEFAULT_HEADER_STR ".1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0" 254 | 255 | typedef enum {MAIN, CORES, CSTATES, TEMPS, SYSINFO, DUMP, WIDGETS} LAYOUTS; 256 | 257 | #define FIRST_WIDGET (MAIN + 1) 258 | #define LAST_WIDGET (WIDGETS - 1) 259 | 260 | #define Quarter_Char_Width(N) (A->W[N].extents.charWidth >> 2) 261 | #define Half_Char_Width(N) (A->W[N].extents.charWidth >> 1) 262 | #define One_Char_Width(N) (A->W[N].extents.charWidth) 263 | #define One_Half_Char_Width(N) (One_Char_Width(N) + Half_Char_Width(N)) 264 | #define Twice_Char_Width(N) (A->W[N].extents.charWidth << 1) 265 | #define Twice_Half_Char_Width(N) (Twice_Char_Width(N) + Half_Char_Width(N)) 266 | 267 | #define Quarter_Char_Height(N) (A->W[N].extents.charHeight >> 2) 268 | #define Half_Char_Height(N) (A->W[N].extents.charHeight >> 1) 269 | #define One_Char_Height(N) (A->W[N].extents.charHeight) 270 | #define One_Half_Char_Height(N) (One_Char_Height(N) + Half_Char_Height(N)) 271 | #define Twice_Char_Height(N) (A->W[N].extents.charHeight << 1) 272 | #define Twice_Half_Char_Height(N) (Twice_Char_Height(N) + Half_Char_Height(N)) 273 | 274 | #define Header_Height(N) (One_Char_Height(N) + Quarter_Char_Height(N)) 275 | #define Footer_Height(N) (One_Char_Height(N) + Half_Char_Height(N)) 276 | 277 | #define GEOMETRY_MAIN_COLS 84 278 | #define GEOMETRY_MAIN_ROWS 36 279 | #define GEOMETRY_CORES_COLS 22 280 | #define GEOMETRY_CORES_ROWS 8 281 | #define GEOMETRY_CSTATES_COLS 8 282 | #define GEOMETRY_CSTATES_ROWS 10 283 | #define GEOMETRY_TEMPS_COLS 32 284 | #define GEOMETRY_TEMPS_ROWS 10 285 | #define GEOMETRY_SYSINFO_COLS 80 286 | #define GEOMETRY_SYSINFO_ROWS 36 287 | 288 | #define MAIN_TEXT_WIDTH MAX(GEOMETRY_MAIN_COLS, A->L.Page[MAIN].Geometry.cols) 289 | #define MAIN_TEXT_HEIGHT MAX(GEOMETRY_MAIN_ROWS, A->L.Page[MAIN].Geometry.rows) 290 | 291 | #define MAIN_SECTION _APPNAME" "_MAJOR"."_MINOR"-"_NIGHTLY" CyrIng" 292 | 293 | #define CORES_TEXT_WIDTH MAX(A->SHM->P.Boost[9], A->L.Page[CORES].Geometry.cols) 294 | #define CORES_TEXT_HEIGHT (A->SHM->P.CPU) 295 | 296 | #define CSTATES_TEXT_SPACING 6 297 | #define CSTATES_TEXT_WIDTH (MAX(A->SHM->P.CPU, A->L.Page[CSTATES].Geometry.cols) * CSTATES_TEXT_SPACING) 298 | #define CSTATES_TEXT_HEIGHT MAX(GEOMETRY_CSTATES_ROWS, A->L.Page[CSTATES].Geometry.rows) 299 | 300 | #define TEMPS_TEXT_WIDTH MAX(((A->SHM->P.Features.ThreadCount + 1) << 2), A->L.Page[TEMPS].Geometry.cols) 301 | #define TEMPS_TEXT_HEIGHT MAX(GEOMETRY_TEMPS_ROWS, A->L.Page[TEMPS].Geometry.rows) 302 | 303 | #define SYSINFO_TEXT_WIDTH MAX(GEOMETRY_SYSINFO_COLS, A->L.Page[SYSINFO].Geometry.cols) 304 | #define SYSINFO_TEXT_HEIGHT MAX(GEOMETRY_SYSINFO_ROWS, A->L.Page[SYSINFO].Geometry.rows) 305 | 306 | #define DUMP_HEX16_STR 16 307 | // BIN64: 16 x 4 digits + '\0' 308 | #define DUMP_BIN64_STR (16 * 4) + 1 309 | // PRE_TEXT: ##' 'Addr[8+1]' 'Name&Padding[24] 310 | #define DUMP_PRE_TEXT (2 + 1 + 8 + 1 + DUMP_REG_ALIGN) 311 | // Columns: PRE_TEXT + BIN64 w/ 15 interspaces + ' ' + CoreNum + ScrollButtons 312 | #define GEOMETRY_DUMP_COLS sizeof(DUMP_SECTION) /*(DUMP_PRE_TEXT + DUMP_BIN64_STR + 15 + 2 + 3 + 3)*/ 313 | #define GEOMETRY_DUMP_ROWS (DUMP_ARRAY_DIMENSION + 2) 314 | #define DUMP_TEXT_WIDTH MAX(GEOMETRY_DUMP_COLS, A->L.Page[DUMP].Geometry.cols) 315 | #define DUMP_TEXT_HEIGHT MAX(GEOMETRY_DUMP_ROWS, A->L.Page[DUMP].Geometry.rows) 316 | 317 | #define GEOMETRY_PARSER "%d:%dx%d%c%d%c%d,%n" 318 | #define GEOMETRY_FORMAT "%d:%dx%d%+d%+d," 319 | #define GEOMETRY_SIZE strlen("0:640x360+5120+2880,") 320 | 321 | #define MENU_FORMAT "[F1] Help [F2] Core\n" \ 322 | "[F3] C-States [F4] Temps \n" \ 323 | "[F5] System Info [F6] Dump\n" \ 324 | "[Pause] Suspend/Resume Widget\n" \ 325 | "\nw/[Shift] key:\n" \ 326 | " [Up]\n" \ 327 | " Page Scrolling [Left] [Right]\n" \ 328 | " [Down]\n\n" \ 329 | "[PgDw] Page Down [PgUp] Page Up\n" \ 330 | "[Home] Line Begin [End] Line End\n" \ 331 | "\nw/[Control] key:\n" \ 332 | "[Home] Page start [End] Page end\n" \ 333 | "[L][l] Refresh page [Q][q] Quit\n" \ 334 | "[Y][y] Cycles [W][w] Wallboard\n" \ 335 | "[Z][z] Frequency Hz [P][p] C-States %\n" \ 336 | "[R][r] Ratio values [T][t] Task schedule\n" \ 337 | "KeyPad[+] Faster Loop KeyPad[-] Slower Loop\n" \ 338 | "[Tab] Substitute the command line using the history index\n\n" \ 339 | "Command keys:\n" \ 340 | "[Left] | [Right] | [Home] | [End] Move the cursor insertion\n" \ 341 | "[Up] | [Down] Browse forward, backward the commands history\n" \ 342 | "[Backspace] Remove the character before the cursor\n" \ 343 | "[Erase] Remove the character under the cursor\n" \ 344 | "[Escape] Cancel the full command line\n" \ 345 | "[Enter] Submit the command line\n" \ 346 | "[Tab] Expand the command line\n\n" \ 347 | "Mouse buttons:\n" \ 348 | "[Left] Activate Button [Right] Grab & Move Widget\n" \ 349 | "[Wheel Down] Page Down [Wheel Up] Page Up\n" 350 | 351 | #define CORE_NUM "#%-2d" 352 | #define CORE_FREQ "%4.0fMHz" 353 | #define CORE_CYCLES "%016llu:%016llu" 354 | #define CORE_IPS "%5.2f" 355 | #define CORE_DELTA "%04llu %04llu:%04llu %04llu / %04llu" 356 | 357 | #define CORE_TASK "%s" 358 | #define CORE_RATIO "%-3.1f" 359 | #define CSTATES_PERCENT "%6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%%" 360 | #define CSTATES_AVERAGE "%6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%% %6.2f%%" 361 | #define CSTATES_FOOTER "Turbo[ ] C0[ ] C1[ ] C3[ ] C6[ ] C7[ ]" 362 | #define OVERCLOCK "%s [%4.0f MHz]" 363 | #define TEMPERATURE "%3d" 364 | 365 | #define PROC_FORMAT "Processor [%s]\n" \ 366 | "\n" \ 367 | "Base Clock [%5.2f] MHz Source [%s]\n" \ 368 | "\n" \ 369 | " Family Model Stepping Online /\n" \ 370 | " Code No. ID Max CPU\n" \ 371 | "[%6X] [%6X] [%6d] [%3u/%3d]\n" \ 372 | "\n" \ 373 | "Architecture [%s]\n" \ 374 | "\n" \ 375 | "Boot Processor features\n" \ 376 | "|- Virtual Mode Extension VME [%c]\n" \ 377 | "|- Debugging Extension DE [%c]\n" \ 378 | "|- Page Size Extension PSE [%c]\n" \ 379 | "|- Time Stamp Counter [%9s] TSC [%c]\n" \ 380 | "|- Model Specific Registers MSR [%c] [%3s]\n" \ 381 | "|- Physical Address Extension PAE [%c]\n" \ 382 | "|- Advanced Programmable Interrupt Controller APIC [%c]\n" \ 383 | "|- Memory Type Range Registers MTRR [%c] [%3s]\n" \ 384 | "|- Page Global Enable PGE [%c]\n" \ 385 | "|- Machine-Check Architecture MCA [%c]\n" \ 386 | "|- Page Attribute Table PAT [%c]\n" \ 387 | "|- 36-bit Page Size Extension PSE36 [%c]\n" \ 388 | "|- Processor Serial Number PSN [%c]\n" \ 389 | "|- Debug Store & Precise Event Based Sampling DS, PEBS [%c] [%3s]\n" \ 390 | "|- Advanced Configuration & Power Interface ACPI [%c]\n" \ 391 | "|- Self-Snoop SS [%c]\n" \ 392 | "|- Hyper-Threading HTT [%c] [%3s]\n" \ 393 | "|- Thermal Monitor TM#1 [%c] [%3s] TM#2 [%c] [%3s]\n" \ 394 | "|- Pending Break Enable PBE [%c]\n" \ 395 | "|- 64-Bit Debug Store DTES64 [%c]\n" \ 396 | "|- CPL Qualified Debug Store DS-CPL [%c]\n" \ 397 | "|- Virtual Machine Extensions VMX [%c]\n" \ 398 | "|- Safer Mode Extensions SMX [%c]\n" \ 399 | "|- SpeedStep EIST [%c] [%3s]\n" \ 400 | "|- L1 Data Cache Context ID CNXT-ID [%c]\n" \ 401 | "|- Fused Multiply Add FMA [%c]\n" \ 402 | "|- xTPR Update Control xTPR [%c] [%3s]\n" \ 403 | "|- Perfmon and Debug Capability PDCM [%c]\n" \ 404 | "|- Process Context Identifiers PCID [%c]\n" \ 405 | "|- Direct Cache Access DCA [%c]\n" \ 406 | "|- Extended xAPIC Support x2APIC [%c]\n" \ 407 | "|- Time Stamp Counter Deadline TSC-DEADLINE [%c]\n" \ 408 | "|- XSAVE/XSTOR States XSAVE [%c]\n" \ 409 | "|- OS-Enabled Ext. State Management OSXSAVE [%c]\n" \ 410 | "|- Execution Disable Bit Support w/PAE [%3s] XD-Bit [%c] [%3s]\n" \ 411 | "|- 1 GB Pages Support 1GB-PAGES [%c]\n" \ 412 | "|- Hardware Lock Elision HLE [%c]\n" \ 413 | "|- Restricted Transactional Memory RTM [%c]\n" \ 414 | "|- Fast-Strings REP MOVSB/STOSB [%c] [%3s]\n" \ 415 | "|- Digital Thermal Sensor DTS [%c]\n" \ 416 | "|- Automatic Thermal Control Circuit Enable TCC [%3s]\n" \ 417 | "|- Performance Monitoring PM [%3s]\n" \ 418 | "|- Branch Trace Storage BTS [%3s]\n" \ 419 | "|- Limit CPUID Maxval Limit-CPUID [%3s]\n" \ 420 | "|- Turbo Boost Technology/Dynamic Acceleration TURBO/IDA [%c] [%3s]\n" \ 421 | "\n" \ 422 | "Ratio Boost: Min Max 8C 7C 6C 5C 4C 3C 2C 1C\n" \ 423 | " %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n" \ 424 | "\n" \ 425 | "Instruction set\n" \ 426 | "|- FPU [%c] CX8 [%c] SEP [%c] CMOV [%c]\n" \ 427 | "|- CLFSH [%c] MMX [%c] FXSR [%c] SSE [%c]\n" \ 428 | "|- SSE2 [%c] SSE3 [%c] SSSE3 [%c] SSE4.1 [%c]\n" \ 429 | "|- SSE4.2 [%c] PCLMULDQ [%c] MONITOR [%c][%3s] CX16 [%c]\n" \ 430 | "|- MOVBE [%c] POPCNT [%c] AES [%c] AVX/AVX2 [%c/%c]\n" \ 431 | "|- F16C [%c] RDRAND [%c]\n" \ 432 | "\n" \ 433 | "Extended Feature\n" \ 434 | "|- LAHF/SAHF [%c] RDTSCP [%c] IA64 [%c] BM1/BM2 [%c/%c]\n" \ 435 | "|- SYSCALL [%c][%3s] IA32e[%3s]\n" \ 436 | "\n" 437 | 438 | #define TOPOLOGY_SECTION "Processor & Caches Topology\n" \ 439 | "|- CPU# APIC Core Thread State | Inst Data Unified\n" 440 | #define TOPOLOGY_FORMAT " %03u %8u%8u%8u [%3s] |%s\n" 441 | 442 | #define PERF_SECTION "\n" \ 443 | "Performance Monitoring\n" \ 444 | "|- Version [%3d]\n" \ 445 | "|- Core Cycles [%c]\n" \ 446 | "|- Instructions Retired [%c]\n" \ 447 | "|- Reference Cycles [%c]\n" \ 448 | "|- Last Level Cache References [%c]\n" \ 449 | "|- Last Level Cache Misses [%c]\n" \ 450 | "|- Branch Instructions Retired [%c]\n" \ 451 | "|- Branch Mispredicts Retired [%c]\n" \ 452 | "|- C-States\n" \ 453 | "| |- Enhanced Halt State C1E [%3s]\n" \ 454 | "| |- C1 Auto Demotion C1A [%3s]\n" \ 455 | "| |- C3 Auto Demotion C3A [%3s]\n" \ 456 | "| |- C1 UnDemotion C1U [%3s]\n" \ 457 | "| |- C3 UnDemotion C3U [%3s]\n" \ 458 | "| |\n" \ 459 | "| |- MWAIT # of sub-states C0 C1 C2 C3 C4\n" \ 460 | "| %2d %2d %2d %2d %2d\n" \ 461 | "|\n" \ 462 | "|- Counters General Fixed\n" \ 463 | " | %3u x%3u bits %3u x%3u bits\n" \ 464 | " |\n" \ 465 | " |- CPU Counter#0 Counter#1 Counter#2\n" \ 466 | " # OS User AnyThread OS User AnyThread OS User AnyThread\n" 467 | #define PERF_FORMAT " %03u %1d %1d %1d %1d %1d %1d %1d %1d %1d\n" 468 | 469 | #define RAM_SECTION "\n" \ 470 | "Memory Controler\n" 471 | #define CHA_FORMAT "|- Channel tCL tRCD tRP tRAS tRRD tRFC tWR tRTPr tWTPr tFAW B2B\n" 472 | #define CAS_FORMAT " #%1i |%4d%6d%6d%6d%6d%6d%6d%6d%6d%6d%6d\n" 473 | 474 | #define SMBIOS_SECTION "\n" \ 475 | "SmBIOS\n" 476 | #define SMBIOS4_FORMAT "|- Processor\n" \ 477 | "| |- Product [%s]\n" \ 478 | "| |- Manufactured by %s\n" \ 479 | "| |- Socket %s\n" \ 480 | "| |- Tension %.1f V\n" 481 | #define SMBIOS7_FORMAT "| |- %s [%4lld]%s\n" 482 | #define SMBIOS2_FORMAT "|- Board\n" \ 483 | "| |- Product [%s]\n" \ 484 | "| |- Version %s\n" \ 485 | "| |- Manufactured by %s\n" \ 486 | "| |- Serial [%s]\n" 487 | #define SMBIOS0_FORMAT "|- BIOS\n" \ 488 | "| |- Product [%s]\n" \ 489 | "| |- Version %s\n" \ 490 | "| |- Released date %s\n" \ 491 | "| |- Revision %lld.%lld\n" \ 492 | "| |- ROM Size %lld KB at 0x%04llX\n" 493 | #define SMBIOS16_FORMAT "|- RAM\n" \ 494 | " |- Capacity [%lld / %lld] MB\n" 495 | #define SMBIOS17_FORMAT " |- %s:%s %lld MB @ %lld MHz\n" 496 | 497 | #define OSINFO_SECTION "\n" \ 498 | "Powered by %s\n" 499 | 500 | 501 | #define SYSINFO_SECTION "System Information" 502 | // 12345678 1234567890123456789012341234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 1234 #00. 12345 503 | #define DUMP_SECTION " Address Register 60 56 52 48 44 40 36 32 28 24 20 16 12 8 4 0 Core " 504 | #define REG_HEXVAL "%016llX" 505 | #define REG_FORMAT_BOL "%08X %s%%%zdc" 506 | #define REG_FORMAT_EOL " "CORE_NUM"\n" 507 | 508 | #define TASK_SECTION "Task Scheduling" 509 | 510 | #define TITLE_MDI_FMT _APPNAME" %.0fMHz %dC" 511 | #define TITLE_MAIN_FMT _APPNAME" %s.%s-%s" 512 | #define TITLE_CORES_FMT "Core#%d @ %.0f MHz" 513 | #define TITLE_CSTATES_FMT "C-States [%.2f%%] [%.2f%%]" 514 | #define TITLE_TEMPS_FMT "Core#%d @ %dC" 515 | #define TITLE_SYSINFO_FMT "Clock @ %5.2f MHz" 516 | 517 | #define SIG_EMERGENCY_FMT "\nShutdown(%02d)" 518 | 519 | #define SCROLLED_ROWS_PER_ONCE 1 520 | #define SCROLLED_ROWS_PER_PAGE (MAIN_TEXT_HEIGHT >> 1) 521 | #define SCROLLED_COLS_PER_ONCE 1 522 | 523 | #define SetHScrolling(N, col) A->L.Page[N].hScroll=col 524 | #define SetVScrolling(N, row) A->L.Page[N].vScroll=row 525 | #define GetHScrolling(N) A->L.Page[N].hScroll 526 | #define GetVScrolling(N) A->L.Page[N].vScroll 527 | 528 | #define SetHViewport(N, col) A->L.Page[N].Visible.cols=col 529 | #define SetVViewport(N, row) A->L.Page[N].Visible.rows=row 530 | #define GetHViewport(N) A->L.Page[N].Visible.cols 531 | #define GetVViewport(N) A->L.Page[N].Visible.rows 532 | 533 | #define SetHListing(N, col) A->L.Page[N].Listing.cols=col 534 | #define SetVListing(N, row) A->L.Page[N].Listing.rows=row 535 | #define GetHListing(N) A->L.Page[N].Listing.cols 536 | #define GetVListing(N) A->L.Page[N].Listing.rows 537 | 538 | #define SetHFrame(N, col) A->L.Page[N].FrameSize.cols=col 539 | #define SetVFrame(N, row) A->L.Page[N].FrameSize.rows=row 540 | #define GetHFrame(N) A->L.Page[N].FrameSize.cols 541 | #define GetVFrame(N) A->L.Page[N].FrameSize.rows 542 | 543 | #define MAIN_FRAME_VIEW_HSHIFT 1 544 | #define MAIN_FRAME_VIEW_VSHIFT 4 545 | #define SYSINFO_FRAME_VIEW_HSHIFT 1 546 | #define SYSINFO_FRAME_VIEW_VSHIFT 3 547 | #define DUMP_FRAME_VIEW_HSHIFT 1 548 | #define DUMP_FRAME_VIEW_VSHIFT 1 549 | #define WALLBOARD_PADDING 11 550 | 551 | #define KEYINPUT_DEPTH 256 552 | #define HISTORY_DEPTH 100 553 | 554 | typedef struct 555 | { 556 | int cols, 557 | rows; 558 | } MaxText; 559 | 560 | typedef struct 561 | { 562 | unsigned int UnMapBitmask; 563 | struct { 564 | Bool32 Pageable; 565 | MaxText Geometry, 566 | Visible, 567 | Listing, 568 | FrameSize; 569 | int hScroll, 570 | vScroll; 571 | Pixmap Pixmap; 572 | int width, 573 | height; 574 | char *Title; 575 | } Page[WIDGETS]; 576 | struct { 577 | Bool32 fillGraphics, 578 | freqHertz, 579 | showCycles, 580 | showIPS, 581 | showIPC, 582 | showCPI, 583 | showRatios, 584 | showSchedule, 585 | cStatePercent, 586 | *showTemps, 587 | wallboard, 588 | flashCursor, 589 | alwaysOnTop, 590 | noDecorations, 591 | skipTaskbar, 592 | cursorShape; 593 | } Play; 594 | struct { 595 | Bool32 *RowSw, 596 | *BitSw; 597 | int RowIx; 598 | } Toggle; 599 | struct {; 600 | int Scroll, 601 | Length; 602 | char *String; 603 | } WB; 604 | struct { 605 | XRectangle *C0, 606 | *C1, 607 | *C3, 608 | *C6, 609 | *C7; 610 | } Usage; 611 | struct NXSEGMENT {; 612 | int N; 613 | XSegment *Segment; 614 | } Axes[WIDGETS], *Temps; 615 | XPoint TextCursor[3]; 616 | struct { 617 | char *KeyBuffer; 618 | int KeyLength, KeyInsert, Recent, Browse, Top, Cmd; 619 | struct { 620 | char *KeyBuffer; 621 | int KeyLength; 622 | } History[HISTORY_DEPTH], Expand; 623 | } Input; 624 | char *Output; 625 | unsigned long int globalBackground, 626 | globalForeground; 627 | COLORS Colors[COLOR_COUNT]; 628 | } LAYOUT; 629 | 630 | #define _IS_MDI_ (A->MDI != FALSE) 631 | 632 | #define SPLASH_HIDDEN_FLAG ((A.Splash.attributes & 0x1000) >> 12) 633 | #define SPLASH_DEFERRED_TIME (__useconds_t) (A.Splash.attributes & 0xFFF) 634 | 635 | #define XDB_SETTINGS_FILE ".xfreq" 636 | #define XDB_CLASS_MAIN "Main" 637 | #define XDB_CLASS_CORES "Cores" 638 | #define XDB_CLASS_CSTATES "CStates" 639 | #define XDB_CLASS_TEMPS "Temps" 640 | #define XDB_CLASS_SYSINFO "SysInfo" 641 | #define XDB_CLASS_DUMP "Dump" 642 | #define XDB_KEY_FONT "Font" 643 | #define XDB_KEY_LEFT "Left" 644 | #define XDB_KEY_TOP "Top" 645 | #define XDB_KEY_BACKGROUND "Background" 646 | #define XDB_KEY_FOREGROUND "Foreground" 647 | #define XDB_KEY_CLOCK_SOURCE "ClockSource" 648 | #define XDB_KEY_ROM_ADDRESS "ClockRomAddr" 649 | #define XDB_KEY_CURSOR_SHAPE "CursorShape" 650 | #define XDB_KEY_PLAY_GRAPHICS "FillGraphics" 651 | #define XDB_KEY_PLAY_FREQ "PlayFrequency" 652 | #define XDB_KEY_PLAY_CYCLES "PlayCycles" 653 | #define XDB_KEY_PLAY_IPS "PlayIPS" 654 | #define XDB_KEY_PLAY_IPC "PlayIPC" 655 | #define XDB_KEY_PLAY_CPI "PlayCPI" 656 | #define XDB_KEY_PLAY_RATIOS "PlayRatios" 657 | #define XDB_KEY_PLAY_SCHEDULE "PlaySchedule" 658 | #define XDB_KEY_PLAY_CSTATES "PlayCStates" 659 | #define XDB_KEY_PLAY_WALLBOARD "PlayBrand" 660 | 661 | #define OPTIONS_COUNT 23 662 | typedef struct 663 | { 664 | char *argument; 665 | char *format; 666 | void *pointer; 667 | char *manual; 668 | char *xrmName; 669 | } OPTIONS; 670 | 671 | #define INSTRUCTION_LEN 16 672 | #define COMMANDS_COUNT 19 673 | typedef struct 674 | { 675 | void (*Proc)(); 676 | char *Spec, 677 | *Inst, 678 | *Usage; 679 | } COMMANDS; 680 | 681 | #define COMMANDS_LIST \ 682 | { \ 683 | { Proc_Help, " %[^\n]", "help", "%s [p1]\nWhere: p1=command (String)\n" }, \ 684 | { Proc_Menu, "%c", "menu", "%s\n" }, \ 685 | { Proc_Quit, "%c", "quit", "%s\n" }, \ 686 | { Proc_Clear, "%c", "clear", "%s\n" }, \ 687 | { Proc_Restart, "%c", "restart", "%s\n" }, \ 688 | { Proc_Release, "%c", "version", "%s\n" }, \ 689 | { Proc_History, "%%%d %c", "history", "%s [%%i]\nWhere: %%i=font index (Int)\n" }, \ 690 | { List_Colors, "%c", "list colors", "%s\n" }, \ 691 | { Get_Color, "%%%d %c", "get color", "%s %%i\nWhere: %%i=index (Int)\n" }, \ 692 | { Set_Color, "%%%d %x %c", "set color", "%s %%i p1\nWhere: %%i=index (Int), p1=RGB (Hex)\n" }, \ 693 | { List_Fonts, "%s %c", "list fonts", "%s [p1]\nWhere: p1=pattern (String)\n" }, \ 694 | { Get_Font, "%c", "get font", "%s\n" }, \ 695 | { Set_Font, "%s %c", "set font", "%s p1 | %%i\nWhere: p1=font name (String)\nor : %%i=font index (Int)\n" }, \ 696 | { Set_Cursor, "%d %c", "set cursor", "%s p1\nWhere: p1=shape# (Int)\n" }, \ 697 | { Svr_Dump_MSR, "%x %hu %hhu", "dump msr", "%s p1 p2 p3\nWhere: p1=address (Hex), p2=Core# (Int), p3=index (Int)\n" }, \ 698 | { Svr_Read_MSR, "%x %hu", "read msr", "%s p1 p2\nWhere: p1=address (Hex), p2=Core# (Int)\n" }, \ 699 | { Svr_Write_MSR, "%x %hu %llx", "write msr", "%s p1 p2 p3\nWhere: p1=address (Hex), p2=Core# (Int), p3=value (Hex)\n" }, \ 700 | { Svr_Enable_Feature, "%s", "enable", "%s p1\nWhere: p1=feature (String)\n" }, \ 701 | { Svr_Disable_Feature, "%s", "disable", "%s p1\nWhere: p1=feature (String)\n" } \ 702 | } 703 | 704 | typedef struct 705 | { 706 | char *Inst; 707 | unsigned int ID; 708 | } CTL_FEATURES; 709 | 710 | #define FEATURES_LIST \ 711 | { \ 712 | {"turbo", CTL_TURBO}, \ 713 | {"eist", CTL_EIST}, \ 714 | {"c1e", CTL_C1E}, \ 715 | {"c3a", CTL_C3A}, \ 716 | {"c1a", CTL_C1A}, \ 717 | {"tcc", CTL_TCC}, \ 718 | {NULL, CTL_NOP} \ 719 | } 720 | 721 | typedef struct 722 | { 723 | struct 724 | { 725 | int Shm, 726 | SmBIOS; 727 | } FD; 728 | 729 | SHM_STRUCT *SHM; 730 | 731 | SMBIOS_TREE *SmBIOS; 732 | 733 | Display *display; 734 | Screen *screen; 735 | char *Geometries; 736 | struct{ 737 | char **List, 738 | *Name; 739 | XFontStruct *Info; 740 | int Count, 741 | Index; 742 | } font; 743 | Atom atom[5]; 744 | Cursor MouseCursor[MC_COUNT]; 745 | XSPLASH Splash; 746 | XWINDOW W[WIDGETS]; 747 | XTARGET T; 748 | LAYOUT L; 749 | sigset_t Signal; 750 | pthread_t TID_SigHandler, 751 | TID_Draw; 752 | Bool32 MDI, 753 | LOOP, 754 | RESTART, 755 | PAUSE[WIDGETS]; 756 | 757 | unsigned int Room; 758 | 759 | char *configFile, 760 | *scrShotPath; 761 | OPTIONS Options[OPTIONS_COUNT]; 762 | COMMANDS Commands[COMMANDS_COUNT]; 763 | char xACL; 764 | } uARG; 765 | 766 | // Definition of the Buttons management functions (CallBack). 767 | Bool32 Button_State(uARG *A, WBUTTON *wButton); 768 | Bool32 SCHED_State(uARG *A, WBUTTON *wButton); 769 | Bool32 TSC_State(uARG *A, WBUTTON *wButton); 770 | Bool32 TSC_AUX_State(uARG *A, WBUTTON *wButton); 771 | Bool32 BIOS_State(uARG *A, WBUTTON *wButton); 772 | Bool32 SPEC_State(uARG *A, WBUTTON *wButton); 773 | Bool32 ROM_State(uARG *A, WBUTTON *wButton); 774 | 775 | void CallBackSave(uARG *A, WBUTTON *wButton) ; 776 | void CallBackQuit(uARG *A, WBUTTON *wButton) ; 777 | void CallBackButton(uARG *A, WBUTTON *wButton) ; 778 | void CallBackTemps(uARG *A, WBUTTON *wButton) ; 779 | void CallBackToggleDump(uARG *A, WBUTTON *wButton) ; 780 | void CallBackToggleBit(uARG *A, WBUTTON *wButton) ; 781 | void CallBackMinimizeWidget(uARG *A, WBUTTON *wButton) ; 782 | void CallBackRestoreWidget(uARG *A, WBUTTON *wButton) ; 783 | 784 | // Definition of the Widgets drawing functions. 785 | // The triple buffering is as the following sequence: 786 | // step 1 : draw the static graphics into the background pixmap. 787 | void BuildLayout(uARG *A, int G) ; 788 | // step 2 : copy the background into the foreground pixmap. 789 | void MapLayout(uARG *A, int G) ; 790 | // step 3 : add the animated graphics into the foreground pixmap. 791 | void DrawLayout(uARG *A, int G) ; 792 | // step 4 : copy the foreground into the display window (taking care of the scrolling pixmap). 793 | void FlushLayout(uARG *A, int G) ; 794 | // loop to step 2 to avoid the execution of the building process. 795 | 796 | // All-in-One macro. 797 | #define fDraw(N, DoBuild, DoDraw) { \ 798 | if(DoBuild) BuildLayout(A, N); \ 799 | MapLayout(A, N); \ 800 | if(DoDraw) DrawLayout(A, N); \ 801 | FlushLayout(A, N); \ 802 | } 803 | 804 | 805 | /* --- Splash bitmap --- */ 806 | 807 | #define splash_width 267 808 | #define splash_height 50 809 | static unsigned char splash_bits[] = { 810 | 0xff, 0x3f, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0x00, 0x00, 0xf0, 0xff, 811 | 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xff, 0xff, 812 | 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0x3f, 813 | 0x00, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 814 | 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xc0, 0xff, 0xff, 0xff, 0xff, 815 | 0x0f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xfe, 0x7f, 0x00, 0x00, 816 | 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xf0, 817 | 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 818 | 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xfc, 0xff, 0x00, 0x00, 0xfe, 0x7f, 819 | 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 820 | 0xff, 0xff, 0x7f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0xff, 0xff, 821 | 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 822 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 823 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 824 | 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 825 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 826 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 827 | 0xf0, 0xff, 0x03, 0x80, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 828 | 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 0xff, 0xff, 829 | 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0xe0, 0xff, 830 | 0x07, 0xc0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 831 | 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 832 | 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0xc0, 0xff, 0x07, 0xe0, 833 | 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 834 | 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 835 | 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0xc0, 0xff, 0x0f, 0xe0, 0xff, 0x03, 836 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 837 | 0xff, 0xff, 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 838 | 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 839 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 840 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 841 | 0x00, 0x00, 0x00, 0xff, 0x3f, 0xf8, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 842 | 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 843 | 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 844 | 0x00, 0xfe, 0x3f, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 845 | 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 846 | 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xfe, 847 | 0x7f, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 848 | 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 849 | 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xfc, 0xff, 0xfe, 850 | 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 851 | 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 852 | 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 853 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 854 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 855 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 856 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 857 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 858 | 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 859 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 860 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 861 | 0x00, 0xe0, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 862 | 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 863 | 0xff, 0xff, 0x0f, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xc0, 864 | 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 865 | 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf0, 0xff, 0xff, 0xff, 0xff, 866 | 0x0f, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 867 | 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 868 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 869 | 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 870 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 871 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 872 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 873 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 874 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 875 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 876 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xf0, 877 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 878 | 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 879 | 0xff, 0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf0, 0xff, 0xff, 880 | 0xff, 0xff, 0x0f, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 881 | 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 882 | 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 883 | 0x0f, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0xff, 0xff, 884 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 885 | 0xff, 0xff, 0xff, 0xff, 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 886 | 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 887 | 0x00, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 888 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 889 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0x00, 0xff, 890 | 0xff, 0x03, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 891 | 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 892 | 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x03, 893 | 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 894 | 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 895 | 0x00, 0xe0, 0xff, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x03, 0xff, 0x07, 896 | 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 897 | 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xe0, 898 | 0xff, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x03, 0xff, 0x07, 0x00, 0x00, 899 | 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 900 | 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xf0, 0xff, 0xff, 901 | 0x1f, 0x00, 0x00, 0xff, 0xff, 0x03, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 902 | 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 903 | 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 904 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 905 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 906 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 907 | 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 908 | 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 909 | 0x07, 0x00, 0x00, 0xfc, 0x7f, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 910 | 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 911 | 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 912 | 0x00, 0xfe, 0x7f, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 913 | 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 914 | 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0xff, 915 | 0x3f, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 916 | 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0x7f, 0x00, 0x00, 0x00, 917 | 0x00, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 918 | 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 919 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 920 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 921 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 922 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 923 | 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x0f, 0xe0, 0xff, 0x07, 0x00, 0x00, 924 | 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 925 | 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 926 | 0xff, 0x07, 0xe0, 0xff, 0x07, 0xc0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 927 | 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 928 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 929 | 0xe0, 0xff, 0x03, 0xc0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 930 | 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0xff, 0xff, 931 | 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xff, 932 | 0x03, 0x80, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 933 | 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xf0, 0xff, 0xff, 0xff, 0xff, 934 | 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 935 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 936 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 937 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 938 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 939 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 940 | 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 941 | 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 942 | 0x7f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0xff, 0xff, 0xff, 0xff, 943 | 0xff, 0x07, 0xfe, 0x7f, 0x00, 0x00, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 944 | 0xff, 0x07, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0xc0, 945 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 946 | 0xff, 0x3f, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x07, 947 | 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0x80, 0xff, 0xff, 948 | 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0x1f, 949 | 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 950 | 0x00, 0xf0, 0x7f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0xff, 0xff, 0xff, 0xff, 951 | 0x0f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07 }; 952 | -------------------------------------------------------------------------------- /svr/Makefile: -------------------------------------------------------------------------------- 1 | export CC 2 | CFLAGS = -Wall -pthread -x c 3 | KERNEL = `uname -s` 4 | APP_NAME=xfreq-intel 5 | SRC_PATH=. 6 | OBJ_PATH=./obj 7 | BIN_PATH=./bin 8 | INC4x86_PATH=-I ../api 9 | LIB4x86_FLAGS=-lpthread -lrt ../api/obj/xfreq-api.o ../api/obj/xfreq-smbios.o 10 | # 11 | all : $(APP_NAME) 12 | # 13 | help : 14 | @echo 'make [all] : Compile, link and store executable file in' $(BIN_PATH)/$(APP_NAME) 15 | @echo 'make clean : Remove object and binary files.' 16 | @echo 'make clean-all : Remove object and binary sub-directories.' 17 | # 18 | clean : 19 | @echo 'Cleaning ...' 20 | @if [ -e $(BIN_PATH)/$(APP_NAME) ]; then rm -v $(BIN_PATH)/$(APP_NAME); else echo 'Nothing to do in '$(BIN_PATH); fi 21 | @if [ -e $(OBJ_PATH)/$(APP_NAME).o ]; then rm -v $(OBJ_PATH)/$(APP_NAME).o; else echo 'Nothing to do in '$(OBJ_PATH); fi 22 | # 23 | clean-all: 24 | @echo 'Cleaning all ...' 25 | @if [ -d $(BIN_PATH) ]; then rm -vr $(BIN_PATH); else echo 'Nothing to do in '$(BIN_PATH); fi 26 | @if [ -d $(OBJ_PATH) ]; then rm -vr $(OBJ_PATH); else echo 'Nothing to do in '$(OBJ_PATH); fi 27 | # 28 | $(APP_NAME) : $(APP_NAME).o 29 | @if [ ! -d $(BIN_PATH) ]; then mkdir $(BIN_PATH); fi 30 | $(CC) $(OBJ_PATH)/$(APP_NAME).o $(LIB4x86_FLAGS) -o $(BIN_PATH)/$(APP_NAME) 31 | # 32 | $(APP_NAME).o : $(APP_NAME).c 33 | @if [ ! -d $(OBJ_PATH) ]; then mkdir $(OBJ_PATH); fi 34 | $(CC) -D$(KERNEL) $(CFLAGS) -c $(APP_NAME).c $(INC4x86_PATH) -o $(OBJ_PATH)/$(APP_NAME).o 35 | -------------------------------------------------------------------------------- /svr/XFreq-Intel-FreeBSD.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 48 | 49 | -------------------------------------------------------------------------------- /svr/XFreq-Intel.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 50 | 51 | -------------------------------------------------------------------------------- /svr/xfreq-intel.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyring/xfreq/4a95bc4082adeb11bdd87e60a0a2bc0f1bee1a43/svr/xfreq-intel.c -------------------------------------------------------------------------------- /svr/xfreq-intel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * xfreq-intel.h by CyrIng 3 | * 4 | * XFreq 5 | * Copyright (C) 2013-2015 CYRIL INGENIERIE 6 | * Licenses: GPL2 7 | */ 8 | 9 | 10 | #define LEVEL_INVALID 0 11 | #define LEVEL_THREAD 1 12 | #define LEVEL_CORE 2 13 | 14 | typedef struct { 15 | union { 16 | struct 17 | { 18 | unsigned int 19 | SHRbits : 5-0, 20 | Unused1 : 32-5; 21 | }; 22 | unsigned int Register; 23 | } AX; 24 | union { 25 | struct 26 | { 27 | unsigned int 28 | Threads : 16-0, 29 | Unused1 : 32-16; 30 | }; 31 | unsigned int Register; 32 | } BX; 33 | union { 34 | struct 35 | { 36 | unsigned int 37 | Level : 8-0, 38 | Type : 16-8, 39 | Unused1 : 32-16; 40 | }; 41 | unsigned int Register; 42 | } CX; 43 | union { 44 | struct 45 | { 46 | unsigned int 47 | x2APIC_ID: 32-0; 48 | }; 49 | unsigned int Register; 50 | } DX; 51 | } CPUID_TOPOLOGY; 52 | 53 | // Memory address of the Base Clock in the ROM of the ASUS Rampage II GENE. 54 | #define BCLK_ROM_ADDR 0xf08d9 + 0x12 55 | 56 | // Read data from the PCI bus. 57 | #define PCI_CONFIG_ADDRESS(bus, dev, fn, reg) \ 58 | (0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3)) 59 | 60 | // Read, Write a Model Specific Register. 61 | 62 | #if defined(Linux) 63 | #define PAGE_SIZE (sysconf(_SC_PAGESIZE)) 64 | #define CPU_BP "/dev/cpu/0/msr" 65 | #define CPU_AP "/dev/cpu/999/msr" 66 | #define CPU_DEV "/dev/cpu/%d/msr" 67 | 68 | #define Read_MSR(FD, msr, data) pread(FD, data, sizeof(*data), msr) 69 | #define Write_MSR(FD, msr, data) pwrite(FD, data, sizeof(*data), msr) 70 | #else // (FreeBSD) & Posix fix. 71 | #define CPU_BP "/dev/cpuctl0" 72 | #define CPU_AP "/dev/cpuctl999" 73 | #define CPU_DEV "/dev/cpuctl%d" 74 | 75 | int Read_MSR(int FD, int msr, unsigned long long int *data) \ 76 | { \ 77 | cpuctl_msr_args_t args; \ 78 | args.msr=msr; \ 79 | int rc=ioctl(FD, CPUCTL_RDMSR, &args); \ 80 | *(data)=args.data; \ 81 | return(rc); \ 82 | } 83 | int Write_MSR(int FD, int msr, unsigned long long int *data) \ 84 | { \ 85 | cpuctl_msr_args_t args; \ 86 | args.msr=msr; \ 87 | args.data=*(data); \ 88 | int rc=ioctl(FD, CPUCTL_WRMSR, &args); \ 89 | return(rc); \ 90 | } 91 | 92 | #define cpu_set_t cpuset_t 93 | #define pthread_setname_np pthread_set_name_np 94 | #endif 95 | 96 | // [GenuineIntel] 97 | #define _GenuineIntel {.ExtFamily=0x0, .Family=0x0, .ExtModel=0x0, .Model=0x0} 98 | // [Core] 06_0EH (32 bits) 99 | #define _Core_Yonah {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x0, .Model=0xE} 100 | // [Core2] 06_0FH, 06_15H, 06_17H, 06_1D 101 | #define _Core_Conroe {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x0, .Model=0xF} 102 | #define _Core_Kentsfield {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0x5} 103 | #define _Core_Conroe_616 {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0x6} 104 | #define _Core_Yorkfield {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0x7} 105 | #define _Core_Dunnington {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0xD} 106 | // [Atom] 06_1CH, 06_26H, 06_27H (32 bits), 06_35H (32 bits), 06_36H 107 | #define _Atom_Bonnell {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0xC} 108 | #define _Atom_Silvermont {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0x6} 109 | #define _Atom_Lincroft {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0x7} 110 | #define _Atom_Clovertrail {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0x5} 111 | #define _Atom_Saltwell {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0x6} 112 | // [Silvermont] 06_37H, 06_4DH 113 | #define _Silvermont_637 {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0x7} 114 | #define _Silvermont_64D {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0xD} 115 | // [Airmont] 06_4CH 116 | #define _Atom_Airmont {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0xC} 117 | // [Goldmont] 06_5CH 118 | #define _Atom_Goldmont {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x5, .Model=0xC} 119 | // [SoFIA] 06_5DH 120 | #define _Atom_Sofia {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x5, .Model=0xD} 121 | // [Merrifield] 06_4AH 122 | #define _Atom_Merrifield {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0xA} 123 | // [Moorefield] 06_5AH 124 | #define _Atom_Moorefield {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x5, .Model=0xA} 125 | // [Nehalem] 06_1AH, 06_1EH, 06_1FH, 06_2EH 126 | #define _Nehalem_Bloomfield {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0xA} 127 | #define _Nehalem_Lynnfield {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0xE} 128 | #define _Nehalem_MB {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x1, .Model=0xF} 129 | #define _Nehalem_EX {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0xE} 130 | // [Westmere] 06_25H, 06_2CH, 06_2FH 131 | #define _Westmere {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0x5} 132 | #define _Westmere_EP {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0xC} 133 | #define _Westmere_EX {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0xF} 134 | // [Sandy Bridge] 06_2AH, 06_2DH 135 | #define _SandyBridge {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0xA} 136 | #define _SandyBridge_EP {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x2, .Model=0xD} 137 | // [Ivy Bridge] 06_3AH, 06_3EH 138 | #define _IvyBridge {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0xA} 139 | #define _IvyBridge_EP {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0xE} 140 | // [Haswell] 06_3CH, 06_3FH, 06_45H, 06_46H 141 | #define _Haswell_DT {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0xC} 142 | #define _Haswell_MB {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0xF} 143 | #define _Haswell_ULT {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0x5} 144 | #define _Haswell_ULX {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0x6} 145 | // [Broadwell] 06_3DH, 06_56H, 06_47H, 06_4FH 146 | #define _Broadwell {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x3, .Model=0xD} 147 | #define _Broadwell_EP {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x5, .Model=0x6} 148 | #define _Broadwell_H {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0x7} 149 | #define _Broadwell_EX {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0xF} 150 | // [Skylake] 06_4EH, 06_5EH, 06_55H 151 | #define _Skylake_UY {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x4, .Model=0xE} 152 | #define _Skylake_S {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x5, .Model=0xE} 153 | #define _Skylake_E {.ExtFamily=0x0, .Family=0x6, .ExtModel=0x5, .Model=0x5} 154 | 155 | typedef struct 156 | { 157 | struct SIGNATURE Signature; 158 | unsigned int MaxOfCores; 159 | double (*ClockSpeed)(); 160 | char *Architecture; 161 | void *(*uCycle)(void *uA, int cpu, int T); 162 | Bool32 (*Init_MSR)(void *); 163 | Bool32 (*Close_MSR)(void *); 164 | } ARCH; 165 | 166 | 167 | /* 168 | Borrow from: 169 | 170 | /include/linux/sched.h: 171 | struct task_struct { 172 | int prio, static_prio, normal_prio; 173 | struct sched_entity se; 174 | struct task_group *sched_task_group; 175 | pid_t pid; 176 | unsigned long nvcsw, nivcsw; // context switch counts 177 | char comm[TASK_COMM_LEN]; // executable name excluding path 178 | }; 179 | static inline pid_t task_pid_nr(struct task_struct *tsk) 180 | static inline int task_node(const struct task_struct *p) 181 | 182 | /kernel/sched/sched.h: 183 | static inline struct task_group *task_group(struct task_struct *p) 184 | { 185 | return p->sched_task_group; 186 | } 187 | 188 | /kernel/sched/debug.c: 189 | print_task(struct seq_file *m, struct rq *rq, struct task_struct *p) 190 | { 191 | if (rq->curr == p) 192 | SEQ_printf(m, "R"); 193 | else 194 | SEQ_printf(m, " "); 195 | 196 | SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ", 197 | p->comm, task_pid_nr(p), 198 | SPLIT_NS(p->se.vruntime), 199 | (long long)(p->nvcsw + p->nivcsw), 200 | p->prio); 201 | //... 202 | SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld", 203 | SPLIT_NS(p->se.vruntime), 204 | SPLIT_NS(p->se.sum_exec_runtime), 205 | SPLIT_NS(p->se.statistics.sum_sleep_runtime)); 206 | //... 207 | SEQ_printf(m, " %d", task_node(p)); 208 | //... 209 | SEQ_printf(m, " %s", task_group_path(task_group(p))); 210 | //... 211 | SEQ_printf(m, "\n"); 212 | } 213 | 214 | /include/linux/limits.h: 215 | 216 | /include/linux/types.h: 217 | typedef __kernel_pid_t pid_t; 218 | 219 | /uapi/asm-generic/int-ll64.h: 220 | 221 | /uapi/asm-generic/posix_types.h: 222 | typedef int __kernel_pid_t; 223 | */ 224 | 225 | #define SCHED_CPU_SECTION "cpu#%d" 226 | #define SCHED_PID_FIELD "curr->pid" 227 | #define SCHED_PID_FORMAT " .%-30s: %%ld\n" 228 | #define SCHED_TASK_SECTION "runnable tasks:" 229 | #define TASK_SECTION "Task Scheduling" 230 | #define TASK_STATE_FMT "%c" 231 | #define TASK_COMM_FMT "%15s" 232 | #define TASK_TIME_FMT "%9Ld.%06Ld" 233 | #define TASK_CTXSWITCH_FMT "%9Ld" 234 | #define TASK_PRIORITY_FMT "%5ld" 235 | #define TASK_NODE_FMT "%ld" 236 | #define TASK_GROUP_FMT "%s" 237 | 238 | #define TASK_STRUCT_FORMAT TASK_STATE_FMT""TASK_COMM_FMT" "TASK_PID_FMT" "TASK_TIME_FMT" "TASK_CTXSWITCH_FMT" "TASK_PRIORITY_FMT" "TASK_TIME_FMT" "TASK_TIME_FMT" "TASK_TIME_FMT" "TASK_NODE_FMT" "TASK_GROUP_FMT 239 | 240 | #define OPTIONS_COUNT 8 241 | typedef struct 242 | { 243 | char *argument; 244 | char *format; 245 | void *pointer; 246 | char *manual; 247 | } OPTIONS; 248 | 249 | #define OPTIONS_LIST \ 250 | { \ 251 | {"-c", "%d", NULL, "Pick up an architecture # (Int)\n" \ 252 | "\t\t refer to the '-A' option" }, \ 253 | {"-S", "%u", NULL, "Clock source (Int)\n" \ 254 | "\t\t argument is one of the [0]TSC [1]BIOS [2]SPEC [3]ROM [4]USER" }, \ 255 | {"-M", "%x", NULL, "ROM address of the Base Clock (Hex)\n" \ 256 | "\t\t argument is the BCLK memory address to read from" }, \ 257 | {"-s", "%u", NULL, "Idle time multiplier (Int)\n" \ 258 | "\t\t argument is a coefficient multiplied by 50000 usec" }, \ 259 | {"-d", "%hhu", NULL, "Registers dump enablement (Bool)" }, \ 260 | {"-t", "%x", NULL, "Task scheduling monitoring sorted by 0x{R}0{N} (Hex)\n" \ 261 | "\t\t where {R} bit:8 is set to reverse sorting\n" \ 262 | "\t\t and {N} is one '/proc/sched_debug' field# from [0x1] to [0xb]" }, \ 263 | {"-z", "%hhu", NULL, "Reset the MSR counters (Bool)" }, \ 264 | {"-B", "%hhu", NULL, "Enable SmBIOS (Bool)" }, \ 265 | } 266 | 267 | typedef struct 268 | { 269 | unsigned int Addr; 270 | char *Name; 271 | } MSR_LIST; 272 | 273 | #define REG_LIST \ 274 | { \ 275 | { IA32_TIME_STAMP_COUNTER, "IA32_TIME_STAMP_COUNTER" }, \ 276 | { IA32_PLATFORM_ID, "IA32_PLATFORM_ID" }, \ 277 | { IA32_MPERF, "IA32_MPERF" }, \ 278 | { IA32_APERF, "IA32_APERF" }, \ 279 | { IA32_PERF_STATUS, "IA32_PERF_STATUS" }, \ 280 | { IA32_PERF_CTL, "IA32_PERF_CTL" }, \ 281 | { IA32_CLOCK_MODULATION, "IA32_CLOCK_MODULATION" }, \ 282 | { IA32_THERM_INTERRUPT, "IA32_THERM_INTERRUPT" }, \ 283 | { IA32_THERM_STATUS, "IA32_THERM_STATUS" }, \ 284 | { IA32_MISC_ENABLE, "IA32_MISC_ENABLE" }, \ 285 | { IA32_ENERGY_PERF_BIAS, "IA32_ENERGY_PERF_BIAS" }, \ 286 | { IA32_PKG_THERM_STATUS, "IA32_PKG_THERM_STATUS" }, \ 287 | { IA32_PKG_THERM_INTERRUPT, "IA32_PKG_THERM_INTERRUPT" }, \ 288 | { IA32_MTRR_DEF_TYPE, "IA32_MTRR_DEF_TYPE" }, \ 289 | { IA32_FIXED_CTR0, "IA32_FIXED_CTR0" }, \ 290 | { IA32_FIXED_CTR1, "IA32_FIXED_CTR1" }, \ 291 | { IA32_FIXED_CTR2, "IA32_FIXED_CTR2" }, \ 292 | { IA32_FIXED_CTR_CTRL, "IA32_FIXED_CTR_CTRL" }, \ 293 | { IA32_PERF_GLOBAL_STATUS, "IA32_PERF_GLOBAL_STATUS" }, \ 294 | { IA32_PERF_GLOBAL_CTRL, "IA32_PERF_GLOBAL_CTRL" }, \ 295 | { IA32_PERF_GLOBAL_OVF_CTRL, "IA32_PERF_GLOBAL_OVF_CTRL" }, \ 296 | { IA32_EFER, "IA32_EFER" }, \ 297 | { MSR_CORE_C3_RESIDENCY, "MSR_CORE_C3_RESIDENCY" }, \ 298 | { MSR_CORE_C6_RESIDENCY, "MSR_CORE_C6_RESIDENCY" }, \ 299 | { MSR_CORE_C7_RESIDENCY, "MSR_CORE_C7_RESIDENCY" }, \ 300 | { MSR_FSB_FREQ, "MSR_FSB_FREQ" }, \ 301 | { MSR_PLATFORM_INFO, "MSR_PLATFORM_INFO" }, \ 302 | { MSR_PKG_CST_CONFIG_CTRL, "MSR_PKG_CST_CONFIG_CTRL" }, \ 303 | { MSR_TURBO_RATIO_LIMIT, "MSR_TURBO_RATIO_LIMIT" }, \ 304 | { MSR_TEMPERATURE_TARGET, "MSR_TEMPERATURE_TARGET" }, \ 305 | { MSR_POWER_CTL, "MSR_POWER_CTL" }, \ 306 | { 0x0, NULL }, \ 307 | } 308 | 309 | typedef struct 310 | { 311 | struct 312 | { 313 | int Shm, 314 | SmBIOS; 315 | } FD; 316 | 317 | SHM_STRUCT *SHM; 318 | 319 | SMBIOS_TREE *SmBIOS, SmbTmpStorage; 320 | 321 | struct 322 | { 323 | size_t Shm, 324 | SmBIOS; 325 | } Size; 326 | 327 | FEATURES Features; 328 | ARCH Arch[ARCHITECTURES]; 329 | const DUMP_STRUCT Loader; 330 | 331 | Bool64 LOOP, fSmBIOS; 332 | OPTIONS Options[OPTIONS_COUNT]; 333 | 334 | sigset_t Signal; 335 | pthread_t TID_SigHandler, 336 | TID_Read, 337 | TID_Dump, 338 | TID_Schedule; 339 | struct SAVEAREA 340 | { 341 | GLOBAL_PERF_COUNTER GlobalPerfCounter; 342 | FIXED_PERF_COUNTER FixedPerfCounter; 343 | } *SaveArea; 344 | } uARG; 345 | 346 | typedef struct 347 | { 348 | long int cpu; 349 | pthread_t TID; 350 | uARG *A; 351 | } uAPIC; 352 | -------------------------------------------------------------------------------- /svr/xfreq-intel.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=XFreq Intel Daemon 3 | 4 | [Service] 5 | Type=simple 6 | ExecStart=/usr/bin/xfreq-intel 7 | ExecStop=/bin/kill -QUIT $MAINPID 8 | RemainAfterExit=no 9 | SuccessExitStatus=SIGQUIT SIGUSR1 SIGTERM 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | --------------------------------------------------------------------------------