> From: Jeremie Courreges-Anglas <j...@wxcvbn.org> > Date: Sat, 24 Jul 2021 21:22:23 +0200 > > hifive /usr/src/regress/sys/kern/gettimeofday$ doas -u build time > obj/gettimeofday > 6.64 real 6.63 user 0.02 sys > hifive /usr/src/regress/sys/kern/gettimeofday$ doas -u build env > LIBC_NOUSERTC=1 time obj/gettimeofday > 6.48 real 0.60 user 5.42 sys > > Initially I thought that a more descriptive name than TC_TB could be > helpful (TC_TIMEBASE?). But since powerpc also uses TC_TB I think it's > fine as a first step. We can change it later easily, it's just a define > name. > > I haven't even built a release with this, not sure it's worth it. > If you have cpu cycles to spare, please say so. > > ok?
Two small nits below. With that fixed, ok kettenis@ > Index: sys/arch/riscv64/include/timetc.h > =================================================================== > RCS file: /cvs/src/sys/arch/riscv64/include/timetc.h,v > retrieving revision 1.2 > diff -u -p -r1.2 timetc.h > --- sys/arch/riscv64/include/timetc.h 12 May 2021 01:20:52 -0000 1.2 > +++ sys/arch/riscv64/include/timetc.h 23 Jul 2021 13:30:08 -0000 > @@ -19,5 +19,6 @@ > #ifndef _MACHINE_TIMETC_H_ > #define _MACHINE_TIMETC_H_ > > +#define TC_TB 1 > > #endif /* _MACHINE_TIMETC_H_ */ > Index: sys/arch/riscv64/riscv64/clock.c > =================================================================== > RCS file: /cvs/src/sys/arch/riscv64/riscv64/clock.c,v > retrieving revision 1.2 > diff -u -p -r1.2 clock.c > --- sys/arch/riscv64/riscv64/clock.c 21 Jun 2021 15:19:39 -0000 1.2 > +++ sys/arch/riscv64/riscv64/clock.c 23 Jul 2021 13:29:42 -0000 > @@ -47,6 +47,7 @@ static struct timecounter tb_timecounter > .tc_name = "tb", > .tc_quality = 0, > .tc_priv = NULL, > + .tc_user = TC_TB, > }; > > void cpu_startclock(void); > Index: lib/libc/arch/riscv64/gen/usertc.c > =================================================================== > RCS file: /cvs/src/lib/libc/arch/riscv64/gen/usertc.c,v > retrieving revision 1.1 > diff -u -p -r1.1 usertc.c > --- lib/libc/arch/riscv64/gen/usertc.c 29 Apr 2021 18:33:36 -0000 > 1.1 > +++ lib/libc/arch/riscv64/gen/usertc.c 24 Jul 2021 17:07:01 -0000 > @@ -1,6 +1,7 @@ > /* $OpenBSD: usertc.c,v 1.1 2021/04/29 18:33:36 drahn Exp $ */ > /* > * Copyright (c) 2020 Paul Irofti <p...@irofti.net> > + * Copyright (c) 2021 Jeremie Courreges-Anglas <j...@wxcvbn.org> > * > * Permission to use, copy, modify, and distribute this software for any > * purpose with or without fee is hereby granted, provided that the above > @@ -18,4 +19,24 @@ > #include <sys/types.h> > #include <sys/timetc.h> > > -int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL; > +static inline u_int > +rdtime(void) > +{ > + uint64_t ret; > + asm volatile("rdtime %0" : "=r"(ret)); Can you make that __asm voltile? > + return ret & 0xffffffff; The & 0xffffffff isn't really necessary here and the kernel doesn't do it. So I'd drop that bit and simply return ret. > +} > + > +static int > +tc_get_timecount(struct timekeep *tk, u_int *tc) > +{ > + switch (tk->tk_user) { > + case TC_TB: > + *tc = rdtime(); > + return 0; > + } > + > + return -1; > +} > + > +int (*const _tc_get_timecount)(struct timekeep *, u_int *) = > tc_get_timecount; > > > -- > jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE > >