mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pete Zaitcev <zaitcev@redhat.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Tina Ruchandani <ruchandani.tina@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	zaitcev@redhat.com
Subject: Re: [PATCH] USB: usbmon: Remove timeval usage for timestamp
Date: Tue, 5 May 2015 09:19:37 -0600	[thread overview]
Message-ID: <20150505091937.58beda9f@guren.zaitcev.lan> (raw)
In-Reply-To: <4936805.OkgPExQ11v@wuerfel>

On Tue, 05 May 2015 11:24:16 +0200
Arnd Bergmann <arnd@arndb.de> wrote:

> On Tuesday 05 May 2015 11:44:33 Tina Ruchandani wrote:

> >  static inline unsigned int mon_get_timestamp(void)
> >  {
> > -	struct timeval tval;
> > +	struct timespec64 now;
> >  	unsigned int stamp;
> >  
> > -	do_gettimeofday(&tval);
> > -	stamp = tval.tv_sec & 0xFFF;	/* 2^32 = 4294967296. Limit to 4096s. */
> > -	stamp = stamp * 1000000 + tval.tv_usec;
> > +	getnstimeofday64(&now);
> > +	stamp = now.tv_sec & 0xFFF;  /* now.tv_sec is 64-bit. Limit to 4096s */
> > +	stamp = stamp * USEC_PER_SEC + now.tv_nsec / NSEC_PER_USEC;
> >  	return stamp;
> >  }
> 
> Your conversion looks entirely correct, but the original code is a bit
> odd here as it does not use the entire range of the 32-bit microsecond
> value, and counts from 0 to 4096000000us instead of the more intuitive
> 0 to 4294967296 us range before wrapping around.

The intent was to create a rolling timestamp that is not too large.
Remember that the text format is intended to be eyeballed. The wrap point
could be anything. No consideration was given to what's intuitive.

> it might be more obvious what is going on, but it would slightly change
> the output in the debugfs file to use the full range. Do we know what
> behavior is expected by normal user space here?
> [...]
> I also wonder if we should make the output use monotonic time instead

The only guarantee we give is that the time corresponds to microseconds.
This is sometimes necessary to debug things in microntrollers in USB
devices.

A monotonic time is fine.

One thing though, I object to Tina's new comment. It does not matter what
now.tv_sec is. The comment is about the destination, that is the stamp.
So, please don't change it, unless you change the type of the ep->tstamp.

> static inline unsigned int mon_get_timestamp(void)
> {
> 	return ktime_to_us(ktime_get_real());
> }
> 
> it might be more obvious what is going on, but it would slightly change

Now you made the truncation explicit, so if anyhing it's less obvious.
The code is fine, but at least add a comment to that effect, if you don't
want to tack %4096000000 or %4000000000.

-- Pete

  parent reply	other threads:[~2015-05-05 16:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-05  6:14 Tina Ruchandani
2015-05-05  9:24 ` Arnd Bergmann
2015-05-05 14:59   ` Alan Stern
2015-05-05 15:33     ` Arnd Bergmann
2015-05-05 15:19   ` Pete Zaitcev [this message]
2015-05-05 15:40     ` Arnd Bergmann

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=20150505091937.58beda9f@guren.zaitcev.lan \
    --to=zaitcev@redhat.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ruchandani.tina@gmail.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

all inboxes | Powered by JetHome®