Kernel Quest: Linux bogomips Quest

Source: Internet
Author: User

by Tao Hongliang of tinylab.org
2015/04/12

Background

Today, as usual, in the lab and a group of siege division colleagues in the day and night code. Suddenly, a classmate asked a sentence:/proc/cpuinfo ( godson platform ) in the bogomips and CPU frequency is what relationship? A stone stirred thousands of waves, a time of various wonderful answers endless, and finally no conclusion. The Siege division decided to destroy Huanglong a probe, to the confused small partners an explanation.

The origin of Bogomips

Bogomips is the original Linus himself, Bogo meaning "false, forged", MIPS means "Millions of instructions Per Second", if the system starts, calculated Bogomips is 100, can be recorded as 1 million Pseudo-instruction per second.

This is called a pseudo-instruction because the CPU has been performing a single NOP (empty operation) while calculating the value of the bogomips, rather than executing arbitrary instructions in the instruction set randomly, so it cannot be used as a CPU performance indicator.

Calculation of Bogomips

Now let's go into the code and see how he calculates it. The author is in the v3.13.0 version of the Linux kernel source of the experiment. There are few changes in this section, and other similar versions should be no different.

first , the bogomips calculation is given in the file arch/mips/kernel/proc.c :

seq_printf (M, "bogomips\t\t:%u.%0 2u\n ",    cpu_data[n].udelay_val/(500000/hz),    (Cpu_data[n].udelay_val/(5000/hz))% 100);

Where HZ is the fixed constant at the time of kernel configuration, the only Udelay_val value left in this formula is unknown. Little reminder: Here is a classic example of using an integer to express floating-point types, and small partners can learn.

then , the Udelay_val calculation is given in the file arch/mips/include/asm/bugs.h :

Cpu_data[cpu].udelay_val = Loops_per_jiffy;

finally , in the file init/calibrate.c , we can find the Loops_per_jiffy calculation method:

#define LPS_PREC 8Static unsigned LongCalibrate_delay_converge (void){/ * First stage-slowly accelerate to find initial bounds * /    unsigned LongLPJ, Lpj_base, Ticks, Loopadd, Loopadd_base, Chop_limit;intTrials =0, band =0, Trial_in_band =0; LPJ = (1<< A);/ * Wait for "start of" clock tick * /    /* It's smart to choose a start time to calculate loops, that is, when a tick starts * /Ticks = jiffies; while(ticks = = jiffies);/ * Nothing * *    / * Go: * /Ticks = jiffies;/* Here, in a jiffy time period, the loop calls the __delay (NOP Loop), and the last cumulative delay is calculated.     How much is the Loops_per_jiffy. */     Do{if(++trial_in_band = = (1<<band)) {++band; Trial_in_band =0;        } __delay (LPJ * band);    Trials + = Band; } while(ticks = = jiffies);/ * * We overshot, so retreat to a clear underestimate. Then estimate * The largest likely undershoot.     This defines our chop bounds. */Trials-= Band;    Loopadd_base = LPJ * BAND; Lpj_base = LPJ * trials;/ * Next, fine-tune the value of the Loops_per_jiffy calculated above to make sure it is accurate * /RECALIBRATE:LPJ = Lpj_base; Loopadd = Loopadd_base;/* * Do a binary approximation to get LPJ set to * equal one clock (up to lps_prec bits) */Chop_limit = LPJ >> lps_prec; while(Loopadd > Chop_limit)        {LPJ + = Loopadd; Ticks = jiffies; while(ticks = = jiffies);/ * Nothing * *Ticks = jiffies; __delay (LPJ);if(jiffies! = ticks)/ * longer than 1 tick * /LPJ-= Loopadd; Loopadd >>=1; }/ * * If We incremented every single time possible, presume we ' ve * massively underestimated initially, and RET Ry with a higher * start, and larger range. (only seen on x86_64, due to SMIs) */    if(LPJ + Loopadd *2= = Lpj_base + loopadd_base *2) {lpj_base = LPJ; Loopadd_base <<=2;Gotorecalibrate; }returnLPJ;}

Now we've got the essence of Loops_per_jiffy. Detailed calculation method, you can refer to the above code given in the Chinese comments.

Bogomips = Loops_per_jiffy÷ (500000/hz)   --->   bogomips = (Loops_per_jiffy * HZ) ÷500000

Hz is the number of ticks per second, that is, the number of Jiffy per second. So, Loops_per_jiffy * HZ = Loops_per_second

bogomips = loops_per_second÷500000  --->   

Since then, Bogomips's calculation quest has ended.

The relationship between Bogomips and CPU frequency

Looking at the calculation of the above bogomips, we find that there is no direct formula that allows bogomips and CPU frequencies to be converted to each other. But at least you can infer that for the same processor :

    • The faster the CPU frequency, the greater the value of the Loops_per_second, the greater the value of the bogomips;
    • The lower the CPU frequency, the smaller the value of the bogomips;
    • When the CPU is variable frequency, the bogomips will increase with the increase of CPU frequency, decrease and decrease.

Referring to the data already on Wikipedia, you can get a deeper understanding of the relationship between Bogomips and CPU frequency:

Kernel Quest: Linux bogomips Quest

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.