From: Wei Yang <richardw.yang@linux.intel.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, Wei Yang <richardw.yang@linux.intel.com>,
quintela@redhat.com,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Wei Yang <richard.weiyang@gmail.com>
Subject: Re: [Qemu-devel] [PATCH] migrtion: define MigrationState/MigrationIncomingState.state as MigrationStatus
Date: Sat, 24 Aug 2019 07:49:00 +0800 [thread overview]
Message-ID: <20190823234900.GA27793@richard> (raw)
In-Reply-To: <12c6eab2-7988-cdb9-ab54-ae052cd45188@redhat.com>
On Fri, Aug 23, 2019 at 11:21:50AM -0500, Eric Blake wrote:
>On 8/19/19 9:08 AM, Wei Yang wrote:
>> On Mon, Aug 19, 2019 at 12:26:32PM +0100, Dr. David Alan Gilbert wrote:
>>> * Wei Yang (richardw.yang@linux.intel.com) wrote:
>
>Typo in the subject line: migrtion should be migration
>
>>>> No functional change. Add default case to fix warning.
>>>
>>> I think the problem with this is that migrate_set_state uses an
>>> atomic_cmpxchg and so we have to be careful that the type we use
>>> is compatible with that.
>>> MigrationStatus is an enum and I think compilers are allowed to
>>> choose the types of that; so I'm not sure we're guaranteed
>>> that an enum is always OK for the atomic_cmpxchg, and if it is
>>
>> Took a look into the definition of atomic_cmpxchg, which finally calls
>>
>> * __atomic_compare_exchange_n for c++11
>> * __sync_val_compare_and_swap
>
>Those are compiler-defined macros, so you have to consult the compiler
>documentation to see if they state what happens when invoked on an enum
>type. You also have to check whether our macro
>typeof_strip_qual(enum_type) produces 'int' or something else.
>
>C99 doesn't specify _Atomic at all (which is why we handrolled our own
>atomic.h built on top of compiler primitives, instead of using
><stdatomic.h>). But reading C11, I see that 6.7.2.4 states that
>_Atomic(type) is okay except for:
>
>"The type name in an atomic type specifier shall not refer to an array
>type, a function type, an atomic type, or a qualified type."
>
>which does NOT preclude the use of _Atomic(enum_type), so presumably
>compilers have to be prepared to handle an atomic enum type. Still,
>it's rather shaky ground if you can't prove compilers handle it correctly.
>
Sounds this is a dark area for all those compilers. I would keep the code
untouched now.
Thanks
>
>>
>> Both of them take two pointers to compare and exchange its content.
>>
>> Per C99 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf,
>> it mentioned:
>>
>> Each enumerated type shall be compatible with char, a signed integer type,
>> or an unsigned integer type. The choice of type is implementation-defined,
>> but shall be capable of representing the values of all the members of the
>> enumeration.
>>
>> Based on this, I think atomic_cmpxchg should work fine with enum.
>
>What C99 says is rather weak; you really want to be basing your
>decisions on atomics based on C11 or later.
>
>
>--
>Eric Blake, Principal Software Engineer
>Red Hat, Inc. +1-919-301-3226
>Virtualization: qemu.org | libvirt.org
>
--
Wei Yang
Help you, Help me
prev parent reply other threads:[~2019-08-24 0:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-21 14:27 [Qemu-devel] [PATCH] migrtion: define MigrationState/MigrationIncomingState.state as MigrationStatus Wei Yang
2019-08-19 3:29 ` Wei Yang
2019-08-19 11:26 ` Dr. David Alan Gilbert
2019-08-19 13:32 ` Wei Yang
2019-08-21 8:51 ` Wei Yang
2019-08-19 11:26 ` Dr. David Alan Gilbert
2019-08-19 14:08 ` Wei Yang
2019-08-23 15:29 ` Dr. David Alan Gilbert
2019-08-23 16:18 ` Dr. David Alan Gilbert
2019-08-23 16:21 ` Eric Blake
2019-08-23 23:49 ` Wei Yang [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=20190823234900.GA27793@richard \
--to=richardw.yang@linux.intel.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=richard.weiyang@gmail.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).