Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1260641imm; Wed, 19 Sep 2018 15:14:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY6bS0ufYG9Lsg9gP1OH/1VyZCjf6VWEG+D4cN+XPKsdit83IWdweWe5a7qygALRS762NrD X-Received: by 2002:a17:902:8a90:: with SMTP id p16-v6mr36695268plo.106.1537395266950; Wed, 19 Sep 2018 15:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395266; cv=none; d=google.com; s=arc-20160816; b=UTa7oXPKqhgy7WFkaikd7ND5p5XPCB8qQxlFuqJPUjTF+pJPsloOv+nNWQDYakwE/0 gWvPkP6bo1GqdjzTHhuVmgRpZg0WTohReoOYxseUNXCQxvw+ZT+hcJXpv9PZcNR2ynzy vrj/WZY2D6JcQZDedcTFBHCKVYWUYE6DMCg0al2fMN/DFq3LAYfW2nrN+pAYIMGNEX2K OHa9ox+OXmC6b82AKjdPgWnXFvc59EJZ3fTRkJVvkeKFYg8i9eX/+QSiH611SD1POxge REg38Y84xGScWU22IV7bJzVvJpg4rmSOVzanhz/YyTzoqVhGaYLr3PlXLz76Nn2NQ37d oeRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=wTgZ9auVCQe3Ddwy+sDwXPpbQxHOertCx4S6lW2HJO4=; b=GIlZsO6dvyftFRzhuiWYjCjFsjZg/KyvLIb++RtylUNOwvUpzjRi/1MAzPoONz0lDl l2oRwcHnW2QWyWUm35O1auYDX6LtQKVXnLE0FKCm2hKZO1PHry4OcZlJ7FHXw7+LBF0o azJPvuF7+BTGjzKAHw2ctMdkkdogH/ZpqsNP/ggvwuyVWb2oCoO14tTMJY6c1UjZQjVA 9skLuHsw7eeEh/KgMG1Zta0oJrUZa9Jkdy7F1hw1tLcW+R567Nc8u/5SPyuM0i2wmNVl WL+/1UTrS934MHMu0QIC8/uADCVcuqIHdiY8hZDojIOAzmx9ESEs3cKXk0+E8JqkJ4VT XejQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="ZMY+/Nhj"; 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=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7-v6si21246399pgc.233.2018.09.19.15.14.11; Wed, 19 Sep 2018 15:14:26 -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=@fb.com header.s=facebook header.b="ZMY+/Nhj"; 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=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733105AbeITDxs (ORCPT + 99 others); Wed, 19 Sep 2018 23:53:48 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:40642 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732113AbeITDxr (ORCPT ); Wed, 19 Sep 2018 23:53:47 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w8JM8Chs000743 for ; Wed, 19 Sep 2018 15:13:47 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=wTgZ9auVCQe3Ddwy+sDwXPpbQxHOertCx4S6lW2HJO4=; b=ZMY+/NhjUJqInzc3hhX1TSYNowlSC8GMTuYUfeA+NXLe5cVhBRn4xBORJ5/Gh6wKXdb7 lyEmBKsDodD+8bEmEUmaeORItu9Uh0mdO4PFugab+3WFrtL7TVM89ydeIzD3Tx2P+ME3 /vhpvwPzD+31SoebGWHC/ljwdoHdpbZZcqc= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2mkvck0kd0-4 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 19 Sep 2018 15:13:47 -0700 Received: from mx-out.facebook.com (192.168.52.123) by mail.thefacebook.com (192.168.16.18) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 19 Sep 2018 15:13:45 -0700 Received: by devvm24792.prn1.facebook.com (Postfix, from userid 150176) id B94A55E465FE; Wed, 19 Sep 2018 15:13:35 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Tao Ren Smtp-Origin-Hostname: devvm24792.prn1.facebook.com To: Daniel Lezcano , Thomas Gleixner , CC: Tao Ren , , , Smtp-Origin-Cluster: prn1c35 Subject: [PATCH] clocksource/drivers/fttmr010: fix set_next_event handler Date: Wed, 19 Sep 2018 15:13:31 -0700 Message-ID: <20180919221331.2511558-1-taoren@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-19_11:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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