From patchwork Fri Apr 9 14:12:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1464405 X-Patchwork-Delegate: priyanka.jain@nxp.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; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=kqdE73T5; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FH0TS3MYZz9sW1 for ; Sat, 10 Apr 2021 00:13:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E570A800B3; Fri, 9 Apr 2021 16:12:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject 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="kqdE73T5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 671648017D; Fri, 9 Apr 2021 16:12:49 +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 autolearn=no autolearn_force=no version=3.4.2 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on20720.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1a::720]) (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 599AB80050 for ; Fri, 9 Apr 2021 16:12:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject 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=NBjgzVug5rhSsz+5XkBuSB1yk9hEeVjoeq+oWwqtVqZpf+Uols13PMi78SVkh2kWDx8eSjcMYb8q6Mw8G6zWNbjPL+LeOOtSXd82vmQGgx5KrpCZuVW7IdNGAaPippcn9lye7z/FFCts2vC9/zYjiun9uJtTHm/A0widf+4p5fN27jlY6htYW/RNxhfHOkWNblhLijoQ7MqqY4tgbwcP5i/7IHDimfcO0+BG6/PKbx8TaTDPRtgGDRfZ4mVSqPsB2R5l7q/84Kglb0VPcJ6yas7BUfAv44evQlpyhpZw/o9nfCzJwyH+bcB8x7P82u/zscjqDRH21nHRE32bE9A87w== 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=6c7KXRrzv/D/CMVSKXgfwR225N4VDkn539vJ2GopUXg=; b=g0gdKTVnflOJIN5zCIaPpgGnme1RE/0p0Iuq1kd6+3PDZjmBMhQJtyUTX/gZWmu0U57EoLyp+7uR5ooAWJ/rlmiNJsQhNvO6yloRIHnI2UawJIszpJgs2p2PPMzvVN0dOddNW0FGXckKc8S5+7SyPm6p0nEUYTQlB4njnclip5Azc86zBquEr49ybal8PrNu6IBEwX9peX/1gd/uPZoawr+z/9nnbaB3W72qUzHEI2yqxrAD77YRzPC3iyaakR8XFVvRJ0MqP3lMMbQaF3+DJqIg35e4eYxkLbtYAt23h1hzgUfEyA1k4dB5vpzfstxNLXJ80E05EXMR+FRhXRkPWQ== 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=6c7KXRrzv/D/CMVSKXgfwR225N4VDkn539vJ2GopUXg=; b=kqdE73T5XdiP3Wcj/JoL/9fDickte1Uyjrp7FViH+Osk0IcgRkBpk4jI4TjwDXxX/BLrWBfCPTIrcf7bd7zYmqAfnw63Ua8hci/C/ILo32NvRLEttC/sMQ5GC+HwzN/1Ju3ZDdWNN34/rIAc4AsFXV7eIVUx5WJcib8bvPFSghM= 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 AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) by AM0PR10MB3059.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:163::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27; Fri, 9 Apr 2021 14:12:37 +0000 Received: from AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::edba:45:89f8:b31f]) by AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM ([fe80::edba:45:89f8:b31f%7]) with mapi id 15.20.3999.033; Fri, 9 Apr 2021 14:12:37 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Stefan Roese , Christophe Leroy , Chris Packham , Rasmus Villemoes Subject: [PATCH] powerpc, wdt: disable ratelimiting when disabling interrupts Date: Fri, 9 Apr 2021 16:12:26 +0200 Message-Id: <20210409141226.2093980-1-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20200605111657.28773-1-rasmus.villemoes@prevas.dk> References: <20200605111657.28773-1-rasmus.villemoes@prevas.dk> X-Originating-IP: [80.208.71.248] X-ClientProxiedBy: AM6P192CA0079.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::20) To AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:3f::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (80.208.71.248) by AM6P192CA0079.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.16 via Frontend Transport; Fri, 9 Apr 2021 14:12:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 75c3c514-f6e6-46f4-3c89-08d8fb61871c X-MS-TrafficTypeDiagnostic: AM0PR10MB3059: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TyFIs2Yr3eN97BZypSl56Vo5h0gzWqFlMinETn7uN/yDlTm1jGJ9k0aEtMoUs9eSK84svGXI19VrsgC9ZklIPLK8TKw4TteAV9BtQqNlBNNK5Gt4+qX+U7MB08MHlvWbD/GM+p8CkX6D0+d3wsLGV5cbTPWuzxB01fCTUegxaxXkCpCk614AC2yLPl9WME5re9x+Maw02WMgT130DbbeodvIsSKyE33ukaWVbxboPhxMjFk/VvwRvlC3R7G+LYKvh/dJos+gV/VgQTwPB6fnhYcnbOkAEs6Pi95TONMx69m1M1HYl03oKLYBv//12TTX6JSZOPm/2hbLRDODg5PXzNUb46P8f0AjdBeg3bz5zAI+MlUAt81rlxKrB4qVNCxFQZ9OItGM7JV7pvyqjkXe/rXHLTn36CCUsb+ddei5oUjc6msfLEahzrcGsyAn5zyqvcbhp8Xiwd7KOjafuwqc4VwGzwIk28XgbJsF9e+aJAnKFUkUPDkZuCbbqSySeLF1/GzIMf16rqxn8ZcUD64cEveDwWXtsVJhyP7xhLyacwXlV4xnzPMO6Z5wtklx+XmKx79p38zJt9jmjQ3RivNG74g2C2g7RwQFZdz7py6qFakna62rbL32pLbZlI/EEBQKlQEfPPKmccqYqNKbJjRwRUTkcJ5N0VoPF0hbZ+si/aZZhJbqdOSh1RGcB4MVv9ClsGwX+CWzcAkIlOlM4UQ+DSW7TWxNEjQZJthfICvn0eShWnwIpe8lRjYRxtwicY77RC7UjCuHI2IKoiIxiiJsDg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(366004)(396003)(39840400004)(376002)(136003)(346002)(16526019)(956004)(2616005)(6506007)(186003)(66556008)(6666004)(44832011)(4326008)(6486002)(107886003)(66946007)(26005)(52116002)(966005)(2906002)(54906003)(478600001)(8936002)(36756003)(1076003)(8676002)(83380400001)(5660300002)(316002)(8976002)(38100700001)(6512007)(66476007)(86362001)(6916009)(38350700001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: RkKrgJ67gSPT9CT7cE4u/m+/LXRfw4hk9Rumz5fuwSr/aWHtqa3r3BZKsgsRqY4OnE517feAGoj/eepHi+m/p815w6rvA6pE6vXYLxIF6Oc1pzcxuTFwcJww/aPS2MN72gu8ZkAuISIpXlikKxUxPInFqpsFTmtwYd7S1sbkc4dX7TCY9mXs0a7IkQOvHTAzkIeeOUmnSaqyY7dDcTxtscO7pzg3DPADrxjAaxFL3KHCmv+0v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DfY4TNzLORGbaBkI2sOXmGnr X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 75c3c514-f6e6-46f4-3c89-08d8fb61871c X-MS-Exchange-CrossTenant-AuthSource: AM0PR10MB1874.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2021 14:12:37.1408 (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: cY4lKk9yYnCHVSzb1lXuJe0xrsfMua6ClimVBeHX55kmJeBIAJixbaIioRMtsu/eUTdIDdUydkpVgaWBF63XEZSAq7bbVGUfqcpelTxA7nw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR10MB3059 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.4 at phobos.denx.de X-Virus-Status: Clean On powerpc, time as measured by get_timer() ceases to pass when interrupts are disabled (since on powerpc get_timer() returns the value of a volatile variable that gets updated via a timer interrupt). That in turn means the watchdog_reset() function provided by CONFIG_WDT ceases to work due to the ratelimiting it imposes. Normally, interrupts are just disabled very briefly. However, during bootm, they are disabled for good prior to decompressing the kernel image, which can be a somewhat time-consuming operation. Even when we manage to decompress the kernel and do the other preparation steps and hand over control to the kernel, the kernel also takes some time before it is ready to assume responsibility for handling the watchdog. The end result is that the board gets reset prematurely. The ratelimiting isn't really strictly needed (prior to DM WDT, no such thing existed), so just disable it when we know that time no longer passes and have watchdog_reset() (e.g. called from decompression loop) unconditionally reset the watchdog timer. Signed-off-by: Rasmus Villemoes --- I previously sent a patch to change the ratelimiting to be based on get_ticks() instead of get_timer(), but that has gone nowhere [1]. This is an alternative which only affects powerpc (and only boards that have enabled CONFIG_WDT). I hope the watchdog maintainers will accept at least one of these, or suggest a third alternative, so I don't have to keep some out-of-tree patch applied without knowing if that's the direction upstream will take. [1] https://patchwork.ozlabs.org/project/uboot/patch/20200605111657.28773-1-rasmus.villemoes@prevas.dk/ arch/powerpc/lib/interrupts.c | 3 +++ drivers/watchdog/wdt-uclass.c | 8 +++++++- include/wdt.h | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/lib/interrupts.c b/arch/powerpc/lib/interrupts.c index 73f270002c..5c5b5fd7ff 100644 --- a/arch/powerpc/lib/interrupts.c +++ b/arch/powerpc/lib/interrupts.c @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef CONFIG_LED_STATUS #include #endif @@ -43,6 +44,7 @@ static __inline__ void set_dec (unsigned long val) void enable_interrupts(void) { set_msr (get_msr () | MSR_EE); + watchdog_ratelimit(1); } /* returns flag if MSR_EE was set before */ @@ -50,6 +52,7 @@ int disable_interrupts(void) { ulong msr = get_msr (); + watchdog_ratelimit(0); set_msr (msr & ~MSR_EE); return ((msr & MSR_EE) != 0); } diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index 0603ffbd36..b70a9d50b8 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -131,6 +131,12 @@ int wdt_expire_now(struct udevice *dev, ulong flags) return ret; } +static int ratelimit = 1; +void watchdog_ratelimit(int on) +{ + ratelimit = on; +} + #if defined(CONFIG_WATCHDOG) /* * Called by macro WATCHDOG_RESET. This function be called *very* early, @@ -148,7 +154,7 @@ void watchdog_reset(void) /* Do not reset the watchdog too often */ now = get_timer(0); - if (time_after(now, next_reset)) { + if (!ratelimit || time_after(now, next_reset)) { next_reset = now + reset_period; wdt_reset(gd->watchdog_dev); } diff --git a/include/wdt.h b/include/wdt.h index bc242c2eb2..9ba1e62dcf 100644 --- a/include/wdt.h +++ b/include/wdt.h @@ -107,4 +107,10 @@ struct wdt_ops { int initr_watchdog(void); +#if CONFIG_IS_ENABLED(WDT) +void watchdog_ratelimit(int on); +#else +static inline void watchdog_ratelimit(int on) { } +#endif + #endif /* _WDT_H_ */