From patchwork Tue Jan 18 00:33:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgar E. Iglesias" X-Patchwork-Id: 79239 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 10D3BB7123 for ; Tue, 18 Jan 2011 11:33:38 +1100 (EST) Received: from localhost ([127.0.0.1]:37318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PezVv-0005Xn-AB for incoming@patchwork.ozlabs.org; Mon, 17 Jan 2011 19:33:35 -0500 Received: from [140.186.70.92] (port=50574 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PezVR-0005Xi-Ly for qemu-devel@nongnu.org; Mon, 17 Jan 2011 19:33:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PezVQ-0007u8-Ah for qemu-devel@nongnu.org; Mon, 17 Jan 2011 19:33:05 -0500 Received: from mail-ey0-f173.google.com ([209.85.215.173]:65344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PezVQ-0007u4-6C for qemu-devel@nongnu.org; Mon, 17 Jan 2011 19:33:04 -0500 Received: by eyg7 with SMTP id 7so3129228eyg.4 for ; Mon, 17 Jan 2011 16:33:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=DrqZ4Jwk3VPeAbT8dJhOycynAiLts3fBMVHVevfHNLk=; b=hJWkOit+jQ0f7CPMS3pKmhXLZeNo2GmrWCAkFRZUm4kxSQ4zAfbFwZ2luaJoTzrurQ t/g1yc1XEtdh6zY5tuamdrRBAznFA8H0yfr+sHk6599RdTcX2mER88PWe1U05wWFy086 GFfblPe+0faZGcDLzi4VrP6CILTeC0XrcojBY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=ulP3g78n4Q2ARzMlv7yM+dncdSRLlDq6Ewgx4Ijd/NAP2UsWCRi2L5b6dskZ1nILic 9xrid4thcWAfxUHf/45dawg/22YROc6dfdljSRYFv6GpO089E2sdinDthFyjU7K5NKjn sWvipzjEqruVwnrH78wJBwvZq1MZxek+kXYUU= Received: by 10.213.104.143 with SMTP id p15mr4554317ebo.68.1295310783062; Mon, 17 Jan 2011 16:33:03 -0800 (PST) Received: from localhost (h59ec3266.selukar.dyn.perspektivbredband.net [89.236.50.102]) by mx.google.com with ESMTPS id b52sm4074204eei.1.2011.01.17.16.33.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 17 Jan 2011 16:33:02 -0800 (PST) Date: Tue, 18 Jan 2011 01:33:00 +0100 From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org Message-ID: <20110118003300.GA11846@laped.lan> References: <1295306982-29629-1-git-send-email-edgar.iglesias@gmail.com> <1295306982-29629-4-git-send-email-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1295306982-29629-4-git-send-email-edgar.iglesias@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: aurelien@aurel32.net Subject: [Qemu-devel] Re: [PATCH 3/3] mips: Expire late timers when reading cp0_count 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 On Tue, Jan 18, 2011 at 12:29:42AM +0100, edgar.iglesias@gmail.com wrote: > From: Edgar E. Iglesias > > When reading cp0_count from a timer with a late trigger that should > already have expired, expire it and raise the timer irq. > > This makes it possible for guest code (e.g, Linux) that first read > cp0_count, then compare it with cp0_compare and check for raised > timer interrupt lines to run reliably. > > Signed-off-by: Edgar E. Iglesias Sorry sent the wrong version of this one. It's supposed to be the following: commit 139330de404209528712fd703952c0b5ad4459a1 Author: Edgar E. Iglesias Date: Tue Jan 18 00:12:22 2011 +0100 mips: Expire late timers when reading cp0_count When reading cp0_count from a timer with a late trigger that should already have expired, expire it and raise the timer irq. This makes it possible for guest code (e.g, Linux) that first read cp0_count, then compare it with cp0_compare and check for raised timer interrupt lines to run reliably. Signed-off-by: Edgar E. Iglesias Acked-by: Aurelien Jarno diff --git a/hw/mips_timer.c b/hw/mips_timer.c index 8c32087..9c95f28 100644 --- a/hw/mips_timer.c +++ b/hw/mips_timer.c @@ -69,9 +69,17 @@ uint32_t cpu_mips_get_count (CPUState *env) if (env->CP0_Cause & (1 << CP0Ca_DC)) { return env->CP0_Count; } else { + uint64_t now; + + now = qemu_get_clock(vm_clock); + if (qemu_timer_pending(env->timer) + && qemu_timer_expired(env->timer, now)) { + /* The timer has already expired. */ + cpu_mips_timer_expire(env); + } + return env->CP0_Count + - (uint32_t)muldiv64(qemu_get_clock(vm_clock), - TIMER_FREQ, get_ticks_per_sec()); + (uint32_t)muldiv64(now, TIMER_FREQ, get_ticks_per_sec()); } }