Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp498985rdb; Mon, 29 Jan 2024 08:36:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0f9bGrwSOUaeCUkB/OTSvgK1xrkCeq0H2zcQ4L99z84YoCdnzYXBMRniwn0L6uuASJudN X-Received: by 2002:a05:6214:f0f:b0:685:5639:fb1d with SMTP id gw15-20020a0562140f0f00b006855639fb1dmr8214961qvb.72.1706546184662; Mon, 29 Jan 2024 08:36:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706546184; cv=pass; d=google.com; s=arc-20160816; b=GU+cog5UYIi5rm4LiayO/LEflaynGvMfrE3Ph/LEeopa7WhWxboU9HN5WvudvHEgyl HD2Q8Sb27e7v707JNtbPf4kK4495phJ1o7JPBTf99CAr8Jq9iHc6foBGMbIwowNPv+lO cyp1/c4l3H6t1AtOxU5Ukmu/9/ObtMMmHV+/QWmKkWmvfHEYq28SOq1SpkYdnITgLx3t D36aaS85+J/gvjlJ3qXC7jM10h2/8P6im1ObHNK/oO+YQU73KUtV/uwC68/GvlzB/j60 QFAkPvGsFpZx36MHvFiZ8ORYJQ9yPNPyoaLzQU5t0arLAenH2YJa8UWj0paMUqRlew0n rH+A== 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=DFMXjYXH0LgQnG94VKRzfz+Pi7W2L2c19ITMHbsxEbY=; fh=4LIu5opAwLV7NEWuWaesW8kxXXZagKTitwg1cEZexpE=; b=NaRjmIjo7c1a6oARotC0Xm7OaukW6uN7bshKLrfDS0ul/ua8iRZ1/WGnHPb2HJhhe1 GJrM2QhcLeUdI0XErbueWbexsm1gutZuwZHeR7QUDIJ0DQF06aoykLmFRnvS5a9ZXTCE syy8D/NHPk1JJImt9kOVAOArj6TMeOILzNGEz+ZR/RVmrXU2qlWLCi9pxo0WJuMJ6dam dENsvWmuYDTQtT/vbDXXEx+12r0WCRalC/Fevovy0R6dAWZjZTrJ0U63OPQpxak3IG41 ZpsYMG7gDDIo4ZYmOb1GGWQ8LsT5EMLpGvcnedQ+jloOvink5ReGSs9MTp0c8aqroB8z 38Sw== 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-43113-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43113-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jz9-20020a0562140e6900b0068464b15882si8037434qvb.324.2024.01.29.08.36.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 08:36:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-43113-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-43113-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-43113-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6B8961C22CC8 for ; Mon, 29 Jan 2024 16:36:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF50015CD44; Mon, 29 Jan 2024 16:32:11 +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 BEC6115AAC2; 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=1706545931; cv=none; b=sPOlqlG5PJmtqQ33XGGUsFcGsreUsohOwZ7hIuyK6RIgAdkDe6p0RdwR1nqZPkUzV07WU7FXD6grhVc6sisDaGubDUk87UqAr+1Wpj4wguUsUNxVUFC5rG0gbK+H4jZvT49iqf55uO8PTSNhgT8IvP58mOPynglATD6hNCXHfCM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706545931; c=relaxed/simple; bh=SjzW2UsvZ2GkecO/LbDZYZGdT8+JTKkaLkPfaULWwgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OwwNWaG2cuqzWIGkGj4sg0X92mqrp+wM7ZcN07V9RriAOQPuqZpCbufYhCam1PugprqYuoOHJtrtuV7cDaW9F0gbEjb+JBXlRvPBkqBKuYQ76ZKO4QLwNfxWSwlbYU1dmQ5/zs0yiEjBHYsBy+scxtH5g86FdpnhUdg715mp7UY= 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 315201b9b6dcb32a; Mon, 29 Jan 2024 17:32:00 +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 6A39F66975C; Mon, 29 Jan 2024 17:32:00 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Ulf Hansson , Stanislaw Gruszka Subject: [PATCH v2 09/10] PM: sleep: Move devices to new lists earlier in each suspend phase Date: Mon, 29 Jan 2024 17:28:37 +0100 Message-ID: <1871146.atdPhlSkOF@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 During a system-wide suspend of devices, dpm_noirq_suspend_devices(), dpm_suspend_late() and dpm_suspend() move devices from one list to another. They do it with each device after its PM callback in the given suspend phase has run or has been scheduled for asynchronous execution, in case it is deleted from the current list in the meantime. However, devices can be moved to a new list before invoking their PM callbacks (which usually is the case for the devices whose callbacks are executed asynchronously anyway), because doing so does not affect the ordering of that list. In either case, each device is moved to the new list after the previous device has been moved to it or gone away, and if a device is removed, it does not matter which list it is in at that point, because deleting an entry from a list does not change the ordering of the other entries in it. Accordingly, modify the functions mentioned above to move devices to new lists without waiting for their PM callbacks to run regardless of whether or not they run asynchronously. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- v1 -> v2: Added R-by from Stanislaw. --- drivers/base/power/main.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) Index: linux-pm/drivers/base/power/main.c =================================================================== --- linux-pm.orig/drivers/base/power/main.c +++ linux-pm/drivers/base/power/main.c @@ -1304,18 +1304,12 @@ static int dpm_noirq_suspend_devices(pm_ while (!list_empty(&dpm_late_early_list)) { struct device *dev = to_device(dpm_late_early_list.prev); + list_move(&dev->power.entry, &dpm_noirq_list); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_suspend_noirq(dev); - mutex_lock(&dpm_list_mtx); - - if (!error && !list_empty(&dev->power.entry)) - list_move(&dev->power.entry, &dpm_noirq_list); - - mutex_unlock(&dpm_list_mtx); - put_device(dev); mutex_lock(&dpm_list_mtx); @@ -1486,19 +1480,13 @@ int dpm_suspend_late(pm_message_t state) while (!list_empty(&dpm_suspended_list)) { struct device *dev = to_device(dpm_suspended_list.prev); + list_move(&dev->power.entry, &dpm_late_early_list); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_suspend_late(dev); - mutex_lock(&dpm_list_mtx); - - if (!list_empty(&dev->power.entry)) - list_move(&dev->power.entry, &dpm_late_early_list); - - mutex_unlock(&dpm_list_mtx); - put_device(dev); mutex_lock(&dpm_list_mtx); @@ -1763,19 +1751,13 @@ int dpm_suspend(pm_message_t state) while (!list_empty(&dpm_prepared_list)) { struct device *dev = to_device(dpm_prepared_list.prev); + list_move(&dev->power.entry, &dpm_suspended_list); get_device(dev); mutex_unlock(&dpm_list_mtx); error = device_suspend(dev); - mutex_lock(&dpm_list_mtx); - - if (!error && !list_empty(&dev->power.entry)) - list_move(&dev->power.entry, &dpm_suspended_list); - - mutex_unlock(&dpm_list_mtx); - put_device(dev); mutex_lock(&dpm_list_mtx);