From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93874 invoked by alias); 24 Sep 2019 15:15:35 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 93763 invoked by uid 89); 24 Sep 2019 15:15:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: smtp-out-so.shaw.ca Received: from smtp-out-so.shaw.ca (HELO smtp-out-so.shaw.ca) (64.59.136.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 24 Sep 2019 15:15:23 +0000 Received: from [192.168.1.114] ([24.64.172.44]) by shaw.ca with ESMTP id CmWzifQdEIhW9CmX0imy4Y; Tue, 24 Sep 2019 09:15:12 -0600 Reply-To: Brian.Inglis@SystematicSw.ab.ca Subject: Re: [PATCH] RTEMS: Synchronize with FreeBSD To: newlib@sourceware.org References: <20190923100708.1181-1-sebastian.huber@embedded-brains.de> <06c22742-4986-33fc-1c5b-696965c75228@SystematicSw.ab.ca> <24852e6e-096e-b214-8527-00a3636ab982@embedded-brains.de> From: Brian Inglis Openpgp: preference=signencrypt Message-ID: <7f116911-f137-a55d-9c8e-7b800efb8659@SystematicSw.ab.ca> Date: Tue, 24 Sep 2019 15:15:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <24852e6e-096e-b214-8527-00a3636ab982@embedded-brains.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019/txt/msg00573.txt.bz2 On 2019-09-23 23:55, Sebastian Huber wrote: > On 23/09/2019 22:06, Brian Inglis wrote: >> On 2019-09-23 04:07, Sebastian Huber wrote: >>> This change is based on the FreeBSD commit: >>> Author: asomers >>> Date:   Mon Jul 30 15:46:40 2018 +0000 >>> Make timespecadd(3) and friends public >>> The timespecadd(3) family of macros were imported from NetBSD back in >>> r35029. However, they were initially guarded by #ifdef _KERNEL. In the >>> meantime, we have grown at least 28 syscalls that use timespecs in some >>> way, leading many programs both inside and outside of the base system to >>> redefine those macros. It's better just to make the definitions public. >>> Our kernel currently defines two-argument versions of timespecadd and >>> timespecsub. NetBSD, OpenBSD, and FreeDesktop.org's libbsd, however, >>> define three-argument versions. Solaris also defines a three-argument >>> version, but only in its kernel. This revision changes our definition to >>> match the common three-argument version. >>> Bump _FreeBSD_version due to the breaking KPI change. >>> Discussed with: cem, jilles, ian, bde >>> Differential Revision:  https://reviews.freebsd.org/D14725 >>> --- >>>   newlib/libc/sys/rtems/include/machine/_time.h | 42 +++++++++++++++++++++++++-- >>>   1 file changed, 39 insertions(+), 3 deletions(-) >>> >>> diff --git a/newlib/libc/sys/rtems/include/machine/_time.h >>> b/newlib/libc/sys/rtems/include/machine/_time.h >>> index 13fa14afa..24e6c7398 100644 >>> --- a/newlib/libc/sys/rtems/include/machine/_time.h >>> +++ b/newlib/libc/sys/rtems/include/machine/_time.h >>> @@ -1,6 +1,9 @@ >>>   /*- >>> + * SPDX-License-Identifier: BSD-3-Clause >>> + * >>> + * Copyright (c) 1982, 1986, 1993 >>> + *    The Regents of the University of California.  All rights reserved. >>>    * Copyright (c) 2016 embedded brains GmbH >>> - * All rights reserved. >>>    * >>>    * Redistribution and use in source and binary forms, with or without >>>    * modification, are permitted provided that the following conditions >>> @@ -10,11 +13,14 @@ >>>    * 2. Redistributions in binary form must reproduce the above copyright >>>    *    notice, this list of conditions and the following disclaimer in the >>>    *    documentation and/or other materials provided with the distribution. >>> + * 3. Neither the name of the University nor the names of its contributors >>> + *    may be used to endorse or promote products derived from this software >>> + *    without specific prior written permission. >>>    * >>> - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND >>> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND >>>    * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >>>    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >>> - * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE >>> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE >>>    * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >>>    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >>>    * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >>> @@ -22,12 +28,42 @@ >>>    * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >>>    * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >>>    * SUCH DAMAGE. >>> + * >>> + *    @(#)time.h    8.5 (Berkeley) 5/4/95 >>> + * $FreeBSD: head/sys/sys/time.h 346176 2019-04-13 04:46:35Z imp $ >>>    */ >>>     #ifndef _SYS_TIME_H_ >>>   #error "must be included via " >>>   #endif /* !_SYS_TIME_H_ */ >>>   +/* Operations on timespecs */ >>> +#define    timespecclear(tvp)    ((tvp)->tv_sec = (tvp)->tv_nsec = 0) >>> +#define    timespecisset(tvp)    ((tvp)->tv_sec || (tvp)->tv_nsec) >>> +#define    timespeccmp(tvp, uvp, cmp)                \ >>> +    (((tvp)->tv_sec == (uvp)->tv_sec) ?                \ >>> +        ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :            \ >>> +        ((tvp)->tv_sec cmp (uvp)->tv_sec)) >>> + >>> +#define    timespecadd(tsp, usp, vsp)                \ >>> +    do {                                \ >>> +        (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;        \ >>> +        (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;    \ >>> +        if ((vsp)->tv_nsec >= 1000000000L) {            \ >>> +            (vsp)->tv_sec++;                \ >>> +            (vsp)->tv_nsec -= 1000000000L;            \ >>> +        }                            \ >>> +    } while (0) >>> +#define    timespecsub(tsp, usp, vsp)                \ >>> +    do {                                \ >>> +        (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec;        \ >>> +        (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec;    \ >>> +        if ((vsp)->tv_nsec < 0) {                \ >>> +            (vsp)->tv_sec--;                \ >>> +            (vsp)->tv_nsec += 1000000000L;            \ >>> +        }                            \ >>> +    } while (0) >>> + >>>   #ifdef _KERNEL >>>   /* Header file provided outside of Newlib */ >>>   #include >> >> It would be good to make this more generally available for Cygwin, RTEMS, and >> other systems, in a similar place to timeval, in >> newlib/libc/include/sys/_timespec.h. > > No, the purpose of this file is to provide only the type definitions and nothing > extra. > >> The timeval timer... macros are already defined in >> newlib/libc/include/sys/_timeval.h under the __BSD_VISIBLE feature and #if*n*def >> _KERNEL, > > That these macros are present in looks like a bug which I > produced. In FreeBSD, the macros are defined in . > >> and these timespec macros are also available under most Linux distros, >> standard on BSD. > > The timespec macros above are not included in openSUSE 15.1 and the latest glibc > Git master. On which Linux system did you see them? They appear in packages libbsd-dev on Debian, Ubuntu, ... and libbsd-devel on Centos, Fedora, openSuSE, ... installed by default on Fedora? Macros in /usr/include/bsd/sys/time.h and manpages under 3bsd in DEBs and RPMs. >> The conversion macros TIMEVAL_TO_TIMESPEC and TIMESPEC_TO_TIMEVAL are already >> available in newlib/libc/include/sys/timespec.h. >> >> All the bintime... and sbintime... facilities are already available in >> newlib/libc/include/sys/time.h guarded by __BSD_VISIBLE. >> >> As the existing facilities require _BSD_SOURCE be defined to make these public, >> should the new additions also be guarded, or the guards removed in all cases? >> >> As I reinvented those wheels just last week, not knowing about these facilities, >> could we please also make all the relevant BSD timeval...(3), timespec...(3), >> and bintime...(9) man pages available also, perhaps under newlib/libc/time/? > > I can change the patch to add these macros to under the > __BSD_VISIBLE guard if this is fine for everyone. You choose what to be compatible with or careful about. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised.