qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Fam Zheng <fam@euphon.net>,
	fweimer@redhat.com, thuth@redhat.com,
	Daniel Berrange <berrange@redhat.com>,
	qemu-block@nongnu.org,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Warner Losh <imp@bsdimp.com>,
	sguelton@redhat.com
Subject: Re: [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables
Date: Mon, 13 Dec 2021 14:09:18 +0000	[thread overview]
Message-ID: <YbdUDkTkt5srNdW+@stefanha-x1.localdomain> (raw)
In-Reply-To: <CAFEAcA_PfjwqS=4c=LCzZWbJBiELeBsdQ4QZur5wMtrtu1BFuQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1725 bytes --]

On Tue, Dec 07, 2021 at 01:55:34PM +0000, Peter Maydell wrote:
> On Tue, 7 Dec 2021 at 13:53, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> >
> > On Mon, Dec 06, 2021 at 02:34:45PM +0000, Peter Maydell wrote:
> > > On Mon, 6 Dec 2021 at 14:33, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> > > >
> > > > v3:
> > > > - Added __attribute__((weak)) to get_ptr_*() [Florian]
> > >
> > > Do we really need it *only* on get_ptr_*() ? If we need to
> > > noinline the other two we probably also should use the same
> > > attribute weak to force no optimizations at all.
> >
> > The weak attribute can't be used on static functions, so I think we need
> > a different approach:
> >
> > In file included from ../util/async.c:35:
> > /builds/stefanha/qemu/include/qemu/coroutine-tls.h:201:11: error: weak declaration of 'get_ptr_my_aiocontext' must be public
> >      type *get_ptr_##var(void)                                                \
> >            ^~~~~~~~
> > ../util/async.c:673:1: note: in expansion of macro 'QEMU_DEFINE_STATIC_CO_TLS'
> >  QEMU_DEFINE_STATIC_CO_TLS(AioContext *, my_aiocontext)
> >  ^~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Adding asm volatile("") seems to work though:
> > https://godbolt.org/z/3hn8Gh41d
> 
> You can see in the clang disassembly there that this isn't
> sufficient. The compiler puts in both calls, but it ignores
> the return results and always returns "true" from the function.

Specifying a input operand forces the compiler to evaluate the return
value of get_ptr_i():

  static __attribute__((noinline)) long get_ptr_i()
  {
    long l = (long)&i;
    asm volatile("" : "+rm" (l));
    return l;
  }

https://godbolt.org/z/e6ddGdPMv

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      parent reply	other threads:[~2021-12-13 14:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 14:26 [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 1/4] " Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 2/4] util/async: replace __thread with QEMU TLS macros Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 3/4] rcu: use coroutine " Stefan Hajnoczi
2021-12-06 14:26 ` [RFC v3 4/4] cpus: use coroutine TLS macros for iothread_locked Stefan Hajnoczi
2021-12-06 14:34 ` [RFC v3 0/4] tls: add macros for coroutine-safe TLS variables Peter Maydell
2021-12-07 13:34   ` Stefan Hajnoczi
2021-12-07 13:53   ` Stefan Hajnoczi
2021-12-07 13:55     ` Peter Maydell
2021-12-07 16:29       ` Stefan Hajnoczi
2021-12-13 14:09       ` Stefan Hajnoczi [this message]

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=YbdUDkTkt5srNdW+@stefanha-x1.localdomain \
    --to=stefanha@redhat.com \
    --cc=berrange@redhat.com \
    --cc=fam@euphon.net \
    --cc=fweimer@redhat.com \
    --cc=imp@bsdimp.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sguelton@redhat.com \
    --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).