Changeset View
Changeset View
Standalone View
Standalone View
ksysguardd/Linux/cpuinfo.c
Context not available. | |||||
40 | static int HighNumCores = 0; /* Highest # of cores ever seen */ | 40 | static int HighNumCores = 0; /* Highest # of cores ever seen */ | ||
---|---|---|---|---|---|
41 | static float* Clocks = 0; /* Array with one entry per core */ | 41 | static float* Clocks = 0; /* Array with one entry per core */ | ||
42 | 42 | | |||
43 | #define CPUINFOBUFSIZE (32 * 1024) | 43 | /* Enough for 4-6 virtual cores. Larger values will be tried as needed. */ | ||
44 | static char CpuInfoBuf[ CPUINFOBUFSIZE ]; | 44 | static size_t CpuInfoBufSize = 8 * 1024; | ||
45 | static char* CpuInfoBuf = NULL; | ||||
45 | static int Dirty = 0; | 46 | static int Dirty = 0; | ||
46 | static struct SensorModul *CpuInfoSM; | 47 | static struct SensorModul *CpuInfoSM; | ||
47 | 48 | | |||
Context not available. | |||||
191 | return -1; | 192 | return -1; | ||
192 | } | 193 | } | ||
193 | 194 | | |||
195 | if ( CpuInfoBuf == NULL ) { | ||||
196 | CpuInfoBuf = malloc( CpuInfoBufSize ); | ||||
197 | } | ||||
194 | n = 0; | 198 | n = 0; | ||
195 | for(;;) { | 199 | for(;;) { | ||
196 | ssize_t len = read( fd, CpuInfoBuf + n, CPUINFOBUFSIZE - 1 - n ); | 200 | ssize_t len = read( fd, CpuInfoBuf + n, CpuInfoBufSize - 1 - n ); | ||
197 | if( len < 0 ) { | 201 | if( len < 0 ) { | ||
198 | print_error( "Failed to read file \'/proc/cpuinfo\'!\n" ); | 202 | print_error( "Failed to read file \'/proc/cpuinfo\'!\n" ); | ||
199 | CpuInfoOK = -1; | 203 | CpuInfoOK = -1; | ||
Context not available. | |||||
203 | n += len; | 207 | n += len; | ||
204 | if( len == 0 ) /* reading finished */ | 208 | if( len == 0 ) /* reading finished */ | ||
205 | break; | 209 | break; | ||
206 | if( n == CPUINFOBUFSIZE - 1 ) { | 210 | if( n == CpuInfoBufSize - 1 ) { | ||
207 | log_error( "Internal buffer too small to read \'/proc/cpuinfo\'" ); | 211 | /* The buffer was too small. Double its size and keep going. */ | ||
208 | CpuInfoOK = 0; | 212 | size_t new_size = CpuInfoBufSize * 2; | ||
209 | close( fd ); | 213 | char* new_buffer = malloc( new_size ); | ||
210 | return -1; | 214 | memcpy( new_buffer, CpuInfoBuf, n ); /* copy read data */ | ||
215 | free( CpuInfoBuf ); /* free old buffer */ | ||||
216 | CpuInfoBuf = new_buffer; /* remember new buffer and size */ | ||||
217 | CpuInfoBufSize = new_size; | ||||
211 | } | 218 | } | ||
212 | } | 219 | } | ||
213 | 220 | | |||
Context not available. |