brintos

brintos / linux-shallow public Read only

0
0
Text · 2.7 KiB · ed07efe Raw
73 lines · plain
1=================================================================2CPU Scheduler implementation hints for architecture specific code3=================================================================4 5	Nick Piggin, 20056 7Context switch8==============91. Runqueue locking10By default, the switch_to arch function is called with the runqueue11locked. This is usually not a problem unless switch_to may need to12take the runqueue lock. This is usually due to a wake up operation in13the context switch.14 15To request the scheduler call switch_to with the runqueue unlocked,16you must `#define __ARCH_WANT_UNLOCKED_CTXSW` in a header file17(typically the one where switch_to is defined).18 19Unlocked context switches introduce only a very minor performance20penalty to the core scheduler implementation in the CONFIG_SMP case.21 22CPU idle23========24Your cpu_idle routines need to obey the following rules:25 261. Preempt should now disabled over idle routines. Should only27   be enabled to call schedule() then disabled again.28 292. need_resched/TIF_NEED_RESCHED is only ever set, and will never30   be cleared until the running task has called schedule(). Idle31   threads need only ever query need_resched, and may never set or32   clear it.33 343. When cpu_idle finds (need_resched() == 'true'), it should call35   schedule(). It should not call schedule() otherwise.36 374. The only time interrupts need to be disabled when checking38   need_resched is if we are about to sleep the processor until39   the next interrupt (this doesn't provide any protection of40   need_resched, it prevents losing an interrupt):41 42	4a. Common problem with this type of sleep appears to be::43 44	        local_irq_disable();45	        if (!need_resched()) {46	                local_irq_enable();47	                *** resched interrupt arrives here ***48	                __asm__("sleep until next interrupt");49	        }50 515. TIF_POLLING_NRFLAG can be set by idle routines that do not52   need an interrupt to wake them up when need_resched goes high.53   In other words, they must be periodically polling need_resched,54   although it may be reasonable to do some background work or enter55   a low CPU priority.56 57      - 5a. If TIF_POLLING_NRFLAG is set, and we do decide to enter58	an interrupt sleep, it needs to be cleared then a memory59	barrier issued (followed by a test of need_resched with60	interrupts disabled, as explained in 3).61 62arch/x86/kernel/process.c has examples of both polling and63sleeping idle functions.64 65 66Possible arch/ problems67=======================68 69Possible arch problems I found (and either tried to fix or didn't):70 71sparc - IRQs on at this point(?), change local_irq_save to _disable.72      - TODO: needs secondary CPUs to disable preempt (See #1)73