* [PATCH] selftests: intel_pstate: ftime() is deprecated
@ 2023-04-11 11:15 Ricardo Cañuelo
2023-04-11 11:39 ` Greg KH
0 siblings, 1 reply; 7+ messages in thread
From: Ricardo Cañuelo @ 2023-04-11 11:15 UTC (permalink / raw)
To: stable
From: Tommi Rantala <tommi.t.rantala@nokia.com>
commit fc4a3a1bf9ad799181e4d4ec9c2598c0405bc27d upstream.
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>
Reviewed-by: Ricardo Cañuelo <ricardo.canuelo@collabora.com>
Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202304060514.ELO1BqLI-lkp@intel.com/
Cc: <stable@vger.kernel.org> # 5.10.x
---
tools/testing/selftests/intel_pstate/aperf.c | 22 ++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/intel_pstate/aperf.c b/tools/testing/selftests/intel_pstate/aperf.c
index f6cd03a87493..a8acf3996973 100644
--- a/tools/testing/selftests/intel_pstate/aperf.c
+++ b/tools/testing/selftests/intel_pstate/aperf.c
@@ -10,8 +10,12 @@
#include <sched.h>
#include <errno.h>
#include <string.h>
+#include <time.h>
#include "../kselftest.h"
+#define MSEC_PER_SEC 1000L
+#define NSEC_PER_MSEC 1000000L
+
void usage(char *name) {
printf ("Usage: %s cpunum\n", name);
}
@@ -22,7 +26,7 @@ int main(int argc, char **argv) {
long long tsc, old_tsc, new_tsc;
long long aperf, old_aperf, new_aperf;
long long mperf, old_mperf, new_mperf;
- struct timeb before, after;
+ struct timespec before, after;
long long int start, finish, total;
cpu_set_t cpuset;
@@ -55,7 +59,10 @@ int main(int argc, char **argv) {
return 1;
}
- ftime(&before);
+ if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) {
+ perror("clock_gettime");
+ return 1;
+ }
pread(fd, &old_tsc, sizeof(old_tsc), 0x10);
pread(fd, &old_aperf, sizeof(old_mperf), 0xe7);
pread(fd, &old_mperf, sizeof(old_aperf), 0xe8);
@@ -64,7 +71,10 @@ int main(int argc, char **argv) {
sqrt(i);
}
- ftime(&after);
+ if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) {
+ perror("clock_gettime");
+ return 1;
+ }
pread(fd, &new_tsc, sizeof(new_tsc), 0x10);
pread(fd, &new_aperf, sizeof(new_mperf), 0xe7);
pread(fd, &new_mperf, sizeof(new_aperf), 0xe8);
@@ -73,11 +83,11 @@ int main(int argc, char **argv) {
aperf = new_aperf-old_aperf;
mperf = new_mperf-old_mperf;
- start = before.time*1000 + before.millitm;
- finish = after.time*1000 + after.millitm;
+ start = before.tv_sec*MSEC_PER_SEC + before.tv_nsec/NSEC_PER_MSEC;
+ finish = after.tv_sec*MSEC_PER_SEC + after.tv_nsec/NSEC_PER_MSEC;
total = finish - start;
- printf("runTime: %4.2f\n", 1.0*total/1000);
+ printf("runTime: %4.2f\n", 1.0*total/MSEC_PER_SEC);
printf("freq: %7.0f\n", tsc / (1.0*aperf / (1.0 * mperf)) / total);
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] selftests: intel_pstate: ftime() is deprecated
2023-04-11 11:15 [PATCH] selftests: intel_pstate: ftime() is deprecated Ricardo Cañuelo
@ 2023-04-11 11:39 ` Greg KH
2023-04-11 12:17 ` Ricardo Cañuelo
0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2023-04-11 11:39 UTC (permalink / raw)
To: Ricardo Cañuelo; +Cc: stable
On Tue, Apr 11, 2023 at 01:15:33PM +0200, Ricardo Cañuelo wrote:
> From: Tommi Rantala <tommi.t.rantala@nokia.com>
>
> commit fc4a3a1bf9ad799181e4d4ec9c2598c0405bc27d upstream.
>
> 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>
> Reviewed-by: Ricardo Cañuelo <ricardo.canuelo@collabora.com>
As you are passing this on to us, you need to also sign off on it as per
our documentation.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] selftests: intel_pstate: ftime() is deprecated
@ 2020-10-16 13:22 Tommi Rantala
2020-10-27 20:08 ` Shuah Khan
0 siblings, 1 reply; 7+ messages in thread
From: Tommi Rantala @ 2020-10-16 13:22 UTC (permalink / raw)
To: linux-kselftest, linux-kernel, Shuah Khan; +Cc: Tommi Rantala
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>
---
tools/testing/selftests/intel_pstate/aperf.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/intel_pstate/aperf.c b/tools/testing/selftests/intel_pstate/aperf.c
index f6cd03a87493..eea9dbab459b 100644
--- a/tools/testing/selftests/intel_pstate/aperf.c
+++ b/tools/testing/selftests/intel_pstate/aperf.c
@@ -10,6 +10,7 @@
#include <sched.h>
#include <errno.h>
#include <string.h>
+#include <time.h>
#include "../kselftest.h"
void usage(char *name) {
@@ -22,7 +23,7 @@ int main(int argc, char **argv) {
long long tsc, old_tsc, new_tsc;
long long aperf, old_aperf, new_aperf;
long long mperf, old_mperf, new_mperf;
- struct timeb before, after;
+ struct timespec before, after;
long long int start, finish, total;
cpu_set_t cpuset;
@@ -55,7 +56,10 @@ int main(int argc, char **argv) {
return 1;
}
- ftime(&before);
+ if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) {
+ perror("clock_gettime");
+ return 1;
+ }
pread(fd, &old_tsc, sizeof(old_tsc), 0x10);
pread(fd, &old_aperf, sizeof(old_mperf), 0xe7);
pread(fd, &old_mperf, sizeof(old_aperf), 0xe8);
@@ -64,7 +68,10 @@ int main(int argc, char **argv) {
sqrt(i);
}
- ftime(&after);
+ if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) {
+ perror("clock_gettime");
+ return 1;
+ }
pread(fd, &new_tsc, sizeof(new_tsc), 0x10);
pread(fd, &new_aperf, sizeof(new_mperf), 0xe7);
pread(fd, &new_mperf, sizeof(new_aperf), 0xe8);
@@ -73,8 +80,8 @@ int main(int argc, char **argv) {
aperf = new_aperf-old_aperf;
mperf = new_mperf-old_mperf;
- start = before.time*1000 + before.millitm;
- finish = after.time*1000 + after.millitm;
+ start = before.tv_sec*1000 + before.tv_nsec/1000000L;
+ finish = after.tv_sec*1000 + after.tv_nsec/1000000L;
total = finish - start;
printf("runTime: %4.2f\n", 1.0*total/1000);
--
2.26.2
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] selftests: intel_pstate: ftime() is deprecated
2020-10-16 13:22 Tommi Rantala
@ 2020-10-27 20:08 ` Shuah Khan
2020-10-28 7:36 ` Rantala, Tommi T. (Nokia - FI/Espoo)
0 siblings, 1 reply; 7+ messages in thread
From: Shuah Khan @ 2020-10-27 20:08 UTC (permalink / raw)
To: Tommi Rantala, linux-kselftest, linux-kernel, Shuah Khan,
Shuah Khan
Hi Tommi,
On 10/16/20 7:22 AM, Tommi Rantala wrote:
> 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)
> | ^~~~~
>
Thanks for the fix. One comment below
> Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
> ---
> tools/testing/selftests/intel_pstate/aperf.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/intel_pstate/aperf.c b/tools/testing/selftests/intel_pstate/aperf.c
> index f6cd03a87493..eea9dbab459b 100644
> --- a/tools/testing/selftests/intel_pstate/aperf.c
> +++ b/tools/testing/selftests/intel_pstate/aperf.c
> @@ -10,6 +10,7 @@
> #include <sched.h>
> #include <errno.h>
> #include <string.h>
> +#include <time.h>
> #include "../kselftest.h"
>
> void usage(char *name) {
> @@ -22,7 +23,7 @@ int main(int argc, char **argv) {
> long long tsc, old_tsc, new_tsc;
> long long aperf, old_aperf, new_aperf;
> long long mperf, old_mperf, new_mperf;
> - struct timeb before, after;
> + struct timespec before, after;
> long long int start, finish, total;
> cpu_set_t cpuset;
>
> @@ -55,7 +56,10 @@ int main(int argc, char **argv) {
> return 1;
> }
>
> - ftime(&before);
> + if (clock_gettime(CLOCK_MONOTONIC, &before) < 0) {
> + perror("clock_gettime");
> + return 1;
> + }
> pread(fd, &old_tsc, sizeof(old_tsc), 0x10);
> pread(fd, &old_aperf, sizeof(old_mperf), 0xe7);
> pread(fd, &old_mperf, sizeof(old_aperf), 0xe8);
> @@ -64,7 +68,10 @@ int main(int argc, char **argv) {
> sqrt(i);
> }
>
> - ftime(&after);
> + if (clock_gettime(CLOCK_MONOTONIC, &after) < 0) {
> + perror("clock_gettime");
> + return 1;
> + }
> pread(fd, &new_tsc, sizeof(new_tsc), 0x10);
> pread(fd, &new_aperf, sizeof(new_mperf), 0xe7);
> pread(fd, &new_mperf, sizeof(new_aperf), 0xe8);
> @@ -73,8 +80,8 @@ int main(int argc, char **argv) {
> aperf = new_aperf-old_aperf;
> mperf = new_mperf-old_mperf;
>
> - start = before.time*1000 + before.millitm;
> - finish = after.time*1000 + after.millitm;
> + start = before.tv_sec*1000 + before.tv_nsec/1000000L;
> + finish = after.tv_sec*1000 + after.tv_nsec/1000000L;
Why not use timespec dNSEC_PER_MSEC define from include/vdso/time64.h?
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] selftests: intel_pstate: ftime() is deprecated
2020-10-27 20:08 ` Shuah Khan
@ 2020-10-28 7:36 ` Rantala, Tommi T. (Nokia - FI/Espoo)
2020-10-28 15:06 ` Shuah Khan
0 siblings, 1 reply; 7+ messages in thread
From: Rantala, Tommi T. (Nokia - FI/Espoo) @ 2020-10-28 7:36 UTC (permalink / raw)
To: shuah@kernel.org, skhan@linuxfoundation.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
On Tue, 2020-10-27 at 14:08 -0600, Shuah Khan wrote:
>
> > @@ -73,8 +80,8 @@ int main(int argc, char **argv) {
> > aperf = new_aperf-old_aperf;
> > mperf = new_mperf-old_mperf;
> >
> > - start = before.time*1000 + before.millitm;
> > - finish = after.time*1000 + after.millitm;
> > + start = before.tv_sec*1000 + before.tv_nsec/1000000L;
> > + finish = after.tv_sec*1000 + after.tv_nsec/1000000L;
>
> Why not use timespec dNSEC_PER_MSEC define from include/vdso/time64.h?
Hi,
If the define was available in the UAPI headers, then certainly would make
sense to use it. But I would not mess with the kernel internal headers here.
-Tommi
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] selftests: intel_pstate: ftime() is deprecated
2020-10-28 7:36 ` Rantala, Tommi T. (Nokia - FI/Espoo)
@ 2020-10-28 15:06 ` Shuah Khan
0 siblings, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2020-10-28 15:06 UTC (permalink / raw)
To: Rantala, Tommi T. (Nokia - FI/Espoo), shuah@kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan
On 10/28/20 1:36 AM, Rantala, Tommi T. (Nokia - FI/Espoo) wrote:
> On Tue, 2020-10-27 at 14:08 -0600, Shuah Khan wrote:
>>
>>> @@ -73,8 +80,8 @@ int main(int argc, char **argv) {
>>> aperf = new_aperf-old_aperf;
>>> mperf = new_mperf-old_mperf;
>>>
>>> - start = before.time*1000 + before.millitm;
>>> - finish = after.time*1000 + after.millitm;
>>> + start = before.tv_sec*1000 + before.tv_nsec/1000000L;
>>> + finish = after.tv_sec*1000 + after.tv_nsec/1000000L;
>>
>> Why not use timespec dNSEC_PER_MSEC define from include/vdso/time64.h?
>
> Hi,
>
> If the define was available in the UAPI headers, then certainly would make
> sense to use it. But I would not mess with the kernel internal headers here.
Suggested the wrong file while looking up the define. I was thinking
linux/time64.h
However it isn't part of headers_install, so can't use that one.
Considering the number of places NSEC_PER_MSEC is hard coded
and defined in headers e.g: tools/include/linux/time64.h, probably
should be included in timespec block in time.h
Not something to worry about for this patch. Please add a NSEC_PER_MSEC
define for now in this file.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-11 12:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-11 11:15 [PATCH] selftests: intel_pstate: ftime() is deprecated Ricardo Cañuelo
2023-04-11 11:39 ` Greg KH
2023-04-11 12:17 ` Ricardo Cañuelo
-- strict thread matches above, loose matches on Subject: below --
2020-10-16 13:22 Tommi Rantala
2020-10-27 20:08 ` Shuah Khan
2020-10-28 7:36 ` Rantala, Tommi T. (Nokia - FI/Espoo)
2020-10-28 15:06 ` Shuah Khan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.