[Qemu-devel] [PULL v3 08/14] Add a 'name' parameter to qemu_thread_create
From: "Dr. David Alan Gilbert"If enabled, set the thread name at creation (on GNU systems with pthread_set_np) Fix up all the callers with a thread name Signed-off-by: Dr. David Alan Gilbert Acked-by: Michael S. Tsirkin Reviewed-by: Laszlo Ersek --- include/qemu/thread.h | 2 +- cpus.c | 25 - hw/block/dataplane/virtio-blk.c | 2 +- hw/usb/ccid-card-emulated.c | 8 libcacard/vscclient.c | 2 +- migration.c | 2 +- thread-pool.c | 2 +- ui/vnc-jobs.c | 3 ++- util/compatfd.c | 3 ++- util/qemu-thread-posix.c| 9 +++-- util/qemu-thread-win32.c| 2 +- 11 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index bf1e110..f7e3b9b 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -52,7 +52,7 @@ void qemu_event_reset(QemuEvent *ev); void qemu_event_wait(QemuEvent *ev); void qemu_event_destroy(QemuEvent *ev); -void qemu_thread_create(QemuThread *thread, +void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), void *arg, int mode); void *qemu_thread_join(QemuThread *thread); diff --git a/cpus.c b/cpus.c index 945d85b..b6421fd 100644 --- a/cpus.c +++ b/cpus.c @@ -1117,8 +1117,13 @@ void resume_all_vcpus(void) } } +/* For temporary buffers for forming a name */ +#define VCPU_THREAD_NAME_SIZE 16 + static void qemu_tcg_init_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + tcg_cpu_address_space_init(cpu, cpu->as); /* share a single thread for all cpus with TCG */ @@ -1127,8 +1132,10 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) cpu->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu->halt_cond); tcg_halt_cond = cpu->halt_cond; -qemu_thread_create(cpu->thread, qemu_tcg_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", + cpu->cpu_index); +qemu_thread_create(cpu->thread, thread_name, qemu_tcg_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); #ifdef _WIN32 cpu->hThread = qemu_thread_get_handle(cpu->thread); #endif @@ -1144,11 +1151,15 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) static void qemu_kvm_start_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + cpu->thread = g_malloc0(sizeof(QemuThread)); cpu->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu->halt_cond); -qemu_thread_create(cpu->thread, qemu_kvm_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", + cpu->cpu_index); +qemu_thread_create(cpu->thread, thread_name, qemu_kvm_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); while (!cpu->created) { qemu_cond_wait(_cpu_cond, _global_mutex); } @@ -1156,10 +1167,14 @@ static void qemu_kvm_start_vcpu(CPUState *cpu) static void qemu_dummy_start_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + cpu->thread = g_malloc0(sizeof(QemuThread)); cpu->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu->halt_cond); -qemu_thread_create(cpu->thread, qemu_dummy_cpu_thread_fn, cpu, +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY", + cpu->cpu_index); +qemu_thread_create(cpu->thread, thread_name, qemu_dummy_cpu_thread_fn, cpu, QEMU_THREAD_JOINABLE); while (!cpu->created) { qemu_cond_wait(_cpu_cond, _global_mutex); diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 2237edb..d1c7ad4 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -358,7 +358,7 @@ static void start_data_plane_bh(void *opaque) qemu_bh_delete(s->start_bh); s->start_bh = NULL; -qemu_thread_create(>thread, data_plane_thread, +qemu_thread_create(>thread, "data_plane", data_plane_thread, s, QEMU_THREAD_JOINABLE); } diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index aa913df..7213c89 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -546,10 +546,10 @@ static int emulated_initfn(CCIDCardState *base) printf("%s: failed to initialize vcard\n", EMULATED_DEV_NAME); return -1; } -qemu_thread_create(>event_thread_id, event_thread, card, - QEMU_THREAD_JOINABLE); -qemu_thread_create(>apdu_thread_id, handle_apdu_thread, card, - QEMU_THREAD_JOINABLE); +
Re: [Qemu-devel] [PULL v3 08/14] Add a 'name' parameter to qemu_thread_create
On 2014-03-09 20:20, Michael S. Tsirkin wrote: From: Dr. David Alan Gilbert dgilb...@redhat.com If enabled, set the thread name at creation (on GNU systems with pthread_set_np) Fix up all the callers with a thread name Seems like not all older Linux systems come with support for pthread_setname_np. Just ran into a linker bug on a box with glib 2.11. Can we discover the availability, if nothing helps during configure? Thanks, Jan Signed-off-by: Dr. David Alan Gilbert dgilb...@redhat.com Acked-by: Michael S. Tsirkin m...@redhat.com Reviewed-by: Laszlo Ersek ler...@redhat.com --- include/qemu/thread.h | 2 +- cpus.c | 25 - hw/block/dataplane/virtio-blk.c | 2 +- hw/usb/ccid-card-emulated.c | 8 libcacard/vscclient.c | 2 +- migration.c | 2 +- thread-pool.c | 2 +- ui/vnc-jobs.c | 3 ++- util/compatfd.c | 3 ++- util/qemu-thread-posix.c| 9 +++-- util/qemu-thread-win32.c| 2 +- 11 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index bf1e110..f7e3b9b 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -52,7 +52,7 @@ void qemu_event_reset(QemuEvent *ev); void qemu_event_wait(QemuEvent *ev); void qemu_event_destroy(QemuEvent *ev); -void qemu_thread_create(QemuThread *thread, +void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), void *arg, int mode); void *qemu_thread_join(QemuThread *thread); diff --git a/cpus.c b/cpus.c index 945d85b..b6421fd 100644 --- a/cpus.c +++ b/cpus.c @@ -1117,8 +1117,13 @@ void resume_all_vcpus(void) } } +/* For temporary buffers for forming a name */ +#define VCPU_THREAD_NAME_SIZE 16 + static void qemu_tcg_init_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + tcg_cpu_address_space_init(cpu, cpu-as); /* share a single thread for all cpus with TCG */ @@ -1127,8 +1132,10 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) cpu-halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu-halt_cond); tcg_halt_cond = cpu-halt_cond; -qemu_thread_create(cpu-thread, qemu_tcg_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, CPU %d/TCG, + cpu-cpu_index); +qemu_thread_create(cpu-thread, thread_name, qemu_tcg_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); #ifdef _WIN32 cpu-hThread = qemu_thread_get_handle(cpu-thread); #endif @@ -1144,11 +1151,15 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) static void qemu_kvm_start_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + cpu-thread = g_malloc0(sizeof(QemuThread)); cpu-halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu-halt_cond); -qemu_thread_create(cpu-thread, qemu_kvm_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, CPU %d/KVM, + cpu-cpu_index); +qemu_thread_create(cpu-thread, thread_name, qemu_kvm_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); while (!cpu-created) { qemu_cond_wait(qemu_cpu_cond, qemu_global_mutex); } @@ -1156,10 +1167,14 @@ static void qemu_kvm_start_vcpu(CPUState *cpu) static void qemu_dummy_start_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + cpu-thread = g_malloc0(sizeof(QemuThread)); cpu-halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu-halt_cond); -qemu_thread_create(cpu-thread, qemu_dummy_cpu_thread_fn, cpu, +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, CPU %d/DUMMY, + cpu-cpu_index); +qemu_thread_create(cpu-thread, thread_name, qemu_dummy_cpu_thread_fn, cpu, QEMU_THREAD_JOINABLE); while (!cpu-created) { qemu_cond_wait(qemu_cpu_cond, qemu_global_mutex); diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 2237edb..d1c7ad4 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -358,7 +358,7 @@ static void start_data_plane_bh(void *opaque) qemu_bh_delete(s-start_bh); s-start_bh = NULL; -qemu_thread_create(s-thread, data_plane_thread, +qemu_thread_create(s-thread, data_plane, data_plane_thread, s, QEMU_THREAD_JOINABLE); } diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index aa913df..7213c89 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -546,10 +546,10 @@ static int emulated_initfn(CCIDCardState
Re: [Qemu-devel] [PULL v3 08/14] Add a 'name' parameter to qemu_thread_create
* Jan Kiszka (jan.kis...@siemens.com) wrote: On 2014-03-09 20:20, Michael S. Tsirkin wrote: From: Dr. David Alan Gilbert dgilb...@redhat.com If enabled, set the thread name at creation (on GNU systems with pthread_set_np) Fix up all the callers with a thread name Seems like not all older Linux systems come with support for pthread_setname_np. Just ran into a linker bug on a box with glib 2.11. Can we discover the availability, if nothing helps during configure? Gah - sorry about that; so either we can: 1) Put a compile/link test in configure 2) I could wrap it in #if __GLIBC_PREREQ(2,12) any preference? Thanks, Jan Thanks for spotting it. Dave -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK
[Qemu-devel] [PULL v3 08/14] Add a 'name' parameter to qemu_thread_create
From: Dr. David Alan Gilbert dgilb...@redhat.com If enabled, set the thread name at creation (on GNU systems with pthread_set_np) Fix up all the callers with a thread name Signed-off-by: Dr. David Alan Gilbert dgilb...@redhat.com Acked-by: Michael S. Tsirkin m...@redhat.com Reviewed-by: Laszlo Ersek ler...@redhat.com --- include/qemu/thread.h | 2 +- cpus.c | 25 - hw/block/dataplane/virtio-blk.c | 2 +- hw/usb/ccid-card-emulated.c | 8 libcacard/vscclient.c | 2 +- migration.c | 2 +- thread-pool.c | 2 +- ui/vnc-jobs.c | 3 ++- util/compatfd.c | 3 ++- util/qemu-thread-posix.c| 9 +++-- util/qemu-thread-win32.c| 2 +- 11 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index bf1e110..f7e3b9b 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -52,7 +52,7 @@ void qemu_event_reset(QemuEvent *ev); void qemu_event_wait(QemuEvent *ev); void qemu_event_destroy(QemuEvent *ev); -void qemu_thread_create(QemuThread *thread, +void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), void *arg, int mode); void *qemu_thread_join(QemuThread *thread); diff --git a/cpus.c b/cpus.c index 945d85b..b6421fd 100644 --- a/cpus.c +++ b/cpus.c @@ -1117,8 +1117,13 @@ void resume_all_vcpus(void) } } +/* For temporary buffers for forming a name */ +#define VCPU_THREAD_NAME_SIZE 16 + static void qemu_tcg_init_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + tcg_cpu_address_space_init(cpu, cpu-as); /* share a single thread for all cpus with TCG */ @@ -1127,8 +1132,10 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) cpu-halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu-halt_cond); tcg_halt_cond = cpu-halt_cond; -qemu_thread_create(cpu-thread, qemu_tcg_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, CPU %d/TCG, + cpu-cpu_index); +qemu_thread_create(cpu-thread, thread_name, qemu_tcg_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); #ifdef _WIN32 cpu-hThread = qemu_thread_get_handle(cpu-thread); #endif @@ -1144,11 +1151,15 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) static void qemu_kvm_start_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + cpu-thread = g_malloc0(sizeof(QemuThread)); cpu-halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu-halt_cond); -qemu_thread_create(cpu-thread, qemu_kvm_cpu_thread_fn, cpu, - QEMU_THREAD_JOINABLE); +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, CPU %d/KVM, + cpu-cpu_index); +qemu_thread_create(cpu-thread, thread_name, qemu_kvm_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); while (!cpu-created) { qemu_cond_wait(qemu_cpu_cond, qemu_global_mutex); } @@ -1156,10 +1167,14 @@ static void qemu_kvm_start_vcpu(CPUState *cpu) static void qemu_dummy_start_vcpu(CPUState *cpu) { +char thread_name[VCPU_THREAD_NAME_SIZE]; + cpu-thread = g_malloc0(sizeof(QemuThread)); cpu-halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(cpu-halt_cond); -qemu_thread_create(cpu-thread, qemu_dummy_cpu_thread_fn, cpu, +snprintf(thread_name, VCPU_THREAD_NAME_SIZE, CPU %d/DUMMY, + cpu-cpu_index); +qemu_thread_create(cpu-thread, thread_name, qemu_dummy_cpu_thread_fn, cpu, QEMU_THREAD_JOINABLE); while (!cpu-created) { qemu_cond_wait(qemu_cpu_cond, qemu_global_mutex); diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 2237edb..d1c7ad4 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -358,7 +358,7 @@ static void start_data_plane_bh(void *opaque) qemu_bh_delete(s-start_bh); s-start_bh = NULL; -qemu_thread_create(s-thread, data_plane_thread, +qemu_thread_create(s-thread, data_plane, data_plane_thread, s, QEMU_THREAD_JOINABLE); } diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index aa913df..7213c89 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -546,10 +546,10 @@ static int emulated_initfn(CCIDCardState *base) printf(%s: failed to initialize vcard\n, EMULATED_DEV_NAME); return -1; } -qemu_thread_create(card-event_thread_id, event_thread, card, - QEMU_THREAD_JOINABLE); -qemu_thread_create(card-apdu_thread_id, handle_apdu_thread, card, - QEMU_THREAD_JOINABLE); +qemu_thread_create(card-event_thread_id,