From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13067 invoked by alias); 1 Dec 2003 15:56:47 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 13045 invoked from network); 1 Dec 2003 15:56:46 -0000 Received: from unknown (HELO jaguar.mkp.net) (192.139.46.146) by sources.redhat.com with SMTP; 1 Dec 2003 15:56:46 -0000 Received: from jes by jaguar.mkp.net with local (Exim 3.35 #1) id 1AQqJX-0001FY-00; Mon, 01 Dec 2003 10:50:19 -0500 To: Ulrich Drepper Cc: davidm@hpl.hp.com, libc-hacker@sources.redhat.com Subject: Re: ia64 clock_gettime and HP_TIMING References: <16306.21333.78785.923547@gargle.gargle.HOWL> <3FB2751B.9010302@redhat.com> <3FB34B5A.2040209@redhat.com> <16308.3006.52067.235699@napali.hpl.hp.com> <3FB515DC.9010909@redhat.com> From: Jes Sorensen Date: Mon, 01 Dec 2003 15:56:00 -0000 In-Reply-To: <3FB515DC.9010909@redhat.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-12/txt/msg00001.txt.bz2 >>>>> "Ulrich" == Ulrich Drepper writes: Ulrich> Jes Sorensen wrote: >> Not knowing enough about HPET, my biggest worry is if we have to >> open up an extra file descriptor for a permanent mmap of it. Ulrich> One immediately closes the filedescriptor after the mmap call Ulrich> if this mmaped region is all that is needed. Ok, what about something like this, it makes clock_getcpuclokcid() return ENOENT if the itc drifts. I left __itc_drift_internal as a global variable as I am not sure whether clock_gettime should be change to check it as well before allowing a call for CLOCK_PROCESS_CPUTIME_ID. I still want to look into supporting the HPET and SN2 RTC at a later stage. Cheers, Jes 2003-12-01 Jes Sorensen * rt/tst-clock.c (do_test): Print message when skipping CLOCK_PROCESS_CPUTIME_ID test. * sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c: New file. Provide CLOCK_PROCESS_CPUTIME_ID only if /proc/sal/itc_drift is 0. --- libc-old/rt/tst-clock.c 6 Jul 2001 04:55:39 -0000 1.3 +++ libc-2.3/rt/tst-clock.c 1 Dec 2003 14:52:07 -0000 @@ -113,6 +113,8 @@ if (clock_getcpuclockid (0, &cl) == 0) /* XXX It's not yet a bug when this fails. */ clock_test (cl); + else + printf("CPU clock unavailble, skipping test\n"); return result; } --- /dev/null Wed Dec 31 16:00:00 1969 +++ libc-2.3/sysdeps/unix/sysv/linux/ia64/clock_getcpuclockid.c Mon Dec 1 06:21:42 2003 @@ -0,0 +1,75 @@ +/* Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + +int __itc_drift_internal; + +int +clock_getcpuclockid (pid_t pid, clockid_t *clock_id) +{ + /* We don't allow any process ID but our own. */ + if (pid != 0 && pid != getpid ()) + return EPERM; + +#ifdef CLOCK_PROCESS_CPUTIME_ID + { + int retval = ENOENT; + + if (__builtin_expect (__itc_drift_internal == 0, 0)) + { + int fd; + + fd = open ("/proc/sal/itc_drift", O_RDONLY); + if (__builtin_expect (fd != -1, 1)) + { + char buf[16]; + ssize_t n; + n = read (fd, buf, sizeof buf); + if (__builtin_expect (n, 1) > 0) + { + if (buf[0] != '0') + __itc_drift_internal = 1; + else + __itc_drift_internal = -1; + } + close (fd); + } + else + __itc_drift_internal = -1; + } + + if (__itc_drift_internal != 1) + { + /* Store the number. */ + *clock_id = CLOCK_PROCESS_CPUTIME_ID; + retval = 0; + } + + return retval; + } +#else + /* We don't have a timer for that. */ + return ENOENT; +#endif +}