From patchwork Mon Jan 22 11:22:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 190119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2514142dyb; Mon, 22 Jan 2024 03:48:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKLk7MIyiqVMf1yhCk0QwRczHmenmEcw3Pe6SNCowIPuJksKOuWYNPmtbkxOfx8k+srKqq X-Received: by 2002:a05:6402:b18:b0:559:c3de:76f with SMTP id bm24-20020a0564020b1800b00559c3de076fmr5058353edb.18.1705924123379; Mon, 22 Jan 2024 03:48:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705924123; cv=pass; d=google.com; s=arc-20160816; b=aCR0ctGaX0S0lh/x1sToIErWHP4asq/WNVBT5nVqtPLuCg78aPEzn3xfcPiYt/lAkB Pfpp/Z7XcF2SP2cPQRGo+Mhrf9K0hdJPXrR8Ekqhy3lj071KD5/m5rmzzc5m5+CEfu7B 2yGTpy92wsFODw3X+Lpw/ozdzJpdj789HfZAeR8rYKN+HiVIM0y4+G5hDe/IP1/FLPFr jDnGqZ4TLCDIXXAbTSthykagN/fC+KNjJY97mXDPOiRFmrSO1+zCxVMPOWExQUBAwDFm zvcQpsutR9uN1iavztUNyoS5D09OzeMB2AFa7PJ7BiYKyNGvrJxNnNOiUjynzR7U+Ak/ IJKA== 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=ne3DcOGfdPztxKZhFMNaRb5HQEqosRx0ocJesFWxitM=; fh=4LIu5opAwLV7NEWuWaesW8kxXXZagKTitwg1cEZexpE=; b=ULbw4fpoDVwzacbtX29D+sCNcWSewBkfIl4/mGO0z8AI/SkiwDKzZe7M48BeNlLHFa r8QVSqSaVuwct5sA50LXq2Q4K+mxyMplMwSQ7fdPbSKf9bq3+rKJIBTKYEdH2bxsTmO6 IZ1Q1oHkt/HniKEOQenjp8W1u6JQOpbypsU72hSoAkoz5iwWi0vvQd/h0Bq5Ih1YrN/Q LvNiHj00dZO3doSzNvS18hoBZ70JJ/1wEaCXPAmbfGypXGJW2FShrYWEUWLaLXVnqPte 7EAr5hBrQ22IdjCXQVdvhGu1/fo4U+EUTk3S8CHA0h2mGoOz7DD+3BM3iiPCyophqNhq BZ6w== 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-32957-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32957-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q28-20020a50cc9c000000b0055bfdb04324si2159819edi.681.2024.01.22.03.48.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:48:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32957-ouuuleilei=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-32957-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32957-ouuuleilei=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 076571F25094 for ; Mon, 22 Jan 2024 11:48:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDDBF3F8D9; Mon, 22 Jan 2024 11:44:36 +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 D5FF03D0D5; Mon, 22 Jan 2024 11:44:31 +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=1705923875; cv=none; b=PqHKgqqanPsPKpsxPPFd0h/3rLKlh9CodYeySk9Tl7k70J9252T2S4XaZhtkSK/kFckh0zxiKKN8duZ3Tlb9iyfAGG/efVgR23TPqUxNPnI+rhBnVuvrTeJLTFiQlZi1Q3zQaabqToAnQ1PRdp79chtDrDi8ukw+t5LFSiPgEVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705923875; c=relaxed/simple; bh=TAuTg+ebqU3GHaMugMat3oRGpYYeFGa9Q3+ZhmA5B20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gRZi4V8+gUzQEyKHdCvPP9S2lp+5/avdMdwhidqRlwMLeaL/cQsMAIalZZ9empO2vjteUprz1ZH4dklHCrfXqbdHZZypkWTk07HSEhRP//7i0Q7mp/Mwfr91YX6cziBw0iOPtuNA5f3z7ShSmkGZlUiEEY2Ct8O7h/gNYgW8qWI= 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 1f64a8577498be2e; Mon, 22 Jan 2024 12:44:29 +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 0D8A3669540; Mon, 22 Jan 2024 12:44:29 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Ulf Hansson , Stanislaw Gruszka Subject: [PATCH v1 01/12] PM: sleep: Simplify dpm_suspended_list walk in dpm_resume() Date: Mon, 22 Jan 2024 12:22:38 +0100 Message-ID: <4553341.LvFx2qVVIh@kreacher> In-Reply-To: <5760158.DvuYhMxLoT@kreacher> References: <5760158.DvuYhMxLoT@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekiedgfedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepgedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehsthgrnhhishhlrgifrdhgrhhushiikhgrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788791093781966785 X-GMAIL-MSGID: 1788791093781966785 From: Rafael J. Wysocki Notice that devices can be moved to dpm_prepared_list before running their resume callbacks, in analogy with dpm_noirq_resume_devices() and dpm_resume_early(), because doing so will not affect the final ordering of that list. Namely, if a device is the first dpm_suspended_list entry while dpm_list_mtx is held, it has not been removed so far and it cannot be removed until dpm_list_mtx is released, so moving it to dpm_prepared_list at that point is valid. If it is removed later, while its resume callback is running, it will be deleted from dpm_prepared_list without changing the ordering of the other devices in that list. Accordingly, rearrange the while () loop in dpm_resume() to move devices to dpm_prepared_list before running their resume callbacks and implify the locking and device reference counting in it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Stanislaw Gruszka --- drivers/base/power/main.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) Index: linux-pm/drivers/base/power/main.c =================================================================== --- linux-pm.orig/drivers/base/power/main.c +++ linux-pm/drivers/base/power/main.c @@ -1017,25 +1017,19 @@ void dpm_resume(pm_message_t state) while (!list_empty(&dpm_suspended_list)) { dev = to_device(dpm_suspended_list.next); - - get_device(dev); + list_move_tail(&dev->power.entry, &dpm_prepared_list); if (!dev->power.async_in_progress) { + get_device(dev); + mutex_unlock(&dpm_list_mtx); device_resume(dev, state, false); + put_device(dev); + mutex_lock(&dpm_list_mtx); } - - if (!list_empty(&dev->power.entry)) - list_move_tail(&dev->power.entry, &dpm_prepared_list); - - mutex_unlock(&dpm_list_mtx); - - put_device(dev); - - mutex_lock(&dpm_list_mtx); } mutex_unlock(&dpm_list_mtx); async_synchronize_full();