Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: intel_pstate: ftime() is deprecated

Use clock_gettime() instead of deprecated ftime().

aperf.c: In function ‘main’:
aperf.c:58:2: warning: ‘ftime’ is deprecated [-Wdeprecated-declarations]
58 | ftime(&before);
| ^~~~~
In file included from aperf.c:9:
/usr/include/sys/timeb.h:39:12: note: declared here
39 | extern int ftime (struct timeb *__timebuf)
| ^~~~~

Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Tommi Rantala and committed by
Shuah Khan
fc4a3a1b 85128c5b

+16 -6
+16 -6
tools/testing/selftests/intel_pstate/aperf.c
··· 10 10 #include <sched.h> 11 11 #include <errno.h> 12 12 #include <string.h> 13 + #include <time.h> 13 14 #include "../kselftest.h" 15 + 16 + #define MSEC_PER_SEC 1000L 17 + #define NSEC_PER_MSEC 1000000L 14 18 15 19 void usage(char *name) { 16 20 printf ("Usage: %s cpunum\n", name); ··· 26 22 long long tsc, old_tsc, new_tsc; 27 23 long long aperf, old_aperf, new_aperf; 28 24 long long mperf, old_mperf, new_mperf; 29 - struct timeb before, after; 25 + struct timespec before, after; 30 26 long long int start, finish, total; 31 27 cpu_set_t cpuset; 32 28 ··· 59 55 return 1; 60 56 } 61 57 62 - ftime(&before); 58 + if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) { 59 + perror("clock_gettime"); 60 + return 1; 61 + } 63 62 pread(fd, &old_tsc, sizeof(old_tsc), 0x10); 64 63 pread(fd, &old_aperf, sizeof(old_mperf), 0xe7); 65 64 pread(fd, &old_mperf, sizeof(old_aperf), 0xe8); ··· 71 64 sqrt(i); 72 65 } 73 66 74 - ftime(&after); 67 + if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) { 68 + perror("clock_gettime"); 69 + return 1; 70 + } 75 71 pread(fd, &new_tsc, sizeof(new_tsc), 0x10); 76 72 pread(fd, &new_aperf, sizeof(new_mperf), 0xe7); 77 73 pread(fd, &new_mperf, sizeof(new_aperf), 0xe8); ··· 83 73 aperf = new_aperf-old_aperf; 84 74 mperf = new_mperf-old_mperf; 85 75 86 - start = before.time*1000 + before.millitm; 87 - finish = after.time*1000 + after.millitm; 76 + start = before.tv_sec*MSEC_PER_SEC + before.tv_nsec/NSEC_PER_MSEC; 77 + finish = after.tv_sec*MSEC_PER_SEC + after.tv_nsec/NSEC_PER_MSEC; 88 78 total = finish - start; 89 79 90 - printf("runTime: %4.2f\n", 1.0*total/1000); 80 + printf("runTime: %4.2f\n", 1.0*total/MSEC_PER_SEC); 91 81 printf("freq: %7.0f\n", tsc / (1.0*aperf / (1.0 * mperf)) / total); 92 82 return 0; 93 83 }