⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpuinfo.c

📁 uboot在arm处理器s3c2410的移植代码
💻 C
📖 第 1 页 / 共 2 页
字号:
RETURNS:True if the RTSC instruction is available, false if not.REMARKS:This function determines if the processor supports the Intel RDTSCinstruction, for high precision timing. If the processor is not an Intel orIntel clone CPU, this function will always return false.DESCRIPTION:Returns true if the processor supports RDTSC extensions.HEADER:ztimer.hRETURNS:True if RTSC is available, false if not.REMARKS:This function determines if the processor supports the RDTSC instructionfor reading the processor time stamp counter.SEE ALSO:CPU_getProcessorType, CPU_getProcessorSpeed, CPU_haveMMX, CPU_have3DNow,CPU_getProcessorName****************************************************************************/ibool ZAPI CPU_haveRDTSC(void){#ifdef  __INTEL__    if (_CPU_haveCPUID())	return (_CPU_getCPUIDFeatures() & CPU_HaveRDTSC) != 0;    return false;#else    return false;#endif}#ifdef  __INTEL__#define ITERATIONS      16000#define SAMPLINGS       2#define INNER_LOOPS     400/****************************************************************************REMARKS:If processor does not support time stamp reading, but is at least a 386 orabove, utilize method of timing a loop of BSF instructions which take aknown number of cycles to run on i386(tm), i486(tm), and Pentium(R)processors.****************************************************************************/static ulong GetBSFCpuSpeed(    ulong cycles){    CPU_largeInteger t0,t1,count_freq;    ulong   ticks;              /* Microseconds elapsed during test     */    ulong   current;            /* Variable to store time elapsed       */    int     i,j,iPriority;    ulong   lowest  = (ulong)-1;    iPriority = SetMaxThreadPriority();    GetCounterFrequency(&count_freq);    for (i = 0; i < SAMPLINGS; i++) {	GetCounter(&t0);	for (j = 0; j < INNER_LOOPS; j++)	    _CPU_runBSFLoop(ITERATIONS);	GetCounter(&t1);	current = t1.low - t0.low;	if (current < lowest)	    lowest = current;	}    RestoreThreadPriority(iPriority);    /* Compute frequency */    ticks = _CPU_mulDiv(lowest,1000000,count_freq.low);    if ((ticks % count_freq.low) > (count_freq.low/2))	ticks++;            /* Round up if necessary */    if (ticks == 0)	return 0;    return ((cycles*INNER_LOOPS)/ticks);}#define TOLERANCE       1/****************************************************************************REMARKS:On processors supporting the Read Time Stamp opcode, compare elapsedtime on the High-Resolution Counter with elapsed cycles on the TimeStamp Register.The inner loop runs up to 20 times oruntil the average of the previousthree calculated frequencies is within 1 MHz of each of the individualcalculated frequencies. This resampling increases the accuracy of theresults since outside factors could affect this calculation.****************************************************************************/static ulong GetRDTSCCpuSpeed(    ibool accurate){    CPU_largeInteger    t0,t1,s0,s1,count_freq;    u64                 stamp0, stamp1, ticks0, ticks1;    u64                 total_cycles, cycles, hz, freq;    u64                 total_ticks, ticks;    int                 tries,iPriority;    ulong               maxCount;    PM_set64_32(total_cycles,0);    PM_set64_32(total_ticks,0);    maxCount = accurate ? 600000 : 30000;    iPriority = SetMaxThreadPriority();    GetCounterFrequency(&count_freq);    PM_set64(freq,count_freq.high,count_freq.low);    for (tries = 0; tries < 3; tries++) {	/* Loop until 100 ticks have passed since last read of hi-res	 * counter. This accounts for overhead later.	 */	GetCounter(&t0);	t1.low = t0.low;	t1.high = t0.high;	while ((t1.low - t0.low) < 100) {	    GetCounter(&t1);	    _CPU_readTimeStamp(&s0);	    }	/* Loop until 30000 ticks have passed since last read of hi-res counter.	 * This allows for elapsed time for sampling. For a hi-res frequency	 * of 1MHz, this is about 0.03 of a second. The frequency reported	 * by the OS dependent code should be tuned to provide a good	 * sample period depending on the accuracy of the OS timers (ie:	 * if the accuracy is lower, lower the frequency to spend more time	 * in the inner loop to get better accuracy).	 */	t0.low = t1.low;	t0.high = t1.high;	while ((t1.low - t0.low) < maxCount) {	    GetCounter(&t1);	    _CPU_readTimeStamp(&s1);	    }	/* Find the difference during the timing loop */	PM_set64(stamp0,s0.high,s0.low);	PM_set64(stamp1,s1.high,s1.low);	PM_set64(ticks0,t0.high,t0.low);	PM_set64(ticks1,t1.high,t1.low);	PM_sub64(cycles,stamp1,stamp0);	PM_sub64(ticks,ticks1,ticks0);	/* Sum up the results */	PM_add64(total_ticks,total_ticks,ticks);	PM_add64(total_cycles,total_cycles,cycles);	}    RestoreThreadPriority(iPriority);    /* Compute frequency in Hz */    PM_mul64(hz,total_cycles,freq);    PM_div64(hz,hz,total_ticks);    return PM_64to32(hz);}#endif  /* __INTEL__ *//****************************************************************************DESCRIPTION:Returns the speed of the processor in MHz.HEADER:ztimer.hPARAMETERS:accurate    - True of the speed should be measured accuratelyRETURNS:Processor speed in MHz.REMARKS:This function returns the speed of the CPU in MHz. Note that if the speedcannot be determined, this function will return 0.If the accurate parameter is set to true, this function will spend longerprofiling the speed of the CPU, and will not round the CPU speed that isreported. This is important for highly accurate timing using the PentiumRDTSC instruction, but it does take a lot longer for the profiling toproduce accurate results.SEE ALSO:CPU_getProcessorSpeedInHz, CPU_getProcessorType, CPU_haveMMX,CPU_getProcessorName****************************************************************************/ulong ZAPI CPU_getProcessorSpeed(    ibool accurate){#if defined(__INTEL__)    /* Number of cycles needed to execute a single BSF instruction on i386+     * processors.     */    ulong   cpuSpeed;    uint    i;    static  ulong intel_cycles[] = {	115,47,43,	};    static  ulong cyrix_cycles[] = {	38,38,52,52,	};    static  ulong amd_cycles[] = {	49,	};    static  ulong known_speeds[] = {	1000,950,900,850,800,750,700,650,600,550,500,450,433,400,350,	333,300,266,233,200,166,150,133,120,100,90,75,66,60,50,33,20,0,	};    if (CPU_haveRDTSC()) {	cpuSpeed = (GetRDTSCCpuSpeed(accurate) + 500000) / 1000000;	}    else {	int type = CPU_getProcessorType();	int processor = type & CPU_mask;	int vendor = type & CPU_familyMask;	if (vendor == CPU_Intel)	    cpuSpeed = GetBSFCpuSpeed(ITERATIONS * intel_cycles[processor - CPU_i386]);	else if (vendor == CPU_Cyrix)	    cpuSpeed = GetBSFCpuSpeed(ITERATIONS * cyrix_cycles[processor - CPU_Cyrix6x86]);	else if (vendor == CPU_AMD)	    cpuSpeed = GetBSFCpuSpeed(ITERATIONS * amd_cycles[0]);	else	    return 0;	}    /* Now normalise the results given known processors speeds, if the     * speed we measure is within 2MHz of the expected values     */    if (!accurate) {	for (i = 0; known_speeds[i] != 0; i++) {	    if (cpuSpeed >= (known_speeds[i]-3) && cpuSpeed <= (known_speeds[i]+3)) {		return known_speeds[i];		}	    }	}    return cpuSpeed;#else    return 0;#endif}/****************************************************************************DESCRIPTION:Returns the speed of the processor in Hz.HEADER:ztimer.hRETURNS:Accurate processor speed in Hz.REMARKS:This function returns the accurate speed of the CPU in Hz. Note that if thespeed cannot be determined, this function will return 0.This function is similar to the CPU_getProcessorSpeed function, except thatit attempts to accurately measure the CPU speed in Hz. This is usedinternally in the Zen Timer libraries to provide accurate real world timinginformation. This is important for highly accurate timing using the PentiumRDTSC instruction, but it does take a lot longer for the profiling toproduce accurate results.SEE ALSO:CPU_getProcessorSpeed, CPU_getProcessorType, CPU_haveMMX,CPU_getProcessorName****************************************************************************/ulong ZAPI CPU_getProcessorSpeedInHZ(    ibool accurate){#if defined(__INTEL__)    if (CPU_haveRDTSC()) {	return GetRDTSCCpuSpeed(accurate);	}    return CPU_getProcessorSpeed(false) * 1000000;#else    return 0;#endif}/****************************************************************************DESCRIPTION:Returns a string defining the speed and name of the processor.HEADER:ztimer.hRETURNS:Processor name string.REMARKS:This function returns an English string describing the speed and name of theCPU.SEE ALSO:CPU_getProcessorType, CPU_haveMMX, CPU_getProcessorName****************************************************************************/char * ZAPI CPU_getProcessorName(void){#if defined(__INTEL__)    static int  cpu,speed = -1;    static char name[80];    if (speed == -1) {	cpu = CPU_getProcessorType();	speed = CPU_getProcessorSpeed(false);	}    sprintf(name,"%d MHz ", speed);    switch (cpu & CPU_mask) {	case CPU_i386:	    strcat(name,"Intel i386 processor");	    break;	case CPU_i486:	    strcat(name,"Intel i486 processor");	    break;	case CPU_Pentium:	    strcat(name,"Intel Pentium processor");	    break;	case CPU_PentiumPro:	    strcat(name,"Intel Pentium Pro processor");	    break;	case CPU_PentiumII:	    strcat(name,"Intel Pentium II processor");	    break;	case CPU_Celeron:	    strcat(name,"Intel Celeron processor");	    break;	case CPU_PentiumIII:	    strcat(name,"Intel Pentium III processor");	    break;	case CPU_UnkIntel:	    strcat(name,"Unknown Intel processor");	    break;	case CPU_Cyrix6x86:	    strcat(name,"Cyrix 6x86 processor");	    break;	case CPU_Cyrix6x86MX:	    strcat(name,"Cyrix 6x86MX processor");	    break;	case CPU_CyrixMediaGX:	    strcat(name,"Cyrix MediaGX processor");	    break;	case CPU_CyrixMediaGXm:	    strcat(name,"Cyrix MediaGXm processor");	    break;	case CPU_UnkCyrix:	    strcat(name,"Unknown Cyrix processor");	    break;	case CPU_AMDAm486:	    strcat(name,"AMD Am486 processor");	    break;	case CPU_AMDAm5x86:	    strcat(name,"AMD Am5x86 processor");	    break;	case CPU_AMDK5:	    strcat(name,"AMD K5 processor");	    break;	case CPU_AMDK6:	    strcat(name,"AMD K6 processor");	    break;	case CPU_AMDK6_2:	    strcat(name,"AMD K6-2 processor");	    break;	case CPU_AMDK6_III:	    strcat(name,"AMD K6-III processor");	    break;	case CPU_AMDK6_2plus:	    strcat(name,"AMD K6-2+ processor");	    break;	case CPU_AMDK6_IIIplus:	    strcat(name,"AMD K6-III+ processor");	    break;	case CPU_UnkAMD:	    strcat(name,"Unknown AMD processor");	    break;	case CPU_AMDAthlon:	    strcat(name,"AMD Athlon processor");	    break;	case CPU_AMDDuron:	    strcat(name,"AMD Duron processor");	    break;	case CPU_WinChipC6:	    strcat(name,"IDT WinChip C6 processor");	    break;	case CPU_WinChip2:	    strcat(name,"IDT WinChip 2 processor");	    break;	case CPU_UnkIDT:	    strcat(name,"Unknown IDT processor");	    break;	default:	    strcat(name,"Unknown processor");	}    if (CPU_haveMMX())	strcat(name," with MMX(R)");    if (CPU_have3DNow())	strcat(name,", 3DNow!(R)");    if (CPU_haveSSE())	strcat(name,", SSE(R)");    return name;#else    return "Unknown";#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -