Skip to content

Commit 2bcc3e2

Browse files
committed
Sync latest code with RyzenAdj
Signed-off-by: Jiaxun Yang <[email protected]>
1 parent b3768bf commit 2bcc3e2

File tree

6 files changed

+342
-11
lines changed

6 files changed

+342
-11
lines changed

smu-tool/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ target_link_libraries(${PROJECT_NAME} WinRing0x64)
2424
else()
2525
ADD_EXECUTABLE(${PROJECT_NAME} libpci.cpp nb_smu_ops.cpp argparse.cpp main.cpp)
2626
target_link_libraries(${PROJECT_NAME} pci)
27-
endif()
27+
endif()

smu-tool/Makefile

+268
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
# CMAKE generated file: DO NOT EDIT!
2+
# Generated by "Unix Makefiles" Generator, CMake Version 3.13
3+
4+
# Default target executed when no arguments are given to make.
5+
default_target: all
6+
7+
.PHONY : default_target
8+
9+
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
10+
.NOTPARALLEL:
11+
12+
13+
#=============================================================================
14+
# Special targets provided by cmake.
15+
16+
# Disable implicit rules so canonical targets will work.
17+
.SUFFIXES:
18+
19+
20+
# Remove some rules from gmake that .SUFFIXES does not remove.
21+
SUFFIXES =
22+
23+
.SUFFIXES: .hpux_make_needs_suffix_list
24+
25+
26+
# Suppress display of executed commands.
27+
$(VERBOSE).SILENT:
28+
29+
30+
# A target that is always out of date.
31+
cmake_force:
32+
33+
.PHONY : cmake_force
34+
35+
#=============================================================================
36+
# Set environment variables for the build.
37+
38+
# The shell in which to execute make rules.
39+
SHELL = /bin/sh
40+
41+
# The CMake executable.
42+
CMAKE_COMMAND = /usr/bin/cmake
43+
44+
# The command to remove a file.
45+
RM = /usr/bin/cmake -E remove -f
46+
47+
# Escaping for special characters.
48+
EQUALS = =
49+
50+
# The top-level source directory on which CMake was run.
51+
CMAKE_SOURCE_DIR = /home/flygoat/ryzen_nb_smu/smu-tool
52+
53+
# The top-level build directory on which CMake was run.
54+
CMAKE_BINARY_DIR = /home/flygoat/ryzen_nb_smu/smu-tool
55+
56+
#=============================================================================
57+
# Targets provided globally by CMake.
58+
59+
# Special rule for the target rebuild_cache
60+
rebuild_cache:
61+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
62+
/usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
63+
.PHONY : rebuild_cache
64+
65+
# Special rule for the target rebuild_cache
66+
rebuild_cache/fast: rebuild_cache
67+
68+
.PHONY : rebuild_cache/fast
69+
70+
# Special rule for the target edit_cache
71+
edit_cache:
72+
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
73+
/usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
74+
.PHONY : edit_cache
75+
76+
# Special rule for the target edit_cache
77+
edit_cache/fast: edit_cache
78+
79+
.PHONY : edit_cache/fast
80+
81+
# The main all target
82+
all: cmake_check_build_system
83+
$(CMAKE_COMMAND) -E cmake_progress_start /home/flygoat/ryzen_nb_smu/smu-tool/CMakeFiles /home/flygoat/ryzen_nb_smu/smu-tool/CMakeFiles/progress.marks
84+
$(MAKE) -f CMakeFiles/Makefile2 all
85+
$(CMAKE_COMMAND) -E cmake_progress_start /home/flygoat/ryzen_nb_smu/smu-tool/CMakeFiles 0
86+
.PHONY : all
87+
88+
# The main clean target
89+
clean:
90+
$(MAKE) -f CMakeFiles/Makefile2 clean
91+
.PHONY : clean
92+
93+
# The main clean target
94+
clean/fast: clean
95+
96+
.PHONY : clean/fast
97+
98+
# Prepare targets for installation.
99+
preinstall: all
100+
$(MAKE) -f CMakeFiles/Makefile2 preinstall
101+
.PHONY : preinstall
102+
103+
# Prepare targets for installation.
104+
preinstall/fast:
105+
$(MAKE) -f CMakeFiles/Makefile2 preinstall
106+
.PHONY : preinstall/fast
107+
108+
# clear depends
109+
depend:
110+
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
111+
.PHONY : depend
112+
113+
#=============================================================================
114+
# Target rules for targets named ryzenadj
115+
116+
# Build rule for target.
117+
ryzenadj: cmake_check_build_system
118+
$(MAKE) -f CMakeFiles/Makefile2 ryzenadj
119+
.PHONY : ryzenadj
120+
121+
# fast build rule for target.
122+
ryzenadj/fast:
123+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/build
124+
.PHONY : ryzenadj/fast
125+
126+
argparse.o: argparse.cpp.o
127+
128+
.PHONY : argparse.o
129+
130+
# target to build an object file
131+
argparse.cpp.o:
132+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/argparse.cpp.o
133+
.PHONY : argparse.cpp.o
134+
135+
argparse.i: argparse.cpp.i
136+
137+
.PHONY : argparse.i
138+
139+
# target to preprocess a source file
140+
argparse.cpp.i:
141+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/argparse.cpp.i
142+
.PHONY : argparse.cpp.i
143+
144+
argparse.s: argparse.cpp.s
145+
146+
.PHONY : argparse.s
147+
148+
# target to generate assembly for a file
149+
argparse.cpp.s:
150+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/argparse.cpp.s
151+
.PHONY : argparse.cpp.s
152+
153+
libpci.o: libpci.cpp.o
154+
155+
.PHONY : libpci.o
156+
157+
# target to build an object file
158+
libpci.cpp.o:
159+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/libpci.cpp.o
160+
.PHONY : libpci.cpp.o
161+
162+
libpci.i: libpci.cpp.i
163+
164+
.PHONY : libpci.i
165+
166+
# target to preprocess a source file
167+
libpci.cpp.i:
168+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/libpci.cpp.i
169+
.PHONY : libpci.cpp.i
170+
171+
libpci.s: libpci.cpp.s
172+
173+
.PHONY : libpci.s
174+
175+
# target to generate assembly for a file
176+
libpci.cpp.s:
177+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/libpci.cpp.s
178+
.PHONY : libpci.cpp.s
179+
180+
main.o: main.cpp.o
181+
182+
.PHONY : main.o
183+
184+
# target to build an object file
185+
main.cpp.o:
186+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/main.cpp.o
187+
.PHONY : main.cpp.o
188+
189+
main.i: main.cpp.i
190+
191+
.PHONY : main.i
192+
193+
# target to preprocess a source file
194+
main.cpp.i:
195+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/main.cpp.i
196+
.PHONY : main.cpp.i
197+
198+
main.s: main.cpp.s
199+
200+
.PHONY : main.s
201+
202+
# target to generate assembly for a file
203+
main.cpp.s:
204+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/main.cpp.s
205+
.PHONY : main.cpp.s
206+
207+
nb_smu_ops.o: nb_smu_ops.cpp.o
208+
209+
.PHONY : nb_smu_ops.o
210+
211+
# target to build an object file
212+
nb_smu_ops.cpp.o:
213+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/nb_smu_ops.cpp.o
214+
.PHONY : nb_smu_ops.cpp.o
215+
216+
nb_smu_ops.i: nb_smu_ops.cpp.i
217+
218+
.PHONY : nb_smu_ops.i
219+
220+
# target to preprocess a source file
221+
nb_smu_ops.cpp.i:
222+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/nb_smu_ops.cpp.i
223+
.PHONY : nb_smu_ops.cpp.i
224+
225+
nb_smu_ops.s: nb_smu_ops.cpp.s
226+
227+
.PHONY : nb_smu_ops.s
228+
229+
# target to generate assembly for a file
230+
nb_smu_ops.cpp.s:
231+
$(MAKE) -f CMakeFiles/ryzenadj.dir/build.make CMakeFiles/ryzenadj.dir/nb_smu_ops.cpp.s
232+
.PHONY : nb_smu_ops.cpp.s
233+
234+
# Help Target
235+
help:
236+
@echo "The following are some of the valid targets for this Makefile:"
237+
@echo "... all (the default if no target is provided)"
238+
@echo "... clean"
239+
@echo "... depend"
240+
@echo "... rebuild_cache"
241+
@echo "... ryzenadj"
242+
@echo "... edit_cache"
243+
@echo "... argparse.o"
244+
@echo "... argparse.i"
245+
@echo "... argparse.s"
246+
@echo "... libpci.o"
247+
@echo "... libpci.i"
248+
@echo "... libpci.s"
249+
@echo "... main.o"
250+
@echo "... main.i"
251+
@echo "... main.s"
252+
@echo "... nb_smu_ops.o"
253+
@echo "... nb_smu_ops.i"
254+
@echo "... nb_smu_ops.s"
255+
.PHONY : help
256+
257+
258+
259+
#=============================================================================
260+
# Special targets to cleanup operation of make.
261+
262+
# Special rule to run CMake to check the build system integrity.
263+
# No rule that depends on this can have commands that come from listfiles
264+
# because they might be regenerated.
265+
cmake_check_build_system:
266+
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
267+
.PHONY : cmake_check_build_system
268+

smu-tool/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# RyzenAdj
2+
Adjust power management settings for Ryzen Processors.
3+
4+
Based on: [FlyGoat/ryzen_nb_smu](https://github.com/flygoat/ryzen_nb_smu)
5+
6+
## Usage
7+
The command line interface is identical on both Windows and Unix-Like OS.
8+
9+
You should run it with Administrator on Windows or root on Linux.
10+
11+
You can write a shell script or bat to do it automaticly.
12+
13+
```
14+
$./ryzenadj -h
15+
16+
Usage: ryzenadj [options] [[--] args]
17+
or: ryzenadj [options]
18+
19+
Ryzen Power Management adjust tool.
20+
21+
-h, --help show this help message and exit
22+
23+
Options
24+
-i, --info Show information (W.I.P.)
25+
26+
Settings
27+
-a, --stapm-limit=<u32> Sustained power limit (10e-3 W)
28+
-b, --fast-limit=<u32> Fast PPT power limit (10e-3 W)
29+
-c, --slow-limit=<u32> Slow PPT power limit (10e-3 W)
30+
-d, --slow-time=<u32> Slow PPT constant time (ms)
31+
-e, --stapm-time=<u32> STAMP constant time (ms)
32+
-f, --tctl-temp=<u32> Tctl temperature (℃)
33+
-g, --vrm-current=<u32> Vrm Current Limit (mA)
34+
-j, --vrmsoc-current=<u32> Vrm SoC Current Limit (mA)
35+
-k, --vrmmax-current=<u32> Vrm Maximum Current Limit (mA)
36+
-l, --vrmsocmax-current=<u32> Vrm SoC Maximum Current Limit (mA)
37+
-m, --psi0-current=<u32> PSI0 Current Limit (mA)
38+
-n, --psi0soc-current=<u32> PSI0 SoC Current Limit (mA)
39+
```
40+
41+
### demo
42+
If I'm going to set all the Power Limit to 45W, and Tctl to 90 ℃,
43+
then the command line should be:
44+
```
45+
./ryzenadj --stapm-limit=45000 --fast-limit=45000 --slow-limit=45000 --tctl-temp=90
46+
```
47+
48+
## Build
49+
### Linux
50+
This project uses cmake for building. You can search for guides online about how to compile a cmake based program or:
51+
52+
```
53+
mkdir build && cd build
54+
cmake ..
55+
make
56+
```
57+
58+
Please make sure that you have libpci dependency before compiling. On Ubuntu, libpci can be simply be added by:
59+
60+
`sudo apt install libpci-dev
61+
62+
### Windows
63+
It can be built by Visual Studio automaticly. However, as for now, MingW can't be used to compile for some reason.
64+
65+
Required dll is included in ./prebuilt of source tree. Please put the dll library and sys driver in the same folder with ryzenadj.exe.
66+
67+
## TODO
68+
- Determine the unit of time
69+
- Add more options
70+
- Code cleanup (The original program was written in C but now it's C++ in order to call VC++ library)
71+

smu-tool/libpci.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ nb_t get_nb(pci_obj_t obj){
1515
nb_t nb;
1616
nb = pci_get_dev(obj, 0, 0, 0, 0);
1717
pci_fill_info(nb, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);
18-
if (nb->vendor_id != AMD_VENDOR_ID){
19-
printf("Not a Ryzen NB Device\n");
20-
return NULL;
21-
}
2218
return nb;
2319
}
2420

smu-tool/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, const char **argv)
3838

3939
struct argparse argparse;
4040
argparse_init(&argparse, options, usage, 0);
41-
argparse_describe(&argparse, "\n Ryzen NB SMU Service Request tool.", "\nWARNING: Use at your own risk!\nBy Jiaxun Yang <[email protected]>, Under GPL-2.0.");
41+
argparse_describe(&argparse, "\n Ryzen NB SMU Service Request tool.", "\nWARNING: Use at your own risk!\nBy Jiaxun Yang <[email protected]>, Under LGPL.");
4242
argc = argparse_parse(&argparse, argc, argv);
4343

4444
pci_obj = init_pci_obj();
@@ -98,4 +98,4 @@ int main(int argc, const char **argv)
9898
out_free_pci_obj:
9999
free_pci_obj(pci_obj);
100100
return err;
101-
}
101+
}

smu-tool/winring0.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ pci_obj_t init_pci_obj(){
2020
}
2121

2222
nb_t get_nb(pci_obj_t obj){
23-
if(ReadPciConfigDword(nb_pci_address, 0x2C) >> 16 != AMD_VENDOR_ID){
24-
printf("Not a Ryzen NB Device\n");
25-
return NULL;
26-
}
2723
return &nb_pci_address;
2824
}
2925

0 commit comments

Comments
 (0)