public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: Dave Chinner <david@fromorbit.com>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs_io: fix operation time reporting
Date: Thu, 1 Mar 2018 22:00:52 -0600	[thread overview]
Message-ID: <f401cfc2-fdcd-15e7-4c1a-254bbe00c2fa@sandeen.net> (raw)
In-Reply-To: <20180301035645.32633-1-david@fromorbit.com>

On 2/28/18 9:56 PM, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> CUrrently the 100th/sec units always report zero, such as:
> 
> 32 MiB, 8192 ops; 0:00:21.00 (1.476 MiB/sec and 377.9260 ops/sec)
>                           ^^
> 
> This is incorrect. Fix the maths that is wrong by removing all the
> unnecesary floating point maths and just using basic integer
> division...
> 
> Signed-Off-By: Dave Chinner <dchinner@redhat.com>
> ---
>  libxcmd/input.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/libxcmd/input.c b/libxcmd/input.c
> index 441bb2fbbf34..6e7a8c9822ee 100644
> --- a/libxcmd/input.c
> +++ b/libxcmd/input.c
> @@ -154,9 +154,10 @@ tdiv(double value, struct timeval tv)
>  	return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
>  }
>  
> -#define HOURS(sec)	((sec) / (60 * 60))
> -#define MINUTES(sec)	(((sec) % (60 * 60)) / 60)
> -#define SECONDS(sec)	((sec) % 60)
> +#define HOURS(sec)		((sec) / (60 * 60))
> +#define MINUTES(sec)		(((sec) % (60 * 60)) / 60)
> +#define SECONDS(sec)		((sec) % 60)
> +#define USEC_TO_100THS(usec)	((usec) / 1000 / 10)

I guess this works but I expected to convert "microseconds to 100ths"
via a conversion like:

usec * 1sec/1000000usec * 100 hundredths/1sec

so just for readability I'd have expected:

#define USEC_TO_100THS(usec)	((usec) / 1000000 * 100)
or possibly just
#define USEC_TO_100THS(usec)	((usec) / 10000)

... I'm confused by your choice of orders of magnitude above even
though it works - it seems a bit random to divide it that way,
unless I'm missing something?

(I had a physics teacher who drilled THINK UNITS BEFORE YOU THINK
NUMBERS" into my head an I still do) :)

>  void
>  timestr(
> @@ -165,14 +166,12 @@ timestr(
>  	size_t		size,
>  	int		format)
>  {
> -	double		usec = (double)tv->tv_usec / 1000000.0;
> -
>  	if (format & TERSE_FIXED_TIME) {
>  		if (!HOURS(tv->tv_sec)) {
>  			snprintf(ts, size, "%u:%02u.%02u",
>  				(unsigned int) MINUTES(tv->tv_sec),
>  				(unsigned int) SECONDS(tv->tv_sec),
> -				(unsigned int) usec * 100);
> +				(unsigned int) USEC_TO_100THS(tv->tv_usec));
>  			return;
>  		}
>  		format |= VERBOSE_FIXED_TIME;	/* fallback if hours needed */
> @@ -183,9 +182,10 @@ timestr(
>  			(unsigned int) HOURS(tv->tv_sec),
>  			(unsigned int) MINUTES(tv->tv_sec),
>  			(unsigned int) SECONDS(tv->tv_sec),
> -			(unsigned int) usec * 100);
> +			(unsigned int) USEC_TO_100THS(tv->tv_usec));
>  	} else {
> -		snprintf(ts, size, "0.%04u sec", (unsigned int) usec * 10000);
> +		snprintf(ts, size, "0.%04u sec",
> +			(unsigned int) tv->tv_usec / 100);

USEC_TO_10000THS() for consistency ?

>  	}
>  }
>  
> 

  reply	other threads:[~2018-03-02  4:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01  3:56 [PATCH] xfs_io: fix operation time reporting Dave Chinner
2018-03-02  4:00 ` Eric Sandeen [this message]
2018-03-02 21:49   ` Dave Chinner
2018-03-02 21:52     ` Eric Sandeen
  -- strict thread matches above, loose matches on Subject: below --
2018-03-27  7:26 Dave Chinner
2018-03-27 18:28 ` Eric Sandeen

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=f401cfc2-fdcd-15e7-4c1a-254bbe00c2fa@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /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