public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [RFC] powerpc: optimizing random() and POSIX question
@ 2020-02-11 14:04 Raphael M Zinsly
  2020-02-11 14:43 ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Raphael M Zinsly @ 2020-02-11 14:04 UTC (permalink / raw)
  To: libc-alpha; +Cc: Tulio Magno Quites Machado Filho, Paul Clarke

Hi,

I’m investigating ways to optimize random() for powerpc and got some 
questions regarding POSIX.
The current code on stdlib/random.c does:

long int
__random (void)
{
   int32_t retval;

   __libc_lock_lock (lock);

   (void) __random_r (&unsafe_state, &retval);

   __libc_lock_unlock (lock);

   return retval;
}

If I remove the lock in order to use lqarx/stqcx to access fptr and rptr 
(that are adjacents), then compute the result as is done in random_r, 
will this still be compliant with POSIX?
As the data is accessed atomically, only one thread access the critical 
section at a time. Am I missing something?


Thanks,
-- 
Raphael Moreira Zinsly
IBM
Linux on Power Toolchain

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [RFC] powerpc: optimizing random() and POSIX question
@ 2020-02-12 15:05 Wilco Dijkstra
  0 siblings, 0 replies; 6+ messages in thread
From: Wilco Dijkstra @ 2020-02-12 15:05 UTC (permalink / raw)
  To: 'GNU C Library', rzinsly; +Cc: tuliom, Paul Clarke

Hi,

Wouldn't the easiest and safest option to be just add the single-threaded check
so 99% of applications just bypass the locks?

Also I would strongly suggest to optimize the generic code first - target-specific
optimizations are almost always counter productive in the long term.

Cheers,
Wilco

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-02-12 15:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-11 14:04 [RFC] powerpc: optimizing random() and POSIX question Raphael M Zinsly
2020-02-11 14:43 ` Florian Weimer
2020-02-12 13:22   ` Raphael M Zinsly
2020-02-12 13:23     ` Florian Weimer
2020-02-12 14:20       ` Adhemerval Zanella
2020-02-12 15:05 Wilco Dijkstra

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).