Saltar para conteúdo


Foto
- - - - -

I/O Schedulers e CPU Governors


  • Por favor inicie sessão para responder
Não há respostas a este tópico.

#1 PGrave

PGrave

    Membro

  • Membros
  • PipPip
  • 70 mensagens

Mensagem publicada 10 March 2012 - 16:26

Resolvi colocar aqui esta informação pois já tive bastantes duvidas sobre este assunto, e como alguns de vós também devem ter, pode ser que ajude a esclarecer.Estas alterações só podem ser feitas por kernels que as suportem, e em sistemas com root' class='bbc_url' title='Link Externo' rel='nofollow external'>http://www.androidpt.info/index.php?title=Root']root. Podem usar o No Frills, ou Antutu CPUMaster para gerenciar isto. I/O SCHEDULERSQ. "What purposes does an i/o scheduler serve?"A.Minimize hard disk seek latency.Prioritize I/O requests from processes.Allocate disk bandwidth for running processes.Guarantee that certain requests will be served before a deadline.So in the simplest of simplest form: Kernel controls the disk access using I/O Scheduler.Q. "What goals every I/O scheduler tries to balance?"A.Fairness (let every process have its share of the access to disk)Performance (try to serve requests close to current disk head position first, because seeking there is fastest)Real-time (guarantee that a request is serviced in a given time)Q. "Description, advantages, disadvantages of each I/O Scheduler?"A.1) NoopInserts all the incoming I/O requests to a First In First Out queue and implements request merging. Best used with storage devices that does not depend on mechanical movement to access data (yes, like our flash drives). Advantage here is that flash drives does not require reordering of multiple I/O requests unlike in normal hard drives.Advantages:Serves I/O requests with least number of cpu cycles. (Battery friendly?)Best for flash drives since there is no seeking penalty.Good throughput on db systems.Disadvantages:Reduction in number of cpu cycles used is proportional to drop in performance.2) DeadlineGoal is to minimize I/O latency or starvation of a request. The same is achieved by round robin policy to be fair among multiple I/O requests. Five queues are aggressively used to reorder incoming requests.Advantages:Nearly a real time scheduler.Excels in reducing latency of any given single I/O.Best scheduler for database access and queries.Bandwidth requirement of a process - what percentage of CPU it needs, is easily calculated.Like noop, a good scheduler for solid state/flash drives.Disadvantages:When system is overloaded, set of processes that may miss deadline is largely unpredictable.3) CFQCompletely Fair Queuing scheduler maintains a scalable per-process I/O queue and attempts to distribute the available I/O bandwidth equally among all I/O requests. Each per-process queue contains synchronous requests from processes. Time slice allocated for each queue depends on the priority of the 'parent' process. V2 of CFQ has some fixes which solves process' i/o starvation and some small backward seeks in the hope of improving responsiveness.Advantages:Considered to deliver a balanced i/o performance.Easiest to tune.Excels on multiprocessor systems.Best database system performance after deadline.Disadvantages:Some users report media scanning takes longest to complete using CFQ. This could be because of the property that since the bandwidth is equally distributed to all i/o operations during boot-up, media scanning is not given any special priority.Jitter (worst-case-delay) exhibited can sometimes be high, because of the number of tasks competing for the disk.4) BFQInstead of time slices allocation by CFQ, BFQ assigns budgets. Disk is granted to an active process until it's budget (number of sectors) expires. BFQ assigns high budgets to non-read tasks. Budget assigned to a process varies over time as a function of it's behavior.Advantages:Believed to be very good for usb data transfer rate.Believed to be the best scheduler for HD video recording and video streaming. (because of less jitter as compared to CFQ and others)Considered an accurate i/o scheduler.Achieves about 30% more throughput than CFQ on most workloads.Disadvantages:Not the best scheduler for benchmarking.Higher budget assigned to a process can affect interactivity and increased latency.5) SIOSimple I/O scheduler aims to keep minimum overhead to achieve low latency to serve I/O requests. No priority quesues concepts, but only basic merging. Sio is a mix between noop & deadline. No reordering or sorting of requests.Advantages:Simple, so reliable.Minimized starvation of requests.Disadvantages:Slow random-read speeds on flash drives, compared to other schedulers.Sequential-read speeds on flash drives also not so good.6) V®Unlike other schedulers, synchronous and asynchronous requests are not treated separately, instead a deadline is imposed for fairness. The next request to be served is based on it's distance from last request.Advantages:May be best for benchmarking because at the peak of it's 'form' VR performs best.Disadvantages:Performance fluctuation results in below-average performance at times.Least reliable/most unstable.7) AnticipatoryBased on two factsi) Disk seeks are really slow.ii) Write operations can happen whenever, but there is always some process waiting for read operation.So anticipatory prioritize read operations over write. It anticipates synchronous read operations.Advantages:Read requests from processes are never starved.As good as noop for read-performance on flash drives.Disadvantages:'Guess works' might not be always reliable.Reduced write-performance on high performance disks.Q. "Best I/O Scheduler?"A.There is nothing called "best" i/o scheduler. Depending on your usage environment and tasks/apps been run, use different schedulers. That's the best i can suggest.However, considering the overall performance, battery, reliability and low latency, it is believed thatSIO > Noop > Deadline > VR > BFQ > CFQ, given all schedulers are tweaked and the storage used is a flash device.Q. "How do i change I/O schedulers?"Voltage Control or No Frills from market.Or init.d script: echo "scheduler-name" > /sys/block/mmcblk0/queue/schedulerGOVERNORSI) MANUAL: These are the 18 governors we're talking about.1) Ondemand2) Ondemandx3) Conservative4) Interactive5) Interactivex6) Lulzactive7) Smartass 8) SmartassV2 9) Intellidemand10) Lazy 11) Lagfree 12) Lionheart13) LionheartX14) Brazilianwax 15) SavagedZen16) Userspacce 17) Powersave18) Performance1) Ondemand:Default governor in almost all stock kernels. One main goal of the ondemand governor is to switch to max frequency as soon as there is a CPU activity detected to ensure the responsiveness of the system. (You can change this behavior using smooth scaling parameters, refer Siyah tweaks at the end of 3rd post.) Effectively, it uses the CPU busy time as the answer to "how critical is performance right now" question. So Ondemand jumps to maximum frequency when CPU is busy and decreases the frequency gradually when CPU is less loaded/apporaching idle. Even though many of us consider this a reliable governor, it falls short on battery saving and performance on default settings. One potential reason for ondemand governor being not very power efficient is that the governor decide the next target frequency by instant requirement during sampling interval. The instant requirement can response quickly to workload change, but it does not usually reflect workload real CPU usage requirement in a small longer time and it possibly causes frequently change between highest and lowest frequency.2) Ondemandx:Basically an ondemand with suspend/wake profiles. This governor is supposed to be a battery friendly ondemand. When screen is off, max frequency is capped at 500 mhz. Even though ondemand is the default governor in many kernel and is considered safe/stable, the support for ondemand/ondemandX depends on CPU capability to do fast frequency switching which are very low latency frequency transitions. I have read somewhere that the performance of ondemand/ondemandx were significantly varying for different i/o schedulers. This is not true for most of the other governors. I personally feel ondemand/ondemandx goes best with SIO I/O scheduler.3) Conservative:A slower Ondemand which scales up slowly to save battery. The conservative governor is based on the ondemand governor. It functions like the Ondemand governor by dynamically adjusting frequencies based on processor utilization. However, the conservative governor increases and decreases CPU speed more gradually. Simply put, this governor increases the frequency step by step on CPU load and jumps to lowest frequency on CPU idle. Conservative governor aims to dynamically adjust the CPU frequency to current utilization, without jumping to max frequency. The sampling_down_factor value acts as a negative multiplier of sampling_rate to reduce the frequency that the scheduler samples the CPU utilization. For example, if sampling_rate equal to 20,000 and sampling_down_factor is 2, the governor samples the CPU utilization every 40,000 microseconds.4) Interactive:Can be considered a faster ondemand. So more snappier, less battery. Interactive is designed for latency-sensitive, interactive workloads. Instead of sampling at every interval like ondemand, it determines how to scale up when CPU comes out of idle. The governor has the following advantages: 1) More consistent ramping, because existing governors do their CPU load sampling in a workqueue context, but interactive governor does this in a timer context, which gives more consistent CPU load sampling. 2) Higher priority for CPU frequency increase, thus giving the remaining tasks the CPU performance benefit, unlike existing governors which schedule ramp-up work to occur after your performance starved tasks have completed. Interactive It's an intelligent Ondemand because of stability optimizations. Why??Sampling the CPU load every X ms (like Ondemand) can lead to under-powering the CPU for X ms, leading to dropped frames, stuttering UI, etc. Instead of sampling the CPU at a specified rate, the interactive governor will check whether to scale the CPU frequency up soon after coming out of idle. When the CPU comes out of idle, a timer is configured to fire within 1-2 ticks. If the CPU is very busy between exiting idle and when the timer fires, then we assume the CPU is underpowered and ramp to max frequency.5) Interactivex:This is an Interactive governor with a wake profile. More battery friendly than interactive.6) Lulzactive:This new find from Tegrak is based on Interactive & Smartass governors and is one of the favorites. Old Version: When workload is greater than or equal to 60%, the governor scales up CPU to next higher step. When workload is less than 60%, governor scales down CPU to next lower step. When screen is off, frequency is locked to global scaling minimum frequency.New Version: Three more user configurable parameters: inc_cpu_load, pump_up_step, pump_down_step. Unlike older version, this one gives more control for the user. We can set the threshold at which governor decides to scale up/down. We can also set number of frequency steps to be skipped while polling up and down.When workload greater than or equal to inc_cpu_load, governor scales CPU pump_up_step steps up. When workload is less than inc_cpu_load, governor scales CPU down pump_down_step steps down.Example:Considerinc_cpu_load=70pump_up_step=2pump_down_step=1If current frequency=200, Every up_sampling_time Us if cpu load >= 70%, cpu is scaled up 2 steps - to 800. If current frequency =1200, Every down_sampling_time Us if cpu load < 70%, cpu is scaled down 1 step - to 1000.7) Smartass:Result of Erasmux rewriting the complete code of interactive governor. Main goal is to optimize battery life without comprising performance. Still, not as battery friendly as smartassV2 since screen-on minimum frequency is greater than frequencies used during screen-off. Smartass would jump up to highest frequency too often as well.8) SmartassV2:Version 2 of the original smartass governor from Erasmux. Another favorite for many a people. The governor aim for an "ideal frequency", and ramp up more aggressively towards this freq and less aggressive after. It uses different ideal frequencies for screen on and screen off, namely awake_ideal_freq and sleep_ideal_freq. This governor scales down CPU very fast (to hit sleep_ideal_freq soon) while screen is off and scales up rapidly to awake_ideal_freq (500 mhz for GS2 by default) when screen is on. There's no upper limit for frequency while screen is off (unlike Smartass). So the entire frequency range is available for the governor to use during screen-on and screen-off state. The motto of this governor is a balance between performance and battery.9) Intellidemand:Intellidemand aka Intelligent Ondemand from Faux is yet another governor that's based on ondemand. Unlike what some users believe, this governor is not the replacement for OC Daemon (Having different governors for sleep and awake). The original intellidemand behaves differently according to GPU usage. When GPU is really busy (gaming, maps, benchmarking, etc) intellidemand behaves like ondemand. When GPU is 'idling' (or moderately busy), intellidemand limits max frequency to a step depending on frequencies available in your device/kernel for saving battery. This is called browsing mode. We can see some 'traces' of interactive governor here. Frequency scale-up decision is made based on idling time of CPU. Lower idling time (<20%) causes CPU to scale-up from current frequency. Frequency scale-down happens at steps=5% of max frequency. (This parameter is tunable only in conservative, among the popular governors )To sum up, this is an intelligent ondemand that enters browsing mode to limit max frequency when GPU is idling, and (exits browsing mode) behaves like ondemand when GPU is busy; to deliver performance for gaming and such. Intellidemand does not jump to highest frequency when screen is off.10) Lazy:This governor from Ezekeel is basically an ondemand with an additional parameter min_time_state to specify the minimum time CPU stays on a frequency before scaling up/down. The Idea here is to eliminate any instabilities caused by fast frequency switching by ondemand. Lazy governor polls more often than ondemand, but changes frequency only after completing min_time_state on a step overriding sampling interval. Lazy also has a screenoff_maxfreq parameter which when enabled will cause the governor to always select the maximum frequency while the screen is off.11) Lagfree:Lagfree is similar to ondemand. Main difference is it's optimization to become more battery friendly. Frequency is gracefully decreased and increased, unlike ondemand which jumps to 100% too often. Lagfree does not skip any frequency step while scaling up or down. Remember that if there's a requirement for sudden burst of power, lagfree can not satisfy that since it has to raise cpu through each higher frequency step from current. Some users report that video playback using lagfree stutters a little. 12) Lionheart:Lionheart is a conservative-based governor which is based on samsung's update3 source. Tweaks comes from 1) Knzo 2) Morfic. The original idea comes from Netarchy. See here. The tunables (such as the thresholds and sampling rate) were changed so the governor behaves more like the performance one, at the cost of battery as the scaling is very aggressive.To 'experience' Lionheart using conservative, try these tweaks:sampling_rate:10000 or 20000 or 50000, whichever you feel is safer. (transition latency of the CPU is something below 10ms/10,000uS hence using 10,000 might not be safe).up_threshold:60down_threshold:30freq_step:5Lionheart goes well with deadline i/o scheduler. When it comes to smoothness (not considering battery drain), a tuned conservative delivers more as compared to a tuned ondemand.13) LionheartX:LionheartX is based on Lionheart but has a few changes on the tunables and features a suspend profile based on Smartass governor.14) Brazilianwax:Similar to smartassV2. More aggressive ramping, so more performance, less battery.15) SavagedZen:Another smartassV2 based governor. Achieves good balance between performance & battery as compared to brazilianwax.16) Userspace:Instead of automatically determining frequencies, lets user set frequencies. 17) Powersave:Locks max frequency to min frequency. Can not be used as a screen-on or even screen-off (if scaling min frequency is too low).18) Performance:Sets min frequency as max frequency. Use this while benchmarking!So, Governors can be categorized into 3/4 on a high level:1.a) Ondemand Based:Works on "ramp-up on high load" principle. CPU busy-time is taken into consideration for scaling decisions. Members: Ondemand, OndemandX, Intellidemand, Lazy, Lagfree.1.b) Conservative Based:Members: Conservative, Lionheart, LionheartX2) Interactive Based:Works on "make scaling decision when CPU comes out of idle-loop" principle. Members: Interactive, InteractiveX, Lulzactive, Smartass, SmartassV2, Brazilianwax, SavagedZen.3) Weird Category:Members: Userspace, Powersave, Performance.__________________________________________________ __________________________________________________ ____________II) QUESTION TIME: Q. "Ok. Enough of explanations. Tell me which governor is for performance and which one is for battery life." A. Tough question! lulzactive and smartassV2 for a balance between performance and battery. For light weight tasks, lulzactive should be better for battery. And for heavy weight tasks, lulzactive should be better for performance also. To get maximum performance, use a tweaked ondemand or conservative, but never complain about battery. NOTE: It's not so easy to tame luzactive. If you don't know how exactly to do it, stay away from it or you will end up complaining about battery drain!Q. "Hey, almost forgot. How do i change governors?"A. Best way is to use an init.d script if your kernel supports it. (echo "governor-name" > /sys/devices/system/cpu/cpu0/cpufreq /scaling_governor) Else use Voltage Control/SetCpu/No Frills/Antuntu CPU Master, etc. Voltage Control has the interfaces for gpu oc/uc/uv and charge-current change if your kernel supports them. Like we guessed, these apps will tell us the active governor too.Q. "How do i know which governor is best for me?"A. It depends on what you need and your daily usage pattern. Performance or battery. Better choose a governor that's balanced for battery/performance. Or tweak a governor to give performance an upper-hand as compared to battery. We can always re-charge the phone: In car when off to work, or overnight. But we can not recharge performance! After all, we bought GS2 to enjoy it's sheer power.Q. "Well i have set my favorite governor as screen-on governor and another one as screen-off governor. Why the hell is the phone not waking up after deep sleep. I need to force-restart the phone by pressing power button for about 10 secs. Is it a sleep-of-death?"A. Yes it is. Do not use two governors as screen-on & screen-off govs, if they both have an upper frequency limit for screen-off state.Didn't get it? Examples for Wrong combinations: (screen-on:screen-off):-ondemandX:smartassV2Examples for right combinations:-ondemand:smartassV2, lulzactive:smartassV2Q. "I can feel slight lags here and there with a governor. For ex: while scrolling through app drawer/vertically scrolling browser, etc. I really love this governor and don't tell me to use another governor. Can i diminish this lag?"A. Hmm well, you can. Basically what we have to do is make the governor "poll" less often to scale-down cpu. Increase down-sampling-time of your governor (whichever parameter that corresponds to), so that the cpu will stay longer on a frequency before scaling down. This should eliminate the lag.Q. "Even though i don't have too much uv/oc, once in a while; may be once in two weeks, i experience a freeze/lock/reboot. I'm using governor X. How do i solve this?" A. Well, a random reboot/freeze once in a while signifies that we're android/galaxy SII enthusiast. If everything go smooth as silk, what's the fun? We could use stock rom/kernel/governor and be happy. A rare reboot or freeze is nothing to worry about. Just restart the phone.Q. "OK. I want to tweak these governors according to my usage pattern, because i'm not happy with the default behavior of these governors". A. You can tweak the governors using an init.d script to echo suitable values into:/sys/devices/system/cpu/cpufreq/name-of-active-governor/name-of-the-paramater-to-tweakExample:echo "20000" /sys/devices/system/cpu/cpufreq/lulzactive/up_sample_timeQ. "I'm going to set scaling min freq as 100 mhz because my kernel supports it. Hope there's nothing wrong in doing that."A. Wait! You may want to stay away from using 100mhz during screen-off or screen-on states for three reasons 1) It seems 100 mhz uses more power than 200 mhz. According to tests, 100 mhz accounted to 1 W / GHz and 200 mhz to 0.7 W / GHz, when both the cores were online. 2) 200 mhz can finish same task faster compared 100 mhz and thus hit deep idle soon. 3) 200 mhz is the 'sweet spot' of frequency in SGS II. ie, the frequency used in the calculations based on the optimal energy to run (Ex: In Milestone it's 550 MHz). So , 'energetically efficient' frequency for our CPU is 200 mhz.Q. "I want to know is there's anything more i can do to improve battery life. I have already tweaked my governor settings but..."A. Take my word. Best way is to limit scaling max freq to 800 or 1000 mhz. Sgs2 can do majority of the task with 1000 or 800 as the max. OCing to 1600mhz draws considerably more power than stock 1200mhz or even 1400mhz. Try scaling between 200 and 1000 mhz for a day and feel the difference.Q. "How to make my device more snappier. I don't care much about batt....err...I do care about battery life, but only in terms of avoiding unwanted power consumption. Device should instantly dance to my tunes."A. Scale 500 to 1200 during screen-on and 200-500 during screen-off. Use performance tweaked conservative/ondemand(x). No excess power consumption because 1400 and 1600 is out the league. Response will be sweet. And don't worry, minimum of 500 during screen-on will not drain too much battery like you think!Fonte e informação mais detalhada:http://forum.xda-developers.com/showthread.php?t=1369817