qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 3/3] Add a 'name' parameter to qemu_thread_create
Date: Mon, 10 Feb 2014 09:49:59 +0000	[thread overview]
Message-ID: <20140210094959.GD3545@work-vm> (raw)
In-Reply-To: <52F74C4A.6050001@redhat.com>

* Laszlo Ersek (lersek@redhat.com) wrote:
> comments below

Thanks,

> On 01/30/14 11:20, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@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 <dgilbert@redhat.com>
> > ---
> >  cpus.c                          | 25 ++++++++++++++++++++-----
> >  hw/block/dataplane/virtio-blk.c |  2 +-
> >  hw/usb/ccid-card-emulated.c     |  8 ++++----
> >  include/qemu/thread.h           |  2 +-
> >  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/cpus.c b/cpus.c
> > index ca4c59f..e5bb271 100644
> > --- a/cpus.c
> > +++ b/cpus.c
> > @@ -1117,16 +1117,23 @@ void resume_all_vcpus(void)
> >      }
> >  }
> >  
> > +/* For temporary buffers for forming a name */
> > +#define TMP_THREAD_NAME_LEN 16
> 
> This should be called _SIZE in my opinion, because it seems to include
> the trailing NUL character.

OK, that's fair enough.

> Alternatively, as much as I hate glib's presence in qemu, you could
> replace each (fixed size buffer, snprintf()) pair with a (pointer,
> g_strdup_printf(), g_free()) triplet.

It seemed to be getting over kill for a name/number pair.

<snip>

> > diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
> > index 456d437..980a684 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);
> >  }
> 
> Don't really want to suggest feature creep, but since we can have
> several dataplane threads as well, I suggest appending the serial number
> of the virtio-blk device, s->blk->serial (can be NULL). Example for
> access is in do_get_id_cmd(). Of course with this free-form string,
> g_strdup_printf() becomes more attractive.

Right, however, pthread_setname_np's manpage says:
    'The thread name is a meaningful C language string, whose length is
     restricted to 16 characters, including the terminating null byte ('\0')'

so we're a bit tight for space (and hence the magical 16 char length above -
they're doesn't seem to be a documented macro for that len),
so while data_plane 'n' might be a good idea, starting putting serial numbers
etc in ain't going to work.

I also thought the best bet was to leave how to use the naming down
to the maintainers of the threads themselves and I'd just take a first punt
at sane names.


> > 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, "ccid/event", event_thread,
> > +                       card, QEMU_THREAD_JOINABLE);
> > +    qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thread,
> > +                       card, QEMU_THREAD_JOINABLE);
> >      return 0;
> >  }
> 
> No clue how many there can be of these.
> 
> >  
> > 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/libcacard/vscclient.c b/libcacard/vscclient.c
> > index 24f7088..3477ab3 100644
> > --- a/libcacard/vscclient.c
> > +++ b/libcacard/vscclient.c
> > @@ -269,7 +269,7 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit *incoming)
> >      send_msg(VSC_ReaderRemove, VSCARD_MINIMAL_READER_ID, NULL, 0);
> >      /* launch the event_thread. This will trigger reader adds for all the
> >       * existing readers */
> > -    qemu_thread_create(&thread_id, event_thread, NULL, 0);
> > +    qemu_thread_create(&thread_id, "vsc/event", event_thread, NULL, 0);
> >      return 0;
> >  }
> 
> Ditto.
> 
> >  
> > diff --git a/migration.c b/migration.c
> > index 7235c23..bddec7e 100644
> > --- a/migration.c
> > +++ b/migration.c
> > @@ -679,6 +679,6 @@ void migrate_fd_connect(MigrationState *s)
> >      /* Notify before starting migration thread */
> >      notifier_list_notify(&migration_state_notifiers, s);
> >  
> > -    qemu_thread_create(&s->thread, migration_thread, s,
> > +    qemu_thread_create(&s->thread, "migration", migration_thread, s,
> >                         QEMU_THREAD_JOINABLE);
> >  }
> 
> At most one such thread at a time, right?

Right (for the moment...)

> > diff --git a/thread-pool.c b/thread-pool.c
> > index 3735fd3..fbdd3ff 100644
> > --- a/thread-pool.c
> > +++ b/thread-pool.c
> > @@ -140,7 +140,7 @@ static void do_spawn_thread(ThreadPool *pool)
> >      pool->new_threads--;
> >      pool->pending_threads++;
> >  
> > -    qemu_thread_create(&t, worker_thread, pool, QEMU_THREAD_DETACHED);
> > +    qemu_thread_create(&t, "worker", worker_thread, pool, QEMU_THREAD_DETACHED);
> >  }
> 
> I do think these guys should be numbered somehow. "pending_threads"
> looks like an obvious choice, but it might be incorrect.
> 
> >  
> >  static void spawn_thread_bh_fn(void *opaque)
> > diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
> > index 2d3fce8..3f3c47b 100644
> > --- a/ui/vnc-jobs.c
> > +++ b/ui/vnc-jobs.c
> > @@ -333,7 +333,8 @@ void vnc_start_worker_thread(void)
> >          return ;
> >  
> >      q = vnc_queue_init();
> > -    qemu_thread_create(&q->thread, vnc_worker_thread, q, QEMU_THREAD_DETACHED);
> > +    qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, q,
> > +                       QEMU_THREAD_DETACHED);
> >      queue = q; /* Set global queue */
> >  }
> 
> Probably one thread only.
> 
> >  
> > diff --git a/util/compatfd.c b/util/compatfd.c
> > index 430a41c..341ada6 100644
> > --- a/util/compatfd.c
> > +++ b/util/compatfd.c
> > @@ -88,7 +88,8 @@ static int qemu_signalfd_compat(const sigset_t *mask)
> >      memcpy(&info->mask, mask, sizeof(*mask));
> >      info->fd = fds[1];
> >  
> > -    qemu_thread_create(&thread, sigwait_compat, info, QEMU_THREAD_DETACHED);
> > +    qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, info,
> > +                       QEMU_THREAD_DETACHED);
> >  
> >      return fds[0];
> >  }
> 
> Ditto.
> 
> > diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> > index 0fa6c81..45113b4 100644
> > --- a/util/qemu-thread-posix.c
> > +++ b/util/qemu-thread-posix.c
> > @@ -394,8 +394,7 @@ void qemu_event_wait(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)
> >  {
> > @@ -421,6 +420,12 @@ void qemu_thread_create(QemuThread *thread,
> >      if (err)
> >          error_exit(err, __func__);
> >  
> > +#ifdef _GNU_SOURCE
> > +    if (name_threads) {
> > +        pthread_setname_np(thread->thread, name);
> > +    }
> > +#endif
> > +
> 
> Maybe a retval check? Or do we ignore ERANGE on purpose?

I decided it was best for QEMU not to die just because we can't get some debug
facility.

> >      pthread_sigmask(SIG_SETMASK, &oldset, NULL);
> >  
> >      pthread_attr_destroy(&attr);
> > diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> > index e42cb77..b9c957b 100644
> > --- a/util/qemu-thread-win32.c
> > +++ b/util/qemu-thread-win32.c
> > @@ -333,7 +333,7 @@ void *qemu_thread_join(QemuThread *thread)
> >      return ret;
> >  }
> >  
> > -void qemu_thread_create(QemuThread *thread,
> > +void qemu_thread_create(QemuThread *thread, const char *name,
> >                         void *(*start_routine)(void *),
> >                         void *arg, int mode)
> >  {
> > 
> 
> Anyway this is for helping debugging, and there's nothing in here that
> I'd call a bug, so I won't waste your time with asking for a new version. :)
> 
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> 
> Thanks!

Thanks!

> Laszlo

Dave
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2014-02-10  9:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-30 10:20 [Qemu-devel] [PATCH v2 0/3] Name threads Dr. David Alan Gilbert (git)
2014-01-30 10:20 ` [Qemu-devel] [PATCH v2 1/3] Rework --name to use QemuOpts Dr. David Alan Gilbert (git)
2014-02-09  8:43   ` Laszlo Ersek
2014-02-10 10:03     ` Dr. David Alan Gilbert
2014-02-10 16:12       ` Laszlo Ersek
2014-02-11  9:07         ` Paolo Bonzini
2014-02-11 13:30           ` Eric Blake
2014-01-30 10:20 ` [Qemu-devel] [PATCH v2 2/3] Add 'debug-threads' suboption to --name Dr. David Alan Gilbert (git)
2014-02-09  9:08   ` Laszlo Ersek
2014-02-10 10:16     ` Dr. David Alan Gilbert
2014-02-10 16:14       ` Laszlo Ersek
2014-01-30 10:20 ` [Qemu-devel] [PATCH v2 3/3] Add a 'name' parameter to qemu_thread_create Dr. David Alan Gilbert (git)
2014-02-09  9:37   ` Laszlo Ersek
2014-02-10  9:49     ` Dr. David Alan Gilbert [this message]
2014-01-30 12:59 ` [Qemu-devel] [PATCH v2 0/3] Name threads Eric Blake
2014-01-30 13:03   ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140210094959.GD3545@work-vm \
    --to=dgilbert@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).