public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>,
	Joseph Myers <joseph@codesourcery.com>
Subject: Re: V3: [PATCH] x86: Install <sys/platform/x86.h> [BZ #26124]
Date: Mon, 22 Jun 2020 15:18:53 -0700	[thread overview]
Message-ID: <CAMe9rOq_DVfTJ2K3wX-PzF8KzP-BqvcEOKRoopYwLAsknzMtYA@mail.gmail.com> (raw)
In-Reply-To: <87a70ug5v8.fsf@oldenburg2.str.redhat.com>

On Mon, Jun 22, 2020 at 2:15 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > I changed the manual to
> >
> > @deftypefn Macro int HAS_CPU_FEATURE (@var{name})
> > This macro returns a nonzero value (true) if the processor has the feature
> > @var{name}.
> > @end deftypefn
> >
> > @deftypefn Macro int CPU_FEATURE_USABLE (@var{name})
> > This macro returns a nonzero value (true) if the processor feature
> > @var{name} is supported by the operating system.
>
> Does this mean that it's necessary to check both before using the
> feature?  This is what the description implies to me.

CPU_FEATURE_USABLE  is true only if HAS_CPU_FEATURE is true.

> If CPU_FEATURE_USABLE implies HAS_CPU_FEATURE (so it's not necessary to
> check both), then I don't see the use case for HAS_CPU_FEATURE.  To me,
> exposing both liks like a trap for programmers: they might check CPU
> support only, but not operating system support.  That's trap that we
> have fallen into with glibc itself at least once.

Since not all features need OS support, only a subset of features have both.
HAS_CPU_FEATURE is useful on its own.  For example, it can be used to
identify processors even if OS doesn't support the feature.  All the information
is readily available.  I just provide a macro with a stable ABI to access it.

>
> >> >> struct cpu_features (even in its reduced form) is fairly large.  We will
> >> >> never be able to reduce its size again if it becomes public ABI.
> >> >
> >> > Fixed by
> >> >
> >> > struct cpu_features
> >> > {
> >> >   struct cpu_features_basic basic;
> >> >   unsigned int *usable_p;
> >> >   struct cpuid_registers cpuid[COMMON_CPUID_INDEX_MAX];
> >> > };
> >>
> >> I think the cpuid member is the fat part.  But the pointer indirection
> >> allows us to grow the *usable_p part without having to duplicate the
> >> backing storage for __x86_get_cpu_features, so it is an improvement.
> >>
> >> > __builtin_cpu_supports is equivalent to CPU_FEATURE_USABLE and it
> >> > doesn't support HAS_CPU_FEATURE which does provide useful information.
> >>
> >> I'm still puzzled as to why you aren't extending the existing function.
> >>
> >
> > I am working on it:
> >
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-May/546522.html
> >
> > But it is very unlikely to support HAS_CPU_FEATURE and
> > <sys/platform/x86.h> works with all GCCs.
>
> On the other hand, it's easier for our users to upgrade GCC than to
> update glibc.

Not everyone needs/wants to upgrade GCC.

-- 
H.J.

  reply	other threads:[~2020-06-22 22:19 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 19:31 [PATCH] x86: Install <cpu-features.h> " H.J. Lu
2020-06-17 20:54 ` Joseph Myers
2020-06-18  0:08   ` [PATCH] x86: Install <sys/platform/x86.h> " H.J. Lu
2020-06-18  8:45     ` Florian Weimer
2020-06-18 16:14       ` V2: " H.J. Lu
2020-06-22  9:09         ` Florian Weimer
2020-06-22 20:25           ` V3: " H.J. Lu
2020-06-22 20:41             ` Florian Weimer
2020-06-22 20:53               ` H.J. Lu
2020-06-22 21:14                 ` Florian Weimer
2020-06-22 22:18                   ` H.J. Lu [this message]
2020-06-22 23:14                     ` V4: " H.J. Lu
2020-06-24 14:33                       ` Florian Weimer
2020-06-24 20:04                         ` Adhemerval Zanella
2020-06-24 21:10                           ` H.J. Lu
2020-06-25  7:33                             ` Florian Weimer
2020-06-25 12:30                               ` V5: " H.J. Lu
2020-06-25 13:20                                 ` V6: " H.J. Lu
2020-06-26 12:52                                   ` H.J. Lu
2020-06-26 13:20                                     ` Florian Weimer
2020-06-26 13:44                                       ` H.J. Lu
2020-06-29 16:13                                   ` Florian Weimer
2020-06-29 16:44                                     ` H.J. Lu
2020-06-29 16:49                                       ` Florian Weimer
2020-06-30  0:29                                         ` H.J. Lu
2020-06-30  9:46                                           ` Florian Weimer
2020-06-30 12:19                                             ` H.J. Lu
2020-06-24 22:07                           ` V4: " Joseph Myers

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

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

  git send-email \
    --in-reply-to=CAMe9rOq_DVfTJ2K3wX-PzF8KzP-BqvcEOKRoopYwLAsknzMtYA@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    /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).