From: Richard Henderson <richard.henderson@linaro.org>
To: Pranith Kumar <bobby.prani@gmail.com>,
alex.bennee@linaro.org, Paolo Bonzini <pbonzini@redhat.com>,
Sergey Fedorov <serge.fdrv@gmail.com>,
"open list:All patches CC here" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [RFC PATCH 2/3] cpus-common: Cache allocated work items
Date: Mon, 28 Aug 2017 10:47:28 -0700 [thread overview]
Message-ID: <8f6169d2-107c-ef7b-cc6f-1ad40a25365f@linaro.org> (raw)
In-Reply-To: <20170828035327.17146-2-bobby.prani@gmail.com>
On 08/27/2017 08:53 PM, Pranith Kumar wrote:
> Using heaptrack, I found that quite a few of our temporary allocations
> are coming from allocating work items. Instead of doing this
> continously, we can cache the allocated items and reuse them instead
> of freeing them.
>
> This reduces the number of allocations by 25% (200000 -> 150000 for
> ARM64 boot+shutdown test).
>
> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> ---
> cpus-common.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 70 insertions(+), 15 deletions(-)
>
> diff --git a/cpus-common.c b/cpus-common.c
> index 59f751ecf9..a1c4c7d1a3 100644
> --- a/cpus-common.c
> +++ b/cpus-common.c
> @@ -24,6 +24,7 @@
> #include "sysemu/cpus.h"
>
> static QemuMutex qemu_cpu_list_lock;
> +static QemuMutex qemu_wi_pool_lock;
> static QemuCond exclusive_cond;
> static QemuCond exclusive_resume;
> static QemuCond qemu_work_cond;
> @@ -33,6 +34,58 @@ static QemuCond qemu_work_cond;
> */
> static int pending_cpus;
>
> +typedef struct qemu_work_item {
> + struct qemu_work_item *next;
> + run_on_cpu_func func;
> + run_on_cpu_data data;
> + bool free, exclusive, done;
> +} qemu_work_item;
> +
> +typedef struct qemu_wi_pool {
> + qemu_work_item *first, *last;
> +} qemu_wi_pool;
> +
> +qemu_wi_pool *wi_free_pool;
> +
> +static void qemu_init_workitem_pool(void)
> +{
> + wi_free_pool = g_malloc0(sizeof(qemu_wi_pool));
> + wi_free_pool->first = NULL;
> + wi_free_pool->last = NULL;
> +}
> +
> +static void qemu_wi_pool_insert(qemu_work_item *item)
> +{
> + qemu_mutex_lock(&qemu_wi_pool_lock);
> + if (wi_free_pool->last == NULL) {
> + wi_free_pool->first = item;
> + wi_free_pool->last = item;
> + } else {
> + wi_free_pool->last->next = item;
> + wi_free_pool->last = item;
> + }
> + qemu_mutex_unlock(&qemu_wi_pool_lock);
> +}
> +
> +static qemu_work_item* qemu_wi_pool_remove(void)
> +{
> + qemu_mutex_lock(&qemu_wi_pool_lock);
> + qemu_work_item *ret = wi_free_pool->first;
> +
> + if (ret == NULL)
> + goto out;
> +
> + wi_free_pool->first = ret->next;
> + if (wi_free_pool->last == ret) {
> + wi_free_pool->last = NULL;
> + }
Why does this list need to record a "last" element?
It would seem a simple lifo would be sufficient.
(You would also be able to manage the list via cmpxchg without a separate lock,
but perhaps the difference between the two isn't measurable.)
r~
next prev parent reply other threads:[~2017-08-28 17:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-28 3:53 [Qemu-devel] [PATCH 1/3] target/arm: Remove stale comment Pranith Kumar
2017-08-28 3:53 ` [Qemu-devel] [RFC PATCH 2/3] cpus-common: Cache allocated work items Pranith Kumar
2017-08-28 17:47 ` Richard Henderson [this message]
2017-08-28 21:43 ` Pranith Kumar
2017-08-29 20:38 ` Paolo Bonzini
2017-08-28 19:05 ` Emilio G. Cota
2017-08-28 21:51 ` Pranith Kumar
2017-08-28 3:53 ` [Qemu-devel] [RFC PATCH 3/3] mttcg: Implement implicit ordering semantics Pranith Kumar
2017-08-28 17:57 ` Richard Henderson
2017-08-28 21:41 ` Pranith Kumar
2017-08-28 22:39 ` Richard Henderson
2017-08-28 17:42 ` [Qemu-devel] [PATCH 1/3] target/arm: Remove stale comment Richard Henderson
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=8f6169d2-107c-ef7b-cc6f-1ad40a25365f@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=bobby.prani@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=serge.fdrv@gmail.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).