[PATCH 0/4] Synchronize <sys/time.h>, etc. with FreeBSD

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/4] Synchronize <sys/time.h>, etc. with FreeBSD

Sebastian Huber-4
Sebastian Huber (3):
  Synchronize <sys/_timespec.h> with FreeBSD
  Synchronize <sys/time.h> with FreeBSD
  Move timeval macros to <sys/time.h>

imp (1):
  Fix sbttons for values > 2s

 newlib/libc/include/sys/_timespec.h |  6 ++--
 newlib/libc/include/sys/_timeval.h  | 35 ++------------------
 newlib/libc/include/sys/time.h      | 66 +++++++++++++++++++++++++++++++++++--
 3 files changed, 71 insertions(+), 36 deletions(-)

--
2.16.4

Reply | Threaded
Open this post in threaded view
|

[PATCH 1/4] Fix sbttons for values > 2s

Sebastian Huber-4
From: imp <[hidden email]>

Add test against negative times. Add code to cope with larger values
properly.

Discussed with: bde@ (quite some time ago, for an earlier version)
---
 newlib/libc/include/sys/time.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/time.h b/newlib/libc/include/sys/time.h
index c760adfbd..103f56660 100644
--- a/newlib/libc/include/sys/time.h
+++ b/newlib/libc/include/sys/time.h
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  *
  * @(#)time.h 8.5 (Berkeley) 5/4/95
- * $FreeBSD: head/sys/sys/time.h 340664 2018-11-20 07:11:23Z imp $
+ * $FreeBSD: head/sys/sys/time.h 346176 2019-04-13 04:46:35Z imp $
  */
 
 #ifndef _SYS_TIME_H_
@@ -191,8 +191,15 @@ sbttobt(sbintime_t _sbt)
 static __inline int64_t
 sbttons(sbintime_t _sbt)
 {
+ uint64_t ns;
 
- return ((1000000000 * _sbt) >> 32);
+ ns = _sbt;
+ if (ns >= SBT_1S)
+ ns = (ns >> 32) * 1000000000;
+ else
+ ns = 0;
+
+ return (ns + (1000000000 * (_sbt & 0xffffffffu) >> 32));
 }
 
 static __inline sbintime_t
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

[PATCH 2/4] Synchronize <sys/_timespec.h> with FreeBSD

Sebastian Huber-4
In reply to this post by Sebastian Huber-4
---
 newlib/libc/include/sys/_timespec.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/include/sys/_timespec.h b/newlib/libc/include/sys/_timespec.h
index 7609e4a46..f810b008f 100644
--- a/newlib/libc/include/sys/_timespec.h
+++ b/newlib/libc/include/sys/_timespec.h
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1982, 1986, 1993
  * The Regents of the University of California.  All rights reserved.
  *
@@ -10,7 +12,7 @@
  * 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.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
  *
@@ -28,7 +30,7 @@
  *
  * @(#)time.h 8.5 (Berkeley) 5/4/95
  * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp
- * $FreeBSD$
+ * $FreeBSD: head/sys/sys/_timespec.h 326023 2017-11-20 19:43:44Z pfg $
  */
 
 #ifndef _SYS__TIMESPEC_H_
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

[PATCH 3/4] Synchronize <sys/time.h> with FreeBSD

Sebastian Huber-4
In reply to this post by Sebastian Huber-4
This change is based on the FreeBSD commit:

Author: asomers <[hidden email]>
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/include/sys/time.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/newlib/libc/include/sys/time.h b/newlib/libc/include/sys/time.h
index 103f56660..370c13406 100644
--- a/newlib/libc/include/sys/time.h
+++ b/newlib/libc/include/sys/time.h
@@ -340,6 +340,33 @@ tvtosbt(struct timeval _tv)
 
  return (((sbintime_t)_tv.tv_sec << 32) + ustosbt(_tv.tv_usec));
 }
+
+/* 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)
 #endif /* __BSD_VISIBLE */
 
 /*
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

[PATCH 4/4] Move timeval macros to <sys/time.h>

Sebastian Huber-4
In reply to this post by Sebastian Huber-4
In FreeBSD, NetBSD, and OpenBSD these macros are defined in
<sys/time.h>.
---
 newlib/libc/include/sys/_timeval.h | 35 +++--------------------------------
 newlib/libc/include/sys/time.h     | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/newlib/libc/include/sys/_timeval.h b/newlib/libc/include/sys/_timeval.h
index 676a0b894..6b250c0d0 100644
--- a/newlib/libc/include/sys/_timeval.h
+++ b/newlib/libc/include/sys/_timeval.h
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
  * Copyright (c) 2002 Mike Barcroft <[hidden email]>
  * All rights reserved.
  *
@@ -23,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/sys/_timeval.h 326256 2017-11-27 15:01:59Z pfg $
  */
 
 #ifndef _SYS__TIMEVAL_H_
@@ -53,37 +55,6 @@ struct timeval {
  time_t tv_sec; /* seconds */
  suseconds_t tv_usec; /* and microseconds */
 };
-
-#if __BSD_VISIBLE
-#ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */
-
-#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
-#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
-#define timercmp(tvp, uvp, cmp) \
- (((tvp)->tv_sec == (uvp)->tv_sec) ? \
-    ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
-    ((tvp)->tv_sec cmp (uvp)->tv_sec))
-#define timeradd(tvp, uvp, vvp) \
- do { \
- (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
- (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
- if ((vvp)->tv_usec >= 1000000) { \
- (vvp)->tv_sec++; \
- (vvp)->tv_usec -= 1000000; \
- } \
- } while (0)
-#define timersub(tvp, uvp, vvp) \
- do { \
- (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
- (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
- if ((vvp)->tv_usec < 0) { \
- (vvp)->tv_sec--; \
- (vvp)->tv_usec += 1000000; \
- } \
- } while (0)
-#endif
-#endif /* __BSD_VISIBLE */
-
 #endif /* _TIMEVAL_DEFINED */
 
 #endif /* !_SYS__TIMEVAL_H_ */
diff --git a/newlib/libc/include/sys/time.h b/newlib/libc/include/sys/time.h
index 370c13406..84a429bf2 100644
--- a/newlib/libc/include/sys/time.h
+++ b/newlib/libc/include/sys/time.h
@@ -367,6 +367,34 @@ tvtosbt(struct timeval _tv)
  (vsp)->tv_nsec += 1000000000L; \
  } \
  } while (0)
+
+#ifndef _KERNEL /* NetBSD/OpenBSD compatible interfaces */
+
+#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
+#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
+#define timercmp(tvp, uvp, cmp) \
+ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
+    ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
+    ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#define timeradd(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
+ if ((vvp)->tv_usec >= 1000000) { \
+ (vvp)->tv_sec++; \
+ (vvp)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+#define timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (0)
+#endif
 #endif /* __BSD_VISIBLE */
 
 /*
--
2.16.4

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/4] Synchronize <sys/time.h>, etc. with FreeBSD

Sebastian Huber-4
In reply to this post by Sebastian Huber-4
Ping.

On 24/09/2019 09:00, Sebastian Huber wrote:

> Sebastian Huber (3):
>    Synchronize <sys/_timespec.h> with FreeBSD
>    Synchronize <sys/time.h> with FreeBSD
>    Move timeval macros to <sys/time.h>
>
> imp (1):
>    Fix sbttons for values > 2s
>
>   newlib/libc/include/sys/_timespec.h |  6 ++--
>   newlib/libc/include/sys/_timeval.h  | 35 ++------------------
>   newlib/libc/include/sys/time.h      | 66 +++++++++++++++++++++++++++++++++++--
>   3 files changed, 71 insertions(+), 36 deletions(-)
>

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : [hidden email]
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/4] Synchronize <sys/time.h>, etc. with FreeBSD

Sebastian Huber-4
Would someone mind having a look at this. I would like to build a new
set of RTEMS tools after the Newlib update.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : [hidden email]
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 0/4] Synchronize <sys/time.h>, etc. with FreeBSD

Corinna Vinschen
In reply to this post by Sebastian Huber-4
On Sep 24 09:00, Sebastian Huber wrote:

> Sebastian Huber (3):
>   Synchronize <sys/_timespec.h> with FreeBSD
>   Synchronize <sys/time.h> with FreeBSD
>   Move timeval macros to <sys/time.h>
>
> imp (1):
>   Fix sbttons for values > 2s
>
>  newlib/libc/include/sys/_timespec.h |  6 ++--
>  newlib/libc/include/sys/_timeval.h  | 35 ++------------------
>  newlib/libc/include/sys/time.h      | 66 +++++++++++++++++++++++++++++++++++--
>  3 files changed, 71 insertions(+), 36 deletions(-)
>
> --
> 2.16.4
Looks good, please push.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer
Red Hat

signature.asc (849 bytes) Download Attachment