Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3729156imm; Mon, 8 Oct 2018 08:36:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV63q8O54IWi+EUtCADnb2W1MxqUwpqfopBX/ZlhZYF1p2k7YPUpwIIuEselVUMj+e6myURV0 X-Received: by 2002:a17:902:5a4d:: with SMTP id f13-v6mr24627155plm.114.1539013004855; Mon, 08 Oct 2018 08:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539013004; cv=none; d=google.com; s=arc-20160816; b=s7TsNMLyxNNHCIhM67hCZd1dRahTk6lRz34E2hpUK51Pz/PwchM7/WO3pqVJvdHvsp JE/THYxzqjYNr4Y28Rdu+RdkQO55EPglG/HuGj9Rxb2nVK38O+4nMOdm83XSuJRF61bU 52PugzBbdTVFp3l4P9II6q4/dE+txsVrSmlFc71wuz9GdZHgmIRRbFCgQdUtNGA+pCMV pXsHhgYBPxUfCf9FZj5IfwAEGKEY9MDYqw/foJji/BWwGD9nGi3pZ4E6D6e69LymZwFT sKdwXjzK5NAsbjE6xklFqE5HnAgL5PYyGV5TE/qZ3H4FLKmfqgmPWyByBjAmwSfnKBua xTTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=4ioJRvNq5TfHpiHupyrSC5Zlrc5c8htQY+W/nZr7RTU=; b=iwo0J3h7p4sdFPigdUXR3rvj/wkLQZ8ZZx3M44nJZvCEaRv9WzipiIzwi5viwLOPsA Ye2eJuNDe7tr/Cs/rowpQTgbsKp/+N0NL80CbDczauAchNQ95vxYeTXlIQ2V1Z4Ts4d3 XOQ9Ri9PVUfy+c+NwDCYcf+ui9U0dHA/2wc4yZwwNbS+nR6wnFLaJ4zbh/XIzglJ47t0 76gBz41svlp6l0j/t4vETfUCBVBudY7rW4n/YPS3XPYLBOXUtfPeLL6363xIJKElgWuc 5r4FUPQn4EEgM/Xe9A/9dLX8FpfcetmEnIrX0bgID2VwF46TVxEZ6YNt9Lk43gCCbBT3 bIow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=N5U9vXaf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6-v6si20434783pln.78.2018.10.08.08.36.29; Mon, 08 Oct 2018 08:36:44 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=N5U9vXaf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728467AbeJHWqz (ORCPT + 99 others); Mon, 8 Oct 2018 18:46:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:57032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727962AbeJHWi1 (ORCPT ); Mon, 8 Oct 2018 18:38:27 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B0915214FA; Mon, 8 Oct 2018 15:26:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539012372; bh=Ysl24WM3RTldRV2S2CS31mftc8XfWm+vLBdmwIVI5i8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5U9vXafRhikAi+GZMdB0Drng3Y9o3kQaiIPpzfmMPiTquJ4THBVy7m2Om2kWZUtK zBSnhuXelNs3iLAdHiT5U8aCheVLYHPvYMvFcJz5fXoXdMMWTmGAIn0V5WPkKSa03p 2BU0uVoM3c3qGFCl8C1nkf/ekoqjH2sgRjvK57iU= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tao Ren , Daniel Lezcano , Sasha Levin Subject: [PATCH AUTOSEL 4.18 48/58] clocksource/drivers/fttmr010: Fix set_next_event handler Date: Mon, 8 Oct 2018 11:25:13 -0400 Message-Id: <20181008152523.70705-48-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181008152523.70705-1-sashal@kernel.org> References: <20181008152523.70705-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tao Ren [ Upstream commit 4451d3f59f2a6f95e5d205c2d04ea072955d080d ] Currently, the aspeed MATCH1 register is updated to in set_next_event handler, with the assumption that COUNT register value is preserved when the timer is disabled and it continues decrementing after the timer is enabled. But the assumption is wrong: RELOAD register is loaded into COUNT register when the aspeed timer is enabled, which means the next event may be delayed because timer interrupt won't be generated until <0xFFFFFFFF - current_count + cycles>. The problem can be fixed by updating RELOAD register to , and COUNT register will be re-loaded when the timer is enabled and interrupt is generated when COUNT register overflows. The test result on Facebook Backpack-CMM BMC hardware (AST2500) shows the issue is fixed: without the patch, usleep(100) suspends the process for several milliseconds (and sometimes even over 40 milliseconds); after applying the fix, usleep(100) takes averagely 240 microseconds to return under the same workload level. Signed-off-by: Tao Ren Reviewed-by: Linus Walleij Tested-by: Lei YU Signed-off-by: Daniel Lezcano Signed-off-by: Sasha Levin --- drivers/clocksource/timer-fttmr010.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/clocksource/timer-fttmr010.c b/drivers/clocksource/timer-fttmr010.c index c020038ebfab..cf93f6419b51 100644 --- a/drivers/clocksource/timer-fttmr010.c +++ b/drivers/clocksource/timer-fttmr010.c @@ -130,13 +130,17 @@ static int fttmr010_timer_set_next_event(unsigned long cycles, cr &= ~fttmr010->t1_enable_val; writel(cr, fttmr010->base + TIMER_CR); - /* Setup the match register forward/backward in time */ - cr = readl(fttmr010->base + TIMER1_COUNT); - if (fttmr010->count_down) - cr -= cycles; - else - cr += cycles; - writel(cr, fttmr010->base + TIMER1_MATCH1); + if (fttmr010->count_down) { + /* + * ASPEED Timer Controller will load TIMER1_LOAD register + * into TIMER1_COUNT register when the timer is re-enabled. + */ + writel(cycles, fttmr010->base + TIMER1_LOAD); + } else { + /* Setup the match register forward in time */ + cr = readl(fttmr010->base + TIMER1_COUNT); + writel(cr + cycles, fttmr010->base + TIMER1_MATCH1); + } /* Start */ cr = readl(fttmr010->base + TIMER_CR); -- 2.17.1