mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +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);
|
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) {
|
if(ioctl(fd, PERF_EVENT_IOC_DISABLE, 0) == -1) {
|
||||||
perror("ioctl");
|
perror("ioctl");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -144,8 +155,6 @@ int64_t measure_max_frequency(uint32_t core) {
|
|||||||
uint64_t usecs = nsecs/1000;
|
uint64_t usecs = nsecs/1000;
|
||||||
double frequency = instructions/((double)usecs);
|
double frequency = instructions/((double)usecs);
|
||||||
|
|
||||||
printf("\r%*c\r", (int) strlen(frequency_banner), ' ');
|
|
||||||
|
|
||||||
// Discard last digit in the frequency, which should help providing
|
// Discard last digit in the frequency, which should help providing
|
||||||
// more reliable and predictable values.
|
// more reliable and predictable values.
|
||||||
return (((int) frequency + 5)/10) * 10;
|
return (((int) frequency + 5)/10) * 10;
|
||||||
|
|||||||
Reference in New Issue
Block a user