Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions doc/LATENCY-OPTIMIZED-MODE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Should this BIOS option be unavailable or if there is a preference to change the

|Platform |Script Type| URL |
|------------------|-----------|---------------------------------------------------------------------|
|Linux/FreeBSD/UNIX|bash | https://github.com/intel/pcm/blob/master/scripts/bhs-power-mode.sh |
|Windows |powershell | https://github.com/intel/pcm/blob/master/scripts/bhs-power-mode.ps1 |
|Linux/FreeBSD/UNIX|bash | https://github.com/intel/pcm/blob/master/scripts/ufs-power-mode.sh |
|Windows |powershell | https://github.com/intel/pcm/blob/master/scripts/ufs-power-mode.ps1 |

The scripts require the pcm-tpmi utility. There are several methods to obtain this utility:
- **Download or install precompiled PCM binaries:** Please refer to the following link: [Downloading Pre-Compiled PCM Tools](https://github.com/intel/pcm?tab=readme-ov-file#downloading-pre-compiled-pcm-tools)
Expand All @@ -39,23 +39,37 @@ Once the pcm-tpmi binary is correctly placed, you can set the Latency Optimized

Linux/FreeBSD/UNIX:
```
bash bhs-power-mode.sh --latency-optimized-mode
bash ufs-power-mode.sh --latency-optimized-mode
```
Windows:
```
.\bhs-power-mode.ps1 --latency-optimized-mode
.\ufs-power-mode.ps1 --latency-optimized-mode
```

### Setting Optimized Power Mode

Linux/FreeBSD/UNIX:
```
bash bhs-power-mode.sh --optimized-power-mode
bash ufs-power-mode.sh --optimized-power-mode
```

Windows:
```
.\bhs-power-mode.ps1 --optimized-power-mode
.\ufs-power-mode.ps1 --optimized-power-mode
```



### Showing the Current Mode

When run without options, the scripts read the TPMI registers and report the current mode (Optimized Power Mode, Latency Optimized Mode or Unknown if the register values on the dies do not match either mode):

Linux/FreeBSD/UNIX:
```
bash ufs-power-mode.sh
```

Windows:
```
.\ufs-power-mode.ps1
```
46 changes: 38 additions & 8 deletions scripts/bhs-power-mode.ps1 → scripts/ufs-power-mode.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Write-Output "Intel(r) Performance Counter Monitor"
Write-Output "Birch Stream Power Mode Utility"
Write-Output "UFS (Uncore Frequency Scaling) Power Mode Utility"
Write-Output ""

Write-Output " Options:"
Write-Output " --optimized-power-mode : set optimized power mode"
Write-Output " --latency-optimized-mode : set latency optimized mode"
Write-Output " (no option) : show the current mode"
Write-Output ""

# Run the pcm-tpmi command to determine I/O and compute dies
Expand All @@ -19,8 +20,8 @@ $die_types = @{}
$output -split "`n" | ForEach-Object {
$line = $_
if ($line -match "entry" -and $line -match "instance") {
$entry = $line -match 'entry (\d+)' | Out-Null; $matches[1]
$instance = $line -match 'instance (\d+)' | Out-Null; $matches[1]
$entry = if ($line -match 'entry (\d+)') { $matches[1] }
$instance = if ($line -match 'instance (\d+)') { $matches[1] }
$die_key = "${instance}:${entry}"
if ($line -match "value 1") {
$die_types[$die_key] = "IO"
Expand Down Expand Up @@ -89,10 +90,14 @@ if ($args[0] -eq "--latency-optimized-mode") {
Write-Output "Dumping TPMI Power control register states..."
Write-Output ""

# Cleared when any die does not match the respective mode settings
$script:all_dies_optimized_power = $true
$script:all_dies_latency_optimized = $true

# Function to extract and calculate metrics from the value
function ExtractAndPrintMetrics {
param (
[int]$value,
[uint64]$value,
[int]$socket_id,
[string]$die_key,
[string]$numa_node,
Expand All @@ -113,6 +118,18 @@ function ExtractAndPrintMetrics {
$eff_latency_ctrl_high_threshold = ($value -shr 40) -band 0x7F
$eff_latency_ctrl_high_threshold_enable = ($value -shr 39) -band 0x1

# Compare raw register fields with the values written by the mode options above
$regs = "$eff_latency_ctrl_ratio"
$optimized_power_regs = "12"
$latency_optimized_regs = "0"
if ($die_type -eq "IO") {
$regs = "${eff_latency_ctrl_ratio}:${eff_latency_ctrl_low_threshold}:${eff_latency_ctrl_high_threshold}:${eff_latency_ctrl_high_threshold_enable}"
$optimized_power_regs = "8:13:120:1"
$latency_optimized_regs = "0:0:0:1"
}
if ($regs -ne $optimized_power_regs) { $script:all_dies_optimized_power = $false }
if ($regs -ne $latency_optimized_regs) { $script:all_dies_latency_optimized = $false }

# Convert to MHz or percentage
$min_ratio = $min_ratio * 100
$max_ratio = $max_ratio * 100
Expand Down Expand Up @@ -148,9 +165,9 @@ foreach ($die_key in $die_types.Keys) {
$output -split "`n" | ForEach-Object {
$line = $_
if ($line -match "Read value") {
$value = $line -match 'value (\d+)' | Out-Null; $matches[1]
$inst = $line -match 'instance (\d+)' | Out-Null; $matches[1]
$ent = $line -match 'entry (\d+)' | Out-Null; $matches[1]
$value = if ($line -match 'value (\d+)') { $matches[1] }
$inst = if ($line -match 'instance (\d+)') { $matches[1] }
$ent = if ($line -match 'entry (\d+)') { $matches[1] }
$parsed_die_key = "${inst}:${ent}"
# Extract socket ID if present, otherwise fallback to instance ID
if ($line -match '\(socket (\d+)\)') {
Expand All @@ -166,4 +183,17 @@ foreach ($die_key in $die_types.Keys) {
ExtractAndPrintMetrics -value $value -socket_id $socket_id -die_key $parsed_die_key -numa_node $numa_node -instance $inst
}
}
}
}

if ($args.Count -eq 0) {
if ($die_types.Count -eq 0) {
$current_mode = "Unknown"
} elseif ($script:all_dies_optimized_power) {
$current_mode = "Optimized Power Mode"
} elseif ($script:all_dies_latency_optimized) {
$current_mode = "Latency Optimized Mode"
} else {
$current_mode = "Unknown"
}
Write-Output "Current mode: $current_mode"
}
31 changes: 30 additions & 1 deletion scripts/bhs-power-mode.sh → scripts/ufs-power-mode.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

echo "Intel(r) Performance Counter Monitor"
echo "Birch Stream Power Mode Utility"
echo "UFS (Uncore Frequency Scaling) Power Mode Utility"
echo ""

echo " Options:"
echo " --optimized-power-mode : set optimized power mode"
echo " --latency-optimized-mode : set latency optimized mode"
echo " (no option) : show the current mode"
echo

# Run the pcm-tpmi command to determine I/O and compute dies
Expand Down Expand Up @@ -92,6 +93,10 @@ fi
echo "Dumping TPMI Power control register states..."
echo ""

# Cleared when any die does not match the respective mode settings
all_dies_optimized_power=1
all_dies_latency_optimized=1

# Function to extract and calculate metrics from the value
extract_and_print_metrics() {
local value=$1
Expand All @@ -113,6 +118,18 @@ extract_and_print_metrics() {
local eff_latency_ctrl_high_threshold=$(( (value >> 40) & 0x7F ))
local eff_latency_ctrl_high_threshold_enable=$(( (value >> 39) & 0x1 ))

# Compare raw register fields with the values written by the mode options above
local regs="$eff_latency_ctrl_ratio"
local optimized_power_regs="12"
local latency_optimized_regs="0"
if [ "$die_type" == "IO" ] ; then
regs="$eff_latency_ctrl_ratio:$eff_latency_ctrl_low_threshold:$eff_latency_ctrl_high_threshold:$eff_latency_ctrl_high_threshold_enable"
optimized_power_regs="8:13:120:1"
latency_optimized_regs="0:0:0:1"
fi
[ "$regs" != "$optimized_power_regs" ] && all_dies_optimized_power=0
[ "$regs" != "$latency_optimized_regs" ] && all_dies_latency_optimized=0

# Convert to MHz or percentage
min_ratio=$(( min_ratio * 100 ))
max_ratio=$(( max_ratio * 100 ))
Expand Down Expand Up @@ -169,3 +186,15 @@ for die_key in "${!die_types[@]}"; do
done <<< "$output"
done

if [ -z "$1" ]; then
if [ ${#die_types[@]} -eq 0 ]; then
current_mode="Unknown"
elif [ $all_dies_optimized_power -eq 1 ]; then
current_mode="Optimized Power Mode"
elif [ $all_dies_latency_optimized -eq 1 ]; then
current_mode="Latency Optimized Mode"
else
current_mode="Unknown"
fi
echo "Current mode: $current_mode"
fi
Loading