Computing the BogoMIPS value in Linux kernel learning

Source: Internet
Author: User
Computing the BogoMIPS value of Linux kernel learning-general Linux technology-Linux programming and kernel information. For details, see the following. For every linux programmer, they share a common wish to understand the linux kernel. However, the size and complexity of the Linux kernel are daunting. It is often the courage to get in and learn nothing. Here I would like to say that beginners may wish to learn some simple functions in the kernel, so that they can have fun and learn some programming styles in the kernel. Then, divide linux into several parts, such as process scheduling and memory management, to understand the principle of each part. Then, the specific implementation of each part is analyzed in detail. Finally, all parts are listed together, so that we can re-understand what we did not understand in the past. In this way, we can learn the linux kernel more quickly and systematically.

This is my understanding of kernel learning. Thank you for your valuable comments. Today, I will introduce an interesting function calibrate_delay () in the Linux kernel ().

The calibrate_delay () function can calculate the number of extremely short cycles executed by the cpu in one second. After the calculated value is processed, the BogoMIPS value is obtained, MIPS is the abbreviation of millions of instructions per second (millions of commands per second. In this way, we know that this function is actually a cpu performance test function in the Linux kernel. Because the kernel does not have high requirements for this value, the kernel uses a very simple and effective algorithm to obtain this value. Although this value is not accurate, it is enough to make us feel the heart. If you want to know your machine's BogoMIPS, you can view the last line in the/proc/cpuinfo file. After you know your cpu's BogoMIPS, if you don't think you are addicted, let's take a look at how the calibrate_delay function completes the work.

The following is the source code of calibrate_delay. I have added a line number before each line to explain it.

  
CODE: 1 # define LPS_PREC 8
2 void _ init calibrate_delay (void)
3 {
4 unsigned long ticks, loopbit;
5 int lps_precision = LPS_PREC
6
7 loops_per_sec = (1 <12 );
8
9 printk ("Calibrating delay loop ...");
10 while (loops_per_sec <= 1 ){
11/* wait for "start of" clock tick */
12 ticks = jiffies;
13 while (ticks = jiffies)
14/* nothing */;
15/* Go... */
16 ticks = jiffies;
17 _ delay (loops_per_sec );
18 ticks = jiffies-ticks;
19 if (ticks)
20 break;
21}
22
23/* Do a binary approximation to get loops_per_second set
24 * to equal one clock (up to lps_precision bits )*/
25 loops_per_sec >>= 1;
26 loopbit = loop_per_sec;
27 while (lps_precision -- & (loopbit >>=1 )){
28 loops_per_sec | = loopbit;
29 ticks = jiffies;
30 while (ticks = jiffies );
31 ticks = jiffies;
32 _ delay (loops_per_sec );
33 if (jiffies! = Ticks)/* longer than 1 tick */
34 loops_per_sec & = ~ Loopbit;
35}
36/* finally, adjust loops per second in terms of seconds
37 * instead of clocks */
38 loops_per_sec * = HZ;
39/* Round the value and print it */
40 printk ("% lu. % 02lu BogoMIPSn ",
41 (loops_per_sec + 2500)/500000,
42 (loops_per_sec + 2500)/5000) % 100 );
43}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.