linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Daniel Wagner <dwagner@suse.de>
Cc: Clark Williams <williams@redhat.com>, linux-rt-users@vger.kernel.org
Subject: Re: [rt-tests 1/4] rt-utils: Move timestamp calc helper to common header
Date: Thu, 3 Sep 2020 12:36:36 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.2.23.451.2009031236060.4001@fionn> (raw)
In-Reply-To: <20200901154657.30198-2-dwagner@suse.de>



On Tue, 1 Sep 2020, Daniel Wagner wrote:

> Several test implement the same helpers. Move it to a
> common header to avoid code duplication.
> 
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
>  src/cyclictest/cyclictest.c | 40 -------------------------------------
>  src/include/rt-utils.h      | 40 +++++++++++++++++++++++++++++++++++++
>  src/pi_tests/pi_stress.c    |  8 --------
>  src/signaltest/signaltest.c | 15 --------------
>  4 files changed, 40 insertions(+), 63 deletions(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index dd418939a0c2..ae1d64a46b21 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -86,9 +86,6 @@ extern int clock_nanosleep(clockid_t __clock_id, int __flags,
>  			   struct timespec *__rem);
>  #endif	/* __UCLIBC__ */
>  
> -#define USEC_PER_SEC		1000000
> -#define NSEC_PER_SEC		1000000000
> -
>  #define HIST_MAX		1000000
>  
>  #define MODE_CYCLIC		0
> @@ -291,43 +288,6 @@ enum {
>  static int trace_fd     = -1;
>  static int tracemark_fd = -1;
>  
> -static inline void tsnorm(struct timespec *ts)
> -{
> -	while (ts->tv_nsec >= NSEC_PER_SEC) {
> -		ts->tv_nsec -= NSEC_PER_SEC;
> -		ts->tv_sec++;
> -	}
> -}
> -
> -static inline int tsgreater(struct timespec *a, struct timespec *b)
> -{
> -	return ((a->tv_sec > b->tv_sec) ||
> -		(a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
> -}
> -
> -static inline int64_t calcdiff(struct timespec t1, struct timespec t2)
> -{
> -	int64_t diff = USEC_PER_SEC * (long long)((int) t1.tv_sec - (int) t2.tv_sec);
> -	diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
> -	return diff;
> -}
> -
> -static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
> -{
> -	int64_t diff;
> -	diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec);
> -	diff += ((int) t1.tv_nsec - (int) t2.tv_nsec);
> -	return diff;
> -}
> -
> -static inline int64_t calctime(struct timespec t)
> -{
> -	int64_t time;
> -	time = USEC_PER_SEC * t.tv_sec;
> -	time += ((int) t.tv_nsec) / 1000;
> -	return time;
> -}
> -
>  /*
>   * Raise the soft priority limit up to prio, if that is less than or equal
>   * to the hard limit
> diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
> index 51489b408e6c..fdd790600d68 100644
> --- a/src/include/rt-utils.h
> +++ b/src/include/rt-utils.h
> @@ -30,4 +30,44 @@ int parse_time_string(char *val);
>  void enable_trace_mark(void);
>  void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
>  
> +#define USEC_PER_SEC		1000000
> +#define NSEC_PER_SEC		1000000000
> +
> +static inline void tsnorm(struct timespec *ts)
> +{
> +	while (ts->tv_nsec >= NSEC_PER_SEC) {
> +		ts->tv_nsec -= NSEC_PER_SEC;
> +		ts->tv_sec++;
> +	}
> +}
> +
> +static inline int tsgreater(struct timespec *a, struct timespec *b)
> +{
> +	return ((a->tv_sec > b->tv_sec) ||
> +		(a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
> +}
> +
> +static inline int64_t calcdiff(struct timespec t1, struct timespec t2)
> +{
> +	int64_t diff = USEC_PER_SEC * (long long)((int) t1.tv_sec - (int) t2.tv_sec);
> +	diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
> +	return diff;
> +}
> +
> +static inline int64_t calcdiff_ns(struct timespec t1, struct timespec t2)
> +{
> +	int64_t diff;
> +	diff = NSEC_PER_SEC * (int64_t)((int) t1.tv_sec - (int) t2.tv_sec);
> +	diff += ((int) t1.tv_nsec - (int) t2.tv_nsec);
> +	return diff;
> +}
> +
> +static inline int64_t calctime(struct timespec t)
> +{
> +	int64_t time;
> +	time = USEC_PER_SEC * t.tv_sec;
> +	time += ((int) t.tv_nsec) / 1000;
> +	return time;
> +}
> +
>  #endif	/* __RT_UTILS.H */
> diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
> index eba21d7727bc..93d7044c9f22 100644
> --- a/src/pi_tests/pi_stress.c
> +++ b/src/pi_tests/pi_stress.c
> @@ -519,14 +519,6 @@ int pending_interrupt(void)
>  	return interrupted = sigismember(&pending, SIGINT);
>  }
>  
> -static inline void tsnorm(struct timespec *ts)
> -{
> -	while (ts->tv_nsec >= NSEC_PER_SEC) {
> -		ts->tv_nsec -= NSEC_PER_SEC;
> -		ts->tv_sec++;
> -	}
> -}
> -
>  /*
>   * this routine serves two purposes:
>   *   1. report progress
> diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c
> index b5c86c5635cb..42a70facc6b3 100644
> --- a/src/signaltest/signaltest.c
> +++ b/src/signaltest/signaltest.c
> @@ -69,21 +69,6 @@ static int shutdown;
>  static int tracelimit = 0;
>  static int oldtrace = 0;
>  
> -static inline void tsnorm(struct timespec *ts)
> -{
> -	while (ts->tv_nsec >= NSEC_PER_SEC) {
> -		ts->tv_nsec -= NSEC_PER_SEC;
> -		ts->tv_sec++;
> -	}
> -}
> -
> -static inline long calcdiff(struct timespec t1, struct timespec t2)
> -{
> -	long diff;
> -	diff = USEC_PER_SEC * ((int) t1.tv_sec - (int) t2.tv_sec);
> -	diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
> -	return diff;
> -}
>  
>  /*
>   * signal thread
> -- 
> 2.28.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>

  reply	other threads:[~2020-09-03 16:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01 15:46 [rt-tests 0/4] Fix signaltest output when quiet Daniel Wagner
2020-09-01 15:46 ` [rt-tests 1/4] rt-utils: Move timestamp calc helper to common header Daniel Wagner
2020-09-03 16:36   ` John Kacur [this message]
2020-09-01 15:46 ` [rt-tests 2/4] rt-utils: Move time defininitions " Daniel Wagner
2020-09-03 16:37   ` John Kacur
2020-09-01 15:46 ` [rt-tests 3/4] rt-utils: Move ARRAY_SIZE " Daniel Wagner
2020-09-03 16:38   ` John Kacur
2020-09-01 15:46 ` [rt-tests 4/4] signaltest: Only print from the first thread stats when quiet Daniel Wagner
2020-09-03 16:43   ` John Kacur

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=alpine.LFD.2.23.451.2009031236060.4001@fionn \
    --to=jkacur@redhat.com \
    --cc=dwagner@suse.de \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.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;
as well as URLs for NNTP newsgroup(s).