From patchwork Wed Oct 24 04:04:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 193651 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id ED5DF2C008B for ; Wed, 24 Oct 2012 15:05:25 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AC10A4A3CB; Wed, 24 Oct 2012 06:05:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jJu6y3bhUUzB; Wed, 24 Oct 2012 06:05:23 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 211E64A200; Wed, 24 Oct 2012 06:05:12 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 04DBB4A1EC for ; Wed, 24 Oct 2012 06:05:10 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SzcItvv4tYk0 for ; Wed, 24 Oct 2012 06:05:08 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-fa0-f74.google.com (mail-fa0-f74.google.com [209.85.161.74]) by theia.denx.de (Postfix) with ESMTPS id 2A43C4A18D for ; Wed, 24 Oct 2012 06:05:06 +0200 (CEST) Received: by mail-fa0-f74.google.com with SMTP id t1so5757fae.3 for ; Tue, 23 Oct 2012 21:05:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=rDs/X5/f0rrCgmd8lf9tUNw1oi2Uyght0YqxIzRRUYg=; b=oQju28ipzhjlBHNb6tJ4dGljB1UNy71crcsWUmH/15u7ByIsr5KMlBVFcwpHPu84o4 9Nyg/f/jfM3+HjoVlK2wNJexK7aZqB5LsCmnh6lk4F7jB8vufKWZrUmVLAJ0H3+iZamS I7LA8XDgmR4lwTWQNsVClvhzZ6SlGKQrWB7YoWzdW21vcyP94++UY8whZyRhMNiaVjvi KfdkOaS5rbvRXQcWUx5PZkOFzZknee7nhCMUAgVdzo4mSgeiUxrjgQYfBbTbrODY0UGR 4DOYTNAiPr7Vdv2OWAJ1TTr0dWiMLz8VDfFBrl/k5WJGSnSnEkJ5sFK9bZVPw6Wl9+aK 4cpQ== Received: by 10.181.13.75 with SMTP id ew11mr250544wid.0.1351051506099; Tue, 23 Oct 2012 21:05:06 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id z7si105360wiw.1.2012.10.23.21.05.06 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 23 Oct 2012 21:05:06 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id B12C120004E; Tue, 23 Oct 2012 21:05:05 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 22F58160D9C; Tue, 23 Oct 2012 21:05:05 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 23 Oct 2012 21:04:32 -0700 Message-Id: <1351051486-6980-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1351051486-6980-1-git-send-email-sjg@chromium.org> References: <1351051486-6980-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQmuYQ4KGSJ+6B159otUfnbDNtgNDg6pkr22G8ysS/RyWSW39AIJzvqGHtZBCISfQ2bdFiNrZWHicmMOeZJnzfkO1d+cFQzpX36GCOB9HwhHDej5o/B93y4z2Fb/OEXuJgYUDyc2bSatNO4dcnG4wNYuOziiXCAkSOQNjMd9bALsSWE4IWivKjkzBhpGfxFO3O9oSob/ Cc: Vadim Bendebury , Stefan Reinauer Subject: [U-Boot] [PATCH 01/15] x86: Add function to read time stamp counter X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Vadim Bendebury Put this function in the u-boot-x86.h header file. We could instead create timer.h perhaps. We support setting a base time, and reading the time relative to this base. Signed-off-by: Vadim Bendebury Signed-off-by: Stefan Reinauer Signed-off-by: Simon Glass --- arch/x86/include/asm/u-boot-x86.h | 12 ++++++++++++ arch/x86/lib/timer.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/asm/u-boot-x86.h b/arch/x86/include/asm/u-boot-x86.h index a4a5ae0..11be5c3 100644 --- a/arch/x86/include/asm/u-boot-x86.h +++ b/arch/x86/include/asm/u-boot-x86.h @@ -68,4 +68,16 @@ int video_init(void); void board_init_f_r_trampoline(ulong) __attribute__ ((noreturn)); void board_init_f_r(void) __attribute__ ((noreturn)); +/* Read the time stamp counter */ +static inline uint64_t rdtsc(void) +{ + uint32_t high, low; + __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)); + return (((uint64_t)high) << 32) | low; +} + +/* board/... */ +void timer_set_tsc_base(uint64_t new_base); +uint64_t timer_get_tsc(void); + #endif /* _U_BOOT_I386_H_ */ diff --git a/arch/x86/lib/timer.c b/arch/x86/lib/timer.c index fd7032e..a13424b 100644 --- a/arch/x86/lib/timer.c +++ b/arch/x86/lib/timer.c @@ -37,6 +37,7 @@ struct timer_isr_function { static struct timer_isr_function *first_timer_isr; static unsigned long system_ticks; +static uint64_t base_value; /* * register_timer_isr() allows multiple architecture and board specific @@ -98,3 +99,19 @@ ulong get_timer(ulong base) { return system_ticks - base; } + +void timer_set_tsc_base(uint64_t new_base) +{ + base_value = new_base; +} + +uint64_t timer_get_tsc(void) +{ + uint64_t time_now; + + time_now = rdtsc(); + if (!base_value) + base_value = time_now; + + return time_now - base_value; +}