[PATCH] linux-user: open_self_stat: Implement num_threads

Fabio D'Urso posted 1 patch 5 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240619194109.248066-1-fdurso@google.com
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/syscall.c | 10 ++++++++++
1 file changed, 10 insertions(+)
[PATCH] linux-user: open_self_stat: Implement num_threads
Posted by Fabio D'Urso 5 months, 1 week ago
The num_threads field reports the total number of threads in the
process. In QEMU, this is equal to the number of CPU instances.

Signed-off-by: Fabio D'Urso <fdurso@google.com>
---
 linux-user/syscall.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b9b5a387b3..a47b2eeb65 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8171,6 +8171,16 @@ static int open_self_stat(CPUArchState *cpu_env, int fd)
         } else if (i == 3) {
             /* ppid */
             g_string_printf(buf, FMT_pid " ", getppid());
+        } else if (i == 19) {
+            /* num_threads */
+            int cpus = 0;
+            WITH_RCU_READ_LOCK_GUARD() {
+                CPUState *cpu_iter;
+                CPU_FOREACH(cpu_iter) {
+                    cpus++;
+                }
+            }
+            g_string_printf(buf, "%d ", cpus);
         } else if (i == 21) {
             /* starttime */
             g_string_printf(buf, "%" PRIu64 " ", ts->start_boottime);
-- 
2.45.2.627.g7a2c4fd464-goog
Re: [PATCH] linux-user: open_self_stat: Implement num_threads
Posted by Alex Bennée 5 months, 1 week ago
"Fabio D'Urso" <fdurso@google.com> writes:

> The num_threads field reports the total number of threads in the
> process. In QEMU, this is equal to the number of CPU instances.
>
> Signed-off-by: Fabio D'Urso <fdurso@google.com>
> ---
>  linux-user/syscall.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index b9b5a387b3..a47b2eeb65 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -8171,6 +8171,16 @@ static int open_self_stat(CPUArchState *cpu_env, int fd)
>          } else if (i == 3) {
>              /* ppid */
>              g_string_printf(buf, FMT_pid " ", getppid());
> +        } else if (i == 19) {
> +            /* num_threads */
> +            int cpus = 0;
> +            WITH_RCU_READ_LOCK_GUARD() {
> +                CPUState *cpu_iter;
> +                CPU_FOREACH(cpu_iter) {
> +                    cpus++;
> +                }
> +            }
> +            g_string_printf(buf, "%d ", cpus);

Looks ok to me.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro