├── .github └── workflows │ ├── arch-package.yml │ └── build.yml ├── LICENSE ├── Makefile ├── PKGBUILD ├── README.md ├── dkms.conf ├── zenergy-kmod.spec ├── zenergy.c └── zenergy.spec /.github/workflows/arch-package.yml: -------------------------------------------------------------------------------- 1 | name: Build Arch package 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | 7 | env: 8 | PKGDEST: "/tmp/package" 9 | 10 | jobs: 11 | build-package: 12 | runs-on: ubuntu-latest 13 | 14 | container: archlinux:base-devel 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Create build user 19 | run: | 20 | useradd -m build 21 | cp -vR . /home/build/amd-energy 22 | chown -vR build /home/build/amd-energy 23 | - name: Set up pacman keyring 24 | run: | 25 | pacman-key --init 26 | pacman-key --populate archlinux 27 | mkdir -p /etc/gnupg && echo "auto-key-retrieve" >> /etc/gnupg/gpg.conf 28 | - name: Install dependencies 29 | run: | 30 | pacman -Syu --noconfirm git dkms linux-headers linux 31 | - name: Build zenergy package 32 | id: build-package 33 | shell: bash 34 | run: | 35 | su build bash -c "cd /home/build/amd-energy && makepkg" 36 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - name: install dependencies 13 | run: | 14 | sudo apt update 15 | sudo apt install dkms linux-headers-$(uname -r) 16 | - name: DKMS install 17 | run: | 18 | make modules -------------------------------------------------------------------------------- /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 | # SPDX-License-Identifier: GPL-2.0 2 | # 3 | # Makefile for AMD Energy driver 4 | # 5 | # Copyright (C) 2021 Advanced Micro Devices, Inc. 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License version 2 9 | 10 | # If KDIR is not specified, assume the development source link 11 | # is in the modules directory for the running kernel 12 | KDIR ?= /lib/modules/`uname -r`/build 13 | obj-m := zenergy.o 14 | 15 | 16 | default: 17 | export CONFIG_SENSOR_zenergy=m; \ 18 | $(MAKE) -C $(KDIR) M=$$PWD modules 19 | 20 | modules: default 21 | 22 | modules_install: 23 | $(MAKE) -C $(KDIR) M=$$PWD modules_install 24 | 25 | clean: 26 | $(MAKE) -C $(KDIR) M=$$PWD clean 27 | 28 | help: 29 | @echo "\nThe following make targets are supported:\n" 30 | @echo "default\t\tBuild the driver module (or if no make target is supplied)" 31 | @echo "modules\t\tSame as default" 32 | @echo "modules_install\tBuild and install the driver module" 33 | @echo "clean" 34 | @echo 35 | 36 | .PHONY: default modules modules_install clean help 37 | 38 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: bouhaa 2 | 3 | _pkgname=zenergy 4 | pkgname=$_pkgname-dkms-git 5 | pkgver=11.91c3ca6 6 | pkgrel=1 7 | pkgdesc='Linux kernel driver for reading RAPL registers for AMD Zen CPUs' 8 | arch=('x86_64' 'i686') 9 | url='https://github.com/boukehaarsma23/zenergy' 10 | license=('GPL2') 11 | depends=('dkms') 12 | provides=('zenergy-dkms') 13 | 14 | source=("$_pkgname::git+$url.git") 15 | 16 | b2sums=("SKIP") 17 | 18 | pkgver() { 19 | cd "$srcdir/$_pkgname" 20 | printf "%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" 21 | } 22 | 23 | prepare() { 24 | sed -e "s/@CFLGS@//" \ 25 | -e "s/@VERSION@/$pkgver/" \ 26 | -i "$srcdir/$_pkgname/dkms.conf" 27 | } 28 | 29 | package() { 30 | install -Dm644 "$srcdir/$_pkgname/dkms.conf" "$pkgdir/usr/src/$_pkgname-$pkgver/dkms.conf" 31 | install -Dm644 "$srcdir/$_pkgname/Makefile" "$pkgdir/usr/src/$_pkgname-$pkgver/Makefile" 32 | install -Dm644 "$srcdir/$_pkgname/zenergy.c" "$pkgdir/usr/src/$_pkgname-$pkgver/zenergy.c" 33 | } 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zenergy kernel driver 2 | 3 | Based on AMD_ENERGY driver, but with some jiffies added so non-root users can read it safely. 4 | 5 | Kernel driver zenergy 6 | ========================== 7 | 8 | Prefix: 'zenergy' 9 | 10 | Addresses used: RAPL MSRs 11 | 12 | Datasheets: 13 | 14 | - Processor Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1 Processors 15 | 16 | https://developer.amd.com/wp-content/resources/55570-B1_PUB.zip 17 | 18 | - Preliminary Processor Programming Reference (PPR) for AMD Family 17h Model 31h, Revision B0 Processors 19 | 20 | https://developer.amd.com/wp-content/resources/56176_ppr_Family_17h_Model_71h_B0_pub_Rev_3.06.zip 21 | 22 | - Preliminary Processor Programming Reference (PPR) for AMD Family 19h Model 1h, Revision B1 Processors 23 | 24 | https://www.amd.com/system/files/TechDocs/55898_pub.zip 25 | 26 | Author: Naveen Krishna Chatradhi 27 | 28 | Description 29 | ----------- 30 | 31 | The Energy driver exposes the energy counters that are 32 | reported via the Running Average Power Limit (RAPL) 33 | Model-specific Registers (MSRs) via the hardware monitor 34 | (HWMON) sysfs interface. 35 | 36 | 1. Power, Energy and Time Units 37 | MSR_RAPL_POWER_UNIT/ C001_0299: 38 | shared with all cores in the socket 39 | 40 | 2. Energy consumed by each Core 41 | MSR_CORE_ENERGY_STATUS/ C001_029A: 42 | 32-bitRO, Accumulator, core-level power reporting 43 | 44 | 3. Energy consumed by Socket 45 | MSR_PACKAGE_ENERGY_STATUS/ C001_029B: 46 | 32-bitRO, Accumulator, socket-level power reporting, 47 | shared with all cores in socket 48 | 49 | These registers are updated every 1ms and cleared on 50 | reset of the system. 51 | 52 | Note: If SMT is enabled, Linux enumerates all threads as cpus. 53 | Since, the energy status registers are accessed at core level, 54 | reading those registers from the sibling threads would result 55 | in duplicate values. Hence, energy counter entries are not 56 | populated for the siblings. 57 | 58 | Energy Caluclation 59 | ------------------ 60 | 61 | Energy information (in Joules) is based on the multiplier, 62 | 1/2^ESU; where ESU is an unsigned integer read from 63 | MSR_RAPL_POWER_UNIT register. Default value is 10000b, 64 | indicating energy status unit is 15.3 micro-Joules increment. 65 | 66 | Reported values are scaled as per the formula 67 | `scaled value = ((1/2^ESU) * (Raw value) * 1000000UL)` in uJoules 68 | 69 | Users calculate power for a given domain by calculating 70 | dEnergy/dTime for that domain. 71 | 72 | Energy accumulation 73 | -------------------------- 74 | 75 | Current, Socket energy status register is 32bit, assuming a 240W 76 | 2P system, the register would wrap around in 77 | 78 | `2^32*15.3 e-6/240 * 2 = 547.60833024` secs to wrap(~9 mins) 79 | 80 | The Core energy register may wrap around after several days. 81 | 82 | To improve the wrap around time, a kernel thread is implemented 83 | to accumulate the socket energy counters and one core energy counter 84 | per run to a respective 64-bit counter. The kernel thread starts 85 | running during probe, wakes up every 100secs and stops running 86 | when driver is removed. 87 | 88 | Frequency of the accumulator thread is set during the probe 89 | based on the chosen energy unit resolution. For example 90 | A. fine grain (1.625 micro J) 91 | B. course grain (0.125 milli J) 92 | 93 | A socket and core energy read would return the current register 94 | value added to the respective energy accumulator. 95 | 96 | On newer EPYC CPUs with 64bit RAPL energy MSRs, software accumulation 97 | of energy counters is not required. Hence, accumulation is enabled 98 | only on select EPYC CPUs with 32bit RAPL MSRs. 99 | 100 | Sysfs attributes 101 | ---------------- 102 | 103 | | Attribute | Label | Description | 104 | | --------------- | ----------------- | ------------------------------------------------------------ | 105 | | energy[X]_input | Ecore[X] energy | X = [0] to [nr_cpus - 1] Measured input core energy | 106 | | energy[X]_input | Esocket[X] energy | X = [nr_cpus] to [nr_socks - 1] Measured input socket energy | 107 | 108 | Build and Install 109 | ----------------- 110 | 111 | Kernel development packages for the running kernel need to be installed 112 | prior to building the Energy module. A Makefile is provided which should 113 | work with most kernel source trees. 114 | 115 | To build the kernel module: 116 | ``` 117 | #> make 118 | ``` 119 | To install the kernel module: 120 | ``` 121 | #> sudo make modules_install 122 | ``` 123 | To clean the kernel module build directory: 124 | ``` 125 | #> make clean 126 | ``` 127 | 128 | Loading 129 | ------- 130 | 131 | If the Energy module was installed you should use the modprobe command to 132 | load the module. 133 | ``` 134 | #> sudo modprobe zenergy 135 | ``` 136 | The Energy module can also be loaded using insmod if the module was not 137 | installed: 138 | ``` 139 | #> sudo insmod ./zenergy.ko 140 | ``` 141 | 142 | DKMS support 143 | ------------ 144 | 145 | Building Module with running version of kernel 146 | 147 | Add the module to DKMS tree: 148 | ``` 149 | #> sudo dkms add ../zenergy 150 | ``` 151 | Build the module using DKMS: 152 | ``` 153 | #> sudo dkms build -m zenergy/1.0 154 | ``` 155 | Install the module using DKMS: 156 | ``` 157 | #> sudo dkms install --force zenergy/1.0 158 | ``` 159 | Load the module: 160 | ``` 161 | #> sudo modprobe zenergy 162 | ``` 163 | Building Module with specific version of kernel 164 | 165 | Add the module to DKMS tree: 166 | ``` 167 | #> sudo dkms add ../zenergy 168 | ``` 169 | Build the module using DKMS: 170 | ``` 171 | #> sudo dkms build zenergy/1.0 -k linux_version 172 | ``` 173 | Install the module using DKMS: 174 | ``` 175 | #> sudo dkms install --force zenergy/1.0 -k linux_version 176 | ``` 177 | Module is built: /lib/modules/linux_version/updates/dkms/ 178 | 179 | Notes: It is required to have specific linux verion header in /usr/src 180 | 181 | To remove module from dkms tree 182 | ``` 183 | #> sudo dkms remove -m zenergy/1.0 --all 184 | #> sudo rm -rf /usr/src/zenergy-1.0/ 185 | ``` -------------------------------------------------------------------------------- /dkms.conf: -------------------------------------------------------------------------------- 1 | PACKAGE_NAME="zenergy" 2 | PACKAGE_VERSION="@VERSION@" 3 | BUILT_MODULE_NAME="zenergy" 4 | DEST_MODULE_LOCATION[0]="/kernel/drivers/hwmon/zenergy" 5 | AUTOINSTALL="yes" 6 | MAKE[0]="make default KDIR='/lib/modules/${kernelver}/build'" 7 | CLEAN="make clean" 8 | -------------------------------------------------------------------------------- /zenergy-kmod.spec: -------------------------------------------------------------------------------- 1 | %if 0%{?fedora} 2 | %global buildforkernels akmod 3 | %global debug_package %{nil} 4 | %endif 5 | 6 | Name: zenergy-kmod 7 | Version: {{{ git_dir_version }}} 8 | Release: 1%{?dist} 9 | Summary: Exposes the energy counters that are reported via the Running Average Power Limit (RAPL) Model-specific Registers (MSRs) via the hardware monitor (HWMON) sysfs interface. 10 | License: GPLv2 11 | URL: https://github.com/BoukeHaarsma23/zenergy 12 | 13 | Source: %{url}/archive/refs/heads/master.tar.gz 14 | 15 | BuildRequires: kmodtool 16 | 17 | %{expand:%(kmodtool --target %{_target_cpu} --kmodname %{name} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null) } 18 | 19 | %description 20 | Based on AMD_ENERGY driver, but with some jiffies added so non-root users can read it safely. Exposes the energy counters that are reported via the Running Average Power Limit (RAPL) Model-specific Registers (MSRs) via the hardware monitor (HWMON) sysfs interface. 21 | 22 | %prep 23 | # error out if there was something wrong with kmodtool 24 | %{?kmodtool_check} 25 | 26 | # print kmodtool output for debugging purposes: 27 | kmodtool --target %{_target_cpu} --kmodname %{name} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null 28 | 29 | %setup -q -c zenergy-master 30 | 31 | find . -type f -name '*.c' -exec sed -i "s/#VERSION#/%{version}/" {} \+ 32 | 33 | for kernel_version in %{?kernel_versions} ; do 34 | cp -a zenergy-master _kmod_build_${kernel_version%%___*} 35 | done 36 | 37 | %build 38 | for kernel_version in %{?kernel_versions} ; do 39 | make V=1 %{?_smp_mflags} -C ${kernel_version##*___} M=${PWD}/_kmod_build_${kernel_version%%___*} VERSION=v%{version} modules 40 | done 41 | 42 | %install 43 | for kernel_version in %{?kernel_versions}; do 44 | mkdir -p %{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/ 45 | install -D -m 755 _kmod_build_${kernel_version%%___*}/zenergy.ko %{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/ 46 | chmod a+x %{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/zenergy.ko 47 | done 48 | %{?akmod_install} 49 | 50 | %changelog 51 | {{{ git_dir_changelog }}} 52 | -------------------------------------------------------------------------------- /zenergy.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-only 2 | 3 | /* 4 | * Copyright (C) 2020 Advanced Micro Devices, Inc. 5 | * Edited by BouHaa (http://github.com/boukehaarsma23) 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 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 | #include 26 | #include 27 | #include 28 | 29 | #define DRV_MODULE_DESCRIPTION "AMD energy driver" 30 | #define DRV_MODULE_VERSION "1.0" 31 | 32 | MODULE_VERSION(DRV_MODULE_VERSION); 33 | 34 | #define DRVNAME "zenergy" 35 | 36 | #define ENERGY_PWR_UNIT_MSR 0xC0010299 37 | #define ENERGY_CORE_MSR 0xC001029A 38 | #define ENERGY_PKG_MSR 0xC001029B 39 | 40 | #define zenergy_UNIT_MASK 0x01F00 41 | #define zenergy_MASK 0xFFFFFFFF 42 | 43 | struct sensor_accumulator { 44 | u64 energy_ctr; 45 | u64 prev_value; 46 | unsigned long cache_timeout; 47 | }; 48 | 49 | struct zenergy_data { 50 | struct hwmon_channel_info energy_info; 51 | const struct hwmon_channel_info *info[2]; 52 | struct hwmon_chip_info chip; 53 | struct task_struct *wrap_accumulate; 54 | /* Lock around the accumulator */ 55 | struct mutex lock; 56 | /* An accumulator for each core and socket */ 57 | struct sensor_accumulator *accums; 58 | unsigned int timeout_ms; 59 | /* Energy Status Units */ 60 | int energy_units; 61 | int nr_cpus; 62 | int nr_socks; 63 | int core_id; 64 | char (*label)[10]; 65 | bool do_not_accum; 66 | }; 67 | 68 | static int zenergy_read_labels(struct device *dev, 69 | enum hwmon_sensor_types type, 70 | u32 attr, int channel, 71 | const char **str) 72 | { 73 | struct zenergy_data *data = dev_get_drvdata(dev); 74 | 75 | *str = data->label[channel]; 76 | return 0; 77 | } 78 | 79 | static void get_energy_units(struct zenergy_data *data) 80 | { 81 | u64 rapl_units; 82 | 83 | rdmsrl_safe(ENERGY_PWR_UNIT_MSR, &rapl_units); 84 | data->energy_units = (rapl_units & zenergy_UNIT_MASK) >> 8; 85 | } 86 | 87 | static void __accumulate_delta(struct sensor_accumulator *accum, 88 | int cpu, u32 reg) 89 | { 90 | u64 input; 91 | 92 | rdmsrl_safe_on_cpu(cpu, reg, &input); 93 | input &= zenergy_MASK; 94 | 95 | if (input >= accum->prev_value) 96 | accum->energy_ctr += 97 | input - accum->prev_value; 98 | else 99 | accum->energy_ctr += UINT_MAX - 100 | accum->prev_value + input; 101 | 102 | accum->prev_value = input; 103 | accum->cache_timeout = (jiffies + HZ + get_random_long()) % HZ; 104 | } 105 | 106 | static void accumulate_delta(struct zenergy_data *data, 107 | int channel, int cpu, u32 reg) 108 | { 109 | mutex_lock(&data->lock); 110 | __accumulate_delta(&data->accums[channel], cpu, reg); 111 | mutex_unlock(&data->lock); 112 | } 113 | 114 | static void read_accumulate(struct zenergy_data *data) 115 | { 116 | int sock, scpu, cpu; 117 | 118 | for (sock = 0; sock < data->nr_socks; sock++) { 119 | scpu = cpumask_first_and(cpu_online_mask, 120 | cpumask_of_node(sock)); 121 | 122 | accumulate_delta(data, data->nr_cpus + sock, 123 | scpu, ENERGY_PKG_MSR); 124 | } 125 | 126 | if (data->core_id >= data->nr_cpus) 127 | data->core_id = 0; 128 | 129 | cpu = data->core_id; 130 | if (cpu_online(cpu)) 131 | accumulate_delta(data, cpu, cpu, ENERGY_CORE_MSR); 132 | 133 | data->core_id++; 134 | } 135 | 136 | static int zenergy_read(struct device *dev, 137 | enum hwmon_sensor_types type, 138 | u32 attr, int channel, long *val) 139 | { 140 | struct zenergy_data *data = dev_get_drvdata(dev); 141 | struct sensor_accumulator *accum; 142 | u64 energy; 143 | u32 reg; 144 | int cpu; 145 | 146 | if (channel >= data->nr_cpus) { 147 | cpu = cpumask_first_and(cpu_online_mask, 148 | cpumask_of_node 149 | (channel - data->nr_cpus)); 150 | reg = ENERGY_PKG_MSR; 151 | } else { 152 | cpu = channel; 153 | if (!cpu_online(cpu)) 154 | return -ENODEV; 155 | 156 | reg = ENERGY_CORE_MSR; 157 | } 158 | 159 | accum = &data->accums[channel]; 160 | 161 | mutex_lock(&data->lock); 162 | if (!accum->energy_ctr || time_after(jiffies, accum->cache_timeout)) 163 | __accumulate_delta(accum, cpu, reg); 164 | energy = accum->energy_ctr; 165 | mutex_unlock(&data->lock); 166 | 167 | *val = div64_ul(energy * 1000000UL, BIT(data->energy_units)); 168 | 169 | return 0; 170 | } 171 | 172 | static umode_t zenergy_is_visible(const void *_data, 173 | enum hwmon_sensor_types type, 174 | u32 attr, int channel) 175 | { 176 | return 0444; 177 | } 178 | 179 | static int energy_accumulator(void *p) 180 | { 181 | struct zenergy_data *data = (struct zenergy_data *)p; 182 | unsigned int timeout = data->timeout_ms; 183 | 184 | while (!kthread_should_stop()) { 185 | /* 186 | * Ignoring the conditions such as 187 | * cpu being offline or rdmsr failure 188 | */ 189 | read_accumulate(data); 190 | 191 | set_current_state(TASK_INTERRUPTIBLE); 192 | if (kthread_should_stop()) 193 | break; 194 | 195 | schedule_timeout(msecs_to_jiffies(timeout)); 196 | } 197 | return 0; 198 | } 199 | 200 | static const struct hwmon_ops zenergy_ops = { 201 | .is_visible = zenergy_is_visible, 202 | .read = zenergy_read, 203 | .read_string = zenergy_read_labels, 204 | }; 205 | 206 | static int amd_create_sensor(struct device *dev, 207 | struct zenergy_data *data, 208 | enum hwmon_sensor_types type, u32 config) 209 | { 210 | struct hwmon_channel_info *info = &data->energy_info; 211 | #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 9, 0) 212 | struct cpuinfo_x86 *c = &boot_cpu_data; 213 | int num_siblings; 214 | #endif 215 | struct sensor_accumulator *accums; 216 | int i, cpus, sockets; 217 | u32 *s_config; 218 | char (*label_l)[10]; 219 | 220 | #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 9, 0) 221 | /* Identify the number of siblings per core */ 222 | num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; 223 | 224 | /* 225 | * Energy counter register is accessed at core level. 226 | * Hence, filterout the siblings. 227 | */ 228 | cpus = num_present_cpus() / num_siblings; 229 | 230 | /* 231 | * topology_num_cores_per_package (or c->x86_max_cores prior to 6.9) is 232 | * the linux count of physical cores. 233 | * total physical cores/ core per socket gives total number of sockets. 234 | */ 235 | 236 | sockets = cpus / c->x86_max_cores; 237 | #else 238 | cpus = num_present_cpus() / __max_threads_per_core; 239 | sockets = cpus / topology_num_cores_per_package(); 240 | #endif 241 | 242 | s_config = devm_kcalloc(dev, cpus + sockets + 1, 243 | sizeof(u32), GFP_KERNEL); 244 | if (!s_config) 245 | return -ENOMEM; 246 | 247 | accums = devm_kcalloc(dev, cpus + sockets, 248 | sizeof(struct sensor_accumulator), 249 | GFP_KERNEL); 250 | if (!accums) 251 | return -ENOMEM; 252 | 253 | label_l = devm_kcalloc(dev, cpus + sockets, 254 | sizeof(*label_l), GFP_KERNEL); 255 | if (!label_l) 256 | return -ENOMEM; 257 | 258 | info->type = type; 259 | info->config = s_config; 260 | 261 | data->nr_cpus = cpus; 262 | data->nr_socks = sockets; 263 | data->accums = accums; 264 | data->label = label_l; 265 | 266 | for (i = 0; i < cpus + sockets; i++) { 267 | s_config[i] = config; 268 | if (i < cpus) 269 | scnprintf(label_l[i], 10, "Ecore%03u", i); 270 | else 271 | scnprintf(label_l[i], 10, "Esocket%u", (i - cpus)); 272 | } 273 | 274 | s_config[i] = 0; 275 | return 0; 276 | } 277 | 278 | static const struct x86_cpu_id bit32_rapl_cpus[] = { 279 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x01, NULL), /* Zen */ 280 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x08, NULL), /* Zen+ */ 281 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x11, NULL), /* Zen APU */ 282 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x18, NULL), /* Picasso */ 283 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x20, NULL), /* Picasso APU */ 284 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x31, NULL), /* Zen2 Threadripper */ 285 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x60, NULL), /* Renoir */ 286 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x68, NULL), /* Lucienne */ 287 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x71, NULL), /* Zen2 */ 288 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x01, NULL), /* Zen3 Threadripper */ 289 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x21, NULL), /* Zen3 */ 290 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x50, NULL), /* Cezanne */ 291 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x44, NULL), /* Rembrandt */ 292 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x60, NULL), /* Rembrandt */ 293 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x1A, 0x44, NULL), /* Granite Ridge */ 294 | // Zen4 (0x19, 0x61) features 64-bit registers for both Core::X86::Msr::CORE_ENERGY_STAT & L3::L3CT::L3PackageEnergyStatus), 295 | // c.f., https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/56713-B1_3_05.zip 296 | {} 297 | }; 298 | 299 | static int zenergy_probe(struct platform_device *pdev) 300 | { 301 | struct device *hwmon_dev; 302 | struct zenergy_data *data; 303 | struct device *dev = &pdev->dev; 304 | int ret; 305 | 306 | data = devm_kzalloc(dev, 307 | sizeof(struct zenergy_data), GFP_KERNEL); 308 | if (!data) 309 | return -ENOMEM; 310 | 311 | data->chip.ops = &zenergy_ops; 312 | data->chip.info = data->info; 313 | 314 | dev_set_drvdata(dev, data); 315 | /* Populate per-core energy reporting */ 316 | data->info[0] = &data->energy_info; 317 | ret = amd_create_sensor(dev, data, hwmon_energy, 318 | HWMON_E_INPUT | HWMON_E_LABEL); 319 | if (ret) 320 | return ret; 321 | 322 | mutex_init(&data->lock); 323 | get_energy_units(data); 324 | 325 | hwmon_dev = devm_hwmon_device_register_with_info(dev, DRVNAME, 326 | data, 327 | &data->chip, 328 | NULL); 329 | if (IS_ERR(hwmon_dev)) 330 | return PTR_ERR(hwmon_dev); 331 | 332 | /* 333 | * On a system with peak wattage of 250W 334 | * timeout = 2 ^ 32 / 2 ^ energy_units / 250 secs 335 | */ 336 | data->timeout_ms = 1000 * 337 | BIT(min(28, 31 - data->energy_units)) / 250; 338 | 339 | /* 340 | * For AMD platforms with 64-bit RAPL MSR registers, accumulation 341 | * of the energy counters are not necessary. 342 | */ 343 | if (!x86_match_cpu(bit32_rapl_cpus)) { 344 | data->do_not_accum = true; 345 | pr_info("CPU supports 64-bit RAPL MSR registers\n"); 346 | return 0; 347 | } 348 | 349 | data->wrap_accumulate = kthread_run(energy_accumulator, data, 350 | "%s", dev_name(hwmon_dev)); 351 | return PTR_ERR_OR_ZERO(data->wrap_accumulate); 352 | } 353 | 354 | #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0) 355 | static int zenergy_remove(struct platform_device *pdev) 356 | #else 357 | static void zenergy_remove(struct platform_device *pdev) 358 | #endif 359 | { 360 | struct zenergy_data *data = dev_get_drvdata(&pdev->dev); 361 | 362 | if (data && data->wrap_accumulate) 363 | kthread_stop(data->wrap_accumulate); 364 | 365 | #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0) 366 | return 0; 367 | #endif 368 | } 369 | 370 | static const struct platform_device_id zenergy_ids[] = { 371 | { .name = DRVNAME, }, 372 | {} 373 | }; 374 | MODULE_DEVICE_TABLE(platform, zenergy_ids); 375 | 376 | static struct platform_driver zenergy_driver = { 377 | .probe = zenergy_probe, 378 | .remove = zenergy_remove, 379 | .id_table = zenergy_ids, 380 | .driver = { 381 | .name = DRVNAME, 382 | }, 383 | }; 384 | 385 | static struct platform_device *zenergy_platdev; 386 | 387 | static const struct x86_cpu_id cpu_ids[] __initconst = { 388 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x01, NULL), /* Zen */ 389 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x08, NULL), /* Zen+ */ 390 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x11, NULL), /* Zen APU */ 391 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x18, NULL), /* Picasso */ 392 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x20, NULL), /* Picasso APU */ 393 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x31, NULL), /* Zen2 Threadripper */ 394 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x60, NULL), /* Renoir */ 395 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x68, NULL), /* Lucienne */ 396 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x17, 0x71, NULL), /* Zen2 */ 397 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x01, NULL), /* Zen3 Threadripper */ 398 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x21, NULL), /* Zen3 */ 399 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x50, NULL), /* Cezanne */ 400 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x44, NULL), /* Rembrandt */ 401 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x60, NULL), /* Rembrandt */ 402 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x19, 0x61, NULL), /* Zen 4 */ 403 | X86_MATCH_VENDOR_FAM_MODEL(AMD, 0x1A, 0x44, NULL), /* Zen 5 */ 404 | {} 405 | }; 406 | MODULE_DEVICE_TABLE(x86cpu, cpu_ids); 407 | 408 | static int __init zenergy_init(void) 409 | { 410 | int ret; 411 | 412 | if (!x86_match_cpu(cpu_ids)) 413 | return -ENODEV; 414 | 415 | ret = platform_driver_register(&zenergy_driver); 416 | if (ret) 417 | return ret; 418 | 419 | zenergy_platdev = platform_device_alloc(DRVNAME, 0); 420 | if (!zenergy_platdev) { 421 | platform_driver_unregister(&zenergy_driver); 422 | return -ENOMEM; 423 | } 424 | 425 | ret = platform_device_add(zenergy_platdev); 426 | if (ret) { 427 | platform_device_put(zenergy_platdev); 428 | platform_driver_unregister(&zenergy_driver); 429 | return ret; 430 | } 431 | 432 | return ret; 433 | } 434 | 435 | static void __exit zenergy_exit(void) 436 | { 437 | platform_device_unregister(zenergy_platdev); 438 | platform_driver_unregister(&zenergy_driver); 439 | } 440 | 441 | module_init(zenergy_init); 442 | module_exit(zenergy_exit); 443 | 444 | MODULE_DESCRIPTION("Driver for AMD Energy reporting from RAPL MSR via HWMON interface"); 445 | MODULE_AUTHOR("Naveen Krishna Chatradhi "); 446 | MODULE_LICENSE("GPL"); 447 | -------------------------------------------------------------------------------- /zenergy.spec: -------------------------------------------------------------------------------- 1 | %if 0%{?fedora} 2 | %global debug_package %{nil} 3 | %endif 4 | 5 | Name: zenergy 6 | Version: {{{ git_dir_version }}} 7 | Release: 1%{?dist} 8 | Summary: Exposes the energy counters that are reported via the Running Average Power Limit (RAPL) Model-specific Registers (MSRs) via the hardware monitor (HWMON) sysfs interface. 9 | License: GPLv2 10 | URL: https://github.com/BoukeHaarsma23/zenergy 11 | 12 | Source: %{url}/archive/refs/heads/master.tar.gz 13 | 14 | Provides: %{name}-kmod-common = %{version} 15 | Requires: %{name}-kmod >= %{version} 16 | 17 | BuildRequires: systemd-rpm-macros 18 | 19 | %description 20 | Based on AMD_ENERGY driver, but with some jiffies added so non-root users can read it safely. Exposes the energy counters that are reported via the Running Average Power Limit (RAPL) Model-specific Registers (MSRs) via the hardware monitor (HWMON) sysfs interface. 21 | 22 | %prep 23 | %setup -q -c %{name}-master 24 | 25 | %files 26 | %doc %{name}-master/README.md 27 | %license %{name}-master/LICENSE 28 | 29 | %changelog 30 | {{{ git_dir_changelog }}} 31 | --------------------------------------------------------------------------------