From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Richard Henderson" <rth@twiddle.net>,
"MTTCG Devel" <mttcg@listserver.greensocs.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"KONRAD Frédéric" <fred.konrad@greensocs.com>,
"Alvise Rigo" <a.rigo@virtualopensystems.com>,
"Emilio G. Cota" <cota@braap.org>,
"Pranith Kumar" <bobby.prani@gmail.com>,
"Nikunj A Dadhania" <nikunj@linux.vnet.ibm.com>,
"Mark Burton" <mark.burton@greensocs.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Jan Kiszka" <jan.kiszka@siemens.com>,
"Fedorov Sergey" <serge.fdrv@gmail.com>,
"Bamvor Zhang Jian" <bamvor.zhangjian@linaro.org>,
"Peter Chubb" <peter.chubb@nicta.com.au>,
"open list:i.MX31" <qemu-arm@nongnu.org>
Subject: Re: [PATCH v11 23/24] hw/misc/imx6_src: defer clearing of SRC_SCR reset bits
Date: Fri, 10 Feb 2017 15:19:17 +0000 [thread overview]
Message-ID: <87tw82vzt6.fsf@linaro.org> (raw)
In-Reply-To: <CAFEAcA8_UNip6QooREop-T5RBpdo1me0piEAscJRC+G7tGcNrA@mail.gmail.com>
Peter Maydell <peter.maydell@linaro.org> writes:
> On 9 February 2017 at 17:09, Alex Bennée <alex.bennee@linaro.org> wrote:
>> The arm_reset_cpu/set_cpu_on/set_cpu_off() functions do their work
>> asynchronously in the target vCPUs context. As a result we need to
>> ensure the SRC_SCR reset bits correctly report the reset status at the
>> right time. To do this we defer the clearing of the bit with an async
>> job which will run after the work queued by ARM powerctl functions.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> hw/misc/imx6_src.c | 58 +++++++++++++++++++++++++++++++++++++++++++++---------
>> 1 file changed, 49 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c
>> index 55b817b8d7..f7c1d94a3e 100644
>> --- a/hw/misc/imx6_src.c
>> +++ b/hw/misc/imx6_src.c
>> @@ -14,6 +14,7 @@
>> #include "qemu/bitops.h"
>> #include "qemu/log.h"
>> #include "arm-powerctl.h"
>> +#include "qom/cpu.h"
>>
>> #ifndef DEBUG_IMX6_SRC
>> #define DEBUG_IMX6_SRC 0
>> @@ -113,6 +114,45 @@ static uint64_t imx6_src_read(void *opaque, hwaddr offset, unsigned size)
>> return value;
>> }
>>
>> +
>> +/* The reset is asynchronous so we need to defer clearing the reset
>> + * bit until the work is completed.
>> + */
>> +
>> +struct src_scr_reset_info {
>
> Struct names should be CamelCase.
>
>> + IMX6SRCState *s;
>> + unsigned long reset_bit;
>
> Unsigned long ? That's always a bit of a red flag because it's
> variable in size from host to host. I think you want "int".
Yeah that's a hangover from the original code that was using unsigned
long for holding bitfields. I'll drop it down to int.
>
>> +};
>> +
>> +static void imx6_clear_reset_bit(CPUState *cpu, run_on_cpu_data data)
>> +{
>> + struct src_scr_reset_info *ri = data.host_ptr;
>> + IMX6SRCState *s = ri->s;
>> +
>> + assert(qemu_mutex_iothread_locked());
>> +
>> + s->regs[SRC_SCR] = deposit32(s->regs[SRC_SCR], ri->reset_bit, 1, 0);
>> + DPRINTF("reg[%s] <= 0x%" PRIx32 "\n",
>> + imx6_src_reg_name(SRC_SCR), s->regs[SRC_SCR]);
>> +
>> + g_free(ri);
>> +}
>> +
>> +static void imx6_defer_clear_reset_bit(int cpuid,
>> + IMX6SRCState *s,
>> + unsigned long reset_shift)
>> +{
>> + struct src_scr_reset_info *ri;
>> +
>> + ri = g_malloc(sizeof(struct src_scr_reset_info));
>> + ri->s = s;
>> + ri->reset_bit = reset_shift;
>> +
>> + async_run_on_cpu(arm_get_cpu_by_id(cpuid), imx6_clear_reset_bit,
>> + RUN_ON_CPU_HOST_PTR(ri));
>> +}
>
> What happens if we do a system reset between calling this
> and the async hook running? Do all the outstanding async
> run hooks guarantee to run first?
Yes they run in the order they are queued.
>
> I guess a malloc-and-free is OK since the guest isn't going to be
> bouncing CPUs through reset very often, though it's a bit ugly to
> see in device code.
Previous patches had expanded the run_on_cpu code to have things like
CPUState and a single field to avoid malloc where we can. However I need
the IMX6SRCState and I don't know if I can get that in the work
function. Will there only ever be one on the system?
>
> Otherwise this looks OK.
>
> thanks
> -- PMM
--
Alex Bennée
WARNING: multiple messages have this Message-ID (diff)
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Richard Henderson" <rth@twiddle.net>,
"MTTCG Devel" <mttcg@listserver.greensocs.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"KONRAD Frédéric" <fred.konrad@greensocs.com>,
"Alvise Rigo" <a.rigo@virtualopensystems.com>,
"Emilio G. Cota" <cota@braap.org>,
"Pranith Kumar" <bobby.prani@gmail.com>,
"Nikunj A Dadhania" <nikunj@linux.vnet.ibm.com>,
"Mark Burton" <mark.burton@greensocs.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Jan Kiszka" <jan.kiszka@siemens.com>,
"Fedorov Sergey" <serge.fdrv@gmail.com>,
"Bamvor Zhang Jian" <bamvor.zhangjian@linaro.org>,
"Peter Chubb" <peter.chubb@nicta.com.au>,
"open list:i.MX31" <qemu-arm@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v11 23/24] hw/misc/imx6_src: defer clearing of SRC_SCR reset bits
Date: Fri, 10 Feb 2017 15:19:17 +0000 [thread overview]
Message-ID: <87tw82vzt6.fsf@linaro.org> (raw)
In-Reply-To: <CAFEAcA8_UNip6QooREop-T5RBpdo1me0piEAscJRC+G7tGcNrA@mail.gmail.com>
Peter Maydell <peter.maydell@linaro.org> writes:
> On 9 February 2017 at 17:09, Alex Bennée <alex.bennee@linaro.org> wrote:
>> The arm_reset_cpu/set_cpu_on/set_cpu_off() functions do their work
>> asynchronously in the target vCPUs context. As a result we need to
>> ensure the SRC_SCR reset bits correctly report the reset status at the
>> right time. To do this we defer the clearing of the bit with an async
>> job which will run after the work queued by ARM powerctl functions.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>> hw/misc/imx6_src.c | 58 +++++++++++++++++++++++++++++++++++++++++++++---------
>> 1 file changed, 49 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c
>> index 55b817b8d7..f7c1d94a3e 100644
>> --- a/hw/misc/imx6_src.c
>> +++ b/hw/misc/imx6_src.c
>> @@ -14,6 +14,7 @@
>> #include "qemu/bitops.h"
>> #include "qemu/log.h"
>> #include "arm-powerctl.h"
>> +#include "qom/cpu.h"
>>
>> #ifndef DEBUG_IMX6_SRC
>> #define DEBUG_IMX6_SRC 0
>> @@ -113,6 +114,45 @@ static uint64_t imx6_src_read(void *opaque, hwaddr offset, unsigned size)
>> return value;
>> }
>>
>> +
>> +/* The reset is asynchronous so we need to defer clearing the reset
>> + * bit until the work is completed.
>> + */
>> +
>> +struct src_scr_reset_info {
>
> Struct names should be CamelCase.
>
>> + IMX6SRCState *s;
>> + unsigned long reset_bit;
>
> Unsigned long ? That's always a bit of a red flag because it's
> variable in size from host to host. I think you want "int".
Yeah that's a hangover from the original code that was using unsigned
long for holding bitfields. I'll drop it down to int.
>
>> +};
>> +
>> +static void imx6_clear_reset_bit(CPUState *cpu, run_on_cpu_data data)
>> +{
>> + struct src_scr_reset_info *ri = data.host_ptr;
>> + IMX6SRCState *s = ri->s;
>> +
>> + assert(qemu_mutex_iothread_locked());
>> +
>> + s->regs[SRC_SCR] = deposit32(s->regs[SRC_SCR], ri->reset_bit, 1, 0);
>> + DPRINTF("reg[%s] <= 0x%" PRIx32 "\n",
>> + imx6_src_reg_name(SRC_SCR), s->regs[SRC_SCR]);
>> +
>> + g_free(ri);
>> +}
>> +
>> +static void imx6_defer_clear_reset_bit(int cpuid,
>> + IMX6SRCState *s,
>> + unsigned long reset_shift)
>> +{
>> + struct src_scr_reset_info *ri;
>> +
>> + ri = g_malloc(sizeof(struct src_scr_reset_info));
>> + ri->s = s;
>> + ri->reset_bit = reset_shift;
>> +
>> + async_run_on_cpu(arm_get_cpu_by_id(cpuid), imx6_clear_reset_bit,
>> + RUN_ON_CPU_HOST_PTR(ri));
>> +}
>
> What happens if we do a system reset between calling this
> and the async hook running? Do all the outstanding async
> run hooks guarantee to run first?
Yes they run in the order they are queued.
>
> I guess a malloc-and-free is OK since the guest isn't going to be
> bouncing CPUs through reset very often, though it's a bit ugly to
> see in device code.
Previous patches had expanded the run_on_cpu code to have things like
CPUState and a single field to avoid malloc where we can. However I need
the IMX6SRCState and I don't know if I can get that in the work
function. Will there only ever be one on the system?
>
> Otherwise this looks OK.
>
> thanks
> -- PMM
--
Alex Bennée
next prev parent reply other threads:[~2017-02-10 15:19 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-09 17:08 [Qemu-devel] [PATCH v11 00/24] MTTCG Base enabling patches with ARM enablement Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 01/24] docs: new design document multi-thread-tcg.txt Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 02/24] mttcg: translate-all: Enable locking debug in a debug build Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 03/24] mttcg: Add missing tb_lock/unlock() in cpu_exec_step() Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 04/24] tcg: move TCG_MO/BAR types into own file Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 05/24] tcg: add options for enabling MTTCG Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 06/24] tcg: add kick timer for single-threaded vCPU emulation Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 07/24] tcg: rename tcg_current_cpu to tcg_current_rr_cpu Alex Bennée
2017-02-09 17:08 ` [PATCH v11 08/24] tcg: drop global lock during TCG code execution Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] " Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 09/24] tcg: remove global exit_request Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 10/24] tcg: enable tb_lock() for SoftMMU Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 11/24] tcg: enable thread-per-vCPU Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 12/24] tcg: handle EXCP_ATOMIC exception for system emulation Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 13/24] cputlb: add assert_cpu_is_self checks Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 14/24] cputlb: tweak qemu_ram_addr_from_host_nofail reporting Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 15/24] cputlb: introduce tlb_flush_* async work Alex Bennée
2017-02-09 17:08 ` [PATCH v11 16/24] cputlb and arm/sparc targets: convert mmuidx flushes from varg to bitmap Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] " Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 17/24] cputlb: add tlb_flush_by_mmuidx async routines Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 18/24] cputlb: atomically update tlb fields used by tlb_reset_dirty Alex Bennée
2017-02-09 17:08 ` [Qemu-devel] [PATCH v11 19/24] cputlb: introduce tlb_flush_*_all_cpus[_synced] Alex Bennée
2017-02-09 17:09 ` [PATCH v11 20/24] target-arm/powerctl: defer cpu reset work to CPU context Alex Bennée
2017-02-09 17:09 ` [Qemu-devel] " Alex Bennée
2017-02-10 14:46 ` Peter Maydell
2017-02-10 14:46 ` [Qemu-devel] " Peter Maydell
2017-02-09 17:09 ` [PATCH v11 21/24] target-arm: don't generate WFE/YIELD calls for MTTCG Alex Bennée
2017-02-09 17:09 ` [Qemu-devel] " Alex Bennée
2017-02-09 17:09 ` [PATCH v11 22/24] target-arm: ensure all cross vCPUs TLB flushes complete Alex Bennée
2017-02-09 17:09 ` [Qemu-devel] " Alex Bennée
2017-02-09 17:09 ` [PATCH v11 23/24] hw/misc/imx6_src: defer clearing of SRC_SCR reset bits Alex Bennée
2017-02-09 17:09 ` [Qemu-devel] " Alex Bennée
2017-02-10 14:53 ` Peter Maydell
2017-02-10 14:53 ` [Qemu-devel] " Peter Maydell
2017-02-10 15:19 ` Alex Bennée [this message]
2017-02-10 15:19 ` Alex Bennée
2017-02-10 15:34 ` Peter Maydell
2017-02-10 15:34 ` [Qemu-devel] " Peter Maydell
2017-02-09 17:09 ` [PATCH v11 24/24] tcg: enable MTTCG by default for ARM on x86 hosts Alex Bennée
2017-02-09 17:09 ` [Qemu-devel] " Alex Bennée
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=87tw82vzt6.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=a.rigo@virtualopensystems.com \
--cc=bamvor.zhangjian@linaro.org \
--cc=bobby.prani@gmail.com \
--cc=cota@braap.org \
--cc=fred.konrad@greensocs.com \
--cc=jan.kiszka@siemens.com \
--cc=mark.burton@greensocs.com \
--cc=mttcg@listserver.greensocs.com \
--cc=nikunj@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.chubb@nicta.com.au \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--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 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.