Skip to contentSkip to conversation

linux-user: open_self_stat: Implement num_threads

PATCH In review Fabio D'Urso 2 participants 2 messages Jun 19, 2024 – Jun 20, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: open_self_stat: Implement num_threads

The num_threads field reports the total number of threads in the process. In QEMU, this is equal to the number of CPU instances.

---
 linux-user/syscall.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
linux-user/syscall.c +10 -0
index b9b5a387b3..a47b2eeb65 100644
@@ -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);
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Fabio D'Urso

The num_threads field reports the total number of threads in the process. In QEMU, this is equal to the number of CPU instances.

---
 linux-user/syscall.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
linux-user/syscall.c +0 -0
index b9b5a387b3..a47b2eeb65 100644
@@ -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());

linux-user/syscall.c static int open_self_stat(CPUArchState *cpu_env, int fd) · line 8183

Quoted 10 lines
linux-user/syscall.c +10 -0
+        } 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.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro