În 19 iunie 2020 23:37:28 EEST, Mark Kettenis <mark.kette...@xs4all.nl> a scris:
>> Date: Fri, 19 Jun 2020 23:16:26 +0300
>> From: Paul Irofti <p...@irofti.net>
>> 
>> În 19 iunie 2020 22:49:32 EEST, Mark Kettenis
><mark.kette...@xs4all.nl> a scris:
>> >> Date: Fri, 19 Jun 2020 20:28:58 +0300
>> >> From: Paul Irofti <p...@irofti.net>
>> >> 
>> >> On Fri, Jun 19, 2020 at 06:52:40PM +0200, Mark Kettenis wrote:
>> >> > > Date: Fri, 19 Jun 2020 14:31:17 +0300
>> >> > > From: Paul Irofti <p...@irofti.net>
>> >> > > 
>> >> > > Hi,
>> >> > > 
>> >> > > Here is another iteration of the diff that addresses all
>issues
>> >raised
>> >> > > in the meantime:
>> >> > > 
>> >> > >   - Switch tc to uint
>> >> > 
>> >> > The request was to use u_int, like we de in the kernel.  The
>uint
>> >type
>> >> > should not be used in OpenBSD code.
>> >> > 
>> >> > >   - Check for version at init and switch to machite/timetc.h
>defs
>> >> > >   - Remove tk_nclocks
>> >> > >   - Switch to single version and ditch minor/major
>> >> > >   - Do not enable user TSC for large skew values
>> >> > >   - Add amd64 clocks and use the define in TSC
>> >> > >   - Include and add machine/timetc.h
>> >> > > 
>> >> > > As we have seen most architectures have support for clocks now
>> >and the
>> >> > > above addresses Mark's last concerns. 
>> >> > > 
>> >> > > Unless other blocking issues arise, this time around I am
>looking
>> >for
>> >> > > OKs to commit. Theo? Mark?
>> >> > 
>> >> > There is one other issue that I wanted to raise.  An that is
>> >whether
>> >> > we really need to implement CLOCK_UPTINME as a userland clock. 
>If
>> >we
>> >> > don't do that we can drop tk_naptime from the shared struct.  I
>> >> > mention this because th_naptime was only recently added to
>struct
>> >> > timehands and much more an implementation detail than the other
>> >fields.
>> >> > 
>> >> > I don't expect userland processes to call CLOCK_UPTIME in a loop
>> >like
>> >> > they tend to do do for CLOCK_MONOTONIC and CLOCK_REALTIME. 
>Linux
>> >> > doesn't have it ;).
>> >> 
>> >> I don't care eitherway about this. But I don't see why we would
>not
>> >have
>> >> this functionality if it is easy to offer. Maybe someone can help
>us
>> >> grep the ports tree for this? Stuart? :)
>> >> 
>> >> > We're getting there...
>> >> 
>> >> I have addressed your comments bellow, except for the CPU skew
>one.
>> >That
>> >> code disables TSC for all CPUs, not just for PRIMARY. Would you
>like
>> >to
>> >> walk and add code for every CPU to check the drift and then
>disable
>> >the
>> >> TSC? It seems a little too much...
>> >
>> >Still uses uint instead of u_int in places. 
>> 
>> Ok. I will check that again.
>> 
>> > Still has the pointless
>> >extra NULL and 0 for timecounters in files that are otherwise
>> 
>> I am not fixing that. If there's a null present before my diff, then
>> there can be a 0 afterwards. If anything my diff unifies this. This
>> is silly.
>
>I'll let others judge that.
>
>> >And regarding the TSC.  That issue is a show-stopper.  We can
>tolerate
>> >a small amout of skew, but not a large amount.  Because otherwise a
>> >multithreaded process might observe time going backwards.
>> 
>> I don't see how this is still an issue with my diff, which is what I
>> said last time. I am stopping the TSC when the drift is larger than
>> a random value that I defined a year ago. What more is needed? Can
>> you describe in more details?
>
>I'm talking about *skew*, not drift.  If there is a significant drift
>you already knock out the TSC.
>
>What's needed is:
>
>1. A bit of research of what an acceptable skew is.  My hypothesis is
>   that on many machines with a single socket the TSCs are actually in
>   synch.  But the way we measure the skew isn't 100% accurate so we
>   still get a small skew.  If we sample these values on a couple of
>   machines across a couple of reboots we can probably tell what the
>   uncertainty in the measurement of the skew is and define a cutoff
>   based on that.
>
>2. When the absolute value of ci->ci_tsc_skew is above this cutoff for
>   any CPU, you set tsc_timecounter.tc_user to zero.  I think you can
>   do that check in tsc_timecounter_init() but I'm not 100% sure.
>

Ok. I understand. I will not do that. If somebody wants to,  please let us know 
and continue this discussion with Kettenis until he is satisfied.

If the consensus is that this is a blocking issue and nobody wants to step up 
and do it, then consider the diff abandoned. 

>
>> >> diff --git lib/libc/arch/aarch64/gen/Makefile.inc
>> >lib/libc/arch/aarch64/gen/Makefile.inc
>> >> index a7b1b73f3ef..ee198f5d611 100644
>> >> --- lib/libc/arch/aarch64/gen/Makefile.inc
>> >> +++ lib/libc/arch/aarch64/gen/Makefile.inc
>> >> @@ -9,4 +9,4 @@ SRCS+=    fpgetmask.c fpgetround.c fpgetsticky.c
>> >>  SRCS+=   fpsetmask.c fpsetround.c fpsetsticky.c
>> >>  SRCS+=   fpclassifyl.c
>> >>  SRCS+=   isfinitel.c isinfl.c isnanl.c isnormall.c
>> >> -SRCS+=   signbitl.c
>> >> +SRCS+=   signbitl.c usertc.c
>> >> diff --git lib/libc/arch/aarch64/gen/usertc.c
>> >lib/libc/arch/aarch64/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/aarch64/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/alpha/gen/Makefile.inc
>> >lib/libc/arch/alpha/gen/Makefile.inc
>> >> index a44599d2cab..2a8abd32b61 100644
>> >> --- lib/libc/arch/alpha/gen/Makefile.inc
>> >> +++ lib/libc/arch/alpha/gen/Makefile.inc
>> >> @@ -3,5 +3,5 @@
>> >>  
>> >>  SRCS+=   _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c setjmp.S
>> >>  SRCS+=   flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c
>> >fpsetmask.c \
>> >> - fpsetround.c fpsetsticky.c
>> >> + fpsetround.c fpsetsticky.c usertc.c
>> >>  SRCS+=   sigsetjmp.S
>> >> diff --git lib/libc/arch/alpha/gen/usertc.c
>> >lib/libc/arch/alpha/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/alpha/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/amd64/gen/Makefile.inc
>> >lib/libc/arch/amd64/gen/Makefile.inc
>> >> index e995309ed71..f6349e2b974 100644
>> >> --- lib/libc/arch/amd64/gen/Makefile.inc
>> >> +++ lib/libc/arch/amd64/gen/Makefile.inc
>> >> @@ -2,6 +2,7 @@
>> >>  
>> >>  SRCS+=   _setjmp.S fabs.S infinity.c ldexp.c modf.S nan.c setjmp.S
>\
>> >>   sigsetjmp.S
>> >> -SRCS+=   fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c
>> >signbitl.c
>> >> +SRCS+=   fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c
>> >signbitl.c \
>> >> + usertc.c
>> >>  SRCS+=   flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S
>> >fpsetmask.S \
>> >>   fpsetround.S fpsetsticky.S
>> >> diff --git lib/libc/arch/amd64/gen/usertc.c
>> >lib/libc/arch/amd64/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..742fb0cc458
>> >> --- /dev/null
>> >> +++ lib/libc/arch/amd64/gen/usertc.c
>> >> @@ -0,0 +1,41 @@
>> >> +/*       $OpenBSD$ */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +static inline uint
>> >> +rdtsc(void)
>> >> +{
>> >> + uint32_t hi, lo;
>> >> + asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
>> >> + return ((uint64_t)lo)|(((uint64_t)hi)<<32);
>> >> +}
>> >> +
>> >> +int
>> >> +tc_get_timecount(struct timekeep *tk, u_int *tc)
>> >> +{
>> >> + int tk_user = tk->tk_user;
>> >> +
>> >> + if (tk_user < 1 || tk_user >= TC_LAST)
>> >> +         return -1;
>> >> +
>> >> + *tc = rdtsc();
>> >> + return 0;
>> >> +}
>> >> +int (*const _tc_get_timecount)(struct timekeep *tk, u_int *tc)
>> >> + = tc_get_timecount;
>> >> diff --git lib/libc/arch/arm/gen/Makefile.inc
>> >lib/libc/arch/arm/gen/Makefile.inc
>> >> index 1b4ab2f3ae7..27090a0d9dc 100644
>> >> --- lib/libc/arch/arm/gen/Makefile.inc
>> >> +++ lib/libc/arch/arm/gen/Makefile.inc
>> >> @@ -2,5 +2,5 @@
>> >>  # $NetBSD: Makefile.inc,v 1.6 2003/08/01 17:03:47 lukem Exp $
>> >>  
>> >>  SRCS+=   byte_swap_2.S byte_swap_4.S divsi3.S fabs.c flt_rounds.c
>> >infinity.c
>> >> -SRCS+=   ldexp.c modf.c nan.c
>> >> +SRCS+=   ldexp.c modf.c nan.c usertc.c
>> >>  SRCS+=   setjmp.S _setjmp.S sigsetjmp.S
>> >> diff --git lib/libc/arch/arm/gen/usertc.c
>> >lib/libc/arch/arm/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/arm/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/hppa/gen/Makefile.inc
>> >lib/libc/arch/hppa/gen/Makefile.inc
>> >> index e0c864242fe..1fde24670f1 100644
>> >> --- lib/libc/arch/hppa/gen/Makefile.inc
>> >> +++ lib/libc/arch/hppa/gen/Makefile.inc
>> >> @@ -2,6 +2,6 @@
>> >>  
>> >>  SRCS+=   setjmp.S
>> >>  SRCS+=   fabs.c
>> >> -SRCS+=   infinity.c ldexp.c modf.c nan.c
>> >> +SRCS+=   infinity.c ldexp.c modf.c nan.c usertc.c
>> >>  SRCS+=   flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c
>> >fpsetmask.c \
>> >>   fpsetround.c fpsetsticky.c
>> >> diff --git lib/libc/arch/hppa/gen/usertc.c
>> >lib/libc/arch/hppa/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/hppa/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/i386/gen/Makefile.inc
>> >lib/libc/arch/i386/gen/Makefile.inc
>> >> index 4c18e059581..b7dd30adccd 100644
>> >> --- lib/libc/arch/i386/gen/Makefile.inc
>> >> +++ lib/libc/arch/i386/gen/Makefile.inc
>> >> @@ -1,6 +1,6 @@
>> >>  #        $OpenBSD: Makefile.inc,v 1.14 2012/04/19 19:14:56 deraadt Exp $
>> >>  
>> >> -SRCS+=   _setjmp.S fabs.S infinity.c ldexp.c \
>> >> +SRCS+=   _setjmp.S fabs.S infinity.c ldexp.c usertc.c \
>> >>   modf.S nan.c setjmp.S sigsetjmp.S
>> >>  SRCS+=   fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c
>> >signbitl.c
>> >>  SRCS+=   flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S
>> >fpsetmask.S \
>> >> diff --git lib/libc/arch/i386/gen/usertc.c
>> >lib/libc/arch/i386/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/i386/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/m88k/gen/Makefile.inc
>> >lib/libc/arch/m88k/gen/Makefile.inc
>> >> index cff75b8d425..d66f66af4af 100644
>> >> --- lib/libc/arch/m88k/gen/Makefile.inc
>> >> +++ lib/libc/arch/m88k/gen/Makefile.inc
>> >> @@ -1,7 +1,7 @@
>> >>  #        $OpenBSD: Makefile.inc,v 1.16 2013/06/05 22:06:30 miod Exp $
>> >>  #        $NetBSD: Makefile.inc,v 1.3 1995/04/10 21:09:06 jtc Exp $
>> >>  
>> >> -SRCS+=   _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c
>> >> +SRCS+=   _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c usertc.c
>> >>  SRCS+=   flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c
>> >fpsetmask.c \
>> >>   fpsetround.c fpsetsticky.c
>> >>  SRCS+=   setjmp.S sigsetjmp.S
>> >> diff --git lib/libc/arch/m88k/gen/usertc.c
>> >lib/libc/arch/m88k/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/m88k/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/mips64/gen/Makefile.inc
>> >lib/libc/arch/mips64/gen/Makefile.inc
>> >> index 8cf1fc2d28a..839241a2069 100644
>> >> --- lib/libc/arch/mips64/gen/Makefile.inc
>> >> +++ lib/libc/arch/mips64/gen/Makefile.inc
>> >> @@ -1,6 +1,6 @@
>> >>  #        $OpenBSD: Makefile.inc,v 1.12 2012/04/12 16:14:09 deraadt Exp $
>> >>  
>> >> -SRCS+=   _setjmp.S fabs.S infinity.c ldexp.S modf.S nan.c
>> >> +SRCS+=   _setjmp.S fabs.S infinity.c ldexp.S modf.S nan.c usertc.c
>> >>  SRCS+=   flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c
>> >fpsetmask.c \
>> >>   fpsetround.c fpsetsticky.c
>> >>  SRCS+=   fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c
>> >signbitl.c
>> >> diff --git lib/libc/arch/mips64/gen/usertc.c
>> >lib/libc/arch/mips64/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/mips64/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/powerpc/gen/Makefile.inc
>> >lib/libc/arch/powerpc/gen/Makefile.inc
>> >> index 6b2e4613ee8..d4d7b00bff7 100644
>> >> --- lib/libc/arch/powerpc/gen/Makefile.inc
>> >> +++ lib/libc/arch/powerpc/gen/Makefile.inc
>> >> @@ -1,5 +1,5 @@
>> >>  SRCS+= infinity.c setjmp.S sigsetjmp.S flt_rounds.c ldexp.c
>modf.c
>> >nan.c
>> >> -SRCS+= fabs.c
>> >> +SRCS+= fabs.c usertc.c
>> >>  SRCS+= fpgetmask.c fpsetmask.c
>> >>  SRCS+= fpgetround.c fpsetround.c
>> >>  SRCS+= fpgetsticky.c fpsetsticky.c
>> >> diff --git lib/libc/arch/powerpc/gen/usertc.c
>> >lib/libc/arch/powerpc/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/powerpc/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/sh/gen/Makefile.inc
>> >lib/libc/arch/sh/gen/Makefile.inc
>> >> index 55de1973b30..4724fb3a6a8 100644
>> >> --- lib/libc/arch/sh/gen/Makefile.inc
>> >> +++ lib/libc/arch/sh/gen/Makefile.inc
>> >> @@ -3,4 +3,4 @@
>> >>  SRCS+= flt_rounds.c infinity.c ldexp.c modf.c nan.c setjmp.S
>> >_setjmp.S
>> >>  SRCS+= sigsetjmp.S
>> >>  SRCS+=   fabs.c fpgetmask.c fpgetround.c fpgetsticky.c \
>> >> - fpsetmask.c fpsetround.c fpsetsticky.c
>> >> + fpsetmask.c fpsetround.c fpsetsticky.c usertc.c
>> >> diff --git lib/libc/arch/sh/gen/usertc.c
>> >lib/libc/arch/sh/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/sh/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/arch/sparc64/gen/Makefile.inc
>> >lib/libc/arch/sparc64/gen/Makefile.inc
>> >> index 58259cedef6..a908e022954 100644
>> >> --- lib/libc/arch/sparc64/gen/Makefile.inc
>> >> +++ lib/libc/arch/sparc64/gen/Makefile.inc
>> >> @@ -3,5 +3,5 @@
>> >>  SRCS+=   _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpclassifyl.c \
>> >>   fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
>> >>   fpsetround.c fpsetsticky.c infinity.c isfinitel.c \
>> >> - isinfl.c isnanl.c isnormall.c ldexp.c modf.S \
>> >> + isinfl.c isnanl.c isnormall.c ldexp.c usertc.c modf.S \
>> >>   mul.S nan.c setjmp.S signbitl.c sigsetjmp.S umul.S
>> >> diff --git lib/libc/arch/sparc64/gen/usertc.c
>> >lib/libc/arch/sparc64/gen/usertc.c
>> >> new file mode 100644
>> >> index 00000000000..6551854a010
>> >> --- /dev/null
>> >> +++ lib/libc/arch/sparc64/gen/usertc.c
>> >> @@ -0,0 +1,21 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >> + */
>> >> +
>> >> +#include <sys/types.h>
>> >> +#include <sys/timetc.h>
>> >> +
>> >> +int (*const _tc_get_timecount)(struct timekeep *, u_int *) =
>NULL;
>> >> diff --git lib/libc/asr/asr.c lib/libc/asr/asr.c
>> >> index 131da4b2190..40e84771f86 100644
>> >> --- lib/libc/asr/asr.c
>> >> +++ lib/libc/asr/asr.c
>> >> @@ -198,11 +198,11 @@ poll_intrsafe(struct pollfd *fds, nfds_t
>nfds,
>> >int timeout)
>> >>   struct timespec pollstart, pollend, elapsed;
>> >>   int r;
>> >>  
>> >> - if (clock_gettime(CLOCK_MONOTONIC, &pollstart))
>> >> + if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &pollstart))
>> >>           return -1;
>> >>  
>> >>   while ((r = poll(fds, 1, timeout)) == -1 && errno == EINTR) {
>> >> -         if (clock_gettime(CLOCK_MONOTONIC, &pollend))
>> >> +         if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &pollend))
>> >>                   return -1;
>> >>           timespecsub(&pollend, &pollstart, &elapsed);
>> >>           timeout -= elapsed.tv_sec * 1000 + elapsed.tv_nsec / 1000000;
>> >> @@ -420,7 +420,7 @@ asr_check_reload(struct asr *asr)
>> >>           asr->a_rtime = 0;
>> >>   }
>> >>  
>> >> - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
>> >> + if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts) == -1)
>> >>           return;
>> >>  
>> >>   if ((ts.tv_sec - asr->a_rtime) < RELOAD_DELAY && asr->a_rtime !=
>0)
>> >> diff --git lib/libc/crypt/bcrypt.c lib/libc/crypt/bcrypt.c
>> >> index 82de8fa33b7..02fd3013cc1 100644
>> >> --- lib/libc/crypt/bcrypt.c
>> >> +++ lib/libc/crypt/bcrypt.c
>> >> @@ -248,9 +248,9 @@ _bcrypt_autorounds(void)
>> >>   char buf[_PASSWORD_LEN];
>> >>   int duration;
>> >>  
>> >> - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &before);
>> >> + WRAP(clock_gettime)(CLOCK_THREAD_CPUTIME_ID, &before);
>> >>   bcrypt_newhash("testpassword", r, buf, sizeof(buf));
>> >> - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &after);
>> >> + WRAP(clock_gettime)(CLOCK_THREAD_CPUTIME_ID, &after);
>> >>  
>> >>   duration = after.tv_sec - before.tv_sec;
>> >>   duration *= 1000000;
>> >> diff --git lib/libc/dlfcn/init.c lib/libc/dlfcn/init.c
>> >> index 270f54aada5..d2632455f11 100644
>> >> --- lib/libc/dlfcn/init.c
>> >> +++ lib/libc/dlfcn/init.c
>> >> @@ -20,6 +20,7 @@
>> >>  
>> >>  #include <sys/types.h>
>> >>  #include <sys/syscall.h>
>> >> +#include <sys/timetc.h>          /* timekeep */
>> >>  
>> >>  #ifndef PIC
>> >>  #include <sys/mman.h>
>> >> @@ -45,8 +46,9 @@
>> >>  /* XXX should be in an include file shared with csu */
>> >>  char     ***_csu_finish(char **_argv, char **_envp, void
>> >(*_cleanup)(void));
>> >>  
>> >> -/* provide definition for this */
>> >> +/* provide definitions for these */
>> >>  int      _pagesize = 0;
>> >> +struct timekeep  *_timekeep;
>> >>  
>> >>  /*
>> >>   * In dynamicly linked binaries environ and __progname are
>overriden
>> >by
>> >> @@ -105,6 +107,13 @@ _libc_preinit(int argc, char **argv, char
>> >**envp, dl_cb_cb *cb)
>> >>                   phnum = aux->au_v;
>> >>                   break;
>> >>  #endif /* !PIC */
>> >> +         case AUX_openbsd_timekeep:
>> >> +                 if (_tc_get_timecount) {
>> >> +                         _timekeep = (void *)aux->au_v;
>> >> +                         if (_timekeep->tk_version != TK_VERSION)
>> >> +                                 _timekeep = NULL;
>> >> +                 }
>> >> +                 break;
>> >>           }
>> >>   }
>> >>  
>> >> diff --git lib/libc/gen/auth_subr.c lib/libc/gen/auth_subr.c
>> >> index 1286a96fe40..32f86eda50f 100644
>> >> --- lib/libc/gen/auth_subr.c
>> >> +++ lib/libc/gen/auth_subr.c
>> >> @@ -752,7 +752,7 @@ auth_check_expire(auth_session_t *as)
>> >>  
>> >>   if (as->pwd && (quad_t)as->pwd->pw_expire != 0) {
>> >>           if (as->now.tv_sec == 0)
>> >> -                 gettimeofday(&as->now, NULL);
>> >> +                 WRAP(gettimeofday)(&as->now, NULL);
>> >>           if ((quad_t)as->now.tv_sec >= (quad_t)as->pwd->pw_expire) {
>> >>                   as->state &= ~AUTH_ALLOW;
>> >>                   as->state |= AUTH_EXPIRED;
>> >> @@ -779,7 +779,7 @@ auth_check_change(auth_session_t *as)
>> >>  
>> >>   if (as->pwd && (quad_t)as->pwd->pw_change) {
>> >>           if (as->now.tv_sec == 0)
>> >> -                 gettimeofday(&as->now, NULL);
>> >> +                 WRAP(gettimeofday)(&as->now, NULL);
>> >>           if (as->now.tv_sec >= (quad_t)as->pwd->pw_change) {
>> >>                   as->state &= ~AUTH_ALLOW;
>> >>                   as->state |= AUTH_PWEXPIRED;
>> >> diff --git lib/libc/gen/time.c lib/libc/gen/time.c
>> >> index 3bbd0d733d1..b3ce9a800f1 100644
>> >> --- lib/libc/gen/time.c
>> >> +++ lib/libc/gen/time.c
>> >> @@ -36,7 +36,7 @@ time(time_t *t)
>> >>  {
>> >>   struct timeval tt;
>> >>  
>> >> - if (gettimeofday(&tt, NULL) == -1)
>> >> + if (WRAP(gettimeofday)(&tt, NULL) == -1)
>> >>           return (-1);
>> >>   if (t)
>> >>           *t = (time_t)tt.tv_sec;
>> >> diff --git lib/libc/gen/times.c lib/libc/gen/times.c
>> >> index 02e4dd44b5c..36841810d1b 100644
>> >> --- lib/libc/gen/times.c
>> >> +++ lib/libc/gen/times.c
>> >> @@ -52,7 +52,7 @@ times(struct tms *tp)
>> >>           return ((clock_t)-1);
>> >>   tp->tms_cutime = CONVTCK(ru.ru_utime);
>> >>   tp->tms_cstime = CONVTCK(ru.ru_stime);
>> >> - if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
>> >> + if (WRAP(clock_gettime)(CLOCK_MONOTONIC, &ts) == -1)
>> >>           return ((clock_t)-1);
>> >>   return (ts.tv_sec * CLK_TCK + ts.tv_nsec / (1000000000 /
>CLK_TCK));
>> >>  }
>> >> diff --git lib/libc/gen/timespec_get.c lib/libc/gen/timespec_get.c
>> >> index 520a5954025..845cbe80356 100644
>> >> --- lib/libc/gen/timespec_get.c
>> >> +++ lib/libc/gen/timespec_get.c
>> >> @@ -37,7 +37,7 @@ timespec_get(struct timespec *ts, int base)
>> >>  {
>> >>   switch (base) {
>> >>   case TIME_UTC:
>> >> -         if (clock_gettime(CLOCK_REALTIME, ts) == -1)
>> >> +         if (WRAP(clock_gettime)(CLOCK_REALTIME, ts) == -1)
>> >>                   return 0;
>> >>           break;
>> >>   default:
>> >> diff --git lib/libc/hidden/sys/time.h lib/libc/hidden/sys/time.h
>> >> index ed112320fa2..df717021cab 100644
>> >> --- lib/libc/hidden/sys/time.h
>> >> +++ lib/libc/hidden/sys/time.h
>> >> @@ -24,7 +24,7 @@ PROTO_NORMAL(adjfreq);
>> >>  PROTO_NORMAL(adjtime);
>> >>  PROTO_NORMAL(futimes);
>> >>  PROTO_NORMAL(getitimer);
>> >> -PROTO_NORMAL(gettimeofday);
>> >> +PROTO_WRAP(gettimeofday);
>> >>  PROTO_NORMAL(setitimer);
>> >>  PROTO_NORMAL(settimeofday);
>> >>  PROTO_NORMAL(utimes);
>> >> diff --git lib/libc/hidden/sys/timetc.h
>lib/libc/hidden/sys/timetc.h
>> >> new file mode 100644
>> >> index 00000000000..bbdaa2d0d4c
>> >> --- /dev/null
>> >> +++ lib/libc/hidden/sys/timetc.h
>> >> @@ -0,0 +1,38 @@
>> >> +/*       $OpenBSD$       */
>> >> +/*
>> >> + * Copyright (c) 2020 Paul Irofti <p...@irofti.net>
>> >> + *
>> >> + * Permission to use, copy, modify, and distribute this software
>for
>> >any
>> >> + * purpose with or without fee is hereby granted, provided that
>the
>> >above
>> >> + * copyright notice and this permission notice appear in all
>copies.
>> >> + *
>> >> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
>> >WARRANTIES
>> >> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
>OF
>> >> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
>> >LIABLE FOR
>> >> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
>> >DAMAGES
>> >> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
>WHETHER
>> >IN AN
>> >> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
>ARISING
>> >OUT OF
>> >> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>> >

Reply via email to