diff mbox

[2/3] Add 'namethreads' suboption to --name

Message ID 1390922439-30750-3-git-send-email-dgilbert@redhat.com
State New
Headers show

Commit Message

Dr. David Alan Gilbert Jan. 28, 2014, 3:20 p.m. UTC
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Add flag storage to qemu-thread-* to store the namethreads flag

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/qemu/thread.h    | 1 +
 qemu-options.hx          | 6 ++++--
 util/qemu-thread-posix.c | 7 +++++++
 util/qemu-thread-win32.c | 8 ++++++++
 vl.c                     | 7 +++++++
 5 files changed, 27 insertions(+), 2 deletions(-)

Comments

Michael S. Tsirkin Jan. 28, 2014, 3:53 p.m. UTC | #1
On Tue, Jan 28, 2014 at 03:20:38PM +0000, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> Add flag storage to qemu-thread-* to store the namethreads flag
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

How about a pattern?  threads='vmfoo-%s' and have qemu fill in
specific strings for %s.

> ---
>  include/qemu/thread.h    | 1 +
>  qemu-options.hx          | 6 ++++--
>  util/qemu-thread-posix.c | 7 +++++++
>  util/qemu-thread-win32.c | 8 ++++++++
>  vl.c                     | 7 +++++++
>  5 files changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/include/qemu/thread.h b/include/qemu/thread.h
> index 3e32c65..bf1e110 100644
> --- a/include/qemu/thread.h
> +++ b/include/qemu/thread.h
> @@ -59,5 +59,6 @@ void *qemu_thread_join(QemuThread *thread);
>  void qemu_thread_get_self(QemuThread *thread);
>  bool qemu_thread_is_self(QemuThread *thread);
>  void qemu_thread_exit(void *retval);
> +void qemu_thread_naming(bool enable);
>  
>  #endif
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 56e5fdf..d53343a 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -328,9 +328,10 @@ possible drivers and properties, use @code{-device help} and
>  ETEXI
>  
>  DEF("name", HAS_ARG, QEMU_OPTION_name,
> -    "-name string1[,process=string2]\n"
> +    "-name string1[,process=string2][,namethreads=on|off]\n"
>      "                set the name of the guest\n"
> -    "                string1 sets the window title and string2 the process name (on Linux)\n",
> +    "                string1 sets the window title and string2 the process name (on Linux)\n"
> +    "                When namethreads is enabled, individual threads are given a separate name (on Linux)\n",
>      QEMU_ARCH_ALL)
>  STEXI
>  @item -name @var{name}
> @@ -339,6 +340,7 @@ Sets the @var{name} of the guest.
>  This name will be displayed in the SDL window caption.
>  The @var{name} will also be used for the VNC server.
>  Also optionally set the top visible process name in Linux.
> +Naming of individual threads can also be enabled on Linux.
>  ETEXI
>  
>  DEF("uuid", HAS_ARG, QEMU_OPTION_uuid,
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index 37dd298..0fa6c81 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -27,6 +27,13 @@
>  #include "qemu/thread.h"
>  #include "qemu/atomic.h"
>  
> +static bool name_threads;
> +
> +void qemu_thread_naming(bool enable)
> +{
> +    name_threads = enable;
> +}
> +
>  static void error_exit(int err, const char *msg)
>  {
>      fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> index 27a5217..e42cb77 100644
> --- a/util/qemu-thread-win32.c
> +++ b/util/qemu-thread-win32.c
> @@ -16,6 +16,14 @@
>  #include <assert.h>
>  #include <limits.h>
>  
> +static bool name_threads;
> +
> +void qemu_thread_naming(bool enable)
> +{
> +    /* But note we don't actually name them on Windows yet */
> +    name_threads = enable;
> +}
> +
>  static void error_exit(int err, const char *msg)
>  {
>      char *pstr;
> diff --git a/vl.c b/vl.c
> index 5f993e4..8c515ae 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -547,6 +547,10 @@ static QemuOptsList qemu_name_opts = {
>              .name = "process",
>              .type = QEMU_OPT_STRING,
>              .help = "Sets the name of the QEMU process, as shown in top etc",
> +        }, {
> +            .name = "namethreads",
> +            .type = QEMU_OPT_BOOL,
> +            .help = "When enabled, name the individual threads; defaults off",
>          },
>          { /* End of list */ }
>      },
> @@ -1006,6 +1010,9 @@ static void parse_name(QemuOpts *opts)
>  {
>      const char *proc_name;
>  
> +    if (qemu_opt_get(opts, "namethreads")) {
> +        qemu_thread_naming(qemu_opt_get_bool(opts, "namethreads", false));
> +    }
>      qemu_name = qemu_opt_get(opts, "guest");
>  
>      proc_name = qemu_opt_get(opts, "process");
> -- 
> 1.8.5.3
Dr. David Alan Gilbert Jan. 28, 2014, 6:09 p.m. UTC | #2
* Michael S. Tsirkin (mst@redhat.com) wrote:
> On Tue, Jan 28, 2014 at 03:20:38PM +0000, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > Add flag storage to qemu-thread-* to store the namethreads flag
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 
> How about a pattern?  threads='vmfoo-%s' and have qemu fill in
> specific strings for %s.

The size of the name is limited to 16bytes according to the manpage
for pthread_setname_sn, so things start to get a bit squashed
if you try and have a vmname and anything else useful in the one name.

Dave
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Michael S. Tsirkin Jan. 28, 2014, 7:01 p.m. UTC | #3
On Tue, Jan 28, 2014 at 06:09:06PM +0000, Dr. David Alan Gilbert wrote:
> * Michael S. Tsirkin (mst@redhat.com) wrote:
> > On Tue, Jan 28, 2014 at 03:20:38PM +0000, Dr. David Alan Gilbert (git) wrote:
> > > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > > 
> > > Add flag storage to qemu-thread-* to store the namethreads flag
> > > 
> > > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > 
> > How about a pattern?  threads='vmfoo-%s' and have qemu fill in
> > specific strings for %s.
> 
> The size of the name is limited to 16bytes according to the manpage
> for pthread_setname_sn, so things start to get a bit squashed
> if you try and have a vmname and anything else useful in the one name.
> 
> Dave

I see. Well, as long as it's a debug only flag, I guess that's fine.

> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff mbox

Patch

diff --git a/include/qemu/thread.h b/include/qemu/thread.h
index 3e32c65..bf1e110 100644
--- a/include/qemu/thread.h
+++ b/include/qemu/thread.h
@@ -59,5 +59,6 @@  void *qemu_thread_join(QemuThread *thread);
 void qemu_thread_get_self(QemuThread *thread);
 bool qemu_thread_is_self(QemuThread *thread);
 void qemu_thread_exit(void *retval);
+void qemu_thread_naming(bool enable);
 
 #endif
diff --git a/qemu-options.hx b/qemu-options.hx
index 56e5fdf..d53343a 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -328,9 +328,10 @@  possible drivers and properties, use @code{-device help} and
 ETEXI
 
 DEF("name", HAS_ARG, QEMU_OPTION_name,
-    "-name string1[,process=string2]\n"
+    "-name string1[,process=string2][,namethreads=on|off]\n"
     "                set the name of the guest\n"
-    "                string1 sets the window title and string2 the process name (on Linux)\n",
+    "                string1 sets the window title and string2 the process name (on Linux)\n"
+    "                When namethreads is enabled, individual threads are given a separate name (on Linux)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -name @var{name}
@@ -339,6 +340,7 @@  Sets the @var{name} of the guest.
 This name will be displayed in the SDL window caption.
 The @var{name} will also be used for the VNC server.
 Also optionally set the top visible process name in Linux.
+Naming of individual threads can also be enabled on Linux.
 ETEXI
 
 DEF("uuid", HAS_ARG, QEMU_OPTION_uuid,
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index 37dd298..0fa6c81 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -27,6 +27,13 @@ 
 #include "qemu/thread.h"
 #include "qemu/atomic.h"
 
+static bool name_threads;
+
+void qemu_thread_naming(bool enable)
+{
+    name_threads = enable;
+}
+
 static void error_exit(int err, const char *msg)
 {
     fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
index 27a5217..e42cb77 100644
--- a/util/qemu-thread-win32.c
+++ b/util/qemu-thread-win32.c
@@ -16,6 +16,14 @@ 
 #include <assert.h>
 #include <limits.h>
 
+static bool name_threads;
+
+void qemu_thread_naming(bool enable)
+{
+    /* But note we don't actually name them on Windows yet */
+    name_threads = enable;
+}
+
 static void error_exit(int err, const char *msg)
 {
     char *pstr;
diff --git a/vl.c b/vl.c
index 5f993e4..8c515ae 100644
--- a/vl.c
+++ b/vl.c
@@ -547,6 +547,10 @@  static QemuOptsList qemu_name_opts = {
             .name = "process",
             .type = QEMU_OPT_STRING,
             .help = "Sets the name of the QEMU process, as shown in top etc",
+        }, {
+            .name = "namethreads",
+            .type = QEMU_OPT_BOOL,
+            .help = "When enabled, name the individual threads; defaults off",
         },
         { /* End of list */ }
     },
@@ -1006,6 +1010,9 @@  static void parse_name(QemuOpts *opts)
 {
     const char *proc_name;
 
+    if (qemu_opt_get(opts, "namethreads")) {
+        qemu_thread_naming(qemu_opt_get_bool(opts, "namethreads", false));
+    }
     qemu_name = qemu_opt_get(opts, "guest");
 
     proc_name = qemu_opt_get(opts, "process");