Skip to content

Commit ecaa52f

Browse files
committed
add scripts/bhs-power-mode.ps1
Change-Id: Ica482610f7107aad538224e3f12f0c830e1d1af8
1 parent 9e5af12 commit ecaa52f

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

scripts/bhs-power-mode.ps1

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
Write-Output "Intel(r) Performance Counter Monitor"
2+
Write-Output "Birch Stream Power Mode Utility"
3+
Write-Output ""
4+
5+
Write-Output " Options:"
6+
Write-Output " --default : set default power mode"
7+
Write-Output " --latency-optimized-mode : set latency optimized mode"
8+
Write-Output ""
9+
10+
# Run the pcm-tpmi command to determine I/O and compute dies
11+
$output = pcm-tpmi 2 0x10 -d -b 26:26
12+
13+
# Parse the output to build lists of I/O and compute dies
14+
$io_dies = @()
15+
$compute_dies = @()
16+
$die_types = @{}
17+
18+
$output -split "`n" | ForEach-Object {
19+
$line = $_
20+
if ($line -match "instance 0") {
21+
$die = $line -match 'entry (\d+)' | Out-Null; $matches[1]
22+
if ($line -match "value 1") {
23+
$die_types[$die] = "IO"
24+
$io_dies += $die
25+
} elseif ($line -match "value 0") {
26+
$die_types[$die] = "Compute"
27+
$compute_dies += $die
28+
}
29+
}
30+
}
31+
32+
if ($args[0] -eq "--default") {
33+
Write-Output "Setting default mode..."
34+
35+
foreach ($die in $io_dies) {
36+
# EFFICIENCY_LATENCY_CTRL_RATIO (Uncore IO)
37+
pcm-tpmi 2 0x18 -d -e $die -b 28:22 -w 8
38+
39+
# EFFICIENCY_LATENCY_CTRL_LOW_THRESHOLD (Uncore IO)
40+
pcm-tpmi 2 0x18 -d -e $die -b 38:32 -w 13
41+
42+
# EFFICIENCY_LATENCY_CTRL_HIGH_THRESHOLD (Uncore IO)
43+
pcm-tpmi 2 0x18 -d -e $die -b 46:40 -w 120
44+
45+
# EFFICIENCY_LATENCY_CTRL_HIGH_THRESHOLD_ENABLE (Uncore IO)
46+
pcm-tpmi 2 0x18 -d -e $die -b 39:39 -w 1
47+
}
48+
49+
foreach ($die in $compute_dies) {
50+
# EFFICIENCY_LATENCY_CTRL_RATIO (Uncore Compute)
51+
pcm-tpmi 2 0x18 -d -e $die -b 28:22 -w 12
52+
}
53+
}
54+
55+
if ($args[0] -eq "--latency-optimized-mode") {
56+
Write-Output "Setting latency optimized mode..."
57+
58+
foreach ($die in $io_dies) {
59+
# EFFICIENCY_LATENCY_CTRL_RATIO (Uncore IO)
60+
pcm-tpmi 2 0x18 -d -e $die -b 28:22 -w 0
61+
62+
# EFFICIENCY_LATENCY_CTRL_LOW_THRESHOLD (Uncore IO)
63+
pcm-tpmi 2 0x18 -d -e $die -b 38:32 -w 0
64+
65+
# EFFICIENCY_LATENCY_CTRL_HIGH_THRESHOLD (Uncore IO)
66+
pcm-tpmi 2 0x18 -d -e $die -b 46:40 -w 0
67+
68+
# EFFICIENCY_LATENCY_CTRL_HIGH_THRESHOLD_ENABLE (Uncore IO)
69+
pcm-tpmi 2 0x18 -d -e $die -b 39:39 -w 1
70+
}
71+
72+
foreach ($die in $compute_dies) {
73+
# EFFICIENCY_LATENCY_CTRL_RATIO (Uncore Compute)
74+
pcm-tpmi 2 0x18 -d -e $die -b 28:22 -w 0
75+
}
76+
}
77+
78+
Write-Output "Dumping TPMI Power control register states..."
79+
Write-Output ""
80+
81+
# Function to extract and calculate metrics from the value
82+
function ExtractAndPrintMetrics {
83+
param (
84+
[int]$value,
85+
[int]$socket_id,
86+
[int]$die
87+
)
88+
89+
$die_type = $die_types[$die]
90+
91+
# Extract bits and calculate metrics
92+
$min_ratio = ($value -shr 15) -band 0x7F
93+
$max_ratio = ($value -shr 8) -band 0x7F
94+
$eff_latency_ctrl_ratio = ($value -shr 22) -band 0x7F
95+
$eff_latency_ctrl_low_threshold = ($value -shr 32) -band 0x7F
96+
$eff_latency_ctrl_high_threshold = ($value -shr 40) -band 0x7F
97+
$eff_latency_ctrl_high_threshold_enable = ($value -shr 39) -band 0x1
98+
99+
# Convert to MHz or percentage
100+
$min_ratio = $min_ratio * 100
101+
$max_ratio = $max_ratio * 100
102+
$eff_latency_ctrl_ratio = $eff_latency_ctrl_ratio * 100
103+
$eff_latency_ctrl_low_threshold = ($eff_latency_ctrl_low_threshold * 100) / 127
104+
$eff_latency_ctrl_high_threshold = ($eff_latency_ctrl_high_threshold * 100) / 127
105+
106+
# Print metrics
107+
Write-Output "Socket ID: $socket_id, Die: $die, Type: $die_type"
108+
Write-Output "MIN_RATIO: $min_ratio MHz"
109+
Write-Output "MAX_RATIO: $max_ratio MHz"
110+
Write-Output "EFFICIENCY_LATENCY_CTRL_RATIO: $eff_latency_ctrl_ratio MHz"
111+
if ($die_type -eq "IO") {
112+
Write-Output "EFFICIENCY_LATENCY_CTRL_LOW_THRESHOLD: $eff_latency_ctrl_low_threshold%"
113+
Write-Output "EFFICIENCY_LATENCY_CTRL_HIGH_THRESHOLD: $eff_latency_ctrl_high_threshold%"
114+
Write-Output "EFFICIENCY_LATENCY_CTRL_HIGH_THRESHOLD_ENABLE: $eff_latency_ctrl_high_threshold_enable"
115+
}
116+
Write-Output ""
117+
}
118+
119+
# Iterate over all dies and run pcm-tpmi for each to get the metrics
120+
foreach ($die in $die_types.Keys) {
121+
$output = pcm-tpmi 2 0x18 -d -e $die
122+
123+
# Parse the output and extract metrics for each socket
124+
$output -split "`n" | ForEach-Object {
125+
$line = $_
126+
if ($line -match "Read value") {
127+
$value = $line -match 'value (\d+)' | Out-Null; $matches[1]
128+
$socket_id = $line -match 'instance (\d+)' | Out-Null; $matches[1]
129+
ExtractAndPrintMetrics -value $value -socket_id $socket_id -die $die
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)