天天看点

进程调度之时间片以及时间相关的概念

一些基本宏定义和基础概念

基础时间片:DEF_TIMESLICE (100 * HZ / 1000) == 100ms

CONFIG_HZ表示每秒定时器发生中断的次数。内核可以配置。也就是linux系统时钟的频率。

内核定义如下: 在C:\linux\linux-2.6.23\arch\i386\defconfig 里面定义

# CONFIG_HZ_100 is not set
CONFIG_HZ_250=y
# CONFIG_HZ_300 is not set
# CONFIG_HZ_1000 is not set
CONFIG_HZ=250
           

对应linux源代码

Param.h (c:\linux\linux-2.6.23\include\asm-i386):# define HZ		CONFIG_HZ	/* Internal kernel timer frequency */
Param.h (c:\linux\linux-2.6.23\include\asm-powerpc):#define HZ		CONFIG_HZ	/* internal kernel timer frequency */

           

JFFIY:表示1个时钟滴答。时间间隔是由CONFIG_HZ决定的,如果CONFIG_HZ配置为250,表示周期为4ms;也就是说每4ms增加一个时钟嘀嗒,即jffies++。

获取当前时间戳

sched_clock
	=>native_sched_clock
		=>/* read the Time Stamp Counter: */
		rdtscll(this_offset);
			=>#define rdtscll(val)	((val) = native_read_tsc())
				=>unsigned long long val;
				=>asm volatile("rdtsc" : "=A" (val));
				=>return val;
		/* return the value in ns */
		=>return cycles_2_ns(this_offset);
           

下面几篇文章写得都不错

参考

http://blog.csdn.net/russell_tao/article/details/7103012

LINUX时间管理

http://blog.csdn.net/zhenwenxian/article/details/7643742

[Timer学习]wall time和monotonic time

http://blog.csdn.net/peterlin666/article/details/32344355

Linux时间管理之clocksource

http://blog.chinaunix.net/uid-24774106-id-3909829.html

Linux时间管理之hardware

http://blog.chinaunix.net/uid-24774106-id-3902906.html

CONFIG_HZ 和 USER_HZ

http://blog.chinaunix.net/uid-24774106-id-3877992.html

继续阅读