Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2993422AbbEEQK4 (ORCPT ); Tue, 5 May 2015 12:10:56 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:64723 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2993430AbbEEPku (ORCPT ); Tue, 5 May 2015 11:40:50 -0400 From: Arnd Bergmann To: Pete Zaitcev Cc: Tina Ruchandani , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] USB: usbmon: Remove timeval usage for timestamp Date: Tue, 05 May 2015 17:40:39 +0200 Message-ID: <2267985.PdWzCZ9u0n@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <20150505091937.58beda9f@guren.zaitcev.lan> References: <20150505061433.GA4690@tinar> <4936805.OkgPExQ11v@wuerfel> <20150505091937.58beda9f@guren.zaitcev.lan> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:vCszYj44mx1DYbogMGKPzLsaWJjg9VYDClMccLYyLjgD2NOgEpA T0cmo3W++OuNnq1GNXj0stSh5DbM2pZoUq1VBHaaFu3g9zDREhypo96vpnfNPhvmLq10TWq 3xGzN7Bo46KY9MNXvY5Rc86CkvgGppt/mQso9AmJZr2aYCh5Tp9HHmgBgYNrivZzXfB8rUE MM2izW5dBHoP8dLPbp5Wg== X-UI-Out-Filterresults: notjunk:1; Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3184 Lines: 77 On Tuesday 05 May 2015 09:19:37 Pete Zaitcev wrote: > On Tue, 05 May 2015 11:24:16 +0200 > Arnd Bergmann 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. Ok > > 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. The point of the patch that I thought she had made clear enough is to eliminate the use of 'struct timeval' from one of the 236 files that currently use it, to make it clearer what the remaining problems are. > > 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. As Alan Stern commented, we should probably leave the wrap point alone, and adding "% 4096000000" (actually do_div() or ktime_divns()) on a 64-bit value is more expensive than the current code, so it's probably best if Tina leaves the existing logic and just changes it to using ktime_get_ts64() for the monotonic time, as well as trying to be more explicit in the changelog about the intention. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/