Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp269784rdb; Mon, 22 Jan 2024 03:49:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHybTXE8bw1/IeK8wmxKyv7gN9hukKc1utNy6yCNwNKBG9yndX81yWdRGH2g/mhZvI44dXi X-Received: by 2002:a05:6214:20a2:b0:686:1e2:747f with SMTP id 2-20020a05621420a200b0068601e2747fmr3796052qvd.2.1705924144923; Mon, 22 Jan 2024 03:49:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705924144; cv=pass; d=google.com; s=arc-20160816; b=wujKQ4ZtfUb5JGyGonXwFbBAPFq2tyHl+RZH1MZs4MZCLlo4S9r0Z9lJqd4XxrHXNb F9pNAMrY2LEY7A3P66sLjeh4JH+9KnxY4DaPcOq1EVOjNLmCw38MQWdzZf3fiJUd3vBI KEHYCN7Cvz61NynfdKlopl1wYP5N2hPelUM1GOXRzYdL+az79lCLE2tORpxJ+4Ce64i2 5AokokHyvq6h44MqEO3RQ8BA5BRw/j5qbz0CzmxaYTgir4jUxMNNzqrI5HoeRpl+VAsq gSFPoX8U6ygAAcMersssAXAul0+S0Ez/RSK3ltfxWoyh3xXtDWWCEFvQ3vrGYwtKkYKL oGxQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32957-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a28-20020a0ca99c000000b0067f3f1efa34si5566473qvb.171.2024.01.22.03.49.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:49:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32957-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-32957-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32957-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 564AB1C27A6A for ; Mon, 22 Jan 2024 11:48:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A77873EA69; Mon, 22 Jan 2024 11:44:35 +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 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: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekiedgfedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepgedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehulhhfrdhhrghnshhsohhnsehlihhnrghrohdrohhrghdprhgtphhtthhopehsthgrnhhishhlrgifrdhgrhhushiikhgrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=4 Fuz1=4 Fuz2=4 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 --- 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();