From owner-freebsd-performance@FreeBSD.ORG Tue Mar 17 15:49:26 2009 Return-Path: Delivered-To: freebsd-performance@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5B265106571F for ; Tue, 17 Mar 2009 15:49:26 +0000 (UTC) (envelope-from mkotlov@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.28]) by mx1.freebsd.org (Postfix) with ESMTP id 1681B8FC13 for ; Tue, 17 Mar 2009 15:49:25 +0000 (UTC) (envelope-from mkotlov@gmail.com) Received: by yw-out-2324.google.com with SMTP id 5so30744ywh.13 for ; Tue, 17 Mar 2009 08:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=AoUVEeQPK0u3JSDlYlNdVGUyrgEUHSRd0tWoBTnIXkQ=; b=ouboiPv60AR7MTMb+I2U7HTnXFeZXuPDLg4/ORf7lChkW7/zH44AzNYhGpmv1xU97I 5O/R2xIbF3VIS1VgSU5wgT36v2HRaXJEctgL0nt+VyFx2z//aLDE17bm+bQytOLK73Dv TYu7hFCKaSWWLF5S6lFiBSXtuJ4B16h//fxYQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=dXQ5y5QQVN+63mRso8SuxtC8p9daHlUgIwtKIjTsvJk8nU8eOJNKP1BO6sDVVK3IRf ao3EHyLdnxwn0Hup4FhYS/Wj/nSMViymNONIIYBJl3aiAKoeIzgzYDkSUZAb7wKQTxv+ aegUE/KtEqADQb0ADOtej2yrE9+kl1glRYAF4= MIME-Version: 1.0 Received: by 10.231.16.129 with SMTP id o1mr62052iba.9.1237303075117; Tue, 17 Mar 2009 08:17:55 -0700 (PDT) Date: Tue, 17 Mar 2009 11:17:55 -0400 Message-ID: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com> From: Mari Kotlov To: freebsd-performance@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: sysctl with KERN_BOOTTIME option vs. gettimeofday() X-BeenThere: freebsd-performance@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Performance/tuning List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Mar 2009 15:49:27 -0000 Hi everyone, I am doing a port of C++ code from Windows to FreeBSD and need to replace function GetTickCount(), which is used mostly for the purposes of obtaining elapsed time (e.g. as a millisecond timer). As I understand it, there are two ways to do that: 1) via sysctl() function with CTL_KERN&KERN_BOOTTIME options and 2) via gettimeofday(). In both case, struct timeval is returned, so I can compute the difference between the two times and get the elapsed time. I am wondering if anyone could tell me performance implications of using sysctl() function call to obtain system boot time vs. gettimeofday(). Is one better than the other? More efficient? Are there advantages or disadvantages to using either of these two methods? Any insight would be appreciated. Thanks very much in advance, Mari. From owner-freebsd-performance@FreeBSD.ORG Tue Mar 17 17:12:54 2009 Return-Path: Delivered-To: freebsd-performance@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 33F031065677 for ; Tue, 17 Mar 2009 17:12:54 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from mx.utwente.nl (mx3.utsp.utwente.nl [130.89.2.14]) by mx1.freebsd.org (Postfix) with ESMTP id AC58D8FC24 for ; Tue, 17 Mar 2009 17:12:53 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from nox.student.utwente.nl (nox.student.utwente.nl [130.89.165.91]) by mx.utwente.nl (8.12.10/SuSE Linux 0.7) with ESMTP id n2HGqbIS030893; Tue, 17 Mar 2009 17:52:37 +0100 From: Pieter de Goeje To: freebsd-performance@freebsd.org Date: Tue, 17 Mar 2009 17:52:37 +0100 User-Agent: KMail/1.9.10 References: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com> In-Reply-To: <3edc36610903170817t7ab70c16tdeed1cb3a99e9a52@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903171752.37337.pieter@degoeje.nl> X-UTwente-MailScanner-Information: Scanned by MailScanner. Contact servicedesk@icts.utwente.nl for more information. X-UTwente-MailScanner: Found to be clean X-UTwente-MailScanner-From: pieter@degoeje.nl X-Spam-Status: No Cc: Mari Kotlov Subject: Re: sysctl with KERN_BOOTTIME option vs. gettimeofday() X-BeenThere: freebsd-performance@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Performance/tuning List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Mar 2009 17:12:56 -0000 On Tuesday 17 March 2009 16:17:55 Mari Kotlov wrote: > Hi everyone, > I am doing a port of C++ code from Windows to FreeBSD and need to > replace function GetTickCount(), which is used mostly for the purposes > of obtaining elapsed time (e.g. as a millisecond timer). As I > understand it, there are two ways to do that: 1) via sysctl() function > with CTL_KERN&KERN_BOOTTIME options and 2) via gettimeofday(). In both > case, struct timeval is returned, so I can compute the difference > between the two times and get the elapsed time. > > I am wondering if anyone could tell me performance implications of > using sysctl() function call to obtain system boot time vs. > gettimeofday(). Is one better than the other? More efficient? Are > there advantages or disadvantages to using either of these two > methods? Any insight would be appreciated. > > Thanks very much in advance, > Mari. For the purpose of determining the elapsed time between two measurements, I can recommend clock_gettime(2) w/ CLOCK_MONOTONIC as clock_id. Sysctl is definately not meant to be used for this, as it is not portable and has probably more overhead than clock_gettime() or gettimeofday(). - Pieter