From owner-freebsd-current@FreeBSD.ORG Thu Jul 9 18:33:49 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 66F3C1065670; Thu, 9 Jul 2009 18:33:49 +0000 (UTC) (envelope-from marius@nuenneri.ch) Received: from mail-bw0-f221.google.com (mail-bw0-f221.google.com [209.85.218.221]) by mx1.freebsd.org (Postfix) with ESMTP id C53368FC0C; Thu, 9 Jul 2009 18:33:48 +0000 (UTC) (envelope-from marius@nuenneri.ch) Received: by bwz21 with SMTP id 21so310962bwz.43 for ; Thu, 09 Jul 2009 11:33:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.171.1 with SMTP id y1mr590244muo.39.1247162529878; Thu, 09 Jul 2009 11:02:09 -0700 (PDT) In-Reply-To: <4A562960.3010801@freebsd.org> References: <4A562960.3010801@freebsd.org> Date: Thu, 9 Jul 2009 20:02:09 +0200 Message-ID: From: =?ISO-8859-1?Q?Marius_N=FCnnerich?= To: Andriy Gapon Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org Subject: Re: dtrace users opinion solicited (timestamps) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2009 18:33:49 -0000 On Thu, Jul 9, 2009 at 19:31, Andriy Gapon wrote: > > As you might be aware DTrace timestamps right now are derived from TSC value. > http://en.wikipedia.org/wiki/Time_Stamp_Counter > > DTrace timestamps are measured in nano-seconds and the formula similar to the > following is used for calculations: > rdtsc() * 1000000000 / tsc_freq > where rdtsc is a function that returns current TSC value and tsc_freq is a > frequency of TSC. > > This formula is supposed to produce proper results if tsc_freq stays constant. > But there are environment where this might not be the case. > If a CPU has a non-invariant TSC and processor's clock frequency changes (e.g. > because of powerd), then tsc_freq changes too. > As a result, the formula would produce wildly different values and, most > importantly, was values would non be monotonic. Timestamp values that jump back > and forth would not only be useless for a user, they would also confuse DTrace > internal logic. > > There are at least the following two alternatives: > > 1. Keep things as they are and warn users not to change CPU clock frequency when > they use DTrace and the CPU doesn't have invariant TSC. I think that this should > cause only minor inconveniences to a portion of DTrace users. > > 2. Use raw TSC value as a DTrace timestamp and document this difference from the > original DTrace. Advantage: timestamp value is always monotonic. Disadvantage: > manual conversion is needed to get "real" time (using the same formula). > Please note that in this case timestamps would be in non-linear time dimension if > TSC frequency changes, so to get meaningful timestamps (when needed/important) one > would still have to make sure that TSC frequency stay constant. > > Please share your opinion on these approaches. > Or suggest yest another alternative. What about atomically changing tsc_freq every time the frequency is changed? > > Just in case, related sysctls: > machdep.tsc_freq > kern.timecounter.invariant_tsc