From patchwork Tue Apr 28 08:17:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 20355 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3S8KhoH017470 for ; Tue, 28 Apr 2009 08:20:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754414AbZD1IUm (ORCPT ); Tue, 28 Apr 2009 04:20:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755136AbZD1IUl (ORCPT ); Tue, 28 Apr 2009 04:20:41 -0400 Received: from wa-out-1112.google.com ([209.85.146.180]:46009 "EHLO wa-out-1112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754414AbZD1IUk (ORCPT ); Tue, 28 Apr 2009 04:20:40 -0400 Received: by wa-out-1112.google.com with SMTP id j5so215149wah.21 for ; Tue, 28 Apr 2009 01:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:date:message-id :subject; bh=gZ6VeQ87fiaJxQW/8nRvdQc2zwkgIPbz8/38oOrNUpI=; b=Ash67a7ndI+C1iwU1pktoDopB/jhNLAcCe9XKWlpI+xp03k+mQhgxQcXOLxFoJ/CCm p6sJYdrqt6a5q8Z0Y0ifMJJoNgRbAYFhHIfIzucUzMTUJQT6WxdEOxVL8nzidpWUnKok ofSHB2I7l0TD/wNCruD/5NZL95KCy6fDZvDmI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:date:message-id:subject; b=hoaZ4dat9+vQZZ+hsXJ7k/xr2f9C4SV6A/06nkR9U/qRvmUUtuRjLubcCgjElL63q/ ve12bW95k1J2t3HbvNhmqJvbcWmeUBLGcGe0rLAKzxKs8l/p7YN83RkmtVNjwJ96tB40 NKLiTPnc9LP7COUlFTMKlpgMuu+wUrTohhg/0= Received: by 10.115.107.1 with SMTP id j1mr2911902wam.165.1240906839435; Tue, 28 Apr 2009 01:20:39 -0700 (PDT) Received: from rx1.opensource.se (210.5.32.202.bf.2iij.net [202.32.5.210]) by mx.google.com with ESMTPS id c26sm3483603waa.50.2009.04.28.01.20.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Apr 2009 01:20:38 -0700 (PDT) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: johnstul@us.ibm.com, Magnus Damm , lethal@linux-sh.org Date: Tue, 28 Apr 2009 17:17:54 +0900 Message-Id: <20090428081754.16592.85760.sendpatchset@rx1.opensource.se> Subject: [PATCH] clocksource: improve sh_cmt clocksource overflow handling Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org From: Magnus Damm This patch improves the sh_cmt clocksource handling. Currently the counter value is ignored in the case of overflow. With this patch the overflow flag is read before and after reading the counter, removing any counter value and overflow flag mismatch issues. Signed-off-by: Magnus Damm --- drivers/clocksource/sh_cmt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0001/drivers/clocksource/sh_cmt.c +++ work/drivers/clocksource/sh_cmt.c 2009-04-28 16:03:20.000000000 +0900 @@ -111,16 +111,21 @@ static unsigned long sh_cmt_get_counter( int *has_wrapped) { unsigned long v1, v2, v3; + int o1, o2; + + o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; /* Make sure the timer value is stable. Stolen from acpi_pm.c */ do { + o2 = o1; v1 = sh_cmt_read(p, CMCNT); v2 = sh_cmt_read(p, CMCNT); v3 = sh_cmt_read(p, CMCNT); - } while (unlikely((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) - || (v3 > v1 && v3 < v2))); + o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit; + } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3) + || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2))); - *has_wrapped = sh_cmt_read(p, CMCSR) & p->overflow_bit; + *has_wrapped = o1; return v2; } @@ -394,7 +399,7 @@ static cycle_t sh_cmt_clocksource_read(s raw = sh_cmt_get_counter(p, &has_wrapped); if (unlikely(has_wrapped)) - raw = p->match_value; + raw += p->match_value; spin_unlock_irqrestore(&p->lock, flags); return value + raw;