[ntp:questions] Enabling WinNT Port NTPD_CPU
Brian Inglis
Brian.Inglis at SystematicSw.ab.ca
Thu Nov 7 21:40:13 UTC 2013
Hi folks,
Wiring the ntpd process/threads to NTPD_CPU seems to be disabled except if using interpolation - is this correct?
I would suggest pinning the ntpd process/threads should be supported, regardless of interpolation, to stabilize time on all multiprocessors.
The highest CPU appears to be scheduled less frequently and have a lower load than the others. So I suggest the default CPU be changed to the value in the NUMBER_OF_PROCESSORS environment variable if available, or the highest processor available in the affinity mask.
This is pretty easy to do as shown in the attached PowerShell script I am using with the attached Cmd script to start and pin the service from a privileged system startup scheduled task (scripts renamed to txt to avoid exec filter issues).
I came up with this approach only because NTPD_CPU did not seem to be working, and no log messages were issued to say it was or was not being used. Why became apparent only when I downloaded, searched, and read the stable and dev sources. The considerations behind the current restrictions are not apparent from code or comments and ML discussions.
--
Take care. Thanks, Brian Inglis
-------------- next part --------------
#!powershell -File
# ntpd.pri.aff.ps1 - show ntpd priority and affinity, and set affinity
$nproc = Get-ChildItem Env:NUMBER_OF_PROCESSORS
[int]$cpus = $nproc.Value
[int]$mask = [Math]::Pow( 2, $cpus) - 1
[int]$des = $mask/2 + 1
$p = Get-Process -ProcessName "wininit"
[int]$aff = $p.ProcessorAffinity
$aff = if ($aff -gt 0) { $aff } else { $mask }
$ntpd = Get-Process -ProcessName "ntpd"
$name = $ntpd.Name
$class = $ntpd.PriorityClass
[int]$cur = $ntpd.ProcessorAffinity
$cur = if ($cur -gt 0) { $cur } else { $mask }
$mcpu = @()
$dcpu = @()
$acpu = @()
$ccpu = @()
$m = $mask
$d = $des
$a = $aff
$c = $cur
for ($n = 0; $n -lt $cpus; ++$n)
{
if ($m % 2) { $mcpu += ,$n }
if ($d % 2) { $dcpu += ,$n }
if ($a % 2) { $acpu += ,$n }
if ($c % 2) { $ccpu += ,$n }
$m /= 2
$d /= 2
$a /= 2
$c /= 2
}
"Number of CPUs : $cpus cpus $mcpu"
"Affinity Mask : $mask cpus $mcpu"
"System Affinity : $aff cpus $acpu"
"Process : $name"
"Priority Class : $class"
"Current Affinity : $cur cpus $ccpu"
"Desired Affinity : $des cpus $dcpu"
if ($cur -ne $des)
{
"Set Affinity : $des cpus $dcpu"
$ntpd.ProcessorAffinity = $des
$ntpd = Get-Process -ProcessName "ntpd"
$cur = $ntpd.ProcessorAffinity
$cur = if ($cur -gt 0) { $cur } else { $mask }
$ccpu = @()
$c = $cur
for ($n = 0; $n -lt $cpus; ++$n)
{
if ($c % 2) { $ccpu += ,$n }
$c /= 2
}
"Actual Affinity : $cur cpus $ccpu"
}
Start-Sleep 30
-------------- next part --------------
@echo off
:!cmd /c
:: ntp.start.cmd - start ntpd service the set affinity
:: set service, log, old log, all logs, affinity script
set S=ntp
set BASE=%~n0
set LOG=%BASE%.log
set NTPLOG=%S%.log
set NTPOLD=%S%.1.log
set NTPWILD=%S%*.log
set AFF=%~dp0ntpd.pri.aff.ps1
:: stop service in case started
sc query %S% > %LOG%
sc stop %S% >> %LOG%
sleep 5
sc query %S% >> %LOG%
:: list all NTP logs, save current, list all
dir %NTPWILD% >> %LOG%
move %NTPLOG% %NTPOLD% >> %LOG%
dir %NTPWILD% >> %LOG%
:: start service
sleep 5
sc query %S% >> %LOG%
sc start %S% >> %LOG%
sc query %S% >> %LOG%
:: query priority and affinity, and set affinity
powershell -File %AFF% >> %LOG%
More information about the questions
mailing list