From patchwork Sat Nov 4 05:12:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6buE5YaN5ry+KEpveXlvdW5nIEh1YW5nKQ==?= X-Patchwork-Id: 13445395 X-Patchwork-Delegate: cw00.choi@samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00F0BC4332F for ; Sat, 4 Nov 2023 05:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbjKDFMx (ORCPT ); Sat, 4 Nov 2023 01:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230454AbjKDFMw (ORCPT ); Sat, 4 Nov 2023 01:12:52 -0400 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2050.outbound.protection.outlook.com [40.107.255.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85A5A187; Fri, 3 Nov 2023 22:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BNq5Fpi62ZpZftDec2h2OK3W4aCrNLQoUO7qu+2n+FrGPDxMneQrvyFBRTkt5Ihv3POF+dNwx9xV5EIUpqkluc7xvjFzB1arD/zmz11LmB/vj2RcFaAAviUOXe+6ENfFLKwRVkXHgeT3ASTFnf1NoLYJfPkK+vDC5/++PIrILEWwPis/gEJ5yuspnuYi53dEECdEgvgOtHVabJ/qhxDkfjHrLGFlrKf+QHGOmJ1b3da9Vj52tk/dY0VuNywJ3c0ltIImzM5zxe4LMH4XRx8JTWW1a1TQZhGHN7t+madsgvzIg3PBGCQmTpeNUcbfv9FKJjUT3WsaRO2hCyiZNRN4cg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T2Ftr2xwwYAw9GywVSN1FeSxgbZOYoaKPdNP95i7HSA=; b=Kmcr65uzV1RzbIL0pXoS/afp6b0q1Yb328TjlRGoGzTNPVlqQfA1Da3IoVLIIcy5ytJnHfaxdR+JW7gdyRKvZBu8xUliQi/LH/JUlwD0Azlv9xoE7eCKg1tXQoFxF8ob0eeWEVnR+xZjYjvYNbKhWtlkva8Ov6HLIXpTnXGR3NQ0TKHi2RVyQfaKzbjOA/snwqq0EINLVdw6y6wmz79JmT52sVgc1E/EdXciVWUtGbSjyxgw74eentQhk6YXFN4l1sDHoy9roasRn7dR7mQ2WBZKTMuG9wUrhJgvh4H7CjqFxlQ9aIcpO8CZX489/Laz9tRtKHauv501Fa6RLY173A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 58.252.5.68) smtp.rcpttodomain=samsung.com smtp.mailfrom=oppo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=oppo.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T2Ftr2xwwYAw9GywVSN1FeSxgbZOYoaKPdNP95i7HSA=; b=PJhSUn5mP3ShZmMPiUz84EhXlF4rxuV1XIJCL4uGkCHHu9RPflWUZU1jrMEFSgowpe4moJpKQYaAw0ETQYesfDlipRJ9OOBvCszExC0b2vcajwAAmPkh/PdGd9Zo6XPpGK692HSbbLiFwKIOujKBE/icV82WL23b9y4bUT3ODBQ= Received: from PS2PR04CA0002.apcprd04.prod.outlook.com (2603:1096:300:55::14) by JH0PR02MB6778.apcprd02.prod.outlook.com (2603:1096:990:49::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.24; Sat, 4 Nov 2023 05:12:43 +0000 Received: from HK3PEPF0000021F.apcprd03.prod.outlook.com (2603:1096:300:55:cafe::a9) by PS2PR04CA0002.outlook.office365.com (2603:1096:300:55::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.22 via Frontend Transport; Sat, 4 Nov 2023 05:12:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 58.252.5.68) smtp.mailfrom=oppo.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=oppo.com; Received-SPF: Pass (protection.outlook.com: domain of oppo.com designates 58.252.5.68 as permitted sender) receiver=protection.outlook.com; client-ip=58.252.5.68; helo=mail.oppo.com; pr=C Received: from mail.oppo.com (58.252.5.68) by HK3PEPF0000021F.mail.protection.outlook.com (10.167.8.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6907.20 via Frontend Transport; Sat, 4 Nov 2023 05:12:42 +0000 Received: from PA80318969.adc.com (172.16.40.118) by mailappw30.adc.com (172.16.56.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 4 Nov 2023 13:12:41 +0800 From: huangzaiyang To: , , CC: , , huangzaiyang , ZaiYang Huang Subject: [PATCH] Performance: devfreq: avoid devfreq delay work re-init before queue, which will cause delayed work queue reentry. Date: Sat, 4 Nov 2023 13:12:26 +0800 Message-ID: <20231104051226.6249-1-huangzaiyang@oppo.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [172.16.40.118] X-ClientProxiedBy: mailappw31.adc.com (172.16.56.198) To mailappw30.adc.com (172.16.56.197) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK3PEPF0000021F:EE_|JH0PR02MB6778:EE_ X-MS-Office365-Filtering-Correlation-Id: 33918595-5b10-4f34-b30f-08dbdcf4ac7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cu8EsvYvPMWe2BZ/RvdKu6+BqbGFJ9cK8quh2Bt7Y0bZcW8rGo9sxdy5Cc4c3dU0TH0urupiZVTcilkxS46A8bEwR6lz+DpZMvO9bKhW7K7kMKb/2kCvmLG9gbkdc+HOBXhCA5pATJIX4gecnX7DJLH3pisstBuy6Ekcbr01CXKxdaCkiUi+IbGZrceq/BY3js+O4ogGDBX6euL6SU0KDyf3KsrTn9QqMzfdbLT0RTstN/k89qritDKTCTAOD1YZ3zKeVafSlKJj9cD5ATmS75n8xzNS8sjJhlXxss6B2WKwoGobioRjME0BDtS6MeyIyPEgV/5jroWNwOEqQQvBT2d0OhKa4K1MtjeL+UVOsop1kPzlZAtO3xRk2+sQlIy3IEDlcfWTWBKWALcTruD/CTYcqg4PHTWXdCBGKwx7WduyYijnLcGHplOPx8E4b9aSHHdd5os0C4xadMGRM3PJygY4WsiumJ9sY3lf4CRJSq7HIoZKhmzEPZKheWJnIgq7nsvRjWdumSWrSmv7y45f0Q2UP7D4VStl8lr2WuhMLya8jhrSh4YdO08S+AFkSd4shwibwAdQjV7+YA504QCB6CweO9+x1HGSff081oEtRezutURT1/dGxyptjaITrNQWv4dv/jtIJO4ZjRKyuS9B4njRlWPDYd25Ee9iENXAVUE1FSpIcxDggLIQe6eYhRKJNHgkjcs7wJM2IMnDh2I4PGM6miiDmmageaRhqjem6FcaRAeYhdjZFRJVFS+E/WrjmZgdjDxNdTpeg6OIMydsBw== X-Forefront-Antispam-Report: CIP:58.252.5.68;CTRY:CN;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.oppo.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(376002)(39860400002)(396003)(346002)(230922051799003)(82310400011)(451199024)(1800799009)(186009)(64100799003)(46966006)(36840700001)(40470700004)(2906002)(1076003)(86362001)(356005)(81166007)(110136005)(316002)(26005)(5660300002)(16526019)(36860700001)(41300700001)(6666004)(2616005)(30864003)(8936002)(478600001)(336012)(40460700003)(82740400003)(83380400001)(40480700001)(70586007)(70206006)(54906003)(36756003)(4326008)(8676002)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2023 05:12:42.5610 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 33918595-5b10-4f34-b30f-08dbdcf4ac7e X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f1905eb1-c353-41c5-9516-62b4a54b5ee6;Ip=[58.252.5.68];Helo=[mail.oppo.com] X-MS-Exchange-CrossTenant-AuthSource: HK3PEPF0000021F.apcprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR02MB6778 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: huangzaiyang There is a timer_list race condition when executing the following test shell script: ''' #!/vendor/bin/sh while true do echo "simple_ondemand" > /sys/class/devfreq/1d84000.ufshc/governor echo "performance" > /sys/class/devfreq/1d84000.ufshc/governor done ''' [13511.214366][ C3] Unable to handle kernel paging request at virtual address dead00000000012a [13511.214393][ C3] Mem abort info: [13511.214398][ C3] ESR = 0x96000044 [13511.214404][ C3] EC = 0x25: DABT (current EL), IL = 32 bits [13511.214409][ C3] SET = 0, FnV = 0 [13511.214414][ C3] EA = 0, S1PTW = 0 [13511.214417][ C3] Data abort info: [13511.214422][ C3] ISV = 0, ISS = 0x00000044 [13511.214427][ C3] CM = 0, WnR = 1 [13511.214432][ C3] [dead00000000012a] address between user and kernel address ranges [13511.214439][ C3] Internal error: Oops: 96000044 [#1] PREEMPT SMP [13511.215449][ C3] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G S W O 5.10.168-android12-9-o-g63cc297a7b34 #1 [13511.215454][ C3] Hardware name: Qualcomm Technologies, Inc. Cape MTP, Whiteswan (DT) [13511.215460][ C3] pstate: 82400085 (Nzcv daIf +PAN -UAO +TCO BTYPE=--) [13511.215472][ C3] pc : expire_timers+0x9c/0x428 [13511.215478][ C3] lr : __run_timers+0x1f0/0x328 [13511.215483][ C3] sp : ffffffc00801bdd0 [13511.215487][ C3] x29: ffffffc00801bdf0 x28: ffffffdb87b31698 [13511.215493][ C3] x27: ffffffdb87999e58 x26: ffffffdb87966008 [13511.215499][ C3] x25: 0000000000000001 x24: ffffff8001734a00 [13511.215506][ C3] x23: 00000000000000e0 x22: dead000000000122 [13511.215512][ C3] x21: 000000010032658e x20: ffffff89f7a9ae80 [13511.215518][ C3] x19: ffffffc00801be50 x18: ffffffc00801d038 [13511.215525][ C3] x17: 0000000000000240 x16: 0000000000000201 [13511.215532][ C3] x15: ffffffffffffffff x14: ffffff89f7a9aef8 [13511.215538][ C3] x13: 0000000000000240 x12: ffffff89f7a9aea8 [13511.215544][ C3] x11: 0000000000000021 x10: 000000014032658e [13511.215550][ C3] x9 : ffffffc00801be50 x8 : dead000000000122 [13511.215556][ C3] x7 : ffff71646c68735e x6 : ffffff89f7aaae58 [13511.215563][ C3] x5 : 0000000000000000 x4 : 0000000000000101 [13511.215569][ C3] x3 : ffffff89f7a9aef0 x2 : ffffff89f7a9aef0 [13511.215575][ C3] x1 : ffffffc00801be50 x0 : ffffff8045804428 [13511.215581][ C3] Call trace: [13511.215586][ C3] expire_timers+0x9c/0x428 [13511.215591][ C3] __run_timers+0x1f0/0x328 [13511.215596][ C3] run_timer_softirq+0x28/0x58 [13511.215602][ C3] efi_header_end+0x168/0x5ec [13511.215610][ C3] __irq_exit_rcu+0x108/0x124 [13511.215617][ C3] __handle_domain_irq+0x118/0x1e4 [13511.215625][ C3] gic_handle_irq.31230+0x6c/0x250 [13511.215630][ C3] el1_irq+0xe4/0x1c0 [13511.215638][ C3] cpuidle_enter_state+0x3a4/0xa04 [13511.215644][ C3] do_idle+0x308/0x574 [13511.215649][ C3] cpu_startup_entry+0x84/0x90 [13511.215656][ C3] secondary_start_kernel+0x204/0x274 [13511.215664][ C3] Code: d503201f a9402408 f9000128 b4000048 (f9000509) [13511.215670][ C3] ---[ end trace 5100bad72a35d566 ]--- [13511.215676][ C3] Kernel panic - not syncing: Oops: Fatal exception in interrupt This is because when switching the governor through the sys node, the devfreq_monitor_start function will re-initialize the delayed work task, which will cause the delay work pending flag to become invalid, and the timer pending judgment contained in the delayed work will also become invalid, and then the pending interception will be executed when the queue is executed. So we remove the delay work'initialization work to the devfreq_add_device and timer_store functions, and the delay work pending judgment is performed before the devfreq_monitor_start function performs the queue operation. Signed-off-by: ZaiYang Huang --- drivers/devfreq/devfreq.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b3a68d5833bd..ce4e1bbb6fea 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -480,21 +480,10 @@ static void devfreq_monitor(struct work_struct *work) */ void devfreq_monitor_start(struct devfreq *devfreq) { - if (IS_SUPPORTED_FLAG(devfreq->governor->flags, IRQ_DRIVEN)) + if (devfreq->governor->interrupt_driven) return; - switch (devfreq->profile->timer) { - case DEVFREQ_TIMER_DEFERRABLE: - INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); - break; - case DEVFREQ_TIMER_DELAYED: - INIT_DELAYED_WORK(&devfreq->work, devfreq_monitor); - break; - default: - return; - } - - if (devfreq->profile->polling_ms) + if (devfreq->profile->polling_ms && !delayed_work_pending(&devfreq->work)) queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms)); } @@ -830,6 +819,17 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_dev; } + switch (devfreq->profile->timer) { + case DEVFREQ_TIMER_DEFERRABLE: + INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); + break; + case DEVFREQ_TIMER_DELAYED: + INIT_DELAYED_WORK(&devfreq->work, devfreq_monitor); + break; + default: + dev_err(dev, "%s: Target devfreq(%s)'s profile timer has no settings \n", devfreq->governor_name, + __func__); + } if (!devfreq->profile->max_state || !devfreq->profile->freq_table) { mutex_unlock(&devfreq->lock); err = set_freq_table(devfreq); @@ -1860,6 +1860,18 @@ static ssize_t timer_store(struct device *dev, struct device_attribute *attr, df->profile->timer = timer; mutex_unlock(&df->lock); + switch (df->profile->timer) { + case DEVFREQ_TIMER_DEFERRABLE: + INIT_DEFERRABLE_WORK(&df->work, devfreq_monitor); + break; + case DEVFREQ_TIMER_DELAYED: + INIT_DELAYED_WORK(&df->work, devfreq_monitor); + break; + default: + dev_err(dev, "%s: Target devfreq(%s)'s profile timer has no settings \n", df->governor_name, + __func__); + } + ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL); if (ret) { dev_warn(dev, "%s: Governor %s not stopped(%d)\n",