Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp714395pxm; Fri, 25 Feb 2022 18:05:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5WfeEToTFCYZxkkleJNdLyn5ZhV9pqpMAU0VsSgZ0JlTcctAWFpn6T1bLq4MwsnYF2nen X-Received: by 2002:a65:4108:0:b0:36b:ffa6:9c86 with SMTP id w8-20020a654108000000b0036bffa69c86mr8554695pgp.203.1645841136601; Fri, 25 Feb 2022 18:05:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645841136; cv=none; d=google.com; s=arc-20160816; b=phTMxjNUAhIuogYmU1MhJO9JuMeC4sUJBKfWWyjUxEsd6UTOLo+PuXkvGqeaOdpt7n /7BR7qAB2/ptLOpM8G+HZuilRA8T7gm9N7cMm5ruvO4ICb4RJgL1SQGMbxeE62sHaGTK jNQASF6gOFIlZ+I0FWbQp3VPxVqrzHub532bLIBnMf7qpqSbyIo8W+QoLikuxKNLRYcf pSo7RW/MGATLa1I1uwVqL7rxo/WnXXjcliPxQ8AmMx9k32LoTmJVmuiM+MroxOkVSmr2 DpIan75nl8L4ceuvtuFTVpls17JMu6XW5M8OaSAhc9iynEd7ZECdOQ0EQSu0CARbZbRK URoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y2IT2MD+M5Kuxt46voh5jFtMk8ayrmPXt7vtMwYPIE4=; b=cXO8vu5A28USsyLHDZb/KqKaPqBYPGfH4PQ2Uw4q9+RQlW6eEiqx7Ire9mMjm782K0 ZkY7O8mQ9X/VgAz/hJsMI3HBSIrWDZZs7nHY8A7vLMwCMrFY0tCGSquiovBASgB/WloZ AajCtgxSWmXTXVdVZhYYc3TqKaatgCYhgVCnBdJ8J0yY3//SV3VV4EjSLp1ZG2UWv677 uInv4K89DDN/UnHfD2ZHgNcEOVPSf7/KZloDaVy45VtHbdJ2hVE9CiXiEqh98XDg7Lww RR556HZHdtOrP99xT58QiyxRofQNKQI4K7LeQESpbP0xUtlgpRi9Pg9kAWuL+T1VM6N/ +ecQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=YLPEjH9M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=o2.pl Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n12-20020a170903404c00b0014a0edf8a41si2732724pla.507.2022.02.25.18.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:05:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@o2.pl header.s=1024a header.b=YLPEjH9M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=o2.pl Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A3E825BB7E; Fri, 25 Feb 2022 17:44:12 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233079AbiBYVvS (ORCPT + 99 others); Fri, 25 Feb 2022 16:51:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232900AbiBYVvR (ORCPT ); Fri, 25 Feb 2022 16:51:17 -0500 Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 439D520B176 for ; Fri, 25 Feb 2022 13:50:44 -0800 (PST) Received: (wp-smtpd smtp.tlen.pl 17847 invoked from network); 25 Feb 2022 22:50:41 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=1024a; t=1645825841; bh=Y2IT2MD+M5Kuxt46voh5jFtMk8ayrmPXt7vtMwYPIE4=; h=From:To:Cc:Subject; b=YLPEjH9M8sPKGfAxQw4h/EvZs8P3vxr1+LZonwamT7gnbHTYCnHewy130o0ImtIoW j8dX1IaVSVzHuosaPI3mkL88X/J7rsCV7+PeTDRIGCnEIFAwgeNWKZPV3uX/D4tt0G aKTvYXDa75qZFYErLyx56m+vnNlcBS2F25MLOp/4= Received: from aaew227.neoplus.adsl.tpnet.pl (HELO localhost.localdomain) (mat.jonczyk@o2.pl@[83.4.126.227]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with SMTP for ; 25 Feb 2022 22:50:41 +0100 From: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= To: linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org Cc: =?UTF-8?q?Mateusz=20Jo=C5=84czyk?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Alessandro Zummo , Alexandre Belloni Subject: [PATCH 1/3] rtc-mc146818-lib: reduce RTC_UIP polling period Date: Fri, 25 Feb 2022 22:50:09 +0100 Message-Id: <20220225215011.861477-2-mat.jonczyk@o2.pl> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225215011.861477-1-mat.jonczyk@o2.pl> References: <20220225215011.861477-1-mat.jonczyk@o2.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-WP-MailID: 478f42270233dca8f289efad5e49b1d1 X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000000 [cVNk] X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Waiting 1ms every time is not necessary, for example on some AMD boxes the RTC_UIP bit is documented as being high for around 270 microseconds in some cases [1], which agreed with experiments on an SB710 southbridge. So 100us seems optimal. This in preparation for mach_get_cmos_time() refactoring. The functions mc146818_get_time() and mach_get_cmos_time() in arch/x86/kernel/rtc.c perform the same function and the code is duplicated. mach_get_cmos_time() is busy waiting for the RTC_UIP bit to clear, so make mc146818_get_time() more similar to it by reducing the polling period. [1] AMD SB700/710/750 Register Reference Guide, page 307, https://developer.amd.com/wordpress/media/2012/10/43009_sb7xx_rrg_pub_1.00.pdf "SB700 A12: The UIP high pulse is 270 μS Typical when SS on SRC clock is OFF and 100μ min when SRC SS is ON." [sic] Signed-off-by: Mateusz Jończyk Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: Alessandro Zummo Cc: Alexandre Belloni --- drivers/rtc/rtc-mc146818-lib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-mc146818-lib.c b/drivers/rtc/rtc-mc146818-lib.c index ae9f131b43c0..ae4b19e0a981 100644 --- a/drivers/rtc/rtc-mc146818-lib.c +++ b/drivers/rtc/rtc-mc146818-lib.c @@ -21,13 +21,13 @@ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), unsigned long flags; unsigned char seconds; - for (i = 0; i < 10; i++) { + for (i = 0; i < 100; i++) { spin_lock_irqsave(&rtc_lock, flags); /* * Check whether there is an update in progress during which the * readout is unspecified. The maximum update time is ~2ms. Poll - * every msec for completion. + * every 100 usec for completion. * * Store the second value before checking UIP so a long lasting * NMI which happens to hit after the UIP check cannot make @@ -37,7 +37,7 @@ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) { spin_unlock_irqrestore(&rtc_lock, flags); - mdelay(1); + udelay(100); continue; } @@ -56,7 +56,7 @@ bool mc146818_avoid_UIP(void (*callback)(unsigned char seconds, void *param), */ if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) { spin_unlock_irqrestore(&rtc_lock, flags); - mdelay(1); + udelay(100); continue; } -- 2.25.1