From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4935 invoked by alias); 18 Apr 2004 02:02:50 -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 4784 invoked from network); 18 Apr 2004 02:02:48 -0000 Received: from unknown (HELO sunsite.ms.mff.cuni.cz) (195.113.15.26) by sources.redhat.com with SMTP; 18 Apr 2004 02:02:48 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8) with ESMTP id i3HNpIHS006136; Sun, 18 Apr 2004 01:51:18 +0200 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id i3HHbmuF027245; Sat, 17 Apr 2004 19:37:48 +0200 Date: Sun, 18 Apr 2004 02:02:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] timer fixes Message-ID: <20040417173747.GL514@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2004-04/txt/msg00050.txt.bz2 Hi! timer_gettime should never return non-zeri it_value for expired timer, but current userland emulation happily returns negative times. Also, periodic SIGEV_NONE needs to be handled for timer_settime and timer_gettime. I think it is easiest to handle it like SIGEV_SIGNAL, people don't use SIGEV_NONE timers that much anyway. Lastly, thread_attr_compare was comparing just a small subset of attributes instead of all of them, which lead to the guardsize failures of tst-timer4. 2004-04-17 Jakub Jelinek nptl/ * sysdeps/pthread/timer_gettime.c (timer_gettime): For expired timer return it_value { 0, 0 }. * sysdeps/pthread/timer_create.c (timer_create): Handle SIGEV_NONE like SIGEV_SIGNAL. * sysdeps/pthread/timer_routines.c (thread_expire_timer): Remove assertion for SIGEV_NONE. (thread_attr_compare): Compare all attributes, not just a partial subset. linuxthreads/ * sysdeps/pthread/timer_gettime.c (timer_gettime): For expired timer return it_value { 0, 0 }. * sysdeps/pthread/timer_create.c (timer_create): Handle SIGEV_NONE like SIGEV_SIGNAL. * sysdeps/pthread/timer_routines.c (thread_expire_timer): Remove assertion for SIGEV_NONE. (thread_attr_compare): Compare all attributes, not just a partial subset. --- libc/nptl/sysdeps/pthread/timer_gettime.c.jj 2002-11-26 23:50:32.000000000 +0100 +++ libc/nptl/sysdeps/pthread/timer_gettime.c 2004-04-17 21:36:03.067458418 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kaz Kylheku . @@ -54,7 +54,13 @@ timer_gettime (timerid, value) if (armed) { clock_gettime (clock, &now); - timespec_sub (&value->it_value, &expiry, &now); + if (timespec_compare (&now, &expiry) < 0) + timespec_sub (&value->it_value, &expiry, &now); + else + { + value->it_value.tv_sec = 0; + value->it_value.tv_nsec = 0; + } } else { --- libc/nptl/sysdeps/pthread/timer_create.c.jj 2003-07-29 11:30:53.000000000 +0200 +++ libc/nptl/sysdeps/pthread/timer_create.c 2004-04-17 21:35:32.216987225 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2003 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kaz Kylheku . @@ -91,9 +91,6 @@ timer_create (clock_id, evp, timerid) switch (__builtin_expect (newtimer->event.sigev_notify, SIGEV_SIGNAL)) { case SIGEV_NONE: - /* This is a strange choice! */ - break; - case SIGEV_SIGNAL: /* We have a global thread for delivering timed signals. If it is not running, try to start it up. */ --- libc/nptl/sysdeps/pthread/timer_routines.c.jj 2003-07-29 11:30:53.000000000 +0200 +++ libc/nptl/sysdeps/pthread/timer_routines.c 2004-04-17 21:38:31.504856504 +0200 @@ -1,5 +1,5 @@ /* Helper code for POSIX timer implementation on NPTL. - Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kaz Kylheku . @@ -319,7 +319,6 @@ thread_expire_timer (struct thread_node switch (__builtin_expect (timer->event.sigev_notify, SIGEV_SIGNAL)) { case SIGEV_NONE: - assert (! "timer_create should never have created such a timer"); break; case SIGEV_SIGNAL: @@ -522,7 +521,15 @@ thread_attr_compare (const pthread_attr_ return (ileft->flags == iright->flags && ileft->schedpolicy == iright->schedpolicy && (ileft->schedparam.sched_priority - == iright->schedparam.sched_priority)); + == iright->schedparam.sched_priority) + && ileft->guardsize == iright->guardsize + && ileft->stackaddr == iright->stackaddr + && ileft->stacksize == iright->stacksize + && ((ileft->cpuset == NULL && iright->cpuset == NULL) + || (ileft->cpuset != NULL && iright->cpuset != NULL + && ileft->cpusetsize == iright->cpusetsize + && memcmp (ileft->cpuset, iright->cpuset, + ileft->cpusetsize) == 0))); } --- libc/linuxthreads/sysdeps/pthread/timer_gettime.c.jj 2002-08-27 00:39:43.000000000 +0200 +++ libc/linuxthreads/sysdeps/pthread/timer_gettime.c 2004-04-17 21:33:23.985967893 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kaz Kylheku . @@ -54,7 +54,13 @@ timer_gettime (timerid, value) if (armed) { clock_gettime (clock, &now); - timespec_sub (&value->it_value, &expiry, &now); + if (timespec_compare (&now, &expiry) < 0) + timespec_sub (&value->it_value, &expiry, &now); + else + { + value->it_value.tv_sec = 0; + value->it_value.tv_nsec = 0; + } } else { --- libc/linuxthreads/sysdeps/pthread/timer_create.c.jj 2003-07-30 12:00:21.000000000 +0200 +++ libc/linuxthreads/sysdeps/pthread/timer_create.c 2004-04-17 21:33:35.791852125 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2003 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kaz Kylheku . @@ -91,9 +91,6 @@ timer_create (clock_id, evp, timerid) switch (__builtin_expect (newtimer->event.sigev_notify, SIGEV_SIGNAL)) { case SIGEV_NONE: - /* This is a strange choice! */ - break; - case SIGEV_SIGNAL: /* We have a global thread for delivering timed signals. If it is not running, try to start it up. */ --- libc/linuxthreads/sysdeps/pthread/timer_routines.c.jj 2004-04-17 20:28:39.122186062 +0200 +++ libc/linuxthreads/sysdeps/pthread/timer_routines.c 2004-04-17 21:33:48.426587815 +0200 @@ -1,5 +1,5 @@ /* Helper code for POSIX timer implementation on LinuxThreads. - Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Kaz Kylheku . @@ -318,7 +318,6 @@ thread_expire_timer (struct thread_node switch (__builtin_expect (timer->event.sigev_notify, SIGEV_SIGNAL)) { case SIGEV_NONE: - assert (! "timer_create should never have created such a timer"); break; case SIGEV_SIGNAL: @@ -517,10 +516,15 @@ thread_attr_compare (const pthread_attr_ { return (left->__detachstate == right->__detachstate && left->__schedpolicy == right->__schedpolicy + && left->__guardsize == right->__guardsize && (left->__schedparam.sched_priority == right->__schedparam.sched_priority) && left->__inheritsched == right->__inheritsched - && left->__scope == right->__scope); + && left->__scope == right->__scope + && left->__stacksize == right->__stacksize + && left->__stackaddr_set == right->__stackaddr_set + && (left->__stackaddr_set + || left->__stackaddr == right->__stackaddr)); } Jakub