Created
November 11, 2024 00:17
-
-
Save lelegard/b183e761c081335db3812ab0a04d1534 to your computer and use it in GitHub Desktop.
Disable Windows power throttling on VirtualBox executables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Disable Windows power throttling on VirtualBox executables. | |
Copyright (c) 2024, Thierry Lelegard | |
BSD-2-Clause license, see https://opensource.org/license/BSD-2-Clause | |
The problem: On some recent Intel chips such as the Alder Lake family, | |
there are two types of cores: P-cores and E-cores. P-cores are designed | |
for performance and E-cores for power efficiency. As a rule of thumb, | |
"foreground" processes, typically manually run with a window on screen, | |
run on P-core while "background" processes run on E-cores. Using VirtualBox, | |
when a virtual machine is started from the command line, headless, it is | |
considered by Windows as a background process and ends on E-cores. Not only | |
the VM has lower performances, but some VM don't even boot for some unknown | |
reasons (Fedora sometimes hangs during boot) | |
The solution: Disable "power throttling" on all VirtualBox executables. | |
Thus, all these executables won't be candidate for E-cores and will run | |
on P-cores. | |
.PARAMETER NoPause | |
Do not wait for the user to press <enter> at end of execution. By default, | |
execute a "pause" instruction at the end of execution, which is useful | |
when the script was run from Windows Explorer. | |
#> | |
param([switch]$NoPause = $false) | |
# VirtualBow installation: | |
$VBoxRoot = "C:\Program Files\Oracle\VirtualBox" | |
# Do we run as administrator? | |
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) | |
# All VirtualBox executables. | |
$Execs = Get-ChildItem "$VBoxRoot\*.exe" | |
if ($Execs -eq $null) { | |
Write-Output "Error: no .exe found in $VBoxRoot" | |
} | |
elseif (-not $IsAdmin) { | |
Write-Output "Must be administrator to continue, trying to restart as administrator ..." | |
$cmd = "& '" + $PSCommandPath + "'" + $(if ($NoPause) {" -NoPause"} else {""}) | |
Start-Process -Verb runas -FilePath PowerShell.exe -ArgumentList @("-ExecutionPolicy", "RemoteSigned", "-Command", $cmd) | |
} | |
else { | |
# Execution as administrator, we can proceed. | |
$Execs | ForEach-Object { powercfg /powerthrottling disable /path $_.fullname } | |
powercfg /powerthrottling list | |
} | |
if (-not $NoPause) { | |
pause | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment