* [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850]
@ 2022-02-01 21:56 Gleb Fotengauer-Malinovskiy
2022-02-01 22:14 ` [PATCH v2] " Gleb Fotengauer-Malinovskiy
2022-02-01 22:14 ` [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes " Dmitry V. Levin
0 siblings, 2 replies; 7+ messages in thread
From: Gleb Fotengauer-Malinovskiy @ 2022-02-01 21:56 UTC (permalink / raw)
To: libc-alpha
---
sysdeps/unix/sysv/linux/getsysstats.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 4798cc337e..5436bdb507 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -41,6 +41,7 @@ __get_nprocs_sched (void)
/* This cannot use malloc because it is used on malloc initialization. */
__cpu_mask cpu_bits[cpu_bits_size / sizeof (__cpu_mask)];
+ CPU_ZERO_S(cpu_bits_size, cpu_bits);
int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
cpu_bits);
if (r > 0)
--
glebfm
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850]
2022-02-01 21:56 [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850] Gleb Fotengauer-Malinovskiy
@ 2022-02-01 22:14 ` Gleb Fotengauer-Malinovskiy
2022-02-01 22:22 ` Dmitry V. Levin
2022-02-01 22:33 ` Andreas Schwab
2022-02-01 22:14 ` [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes " Dmitry V. Levin
1 sibling, 2 replies; 7+ messages in thread
From: Gleb Fotengauer-Malinovskiy @ 2022-02-01 22:14 UTC (permalink / raw)
To: libc-alpha
---
sysdeps/unix/sysv/linux/getsysstats.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 4798cc337e..b0a7663f56 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -41,6 +41,7 @@ __get_nprocs_sched (void)
/* This cannot use malloc because it is used on malloc initialization. */
__cpu_mask cpu_bits[cpu_bits_size / sizeof (__cpu_mask)];
+ CPU_ZERO_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
cpu_bits);
if (r > 0)
--
glebfm
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850]
2022-02-01 21:56 [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850] Gleb Fotengauer-Malinovskiy
2022-02-01 22:14 ` [PATCH v2] " Gleb Fotengauer-Malinovskiy
@ 2022-02-01 22:14 ` Dmitry V. Levin
1 sibling, 0 replies; 7+ messages in thread
From: Dmitry V. Levin @ 2022-02-01 22:14 UTC (permalink / raw)
To: Gleb Fotengauer-Malinovskiy; +Cc: libc-alpha
On Tue, Feb 01, 2022 at 09:56:44PM +0000, Gleb Fotengauer-Malinovskiy wrote:
> ---
> sysdeps/unix/sysv/linux/getsysstats.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
> index 4798cc337e..5436bdb507 100644
> --- a/sysdeps/unix/sysv/linux/getsysstats.c
> +++ b/sysdeps/unix/sysv/linux/getsysstats.c
> @@ -41,6 +41,7 @@ __get_nprocs_sched (void)
>
> /* This cannot use malloc because it is used on malloc initialization. */
> __cpu_mask cpu_bits[cpu_bits_size / sizeof (__cpu_mask)];
> + CPU_ZERO_S(cpu_bits_size, cpu_bits);
Good catch!
Please cast cpu_bits to "cpu_set_t*" to make this CPU_ZERO_S invocation
consistent with the CPU_COUNT_S invocation below.
Also, please add a space between CPU_ZERO_S and the opening parenthesis.
--
ldv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850]
2022-02-01 22:14 ` [PATCH v2] " Gleb Fotengauer-Malinovskiy
@ 2022-02-01 22:22 ` Dmitry V. Levin
2022-02-01 22:33 ` Andreas Schwab
1 sibling, 0 replies; 7+ messages in thread
From: Dmitry V. Levin @ 2022-02-01 22:22 UTC (permalink / raw)
To: Gleb Fotengauer-Malinovskiy; +Cc: libc-alpha
On Tue, Feb 01, 2022 at 10:14:07PM +0000, Gleb Fotengauer-Malinovskiy wrote:
> ---
> sysdeps/unix/sysv/linux/getsysstats.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
> index 4798cc337e..b0a7663f56 100644
> --- a/sysdeps/unix/sysv/linux/getsysstats.c
> +++ b/sysdeps/unix/sysv/linux/getsysstats.c
> @@ -41,6 +41,7 @@ __get_nprocs_sched (void)
>
> /* This cannot use malloc because it is used on malloc initialization. */
> __cpu_mask cpu_bits[cpu_bits_size / sizeof (__cpu_mask)];
> + CPU_ZERO_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
> int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
> cpu_bits);
> if (r > 0)
Fixes: 33099d72e41c ("linux: Simplify get_nprocs")
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
--
ldv
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850]
2022-02-01 22:14 ` [PATCH v2] " Gleb Fotengauer-Malinovskiy
2022-02-01 22:22 ` Dmitry V. Levin
@ 2022-02-01 22:33 ` Andreas Schwab
2022-02-01 22:44 ` [PATCH v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage " Gleb Fotengauer-Malinovskiy
1 sibling, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2022-02-01 22:33 UTC (permalink / raw)
To: Gleb Fotengauer-Malinovskiy; +Cc: libc-alpha
On Feb 01 2022, Gleb Fotengauer-Malinovskiy wrote:
> ---
> sysdeps/unix/sysv/linux/getsysstats.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
> index 4798cc337e..b0a7663f56 100644
> --- a/sysdeps/unix/sysv/linux/getsysstats.c
> +++ b/sysdeps/unix/sysv/linux/getsysstats.c
> @@ -41,6 +41,7 @@ __get_nprocs_sched (void)
>
> /* This cannot use malloc because it is used on malloc initialization. */
> __cpu_mask cpu_bits[cpu_bits_size / sizeof (__cpu_mask)];
> + CPU_ZERO_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
> int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
> cpu_bits);
> if (r > 0)
r is the actual size of the cpu mask, which can conveniently be passed
to CPU_COUNT_S.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850]
2022-02-01 22:33 ` Andreas Schwab
@ 2022-02-01 22:44 ` Gleb Fotengauer-Malinovskiy
2022-02-01 22:46 ` Dmitry V. Levin
0 siblings, 1 reply; 7+ messages in thread
From: Gleb Fotengauer-Malinovskiy @ 2022-02-01 22:44 UTC (permalink / raw)
To: libc-alpha
Pass the actual number of bytes returned by the kernel.
Fixes: 33099d72e41c ("linux: Simplify get_nprocs")
---
sysdeps/unix/sysv/linux/getsysstats.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 4798cc337e..c98c8ce3d4 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -44,7 +44,7 @@ __get_nprocs_sched (void)
int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
cpu_bits);
if (r > 0)
- return CPU_COUNT_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
+ return CPU_COUNT_S (r, (cpu_set_t*) cpu_bits);
else if (r == -EINVAL)
/* The input buffer is still not enough to store the number of cpus. This
is an arbitrary values assuming such systems should be rare and there
--
glebfm
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage [BZ #28850]
2022-02-01 22:44 ` [PATCH v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage " Gleb Fotengauer-Malinovskiy
@ 2022-02-01 22:46 ` Dmitry V. Levin
0 siblings, 0 replies; 7+ messages in thread
From: Dmitry V. Levin @ 2022-02-01 22:46 UTC (permalink / raw)
To: Gleb Fotengauer-Malinovskiy; +Cc: libc-alpha
On Tue, Feb 01, 2022 at 10:44:46PM +0000, Gleb Fotengauer-Malinovskiy wrote:
> Pass the actual number of bytes returned by the kernel.
>
> Fixes: 33099d72e41c ("linux: Simplify get_nprocs")
> ---
> sysdeps/unix/sysv/linux/getsysstats.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
> index 4798cc337e..c98c8ce3d4 100644
> --- a/sysdeps/unix/sysv/linux/getsysstats.c
> +++ b/sysdeps/unix/sysv/linux/getsysstats.c
> @@ -44,7 +44,7 @@ __get_nprocs_sched (void)
> int r = INTERNAL_SYSCALL_CALL (sched_getaffinity, 0, cpu_bits_size,
> cpu_bits);
> if (r > 0)
> - return CPU_COUNT_S (cpu_bits_size, (cpu_set_t*) cpu_bits);
> + return CPU_COUNT_S (r, (cpu_set_t*) cpu_bits);
> else if (r == -EINVAL)
> /* The input buffer is still not enough to store the number of cpus. This
> is an arbitrary values assuming such systems should be rare and there
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
--
ldv
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-02-01 22:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 21:56 [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes [BZ #28850] Gleb Fotengauer-Malinovskiy
2022-02-01 22:14 ` [PATCH v2] " Gleb Fotengauer-Malinovskiy
2022-02-01 22:22 ` Dmitry V. Levin
2022-02-01 22:33 ` Andreas Schwab
2022-02-01 22:44 ` [PATCH v3] linux: __get_nprocs_sched: do not feed CPU_COUNT_S with garbage " Gleb Fotengauer-Malinovskiy
2022-02-01 22:46 ` Dmitry V. Levin
2022-02-01 22:14 ` [PATCH] linux: __get_nprocs_sched: initialize cpu_bits array with zeroes " Dmitry V. Levin
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).