mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-24 23:40:39 +01:00
[v1.05] Check read return value in frequency measurement
This commit is contained in:
@@ -130,7 +130,18 @@ int64_t measure_max_frequency(uint32_t core) {
|
||||
|
||||
nop_function(iters);
|
||||
|
||||
read(fd, &instructions, sizeof(uint64_t));
|
||||
// Clean screen once measurement is finished
|
||||
printf("\r%*c\r", (int) strlen(frequency_banner), ' ');
|
||||
|
||||
ssize_t ret = read(fd, &instructions, sizeof(uint64_t));
|
||||
if (ret == -1) {
|
||||
perror("read");
|
||||
return -1;
|
||||
}
|
||||
if (ret != sizeof(uint64_t)) {
|
||||
printErr("Read returned %d, expected %d", ret, sizeof(uint64_t));
|
||||
return -1;
|
||||
}
|
||||
if(ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) == -1) {
|
||||
perror("ioctl");
|
||||
return -1;
|
||||
@@ -144,8 +155,6 @@ int64_t measure_max_frequency(uint32_t core) {
|
||||
uint64_t usecs = nsecs/1000;
|
||||
double frequency = instructions/((double)usecs);
|
||||
|
||||
printf("\r%*c\r", (int) strlen(frequency_banner), ' ');
|
||||
|
||||
// Discard last digit in the frequency, which should help providing
|
||||
// more reliable and predictable values.
|
||||
return (((int) frequency + 5)/10) * 10;
|
||||
|
||||
Reference in New Issue
Block a user