All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Alcantara <pcacjr@zytor.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: seabios@seabios.org, Paulo Alcantara <pcacjr@gmail.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/3] ich9: add TCO interface emulation
Date: Wed, 27 May 2015 15:23:28 -0300	[thread overview]
Message-ID: <20150527152328.33a8acf5@zytor.com> (raw)
In-Reply-To: <5565B181.7020700@redhat.com>

On Wed, 27 May 2015 13:58:57 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:

> the main issue here is lack of migration support.  You need to add a
> new subsection to vmstate_ich9_pm that is migrated if the registers
> are different from the default values.

Hrm - OK. I didn't even take that into account. I'll do it.

> > +static QEMUTimer *tco_timer;
> > +static unsigned int timeouts_no;
> 
> These must not be globals.  Instead, add them to TCOIORegs.

OK.

> 
> > +static inline void tco_timer_reload(void)
> > +{
> > +    int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> > +
> > +    timer_del(tco_timer);
> > +    timer_mod(tco_timer, now + tco_ticks_per_sec());
> 
> No need for del+mod.  Also, these are not tco_ticks_per_sec() but
> rather TCO_TICK_NSEC.  It can be a #define instead of a function.

OK.

> For a little extra challenge, you could the base value when the timer
> was started inside TCOIORegs.  The timer can be made to expire
> directly after 0.6*TCO_TMR seconds; you can use the base value and
> the current time to compute the value of TCO_RLD.  Something like:
> 
>     case TCO_RLD:
>         rld = tr->tco.rld;
>         /* base_clock is set to -1 in tco_timer_stop, reloaded in
>          * tco_timer_reload.
>          */
>         if (base_clock != -1) {
>             elapsed = (qemu_get_clock(QEMU_CLOCK_VIRTUAL) -
> base_clock) / TCO_TICK_NSEC;
>             rld -= MIN(elapsed, rld);
>         }
> 
> This makes it possible for QEMU to sleep most of the time when the
> guest is idle, instead of waking up every 0.6 seconds.  But feel free
> to work on this afterwards.

Nice. I liked your approach and that will definitely avoid overheard
waking up on every 0.6s. No, I will work on this approach right now so
I can sleep well.

> 
> > +void acpi_pm_tco_init(TCOIORegs *tr)
> > +{
> > +    *tr = TCO_IO_REGS_DEFAULTS_INIT();
> 
> Just inline the macro definition here.

OK.

> > +    case TCO1_CNT:
> > +        val &= TCO1_CNT_MASK;
> > +        /* TCO_LOCK bit cannot be changed once set */
> > +        tr->tco.cnt1 = (val & ~TCO_LOCK) | (tr->tco.cnt1 &
> > TCO_LOCK);
> 
> This means that TCO_LOCK is never set in tr->tco.cnt1, I think?  If
> I'm correct, it should be covered by tests.

No. The TCO_LOCK bit is set in tr->tco.cnt1, but cannot be unset
afterwards -- on reset, of course, it will. Maybe a test that covers
setting it and then unsetting it might be interesting to have in
tests/tco-test.c.

> > +#define TCO_IO_REGS_DEFAULTS_INIT()             \
> > +    (TCOIORegs) {                               \
> > +        .tco = {                                \
> > +            .rld      = TCO_RLD_DEFAULT,        \
> > +            .din      = TCO_DAT_IN_DEFAULT,     \
> > +            .dout     = TCO_DAT_OUT_DEFAULT,    \
> > +            .sts1     = TCO1_STS_DEFAULT,       \
> > +            .sts2     = TCO2_STS_DEFAULT,       \
> > +            .cnt1     = TCO1_CNT_DEFAULT,       \
> > +            .cnt2     = TCO2_CNT_DEFAULT,       \
> > +            .msg1     = TCO_MESSAGE1_DEFAULT,   \
> > +            .msg2     = TCO_MESSAGE2_DEFAULT,   \
> > +            .wdcnt    = TCO_WDCNT_DEFAULT,      \
> > +            .tmr      = TCO_TMR_DEFAULT,        \
> > +        },                                      \
> > +        .sw_irq_gen = SW_IRQ_GEN_DEFAULT        \
> > +    }
> 
> No need for this definition.  This and the *_DEFAULT definitions as
> well should be in the .c file.

OK.

> 
> > +/* tco.c */
> > +void acpi_pm_tco_init(TCOIORegs *tr);
> > +uint32_t acpi_pm_tco_ioport_readw(TCOIORegs *tr, uint32_t addr);
> > +void acpi_pm_tco_ioport_writew(TCOIORegs *tr, uint32_t addr,
> > uint32_t val); +
> > +/* As per ICH9 spec, the internal timer has an error of ~0.6s on
> > every tick */ +static inline int64_t tco_ticks_per_sec(void)
> > +{
> > +    return 600000000LL;
> > +}
> > +
> > +static inline int is_valid_tco_time(uint32_t val)
> > +{
> > +    /* values of 0 or 1 will be ignored by ICH */
> > +    return val > 1;
> > +}
> > +
> > +static inline int can_start_tco_timer(TCOIORegs *tr)
> > +{
> > +    return !(tr->tco.cnt1 & TCO_TMR_HLT) &&
> > is_valid_tco_time(tr->tco.tmr); +}
> 
> These three inlines should be in the .c file.

OK.

> 
> Don't be discouraged by the comments.  It's good work!

Alright. Thank you for the comments! I'll send a v2 soon.

Paulo

-- 
Paulo Alcantara, C.E.S.A.R
Speaking for myself only.

  reply	other threads:[~2015-05-27 18:23 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27  0:29 [Qemu-devel] [PATCH 1/3] ich9: add TCO interface emulation Paulo Alcantara
2015-05-27  0:29 ` [Qemu-devel] [PATCH 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table Paulo Alcantara
2015-05-27 12:03   ` Paolo Bonzini
2015-05-27 17:51     ` Paulo Alcantara
2015-05-28  7:13   ` [Qemu-devel] [SeaBIOS] " Gerd Hoffmann
2015-05-30 10:57     ` Paulo Alcantara
2015-06-01  7:16       ` Gerd Hoffmann
2015-06-01 11:59         ` Paulo Alcantara
2015-05-27  0:29 ` [Qemu-devel] [PATCH 3/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-05-27 11:58 ` [Qemu-devel] [PATCH 1/3] ich9: add TCO interface emulation Paolo Bonzini
2015-05-27 18:23   ` Paulo Alcantara [this message]
2015-05-30 22:04 ` [Qemu-devel] [PATCH v2 " Paulo Alcantara
2015-05-30 22:04   ` [Qemu-devel] [PATCH v2 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table Paulo Alcantara
2015-05-30 22:04   ` [Qemu-devel] [PATCH v2 3/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-01  9:07     ` Paolo Bonzini
2015-06-01  9:05   ` [Qemu-devel] [PATCH v2 1/3] ich9: add TCO interface emulation Paolo Bonzini
2015-06-01 13:38     ` Paulo Alcantara
2015-06-01 21:37       ` Paulo Alcantara
2015-06-01 23:48   ` [Qemu-devel] [PATCH v3 " Paulo Alcantara
2015-06-01 23:48     ` [Qemu-devel] [PATCH v3 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table Paulo Alcantara
2015-06-17 13:33       ` Michael S. Tsirkin
2015-06-18  2:14         ` Paulo Alcantara
2015-06-01 23:48     ` [Qemu-devel] [PATCH v3 3/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-17 13:37       ` Michael S. Tsirkin
2015-06-18  2:23         ` Paulo Alcantara
2015-06-10 13:17     ` [Qemu-devel] [PATCH v3 1/3] ich9: add TCO interface emulation Paulo Alcantara
2015-06-17 13:27     ` Michael S. Tsirkin
2015-06-18  2:10       ` Paulo Alcantara
2015-06-22  0:37 ` [Qemu-devel] [PATCH v4 " Paulo Alcantara
2015-06-22  0:37   ` [Qemu-devel] [PATCH v4 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table Paulo Alcantara
2015-06-22  8:40     ` Michael S. Tsirkin
2015-06-22 12:53       ` Paulo Alcantara
2015-06-23 10:38     ` [Qemu-devel] [SeaBIOS] " Igor Mammedov
2015-06-23 10:58       ` Michael S. Tsirkin
2015-06-23 12:29         ` Igor Mammedov
2015-06-23 12:37           ` Michael S. Tsirkin
2015-06-23 11:15       ` Paolo Bonzini
2015-06-23 11:18       ` Paolo Bonzini
2015-06-23 12:22       ` Michael S. Tsirkin
2015-06-22  0:37   ` [Qemu-devel] [PATCH v4 3/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-22  8:39   ` [Qemu-devel] [PATCH v4 1/3] ich9: add TCO interface emulation Michael S. Tsirkin
2015-06-22 12:30     ` Paulo Alcantara
2015-06-22 12:32       ` Paolo Bonzini
2015-06-22 12:47         ` Michael S. Tsirkin
2015-06-22 13:04           ` Paolo Bonzini
2015-06-22 13:07             ` Michael S. Tsirkin
2015-06-22 13:19               ` Paulo Alcantara
2015-06-22 13:10           ` Markus Armbruster
2015-06-22  8:43   ` Michael S. Tsirkin
2015-06-22  9:45     ` Paolo Bonzini
2015-06-22 12:11       ` Michael S. Tsirkin
2015-06-22 12:36         ` Paulo Alcantara
2015-06-22 12:44           ` Michael S. Tsirkin
2015-06-22 12:59             ` Paolo Bonzini
2015-06-22 18:29   ` Paulo Alcantara
2015-06-22 23:10 ` [Qemu-devel] [PATCH v5 " Paulo Alcantara
2015-06-22 23:10   ` [Qemu-devel] [PATCH v5 2/3] target-i386: reserve RCRB mmio space in ACPI DSDT table Paulo Alcantara
2015-06-23 14:29     ` [Qemu-devel] [SeaBIOS] " Igor Mammedov
2015-06-23 15:33       ` Michael S. Tsirkin
2015-06-23 14:39     ` Igor Mammedov
2015-06-23 15:06       ` Michael S. Tsirkin
2015-06-23 15:12         ` Igor Mammedov
2015-06-23 15:29           ` Michael S. Tsirkin
2015-06-24 15:11     ` [Qemu-devel] " Michael S. Tsirkin
2015-06-24 16:00       ` Paulo Alcantara
2015-06-24 16:04         ` Michael S. Tsirkin
2015-06-22 23:10   ` [Qemu-devel] [PATCH v5 3/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-23  6:39   ` [Qemu-devel] [PATCH v5 1/3] ich9: add TCO interface emulation Michael S. Tsirkin
2015-06-24 18:03 ` [Qemu-devel] [PATCH v6 1/2] " Paulo Alcantara
2015-06-24 18:03   ` [Qemu-devel] [PATCH v6 2/2] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-27 17:56 ` [Qemu-devel] [PATCH v7 1/3] ich9: add TCO interface emulation Paulo Alcantara
2015-06-27 17:56   ` [Qemu-devel] [PATCH v7 2/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-27 17:56   ` [Qemu-devel] [PATCH v7 3/3] ich9: implement strap SPKR pin logic Paulo Alcantara
2015-06-28  8:37     ` Michael S. Tsirkin
2015-06-28 16:21       ` Paulo Alcantara
2015-06-28 17:58 ` [Qemu-devel] [PATCH v8 1/3] ich9: add TCO interface emulation Paulo Alcantara
2015-06-28 17:58   ` [Qemu-devel] [PATCH v8 2/3] tests: add testcase for TCO watchdog emulation Paulo Alcantara
2015-06-28 17:58   ` [Qemu-devel] [PATCH v8 3/3] ich9: implement strap SPKR pin logic Paulo Alcantara
2015-07-01 13:18     ` Paolo Bonzini
2015-07-01 13:31       ` Michael S. Tsirkin
2015-07-01 13:34         ` Paolo Bonzini
2015-07-02  1:30         ` Paulo Alcantara
2015-07-02  6:55           ` Paolo Bonzini

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=20150527152328.33a8acf5@zytor.com \
    --to=pcacjr@zytor.com \
    --cc=pbonzini@redhat.com \
    --cc=pcacjr@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.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 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.