From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Subject: Re: [PATCH v2 1/4] balloon: Allow nested inhibits Date: Tue, 31 Jul 2018 10:25:55 +0200 Message-ID: <9e7101c8-0019-0fd4-7195-b5cd150e103a@redhat.com> References: <153299204130.14411.11438396195753743913.stgit@gimli.home> <153299242656.14411.14216251294160965283.stgit@gimli.home> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: cohuck@redhat.com, peterx@redhat.com, kvm@vger.kernel.org, mst@redhat.com To: Alex Williamson , qemu-devel@nongnu.org Return-path: In-Reply-To: <153299242656.14411.14216251294160965283.stgit@gimli.home> Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel2=m.gmane.org@nongnu.org Sender: "Qemu-devel" List-Id: kvm.vger.kernel.org On 31.07.2018 01:13, Alex Williamson wrote: > A simple true/false internal state does not allow multiple users. Fix > this within the existing interface by converting to a counter, so long > as the counter is elevated, ballooning is inhibited. > Not sure if "nested" is really the right term here. It is really multiple users. anyhow Reviewed-by: David Hildenbrand > Signed-off-by: Alex Williamson > --- > balloon.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/balloon.c b/balloon.c > index 6bf0a9681377..931987983858 100644 > --- a/balloon.c > +++ b/balloon.c > @@ -26,6 +26,7 @@ > > #include "qemu/osdep.h" > #include "qemu-common.h" > +#include "qemu/atomic.h" > #include "exec/cpu-common.h" > #include "sysemu/kvm.h" > #include "sysemu/balloon.h" > @@ -37,16 +38,22 @@ > static QEMUBalloonEvent *balloon_event_fn; > static QEMUBalloonStatus *balloon_stat_fn; > static void *balloon_opaque; > -static bool balloon_inhibited; > +static int balloon_inhibit_count; > > bool qemu_balloon_is_inhibited(void) > { > - return balloon_inhibited; > + return atomic_read(&balloon_inhibit_count) > 0; > } > > void qemu_balloon_inhibit(bool state) > { > - balloon_inhibited = state; > + if (state) { > + atomic_inc(&balloon_inhibit_count); > + } else { > + atomic_dec(&balloon_inhibit_count); > + } > + > + assert(atomic_read(&balloon_inhibit_count) >= 0); > } > > static bool have_balloon(Error **errp) > -- Thanks, David / dhildenb