From patchwork Thu Oct 22 20:17:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 36752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9EDF7B7BBF for ; Fri, 23 Oct 2009 08:14:59 +1100 (EST) Received: from localhost ([127.0.0.1]:35754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N14zl-0007ng-E1 for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 17:14:53 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N14q2-0003sR-SZ for qemu-devel@nongnu.org; Thu, 22 Oct 2009 17:04:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N14pz-0003qx-Nt for qemu-devel@nongnu.org; Thu, 22 Oct 2009 17:04:48 -0400 Received: from [199.232.76.173] (port=48145 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N14pz-0003qo-DA for qemu-devel@nongnu.org; Thu, 22 Oct 2009 17:04:47 -0400 Received: from hall.aurel32.net ([88.191.82.174]:47910) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N14py-0001sW-Sw for qemu-devel@nongnu.org; Thu, 22 Oct 2009 17:04:47 -0400 Received: from aurel32 by hall.aurel32.net with local (Exim 4.69) (envelope-from ) id 1N14px-0006yM-Fn; Thu, 22 Oct 2009 23:04:45 +0200 Resent-From: Aurelien Jarno Resent-Date: Thu, 22 Oct 2009 23:04:45 +0200 Resent-Message-ID: <20091022210445.GU1883@hall.aurel32.net> Resent-To: qemu-devel@nongnu.org, arnaud.patard@rtp-net.org Message-Id: <43744f904f71f4177e961065215a2d3fa7c13ab1.1256241265.git.aurelien@aurel32.net> X-OfflineIMAP-x1272945120-52656d6f7465617572656c3332-494e424f58: 1256242145-088025769817-v6.0.3 In-Reply-To: References: From: Aurelien Jarno To: qemu-devel@nongnu.org Date: Thu, 22 Oct 2009 22:17:47 +0200 Resent-Sender: Aurelien Jarno Resent-Date: Thu, 22 Oct 2009 23:04:45 +0200 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Arnaud Patard Subject: [Qemu-devel] [PATCH 2/5] cpu-all.h: fix cpu_get_real_ticks on mips host X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Arnaud Patard Fix cpu_get_real_ticks: - check should be done on __mips and not __mips_isa_rev - linux kernels >= 2.6.25 are emulating the 2 needed rdhwr functions so it's safe to use rdhwr. This is better than what's currently in but it doesn't mean it works nicely Some tests needs to be done imho Signed-off-by: Arnaud Patard Signed-off-by: Aurelien Jarno --- cpu-all.h | 27 ++++++++++++++++++--------- 1 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index ebe8bfb..e214374 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -1017,24 +1017,33 @@ static inline int64_t cpu_get_real_ticks (void) #endif } -#elif defined(__mips__) +#elif (defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__) +/* + * binutils wants to use rdhwr only on mips32r2 + * but as linux kernel emulate it, it's fine + * to use it. + * + */ +#define MIPS_RDHWR(rd, value) { \ + __asm__ __volatile__ ( \ + ".set push\n\t" \ + ".set mips32r2\n\t" \ + "rdhwr %0, "rd"\n\t" \ + ".set pop" \ + : "=r" (value)); \ +} static inline int64_t cpu_get_real_ticks(void) { -#if defined(__mips_isa_rev) && __mips_isa_rev >= 2 +/* On kernels >= 2.6.25 rdhwr , $2 and $3 are emulated */ uint32_t count; static uint32_t cyc_per_count = 0; if (!cyc_per_count) - __asm__ __volatile__("rdhwr %0, $3" : "=r" (cyc_per_count)); + MIPS_RDHWR("$3", cyc_per_count); - __asm__ __volatile__("rdhwr %1, $2" : "=r" (count)); + MIPS_RDHWR("$2", count); return (int64_t)(count * cyc_per_count); -#else - /* FIXME */ - static int64_t ticks = 0; - return ticks++; -#endif } #else