Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2161605imu; Sun, 18 Nov 2018 17:24:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/W8Sy8Mc/9XCtm9TbMFfI+XgreHjIe/qHFq4zi1+m8Nuz/TiZWXG1U/F4DUr6akmcACMSG1 X-Received: by 2002:a17:902:830a:: with SMTP id bd10mr5867848plb.321.1542590654501; Sun, 18 Nov 2018 17:24:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542590654; cv=none; d=google.com; s=arc-20160816; b=lyJshHFTr9LT1YDdtepi4PzxnKwFwpz5A2fywtj/1A3FBzDnTOcJ24GbNQjjW77LPB JUucwLtgV9iOe2+q1xmfHw3cmPmnoUHqzt8k0UAkbyPo8hplGmaE9rv178umjaguITyq d3X7qeaQW/cShdZbM86I1qJsRJOjHgt2rk2hsQciKUX1y3jG5E9poERaC23Fv3dC8Vmu K29m7DBstWrlBy7R50zHb9Wlj0OhdU50pM+eOGwS1/NVxkEWHn2eae+ni1utj6hJ8d8N DhUNpI8Gm2nNdap4mGC/ZQYGWQOGSgCi7ycQev0sojEAF7uys9Qg2K6zPnJeh26L5xjg m5Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to; bh=2RIY1jZTgpmpykbDt3kKdDCUV1KdwgfAcZUKC12QLD0=; b=od0Qo2djSBN+E8eXdQYZYs5Kzrdpp9313Dbq/RzYNS/PAy7tpvwHJbJmSG9A+wJCcX HJCQnqmOflr2TIiWZDxCtyMhu23vs24FvjB2XipxZsDzkHN0hNDQP9etin4kNdurXh9S +8sQZLhJ7+s24vsTNLT7ZyReL+mTZ7Is0/Y1sTbJq8HIi7FfFOzX+9A++qkBuZruQ2zH e7XvU5otfSSATm0jpMAbc8IzN5VFpMu0yXAgCHAfsToWik2RSBXCsG6irjtirEkY+DjO wsgSZZURz9NEek3fFCQ7j32/plAV/HO5ZgeMSvcmeYEJLAoMBJNUDQ37ntzUdASdGpqc m5Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1si37515984pgh.172.2018.11.18.17.24.00; Sun, 18 Nov 2018 17:24:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728266AbeKSLok (ORCPT + 99 others); Mon, 19 Nov 2018 06:44:40 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:49286 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728045AbeKSLoS (ORCPT ); Mon, 19 Nov 2018 06:44:18 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 49FDB29E01; Sun, 18 Nov 2018 20:22:18 -0500 (EST) To: Geert Uytterhoeven Cc: Andreas Schwab , Arnd Bergmann , Stephen N Chivers , Thomas Gleixner , Daniel Lezcano , Michael Schmitz , John Stultz , Linus Walleij , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [RFC PATCH v2 12/14] m68k: mvme147: Handle timer counter overflow Date: Mon, 19 Nov 2018 12:10:38 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reading the timer counter races with timer overflow (and the corresponding interrupt). This is resolved by reading the overflow register and taking this value into account. The interrupt handler must clear the overflow register when it eventually executes. Suggested-by: Thomas Gleixner Signed-off-by: Finn Thain --- TODO: find a spare counter for the clocksource, rather than hanging it off the HZ timer. --- arch/m68k/include/asm/mvme147hw.h | 1 + arch/m68k/mvme147/config.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/m68k/include/asm/mvme147hw.h b/arch/m68k/include/asm/mvme147hw.h index 7c3dd513128e..257b29184af9 100644 --- a/arch/m68k/include/asm/mvme147hw.h +++ b/arch/m68k/include/asm/mvme147hw.h @@ -66,6 +66,7 @@ struct pcc_regs { #define PCC_INT_ENAB 0x08 #define PCC_TIMER_INT_CLR 0x80 +#define PCC_TIMER_CLR_OVF 0x04 #define PCC_LEVEL_ABORT 0x07 #define PCC_LEVEL_SERIAL 0x04 diff --git a/arch/m68k/mvme147/config.c b/arch/m68k/mvme147/config.c index 82b53b5ca82b..545a1fe0e119 100644 --- a/arch/m68k/mvme147/config.c +++ b/arch/m68k/mvme147/config.c @@ -118,7 +118,7 @@ static irqreturn_t mvme147_timer_int (int irq, void *dev_id) local_irq_save(flags); m147_pcc->t1_int_cntrl = PCC_TIMER_INT_CLR; - m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1; + m147_pcc->t1_cntrl = PCC_TIMER_CLR_OVF; clk_total += PCC_TIMER_CYCLES; timer_routine(0, NULL); local_irq_restore(flags); @@ -144,23 +144,22 @@ void mvme147_sched_init (irq_handler_t timer_routine) clocksource_register_hz(&mvme147_clk, PCC_TIMER_CLOCK_FREQ); } -/* XXX There are race hazards in this code XXX */ static u64 mvme147_read_clk(struct clocksource *cs) { unsigned long flags; - volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012; - unsigned short n; + u8 overflow, tmp; + u16 count; u32 ticks; local_irq_save(flags); - - n = *cp; - while (n != *cp) - n = *cp; - - n -= PCC_TIMER_PRELOAD; - ticks = clk_total + n; - + tmp = m147_pcc->t1_cntrl >> 4; + count = m147_pcc->t1_count; + overflow = m147_pcc->t1_cntrl >> 4; + if (overflow != tmp) + count = m147_pcc->t1_count; + count -= PCC_TIMER_PRELOAD; + ticks = count + overflow * PCC_TIMER_CYCLES; + ticks += clk_total; local_irq_restore(flags); return ticks; -- 2.18.1