Chinaunix首页 | 论坛 | 博客
  • 博客访问: 641217
  • 博文数量: 75
  • 博客积分: 7001
  • 博客等级: 少将
  • 技术积分: 1465
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-11 17:39
文章分类

全部博文(75)

文章存档

2010年(1)

2009年(25)

2008年(49)

我的朋友

分类: LINUX

2009-05-21 10:14:56

Call graph of CPU idle thread

Recently I'm absorbed in DPM project, meeting a problem that when and where the cpu idle thread will be called?

After surfing the Internet, I find following useful notes.

Machine class idle function - arch_idle
The arch_idle call is only called when the machine has no other process to run. Since the arch_idle call is both machine class and processor dependent, we call the machine class idle function, which will perform any specific idle functions, and which may or may not call call the cpu idle function.

The idea is that if the CPU has some instructions to put it to sleep, then these go into the cpu idle function. If not, the cpu idle function should be empty, and the idle stuff goes into arch_idle (since its touching machine-specific registers).

To give you an example, on machines which can have a StrongARM, we have the ability to slow down the processors clock. However, we don't just slow down the clock when we enter arch_idle, delay, speed it back up and then return since that would hurt the latency of the system.

Instead, we wait a while to see if a process becomes runnable. If it does, we return immediately from arch_idle, thus preserving the low latency of the system.

However, once 1/3 sec has expired, we slow the core clock and then use anything which provides us with a more "low-power" sleep, eg, wait-for-interrupt instruction. Once a process becomes runnable again, we speed the clock up again.

As you can see, if the system is active, the processors clock will be running at high speed all the time, but if you get unactivity for 1/3 sec, then it starts dropping the processor clock speed and therefore conserving power.

Obviously, if your machine has more processor clock rates/sleep options that would be useful, you could do a more fancy scheme here which could trade idle time vs power conservation. (eg, measure idle time and increase processor clock as idle time decreases).
                     -- quote from http://www.arm.linux.org.uk/developer/kernelnotes.php



I also draw the following flow chart while checking corresponding code. While there is no task existing in the system, cpu_idle() function will be called, in cpu_idle() function, the actual idle function relies on the callback function assigned to function pointer void(*idle)(void), if global function pointer pm_idle is NULL, default_idle() function will be assigned to idle, else, the default_idle will be replaced with pm_idle, as we know, in pm.c file, pm_idle is assigned with evb1226_pm_idle function during the bootup of kernel, in which WFI instruction will be executed, whereas, in cpu_do_idle() invoked by default_idle(), no similar related operations found.
We can also find out that the instruction “__asm__ volatile ("mcr        p15, 0, r0, c7, c0, 4")” will be executed in evb1226_pm_idle function.




阅读(1563) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~