The Ondemand Governor.pdf

(169 KB) Pobierz
TheOndemandGovernor
Past,Present,andFuture
VenkateshPallipadi AlexeyStarikovskiy
IntelOpenSourceTechnologyCenter
venkatesh.pallipadi@intel.com
alexey.y.starikovskiy@intel.com
Abstract
ingotherprocessors.Italsodiscussesrelative
power/performancedatawiththe ondemand
governoranditsvariousoptimizations.
ondemand isadynamicin-kernel cpufreq
governorthatcanchangeCPUfrequencyde-
pendingonCPUutilization.Itwasfirstintro-
ducedinthelinux-2.6.9kernel.Itssimplistic
policyprovidedsignificantbenefitstolaptops,
desktops,andserversalikebymakinguseof
fastfrequency-switchingfeaturesoftheproces-
sorstoeffectivelypower-managethem.
Thispaperconcludeswithafewideasabout
wherethe ondemand governorisheadedin
thefuture,includingadditionalfeaturesthat
arenicetohaveandhowthe ondemand gov-
ernorcanbemademoreusefulinawide
rangeofsystems—fromhandheldstoservers.
Thisdiscussiontouchesuponchangesthatmay
berequiredinkernelsubsystemsotherthan
cpufreq ,inordertoimproveeffectivenessof
the ondemand governor.
Thispaperstartswithadescriptionofthe
ondemand governorpresentinthe2.6.9ker-
nel:thealgorithmandtuningparametersinthat
governor.Inparticular,ithighlightsthesignif-
icantdifferencebetweenthe ondemand gov-
ernorvs.theuser-level cpufreq governors.
Thissectionalsoincludesabriefoverviewof
howtoconfigureandrunthe ondemand gov-
ernor.
1Introduction
Mostofthelatestmicroprocessorshavemecha-
nismstosavepowerbychangingthecorevolt-
ageandfrequencyatruntime.Section2.1
givesadetailedviewonthis.
Nextisadiscussionofvariousoptimizations
totheoriginal ondemand algorithm.Some
ofthesechangesweredrivenbythenewpro-
cessorsupportofdynamicchangingoffre-
quencyinmulti-coreandmultiprocessorsys-
temenvironments.Thissectionhighlightsthe
challengesofchangingfrequencyinamulti-
processorsystemenvironmentsuchasprevent-
ingfrequencychangeinoneprocessoraffect-
Thistechniquewasfirstwidelydeployedon
mobilesystemsduetotheirbatteryliferequire-
ments,butisnowcommonondesktopsand
serversaswell.
Withthistechniquebeingwidelyusedindif-
ferentkindsofsystems,therehasbeena
658 TheOndemandGovernor
constantstreamofoptimizationshappening
inthe cpufreq infrastructureitself,inthe
ondemand governor,andalsoinlow-level
driversandACPI[4].Recentchangesin
cpufreq includetheabilitytohandleCPU
hot-plugcleanlyandalsotheabilitytodeal
withprocessorgroupssharingonefrequency.
Thislatterfeaturesupportisimportantinmulti-
coreandmulti-threadenvironments,where
platformsmayhaverestrictionsofrunningdif-
ferentlogicalprocessorsatsamefrequency.
Thispaperwilldealindetailwithchangesin
the ondemand governorandlow-levelgover-
norsthatuseACPItoidentifythatallCPUs
sharethesamefrequency.
P = P 1 + P 2 + P 3
leakage–currentgoingeitherthroughsub-
strate(underschematics)ornotfully
closedtransistors(throughschematics)
anddependsonvoltage,thusthispart
ofthepowerwillbeproportionaltothe
squareofthevoltage:
P 1 = I L U C = U 2 C / R L
rechargingparasiticcapacitanceofwiresand
inputs—dependsonbothfrequencyand
voltage,linearonfrequencyandsquareon
voltage.
P 2 = U 2 C / R P = U 2 C C P F
Section2ofthispaperincludesaprimeron
cpufreq .Section3coversthemotivation
forthe ondemand governorandtheoriginal
ondemand algorithm.InSection4,wedis-
cussvariousoptimizationstothe ondemand
governorsinceitsoriginalinceptionintothe
Linuxkernel,followedbysomeongoinginves-
tigations.InSection5wedealwithhowFre-
quencyVoltagechangeshappeninpresenceof
multiplelogicalprocessorsinapackage.This
issue,althoughorthogonaltothe ondemand
governorinitself,iscriticalforsavingpowerin
amulti-coreandmulti-threadCPUworld.Sec-
tion6includesmeasurementresultsfromour
lab,madewithvariousgovernorsandoptimiza-
tions.Weconcludethepaperwithaglimpseof
changesthatarelikelytocometo ondemand
inthefuture.Unlessotherwisementioned,all
thekernel-specificdetailsinthepaperwillbe
forthe2.6.16kernel.
shoot-throughcurrent–happensduringthe
switchoftheCMOScircuitthenonetran-
sistorisalreadyopenwhileoppositetoit
isjuststartedtoclose,andthus,islinear
proportionaltofrequencyandsquarepro-
portionaltovoltage.
P 3 = U 2 C F / R S
Summarizingtheabove,consumedpoweris
proportionaltosquareofcorevoltageandei-
therconstantorlineartofrequency,depend-
ingonwhichpowerconsumeronachipdom-
inates.MaximumfrequencyoftheCMOScir-
cuitdependsoncorevoltageaswell,andthus,
tosavepowerweneedtodecreasethecorevolt-
age,butbeforehandsetfrequencytovalue,al-
lowedatthisreducedvoltage.Changingthe
frequencyalonedoesnotbringanysignificant
benefits.Thisiswhydriversthatmodulatethe
clockwithoutchangingthevoltageareineffec-
tiveatsavingpower.
2Background
2.2 Cpufreq andgovernors
2.1Physics
CurrentCMOSelectronicsconsumespowerin
threebigareas:
cpufreq isthesubsystemoftheLinuxker-
nelthatallowsfrequencytobeexplicitlyseton
2006LinuxSymposium 659
processors[3]. cpufreq providesamodular-
izedsetofinterfacestomanagetheCPUfre-
quencychanges.Figure1depictsthehigh-level
cpufreq infrastructure.
governortomanagethefrequencyofeach
independentCPU.
Kernel2.6.16comesbundledwithfivedif-
ferentgovernors.Threeofthesegovernors
canberunonanykindofCPUthathasa
low-leveldrivertochangethefrequencyat
runtimeandcanbechosenasdefaultgov-
ernoratcompiletime:
Theprimarycomponentsofthisinfrastructure
areasfollows:
Cpufreq moduleprovidesacommoninter-
facetothevariouslow-level,CPU-specific
frequencycontroltechnologiesandhigh-
levelCPUfrequencycontrollingpolicies.
cpufreq decouplestheCPUfrequency
controllingmechanismsandpoliciesand
helpsinindependentdevelopmentofthe
two.Italsoprovidessomestandardinter-
facestotheuser,withwhichtheusercan
choosethepolicygovernorandsetparam-
etersforthatparticularpolicygovernor.
Performance governorkeeps the
CPUatthehighestpossiblefre-
quencywithinauser-specified
range.
Powersave governorkeepstheCPUat
thelowestpossiblefrequencywithin
auser-specifiedrange.
Userspace governorexportstheavail-
ablefrequencyinformationtothe
userlevel(throughthe sysfs )and
permitsuser-spacecontrolofthe
CPUfrequency.Alluser-spacedy-
namicCPUfrequencygovernorsuse
thisgovernorastheirproxy.
CPU-specificdriversimplement different
CPUfrequencychangingtechnologies,
suchasIntel R SpeedStep R Technology,
EnhancedIntel R SpeedStep R Tech-
nology[6],AMDPowerNow! TM ,and
IntelPentium R 4processorclockmod-
ulation.Onagivenplatform,oneor
morefrequencymodulationtechnologies
canbesupported,andaproperdriver
mustbeloadedfortheplatformtoper-
formefficientfrequencychanges.The
cpufreq infrastructureallowsuseofone
CPU-specificdriverperplatform.Some
oftheselow-leveldriversalsodependon
ACPImethodstogetinformationfrom
theBIOSabouttheCPUandfrequencies
itcansupport.
Therearetworelativelynewgovernors,
ondemand and conservative ,capa-
bleoffrequentloadmonitoringonCPUs
whichcandofastfrequencyswitching.
ondemand governorwas introduced
intoLinuxkernelin2.6.9andrest
ofthispapercoversindetailtheal-
gorithm,usage,andrecent,ongoing,
andfuturechangestothisgovernor.
conservative governorisaforkof
the ondemand governorwitha
slightlydifferentalgorithmtodecide
onthetargetfrequency.Mostofthe
configurationdetailsof ondemand
inthispaperalsoholdstrueforthe
conservative governor.
In-kernelgovernors.The cpufreq infras-
tructureallowsforfrequency-changing
policygovernors,whichcanchangethe
CPUfrequencybasedondifferentcriteria,
suchasCPUusage.The cpufreq infras-
tructurecanshowavailablegovernorson
thesystemandallowstheusertoselecta
660 TheOndemandGovernor
User-level
governors
powersaved
cpuspeed
In-kernel
governors
performance
powersave
userspace
ondemand
cpufreq module (with /proc and /sys interfaces)
CPU-specific
drivers
...
acpi-cpufreq
speedstep-centrino
powernow-k8
ACPI processor driver
Figure1: cpufreq infrastructure
2.3 cpufreq and sysfs interfaces
scaling_governor
scaling_max_freq
scaling_min_freq
stats/
Theuserinterfaceto cpufreq isthrough
sysfs . cpufreq providestheflexibil-
itytomanageCPUsataper-processor
level(aslongashardwareagreestoman-
ageCPUsat that level). Theinter-
faceforeachCPUwillbeunder sysfs ,
typicallyat /sys/devices/system/cpu/
cpuX/cpufreq ,where X rangesfrom 0
through N-1 ,with N beingtotalnumberoflog-
icalCPUsinthesystem.
Allthesefilescanbereadbydoinga cat and
allthewritablefilescanbewrittentousinga
echo andredirectionintothefile. stats/ is
adirectoryandwillbediscussedinSection2.4.
AllthefrequencyvaluesareinkHz.
Reading cpuinfo_max_freq and cpuinfo_
min_freq willgivethemaximumandmin-
imumfrequencysupportedbytheCPUand
cpuinfo_cur_freq willreadthecurrentfre-
quencyfromhardwareanddisplayit.
Thebasicinterfacesprovidedby cpufreq
are:
scaling_available_frequencies lists
outalltheavailablefrequenciesfortheCPU.
linux:>cd/sys/devices/system/cpu
linux:>cdcpu0/cpufreq
linux:>ls-1-F
affected_cpus
cpuinfo_cur_freq
cpuinfo_max_freq
cpuinfo_min_freq
scaling_available_frequencies
scaling_available_governors
scaling_cur_freq
scaling_driver
scaling_available_governors listsout
allthegovernorssupportedbythekernel.Note
thatthegovernormodulesmustbeloaded
throughmodprobeforittoappearhere.The
administratorcan echo aparticularavailable
governorinto scaling_governor inorder
tochangethegovernoronaparticularCPU.
scaling_cur_freq willreturnthecached
813356059.011.png 813356059.012.png 813356059.013.png 813356059.014.png 813356059.001.png 813356059.002.png 813356059.003.png 813356059.004.png 813356059.005.png 813356059.006.png 813356059.007.png 813356059.008.png 813356059.009.png 813356059.010.png
 
2006LinuxSymposium 661
valueofthecurrentfrequencyfromthe
cpufreq subsystem. scaling_max_freq
and scaling_min_freq areusercontrolled
upperandlowerlimits,withinwhichthegov-
ernorwilloperateatanytime.
(superuserorroot)thecontroltosetthefre-
quencyonaparticularplatform.Thisuserspace
interfacecouldthenbeusedbythedaemons
runninginuserlandtomanagetheCPUfre-
quencyovertime,dependingontheload.
Therearemultipleuserspaceprograms,like
cpuspeed and powersaved thatcanuse
userspace governorinterfaceandchange
thefrequencybasedonload.Theuserspace
governorswouldtypicallysampletheutiliza-
tioneveryfewseconds,andthentakeadecision
onwhatfrequencytogotoforthenextsam-
pleinterval.Thismethodofchangingthefre-
quencyoperatesproperlywithalmostanyfre-
quency/voltage-changinghardware.
scaling_driver namesthelow-level
CPU-specificdriverthatisusedtochangethe
CPUfrequency.
Inadditiontoaboveinterfaces,therunning
governormayaddsomemoreinterfacesofits
own,whichcanbeusedtomanagethefre-
quencyorfine-tunethegovernor.
2.4 cpufreq-stats
However,hardwarecapableoflow-latencyfre-
quencyswitchingcantakeadvantageofsoft-
warethatdoesmoreaggressivesamplingofuti-
lizationandchangethefrequencymoreoften
tosuittheworkload.Forexample,Enhanced
IntelSpeedstepTechnologycanswitchthefre-
quencywithlatencyaslowas10 µ S.Thisfaster
samplingwillalsohelpinquickresponsetime
forchangingworkloads,whichiscriticalin
serversandwillalsobringvisiblebenefitfor
laptopusers.ThinkofCPUfrequencygoingto
themaxwithinafewmillisecondsafterclick-
ingonOpenOfficeandcompareagainstclick-
ingonOpenOffice,withtheCPUrunningat
lowfrequencyforseveralseconds,andthenin-
creasingthefrequencytothemaximum.
Theinterfacesunderthe stats/ directory
providethestatisticsabouttheusageoffre-
quencychangesonanyparticularCPU.Theex-
actdetailsoftheinterfacesandtheirmeaning
canbefoundin[1].
2.5 cpufreq -basedtools
Readingandchangingdifferentfieldsinthe
specific sysfs directorybyhandonasystem
withalotofCPUscanbepainfulandtimecon-
suming.DominikBrodowskihasledthedevel-
opmentof cpufrequtils containingasetof
toolstomakeuseof cpufreq easier[2].
Butdoingthisfrequentpollingfromuserspace
mayaddmoreoverheadduetokerneltouser
transitionandreading/writing /proc/ and
/sys files,etc.Thiswastheoriginalmotiva-
tionbehindthe ondemand governor.Doing
thedynamicfrequencychangeinsidetheker-
nel,moreoften,withlessoverhead.Also,the
kernelistherightplacetotakethefrequency
decisionasithaslotofotherinformationabout
thesystemoverallandtheparticularCPU[7].
3Originalon-demandgovernor
3.1Motivation
Ofthethreegovernorsthatwerethereinthe
kernelbefore ondemand ,the performance
and powersave governorswerestaticgover-
nors.The userspace governorgavetheuser
Zgłoś jeśli naruszono regulamin