public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: libc-alpha@sourceware.org,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: Re: [PATCH 3/5] Linux: Use rseq to accelerate sched_getcpu
Date: Mon, 06 Dec 2021 18:06:03 +0100	[thread overview]
Message-ID: <87a6hdoe84.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20211206165004.GB3294453@arm.com> (Szabolcs Nagy's message of "Mon, 6 Dec 2021 16:50:04 +0000")

* Szabolcs Nagy:

> The 12/06/2021 14:46, Florian Weimer via Libc-alpha wrote:
>> Co-Authored-By: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
>> ---
>>  sysdeps/unix/sysv/linux/sched_getcpu.c | 19 +++++++++++++++++--
>>  1 file changed, 17 insertions(+), 2 deletions(-)
>> 
>> diff --git a/sysdeps/unix/sysv/linux/sched_getcpu.c b/sysdeps/unix/sysv/linux/sched_getcpu.c
>> index c41e986f2c..91250f9d0c 100644
>> --- a/sysdeps/unix/sysv/linux/sched_getcpu.c
>> +++ b/sysdeps/unix/sysv/linux/sched_getcpu.c
>> @@ -20,8 +20,8 @@
>>  #include <sysdep.h>
>>  #include <sysdep-vdso.h>
>>  
>> -int
>> -sched_getcpu (void)
>> +static int
>> +vsyscall_sched_getcpu (void)
>>  {
>>    unsigned int cpu;
>>    int r = -1;
>> @@ -32,3 +32,18 @@ sched_getcpu (void)
>>  #endif
>>    return r == -1 ? r : cpu;
>>  }
>> +
>> +#ifdef RSEQ_SIG
>> +int
>> +sched_getcpu (void)
>> +{
>> +  int cpu_id = THREAD_GETMEM (THREAD_SELF, rseq_area.cpu_id);
>> +  return __glibc_likely (cpu_id >= 0) ? cpu_id : vsyscall_sched_getcpu ();
>> +}
>
> i think there is a formal memory model issue here since
> tp->rseq_area.cpu_id can be modified by the kernel asynchronously
> but we don't use volatile or relaxed_mo atomic access.
> (assuming THREAD_GETMEM is defined as a normal access)

The kernel only modifies cpu_id if the user code is not running on the
thread, so I don't think this doesn't matter.

> i think this is fine here (unlikely to cause miscompilation),
> but may be worth a note?

The kernel doesn't use the C memory model, so using that terminology in
the kernel context would only be more confusing.

Thanks,
Florian


  reply	other threads:[~2021-12-06 17:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 13:45 [PATCH 0/5] Extensible rseq support for glibc Florian Weimer
2021-12-06 13:46 ` [PATCH 1/5] nptl: Add <thread_pointer.h> for defining __thread_pointer Florian Weimer
2021-12-06 16:44   ` Mathieu Desnoyers
2021-12-06 17:01     ` Florian Weimer
2021-12-06 19:55       ` Florian Weimer
2021-12-06 13:46 ` [PATCH 2/5] nptl: Add rseq registration Florian Weimer
2021-12-06 16:53   ` Mathieu Desnoyers
2021-12-06 17:10     ` Florian Weimer
2021-12-06 16:59   ` Mathieu Desnoyers
2021-12-06 17:14     ` Florian Weimer
2021-12-06 18:52       ` Mathieu Desnoyers
2021-12-06 19:03         ` Florian Weimer
2021-12-06 20:11           ` Paul E. McKenney
2021-12-06 20:26             ` Florian Weimer
2021-12-06 21:08               ` Paul E. McKenney
2021-12-06 13:46 ` [PATCH 3/5] Linux: Use rseq to accelerate sched_getcpu Florian Weimer
2021-12-06 16:50   ` Szabolcs Nagy
2021-12-06 17:06     ` Florian Weimer [this message]
2021-12-06 17:45       ` Szabolcs Nagy
2021-12-07 15:48         ` Florian Weimer
2021-12-06 13:46 ` [PATCH 4/5] nptl: Add glibc.pthread.rseq tunable to control rseq registration Florian Weimer
2021-12-06 13:53 ` [PATCH 5/5] nptl: Add public rseq symbols and <sys/rseq.h> Florian Weimer
2021-12-07 11:01   ` Szabolcs Nagy
2021-12-07 11:28     ` Florian Weimer
2021-12-06 16:13 ` [PATCH 0/5] Extensible rseq support for glibc Mathieu Desnoyers

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=87a6hdoe84.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=szabolcs.nagy@arm.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).