public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] Remove cached PID/TID in clone
Date: Tue, 08 Nov 2016 20:37:00 -0000	[thread overview]
Message-ID: <d3453042-f7ba-d43e-09c8-b3831aab1d2c@linaro.org> (raw)
In-Reply-To: <878tstu3yc.fsf@mid.deneb.enyo.de>



On 08/11/2016 18:11, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>>> It's a hotspot for incorrect/broken fork detection.
>>
>> If you mean the assert on fork.c, I review the code and it seems
>> unnecessary to remove the assert on child creation:
> 
> No, something else entirely.  OpenSSL mixes the current PID into the
> randomness pool, in an attempt to make sure that the streams generated
> by parent and child are different:
> 
>     pid_t curr_pid = getpid();
> …
>         if (curr_pid) {         /* just in the first iteration to save time */
>             if (!MD_Update(m, (unsigned char *)&curr_pid, sizeof curr_pid))
>                 goto err;
>             curr_pid = 0;
>         }
> 
> <https://github.com/openssl/openssl/blob/master/crypto/rand/md_rand.c#L283>
> 
> This happens at every invocation of RAND_bytes.  It may show up in
> profiles if all the other system calls (time, gettimeofday etc.) are
> handled by the vDSO.
> 
> But I suggest that this shouldn't block your change.  It's just
> something we should be aware of.  If the kernel provides a more
> efficient way to get the PID, we can change glibc to use it.
> 
> More comments about your revised patch tomorrow.
> 

Right, I referenced a quite old discussion about the pid caching
and the randomness provided by getpid [1].  And I think that an
portable application like OpenSSL should not rely on an specific
getpid implementation in a hotspot call, since on mostly 
implementations it will likely be a syscall.

[1] http://yarchive.net/comp/linux/getpid_caching.html

  reply	other threads:[~2016-11-08 20:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-13 19:45 Adhemerval Zanella
2016-10-26 17:59 ` Adhemerval Zanella
2016-11-07 17:21 ` Florian Weimer
2016-11-08 19:58   ` Adhemerval Zanella
2016-11-08 20:11     ` Florian Weimer
2016-11-08 20:37       ` Adhemerval Zanella [this message]
2016-11-08 20:44         ` Florian Weimer
2016-11-09 12:18     ` Florian Weimer
2016-11-15 14:27       ` Adhemerval Zanella
2016-11-15 14:30         ` Florian Weimer
2016-11-24 21:24           ` Adhemerval Zanella
2016-11-25 10:50             ` 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=d3453042-f7ba-d43e-09c8-b3831aab1d2c@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fw@deneb.enyo.de \
    --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).