From: Florian Weimer <fweimer@redhat.com>
To: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Subject: Re: [PATCH] <sys/platform/x86.h>: Remove the C preprocessor magic
Date: Wed, 20 Jan 2021 10:53:07 +0100 [thread overview]
Message-ID: <87h7nc6ikc.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20201225162451.1657088-1-hjl.tools@gmail.com> (H. J. Lu via Libc-alpha's message of "Fri, 25 Dec 2020 08:24:51 -0800")
* H. J. Lu via Libc-alpha:
> +enum
> +{
> + COMMON_CPUID_INDEX_1 = 0,
> + COMMON_CPUID_INDEX_7,
> + COMMON_CPUID_INDEX_80000001,
> + COMMON_CPUID_INDEX_D_ECX_1,
> + COMMON_CPUID_INDEX_80000007,
> + COMMON_CPUID_INDEX_80000008,
> + COMMON_CPUID_INDEX_7_ECX_1,
> + COMMON_CPUID_INDEX_19,
> + /* Keep the following line at the end. */
> + COMMON_CPUID_INDEX_MAX
> +};
COMMON_CPUID_INDEX_MAX should not be in the public header because it
subject to changes.
> +struct cpuid_registers
> +{
> + unsigned int eax;
> + unsigned int ebx;
> + unsigned int ecx;
> + unsigned int edx;
> +};
Should the non-public interfaces use __?
> +enum cpu_features_kind
> +{
> + arch_kind_unknown = 0,
> + arch_kind_intel,
> + arch_kind_amd,
> + arch_kind_zhaoxin,
> + arch_kind_other
> +};
> +
> +struct cpu_features_basic
> +{
> + enum cpu_features_kind kind;
> + int max_cpuid;
> + unsigned int family;
> + unsigned int model;
> + unsigned int stepping;
> +};
Should we really expose all this? It's not documented. enum
cpu_features_kind doesn't seem to be compatible with how people use
virtualization.
> diff --git a/sysdeps/x86/dl-get-cpu-features.c b/sysdeps/x86/dl-get-cpu-features.c
> index 349472d99f..4636d9f4a7 100644
> --- a/sysdeps/x86/dl-get-cpu-features.c
> +++ b/sysdeps/x86/dl-get-cpu-features.c
> @@ -46,9 +46,9 @@ __ifunc (__x86_cpu_features, __x86_cpu_features, NULL, void,
> #undef __x86_get_cpu_features
>
> const struct cpu_features *
> -__x86_get_cpu_features (unsigned int max)
> +__x86_get_cpu_features (unsigned int index)
> {
> - if (max > COMMON_CPUID_INDEX_MAX)
> + if (index > COMMON_CPUID_INDEX_MAX * 8 * sizeof (unsigned int) * 4)
> return NULL;
> return &GLRO(dl_x86_cpu_features);
> }
This should work in principle (but I haven't verified the boundary
condition).
Could you pass the COMMON_CPUID_INDEX_* value (without the register and
bit selectors)? Then more calls can be subject to common subexpression
elimination in the caller, leading to more compact code.
You could perhaps return a pointer to a zero struct in case the index is
too large. This way, the caller does not have to check for a null
pointer.
The result should be very close to what we had before in terms of
generated code, I hope.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
next prev parent reply other threads:[~2021-01-20 9:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-25 16:24 H.J. Lu
2021-01-20 9:53 ` Florian Weimer [this message]
2021-01-20 11:23 ` Florian Weimer
2021-01-20 14:43 ` V2 " H.J. Lu
2021-01-20 15:58 ` Florian Weimer
2021-01-21 0:19 ` V3 " H.J. Lu
2021-01-21 11:19 ` Florian Weimer
2021-01-21 13:29 ` V4 " H.J. Lu
2021-01-21 13:57 ` Florian Weimer
2021-01-21 14:12 ` Adhemerval Zanella
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=87h7nc6ikc.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.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).