unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] x86: Properly match CPU feature [BZ #27222]
Date: Fri, 22 Jan 2021 10:11:19 -0800	[thread overview]
Message-ID: <CAMe9rOpLk_6odrs5B6-_YceVifsugf_qT430eLVyYfr2SKQ7CA@mail.gmail.com> (raw)
In-Reply-To: <9c8d88ef-13c3-144f-d6eb-0cf0463f54d8@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2047 bytes --]

On Fri, Jan 22, 2021 at 8:56 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
>
>
> On 22/01/2021 12:01, H.J. Lu via Libc-alpha wrote:
> > On Thu, Jan 21, 2021 at 11:47 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>
> >> /proc/cpuinfo has
> >>
> >> flags           : fpu vme de pse ... ssse3 ...
> >>
> >> SSE3 in /proc/cpuinfo is displaced as "pni".  Search "pni" instead of
> >> "sse3" for SSE3.  After finding a match for a string, verify the previous
> >> character is space and the next character is space or null byte to avoid
> >> matching "XXXYYYXXX" with "YYY".
> >> ---
> >>  sysdeps/x86/tst-cpu-features-cpuinfo.c | 9 +++++++--
> >>  1 file changed, 7 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
> >> index 771771c959..9308349869 100644
> >> --- a/sysdeps/x86/tst-cpu-features-cpuinfo.c
> >> +++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
> >> @@ -64,7 +64,12 @@ check_proc (const char *proc_name, int flag, int usable, const char *name)
> >>        return 0;
> >>      }
> >>    printf ("  %s: %d\n", name, flag);
> >> -  if (strstr (cpu_flags, proc_name) != NULL)
> >> +  char *str = strstr (cpu_flags, proc_name);
> >> +  size_t len = strlen (proc_name);
> >> +  /* Don't match "ssse3" with "sse3".  */
> >> +  if (str != NULL
> >> +      && str[-1] == ' '
> >> +      && (str[len] == ' ' || str[len] == '\0'))
> >>      found = 1;
> >>    printf ("  cpuinfo (%s): %d\n", proc_name, found);
> >>
> >> @@ -206,7 +211,7 @@ do_test (int argc, char **argv)
> >>    fails += CHECK_PROC (ssbd, SSBD);
> >>    fails += CHECK_PROC (sse, SSE);
> >>    fails += CHECK_PROC (sse2, SSE2);
> >> -  fails += CHECK_PROC (sse3, SSE3);
> >> +  fails += CHECK_PROC (pni, SSE3);
> >>    fails += CHECK_PROC (sse4_1, SSE4_1);
> >>    fails += CHECK_PROC (sse4_2, SSE4_2);
> >>    fails += CHECK_PROC (sse4a, SSE4A);
> >> --
> >> 2.29.2
> >>
> >
> > I am checking it in.
> >
>
> Ok for 2.33.

I am checking in this different variant.

-- 
H.J.

[-- Attachment #2: 0001-x86-Properly-match-CPU-features-in-proc-cpuinfo-BZ-2.patch --]
[-- Type: text/x-patch, Size: 4140 bytes --]

From 27932428e116d9ca9d949305d880c9218479afa0 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 21 Jan 2021 11:12:30 -0800
Subject: [PATCH] x86: Properly match CPU features in /proc/cpuinfo [BZ #27222]

Search " YYY " and " YYY\n", instead of "YYY", to avoid matching
"XXXYYYZZZ" with "YYY".

Update /proc/cpuinfo CPU feature names:

/proc/cpuinfo                     glibc
------------------------------------------------
avx512vbmi                        AVX512_VBMI
dts                               DS
pni                               SSE3
tsc_deadline_timer                TSC_DEADLINE
---
 sysdeps/x86/tst-cpu-features-cpuinfo.c | 43 ++++++++++++++++++--------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
index 771771c959..f38a0f6af6 100644
--- a/sysdeps/x86/tst-cpu-features-cpuinfo.c
+++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
@@ -53,30 +53,47 @@ get_cpuinfo (void)
 }
 
 int
-check_proc (const char *proc_name, int flag, int usable, const char *name)
+check_proc (const char *proc_name, const char *search_name, int flag,
+	    int usable, const char *name)
 {
   int found = 0;
 
   printf ("Checking %s:\n", name);
-  if (!usable)
+  printf ("  %s: %d\n", name, flag);
+  char *str = strstr (cpu_flags, search_name);
+  if (str == NULL)
     {
-      printf ("  %s: insufficient usable info, skipped\n", name);
-      return 0;
+      /* If searching for " XXX " failed, try " XXX\n".  */
+      size_t len = strlen (search_name);
+      char buffer[80];
+      if (len >= sizeof buffer)
+	abort ();
+      memcpy (buffer, search_name, len + 1);
+      buffer[len - 1] = '\n';
+      str = strstr (cpu_flags, buffer);
     }
-  printf ("  %s: %d\n", name, flag);
-  if (strstr (cpu_flags, proc_name) != NULL)
+  if (str != NULL)
     found = 1;
   printf ("  cpuinfo (%s): %d\n", proc_name, found);
 
   if (found != flag)
-    printf (" *** failure ***\n");
+    {
+      if (found || usable)
+	printf (" *** failure ***\n");
+      else
+	{
+	  printf (" *** missing in /proc/cpuinfo ***\n");
+	  return 0;
+	}
+    }
 
   return (found != flag);
 }
 
 #define CHECK_PROC(str, name) \
-  check_proc (#str, HAS_CPU_FEATURE (name), CPU_FEATURE_USABLE (name), \
-	      "HAS_CPU_FEATURE (" #name ")");
+  check_proc (#str, " "#str" ", HAS_CPU_FEATURE (name), \
+	      CPU_FEATURE_USABLE (name), \
+	      "CPU_FEATURE_USABLE (" #name ")")
 
 static int
 do_test (int argc, char **argv)
@@ -99,7 +116,7 @@ do_test (int argc, char **argv)
   fails += CHECK_PROC (avx512_bf16, AVX512_BF16);
   fails += CHECK_PROC (avx512_bitalg, AVX512_BITALG);
   fails += CHECK_PROC (avx512ifma, AVX512_IFMA);
-  fails += CHECK_PROC (avx512_vbmi, AVX512_VBMI);
+  fails += CHECK_PROC (avx512vbmi, AVX512_VBMI);
   fails += CHECK_PROC (avx512_vbmi2, AVX512_VBMI2);
   fails += CHECK_PROC (avx512_vnni, AVX512_VNNI);
   fails += CHECK_PROC (avx512_vp2intersect, AVX512_VP2INTERSECT);
@@ -125,7 +142,7 @@ do_test (int argc, char **argv)
   fails += CHECK_PROC (dca, DCA);
   fails += CHECK_PROC (de, DE);
   fails += CHECK_PROC (zero_fcs_fds, DEPR_FPU_CS_DS);
-  fails += CHECK_PROC (ds, DS);
+  fails += CHECK_PROC (dts, DS);
   fails += CHECK_PROC (ds_cpl, DS_CPL);
   fails += CHECK_PROC (dtes64, DTES64);
   fails += CHECK_PROC (est, EIST);
@@ -206,7 +223,7 @@ do_test (int argc, char **argv)
   fails += CHECK_PROC (ssbd, SSBD);
   fails += CHECK_PROC (sse, SSE);
   fails += CHECK_PROC (sse2, SSE2);
-  fails += CHECK_PROC (sse3, SSE3);
+  fails += CHECK_PROC (pni, SSE3);
   fails += CHECK_PROC (sse4_1, SSE4_1);
   fails += CHECK_PROC (sse4_2, SSE4_2);
   fails += CHECK_PROC (sse4a, SSE4A);
@@ -223,7 +240,7 @@ do_test (int argc, char **argv)
   fails += CHECK_PROC (intel_pt, TRACE);
   fails += CHECK_PROC (tsc, TSC);
   fails += CHECK_PROC (tsc_adjust, TSC_ADJUST);
-  fails += CHECK_PROC (tsc_deadline, TSC_DEADLINE);
+  fails += CHECK_PROC (tsc_deadline_timer, TSC_DEADLINE);
   fails += CHECK_PROC (tsxldtrk, TSXLDTRK);
   fails += CHECK_PROC (umip, UMIP);
   fails += CHECK_PROC (vaes, VAES);
-- 
2.29.2


  reply	other threads:[~2021-01-22 18:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 19:47 [PATCH] x86: Properly match CPU feature [BZ #27222] H.J. Lu via Libc-alpha
2021-01-22 15:01 ` H.J. Lu via Libc-alpha
2021-01-22 16:56   ` Adhemerval Zanella via Libc-alpha
2021-01-22 18:11     ` H.J. Lu via Libc-alpha [this message]
2021-02-02 11:07       ` Andreas Schwab
2021-02-02 15:01         ` [PATCH] <bits/platform/x86.h>: Correct x86_cpu_TBM H.J. Lu via Libc-alpha
2021-02-22  9:49           ` Florian Weimer via Libc-alpha
2022-02-17  0:10             ` H.J. Lu via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOpLk_6odrs5B6-_YceVifsugf_qT430eLVyYfr2SKQ7CA@mail.gmail.com \
    --to=libc-alpha@sourceware.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).