Deleted Added
full compact
__vdso_gettc.c (286284) __vdso_gettc.c (291937)
1/*-
1/*-
2 * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
2 * Copyright (c) 2015 The FreeBSD Foundation
3 *
3 *
4 * This software was developed by Konstantin Belousov
5 * under sponsorship from the FreeBSD Foundation.
6 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.

--- 7 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.

--- 7 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: head/lib/libc/amd64/sys/__vdso_gettc.c 286284 2015-08-04 12:33:51Z kib $");
30__FBSDID("$FreeBSD: head/lib/libc/arm/sys/__vdso_gettc.c 291937 2015-12-07 12:20:26Z kib $");
28
29#include <sys/types.h>
30#include <sys/elf.h>
31#include <sys/time.h>
32#include <sys/vdso.h>
33#include <machine/cpufunc.h>
34#include "libc_private.h"
35
31
32#include <sys/types.h>
33#include <sys/elf.h>
34#include <sys/time.h>
35#include <sys/vdso.h>
36#include <machine/cpufunc.h>
37#include "libc_private.h"
38
36static u_int
37__vdso_gettc_low(const struct vdso_timehands *th)
39static inline uint64_t
40cp15_cntvct_get(void)
38{
41{
39 u_int rv;
42 uint64_t reg;
40
43
41 __asm __volatile("lfence; rdtsc; shrd %%cl, %%edx, %0"
42 : "=a" (rv) : "c" (th->th_x86_shift) : "edx");
43 return (rv);
44 __asm __volatile("mrrc\tp15, 1, %Q0, %R0, c14" : "=r" (reg));
45 return (reg);
44}
45
46}
47
46static u_int
47__vdso_rdtsc32(void)
48static inline uint64_t
49cp15_cntpct_get(void)
48{
50{
49 u_int rv;
51 uint64_t reg;
50
52
51 __asm __volatile("lfence;rdtsc" : "=a" (rv) : : "edx");
52 return (rv);
53 __asm __volatile("mrrc\tp15, 0, %Q0, %R0, c14" : "=r" (reg));
54 return (reg);
53}
54
55#pragma weak __vdso_gettc
56u_int
57__vdso_gettc(const struct vdso_timehands *th)
58{
55}
56
57#pragma weak __vdso_gettc
58u_int
59__vdso_gettc(const struct vdso_timehands *th)
60{
61 uint64_t val;
59
62
60 return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) :
61 __vdso_rdtsc32());
63 /*
64 * Userspace gettimeofday() is only enabled on ARMv7 CPUs, but
65 * libc is compiled for ARMv6. Due to clang issues, .arch
66 * armv7-a directive does not work.
67 */
68 __asm __volatile(".word\t0xf57ff06f" : : : "memory"); /* isb */
69 val = th->th_physical == 0 ? cp15_cntvct_get() : cp15_cntpct_get();
70 return (val);
62}
63
64#pragma weak __vdso_gettimekeep
65int
66__vdso_gettimekeep(struct vdso_timekeep **tk)
67{
68
69 return (_elf_aux_info(AT_TIMEKEEP, tk, sizeof(*tk)));
70}
71}
72
73#pragma weak __vdso_gettimekeep
74int
75__vdso_gettimekeep(struct vdso_timekeep **tk)
76{
77
78 return (_elf_aux_info(AT_TIMEKEEP, tk, sizeof(*tk)));
79}