qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David CARLIER <devnexen@gmail.com>
To: Thomas Huth <thuth@redhat.com>,
	pbonzini@readhat.com, qemu-trivial@nongnu.org
Cc: Kamil Rytarowski <kamil@netbsd.org>,
	Ed Maste <emaste@freebsd.org>,
	qemu-devel@nongnu.org, bauerchen@tencent.com,
	Li-Wen Hsu <lwhsu@freebsd.org>
Subject: Re: [PATCH 1/1] util/oslib: Returns real thread identifier on FreeBSD and NetBSD
Date: Tue, 26 May 2020 08:29:09 +0100	[thread overview]
Message-ID: <CA+XhMqx6_mWvb-5Z2Mbtw3V-q-WkZPnOF10VK=iLwSwUGnOJAQ@mail.gmail.com> (raw)
In-Reply-To: <f9ebb603-0a0e-8775-8405-dd8de2493a3f@redhat.com>

From 792fbcd9114f43bd80fd1ef5b25cd9935a536f9f Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Tue, 26 May 2020 08:25:26 +0100
Subject: [PATCH] util/oslib: Returns the real thread identifier on FreeBSD and
 NetBSD

getpid is good enough in a mono thread context, however
 thr_self/_lwp_self reflects the real current thread identifier
 from a given process.
---
 util/oslib-posix.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 062236a1ab..916f1be224 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -48,11 +48,13 @@
 #ifdef __FreeBSD__
 #include <sys/sysctl.h>
 #include <sys/user.h>
+#include <sys/thr.h>
 #include <libutil.h>
 #endif

 #ifdef __NetBSD__
 #include <sys/sysctl.h>
+#include <lwp.h>
 #endif

 #include "qemu/mmap-alloc.h"
@@ -84,6 +86,13 @@ int qemu_get_thread_id(void)
 {
 #if defined(__linux__)
     return syscall(SYS_gettid);
+#elif defined(__FreeBSD__)
+    /* thread id is up to INT_MAX */
+    long tid;
+    thr_self(&tid);
+    return (int)tid;
+#elif defined(__NetBSD__)
+    return _lwp_self();
 #else
     return getpid();
 #endif
-- 
2.27.0.rc0

On Tue, 26 May 2020 at 06:40, Thomas Huth <thuth@redhat.com> wrote:
>
> On 23/05/2020 09.23, David CARLIER wrote:
> > Hi this is my first contribution hope it s useful . Regards.
>
>  Hi!
>
> Thanks for your contribution. Some hints for getting your patch included:
>
> - Please make sure to CC: the corresponding maintainers, otherwise your
> patch might get lost in the high traffic of the mailing list. See the
> MAINTAINERS file for more information.
>
> - For simple patches like this one, it might also be helpful to CC:
> qemu-trivial@nongnu.org so that the patch could get picked up via the
> trivial queue
>
> > From ca7fcd85e0453f7173ce73732905463bc259ee32 Mon Sep 17 00:00:00 2001
> > From: David Carlier <devnexen@gmail.com>
> > Date: Sat, 23 May 2020 08:17:51 +0100
> > Subject: [PATCH] util/oslib: returns real thread identifier on FreeBSD and
> >  NetBSD
>
> The body of the mail should only contain a proper patch description, not
> these head lines anymore, so that the patch can directly applied via
> "git am". Please also add a proper description, e.g. saying what's the
> effect of your patch. Is it just a cosmetic thing? Does it fix a real
> bug that you've hit?
>
> > Signed-off-by: David Carlier <devnexen@gmail.com>
> > ---
> >  util/oslib-posix.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> > index 062236a1ab..4d28dfd8f5 100644
> > --- a/util/oslib-posix.c
> > +++ b/util/oslib-posix.c
> > @@ -48,11 +48,13 @@
> >  #ifdef __FreeBSD__
> >  #include <sys/sysctl.h>
> >  #include <sys/user.h>
> > +#include <sys/thr.h>
> >  #include <libutil.h>
> >  #endif
> >
> >  #ifdef __NetBSD__
> >  #include <sys/sysctl.h>
> > +#include <lwp.h>
> >  #endif
> >
> >  #include "qemu/mmap-alloc.h"
> > @@ -84,6 +86,13 @@ int qemu_get_thread_id(void)
> >  {
> >  #if defined(__linux__)
> >      return syscall(SYS_gettid);
> > +#elif defined(__FreeBSD__)
> > +    // thread id is up to INT_MAX
>
> QEMU coding style only used /* ... */ comments, see the CODING_STYLE.rst
> file.
>
> > +    long tid;
> > +    thr_self(&tid);
> > +    return (int)tid;
> > +#elif defined(__NetBSD__)
> > +    return _lwp_self();
> >  #else
> >      return getpid();
> >  #endif
> >
>
>  HTH,
>   Thomas
>


  reply	other threads:[~2020-05-26  7:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-23  7:23 [PATCH 1/1] util/oslib: Returns real thread identifier on FreeBSD and NetBSD David CARLIER
2020-05-26  5:40 ` Thomas Huth
2020-05-26  7:29   ` David CARLIER [this message]
2020-05-26 13:15     ` Kamil Rytarowski
2020-06-03  5:12     ` Philippe Mathieu-Daudé
2020-06-03  6:14       ` David CARLIER
2020-06-03 15:07         ` Li-Wen Hsu
2020-06-05 16:24           ` David CARLIER

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='CA+XhMqx6_mWvb-5Z2Mbtw3V-q-WkZPnOF10VK=iLwSwUGnOJAQ@mail.gmail.com' \
    --to=devnexen@gmail.com \
    --cc=bauerchen@tencent.com \
    --cc=emaste@freebsd.org \
    --cc=kamil@netbsd.org \
    --cc=lwhsu@freebsd.org \
    --cc=pbonzini@readhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=thuth@redhat.com \
    /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).