All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wenchao Xia <wenchaoqemu@gmail.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com, lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH V6 06/29] monitor: add an implemention as qapi event emit method
Date: Sun, 15 Jun 2014 08:27:45 +0800	[thread overview]
Message-ID: <539CE881.4050608@gmail.com> (raw)
In-Reply-To: <539B4B23.60807@redhat.com>

于 2014/6/14 3:04, Eric Blake 写道:
> On 06/05/2014 06:22 AM, Wenchao Xia wrote:
>
> In the subject: s/as/of/
>
>> Now monitor has been hooked on the new event mechanism, so the patches
>
> s/Now/The/
>
>> later can convert event callers one by one. Most code are copied from
>
> s/the patches later/that later patches/
>
> s/are/is/
>
>> old monitor_protocol_* functions with some modification.
>>
>> Note that two build time warnings will be raised after this patch. One is
>> caused by no caller of monitor_qapi_event_throttle(), the other one is
>> caused by QAPI_EVENT_MAX = 0. They will be fixed automatically after
>> full event conversion later.
>
> I only got one of those two warnings, about the unused function.  What
> compiler and options are you using to get a warning about
> QAPI_EVENT_MAX?.  Furthermore, since the default 'configure' turns
> warnings into errors, this would be a build-breaker that hurts 'git
> bisect'.  I think it's easy enough to avoid, if you would please squash
> this in:
>

   The QAPI_EVENT_MAX = 0 cause a warning for code:

monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
{
     ....
     assert(event < QAPI_EVENT_MAX);
}

which is always false now. Perhaps change it as

assert((int)event < QAPI_EVENT_MAX);

?


> diff --git i/monitor.c w/monitor.c
> index 952e1cb..a593d17 100644
> --- i/monitor.c
> +++ w/monitor.c
> @@ -594,6 +594,7 @@ static void monitor_qapi_event_handler(void *opaque)
>    * more than 1 event will be emitted within @rate
>    * milliseconds
>    */
> +__attribute__((unused)) /* FIXME remove once in use */
>   static void monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
>   {
>       MonitorQAPIEventState *evstate;
>
>
> You can then remove that attribute later in 29/29 when you delete
> everything else about the older implementation.
>
> At this point, I think we're racking up enough fixes to be worth a v7
> respin (particularly since avoiding 'git bisect' breakage cannot be done
> as a followup patch, but has to be done in-place in the series).
>

   Thanks for tipping, it is a good way to go.


>>
>> Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
>> ---
>>   monitor.c    |  128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>>   trace-events |    4 ++
>>   2 files changed, 131 insertions(+), 1 deletions(-)
>>
>
>>
>> +typedef struct MonitorQAPIEventState {
>> +    QAPIEvent event;    /* Event being tracked */
>> +    int64_t rate;       /* Period over which to throttle. 0 to disable */
>> +    int64_t last;       /* Time at which event was last emitted */
>
> in what unit? [1]...
>
>> +    QEMUTimer *timer;   /* Timer for handling delayed events */
>> +    QObject *data;        /* Event pending delayed dispatch */
>
> Any reason the comments aren't aligned?

   Will fix.

>
>> +} MonitorQAPIEventState;
>> +
>>   struct Monitor {
>>       CharDriverState *chr;
>>       int mux_out;
>> @@ -489,6 +499,122 @@ static const char *monitor_event_names[] = {
>>   QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
>>
>>   static MonitorEventState monitor_event_state[QEVENT_MAX];
>> +static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX];
>
> If you are still seeing a compiler warning about allocating an array of
> size 0, you could likewise try this hack:
>
> /* FIXME Hack a minimum array size until we have events */
> static MonitorQAPIEventState monitor_qapi_event_state[QAPI_EVENT_MAX +
> !QAPI_EVENT_MAX];
>
> and likewise clean that up in 29/29
>
>> +static void
>> +monitor_qapi_event_queue(int event_kind, QDict *data, Error **errp)
>
> This is not the usual formatting in qemu.

   Fixing it.

>
>> +{
>> +    MonitorQAPIEventState *evstate;
>> +    assert(event_kind < QAPI_EVENT_MAX);
>
> This doesn't filter out negative values for event_kind.  Is it worth the
> extra paranoia to either make event_kind unsigned, or to assert that
> event_kind >= 0?
>

   Build waring will be raised for QAPI_EVENT_MAX = 0, same as above,
any better way to solve?

>> +    QAPIEvent event = (QAPIEvent)event_kind;
>
> Why are we casting here?  Would it not make more sense to change the
> signature in patch 2/29 to use the enum type from the get-go?
>
> typedef void (*QMPEventFuncEmit)(QAPIEvent event_kind, QDict *dict,
> Error **errp);
>
> and adjust the signature of this function to match
>

   Since QAPIEvent is generated by qapi-event.py, and they are
different in qemu code and test code, so there will be conflict
in test code which include qmp-event.h:
in qemu:
qmp-event.h include qapi-event.h
in test:
qmp-event.h include test-qapi-event.h
For simple I just used int type instead of QAPIEvent type.

   To use QAPIEvent in declaration, I think there would be some
tricks in test, and doc that using qapi-event.h define in
qmp-event.c may break test code, the encapsulation is not very goood.


>> +    int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
>
> ...[1] okay, it looks like 'rate' and 'last' are specified in
> nanoseconds.  Worth documenting in their declaration above.
> Particularly since [1]...
>
>> +static void monitor_qapi_event_handler(void *opaque)
>> +{
>> +    MonitorQAPIEventState *evstate = opaque;
>> +    int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
>> +
>> +
>> +    trace_monitor_qapi_event_handler(evstate->event,
>
> Why the double blank line?
>

   Copied code, will fix.

>> +
>> +/*
>> + * @event: the event ID to be limited
>> + * @rate: the rate limit in milliseconds
>> + *
>> + * Sets a rate limit on a particular event, so no
>> + * more than 1 event will be emitted within @rate
>> + * milliseconds
>> + */
>> +static void monitor_qapi_event_throttle(QAPIEvent event, int64_t rate)
>
> ...[1] this function is documented in milliseconds, not nanoseconds, and
> you are scaling internally.
>
>> +{
>> +    MonitorQAPIEventState *evstate;
>> +    assert(event < QAPI_EVENT_MAX);
>> +
>> +    evstate = &(monitor_qapi_event_state[event]);
>> +
>> +    trace_monitor_qapi_event_throttle(event, rate);
>> +    evstate->event = event;
>> +    evstate->rate = rate * SCALE_MS;
>
> This value can overflow if a user passes in an insanely large rate. Do
> we care?
>

   There is not much existing caller, maybe we can change it as
nonoseconds.

>> +    evstate->last = 0;
>> +    evstate->data = NULL;
>> +    evstate->timer = timer_new(QEMU_CLOCK_REALTIME,
>> +                               SCALE_MS,
>> +                               monitor_qapi_event_handler,
>> +                               evstate);
>
>> @@ -507,7 +633,6 @@ monitor_protocol_event_emit(MonitorEvent event,
>>       }
>>   }
>>
>> -
>>   /*
>
> Why the spurious line deletion?
>
   Will remove.

>> +++ b/trace-events
>> @@ -932,6 +932,10 @@ monitor_protocol_event_handler(uint32_t event, void *data, uint64_t last, uint64
>>   monitor_protocol_event_emit(uint32_t event, void *data) "event=%d data=%p"
>>   monitor_protocol_event_queue(uint32_t event, void *data, uint64_t rate, uint64_t last, uint64_t now) "event=%d data=%p rate=%" PRId64 " last=%" PRId64 " now=%" PRId64
>>   monitor_protocol_event_throttle(uint32_t event, uint64_t rate) "event=%d rate=%" PRId64
>> +monitor_qapi_event_emit(uint32_t event, void *data) "event=%d data=%p"
>> +monitor_qapi_event_queue(uint32_t event, void *data, uint64_t rate, uint64_t last, uint64_t now) "event=%d data=%p rate=%" PRId64 " last=%" PRId64 " now=%" PRId64
>> +monitor_qapi_event_handler(uint32_t event, void *data, uint64_t last, uint64_t now) "event=%d data=%p last=%" PRId64 " now=%" PRId64
>> +monitor_qapi_event_throttle(uint32_t event, uint64_t rate) "event=%d rate=%" PRId64
>
> Any reason you wanted to invent four new trace names, even though the
> existing 4 traces have the same signatures?  I'm wondering whether it
> would have just been better to use the old trace names.
>

   The old trace functions are still in use of old event code,
so I added fource new ones. The old ones should be removed in
cleanup patch.

  reply	other threads:[~2014-06-15  0:28 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 12:21 [Qemu-devel] [PATCH V6 00/29] add direct support of event in qapi schema Wenchao Xia
2014-06-05 12:21 ` [Qemu-devel] [PATCH V6 01/29] os-posix: include sys/time.h Wenchao Xia
2014-06-05 12:21 ` [Qemu-devel] [PATCH V6 02/29] qapi: add event helper functions Wenchao Xia
2014-06-05 12:21 ` [Qemu-devel] [PATCH V6 03/29] qapi script: add event support Wenchao Xia
2014-06-13 16:47   ` Eric Blake
2014-06-13 21:28   ` Eric Blake
2014-06-18  3:33   ` Eric Blake
2014-06-18  6:06     ` Paolo Bonzini
2014-06-18 22:45       ` Wenchao Xia
2014-06-18  3:50   ` Eric Blake
2014-06-05 12:21 ` [Qemu-devel] [PATCH V6 04/29] test: add test cases for qapi event Wenchao Xia
2014-06-13 17:05   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 05/29] qapi: adjust existing defines Wenchao Xia
2014-06-13 17:32   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 06/29] monitor: add an implemention as qapi event emit method Wenchao Xia
2014-06-13 19:04   ` Eric Blake
2014-06-15  0:27     ` Wenchao Xia [this message]
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 07/29] qapi: add new schema file qapi-event.json Wenchao Xia
2014-06-13 19:25   ` Eric Blake
2014-06-13 19:45     ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 08/29] qapi event: convert SHUTDOWN Wenchao Xia
2014-06-13 19:57   ` Eric Blake
2014-06-15  0:32     ` Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 09/29] qapi event: convert POWERDOWN Wenchao Xia
2014-06-13 20:02   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 10/29] qapi event: convert RESET Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 11/29] qapi event: convert STOP Wenchao Xia
2014-06-13 20:29   ` Eric Blake
2014-06-17  9:17     ` Paolo Bonzini
2014-06-17 13:18       ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 12/29] qapi event: convert RESUME Wenchao Xia
2014-06-13 20:33   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 13/29] qapi event: convert SUSPEND Wenchao Xia
2014-06-13 20:40   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 14/29] qapi event: convert SUSPEND_DISK Wenchao Xia
2014-06-13 20:42   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 15/29] qapi event: convert WAKEUP Wenchao Xia
2014-06-13 20:57   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 16/29] qapi event: convert RTC_CHANGE Wenchao Xia
2014-06-13 21:27   ` Eric Blake
2014-06-15  0:38     ` Wenchao Xia
2014-06-15 14:01       ` Paolo Bonzini
2014-06-15 14:00     ` Paolo Bonzini
2014-06-17  9:21     ` Paolo Bonzini
2014-06-17 13:19       ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 17/29] qapi event: convert WATCHDOG Wenchao Xia
2014-06-13 21:47   ` Eric Blake
2014-06-13 22:05     ` Eric Blake
2014-06-15  0:45       ` Wenchao Xia
2014-06-17  9:23     ` Paolo Bonzini
2014-06-17 13:21       ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 18/29] qapi event: convert DEVICE_DELETED Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 19/29] qapi event: convert DEVICE_TRAY_MOVED Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 20/29] qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 21/29] qapi event: convert BLOCK_IMAGE_CORRUPTED Wenchao Xia
2014-06-16 22:53   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 22/29] qapi event: convert other BLOCK_JOB events Wenchao Xia
2014-06-16 22:57   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 23/29] qapi event: convert NIC_RX_FILTER_CHANGED Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 24/29] qapi event: convert VNC events Wenchao Xia
2014-06-16 23:01   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 25/29] qapi event: convert SPICE events Wenchao Xia
2014-06-16 23:05   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 26/29] qapi event: convert BALLOON_CHANGE Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 27/29] qapi event: convert GUEST_PANICKED Wenchao Xia
2014-06-16 14:08   ` Eric Blake
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 28/29] qapi event: convert QUORUM events Wenchao Xia
2014-06-05 12:22 ` [Qemu-devel] [PATCH V6 29/29] qapi event: clean up Wenchao Xia
2014-06-16 14:09   ` Eric Blake
2014-06-10  5:48 ` [Qemu-devel] [PATCH V6 00/29] add direct support of event in qapi schema Paolo Bonzini
2014-06-15  0:52   ` Wenchao Xia
2014-06-17 10:57     ` Paolo Bonzini
2014-06-17 16:05       ` Eric Blake
2014-06-17 16:30         ` Paolo Bonzini
2014-06-17 22:10           ` Wenchao Xia
2014-06-18  4:00       ` Eric Blake
2014-06-18  6:07         ` Paolo Bonzini

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=539CE881.4050608@gmail.com \
    --to=wenchaoqemu@gmail.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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.