* [Qemu-devel] [PATCH v2] qemu-thread: always keep the posix wrapper layer
@ 2018-04-12 5:34 Peter Xu
2018-04-12 7:55 ` Fam Zheng
0 siblings, 1 reply; 3+ messages in thread
From: Peter Xu @ 2018-04-12 5:34 UTC (permalink / raw)
To: qemu-devel; +Cc: Eric Blake, Fam Zheng, Stefan Hajnoczi, peterx, Paolo Bonzini
We will conditionally have a wrapper layer depending on whether the host
has the PTHREAD_SETNAME capability. It complicates stuff. Let's keep
the wrapper there; we opt out the pthread_setname_np() call only.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
v2:
- set thread name only conditionally [Eric]
---
util/qemu-thread-posix.c | 33 +++++++++++++--------------------
1 file changed, 13 insertions(+), 20 deletions(-)
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index b789cf32e9..a1c34ba6f2 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -482,7 +482,6 @@ static void __attribute__((constructor)) qemu_thread_atexit_init(void)
}
-#ifdef CONFIG_PTHREAD_SETNAME_NP
typedef struct {
void *(*start_routine)(void *);
void *arg;
@@ -495,16 +494,18 @@ static void *qemu_thread_start(void *args)
void *(*start_routine)(void *) = qemu_thread_args->start_routine;
void *arg = qemu_thread_args->arg;
+#ifdef CONFIG_PTHREAD_SETNAME_NP
/* Attempt to set the threads name; note that this is for debug, so
* we're not going to fail if we can't set it.
*/
- pthread_setname_np(pthread_self(), qemu_thread_args->name);
+ if (name_threads && qemu_thread_args->name) {
+ pthread_setname_np(pthread_self(), qemu_thread_args->name);
+ }
+#endif
g_free(qemu_thread_args->name);
g_free(qemu_thread_args);
return start_routine(arg);
}
-#endif
-
void qemu_thread_create(QemuThread *thread, const char *name,
void *(*start_routine)(void*),
@@ -513,6 +514,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,
sigset_t set, oldset;
int err;
pthread_attr_t attr;
+ QemuThreadArgs *qemu_thread_args;
err = pthread_attr_init(&attr);
if (err) {
@@ -527,22 +529,13 @@ void qemu_thread_create(QemuThread *thread, const char *name,
sigfillset(&set);
pthread_sigmask(SIG_SETMASK, &set, &oldset);
-#ifdef CONFIG_PTHREAD_SETNAME_NP
- if (name_threads) {
- QemuThreadArgs *qemu_thread_args;
- qemu_thread_args = g_new0(QemuThreadArgs, 1);
- qemu_thread_args->name = g_strdup(name);
- qemu_thread_args->start_routine = start_routine;
- qemu_thread_args->arg = arg;
-
- err = pthread_create(&thread->thread, &attr,
- qemu_thread_start, qemu_thread_args);
- } else
-#endif
- {
- err = pthread_create(&thread->thread, &attr,
- start_routine, arg);
- }
+ qemu_thread_args = g_new0(QemuThreadArgs, 1);
+ qemu_thread_args->name = g_strdup(name);
+ qemu_thread_args->start_routine = start_routine;
+ qemu_thread_args->arg = arg;
+
+ err = pthread_create(&thread->thread, &attr,
+ qemu_thread_start, qemu_thread_args);
if (err)
error_exit(err, __func__);
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qemu-thread: always keep the posix wrapper layer
2018-04-12 5:34 [Qemu-devel] [PATCH v2] qemu-thread: always keep the posix wrapper layer Peter Xu
@ 2018-04-12 7:55 ` Fam Zheng
2018-04-12 9:04 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Fam Zheng @ 2018-04-12 7:55 UTC (permalink / raw)
To: Peter Xu; +Cc: qemu-devel, Eric Blake, Stefan Hajnoczi, Paolo Bonzini
On Thu, 04/12 13:34, Peter Xu wrote:
> We will conditionally have a wrapper layer depending on whether the host
> has the PTHREAD_SETNAME capability. It complicates stuff. Let's keep
> the wrapper there; we opt out the pthread_setname_np() call only.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> v2:
> - set thread name only conditionally [Eric]
> ---
> util/qemu-thread-posix.c | 33 +++++++++++++--------------------
> 1 file changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index b789cf32e9..a1c34ba6f2 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -482,7 +482,6 @@ static void __attribute__((constructor)) qemu_thread_atexit_init(void)
> }
>
>
> -#ifdef CONFIG_PTHREAD_SETNAME_NP
> typedef struct {
> void *(*start_routine)(void *);
> void *arg;
> @@ -495,16 +494,18 @@ static void *qemu_thread_start(void *args)
> void *(*start_routine)(void *) = qemu_thread_args->start_routine;
> void *arg = qemu_thread_args->arg;
>
> +#ifdef CONFIG_PTHREAD_SETNAME_NP
> /* Attempt to set the threads name; note that this is for debug, so
> * we're not going to fail if we can't set it.
> */
> - pthread_setname_np(pthread_self(), qemu_thread_args->name);
> + if (name_threads && qemu_thread_args->name) {
> + pthread_setname_np(pthread_self(), qemu_thread_args->name);
> + }
> +#endif
> g_free(qemu_thread_args->name);
> g_free(qemu_thread_args);
> return start_routine(arg);
> }
> -#endif
> -
>
> void qemu_thread_create(QemuThread *thread, const char *name,
> void *(*start_routine)(void*),
> @@ -513,6 +514,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,
> sigset_t set, oldset;
> int err;
> pthread_attr_t attr;
> + QemuThreadArgs *qemu_thread_args;
>
> err = pthread_attr_init(&attr);
> if (err) {
> @@ -527,22 +529,13 @@ void qemu_thread_create(QemuThread *thread, const char *name,
> sigfillset(&set);
> pthread_sigmask(SIG_SETMASK, &set, &oldset);
>
> -#ifdef CONFIG_PTHREAD_SETNAME_NP
> - if (name_threads) {
> - QemuThreadArgs *qemu_thread_args;
> - qemu_thread_args = g_new0(QemuThreadArgs, 1);
> - qemu_thread_args->name = g_strdup(name);
> - qemu_thread_args->start_routine = start_routine;
> - qemu_thread_args->arg = arg;
> -
> - err = pthread_create(&thread->thread, &attr,
> - qemu_thread_start, qemu_thread_args);
> - } else
> -#endif
> - {
> - err = pthread_create(&thread->thread, &attr,
> - start_routine, arg);
> - }
> + qemu_thread_args = g_new0(QemuThreadArgs, 1);
> + qemu_thread_args->name = g_strdup(name);
> + qemu_thread_args->start_routine = start_routine;
> + qemu_thread_args->arg = arg;
> +
> + err = pthread_create(&thread->thread, &attr,
> + qemu_thread_start, qemu_thread_args);
>
> if (err)
> error_exit(err, __func__);
> --
> 2.14.3
>
Reviewed-by: Fam Zheng <famz@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qemu-thread: always keep the posix wrapper layer
2018-04-12 7:55 ` Fam Zheng
@ 2018-04-12 9:04 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2018-04-12 9:04 UTC (permalink / raw)
To: Fam Zheng, Peter Xu; +Cc: qemu-devel, Eric Blake, Stefan Hajnoczi
On 12/04/2018 09:55, Fam Zheng wrote:
> Reviewed-by: Fam Zheng <famz@redhat.com>
Queued, thanks Fam and Peter.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-12 9:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-12 5:34 [Qemu-devel] [PATCH v2] qemu-thread: always keep the posix wrapper layer Peter Xu
2018-04-12 7:55 ` Fam Zheng
2018-04-12 9:04 ` Paolo Bonzini
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 NNTP newsgroup(s).