x86计算CPU频率示例

#include                                 
#include                                
#include                                
#include                                
#include                                
#include                                  
#include                             
#include                              
#include                                 
#include                                
#include                                 
                                                   
#define ns 1000000000                             
                                                  
                                                   
//  Linux/GCC                                     
                                                   
static inline uint64_t get_cycle_count()          
{                                                 
    unsigned int lo,hi;                           
    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
    return ((uint64_t)hi << 32) | lo;             
}                                                 
                                                   
int main(int argc,char ** argv)                   
{                                                 
                                                   
    int i = 0;                                    
    uint64_t start,end;                             
    int ms = 700;                            
    for(i = 0; i < 100; i++)                      
    {                                             
        start = get_cycle_count();                  
        usleep(ms * 1000);                   
        end = get_cycle_count();                  
        printf("%u\n",(new-old)/(ms*1000));                                                                                                                                       
                                                   
    }                                             
}

你可能感兴趣的:(嵌入式,linux,x86,rdtsc)