Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp499324rdb; Mon, 29 Jan 2024 08:37:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGjw4FRQIgVg5y+drQj6wXIEE0ACcLTWmEGcv3VB7gzyhPK7lLmotJBlNAxACgsxo1aC4X X-Received: by 2002:a17:906:831a:b0:a35:3b07:11c3 with SMTP id j26-20020a170906831a00b00a353b0711c3mr4318399ejx.42.1706546226447; Mon, 29 Jan 2024 08:37:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706546226; cv=pass; d=google.com; s=arc-20160816; b=xsKqO54m+FYS6i4FpZOxr2UBKdFkJRkAA/j9jw+2uHBBX4irfpktV3FYeKW95Ju19j UA1v39sboS7JV2yjkKwiTLY26bvkvI2kA3yKcelj2fXerPrD1g1+3rEiOHHs7FeUB6mU i29DUxG12grFykEMna0WbIr/19nmMFdQ0jtBtbFgAFMtDBhLPmZFEx+NDz/vE5pRMD9t RtvJW0NKngvyvSr8MslkoW/Cqy2iLqcyWdT8YuBIE7IQpmcWNZipzGaXjF5bbm0f+J5u Ff30E39gEkQsvBuX2NXl69EoS66ldnKMFYprq0GGRQNsF49HNcw83gYt+AHKBSYPlaAb 5Aqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=KrR+pJQswjkficwnw67+c/hG4AU3g9R5wZ4mW5iGSf0=; fh=4LIu5opAwLV7NEWuWaesW8kxXXZagKTitwg1cEZexpE=; b=BzkQHOfDvQfFV2y+w+ol5iDJMN118L9PnxUBHs3SYrLU0oU1hOj8LzAvaF8uu9d5DY eT0HThC/eouDBGfUxHfIS3sAinCerd0Vm4rHxD4tud0YCKI6nyQIz1AW7Lh2ODEHm7gG MN9Eaefh7LKIWETm5YNoCqrnmhrx9xzTDPWnBwBWCqV9AQslE4Ury3wU3GjSKCLURBvc mQr7dd6G7a+QpmxHpVaUxSi6F3xp6R70ZsrpviJcQbFppMvUtGVvbA2gzDE6ptut6VXZ m0QkS+g5CB58JNEd2XkCtc8GARfglesNbeX1SUt7Hpb6IZe841PAtYUG7OypbLk+NPJ+ 6yww== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-43115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43115-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l8-20020a1709060e0800b00a33b00b4a94si3644600eji.15.2024.01.29.08.37.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 08:37:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-43115-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43115-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 376BF1F244F9 for ; Mon, 29 Jan 2024 16:37:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D70C15D5B8; Mon, 29 Jan 2024 16:32:13 +0000 (UTC) Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BECE015AAC9; Mon, 29 Jan 2024 16:32:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706545932; cv=none; b=URBoMmkmjguqI9A6RrKG+d2HlwISEB8ZUcDYmz0vpIF2b5SCzJshDdB3rKANmNfOShck075z7MCQYH5Gx48hLdzc2YRhD+Qmkr2cKkAaAHPrnobuzBFnSUiFsIxW3k8y8SFPukIM6t1fAmt8q1g6IVtQGFE9v9sSpJ8515IWvTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706545932; c=relaxed/simple; bh=t4M5s2l4WBiO5aXChunZB44zHCQq/VhfSSIwb2z2C7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kkbi6QNWzxoRRFH+xRrqzIj+oX7UXausCfJu3ckDNmiaS+2qbyashSdYp/YmVsFzhIFO1BsAQB8V1hnh0hR3l/x058F3/5nyROYtpKjUBitOLZvJ6v88SfPE8SuQWah14WspkCKxnWb4G1ia92cJk+EbZjaIpM3O2+aniqn8rLE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id cf5c7351ec63126c; Mon, 29 Jan 2024 17:32:01 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 13A7E66975C; Mon, 29 Jan 2024 17:32:01 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Ulf Hansson , Stanislaw Gruszka Subject: [PATCH v2 08/10] PM: sleep: Move some assignments from under a lock Date: Mon, 29 Jan 2024 17:27:33 +0100 Message-ID: <3750318.MHq7AAxBmi@kreacher> In-Reply-To: <5770175.DvuYhMxLoT@kreacher> References: <5770175.DvuYhMxLoT@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtgedgjeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepgedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehsthgrnhhishhlrgifrdhgrhhushiikhgrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 From: Rafael J. Wysocki The async_error and pm_transition variables are set under dpm_list_mtx in multiple places in the system-wide device PM core code, which is unnecessary and confusing, so rearrange the code so that the variables in question are set before acquiring the lock. While at it, add some empty code lines around locking to improve the consistency of the code. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- v1 -> v2: No changes. --- drivers/base/power/main.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) Index: linux-pm/drivers/base/power/main.c =================================================================== --- linux-pm.orig/drivers/base/power/main.c +++ linux-pm/drivers/base/power/main.c @@ -707,9 +707,9 @@ static void dpm_noirq_resume_devices(pm_ trace_suspend_resume(TPS("dpm_resume_noirq"), state.event, true); async_error = 0; + pm_transition = state; mutex_lock(&dpm_list_mtx); - pm_transition = state; /* * Trigger the resume of "async" devices upfront so they don't have to @@ -847,9 +847,9 @@ void dpm_resume_early(pm_message_t state trace_suspend_resume(TPS("dpm_resume_early"), state.event, true); async_error = 0; + pm_transition = state; mutex_lock(&dpm_list_mtx); - pm_transition = state; /* * Trigger the resume of "async" devices upfront so they don't have to @@ -1012,10 +1012,11 @@ void dpm_resume(pm_message_t state) trace_suspend_resume(TPS("dpm_resume"), state.event, true); might_sleep(); - mutex_lock(&dpm_list_mtx); pm_transition = state; async_error = 0; + mutex_lock(&dpm_list_mtx); + /* * Trigger the resume of "async" devices upfront so they don't have to * wait for the "non-async" ones they don't depend on. @@ -1294,10 +1295,12 @@ static int dpm_noirq_suspend_devices(pm_ int error = 0; trace_suspend_resume(TPS("dpm_suspend_noirq"), state.event, true); - mutex_lock(&dpm_list_mtx); + pm_transition = state; async_error = 0; + mutex_lock(&dpm_list_mtx); + while (!list_empty(&dpm_late_early_list)) { struct device *dev = to_device(dpm_late_early_list.prev); @@ -1320,7 +1323,9 @@ static int dpm_noirq_suspend_devices(pm_ if (error || async_error) break; } + mutex_unlock(&dpm_list_mtx); + async_synchronize_full(); if (!error) error = async_error; @@ -1470,11 +1475,14 @@ int dpm_suspend_late(pm_message_t state) int error = 0; trace_suspend_resume(TPS("dpm_suspend_late"), state.event, true); - wake_up_all_idle_cpus(); - mutex_lock(&dpm_list_mtx); + pm_transition = state; async_error = 0; + wake_up_all_idle_cpus(); + + mutex_lock(&dpm_list_mtx); + while (!list_empty(&dpm_suspended_list)) { struct device *dev = to_device(dpm_suspended_list.prev); @@ -1498,7 +1506,9 @@ int dpm_suspend_late(pm_message_t state) if (error || async_error) break; } + mutex_unlock(&dpm_list_mtx); + async_synchronize_full(); if (!error) error = async_error; @@ -1745,9 +1755,11 @@ int dpm_suspend(pm_message_t state) devfreq_suspend(); cpufreq_suspend(); - mutex_lock(&dpm_list_mtx); pm_transition = state; async_error = 0; + + mutex_lock(&dpm_list_mtx); + while (!list_empty(&dpm_prepared_list)) { struct device *dev = to_device(dpm_prepared_list.prev); @@ -1771,7 +1783,9 @@ int dpm_suspend(pm_message_t state) if (error || async_error) break; } + mutex_unlock(&dpm_list_mtx); + async_synchronize_full(); if (!error) error = async_error;