From: Ian Campbell Subject: Re: [PATCH ARM v7 09/13] mini-os: arm: time Date: Mon, 8 Sep 2014 11:59:43 +0100 Message-ID: <1410173983.10156.167.camel@kazak.uk.xensource.com> References: <1407512862-9373-1-git-send-email-talex5@gmail.com> <1407512862-9373-10-git-send-email-talex5@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XQwfk-0007Cn-K2 for xen-devel@lists.xenproject.org; Mon, 08 Sep 2014 10:59:48 +0000 In-Reply-To: <1407512862-9373-10-git-send-email-talex5@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Thomas Leonard Cc: xen-devel@lists.xenproject.org, stefano.stabellini@eu.citrix.com, Dave.Scott@eu.citrix.com, samuel.thibault@ens-lyon.org, anil@recoil.org List-Id: xen-devel@lists.xenproject.org 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. > + __asm__ __volatile__("isb;mrrc p15, 1, %0, %1, c14":"=r"(c_lo), "=r"(c_hi)); Is the isb really necessary here? > + 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. > + unset_vtimer_compare(); > + > + /* Give the IRQ handler a chance to handle whatever woke us up. */ > + local_irq_enable(); > + local_irq_disable(); > + } > +} Ian.