From patchwork Fri Jun 5 11:16:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1304067 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=OjsbpxzY; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49dg925JPXz9sT6 for ; Fri, 5 Jun 2020 21:17:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D00B581E1E; Fri, 5 Jun 2020 13:17:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="OjsbpxzY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7E0F681E00; Fri, 5 Jun 2020 13:17:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0706.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::706]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3AD8981E00 for ; Fri, 5 Jun 2020 13:17:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eKT4dAoLUnol8f3LgyKRd4HVTcgCICw7pQSYg2Tbwk+/k/nfgHahP78UwKFrqtsn6FArzxz3nFwVJ1v9PawqAEokrQb3Ykep6T8C8NnkHRolCSXDyLlyR5Q56MocUHcwY4LJ7SG4zsShFhnp4ZCsP+NZkRanqOIkXpYbQJQu/caxmmf6h+6GmSbnuGcKrShn1NVhtNoV+4+uHp8+up7orHWfXaCNTWaa4aevBn1orm25PS0Ylbrgk08dwqFM2hSsxpUwH60lFT8jEVFf9PNvecRQbzKaaRE/4Q+b+pdoYZes6NzAqhYBWgCH6BlGcFwiZlUFXROw9Hwfy7ZkjdxJrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OaAPgvxYHUzxgtjybKBS8WOehiI9UOTef+SPqduTga4=; b=Ux0OkxFRt+NHAOdaPH3EeTVn1tGxFiWgdovAvYg3QHRwq6tN7eL+rn7l4hacLi3YtpaCQhD+LYD5EQXtZ/P5JOgX3AmdqZ43TzUiNednJDwYQR/BoqRwwLC7FSAb/rAkgR6z3VwtAlhLHI3A6k0FuQE42pK25XWOTUlgqTbb9bf0pZgLejrtWt1sWhtrKnpzKPYMF3tNrno0CNmANG7nTdYHwMhnl3T7YMTOm7Yj9sc4JnQabM3fKQbDt/My9+TkhX0BJHuh3/kyB62zc3KQXdFTZkGNX79U2jdbJ/+RH2PvYs8lr2qeDDsroGVroGK0N78gvH9FNwNytQChn8pB/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OaAPgvxYHUzxgtjybKBS8WOehiI9UOTef+SPqduTga4=; b=OjsbpxzYbrOvQANYLuHLiHP0Lxt4CMYePbCqq6oVyw3HPzXF68Fwy1KMS+cjZ2gPQRCQdp27IVnMfDV9s0tpp19MuMjQ7Cu2W0K32oSZa7Y7Q9rQH20oJCf/aK+3NNmnIIFRbzQ6qd91ZV+rOlAOvKWh3eJLE8VNd28qUFoU1lg= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) by VI1PR10MB1645.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:802:31::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.22; Fri, 5 Jun 2020 11:17:08 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::f0ac:4e97:2536:faa]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::f0ac:4e97:2536:faa%7]) with mapi id 15.20.3066.018; Fri, 5 Jun 2020 11:17:08 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Stefan Roese , Christophe Leroy , Chris Packham , Rasmus Villemoes Subject: [RFC PATCH] watchdog: base rate-limiting on get_ticks() rather than get_timer() Date: Fri, 5 Jun 2020 13:16:57 +0200 Message-Id: <20200605111657.28773-1-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 X-ClientProxiedBy: AM5PR0601CA0053.eurprd06.prod.outlook.com (2603:10a6:206::18) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.116.45) by AM5PR0601CA0053.eurprd06.prod.outlook.com (2603:10a6:206::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18 via Frontend Transport; Fri, 5 Jun 2020 11:17:07 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.116.45] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e9d17a6a-a2eb-4554-6be9-08d80941fc36 X-MS-TrafficTypeDiagnostic: VI1PR10MB1645: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0425A67DEF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e8APMfNcjBcP/BXgsU+BFEfx/AQ676P0X8ntbd6TnYmFNK/20yK0aXhm9wnSluUTuiNwZ1d8Go5A0931YcCJ3uFTwUxAGXksm1gs4Y8MASzd1qttL4M867oK9nZFOzx9i0eitkCVS3yGVo7zDK6UImRfSnNMZW/Tem+ywY0gTxiBPy/WGnRWKdrxEwe5HLet3wP3mPoFd714ZfYebMRzmyEr5wsIEEOuHxM0nfh01s7VVgXedY3bMw1NvVKyqg8WVRiP8gTY+GT1KRNfxpG5IkFTMP8e570ROfoWmPJtlUWp02pEqWJIBaHEFWwyGTybaw/y6YqoP0rGlWq02MXbAg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFTY:; SFS:(396003)(136003)(376002)(346002)(39850400004)(366004)(2906002)(107886003)(1076003)(26005)(6506007)(6916009)(316002)(86362001)(4326008)(83380400001)(6666004)(66556008)(52116002)(44832011)(16526019)(2616005)(36756003)(478600001)(66946007)(6512007)(6486002)(5660300002)(8936002)(956004)(66476007)(8976002)(54906003)(8676002)(186003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: k8p2msZAX5R9mVNmrz8J3XdXNxivk0fuDKflz3OcG5WbYyPorNsYwJm7NQVuThR3XA/JpTkRVC66ntSRz27Q/JnM3GRV9kqwkuYnymV9YPlwRR3JGHQhBgCRPLjm00zN3G42LqYrdujLWI9ftby1A2dgzHCRVmLnEOtKNlPzlWcKuHYD4BwwAhcRJDk7/Qqf/Ikx8kOFCcvd/bd11X4SP/zp+afCUe75nFhEHCzA9/BL0U6LtMlTagjr/zri3Sofo8A7mlxKC6Mbey+eOo0D3Wzw+YqTHfkN3DIi05p9k3wdhyXs2MNsaHhnrH/ogNKiURRZp1321yuRcRfl8sDC1mm15uif8zu933j/v0GRFNFy6jwHnVkt8HC9G2/TzHZkycnqDivcxyUebca4me78BsVr3pnn0eemyYP8JN/8+MRwV/Nix4hfeQkWTlb4sF5HqXnak2CZt7FnoWgTwf7M5HrGbwtPMG2SOnK4iGHI/C8= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: e9d17a6a-a2eb-4554-6be9-08d80941fc36 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2020 11:17:08.3713 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 91k8hDPcNn5WCSCDh6CBN/EQ6frER2MPAyuXKZcDTeH+wx0jlCwYe1cNIky6NsYAyE9Yxk1z+bOTfdhfV0FQ2wKW+JVeWqURlnYZIoji2bo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB1645 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean On powerpc, get_timer() is implemented using a volatile variable that gets incremented from the decrementer interrupt handler. Hence, when interrupts are disabled, time as measured by get_timer() ceases to pass. Interrupts are necessarily disabled during bootm (see the comment in bootm_disable_interrupts() for why). But after interrupts are disabled, there's still lots of work to do - e.g. decompressing the kernel image to the right load address. Unfortunately, the rate-limiting logic in wdt_uclass.c's watchdog_reset function means that WATCHDOG_RESET() becomes a no-op, since get_timer() never progresses past the next_reset. This, combined with an external gpio-triggered watchdog that must be petted at least every 800ms, means our board gets reset before booting into linux. Now, at least on powerpc, get_ticks() continues to return sensible results whether or not interrupts are enabled. So this fixes the above problem for our board - but I don't know if get_ticks() can be assumed to always work. Signed-off-by: Rasmus Villemoes --- This is what I had in mind. I also considered making it a config knob (possibly just auto-selected based on $ARCH) whether to use get_timer() or get_ticks(), but that becomes quite ugly. drivers/watchdog/wdt-uclass.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index 4cdb7bd64c..7be4e9b5bc 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -16,14 +16,15 @@ DECLARE_GLOBAL_DATA_PTR; #define WATCHDOG_TIMEOUT_SECS (CONFIG_WATCHDOG_TIMEOUT_MSECS / 1000) -/* - * Reset every 1000ms, or however often is required as indicated by a - * hw_margin_ms property. - */ -static ulong reset_period = 1000; +static u64 ratelimit_ticks; int initr_watchdog(void) { + /* + * Reset every 1000ms, or however often is required as indicated by a + * hw_margin_ms property. + */ + u32 reset_period = 1000; u32 timeout = WATCHDOG_TIMEOUT_SECS; /* @@ -48,6 +49,7 @@ int initr_watchdog(void) 4 * reset_period) / 4; } + ratelimit_ticks = usec_to_tick(reset_period * 1000); wdt_start(gd->watchdog_dev, timeout * 1000, 0); gd->flags |= GD_FLG_WDT_READY; printf("WDT: Started with%s servicing (%ds timeout)\n", @@ -117,17 +119,17 @@ int wdt_expire_now(struct udevice *dev, ulong flags) */ void watchdog_reset(void) { - static ulong next_reset; - ulong now; + static u64 last_reset; + u64 now; /* Exit if GD is not ready or watchdog is not initialized yet */ if (!gd || !(gd->flags & GD_FLG_WDT_READY)) return; /* Do not reset the watchdog too often */ - now = get_timer(0); - if (time_after(now, next_reset)) { - next_reset = now + reset_period; + now = get_ticks(); + if (now - last_reset >= ratelimit_ticks) { + last_reset = now; wdt_reset(gd->watchdog_dev); } }