[02/10] y2038: Introduce struct __timex64 - new internal glibc type

Message ID 20200426133110.5312-3-lukma@denx.de
State New
Headers show
Series
  • y2038: Convert clock_adjtime related syscalls to support 64 bit time
Related show

Commit Message

Lukasz Majewski April 26, 2020, 1:31 p.m.
The introduced glibc's 'internal' struct __timex64 is a copy of Linux kernel's
struct __kernel_timex (v5.6) introduced for properly handling data for
clock_adjtime64 syscall.
As the struct's __kernel_timex size is the same as for archs with
__WORDSIZE == 64, proper padding and data types conversion (i.e. long to long
long) had to be added for architectures with __WORDSIZE == 32 &&
__TIMESIZE != 64.

Moreover, it stores time in struct __timeval64 rather than struct
timeval, which makes it Y2038-proof.

Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
 sysdeps/unix/sysv/linux/include/sys/timex.h | 38 +++++++++++++++++++++
 1 file changed, 38 insertions(+)

-- 
2.20.1

Comments

Adhemerval Zanella via Libc-alpha April 27, 2020, 3:22 p.m. | #1
On Sun, Apr 26, 2020 at 6:31 AM Lukasz Majewski <lukma@denx.de> wrote:
>

> The introduced glibc's 'internal' struct __timex64 is a copy of Linux kernel's

> struct __kernel_timex (v5.6) introduced for properly handling data for

> clock_adjtime64 syscall.

> As the struct's __kernel_timex size is the same as for archs with

> __WORDSIZE == 64, proper padding and data types conversion (i.e. long to long

> long) had to be added for architectures with __WORDSIZE == 32 &&

> __TIMESIZE != 64.

>

> Moreover, it stores time in struct __timeval64 rather than struct

> timeval, which makes it Y2038-proof.

>

> Build tests:

> ./src/scripts/build-many-glibcs.py glibcs


Reviewed-by: Alistair Francis <alistair.francis@wdc.com>


Alistair

> ---

>  sysdeps/unix/sysv/linux/include/sys/timex.h | 38 +++++++++++++++++++++

>  1 file changed, 38 insertions(+)

>

> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h

> index 319d566608..f25081639b 100644

> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h

> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h

> @@ -25,5 +25,43 @@

>

>  libc_hidden_proto (__adjtimex)

>

> +#  include <struct___timeval64.h>

> +/* Local definition of 64 bit time supporting timex struct */

> +#  if __TIMESIZE == 64

> +#   define __timex64 timex

> +#  else

> +

> +struct __timex64

> +{

> +  unsigned int modes;          /* mode selector */

> +  int :32;                     /* pad */

> +  long long offset;            /* time offset (usec) */

> +  long long freq;              /* frequency offset (scaled ppm) */

> +  long long maxerror;          /* maximum error (usec) */

> +  long long esterror;          /* estimated error (usec) */

> +  int status;                  /* clock command/status */

> +  int :32;                     /* pad */

> +  long long constant;          /* pll time constant */

> +  long long precision;         /* clock precision (usec) (read only) */

> +  long long tolerance;         /* clock frequency tolerance (ppm) (ro) */

> +  struct __timeval64 time;     /* (read only, except for ADJ_SETOFFSET) */

> +  long long tick;              /* (modified) usecs between clock ticks */

> +  long long ppsfreq;           /* pps frequency (scaled ppm) (ro) */

> +  long long jitter;            /* pps jitter (us) (ro) */

> +  int shift;                   /* interval duration (s) (shift) (ro) */

> +  int :32;                     /* pad */

> +  long long stabil;            /* pps stability (scaled ppm) (ro) */

> +  long long jitcnt;            /* jitter limit exceeded (ro) */

> +  long long calcnt;            /* calibration intervals (ro) */

> +  long long errcnt;            /* calibration errors (ro) */

> +  long long stbcnt;            /* stability limit exceeded (ro) */

> +

> +  int tai;                     /* TAI offset (ro) */

> +

> +  int  :32; int  :32; int  :32; int  :32;

> +  int  :32; int  :32; int  :32; int  :32;

> +  int  :32; int  :32; int  :32;

> +};

> +#  endif

>  # endif /* _ISOMAC */

>  #endif /* sys/timex.h */

> --

> 2.20.1

>
Adhemerval Zanella via Libc-alpha April 28, 2020, 2:34 p.m. | #2
On 26/04/2020 10:31, Lukasz Majewski wrote:
> The introduced glibc's 'internal' struct __timex64 is a copy of Linux kernel's

> struct __kernel_timex (v5.6) introduced for properly handling data for

> clock_adjtime64 syscall.

> As the struct's __kernel_timex size is the same as for archs with

> __WORDSIZE == 64, proper padding and data types conversion (i.e. long to long

> long) had to be added for architectures with __WORDSIZE == 32 &&

> __TIMESIZE != 64.

> 

> Moreover, it stores time in struct __timeval64 rather than struct

> timeval, which makes it Y2038-proof.

> 

> Build tests:

> ./src/scripts/build-many-glibcs.py glibcs


LGTM, with just two nits about code formatting and and type specification.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>


> ---

>  sysdeps/unix/sysv/linux/include/sys/timex.h | 38 +++++++++++++++++++++

>  1 file changed, 38 insertions(+)

> 

> diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h

> index 319d566608..f25081639b 100644

> --- a/sysdeps/unix/sysv/linux/include/sys/timex.h

> +++ b/sysdeps/unix/sysv/linux/include/sys/timex.h

> @@ -25,5 +25,43 @@

>  

>  libc_hidden_proto (__adjtimex)

>  

> +#  include <struct___timeval64.h>

> +/* Local definition of 64 bit time supporting timex struct */

> +#  if __TIMESIZE == 64

> +#   define __timex64 timex

> +#  else

> +

> +struct __timex64

> +{

> +  unsigned int modes;          /* mode selector */

> +  int :32;                     /* pad */

> +  long long offset;            /* time offset (usec) */

> +  long long freq;              /* frequency offset (scaled ppm) */

> +  long long maxerror;          /* maximum error (usec) */

> +  long long esterror;          /* estimated error (usec) */

> +  int status;                  /* clock command/status */

> +  int :32;                     /* pad */

> +  long long constant;          /* pll time constant */

> +  long long precision;         /* clock precision (usec) (read only) */

> +  long long tolerance;         /* clock frequency tolerance (ppm) (ro) */

> +  struct __timeval64 time;     /* (read only, except for ADJ_SETOFFSET) */

> +  long long tick;              /* (modified) usecs between clock ticks */

> +  long long ppsfreq;           /* pps frequency (scaled ppm) (ro) */

> +  long long jitter;            /* pps jitter (us) (ro) */

> +  int shift;                   /* interval duration (s) (shift) (ro) */

> +  int :32;                     /* pad */

> +  long long stabil;            /* pps stability (scaled ppm) (ro) */

> +  long long jitcnt;            /* jitter limit exceeded (ro) */

> +  long long calcnt;            /* calibration intervals (ro) */

> +  long long errcnt;            /* calibration errors (ro) */

> +  long long stbcnt;            /* stability limit exceeded (ro) */

> +

> +  int tai;                     /* TAI offset (ro) */

> +

> +  int  :32; int  :32; int  :32; int  :32;

> +  int  :32; int  :32; int  :32; int  :32;

> +  int  :32; int  :32; int  :32;


Not sure which is the code guidelines for unnamed bit fields, indent
places one field per line:

  [...]   
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  int:32;
  [...]


> +};

> +#  endif

>  # endif /* _ISOMAC */

>  #endif /* sys/timex.h */

> 


Use 'long long int' instead of 'long long'.
Lukasz Majewski April 29, 2020, 9:45 p.m. | #3
Hi Adhemerval,

> On 26/04/2020 10:31, Lukasz Majewski wrote:

> > The introduced glibc's 'internal' struct __timex64 is a copy of

> > Linux kernel's struct __kernel_timex (v5.6) introduced for properly

> > handling data for clock_adjtime64 syscall.

> > As the struct's __kernel_timex size is the same as for archs with

> > __WORDSIZE == 64, proper padding and data types conversion (i.e.

> > long to long long) had to be added for architectures with

> > __WORDSIZE == 32 && __TIMESIZE != 64.

> > 

> > Moreover, it stores time in struct __timeval64 rather than struct

> > timeval, which makes it Y2038-proof.

> > 

> > Build tests:

> > ./src/scripts/build-many-glibcs.py glibcs  

> 

> LGTM, with just two nits about code formatting and and type

> specification.

> 

> Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 

> > ---

> >  sysdeps/unix/sysv/linux/include/sys/timex.h | 38

> > +++++++++++++++++++++ 1 file changed, 38 insertions(+)

> > 

> > diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h

> > b/sysdeps/unix/sysv/linux/include/sys/timex.h index

> > 319d566608..f25081639b 100644 ---

> > a/sysdeps/unix/sysv/linux/include/sys/timex.h +++

> > b/sysdeps/unix/sysv/linux/include/sys/timex.h @@ -25,5 +25,43 @@

> >  

> >  libc_hidden_proto (__adjtimex)

> >  

> > +#  include <struct___timeval64.h>

> > +/* Local definition of 64 bit time supporting timex struct */

> > +#  if __TIMESIZE == 64

> > +#   define __timex64 timex

> > +#  else

> > +

> > +struct __timex64

> > +{

> > +  unsigned int modes;          /* mode selector */

> > +  int :32;                     /* pad */

> > +  long long offset;            /* time offset (usec) */

> > +  long long freq;              /* frequency offset (scaled ppm) */

> > +  long long maxerror;          /* maximum error (usec) */

> > +  long long esterror;          /* estimated error (usec) */

> > +  int status;                  /* clock command/status */

> > +  int :32;                     /* pad */

> > +  long long constant;          /* pll time constant */

> > +  long long precision;         /* clock precision (usec) (read

> > only) */

> > +  long long tolerance;         /* clock frequency tolerance (ppm)

> > (ro) */

> > +  struct __timeval64 time;     /* (read only, except for

> > ADJ_SETOFFSET) */

> > +  long long tick;              /* (modified) usecs between clock

> > ticks */

> > +  long long ppsfreq;           /* pps frequency (scaled ppm) (ro)

> > */

> > +  long long jitter;            /* pps jitter (us) (ro) */

> > +  int shift;                   /* interval duration (s) (shift)

> > (ro) */

> > +  int :32;                     /* pad */

> > +  long long stabil;            /* pps stability (scaled ppm) (ro)

> > */

> > +  long long jitcnt;            /* jitter limit exceeded (ro) */

> > +  long long calcnt;            /* calibration intervals (ro) */

> > +  long long errcnt;            /* calibration errors (ro) */

> > +  long long stbcnt;            /* stability limit exceeded (ro) */

> > +

> > +  int tai;                     /* TAI offset (ro) */

> > +

> > +  int  :32; int  :32; int  :32; int  :32;

> > +  int  :32; int  :32; int  :32; int  :32;

> > +  int  :32; int  :32; int  :32;  

> 

> Not sure which is the code guidelines for unnamed bit fields, indent

> places one field per line:

> 

>   [...]   

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   int:32;

>   [...]

> 

> 

> > +};

> > +#  endif

> >  # endif /* _ISOMAC */

> >  #endif /* sys/timex.h */

> >   

> 

> Use 'long long int' instead of 'long long'.


I took the structure directly from v5.6 linux kernel - I will fix those
issues.


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

Patch

diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index 319d566608..f25081639b 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -25,5 +25,43 @@ 
 
 libc_hidden_proto (__adjtimex)
 
+#  include <struct___timeval64.h>
+/* Local definition of 64 bit time supporting timex struct */
+#  if __TIMESIZE == 64
+#   define __timex64 timex
+#  else
+
+struct __timex64
+{
+  unsigned int modes;          /* mode selector */
+  int :32;                     /* pad */
+  long long offset;            /* time offset (usec) */
+  long long freq;              /* frequency offset (scaled ppm) */
+  long long maxerror;          /* maximum error (usec) */
+  long long esterror;          /* estimated error (usec) */
+  int status;                  /* clock command/status */
+  int :32;                     /* pad */
+  long long constant;          /* pll time constant */
+  long long precision;         /* clock precision (usec) (read only) */
+  long long tolerance;         /* clock frequency tolerance (ppm) (ro) */
+  struct __timeval64 time;     /* (read only, except for ADJ_SETOFFSET) */
+  long long tick;              /* (modified) usecs between clock ticks */
+  long long ppsfreq;           /* pps frequency (scaled ppm) (ro) */
+  long long jitter;            /* pps jitter (us) (ro) */
+  int shift;                   /* interval duration (s) (shift) (ro) */
+  int :32;                     /* pad */
+  long long stabil;            /* pps stability (scaled ppm) (ro) */
+  long long jitcnt;            /* jitter limit exceeded (ro) */
+  long long calcnt;            /* calibration intervals (ro) */
+  long long errcnt;            /* calibration errors (ro) */
+  long long stbcnt;            /* stability limit exceeded (ro) */
+
+  int tai;                     /* TAI offset (ro) */
+
+  int  :32; int  :32; int  :32; int  :32;
+  int  :32; int  :32; int  :32; int  :32;
+  int  :32; int  :32; int  :32;
+};
+#  endif
 # endif /* _ISOMAC */
 #endif /* sys/timex.h */