qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: KONRAD Frederic <frederic.konrad@adacore.com>,
	Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Fabien Chouteau <chouteau@adacore.com>
Subject: Re: [PATCH 2/2] hw/timer/slavio_timer.c: Switch to transaction-based ptimer API
Date: Thu, 17 Oct 2019 17:22:52 +0200	[thread overview]
Message-ID: <f1ada0bb-4d8c-69cc-df00-3f69c3891718@redhat.com> (raw)
In-Reply-To: <CAFEAcA_jYjN=pQ719kbrRGXF2f8uDg_uj1r_dO0320qqB1Nppg@mail.gmail.com>

On 10/17/19 5:00 PM, Peter Maydell wrote:
> On Thu, 17 Oct 2019 at 15:54, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>
>> Hi Peter,
>>
>> On 10/17/19 3:23 PM, Peter Maydell wrote:
>>> Switch the slavio_timer code away from bottom-half based ptimers to
>>> the new transaction-based ptimer API.  This just requires adding
>>> begin/commit calls around the various places that modify the ptimer
>>> state, and using the new ptimer_init() function to create the timer.
>>>
>>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>>> ---
>>>    hw/timer/slavio_timer.c | 20 ++++++++++++++++----
>>>    1 file changed, 16 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/timer/slavio_timer.c b/hw/timer/slavio_timer.c
>>> index 692d213897d..0e2efe6fe89 100644
>>> --- a/hw/timer/slavio_timer.c
>>> +++ b/hw/timer/slavio_timer.c
>>> @@ -30,7 +30,6 @@
>>>    #include "hw/sysbus.h"
>>>    #include "migration/vmstate.h"
>>>    #include "trace.h"
>>> -#include "qemu/main-loop.h"
>>>    #include "qemu/module.h"
>>>
>>>    /*
>>> @@ -213,6 +212,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr,
>>>        saddr = addr >> 2;
>>>        switch (saddr) {
>>>        case TIMER_LIMIT:
>>> +        ptimer_transaction_begin(t->timer);
>>>            if (slavio_timer_is_user(tc)) {
>>>                uint64_t count;
>>
>>
>> This part is odd since there is a check on t->timer != NULL later, and
>> ptimer_transaction_commit() can't take NULL.
> 
> Hmm, I hadn't noticed that. I think the bug is the check
> for NULL, though, beacuse the slavio_timer_init() function
> always initializes all the timer pointers, so there's
> no situation where the pointer can be non-NULL as far
> as I can see. So I think I'd rather fix this by removing
> the NULL pointer check...

Yes, you are correct.

>>> @@ -255,13 +258,16 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr,
>>>        case TIMER_COUNTER_NORST:
>>>            // set limit without resetting counter
>>>            t->limit = val & TIMER_MAX_COUNT32;
>>> +        ptimer_transaction_begin(t->timer);
>>>            if (t->limit == 0) { /* free-run */
>>>                ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 0);
>>>            } else {
>>>                ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 0);
>>>            }
>>> +        ptimer_transaction_commit(t->timer);
>>>            break;
>>>        case TIMER_STATUS:
>>> +        ptimer_transaction_begin(t->timer);
>>>            if (slavio_timer_is_user(tc)) {
>>
>> I'd move the begin() here.
> 
> This would be awkward because then it won't neatly nest with
> the commit call unless you add an extra if() for the
> commit or otherwise rearrange/duplicate code...
> 
>>>                // start/stop user counter
>>>                if (val & 1) {
>>> @@ -273,6 +279,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr,
>>>                }
>>>            }
>>>            t->run = val & 1;
>>> +        ptimer_transaction_commit(t->timer);
> 
> ...because the commit should come after we have finished
> updating the timer state (t->run in this case), because
> the trigger callback slavio_timer_irq() otherwise sees
> inconsistent half-updated state if commit() calls it.

Oh, slavio_timer_irq() calls slavio_timer_get_out() which accesses the 
ptimer... OK I missed that.

Whew we need to be extra cautious with this API...

If possible I'd rather see the patch removing the NULL check previous to 
this one, anyway:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Thanks,

Phil.



  reply	other threads:[~2019-10-17 16:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 13:23 [PATCH 0/2] Convert sparc devices to new ptimer API Peter Maydell
2019-10-17 13:23 ` [PATCH 1/2] hw/timer/grlib_gptimer.c: Switch to transaction-based " Peter Maydell
2019-10-17 14:19   ` Richard Henderson
2019-10-17 14:46   ` Philippe Mathieu-Daudé
2019-10-17 13:23 ` [PATCH 2/2] hw/timer/slavio_timer.c: " Peter Maydell
2019-10-17 14:21   ` Richard Henderson
2019-10-17 14:54   ` Philippe Mathieu-Daudé
2019-10-17 15:00     ` Peter Maydell
2019-10-17 15:22       ` Philippe Mathieu-Daudé [this message]
2019-10-17 15:31         ` Peter Maydell
2019-10-20 16:11 ` [PATCH 0/2] Convert sparc devices to new " Mark Cave-Ayland

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=f1ada0bb-4d8c-69cc-df00-3f69c3891718@redhat.com \
    --to=philmd@redhat.com \
    --cc=chouteau@adacore.com \
    --cc=frederic.konrad@adacore.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).