public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3] stdlib: Tuned down tst-arc4random-thread internal parameters
@ 2022-07-28 12:44 Adhemerval Zanella
  2022-07-28 14:14 ` Szabolcs Nagy
  0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2022-07-28 12:44 UTC (permalink / raw)
  To: libc-alpha, Florian Weimer, Carlos O'Donell, Szabolcs Nagy

With new arc4random implementation, the internal parameters might
require a lot of runtime and/or trigger some contention on older
kernels (which might trigger spurious timeout failures).

Also, since we are now testing getrandom entropy instead of an
userspace RNG, there is no much need to extensive testing.

With this change the tst-arc4random-thread goes from about 1m to
5s on a Ryzen 9 with 5.15.0-41-generic.

Checked on x86_64-linux-gnu.
---
 stdlib/tst-arc4random-thread.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/stdlib/tst-arc4random-thread.c b/stdlib/tst-arc4random-thread.c
index 3373d4d446..daba828fad 100644
--- a/stdlib/tst-arc4random-thread.c
+++ b/stdlib/tst-arc4random-thread.c
@@ -17,23 +17,23 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <array_length.h>
+#include <sched.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
 #include <support/check.h>
 #include <support/namespace.h>
 #include <support/support.h>
 #include <support/xthread.h>
 
 /* Number of arc4random_buf calls per thread.  */
-enum { count_per_thread = 5000 };
+enum { count_per_thread = 2048 };
 
 /* Number of threads computing randomness.  */
-enum { inner_threads = 5 };
+enum { inner_threads = 4 };
 
-/* Number of threads launching other threads.  Chosen as to not to
-   overload the system.  */
-enum { outer_threads = 7 };
+/* Number of threads launching other threads.  */
+static int outer_threads = 1;
 
 /* Number of launching rounds performed by the outer threads.  */
 enum { outer_rounds = 10 };
@@ -331,6 +331,18 @@ do_test_func (const char *fname, void (*func)(unsigned char *, size_t))
 static int
 do_test (void)
 {
+  /* Do not run more threads than the maximum of schedulable CPUs.  */
+  cpu_set_t cpuset;
+  if (sched_getaffinity (0, sizeof cpuset, &cpuset) == 0)
+    {
+      unsigned int ncpus = CPU_COUNT (&cpuset);
+      /* Limit the number to not overload the system.  */
+      outer_threads = (ncpus / 2) / inner_threads ?: 1;
+    }
+
+  printf ("info: outer_threads=%d inner_threads=%d\n", outer_threads,
+	  inner_threads);
+
   do_test_func ("arc4random", generate_arc4random);
   do_test_func ("arc4random_buf", generate_arc4random_buf);
   do_test_func ("arc4random_uniform", generate_arc4random_uniform);
-- 
2.34.1


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

* Re: [PATCH v3] stdlib: Tuned down tst-arc4random-thread internal parameters
  2022-07-28 12:44 [PATCH v3] stdlib: Tuned down tst-arc4random-thread internal parameters Adhemerval Zanella
@ 2022-07-28 14:14 ` Szabolcs Nagy
  2022-07-29 12:15   ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2022-07-28 14:14 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha, Florian Weimer, Carlos O'Donell

The 07/28/2022 09:44, Adhemerval Zanella wrote:
> With new arc4random implementation, the internal parameters might
> require a lot of runtime and/or trigger some contention on older
> kernels (which might trigger spurious timeout failures).
> 
> Also, since we are now testing getrandom entropy instead of an
> userspace RNG, there is no much need to extensive testing.
> 
> With this change the tst-arc4random-thread goes from about 1m to
> 5s on a Ryzen 9 with 5.15.0-41-generic.
> 
> Checked on x86_64-linux-gnu.

thanks, this looks good.

Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

> ---
>  stdlib/tst-arc4random-thread.c | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/stdlib/tst-arc4random-thread.c b/stdlib/tst-arc4random-thread.c
> index 3373d4d446..daba828fad 100644
> --- a/stdlib/tst-arc4random-thread.c
> +++ b/stdlib/tst-arc4random-thread.c
> @@ -17,23 +17,23 @@
>     <https://www.gnu.org/licenses/>.  */
>  
>  #include <array_length.h>
> +#include <sched.h>
>  #include <stdio.h>
> -#include <string.h>
>  #include <stdlib.h>
> +#include <string.h>
>  #include <support/check.h>
>  #include <support/namespace.h>
>  #include <support/support.h>
>  #include <support/xthread.h>
>  
>  /* Number of arc4random_buf calls per thread.  */
> -enum { count_per_thread = 5000 };
> +enum { count_per_thread = 2048 };
>  
>  /* Number of threads computing randomness.  */
> -enum { inner_threads = 5 };
> +enum { inner_threads = 4 };
>  
> -/* Number of threads launching other threads.  Chosen as to not to
> -   overload the system.  */
> -enum { outer_threads = 7 };
> +/* Number of threads launching other threads.  */
> +static int outer_threads = 1;
>  
>  /* Number of launching rounds performed by the outer threads.  */
>  enum { outer_rounds = 10 };
> @@ -331,6 +331,18 @@ do_test_func (const char *fname, void (*func)(unsigned char *, size_t))
>  static int
>  do_test (void)
>  {
> +  /* Do not run more threads than the maximum of schedulable CPUs.  */
> +  cpu_set_t cpuset;
> +  if (sched_getaffinity (0, sizeof cpuset, &cpuset) == 0)
> +    {
> +      unsigned int ncpus = CPU_COUNT (&cpuset);
> +      /* Limit the number to not overload the system.  */
> +      outer_threads = (ncpus / 2) / inner_threads ?: 1;
> +    }
> +
> +  printf ("info: outer_threads=%d inner_threads=%d\n", outer_threads,
> +	  inner_threads);
> +
>    do_test_func ("arc4random", generate_arc4random);
>    do_test_func ("arc4random_buf", generate_arc4random_buf);
>    do_test_func ("arc4random_uniform", generate_arc4random_uniform);
> -- 
> 2.34.1
> 

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

* Re: [PATCH v3] stdlib: Tuned down tst-arc4random-thread internal parameters
  2022-07-28 14:14 ` Szabolcs Nagy
@ 2022-07-29 12:15   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella Netto @ 2022-07-29 12:15 UTC (permalink / raw)
  To: Szabolcs Nagy; +Cc: libc-alpha, Florian Weimer, Carlos O'Donell



On 28/07/22 11:14, Szabolcs Nagy wrote:
> The 07/28/2022 09:44, Adhemerval Zanella wrote:
>> With new arc4random implementation, the internal parameters might
>> require a lot of runtime and/or trigger some contention on older
>> kernels (which might trigger spurious timeout failures).
>>
>> Also, since we are now testing getrandom entropy instead of an
>> userspace RNG, there is no much need to extensive testing.
>>
>> With this change the tst-arc4random-thread goes from about 1m to
>> 5s on a Ryzen 9 with 5.15.0-41-generic.
>>
>> Checked on x86_64-linux-gnu.
> 
> thanks, this looks good.
> 
> Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>

Thanks, I will commit this shortly since this is most likely required
to have a clean make check.

> 
>> ---
>>  stdlib/tst-arc4random-thread.c | 24 ++++++++++++++++++------
>>  1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/stdlib/tst-arc4random-thread.c b/stdlib/tst-arc4random-thread.c
>> index 3373d4d446..daba828fad 100644
>> --- a/stdlib/tst-arc4random-thread.c
>> +++ b/stdlib/tst-arc4random-thread.c
>> @@ -17,23 +17,23 @@
>>     <https://www.gnu.org/licenses/>.  */
>>  
>>  #include <array_length.h>
>> +#include <sched.h>
>>  #include <stdio.h>
>> -#include <string.h>
>>  #include <stdlib.h>
>> +#include <string.h>
>>  #include <support/check.h>
>>  #include <support/namespace.h>
>>  #include <support/support.h>
>>  #include <support/xthread.h>
>>  
>>  /* Number of arc4random_buf calls per thread.  */
>> -enum { count_per_thread = 5000 };
>> +enum { count_per_thread = 2048 };
>>  
>>  /* Number of threads computing randomness.  */
>> -enum { inner_threads = 5 };
>> +enum { inner_threads = 4 };
>>  
>> -/* Number of threads launching other threads.  Chosen as to not to
>> -   overload the system.  */
>> -enum { outer_threads = 7 };
>> +/* Number of threads launching other threads.  */
>> +static int outer_threads = 1;
>>  
>>  /* Number of launching rounds performed by the outer threads.  */
>>  enum { outer_rounds = 10 };
>> @@ -331,6 +331,18 @@ do_test_func (const char *fname, void (*func)(unsigned char *, size_t))
>>  static int
>>  do_test (void)
>>  {
>> +  /* Do not run more threads than the maximum of schedulable CPUs.  */
>> +  cpu_set_t cpuset;
>> +  if (sched_getaffinity (0, sizeof cpuset, &cpuset) == 0)
>> +    {
>> +      unsigned int ncpus = CPU_COUNT (&cpuset);
>> +      /* Limit the number to not overload the system.  */
>> +      outer_threads = (ncpus / 2) / inner_threads ?: 1;
>> +    }
>> +
>> +  printf ("info: outer_threads=%d inner_threads=%d\n", outer_threads,
>> +	  inner_threads);
>> +
>>    do_test_func ("arc4random", generate_arc4random);
>>    do_test_func ("arc4random_buf", generate_arc4random_buf);
>>    do_test_func ("arc4random_uniform", generate_arc4random_uniform);
>> -- 
>> 2.34.1
>>

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

end of thread, other threads:[~2022-07-29 12:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-28 12:44 [PATCH v3] stdlib: Tuned down tst-arc4random-thread internal parameters Adhemerval Zanella
2022-07-28 14:14 ` Szabolcs Nagy
2022-07-29 12:15   ` Adhemerval Zanella Netto

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