From owner-freebsd-hackers Mon Dec 23 3:18:30 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AABE437B401 for ; Mon, 23 Dec 2002 03:18:26 -0800 (PST) Received: from heaven.gigo.com (heaven.gigo.com [64.57.102.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B54843EDA for ; Mon, 23 Dec 2002 03:18:26 -0800 (PST) (envelope-from lioux@brturbo.com) Received: from 200-163-006-237.bsace7003.dsl.brasiltelecom.net.br (200-163-006-237.bsace7003.dsl.brasiltelecom.net.br [200.163.6.237]) by heaven.gigo.com (Postfix) with ESMTP id EED60B8C2 for ; Mon, 23 Dec 2002 03:17:55 -0800 (PST) Received: (qmail 2849 invoked by uid 1001); 23 Dec 2002 11:04:26 -0000 Message-ID: <20021223110426.2848.qmail@exxodus.fedaykin.here> Date: Mon, 23 Dec 2002 09:04:04 -0200 From: Mario Sergio Fujikawa Ferreira To: FreeBSD-hackers@FreeBSD.org Cc: Garrett Wollman Subject: Timing with clock_gettime(2) (sysutils/clockspeed port) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline User-Agent: Mutt/1.4i X-Operating-System: FreeBSD 4.7-STABLE X-Disclaimer: I hope you find what you are looking for... in life :) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, clockspeed is a port that "Uses a hardware tick counter to compensate for deviant system clock". From pkg-descr: "clockspeed uses a hardware tick counter to compensate for a persistently fast or slow system clock. Given a few time measurements from a reliable source, it computes and then eliminates the clock skew. "sntpclock checks another system's NTP clock, and prints the results in a format suitable for input to clockspeed. sntpclock is the simplest available NTP/SNTP client. "taiclock and taiclockd form an even simpler alternative to SNTP. They are suitable for precise time synchronization over a local area network, without the hassles and potential security problems of an NTP server. "This version of clockspeed can use the Pentium RDTSC tick counter or the Solaris gethrtime() nanosecond counter." Well, as you can see this port will not work without RDTSC which means that it will not work in either alpha or sparc64 ARCHes. We do not have gethrtime() but we have clock_gettime(2) as suggested by Garret Wollman. I did cook a small test program to find out how would I would use clock_gettime(2) to achieve an output similar to that of RDTSC. I am using an idea taken from tar sources ((x)->t.tv_sec - (y)->t.tv_sec) + \ ((x)->t.tv_nsec - (y)->t.tv_nsec) * 4294967296.0 / 1e9) That's where the * 4294967296.0 / 1e9 came from. However, my timing with clock_gettime() does not sufficiently resembles that of RDTSC. I need a closer value. I'm getting big differences as shown below. Ideas? This will help us get yet another port under both alpha and sparc64. :) My timing test code is attached. Regards, [exxodus:lioux:75]./timing RDTSC Avg getpid() time = 4647397804253831496 nsec clock_gettime() Avg getpid() time = 4652939263933680218 nsec [exxodus:lioux:76]./timing RDTSC Avg getpid() time = 4647692649291935908 nsec clock_gettime() Avg getpid() time = 4652939075039020903 nsec [exxodus:lioux:77]./timing RDTSC Avg getpid() time = 4647378628771043082 nsec clock_gettime() Avg getpid() time = 4652939075039020903 nsec [exxodus:lioux:78]./timing RDTSC Avg getpid() time = 4647343972164535583 nsec clock_gettime() Avg getpid() time = 4652939263933680218 nsec [exxodus:lioux:79]./timing RDTSC Avg getpid() time = 4655770321416555069 nsec clock_gettime() Avg getpid() time = 4652939075039020903 nsec [exxodus:lioux:80]./timing RDTSC Avg getpid() time = 4647110875699447071 nsec clock_gettime() Avg getpid() time = 4652780781314515112 nsec [exxodus:lioux:81]./timing RDTSC Avg getpid() time = 4647597475565435617 nsec clock_gettime() Avg getpid() time = 4652939263933680218 nsec [exxodus:lioux:82]./timing RDTSC Avg getpid() time = 4647755189513323807 nsec clock_gettime() Avg getpid() time = 4653097557658186008 nsec [exxodus:lioux:83]./timing RDTSC Avg getpid() time = 4647490163230564680 nsec clock_gettime() Avg getpid() time = 4652939075039020903 nsec -- Mario S F Ferreira - DF - Brazil - "I guess this is a signature." Computer Science Undergraduate | FreeBSD Committer | CS Developer flames to beloved devnull@someotherworldbeloworabove.org feature, n: a documented bug | bug, n: an undocumented feature --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="timing.c" #include #include #include #include void main(void) { int i,iters = 100; { typedef struct { unsigned long t[2]; } timing; #define timing_now(x) asm volatile(".byte 15;.byte 49" : "=a"((x)->t[0]),"=d"((x)->t[1])) #define timing_diff(x,y) (((x)->t[0] - (double) (y)->t[0]) + 4294967296.0 * ((x)->t[1] - (double) (y)->t[1])) timing start,end; timing_now(&start); for (i = 0; i < iters; i++) getpid(); timing_now(&end); printf("RDTSC\n"); printf("Avg getpid() time = %lld nsec\n", timing_diff(&end,&start)/iters); } { typedef struct { struct timespec t; } timingi; #define timing_nowi(x) ((void) clock_gettime(CLOCK_REALTIME, &((x)->t))) #define timing_diffi(x,y) \ ( \ (double) ( ((x)->t.tv_sec - (y)->t.tv_sec) + \ (double) ( \ ((x)->t.tv_nsec - (double) (y)->t.tv_nsec) * 4294967296.0 / 1e9 \ ) \ ) \ ) timingi start,end; timing_nowi(&start); for (i = 0; i < iters; i++) getpid(); timing_nowi(&end); printf("clock_gettime()\n"); printf("Avg getpid() time = %lld nsec\n", timing_diffi(&end,&start)/iters); } } --vtzGhvizbBRQ85DL-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message