All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: Dave Scott <Dave.Scott@citrix.com>
Cc: Thomas Leonard <talex5@gmail.com>,
	Ian Campbell <Ian.Campbell@citrix.com>,
	Anil Madhavapeddy <anil@recoil.org>,
	Stefano Stabellini <Stefano.Stabellini@citrix.com>,
	Samuel Thibault <samuel.thibault@ens-lyon.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH ARM v7 09/13] mini-os: arm: time
Date: Tue, 23 Sep 2014 17:53:07 +0100	[thread overview]
Message-ID: <alpine.DEB.2.02.1409231747080.22344@kaball.uk.xensource.com> (raw)
In-Reply-To: <2E60909D-BE55-4E5C-8A38-98808E5893A3@citrix.com>

[-- Attachment #1: Type: text/plain, Size: 5415 bytes --]

On Mon, 22 Sep 2014, Dave Scott wrote:
> Hi,
> 
> On 8 Sep 2014, at 17:08, Thomas Leonard <talex5@gmail.com> wrote:
> 
> > On 8 September 2014 11:59, Ian Campbell <Ian.Campbell@citrix.com> wrote:
> >> On Fri, 2014-08-08 at 16:47 +0100, Thomas Leonard wrote:
> >> 
> >> Sorry for how long I took to get to this, travel and the resulting
> >> backlog conspired against me.
> > 
> > Hi Ian,
> > 
> > I'm on holiday for a few weeks now. Please feel free to apply any
> > minor changes if you don't want to wait. In any case, I'll take
> > another look at the end of Sep.
> > 
> > Regards,
> > 
> >>> +    __asm__ __volatile__("isb;mrrc p15, 1, %0, %1, c14":"=r"(c_lo), "=r"(c_hi));
> >> 
> >> Is the isb really necessary here?
> > 
> > I don't think so.
> > 
> >>> +    return (((uint64_t) c_hi) << 32) + c_lo;
> >>> +}
> >>> +
> >>> +/* monotonic_clock(): returns # of nanoseconds passed since time_init()
> >>> + *        Note: This function is required to return accurate
> >>> + *        time even in the absence of multiple timer ticks.
> >>> + */
> >>> +uint64_t monotonic_clock(void)
> >>> +{
> >>> +    s_time_t time = ticks_to_ns(read_virtual_count() - cntvct_at_init);
> >>> +    //printk("monotonic_clock: %llu (%llu)\n", time, NSEC_TO_SEC(time));
> >> 
> >> There's quite a few of these //printk(debug) statements in this patch...
> >> 
> >>> +    return time;
> >>> +}
> >>> +
> >>> +int gettimeofday(struct timeval *tv, void *tz)
> >>> +{
> >>> +    uint64_t nsec = monotonic_clock();
> >>> +    nsec += shadow_ts.tv_nsec;
> >>> +
> >>> +    tv->tv_sec = shadow_ts.tv_sec;
> >>> +    tv->tv_sec += NSEC_TO_SEC(nsec);
> >>> +    tv->tv_usec = NSEC_TO_USEC(nsec % 1000000000UL);
> >>> +
> >>> +    return 0;
> >>> +}
> >>> +
> >>> +void set_vtimer_compare(uint64_t value) {
> >>> +    uint32_t x, y;
> >>> +
> >>> +    DEBUG("New CompareValue : %llx\n", value);
> >>> +    x = 0xFFFFFFFFULL & value;
> >>> +    y = (value >> 32) & 0xFFFFFFFF;
> >>> +
> >>> +    __asm__ __volatile__("mcrr p15, 3, %0, %1, c14"
> >>> +            ::"r"(x), "r"(y));
> >> 
> >> I think you can use
> >>        "mcrr p15, 3, %0, %H0, c14" :: "r" (value)
> >> here.
> >> 
> >> 
> >>> +
> >>> +    __asm__ __volatile__("mov %0, #0x1\n"
> >>> +            "mcr p15, 0, %0, c14, c3, 1\n" /* Enable timer and unmask the output signal */
> >>> +            "isb":"=r"(x));
> >> 
> >> x = 1 before this would avoid the mov inside the inline stuff as well as
> >> the strange looking use of an output register for a write.
> >> 
> >>> +}
> >>> +
> >>> +void unset_vtimer_compare(void) {
> >>> +    uint32_t x;
> >>> +
> >>> +    __asm__ __volatile__("mov %0, #0x2\n"
> >>> +            "mcr p15, 0, %0, c14, c3, 1\n" /* Disable timer and mask the output signal */
> >>> +            "isb":"=r"(x));
> >> 
> >> and again. You probably just want a write_timer_ctl(uiint.. val) type
> >> function.
> >> 
> >>> +}
> >>> +
> >>> +void block_domain(s_time_t until)
> >>> +{
> >>> +    uint64_t until_count = ns_to_ticks(until) + cntvct_at_init;
> >>> +    ASSERT(irqs_disabled());
> >>> +    if (read_virtual_count() < until_count)
> >>> +    {
> >>> +        set_vtimer_compare(until_count);
> >>> +        //char buf[] = "sleep\n"; (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(buf), buf);
> >>> +        __asm__ __volatile__("wfi");
> >>> +        //char wake[] = "wake\n"; (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(wake), wake);
> >> 
> >> More left over debug.
> 
> I had a play with this yesterday on my cubieboard with Mirage. Using network and vchan connections worked fine, so event channels are working ok. However when I had no external event channel input and my domain blocked on a timer, it seemed to block forever in the ‘wfi’ (as I could see by enabling these debug lines and then pressing ‘enter’ to trigger an interrupt on the console). As far as I can tell the monotonic clock is giving me sensible values, and the ‘until’ value looked sensible. For now I can work around the problem by attaching a vif to a busy network :-)
> 
> Sorry for the vagueness of the bug report. I’ll try to make a more minimal repro example when I get the time.

This reminds me of many fun memories about late debugging sessions.

What Xen version are you using?

WFI means wait-for-interrupt and it is trapped into Xen, see:

xen/arch/arm/traps.c:do_trap_hypervisor, label HSR_EC_WFI_WFE.

When the guest issues a WFI instruction, Xen blocks the vcpu on its
behalf. Any interrupt for the vcpu in question should wake it up, see
the vcpu_unblock call at the end of
xen/arch/arm/vgic.c:vgic_vcpu_inject_irq. vgic_vcpu_inject_irq is called
by the timer code, both vtimer.c (emulated time) and time.c (virtual
timer).

If something goes wrong with the wake-up, the vcpu could remain blocked.

Have fun! ;-)


> Dave
> 
> 
> >> 
> >>> +        unset_vtimer_compare();
> >>> +
> >>> +        /* Give the IRQ handler a chance to handle whatever woke us up. */
> >>> +        local_irq_enable();
> >>> +        local_irq_disable();
> >>> +    }
> >>> +}
> >> 
> >> Ian.
> >> 
> > 
> > 
> > 
> > -- 
> > Dr Thomas Leonard        http://0install.net/
> > GPG: 9242 9807 C985 3C07 44A6  8B9A AE07 8280 59A5 3CC1
> > GPG: DA98 25AE CAD0 8975 7CDA  BD8E 0713 3F96 CA74 D8BA
> 

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2014-09-23 16:55 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-08 15:47 [PATCH ARM v7 00/13] mini-os: initial ARM support Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 01/13] mini-os: don't include lib.h from mm.h Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 02/13] mini-os: added HYPERVISOR_xsm_op Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 03/13] mini-os: move poor rand function to test.c Thomas Leonard
2014-08-08 16:37   ` Samuel Thibault
2014-08-11  7:59     ` Thomas Leonard
2014-08-11  9:29       ` Samuel Thibault
2014-08-28 15:07         ` Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 04/13] mini-os: arm: add header files Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 05/13] mini-os: arm: boot code Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 06/13] mini-os: arm: memory management Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 07/13] mini-os: arm: scheduling Thomas Leonard
2014-08-08 15:47 ` [PATCH ARM v7 08/13] mini-os: arm: events Thomas Leonard
2014-09-08 11:52   ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 09/13] mini-os: arm: time Thomas Leonard
2014-09-08 10:59   ` Ian Campbell
2014-09-08 16:08     ` Thomas Leonard
2014-09-22 10:35       ` Dave Scott
2014-09-23 16:53         ` Stefano Stabellini [this message]
2014-09-26 10:01         ` Thomas Leonard
2014-10-01 11:10         ` Thomas Leonard
2014-10-01 11:10         ` Thomas Leonard
2014-10-01 11:31           ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 10/13] mini-os: arm: interrupt controller Thomas Leonard
2014-09-08 11:01   ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 11/13] mini-os: arm: build system Thomas Leonard
2014-09-08 11:05   ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 12/13] mini-os: arm: show registers, stack and exception vector on fault Thomas Leonard
2014-09-08 11:06   ` Ian Campbell
2014-08-08 15:47 ` [PATCH ARM v7 13/13] mini-os: fixed compiling with debug=n Thomas Leonard
2014-09-08 11:08   ` Ian Campbell

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=alpine.DEB.2.02.1409231747080.22344@kaball.uk.xensource.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=Dave.Scott@citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Stefano.Stabellini@citrix.com \
    --cc=anil@recoil.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=talex5@gmail.com \
    --cc=xen-devel@lists.xenproject.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.