All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlad Yasevich <vyasevic@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: qemu-devel@nongnu.org, quintela@redhat.com, germano@redhat.com,
	lvivier@redhat.com, jasowang@redhat.com, jdenemar@redhat.com,
	kashyap@redhat.com, armbru@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH 08/12] announce_timer: Add ability to reset an existing
Date: Tue, 30 May 2017 16:01:28 -0400	[thread overview]
Message-ID: <a6643292-6926-7ca3-4576-b9c661ccc812@redhat.com> (raw)
In-Reply-To: <20170530193542.GX2120@work-vm>

On 05/30/2017 03:35 PM, Dr. David Alan Gilbert wrote:
> * Vladislav Yasevich (vyasevic@redhat.com) wrote:
>> It is now potentially possible to issue annouce-self command in a tight
>> loop.  Instead of doing nother, we can reset the timeout pararameters,
>> especially since each instance may provide it's own values.  This
>> allows the user to  extend or cut short currently runnig timer.
>>
>> Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com>
> 
> ah ok, you can ignore my comment on the previous patch then!
> 
>> ---
>>  include/migration/vmstate.h |  1 +
>>  migration/savevm.c          | 41 +++++++++++++++++++++++++++++++----------
>>  2 files changed, 32 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
>> index 689b685..6dfdac3 100644
>> --- a/include/migration/vmstate.h
>> +++ b/include/migration/vmstate.h
>> @@ -1057,6 +1057,7 @@ void vmstate_register_ram_global(struct MemoryRegion *memory);
>>  
>>  typedef struct AnnounceTimer {
>>      QEMUTimer *tm;
>> +    QemuMutex active_lock;
>>      struct AnnounceTimer **entry;
>>      AnnounceParameters params;
>>      QEMUClockType type;
>> diff --git a/migration/savevm.c b/migration/savevm.c
>> index dcba8bd..e43658f 100644
>> --- a/migration/savevm.c
>> +++ b/migration/savevm.c
>> @@ -220,20 +220,29 @@ static void qemu_announce_self_iter(NICState *nic, void *opaque)
>>  
>>  AnnounceTimer *announce_timers[QEMU_ANNOUNCE__MAX];
>>  
>> +static void qemu_announce_timer_destroy(AnnounceTimer *timer)
>> +{
>> +    timer_del(timer->tm);
>> +    timer_free(timer->tm);
>> +    qemu_mutex_destroy(&timer->active_lock);
> 
> Can you explain what makes this safe; we're not
> holding the lock at this point are we? Are we guaranteed
> that no one else will try and take it?
> Either way it should be commented to say why it's safe.

Looking at this again, it doesn't look safe.
The problem is the lookup code.  There is needs to be a lock on the
on the global array that needs to be held during creation/modification.

Thanks
-vlad

> 
> Dave
> 
>> +    g_free(timer);
>> +}
>> +
>>  static void qemu_announce_self_once(void *opaque)
>>  {
>>      AnnounceTimer *timer = (AnnounceTimer *)opaque;
>>  
>> +    qemu_mutex_lock(&timer->active_lock);
>>      qemu_foreach_nic(qemu_announce_self_iter, NULL);
>>  
>> -    if (--timer->round) {
>> +    if (--timer->round ) {
>>          timer_mod(timer->tm, qemu_clock_get_ms(timer->type) +
>>                    self_announce_delay(timer));
>> +        qemu_mutex_unlock(&timer->active_lock);
>>      } else {
>> -            *(timer->entry) = NULL;
>> -            timer_del(timer->tm);
>> -            timer_free(timer->tm);
>> -            g_free(timer);
>> +        *(timer->entry) = NULL;
>> +        qemu_mutex_unlock(&timer->active_lock);
>> +        qemu_announce_timer_destroy(timer);
>>      }
>>  }
>>  
>> @@ -242,6 +251,7 @@ AnnounceTimer *qemu_announce_timer_new(AnnounceParameters *params,
>>  {
>>      AnnounceTimer *timer = g_new(AnnounceTimer, 1);
>>  
>> +    qemu_mutex_init(&timer->active_lock);
>>      timer->params = *params;
>>      timer->round = params->rounds;
>>      timer->type = type;
>> @@ -259,6 +269,21 @@ AnnounceTimer *qemu_announce_timer_create(AnnounceParameters *params,
>>      return timer;
>>  }
>>  
>> +static void qemu_announce_timer_update(AnnounceTimer *timer,
>> +                                       AnnounceParameters *params)
>> +{
>> +    qemu_mutex_lock(&timer->active_lock);
>> +
>> +    /* Update timer paramenter with any new values.
>> +     * Reset the number of rounds to run, and stop the current timer.
>> +     */
>> +    timer->params = *params;
>> +    timer->round = params->rounds;
>> +    timer_del(timer->tm);
>> +
>> +    qemu_mutex_unlock(&timer->active_lock);
>> +}
>> +
>>  void qemu_announce_self(AnnounceParameters *params, AnnounceType type)
>>  {
>>      AnnounceTimer *timer;
>> @@ -270,11 +295,7 @@ void qemu_announce_self(AnnounceParameters *params, AnnounceType type)
>>          announce_timers[type] = timer;
>>          timer->entry = &announce_timers[type];
>>      } else {
>> -        /* For now, don't do anything.  If we want to reset the timer,
>> -         * we'll need to add locking to each announce timer to prevent
>> -         * races between timeout handling and a reset.
>> -         */
>> -        return;
>> +        qemu_announce_timer_update(timer, params);
>>      }
>>      qemu_announce_self_once(timer);
>>  }
>> -- 
>> 2.7.4
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 

  reply	other threads:[~2017-05-30 20:01 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 18:05 [Qemu-devel] [PATCH 00/12] self-announce updates Vladislav Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 01/12] migration: Introduce announce parameters Vladislav Yasevich
2017-05-26  4:03   ` Jason Wang
2017-05-26 13:06     ` Vlad Yasevich
2017-05-30 18:57       ` Dr. David Alan Gilbert
2017-06-01  7:02         ` Jason Wang
2017-06-01 13:45           ` Vlad Yasevich
2017-06-01 14:02             ` Dr. David Alan Gilbert
2017-05-26 13:08   ` Eric Blake
2017-05-26 13:17     ` Vlad Yasevich
2017-05-30  9:58   ` Juan Quintela
2017-05-30 13:45     ` Vlad Yasevich
2017-05-30 19:08   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 02/12] migration: Introduce announcement timer Vladislav Yasevich
2017-05-26  4:13   ` Jason Wang
2017-05-30 10:00   ` Juan Quintela
2017-05-24 18:05 ` [Qemu-devel] [PATCH 03/12] migration: Switch to using " Vladislav Yasevich
2017-05-26  4:16   ` Jason Wang
2017-05-26 13:01     ` Vlad Yasevich
2017-05-30 10:10   ` Juan Quintela
2017-05-30 13:46     ` Vlad Yasevich
2017-05-30 19:19   ` Dr. David Alan Gilbert
2017-05-30 19:34     ` Vlad Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 04/12] net: Add a network device specific self-announcement ability Vladislav Yasevich
2017-05-26  4:17   ` Jason Wang
2017-05-24 18:05 ` [Qemu-devel] [PATCH 05/12] virtio-net: Allow qemu_announce_self to trigger virtio announcements Vladislav Yasevich
2017-05-26  4:21   ` Jason Wang
2017-05-24 18:05 ` [Qemu-devel] [PATCH 06/12] qmp: Expose qemu_announce_self as a qmp command Vladislav Yasevich
2017-05-26 13:16   ` Eric Blake
2017-05-26 13:19     ` Vlad Yasevich
2017-05-30 10:11   ` Juan Quintela
2017-05-30 13:49     ` Vlad Yasevich
2017-05-30 14:24       ` Juan Quintela
2017-05-30 14:43         ` Vlad Yasevich
2017-05-30 14:14   ` Daniel P. Berrange
2017-05-30 15:01     ` Vlad Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 07/12] migration: Allow for a limited number of announce timers Vladislav Yasevich
2017-05-30 10:13   ` Juan Quintela
2017-05-30 19:31   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 08/12] announce_timer: Add ability to reset an existing Vladislav Yasevich
2017-05-30 10:15   ` Juan Quintela
2017-05-30 19:35   ` Dr. David Alan Gilbert
2017-05-30 20:01     ` Vlad Yasevich [this message]
2017-05-24 18:05 ` [Qemu-devel] [PATCH 09/12] hmp: add announce paraters info/set Vladislav Yasevich
2017-05-30 10:18   ` Juan Quintela
2017-05-30 13:57     ` Vlad Yasevich
2017-05-24 18:05 ` [Qemu-devel] [PATCH 10/12] hmp: Add hmp_announce_self Vladislav Yasevich
2017-05-31  9:47   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 11/12] tests/test-hmp: Add announce parameter tests Vladislav Yasevich
2017-05-31  9:53   ` Dr. David Alan Gilbert
2017-05-24 18:05 ` [Qemu-devel] [PATCH 12/12] tests: Add a test for qemu self announcments Vladislav Yasevich
2017-05-24 18:19 ` [Qemu-devel] [PATCH 00/12] self-announce updates no-reply
2017-05-24 18:38 ` no-reply
2017-05-24 18:40 ` no-reply
2017-05-31 10:29 ` Dr. David Alan Gilbert

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=a6643292-6926-7ca3-4576-b9c661ccc812@redhat.com \
    --to=vyasevic@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=germano@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jdenemar@redhat.com \
    --cc=kashyap@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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 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.