From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 2/2] x86: Add generic CPUID data dumper to ld.so --list-diagnostics
Date: Mon, 11 Sep 2023 13:41:15 -0300 [thread overview]
Message-ID: <827ddec8-d5fd-42f0-8401-6cbd161f3b3d@linaro.org> (raw)
In-Reply-To: <87o7i8ptrf.fsf@oldenburg.str.redhat.com>
On 11/09/23 13:19, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
>
>>> +void
>>> +_dl_diagnostics_cpu_kernel (void)
>>> +{
>>> +#if !HAS_CPUID
>>> + /* CPUID is not supported, so there is nothing to dump. */
>>> + if (__get_cpuid_max (0, 0) == 0)
>>> + return;
>>> +#endif
>>
>> I think we don't support __i486__ anymore, so we can just assume HAS_CPUID
>> at sysdeps/x86/include/cpu-features.h.
>
> We still build an i486 variant in build-many-glibcs.py.
Indeed.
>> Why not use the interfaces to work on cpuset?
>>
>> if (length_reference > 0)
>> {
>> int cpu_count = CPU_COUNT_S (length_reference, mask_reference);
>> for (int i = 0; i < cpu_count; i++)
>> {
>> if (CPU_ISSET_S (i, length_reference, mask_reference)
>> {
>> CPU_SET_S (i, length_reference, mask_request);
>> if (INTERNAL_SYSCALL_CALL (sched_setaffinity, 0,
>> length_reference, mask_request) == 0)
>> {
>> _dl_diagnostics_cpuid_collect (&ccd[i & 1]);
>> _dl_diagnostics_cpuid_report (processor_index, i,
>> &ccd[processor_index & 1],
>> &ccd[!(processor_index & 1)]);
>> ++processor_index;
>> }
>> CPU_CLR_S (i, length_reference, mask_request);
>> }
>> }
>> }
>>
>> I will iterate over the list twice, but I don't think this would really matter
>> here.
>
> I think the macros are somewhat incompatible with direct system calls.
> CPU_COUNT_S requires that the tail is zeroed, which the system call
> doesn't do. Maybe we can memset the whole thing before the sched_getcpu
> system call. I haven't tried if we can directly rebuild
> __sched_cpucount for ld.so, either.
Afaiu the setsize is exactly to avoid the tail zeroing and to use the syscall
return code, isn't? It does not work outside libc because sched_getaffinity
does not return the bytes set from the kernel, but it does work with direct
syscalls:
$ cat > test.c <<EOF
#define _GNU_SOURCE
#include <assert.h>
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
int
main (int argc, char *argv[])
{
size_t cpusetsize = CPU_ALLOC_SIZE (1024);
cpu_set_t cpuset[cpusetsize];
memset (cpuset, 0xff, cpusetsize * sizeof (cpu_set_t));
long int sz = syscall (SYS_sched_getaffinity, getpid (), cpusetsize, cpuset);
printf ("%ld %d\n", sz, CPU_COUNT_S (sz, cpuset));
return 0;
}
EOF
$ gcc -Wall test.c -o test && ./test
8 24
next prev parent reply other threads:[~2023-09-11 16:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 20:09 [PATCH 1/2] elf: Wire up _dl_diagnostics_cpu_kernel Florian Weimer
2023-09-08 20:10 ` [PATCH 2/2] x86: Add generic CPUID data dumper to ld.so --list-diagnostics Florian Weimer
2023-09-10 19:56 ` Noah Goldstein
2023-09-11 4:24 ` Florian Weimer
2023-09-11 16:16 ` Noah Goldstein
2023-09-11 16:25 ` Florian Weimer
2023-09-11 16:28 ` Noah Goldstein
2023-09-11 16:31 ` Noah Goldstein
2023-09-11 17:48 ` Florian Weimer
2023-09-11 18:35 ` Noah Goldstein
2023-09-11 16:08 ` Adhemerval Zanella Netto
2023-09-11 16:19 ` Florian Weimer
2023-09-11 16:41 ` Adhemerval Zanella Netto [this message]
2024-02-09 19:08 [PATCH 0/2] Enhanced x86 CPU diagnostics Florian Weimer
2024-02-09 19:08 ` [PATCH 2/2] x86: Add generic CPUID data dumper to ld.so --list-diagnostics Florian Weimer
2024-02-09 19:34 ` H.J. Lu
2024-02-10 0:44 ` H.J. Lu
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=827ddec8-d5fd-42f0-8401-6cbd161f3b3d@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=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).