public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>,
	Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 3/8] posix: Consolidate fork implementation
Date: Wed, 10 Mar 2021 14:07:52 -0300	[thread overview]
Message-ID: <eca0d704-5d42-e028-41a2-218ca76002e8@linaro.org> (raw)
In-Reply-To: <87sg544mq4.fsf@oldenburg.str.redhat.com>



On 09/03/2021 07:58, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> diff --git a/sysdeps/nptl/_Fork.c b/sysdeps/nptl/_Fork.c
>> new file mode 100644
>> index 0000000000..9c701bc3d7
>> --- /dev/null
>> +++ b/sysdeps/nptl/_Fork.c
> 
>> +pid_t
>> +_Fork (void)
>> +{
>> +  pid_t pid = arch_fork (&THREAD_SELF->tid);
>> +  if (pid == 0)
>> +    {
>> +      struct pthread *self = THREAD_SELF;
>> +
>> +      /* See __pthread_once.  */
>> +      if (__fork_generation_pointer != NULL)
>> +	*__fork_generation_pointer += __PTHREAD_ONCE_FORK_GEN_INCR;
> 
> This should not be part of _Fork, I think.  There is no need to do that
> for a new interface.

I think you are right, this is used solely for pthread_once and it is not
marked as async-signal-safe (so there is no need to keep it on Linux
_Fork implementation).

> 
> I think this means that there has to be _Fork, the generic fork
> implementation, and something between _Fork and fork that performs the
> architecture-specific bits.

It should be simpler to add a inline hook on fork instead, so the 
sequence would be:

posix/fork.c
   [...]
   pid_t pid = _Fork ();
   if (pid == 0)
     {
       __fork_system_setup ();
       [...]
     }

And __fork_system_setup () is implemented on Linux to setup the required
fork generation for pthread_once (with an empty generic one).

> 
> Hurd may also need this for its internal fork handlers if they are
> supposed to run for fork, but not for _Fork.

I did not dig into Hurd implementation, but I tried to make its _Fork
to no run pthread_atfork as well.  It does use the old callback 
mechanism:

sysdeps/mach/hurd/_Fork.c

 41 /* Things that want to be called before we fork, to prepare the parent for
 42    task_create, when the new child task will inherit our address space.  */
 43 DEFINE_HOOK (_hurd_fork_prepare_hook, (void));
 44 
 45 /* Things that want to be called when we are forking, with the above all
 46    locked.  They are passed the task port of the child.  The child process
 47    is all set up except for doing proc_child, and has no threads yet.  */
 48 DEFINE_HOOK (_hurd_fork_setup_hook, (void));
 49 
 50 /* Things to be run in the child fork.  */
 51 DEFINE_HOOK (_hurd_fork_child_hook, (void));
 52 
 53 /* Things to be run in the parent fork.  */
 54 DEFINE_HOOK (_hurd_fork_parent_hook, (void));

sysdeps/mach/hurd/profil.c:213:text_set_element (_hurd_fork_prepare_hook, fork_profil_prepare);

sysdeps/mach/hurd/profil.c:255:text_set_element (_hurd_fork_child_hook, fork_profil_child);
sysdeps/mach/hurd/setitimer.c:377:text_set_element (_hurd_fork_child_hook, fork_itimer);

sysdeps/mach/hurd/profil.c:221:text_set_element (_hurd_fork_parent_hook, fork_profil_parent);

The hooks seems to be self-contained and there are only a handful of them,
so maybe Hurd developers could cleanup this up and run in directly
instead.

The __run_fork_handlers is only called from fork.c now.

> 
> Given that this affects the way functionality is split in the
> consolidation, I have not reviewed this version of the patch further.

Alright, I will update the patch.

 

  reply	other threads:[~2021-03-10 17:07 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 15:11 [PATCH 1/8] posix: Consolidate register-atfork Adhemerval Zanella
2021-02-02 15:11 ` [PATCH 2/8] linux: Use __libc_single_threaded on fork Adhemerval Zanella
2021-02-02 15:15   ` Andreas Schwab
2021-02-02 16:40     ` Adhemerval Zanella
2021-02-02 15:11 ` [PATCH 3/8] posix: Consolidate fork implementation Adhemerval Zanella
2021-03-09 10:58   ` Florian Weimer
2021-03-10 17:07     ` Adhemerval Zanella [this message]
2021-03-11 13:56   ` Andreas Schwab
2021-03-11 13:59     ` Adhemerval Zanella
2021-02-02 15:11 ` [PATCH 4/8] nptl: Move fork into libc Adhemerval Zanella
2021-03-08 13:42   ` Florian Weimer
2021-03-10 17:08     ` Adhemerval Zanella
2021-02-02 15:11 ` [PATCH 5/8] posix: Do not clobber errno by atfork handlers Adhemerval Zanella
2021-03-09 11:01   ` Florian Weimer
2021-03-10 20:10     ` Adhemerval Zanella
2021-03-11 13:25       ` Florian Weimer
2021-03-11 14:07         ` Adhemerval Zanella
2021-03-11 14:22           ` Andreas Schwab
2021-03-11 14:25             ` Florian Weimer
2021-03-11 15:29               ` Adhemerval Zanella
2021-03-11 15:32                 ` Florian Weimer
2021-03-11 17:25                   ` Adhemerval Zanella
2021-03-11 19:23                     ` Florian Weimer
2021-03-11 19:30                       ` Adhemerval Zanella
2021-02-02 15:11 ` [PATCH 6/8] Consolidate pthread_atfork Adhemerval Zanella
2021-03-09 11:09   ` Florian Weimer
2021-03-10 20:15     ` Adhemerval Zanella
2021-02-02 15:11 ` [PATCH 7/8] support: Add xpthread_kill Adhemerval Zanella
2021-03-08 12:13   ` Florian Weimer
2021-02-02 15:11 ` [PATCH 8/8] posix: Add _Fork [BZ #4737] Adhemerval Zanella
2021-02-02 15:48   ` Andreas Schwab
2021-02-02 18:22   ` Joseph Myers
2021-02-11 15:26   ` [PATCH v2] " Adhemerval Zanella
2021-02-11 16:21     ` Andreas Schwab
2021-02-11 17:10       ` Adhemerval Zanella
2021-02-11 17:33         ` Andreas Schwab
2021-02-11 17:36           ` Adhemerval Zanella
2021-03-08 13:04 ` [PATCH 1/8] posix: Consolidate register-atfork Florian Weimer

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=eca0d704-5d42-e028-41a2-218ca76002e8@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).