public inbox for linux-kselftest@vger.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Tommi Rantala <tommi.t.rantala@nokia.com>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shuah Khan <shuah@kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests: intel_pstate: ftime() is deprecated
Date: Tue, 27 Oct 2020 14:08:32 -0600	[thread overview]
Message-ID: <d315994a-3398-be41-1b26-e78f8359aa5c@linuxfoundation.org> (raw)
In-Reply-To: <20201016132245.73378-1-tommi.t.rantala@nokia.com>

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


  reply	other threads:[~2020-10-27 20:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-16 13:22 [PATCH] selftests: intel_pstate: ftime() is deprecated Tommi Rantala
2020-10-27 20:08 ` Shuah Khan [this message]
2020-10-28  7:36   ` Rantala, Tommi T. (Nokia - FI/Espoo)
2020-10-28 15:06     ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d315994a-3398-be41-1b26-e78f8359aa5c@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=tommi.t.rantala@nokia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox