Changeset View
Changeset View
Standalone View
Standalone View
ksysguardd/Linux/cpuinfo.c
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 49 | { | |||
---|---|---|---|---|---|
51 | char tag[ 32 ]; | 51 | char tag[ 32 ]; | ||
52 | char value[ 256 ]; | 52 | char value[ 256 ]; | ||
53 | char* cibp = CpuInfoBuf; | 53 | char* cibp = CpuInfoBuf; | ||
54 | 54 | | |||
55 | /* coreUniqueId is not per processor; it is a counter of the number of cores encountered | 55 | /* coreUniqueId is not per processor; it is a counter of the number of cores encountered | ||
56 | * by the parse thus far */ | 56 | * by the parse thus far */ | ||
57 | int coreUniqueId = 0; | 57 | int coreUniqueId = 0; | ||
58 | 58 | | |||
59 | /* Indicates whether the "cpu MHz" value of the processor in /proc/cpuinfo should be used. | ||||
60 | * This is not done if parsing the frequency from cpufreq worked. */ | ||||
61 | int useCpuInfoFreq = 1; | ||||
62 | | ||||
59 | /* Reset global variables */ | 63 | /* Reset global variables */ | ||
60 | numCores = 0; | 64 | numCores = 0; | ||
61 | numProcessors = 0; | 65 | numProcessors = 0; | ||
62 | 66 | | |||
63 | if ( !CpuInfoOK ) | 67 | if ( !CpuInfoOK ) | ||
64 | return; | 68 | return; | ||
65 | 69 | | |||
66 | sprintf( format, "%%%d[^:]: %%%d[^\n]\n", (int)sizeof( tag ) - 1, | 70 | sprintf( format, "%%%d[^:]: %%%d[^\n]\n", (int)sizeof( tag ) - 1, | ||
Show All 22 Lines | 87 | if ( coreUniqueId >= HighNumCores ) { | |||
89 | memset(Clocks + HighNumCores, 0, (coreUniqueId +1 - HighNumCores) * sizeof( float )); | 93 | memset(Clocks + HighNumCores, 0, (coreUniqueId +1 - HighNumCores) * sizeof( float )); | ||
90 | 94 | | |||
91 | HighNumCores = coreUniqueId + 1; | 95 | HighNumCores = coreUniqueId + 1; | ||
92 | 96 | | |||
93 | snprintf( cmdName, sizeof( cmdName ) - 1, "cpu/cpu%d/clock", coreUniqueId ); | 97 | snprintf( cmdName, sizeof( cmdName ) - 1, "cpu/cpu%d/clock", coreUniqueId ); | ||
94 | registerMonitor( cmdName, "float", printCPUxClock, printCPUxClockInfo, | 98 | registerMonitor( cmdName, "float", printCPUxClock, printCPUxClockInfo, | ||
95 | CpuInfoSM ); | 99 | CpuInfoSM ); | ||
96 | } | 100 | } | ||
101 | | ||||
102 | useCpuInfoFreq = 1; | ||||
103 | | ||||
104 | const char freqTemplate[] = "/sys/bus/cpu/devices/cpu%d/cpufreq/scaling_cur_freq"; | ||||
105 | char freqName[sizeof(freqTemplate) + 3]; | ||||
106 | snprintf(freqName, sizeof(freqName) - 1, freqTemplate, coreUniqueId); | ||||
107 | FILE *freqFd = fopen(freqName, "r"); | ||||
108 | if (freqFd) { | ||||
109 | unsigned long khz; | ||||
110 | if(fscanf(freqFd, "%lu\n", &khz) == 1) { | ||||
111 | Clocks[coreUniqueId] = khz / 1000.0f; | ||||
112 | useCpuInfoFreq = 0; | ||||
113 | } | ||||
114 | | ||||
115 | fclose(freqFd); | ||||
116 | } | ||||
97 | } | 117 | } | ||
98 | } else if ( strcmp( tag, "cpu MHz" ) == 0 ) { | 118 | } else if ( useCpuInfoFreq && strcmp( tag, "cpu MHz" ) == 0 ) { | ||
99 | if (HighNumCores > coreUniqueId) { | 119 | if (HighNumCores > coreUniqueId) { | ||
100 | /* The if statement above *should* always be true, but there's no harm in being safe. */ | 120 | /* The if statement above *should* always be true, but there's no harm in being safe. */ | ||
101 | sscanf( value, "%f", &Clocks[ coreUniqueId ] ); | 121 | sscanf( value, "%f", &Clocks[ coreUniqueId ] ); | ||
102 | } | 122 | } | ||
103 | } else if ( strcmp( tag, "core id" ) == 0 ) { | 123 | } else if ( strcmp( tag, "core id" ) == 0 ) { | ||
104 | /* the core id is per processor */ | 124 | /* the core id is per processor */ | ||
105 | int curCore; | 125 | int curCore; | ||
106 | 126 | | |||
▲ Show 20 Lines • Show All 170 Lines • Show Last 20 Lines |