2.6.11内核CPU频率(khz)的计算
来源:互联网 发布:通过大数据分析 编辑:程序博客网 时间:2024/05/18 20:06
CPU频率的计算使用了两个函数init_cpu_khz()和calibrate_tsc()
----------------------------arch/i386/kernel/timers/Common.c--------------------
//tsc_quotient中保存通过calibrate_tsc()计算得出(CPU单个时钟周期的微秒数)*(2^32)的值,然后用1毫秒的微秒数即1000乘以2^32,再除以tsc_quotient,
//分子分母中的2^32抵消,最后的结果是1毫秒内的时钟周期数,即cpu频率的khz数
/* calculate cpu_khz */void __init init_cpu_khz(void){ if (cpu_has_tsc) { unsigned long tsc_quotient = calibrate_tsc(); if (tsc_quotient) { /* report CPU clock rate in Hz. * The formula is (10^6 * 2^32) / (2^32 * 1 / (clocks/us)) = * clock/second. Our precision is about 100 ppm. */ { unsigned long eax=0, edx=1000; __asm__("divl %2" :"=a" (cpu_khz), "=d" (edx) :"r" (tsc_quotient), "0" (eax), "1" (edx)); printk("Detected %lu.%03lu MHz processor.\n", cpu_khz / 1000, cpu_khz % 1000); } } }}
----------------------------arch/i386/kernel/timers/Common.c--------------------
//计算并返回(CPU单个时钟周期的微秒数)*(2^32)的值
unsigned long __init calibrate_tsc(void){ mach_prepare_counter();//设置5ms的计数器 { unsigned long startlow, starthigh; unsigned long endlow, endhigh; unsigned long count; rdtsc(startlow,starthigh);//读取起始时间戳 mach_countup(&count);//等待5ms rdtsc(endlow,endhigh);//读取结束时间戳 /* Error: ECTCNEVERSET */ if (count <= 1) goto bad_ctc;//计算时间戳的计数差值,即5ms中CPU收到的时钟脉冲数 /* 64-bit subtract - gcc just messes up with long longs */ __asm__("subl %2,%0\n\t" "sbbl %3,%1" :"=a" (endlow), "=d" (endhigh) :"g" (startlow), "g" (starthigh), "0" (endlow), "1" (endhigh)); /* Error: ECPUTOOFAST */ if (endhigh) goto bad_ctc; /* Error: ECPUTOOSLOW */ if (endlow <= CALIBRATE_TIME) goto bad_ctc; //计算出(每个clock的微秒数)*(2^32)的值并返回 __asm__("divl %2" :"=a" (endlow), "=d" (endhigh) :"r" (endlow), "0" (0), "1" (CALIBRATE_TIME)); return endlow; } /* * The CTC wasn't reliable: we got a hit on the very first read, * or the CPU was so fast/slow that the quotient wouldn't fit in * 32 bits.. */bad_ctc: return 0;}
- 2.6.11内核CPU频率(khz)的计算
- 关于ADC0809的500kHz时钟频率
- 内核检测CPU的时钟频率
- 利用程序计算cpu的频率
- CD为什么采用44.1kHz采样频率的问题
- 电路设计_为什么晶振的频率是32.768kHz?
- CD为什么采用44.1kHz采样频率的问题
- CPU的时钟频率
- 关于cpu的频率
- 理解CPU的频率
- cpu的几个频率
- CPU的频率
- CPU当前的频率
- CPU的频率
- CPU频率与内存频率的关系
- 单词频率的计算
- 计算单词的频率
- 获取cpu频率的代码
- Android四大组件之一-----Activity总结
- vi常用命令
- 问题如图。。。long型那个只是自己设问自问自答。。。
- 【黑马程序员】多线程(一) 第十一天
- Objective-c Beginner's Guide
- 2.6.11内核CPU频率(khz)的计算
- 走进结构体存储--位域
- hdu 1874 最短路
- 给通过代码创建的控件关联消息映射
- 玩转php数组(三)
- expandablelistview学习--在listView里面嵌套GridView
- 漫画讲解HDFS工作原理
- sayHellow --android开发
- URAL1742 Team building