Added some methods to get some CPU Informations
This commit is contained in:
parent
c55e7551b2
commit
e9b8368830
5 changed files with 85 additions and 4 deletions
|
|
@ -3,9 +3,80 @@
|
|||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "os_info.h"
|
||||
#include "logger.h"
|
||||
#include <cpuid.h>
|
||||
|
||||
|
||||
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
|
||||
unsigned int *ecx, unsigned int *edx){
|
||||
#ifndef __GNUC__
|
||||
#define __asm__ asm
|
||||
#endif
|
||||
asm volatile ("cpuid"
|
||||
: "=a" (*eax),
|
||||
"=b" (*ebx),
|
||||
"=c" (*ecx),
|
||||
"=d" (*edx)
|
||||
: "0" (*eax), "2" (*ecx));
|
||||
|
||||
}
|
||||
|
||||
unsigned int getCPUStepping(){
|
||||
unsigned eax,ebx,ecx,edx;
|
||||
unsigned int stepping;
|
||||
eax=1;
|
||||
native_cpuid(&eax, &ebx, &ecx, &edx);
|
||||
|
||||
stepping = (eax >> 0) & 0xF;
|
||||
|
||||
return stepping;
|
||||
}
|
||||
|
||||
unsigned int getCPUFamily(){
|
||||
unsigned eax,ebx,ecx,edx;
|
||||
unsigned int family;
|
||||
eax = 1;
|
||||
native_cpuid(&eax, &ebx, &ecx, &edx);
|
||||
|
||||
family = (eax >> 8) & 0xF;
|
||||
|
||||
return family;
|
||||
}
|
||||
|
||||
char* getCPUType(){
|
||||
unsigned eax,ebx,ecx,edx;
|
||||
unsigned int type_id;
|
||||
char* type;
|
||||
type = malloc(sizeof(char) * 40);
|
||||
eax = 1;
|
||||
native_cpuid(&eax, &ebx, &ecx, &edx);
|
||||
type_id = (eax >> 12) & 0xF;
|
||||
if(type_id == 00){
|
||||
strcpy(type, "Original OEM Processor");
|
||||
}else if(type_id == 01){
|
||||
strcpy(type, "Intel Overdrive Processor");
|
||||
}else if(type_id == 10){
|
||||
strcpy(type, "Dual processor");
|
||||
}else{
|
||||
strcpy(type, "Reserved value");
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
double getCPUClockSpeed(){
|
||||
clock_t start, end;
|
||||
double tmp;
|
||||
start = clock();
|
||||
for(int i = 0; i < 10000; i++){
|
||||
tmp = i * i /2;
|
||||
}
|
||||
end = clock();
|
||||
return ((double) (end-start)) / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
char* getOS(){
|
||||
char *os;
|
||||
|
|
@ -13,7 +84,7 @@ char* getOS(){
|
|||
#ifdef linux
|
||||
strcpy(os, "Linux");
|
||||
#endif
|
||||
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
|
@ -33,6 +104,10 @@ char* getArch(){
|
|||
void print_Specs(){
|
||||
printf("OS: %s\n", getOS());
|
||||
printf("Architecture: %s\n", getArch());
|
||||
printf("CPU Stepping: %u\n", getCPUStepping());
|
||||
printf("CPU Family: %u\n", getCPUFamily());
|
||||
printf("CPU Type: %s\n", getCPUType());
|
||||
printf("CPU Clock: %d\n", getCPUClockSpeed());
|
||||
free(NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue