diff --git a/doc/LATENCY-OPTIMIZED-MODE.md b/doc/LATENCY-OPTIMIZED-MODE.md index e7c629a2..cbb0b262 100644 --- a/doc/LATENCY-OPTIMIZED-MODE.md +++ b/doc/LATENCY-OPTIMIZED-MODE.md @@ -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) @@ -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 +``` diff --git a/scripts/bhs-power-mode.ps1 b/scripts/ufs-power-mode.ps1 similarity index 78% rename from scripts/bhs-power-mode.ps1 rename to scripts/ufs-power-mode.ps1 index 488eb3dc..21c0354f 100644 --- a/scripts/bhs-power-mode.ps1 +++ b/scripts/ufs-power-mode.ps1 @@ -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 @@ -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" @@ -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, @@ -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 @@ -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+)\)') { @@ -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 } } -} \ No newline at end of file +} + +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" +} diff --git a/scripts/bhs-power-mode.sh b/scripts/ufs-power-mode.sh similarity index 83% rename from scripts/bhs-power-mode.sh rename to scripts/ufs-power-mode.sh index 988c6c40..13cd1fbe 100644 --- a/scripts/bhs-power-mode.sh +++ b/scripts/ufs-power-mode.sh @@ -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 @@ -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 @@ -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 )) @@ -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