public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,  Joseph Myers <joseph@codesourcery.com>
Subject: Re: V2: [PATCH] x86: Install <sys/platform/x86.h> [BZ #26124]
Date: Mon, 22 Jun 2020 11:09:25 +0200	[thread overview]
Message-ID: <87o8pbpiuy.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <CAMe9rOoST0GwLaMVCO4QqYOGxBCQr1JXKZoq=N8Sz0BL33Vk8Q@mail.gmail.com> (H. J. Lu via Libc-alpha's message of "Thu, 18 Jun 2020 09:14:22 -0700")

* H. J. Lu via Libc-alpha:

> On Thu, Jun 18, 2020 at 1:45 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu via Libc-alpha:
>>
>> > <sys/platform/x86.h> exports only:
>> >
>> > struct cpu_features
>> > {
>> >   struct cpuid_registers cpuid[COMMON_CPUID_INDEX_MAX];
>> >   unsigned int feature[FEATURE_INDEX_MAX];
>> >   struct cpu_features_basic basic;
>> > };
>>
>> The struct cpu_features ABI does not appear to be stable, as I wrote on
>> the other thread:
>>
>>   <https://sourceware.org/pipermail/libc-alpha/2020-June/115161.html>
>>
>
> Here is the updated patch to use
>
> struct cpu_features
> {
>   struct cpu_features_basic basic;
>   unsigned int usable[USABLE_FEATURE_INDEX_MAX];
>   struct cpuid_registers cpuid[COMMON_CPUID_INDEX_MAX];
> };
>
> This should be backward compatible for both .o and .so files.

This is an improvement.  I still see issues with this interface, though.

Programmers will need something like this for IFUNC resolvers, but this
is not usable there if the relocation order does not match the explicit
ELF dependency order (e.g., due to symbol interposition).  This is a
generic problem with IFUNC resolvers.  Other architectures solve this by
adding arguments to IFUNC resolvers, so that the required can be
accessed without relocations.  __builtin_cpu_supports does not have this
issue.

The manual does not explain the difference between “available” and
“usable”.  I do not think we should expose both.  I don't see any
circumstances under which “available” would provide useful information.

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.

I'm not convinced that this interface conforms to the API contract for
the CPUID instruction.  Aren't the raw bits in the cpuid field subject
to interpretation based on family and model?  HAS_CPU_FEATURE does not
reflect this at all.

My preferred interface would look like this:

* The low-level function call ABI is:

  unsigned long long long int __x86_get_cpu_features (unsigned int word)
    __attribute__ ((const));

* IFUNC resolvers receive two arguments,

  unsigned long long long int *feature_words, size_t feature_words_length

* CPU_FEATURE_USABLE (NAME) would expand to something like

    ((__x86_get_cpu_features (NAME_word) & NAME_bitmask) != 0)

  The implementation of __x86_get_cpu_features simply returns 0 if the
  index is too large, which solves the extension problem.

* CPU_FEATURE_USABLE_ARRAY (WORDS, WORDS_LENGTH, NAME) would expand to this:

  (((NAME_word < WORDS_LENGTH ? WORDS[NAME_word] ? : 0) & NAME_bitmask) != 0)

  This version is expected to be used in IFUNC resolvers.  The macro
  name is just a strawman.

Only the “usable” bits are exposed, so the interface makes it clear that
the implementation performs some normalization.

Alternatively, the __builtin_cpu_supports interface could be enhanced to
cover all the features you need.

Thanks,
Florian


  reply	other threads:[~2020-06-22  9:09 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 [this message]
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
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=87o8pbpiuy.fsf@oldenburg2.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=hjl.tools@gmail.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).