Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1020816rdb; Tue, 30 Jan 2024 05:56:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIWuRiVSz9mkJxn0Hlgk5JgGGagdu+ZTQSnjHecRjCKWAOSC9wzVlrjOdezGov30FnygMR X-Received: by 2002:a2e:b0d3:0:b0:2cd:2444:d24 with SMTP id g19-20020a2eb0d3000000b002cd24440d24mr6235030ljl.47.1706622989797; Tue, 30 Jan 2024 05:56:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706622989; cv=pass; d=google.com; s=arc-20160816; b=eqr55xve+1jLitpBAD0w/RvG0xublz0FXQuE5jDRsPqomneUdnhAkD9Ehk9gGk/5vr K8pt5+mTv4tdc4H96IYh+x9x0wVkNMZNi2O2oBXWfQ+q/ZFpbhW27xxlfK14KKZobHhk Q5IDoPW16Vq7azmvIhxHk4pqO9I2VMrq1KL+afbX9m2t3vXPiXTG4k2ZjVGwnTiBsSrQ F6F+5YrsC8uHOpdYsPCtAiQowrK7dzz3jLURx8NI81VSCC2fiaUKiptgCbWdljp6rdm9 uHtYDAY4F5PxO3zzW4e7q54zz6zPbgcXZBIjaoDzozWWtYd3kOgIfTwQOsEPMd9PZYmX TxPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VhM4I+NVQMXAjMh8ZB8fOQpIn2P5PCgXqdocdKQIpBY=; fh=3lCNSO6LQCqhm4IvCPXj5H7Te/C8INRvRb78PtOk2Ps=; b=EC/g5NxWhylL9GthGQM7XbzRFtXuTC0JVPwk/V8pAPEl1xoDBruumD6048GrIn6oNW PopY8Te+dQrk2uiaXD8ZS7XfpJhbj9VK/6graCpPC9pjVoGhORnrQ+wV2rqVgu9Tyft/ PsN4Wc5arJZYh3QsuL7JX3Fsw+9hACXUEHyBFYUVeGd4RDRp3xzw5bmikk7sB3y2DU/U dHxhSmn1qXE+Vdclx1gi1Se7COsQvmdixCjKlw7S0jKOLW2OZrMKJH/Ij+JgAJSn9Z2y 1/JfcZKywwKOvxEjFcg462W8bd333jEM6AYfsUeh7YyMVPprJJeDkPUNa8gBxJts2nw6 ecXw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Fe3J+soW; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h7-20020a056402280700b0055f1331b162si1554668ede.572.2024.01.30.05.56.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 05:56:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44034-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; dkim=pass header.i=@intel.com header.s=Intel header.b=Fe3J+soW; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-44034-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44034-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 36FE81F2441C for ; Tue, 30 Jan 2024 07:21:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BB694F1F3; Tue, 30 Jan 2024 07:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Fe3J+soW" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) (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 06D224EB41; Tue, 30 Jan 2024 07:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706599296; cv=none; b=rtkx2mcfuF8AmhVC8/0yX/0IQBaKxl/eJWXivRrapM6RHtijwnaShUbAWMcBkpCbvvClFK1F842pVX8olP1ssB+ZYbnC+Rq1Bjbrnaod3OXIsMezinrV1U5jeGQoRRgmjOhhfQBrQEq2jRVz7qYUu93idepLnBDHYJ1v444FBfI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706599296; c=relaxed/simple; bh=tSB6EPHkugRg1IchrfqLds1PZx5JuhXbsW6yBlZ7EVM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eawGO07tIuVunNpApA+msUT93r0s2doxdRf/6zDAmSZVWGuq1qveHRaGvXA3ww7EaQ4crxsveH+HjKiG0RngFMdITlv2PzFcRMslSpeok4kJjAleS7xVyN6X0XNR2I3D5DWS8xek8yxH7GI5hmI6Q2W/s6aRUhNIjV1GrN20hrg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Fe3J+soW; arc=none smtp.client-ip=134.134.136.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706599294; x=1738135294; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=tSB6EPHkugRg1IchrfqLds1PZx5JuhXbsW6yBlZ7EVM=; b=Fe3J+soWgONhjFNe1ExFTy3EoqNSC1s8mttPLi1mRsBAc/8qjhyjhRMc 0scaiIPvOyLz6E23ti4TirpIU9ckwrgwo+yuinLRdZw2pdTGLBRbvXDer bYB3VDGlOmhj2qUpWeA2zaL/8yQFUJ/VVNnrpuostdv3xWtFG3jw0wHED YR1CxUayjeLRlXyHV+N8lDG+78WeK3icCFuecgEEJilGYozcm81fIut5O Zfe91i4URZH2oholoSRHr+yUWEwfzS2A+4H/3ftQemcGRBfHYnHchGnnv Jl8RKLy6i+qOV6BlxMbCXuOn+3f2mypFDDeORL3OkfBhdE/IIGYVAtUVO g==; X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="393624513" X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="393624513" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 23:21:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10968"; a="737681679" X-IronPort-AV: E=Sophos;i="6.05,707,1701158400"; d="scan'208";a="737681679" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.252.42.115]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jan 2024 23:21:32 -0800 Date: Tue, 30 Jan 2024 08:21:30 +0100 From: Stanislaw Gruszka To: "Rafael J. Wysocki" Cc: Linux PM , LKML , Ulf Hansson Subject: Re: [PATCH v2 08/10] PM: sleep: Move some assignments from under a lock Message-ID: References: <5770175.DvuYhMxLoT@kreacher> <3750318.MHq7AAxBmi@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3750318.MHq7AAxBmi@kreacher> On Mon, Jan 29, 2024 at 05:27:33PM +0100, Rafael J. Wysocki wrote: > 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 Reviewed-by: Stanislaw Gruszka > --- > > 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; > > > >