All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/6] qapi: extract CpuInfoCommon to mitigate schema duplication
Date: Wed, 25 Apr 2018 19:12:20 +0200	[thread overview]
Message-ID: <87604f6wi3.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <5ffb031a-554a-81c1-b374-eb82f410bf83@redhat.com> (Laszlo Ersek's message of "Wed, 25 Apr 2018 15:20:13 +0200")

Laszlo Ersek <lersek@redhat.com> writes:

> On 04/25/18 09:06, Markus Armbruster wrote:
>> Laszlo Ersek <lersek@redhat.com> writes:
>> 
>>> @CpuInfo and @CpuInfoFast duplicate the following four fields: @qom-path,
>>> @thread-id, @props and @arch. From these, extract the first three to a
>>> common structure called @CpuInfoCommon. (More on @arch later.)
>>>
>>> Introduce two new mid-layer structures, @CpuInfoBase and @CpuInfoFastBase,
>>> to soak up the union base struct fields on top of @CpuInfoCommon that are
>>> specific to @query-cpus and @query-cpus-fast, respectively.
>
> [[
>
>>> This is
>>> necessary because the base struct spec in union definitions does not let
>>> us mix named fields with a recursive base struct. (In other words, we
>>> couldn't directly use @CpuInfoCommon *plus* some other fields within
>>> @CpuInfo and @CpuInfoFast as base struct).
>
> ]]
>
>> 
>> Yes, you can either specify a base type or inline common members.  If
>> "union's common members = base type plus additional inline members"
>> turns out to be desirable in more places, we can try to add the feature.
>> I'm not asking *you* to find out, let alone try :)
>
> [[
>
>>> @arch cannot be hoisted higher than to @CpuInfoBase and @CpuInfoFastBase
>>> because the union descriminator is only accepted from a direct base
>>> struct, not from an indirect one.
>
> ]]
>
>> That's a bit of a blemish.  Again, I'm not asking you to do anything
>> about it.
>
> If these characteristics of the generator are operating knowledge for
> QAPI developers, I can trim the commit message -- those traits don't
> bother me at all, I just felt that I needed to justify the code.
>
> IOW, should I drop:
> - the sentences marked with [[ ]] above,
> - and/or the "Notes:" on @arch in the schema itself (which are updated
>   to @target, in the next patch)
> ?

Let's keep them.

>
> [snip]
>
>>> @@ -512,70 +541,77 @@
>>>  #
>>>  # Since: 0.14.0
>>>  #
>>>  # Example:
>>>  #
>>>  # -> { "execute": "query-cpus" }
>>>  # <- { "return": [
>>>  #          {
>>>  #             "CPU":0,
>>>  #             "current":true,
>>>  #             "halted":false,
>>> -#             "qom_path":"/machine/unattached/device[0]",
>>> +#             "qom-path":"/machine/unattached/device[0]",
>>>  #             "arch":"x86",
>>>  #             "pc":3227107138,
>>> -#             "thread_id":3134
>>> +#             "thread-id":3134
>>>  #          },
>>>  #          {
>>>  #             "CPU":1,
>>>  #             "current":false,
>>>  #             "halted":true,
>>> -#             "qom_path":"/machine/unattached/device[2]",
>>> +#             "qom-path":"/machine/unattached/device[2]",
>>>  #             "arch":"x86",
>>>  #             "pc":7108165,
>>> -#             "thread_id":3135
>>> +#             "thread-id":3135
>>>  #          }
>>>  #       ]
>>>  #    }
>> 
>> Compatibility break, whoops!
>
> But, at least, I updated the example! :)

Thanks :)

>> CpuInfo and CpuInfoFast do share qom-path and thread-id *values*, but
>> the keys differ in '_' vs. '-'.  Sad.
>> 
>> What now?  Is there enough common stuff left to justify the refactoring?
>
> While working on the schema changes, I saw the '_' vs. '-' difference
> immediately, but I thought these two characters were treated
> equivalently by all QAPI clients.

I wish...

QEMU could do that on QMP input.  We've talked about it, but no patches.

On QMP output, we're screwed.

Tolerating '_' was one of the dumber mistakes in QAPI.

> Later I found (in the test suite) that this wasn't the case, so I
> thought my memories must have applied to libvirtd only. (Because,
> libvirt does map "_" to "-", right?) Anyway, I figured the best way to
> ask was to post the patch like this :)

Heh.  I would've appreciated a hint in the commit message, though.

> So, if I drop @qom-path and @thread-id from CpuInfoCommon, then only
> @props remains subject to hoisting, in this patch. In the next patch,
> @arch joins @props.
>
> I believe the refactoring is still worth doing, because otherwise, after
> the addition of @target, we'd end up with:
>
> { 'union' : 'CpuInfo',
>   'base'  : { 'CPU'       : 'int',
>               'current'   : 'bool',
>               'halted'    : 'bool',
>               'qom_path'  : 'str',
>               'thread_id' : 'int',
>               '*props'    : 'CpuInstanceProperties',
>               'arch'      : 'CpuInfoArch',
>               'target'    : 'SysEmuTarget' },
> ...
>
> { 'union' : 'CpuInfoFast',
>   'base'  : { 'cpu-index' : 'int',
>               'qom-path'  : 'str',
>               'thread-id' : 'int',
>               '*props'    : 'CpuInstanceProperties',
>               'arch'      : 'CpuInfoArch',
>               'target'    : 'SysEmuTarget' },
> ...
>
> and people would ask themselves ever after, "are there some common
> fields in there that we could extract ... hmmm, @props and @arch, okay,
> maybe, maybe not, grey area". Let's do it now and save them the thinking.

Works for me.

> [snip]
>
>>> diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json
>>> index 25bce78352b8..5bfd2ef1dd3b 100644
>>> --- a/qapi/qapi-schema.json
>>> +++ b/qapi/qapi-schema.json
>>> @@ -61,23 +61,23 @@
>>>          'query-migrate-cache-size',
>>>          'query-tpm-models',
>>>          'query-tpm-types',
>>>          'ringbuf-read' ],
>>>      'name-case-whitelist': [
>>>          'ACPISlotType',         # DIMM, visible through query-acpi-ospm-status
>>>          'CpuInfoMIPS',          # PC, visible through query-cpu
>>>          'CpuInfoTricore',       # PC, visible through query-cpu
>>>          'QapiErrorClass',       # all members, visible through errors
>>>          'UuidInfo',             # UUID, visible through query-uuid
>>>          'X86CPURegister32',     # all members, visible indirectly through qom-get
>>> -        'q_obj_CpuInfo-base'    # CPU, visible through query-cpu
>>> +        'CpuInfoBase'           # CPU, visible through query-cpu
>> 
>> Let's update this to "visible through query-cpus, query-cpus-fast" while
>> there.
>
> Right, I noticed the typo in the preexistent comment too late (and I
> didn't notice the "query-cpus-fast" omission at all).
>
> Thanks!

You're welcome!

  reply	other threads:[~2018-04-25 17:12 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24 21:45 [Qemu-devel] [PATCH 0/6] qapi: introduce the SysEmuTarget enumeration Laszlo Ersek
2018-04-24 21:45 ` [Qemu-devel] [PATCH 1/6] qapi: fill in CpuInfoFast.arch in query-cpus-fast Laszlo Ersek
2018-04-24 22:30   ` Eric Blake
2018-04-25 12:30     ` Laszlo Ersek
2018-04-25  6:39   ` Markus Armbruster
2018-04-25 12:30     ` Laszlo Ersek
2018-04-25  7:28   ` Cornelia Huck
2018-04-24 21:45 ` [Qemu-devel] [PATCH 2/6] qapi: handle the riscv CpuInfoArch " Laszlo Ersek
2018-04-24 22:32   ` Eric Blake
2018-04-25 12:32     ` Laszlo Ersek
2018-04-25  6:44   ` Markus Armbruster
2018-04-25  7:48     ` Cornelia Huck
2018-04-25 12:38       ` Viktor VM Mihajlovski
2018-04-25 12:43       ` Laszlo Ersek
2018-04-24 21:45 ` [Qemu-devel] [PATCH 3/6] qapi: add SysEmuTarget to "common.json" Laszlo Ersek
2018-04-24 23:11   ` Eric Blake
2018-04-25 12:54     ` Daniel P. Berrangé
2018-04-25 19:05       ` Laszlo Ersek
2018-04-25 19:08         ` Eric Blake
2018-04-25 22:57           ` Laszlo Ersek
2018-04-24 21:45 ` [Qemu-devel] [PATCH 4/6] qapi: change the type of TargetInfo.arch from string to enum SysEmuTarget Laszlo Ersek
2018-04-25  6:48   ` Markus Armbruster
2018-04-25 12:58     ` Laszlo Ersek
2018-04-24 21:45 ` [Qemu-devel] [PATCH 5/6] qapi: extract CpuInfoCommon to mitigate schema duplication Laszlo Ersek
2018-04-25  7:06   ` Markus Armbruster
2018-04-25 13:20     ` Laszlo Ersek
2018-04-25 17:12       ` Markus Armbruster [this message]
2018-04-25 19:12       ` Eric Blake
2018-04-25 22:56         ` Laszlo Ersek
2018-04-26  6:19           ` Markus Armbruster
2018-04-24 21:45 ` [Qemu-devel] [PATCH 6/6] qapi: discriminate CpuInfo[Fast] on SysEmuTarget, not CpuInfoArch Laszlo Ersek
2018-04-25  7:33   ` Markus Armbruster
2018-04-25 13:47     ` Laszlo Ersek
2018-04-26  6:26       ` Markus Armbruster
2018-04-26  9:18         ` Laszlo Ersek
2018-04-26 11:57           ` Markus Armbruster
2018-04-26 13:33           ` Laszlo Ersek
2018-04-26 14:34             ` Markus Armbruster
2018-04-26 14:48               ` Eric Blake
2018-04-26 15:51                 ` Markus Armbruster
2018-04-26 16:30                   ` Laszlo Ersek
2018-04-27  6:53                     ` Markus Armbruster
2018-04-27 13:46                       ` Eric Blake
2018-04-24 22:03 ` [Qemu-devel] [PATCH 0/6] qapi: introduce the SysEmuTarget enumeration no-reply
2018-04-25 12:26   ` Laszlo Ersek
2018-04-25 14:37     ` Eric Blake

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=87604f6wi3.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=lersek@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.