Skip to contentSkip to conversation

cpus: Constify some CPUState arguments

PATCH In review Philippe Mathieu-Daudé 3 participants 11 messages Jan 20, 2025 – Oct 30, 2025 KVM

lore
Share & tools
lore
#0 lore raw

cover cpus: Constify some CPUState arguments

This is in preparation of making various CPUClass handlers take a const CPUState argument.

Philippe Mathieu-Daudé (7):
qemu/thread: Constify qemu_thread_get_affinity() 'thread' argument qemu/thread: Constify qemu_thread_is_self() argument
cpus: Constify qemu_cpu_is_self() argument
cpus: Constify cpu_get_address_space() 'cpu' argument
cpus: Constify cpu_is_stopped() argument
cpus: Constify cpu_work_list_empty() argument
accels: Constify AccelOpsClass::cpu_thread_is_idle() argument

 include/hw/core/cpu.h             | 6 +++---
 include/qemu/thread.h             | 6 +++---
 include/system/accel-ops.h        | 2 +-
 include/system/cpus.h             | 2 +-
 accel/kvm/kvm-accel-ops.c         | 2 +-
 bsd-user/main.c                   | 2 +-
 linux-user/main.c                 | 2 +-
 system/cpus.c                     | 6 +++---
 system/physmem.c                  | 2 +-
 target/i386/whpx/whpx-accel-ops.c | 2 +-
 util/qemu-thread-posix.c          | 6 +++---
 util/qemu-thread-win32.c          | 6 +++---
 12 files changed, 22 insertions(+), 22 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/7 qemu/thread: Constify qemu_thread_get_affinity() 'thread' argument

QemuThread structure is not modified, only read.

---
 include/qemu/thread.h    | 4 ++--
 util/qemu-thread-posix.c | 4 ++--
 util/qemu-thread-win32.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
include/qemu/thread.h +2 -2
index 7eba27a7049..d4f44241ef0 100644
@@ -191,8 +191,8 @@ void qemu_thread_create(QemuThread *thread, const char *name,
                         void *arg, int mode);
 int qemu_thread_set_affinity(QemuThread *thread, unsigned long *host_cpus,
                              unsigned long nbits);
-int qemu_thread_get_affinity(QemuThread *thread, unsigned long **host_cpus,
-                             unsigned long *nbits);
+int qemu_thread_get_affinity(const QemuThread *thread,
+                             unsigned long **host_cpus, unsigned long *nbits);
 void *qemu_thread_join(QemuThread *thread);
 void qemu_thread_get_self(QemuThread *thread);
 bool qemu_thread_is_self(QemuThread *thread);
util/qemu-thread-posix.c +2 -2
index 6fff4162ac6..0fc3003ec46 100644
@@ -617,8 +617,8 @@ int qemu_thread_set_affinity(QemuThread *thread, unsigned long *host_cpus,
 #endif
 }
 
-int qemu_thread_get_affinity(QemuThread *thread, unsigned long **host_cpus,
-                             unsigned long *nbits)
+int qemu_thread_get_affinity(const QemuThread *thread,
+                             unsigned long **host_cpus, unsigned long *nbits)
 {
 #if defined(CONFIG_PTHREAD_AFFINITY_NP)
     unsigned long tmpbits;
util/qemu-thread-win32.c +2 -2
index a7fe3cc345f..0d512c0188e 100644
@@ -513,8 +513,8 @@ int qemu_thread_set_affinity(QemuThread *thread, unsigned long *host_cpus,
     return -ENOSYS;
 }
 
-int qemu_thread_get_affinity(QemuThread *thread, unsigned long **host_cpus,
-                             unsigned long *nbits)
+int qemu_thread_get_affinity(const QemuThread *thread,
+                             unsigned long **host_cpus, unsigned long *nbits)
 {
     return -ENOSYS;
 }
Signature · 1 line
2.47.1
#2 lore raw

PATCH 2/7 qemu/thread: Constify qemu_thread_is_self() argument

In reply to Philippe Mathieu-Daudé

QemuThread structure is not modified, only read.

---
 include/qemu/thread.h    | 2 +-
 util/qemu-thread-posix.c | 2 +-
 util/qemu-thread-win32.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/qemu/thread.h +1 -1
index d4f44241ef0..d3027c843bc 100644
@@ -195,7 +195,7 @@ int qemu_thread_get_affinity(const QemuThread *thread,
                              unsigned long **host_cpus, unsigned long *nbits);
 void *qemu_thread_join(QemuThread *thread);
 void qemu_thread_get_self(QemuThread *thread);
-bool qemu_thread_is_self(QemuThread *thread);
+bool qemu_thread_is_self(const QemuThread *thread);
 G_NORETURN void qemu_thread_exit(void *retval);
 void qemu_thread_naming(bool enable);
 
util/qemu-thread-posix.c +1 -1
index 0fc3003ec46..c85421f1a0f 100644
@@ -664,7 +664,7 @@ void qemu_thread_get_self(QemuThread *thread)
     thread->thread = pthread_self();
 }
 
-bool qemu_thread_is_self(QemuThread *thread)
+bool qemu_thread_is_self(const QemuThread *thread)
 {
    return pthread_equal(pthread_self(), thread->thread);
 }
util/qemu-thread-win32.c +1 -1
index 0d512c0188e..08c6543fe51 100644
@@ -546,7 +546,7 @@ HANDLE qemu_thread_get_handle(QemuThread *thread)
     return handle;
 }
 
-bool qemu_thread_is_self(QemuThread *thread)
+bool qemu_thread_is_self(const QemuThread *thread)
 {
     return GetCurrentThreadId() == thread->tid;
 }
Signature · 1 line
2.47.1
#3 lore raw

PATCH 3/7 cpus: Constify qemu_cpu_is_self() argument

In reply to Philippe Mathieu-Daudé

CPUState structure is not modified, make it const.

---
 include/hw/core/cpu.h | 2 +-
 bsd-user/main.c       | 2 +-
 linux-user/main.c     | 2 +-
 system/cpus.c         | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
include/hw/core/cpu.h +1 -1
index fb397cdfc53..782c43ac8b3 100644
@@ -838,7 +838,7 @@ static inline bool cpu_has_work(CPUState *cpu)
  *
  * Returns: %true if called from @cpu's thread, %false otherwise.
  */
-bool qemu_cpu_is_self(CPUState *cpu);
+bool qemu_cpu_is_self(const CPUState *cpu);
 
 /**
  * qemu_cpu_kick:
bsd-user/main.c +1 -1
index b2f6a9be2f2..6dc4512cebf 100644
@@ -205,7 +205,7 @@ void stop_all_tasks(void)
     start_exclusive();
 }
 
-bool qemu_cpu_is_self(CPUState *cpu)
+bool qemu_cpu_is_self(const CPUState *cpu)
 {
     return thread_cpu == cpu;
 }
linux-user/main.c +1 -1
index 7198fa0986b..104704ace96 100644
@@ -181,7 +181,7 @@ void fork_end(pid_t pid)
 
 __thread CPUState *thread_cpu;
 
-bool qemu_cpu_is_self(CPUState *cpu)
+bool qemu_cpu_is_self(const CPUState *cpu)
 {
     return thread_cpu == cpu;
 }
system/cpus.c +1 -1
index 37e5892c240..e4910d670cf 100644
@@ -502,7 +502,7 @@ void qemu_cpu_kick_self(void)
     cpus_kick_thread(current_cpu);
 }
 
-bool qemu_cpu_is_self(CPUState *cpu)
+bool qemu_cpu_is_self(const CPUState *cpu)
 {
     return qemu_thread_is_self(cpu->thread);
 }
Signature · 1 line
2.47.1
#4 lore raw

PATCH 4/7 cpus: Constify cpu_get_address_space() 'cpu' argument

In reply to Philippe Mathieu-Daudé

CPUState structure is not modified, make it const.

---
 include/hw/core/cpu.h | 2 +-
 system/physmem.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/hw/core/cpu.h +1 -1
index 782c43ac8b3..04fede0e69a 100644
@@ -1155,7 +1155,7 @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
  * Return the requested address space of this CPU. @asidx
  * specifies which address space to read.
  */
-AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
+AddressSpace *cpu_get_address_space(const CPUState *cpu, int asidx);
 
 G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)
     G_GNUC_PRINTF(2, 3);
system/physmem.c +1 -1
index c76503aea82..0ac6acb9764 100644
@@ -805,7 +805,7 @@ void cpu_address_space_destroy(CPUState *cpu, int asidx)
     }
 }
 
-AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
+AddressSpace *cpu_get_address_space(const CPUState *cpu, int asidx)
 {
     /* Return the AddressSpace corresponding to the specified index */
     return cpu->cpu_ases[asidx].as;
Signature · 1 line
2.47.1
#5 lore raw

PATCH 5/7 cpus: Constify cpu_is_stopped() argument

In reply to Philippe Mathieu-Daudé

CPUState structure is not modified, make it const.

---
 include/hw/core/cpu.h | 2 +-
 system/cpus.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/hw/core/cpu.h +1 -1
index 04fede0e69a..00c16081396 100644
@@ -857,7 +857,7 @@ void qemu_cpu_kick(CPUState *cpu);
  * Returns: %true if run state is not running or if artificially stopped;
  * %false otherwise.
  */
-bool cpu_is_stopped(CPUState *cpu);
+bool cpu_is_stopped(const CPUState *cpu);
 
 /**
  * do_run_on_cpu:
system/cpus.c +1 -1
index e4910d670cf..5ea124aed0b 100644
@@ -73,7 +73,7 @@ static QemuMutex bql;
  */
 static const AccelOpsClass *cpus_accel;
 
-bool cpu_is_stopped(CPUState *cpu)
+bool cpu_is_stopped(const CPUState *cpu)
 {
     return cpu->stopped || !runstate_is_running();
 }
Signature · 1 line
2.47.1
#6 lore raw

PATCH 6/7 cpus: Constify cpu_work_list_empty() argument

In reply to Philippe Mathieu-Daudé

CPUState structure is not modified, make it const.

---
 include/system/cpus.h | 2 +-
 system/cpus.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/system/cpus.h +1 -1
index 3d8fd368f32..3a364fe61b4 100644
@@ -20,7 +20,7 @@ void dummy_start_vcpu_thread(CPUState *);
 #define VCPU_THREAD_NAME_SIZE 16
 
 void cpus_kick_thread(CPUState *cpu);
-bool cpu_work_list_empty(CPUState *cpu);
+bool cpu_work_list_empty(const CPUState *cpu);
 bool cpu_thread_is_idle(CPUState *cpu);
 bool all_cpu_threads_idle(void);
 bool cpu_can_run(CPUState *cpu);
system/cpus.c +1 -1
index 5ea124aed0b..68add85bdc7 100644
@@ -78,7 +78,7 @@ bool cpu_is_stopped(const CPUState *cpu)
     return cpu->stopped || !runstate_is_running();
 }
 
-bool cpu_work_list_empty(CPUState *cpu)
+bool cpu_work_list_empty(const CPUState *cpu)
 {
     return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list);
 }
Signature · 1 line
2.47.1
#7 lore raw

PATCH 7/7 accels: Constify AccelOpsClass::cpu_thread_is_idle() argument

In reply to Philippe Mathieu-Daudé

If a cpu_thread_is_idle() implementation accesses
@cpu fields, it shouldn't modify them. Make the
argument const in preparation.

---
 include/system/accel-ops.h        | 2 +-
 accel/kvm/kvm-accel-ops.c         | 2 +-
 target/i386/whpx/whpx-accel-ops.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/system/accel-ops.h +1 -1
index 137fb96d444..8cf353105e2 100644
@@ -39,7 +39,7 @@ struct AccelOpsClass {
 
     void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */
     void (*kick_vcpu_thread)(CPUState *cpu);
-    bool (*cpu_thread_is_idle)(CPUState *cpu);
+    bool (*cpu_thread_is_idle)(const CPUState *cpu);
 
     void (*synchronize_post_reset)(CPUState *cpu);
     void (*synchronize_post_init)(CPUState *cpu);
accel/kvm/kvm-accel-ops.c +1 -1
index a81e8f3b03b..3fe26f54d30 100644
@@ -72,7 +72,7 @@ static void kvm_start_vcpu_thread(CPUState *cpu)
                        cpu, QEMU_THREAD_JOINABLE);
 }
 
-static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
+static bool kvm_vcpu_thread_is_idle(const CPUState *cpu)
 {
     return !kvm_halt_in_kernel();
 }
target/i386/whpx/whpx-accel-ops.c +1 -1
index ab2e014c9ea..ae4f1282801 100644
@@ -77,7 +77,7 @@ static void whpx_kick_vcpu_thread(CPUState *cpu)
     }
 }
 
-static bool whpx_vcpu_thread_is_idle(CPUState *cpu)
+static bool whpx_vcpu_thread_is_idle(const CPUState *cpu)
 {
     return !whpx_apic_in_platform();
 }
Signature · 1 line
2.47.1
#8 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

This is in preparation of making various CPUClass handlers take a const CPUState argument.

Philippe Mathieu-Daudé (7):
qemu/thread: Constify qemu_thread_get_affinity() 'thread' argument qemu/thread: Constify qemu_thread_is_self() argument
cpus: Constify qemu_cpu_is_self() argument
cpus: Constify cpu_get_address_space() 'cpu' argument
cpus: Constify cpu_is_stopped() argument
cpus: Constify cpu_work_list_empty() argument
accels: Constify AccelOpsClass::cpu_thread_is_idle() argument

ping?

#9 lore raw
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

This is in preparation of making various CPUClass handlers take a const CPUState argument.

Philippe Mathieu-Daudé (7):
qemu/thread: Constify qemu_thread_get_affinity() 'thread' argument qemu/thread: Constify qemu_thread_is_self() argument
cpus: Constify qemu_cpu_is_self() argument
cpus: Constify cpu_get_address_space() 'cpu' argument
cpus: Constify cpu_is_stopped() argument
cpus: Constify cpu_work_list_empty() argument
accels: Constify AccelOpsClass::cpu_thread_is_idle() argument

Quoted 2 lines

ping?

Hi Philippe, I can't find this series in my mailbox and it's not on lore.kernel.org/patchew/lists.gnu.org either. Resend?

#10 lore raw
Quoted 16 lines · Manos Pitsidianakis
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

This is in preparation of making various CPUClass handlers take a const CPUState argument.

Philippe Mathieu-Daudé (7):
qemu/thread: Constify qemu_thread_get_affinity() 'thread' argument qemu/thread: Constify qemu_thread_is_self() argument
cpus: Constify qemu_cpu_is_self() argument
cpus: Constify cpu_get_address_space() 'cpu' argument
cpus: Constify cpu_is_stopped() argument
cpus: Constify cpu_work_list_empty() argument
accels: Constify AccelOpsClass::cpu_thread_is_idle() argument

Quoted 6 lines
Quoted 2 lines

ping?

Hi Philippe, I can't find this series in my mailbox and it's not on lore.kernel.org/patchew/lists.gnu.org either. Resend?

Hi,

Looks like it landed on the kvm mailing list via Cc but was left out of qemu-devel, despite the seemingly correct To header:

https://lore.kernel.org/kvm/[email protected]/

Regards,
Yodel