From: Alberto Garcia <berto@igalia.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
qemu-devel@nongnu.org, "Benoît Canet" <benoit.canet@nodalink.com>
Subject: Re: [Qemu-devel] [PATCH 2/9] throttle: Add throttle group infrastructure
Date: Wed, 4 Mar 2015 11:18:21 +0100 [thread overview]
Message-ID: <20150304101821.GA5872@igalia.com> (raw)
In-Reply-To: <20150303163845.GD15846@stefanha-thinkpad.redhat.com>
On Tue, Mar 03, 2015 at 10:38:45AM -0600, Stefan Hajnoczi wrote:
> > + qemu_mutex_init(&tg->lock);
> > + throttle_init(&tg->ts);
> > + QLIST_INIT(&tg->head);
> > + tg->refcount = 1;
> > +
> > + /* insert new entry in the list */
> > + QTAILQ_INSERT_TAIL(&throttle_groups, tg, list);
>
> It is safest to hold tg->lock before adding the group to the
> list. This way there is a memory barrier and other threads will not
> access the group until we've finished adding it to the list.
I think that the throttle_group_incref/unref calls are only made from
the QEMU main loop, and that's the only code that deals with the
throttle_groups list, so I don't see any chance for a race condition
there.
Also, there's no way a different thread can have access to a group
before it's in the list, because the only way to get a group is to
retrieve it from the list.
If it was possible for two threads to try to incref() the same group
we would need to make the whole function thread-safe, otherwise we
would have a situation where two threads can create two groups with
the same name because both think that it doesn't exist yet.
I will anyway double-check if that's the case. Maybe it's a good idea
to protect both calls with a mutex anyway so we don't have to rely on
any assumptions?
> > + /* If the ThrottleState was not found something is seriously broken */
> > + if (!found) {
> > + return false;
> > + }
>
> Please correct me if I'm wrong but I suggest:
>
> Make this function void and replace this statement with
> assert(found). This case should never happen and I doubt callers
> will be able to handle the error case.
I think you're right, it seems that the only use of that is to check
its return value from the tests, but I don't see any other use case
for an unref() function returning a bool, so I'll make it void.
> > + ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts);
>
> Why can this function use container_of() while
> throttle_group_unref() has to loop over all ThrottleGroups to find
> ts?
I hadn't actually noticed this, thanks for pointing it out. I don't
think there's any need to loop over the groups, so I'll just use
container_of in both cases.
Thanks also for the rest of the suggestions, I'll include them the
next time I submit the patches.
Berto
next prev parent reply other threads:[~2015-03-04 10:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-13 16:06 [Qemu-devel] [PATCH v2 0/9] Block Throttle Group Support Alberto Garcia
2015-02-13 16:06 ` [Qemu-devel] [PATCH 1/9] throttle: Extract timers from ThrottleState into a separate ThrottleTimers structure Alberto Garcia
2015-03-03 16:03 ` Stefan Hajnoczi
2015-02-13 16:06 ` [Qemu-devel] [PATCH 2/9] throttle: Add throttle group infrastructure Alberto Garcia
2015-03-03 16:38 ` Stefan Hajnoczi
2015-03-04 10:18 ` Alberto Garcia [this message]
2015-03-04 16:02 ` Stefan Hajnoczi
2015-02-13 16:06 ` [Qemu-devel] [PATCH 3/9] throttle: Add throttle group infrastructure tests Alberto Garcia
2015-02-13 16:06 ` [Qemu-devel] [PATCH 4/9] throttle: Prepare to have multiple timers for one ThrottleState Alberto Garcia
2015-03-03 16:50 ` Stefan Hajnoczi
2015-02-13 16:06 ` [Qemu-devel] [PATCH 5/9] throttle: Add a way to know if throttle_schedule_timer had armed a timer Alberto Garcia
2015-02-13 16:06 ` [Qemu-devel] [PATCH 6/9] throttle: Add a way to fire one of the timers asap like a bottom half Alberto Garcia
2015-03-03 17:08 ` Stefan Hajnoczi
2015-02-13 16:06 ` [Qemu-devel] [PATCH 7/9] throttle: Add throttle group support Alberto Garcia
2015-02-24 16:45 ` Eric Blake
2015-02-24 16:47 ` Eric Blake
2015-03-03 21:00 ` Stefan Hajnoczi
2015-03-04 13:53 ` Alberto Garcia
2015-03-04 16:04 ` Stefan Hajnoczi
2015-03-04 16:16 ` Alberto Garcia
2015-03-05 17:41 ` Stefan Hajnoczi
2015-02-13 16:06 ` [Qemu-devel] [PATCH 8/9] throttle: Update throttle infrastructure copyright Alberto Garcia
2015-02-24 16:49 ` Eric Blake
2015-02-24 20:21 ` Benoît Canet
2015-02-13 16:06 ` [Qemu-devel] [PATCH 9/9] throttle: add name of ThrottleGroup to BlockDeviceInfo Alberto Garcia
2015-02-24 16:54 ` Eric Blake
2015-02-25 10:56 ` Alberto Garcia
2015-02-25 15:23 ` Eric Blake
2015-02-25 15:37 ` Alberto Garcia
2015-02-26 13:56 ` Alberto Garcia
2015-03-03 17:53 ` Eric Blake
2015-03-04 7:09 ` Markus Armbruster
2015-03-04 7:20 ` Alberto Garcia
2015-03-03 21:07 ` [Qemu-devel] [PATCH v2 0/9] Block Throttle Group Support Stefan Hajnoczi
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=20150304101821.GA5872@igalia.com \
--to=berto@igalia.com \
--cc=benoit.canet@nodalink.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
--cc=stefanha@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 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).