The branch stable/12 has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=6494841a80aa7913ead34ea7f5fdc6be78c9c8d6

commit 6494841a80aa7913ead34ea7f5fdc6be78c9c8d6
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2021-01-06 15:05:09 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2021-02-09 08:36:25 +0000

    x86 vdso gettc: Add RDTSCP support
    
    Tested by:      pho
    
    (cherry picked from commit cd240c9cf100bec3def38ceb4a320611b1d02693)
    (cherry picked from commit 523d94dbeab5ccb1cce21b8cad350b700c3d01b2)
---
 lib/libc/x86/sys/__vdso_gettc.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/lib/libc/x86/sys/__vdso_gettc.c b/lib/libc/x86/sys/__vdso_gettc.c
index c3ace1685561..1f3e8133040f 100644
--- a/lib/libc/x86/sys/__vdso_gettc.c
+++ b/lib/libc/x86/sys/__vdso_gettc.c
@@ -63,6 +63,16 @@ rdtsc_low(const struct vdso_timehands *th)
        return (rv);
 }
 
+static inline u_int
+rdtscp_low(const struct vdso_timehands *th)
+{
+       u_int rv;
+
+       __asm __volatile("rdtscp; movl %%edi,%%ecx; shrd %%cl, %%edx, %0"
+           : "=a" (rv) : "D" (th->th_x86_shift) : "ecx", "edx");
+       return (rv);
+}
+
 static u_int
 rdtsc_low_mb_lfence(const struct vdso_timehands *th)
 {
@@ -103,13 +113,19 @@ rdtsc32_mb_none(void)
        return (rdtsc32());
 }
 
+static u_int
+rdtscp32_(void)
+{
+       return (rdtscp32());
+}
+
 struct tsc_selector_tag {
        u_int (*ts_rdtsc32)(void);
        u_int (*ts_rdtsc_low)(const struct vdso_timehands *);
 };
 
 static const struct tsc_selector_tag tsc_selector[] = {
-       [0] = {                         /* Intel or AMD Zen+, LFENCE */
+       [0] = {                         /* Intel, LFENCE */
                .ts_rdtsc32 =   rdtsc32_mb_lfence,
                .ts_rdtsc_low = rdtsc_low_mb_lfence,
        },
@@ -121,6 +137,10 @@ static const struct tsc_selector_tag tsc_selector[] = {
                .ts_rdtsc32 = rdtsc32_mb_none,
                .ts_rdtsc_low = rdtsc_low_mb_none,
        },
+       [3] = {                         /* RDTSCP */
+               .ts_rdtsc32 =   rdtscp32_,
+               .ts_rdtsc_low = rdtscp_low,
+       },
 };
 
 static int
@@ -157,6 +177,8 @@ tsc_selector_idx(u_int cpu_feature)
                amd_feature = 0;
        }
 
+       if ((amd_feature & AMDID_RDTSCP) != 0)
+               return (3);
        if ((cpu_feature & CPUID_SSE2) == 0)
                return (2);
        return (amd_cpu ? 1 : 0);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to