diff options
author | 2020-07-08 09:17:48 +0000 | |
---|---|---|
committer | 2020-07-08 09:17:48 +0000 | |
commit | c8437fb9fb14bc7d741cd869c83f7b73101f3962 (patch) | |
tree | c251016fafc8b977558c1de26aa85b9af2684bc1 | |
parent | Mention that we support building a port from Go modules now. (diff) | |
download | wireguard-openbsd-c8437fb9fb14bc7d741cd869c83f7b73101f3962.tar.xz wireguard-openbsd-c8437fb9fb14bc7d741cd869c83f7b73101f3962.zip |
Clean up the amd64 userland timecounter implementation a bit:
* We don't need TC_LAST
* Make internal functions static to avoid namespace pollution in libc.a
* Use a switch statement to harmonize with architectures providing
multiple timecounters
ok deraadt@, pirofti@
-rw-r--r-- | lib/libc/arch/amd64/gen/usertc.c | 20 | ||||
-rw-r--r-- | sys/arch/amd64/include/timetc.h | 5 |
2 files changed, 12 insertions, 13 deletions
diff --git a/lib/libc/arch/amd64/gen/usertc.c b/lib/libc/arch/amd64/gen/usertc.c index ea920481841..7529af598da 100644 --- a/lib/libc/arch/amd64/gen/usertc.c +++ b/lib/libc/arch/amd64/gen/usertc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usertc.c,v 1.1 2020/07/06 13:33:05 pirofti Exp $ */ +/* $OpenBSD: usertc.c,v 1.2 2020/07/08 09:17:48 kettenis Exp $ */ /* * Copyright (c) 2020 Paul Irofti <paul@irofti.net> * @@ -26,16 +26,16 @@ rdtsc(void) return ((uint64_t)lo)|(((uint64_t)hi)<<32); } -int +static int tc_get_timecount(struct timekeep *tk, u_int *tc) { - int tk_user = tk->tk_user; + switch (tk->tk_user) { + case TC_TSC: + *tc = rdtsc(); + return 0; + } - if (tk_user < 1 || tk_user >= TC_LAST) - return -1; - - *tc = rdtsc(); - return 0; + return -1; } -int (*const _tc_get_timecount)(struct timekeep *tk, u_int *tc) - = tc_get_timecount; + +int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount; diff --git a/sys/arch/amd64/include/timetc.h b/sys/arch/amd64/include/timetc.h index 273e809116a..48e1b57d410 100644 --- a/sys/arch/amd64/include/timetc.h +++ b/sys/arch/amd64/include/timetc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:06 pirofti Exp $ */ +/* $OpenBSD: timetc.h,v 1.2 2020/07/08 09:17:48 kettenis Exp $ */ /* * Copyright (c) 2020 Paul Irofti <paul@irofti.net> * @@ -18,7 +18,6 @@ #ifndef _MACHINE_TIMETC_H_ #define _MACHINE_TIMETC_H_ -#define TC_TSC 1 -#define TC_LAST 2 +#define TC_TSC 1 #endif /* _MACHINE_TIMETC_H_ */ |