From patchwork Tue Sep 1 08:27:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 248839 Delivered-To: patches@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp4017769ilg; Tue, 1 Sep 2020 01:27:17 -0700 (PDT) X-Received: by 2002:a2e:865a:: with SMTP id i26mr7271ljj.246.1598948837572; Tue, 01 Sep 2020 01:27:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598948837; cv=none; d=google.com; s=arc-20160816; b=06gnReGDzbPX2ANWQd+zhP6D6uZ38Av4f25qGSjmXACSDfh/8L2xQVhHqr/yFcLc+y ktK51iO6E2hR9liZvyM8C0fnWX3XULsLSnjTPkvDeZkvkhCMG2B3xmx3D1SdpJ3DxVXL 3h2w9anV+stlP3EHuH/o1qeLXMUZ3bF8mwC+ffWDMv8Y6LuW5zJylK0TKVQh6c7Zw5Wl Rq9o7TZ3c3LlecrFEMBh0+/5Vikb5iCdjgE4yJ/RlgXmx/tauCcjG9EbX+QgPIcKwdy1 zsVa+pDquIJV81nQDMudMXNPtywuD+KKA01xt09UljVOwILNC0Vr9wpQ93MMszGrNXpj C9mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=+5tYnQUX16Q+heMCNRPh41Y4CeDI+HHRPCn/NIvgA2k=; b=Mu0M4yoqOxmkgjMicLEmgMcW7Jc1MHDQZn9saEg0gOVvSDKuqvf8wdeKB/oFE89BpI oZTIiSO65p9ja4P5FqmLMdyNTlHrdY8q2mZemJFm6uffXi3ndwnu3OtF9o3pKtQj5F9A aX7N0UpenmWGssyumKUdLo3mvaBaq7jwgqek84hXYwqE/F2p70+VyqF+Jbrbf/fFgZcF YITSxUcdaxty9DdnZ8BbrzbPGjezmBbwH/dAOofLi3t7cWVhzN1YqkHrhjgE2vts75Ys VKvN+Qc0MWeqGsKfjWqTEY26PuWJZxBqm3B34de0mGPEP7XITnyKB9xp0NAq7t4qnRRq I0/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yxjSKuPU; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h10sor217822ljj.56.2020.09.01.01.27.17 for (Google Transport Security); Tue, 01 Sep 2020 01:27:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yxjSKuPU; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+5tYnQUX16Q+heMCNRPh41Y4CeDI+HHRPCn/NIvgA2k=; b=yxjSKuPUj5jB/wd3E8BkAdEXpcwx+QYNlsPC+DlHOjFfNJIeYoAl+TOYLt71CG5nws 4wfPK6ihZGANEYge9CnzaRZHhIfU85mFZAjm5NIeQHIeTcT8xhHssr37u5c82vV3Xg6e xkaIuaf0XNj5qVPUGpCAxh1r2VKsdBceZ1rao2PrnuhOMMKML5sA/N/PePhhSTZeZpiC DvQ9ojYsgfYnm3yMYakbKCVddVBeIPTRRwTGlN6Oh7ThjJdgVYpmaZi1RKDRomNJUHSf cTUn/ZKpPJV1SIQhRuxZSJkuVw2eNdB3EoSbTyhnzkNnWaC1aYkicnw01akLplRv1s5o 85RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+5tYnQUX16Q+heMCNRPh41Y4CeDI+HHRPCn/NIvgA2k=; b=AlmzlxIm+BDdAnO7u7xemu4jW9SxU0eUaqq3TYK3AEY7bSTnX5Uf0rebKYQEDgfuMf y7Bco0NQZC9qiCqquYNo7Yn+RWqEPQkSDvAeb5vBvLk2OhN0TzJm/GS/uAooKjWoqwvz bfFjFYZt7kbb6aQENGcynU/8EyIQRXv2na9aA+xXf6a6dMlKG2i+WaB+PjUrnTTv+xPZ e9mBxAtHsDj5QUOOTqVoqHl2QwuO2iB5cRsMYxvmuIwTb/LShFE+Y8R00/bSATxUG8lH 7su/2+vBhQ4zGgJXVFSqVZ3qqsXptUn5G2l7q1ZhS+WJxsKNsXPTOaloh/1ay4HArCZO sKyQ== X-Gm-Message-State: AOAM5337tNAZ4lgAtV4qTgT4YgCSuLYPvlNQGbXNFH6ucp3iv2q19in1 iQGvNzzYdCOxBJGqCstKhif4sVzI X-Google-Smtp-Source: ABdhPJzBA4RJyll+BAH3x5aIMti9jSrmCxrccc4R3hcNImFw9LL9oQ7gvcPr4tUtek3iqAyzWjLKIw== X-Received: by 2002:a2e:900e:: with SMTP id h14mr438675ljg.103.1598948837167; Tue, 01 Sep 2020 01:27:17 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id c5sm111252lfb.24.2020.09.01.01.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 01:27:16 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] PM / Domains: Enable locking for syscore devices for IRQ safe genpds Date: Tue, 1 Sep 2020 10:27:06 +0200 Message-Id: <20200901082707.106860-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901082707.106860-1-ulf.hansson@linaro.org> References: <20200901082707.106860-1-ulf.hansson@linaro.org> MIME-Version: 1.0 The genpd lock is currently not being used, while suspending/resuming syscore devices through genpd. This because we need to avoid using a mutex when running in the syscore phase. However, the locking can be useful under special circumstances (as shown in subsequent changes) and for a genpd having the flag GENPD_FLAG_IRQ_SAFE set. Therefore, let's make use of the lock when it's possible. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 2cb5e04cf86c..55d99a36bf6b 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1342,18 +1342,27 @@ static void genpd_complete(struct device *dev) static void genpd_syscore_switch(struct device *dev, bool suspend) { struct generic_pm_domain *genpd; + bool use_lock; genpd = dev_to_genpd_safe(dev); if (!genpd) return; + use_lock = genpd_is_irq_safe(genpd); + + if (use_lock) + genpd_lock(genpd); + if (suspend) { genpd->suspended_count++; - genpd_sync_power_off(genpd, false, 0); + genpd_sync_power_off(genpd, use_lock, 0); } else { - genpd_sync_power_on(genpd, false, 0); + genpd_sync_power_on(genpd, use_lock, 0); genpd->suspended_count--; } + + if (use_lock) + genpd_unlock(genpd); } void pm_genpd_syscore_poweroff(struct device *dev) From patchwork Tue Sep 1 08:27:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 248840 Delivered-To: patches@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp4017785ilg; Tue, 1 Sep 2020 01:27:19 -0700 (PDT) X-Received: by 2002:a05:651c:110d:: with SMTP id d13mr8651ljo.206.1598948839553; Tue, 01 Sep 2020 01:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598948839; cv=none; d=google.com; s=arc-20160816; b=Ads8rXGfhn8iRQWrArx4Ae6eKAc1++ln2lH0fsE9yzgS2SiFnHT6GXkAMnk0y8kSIw XNBX/UT4+v331ZgSMjo76C9gicNcUryp3dvoUAwxJtY/ltgKspawF2mSS1rAjLK+xzUJ YhN1TF1K2prK8xOZCgNYTL9mXcO4IkcUZDFF8lpBw4HmXDhSgC/Mq83KwhoLbTl+jcpE Fd62UKP/Ke1oQAAArbPXbkkLkHMEdPBlR/okoTfynk3VtRaLHjxVN3ObxXkOFQ26O+9D QqyPfy4oo2zCa1VTq/P/HxISHqtWGJkOGLBFJDA/GRDHPxDMSsalWAmN4/KkA+NYJAzE tgTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=lXhXw6gw2mHmJ9Say6lfS63FssmiQ2xQJb+o3xFUf34=; b=Pux+EGILSTdMTiDYpy/UxwT+7aYPG2fHMpn1t6XMbWg9nCBtu///dDkidgEad0qdW2 12VQ+TGdBhYHR+YVGDM7sXmaftnlcMAzleJXXpKh8p25nFoJqBB04t15VkYxri4nr4wT 0Xnv8UhDyFO35dNdVaTdwB83kBOv7o4E4g3AOML3b4MGr7oOokz5y44DMPQmMnl4TbMv 0pz1dsNnHtu4G+GSw5w0Qp+c3eF8UjG5AvOb3qGI18tF8eUmAtiHeKpwJtphBG2UGVx/ sZXsTBBkFXsj2upNuTYhBOFbqQgCiHgTAj9BCHWhhBbr2QcnnVAtiIi+8aW3S6EE5Kgn lsnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zfzrThjF; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d12sor208780ljj.54.2020.09.01.01.27.19 for (Google Transport Security); Tue, 01 Sep 2020 01:27:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zfzrThjF; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lXhXw6gw2mHmJ9Say6lfS63FssmiQ2xQJb+o3xFUf34=; b=zfzrThjFMwF1c1XHJi778ZPH/w59mrO8rbDIg8IHZiiE0F8rQSGJCpKFoeWGheWK96 Idd0WZeKs/qriujA6iGr594rONIcY2Pe1Y1GVVQsO4lgvEGU9+96HJPQvxRP13iXjLUj Cz0eNJgi9pyOL2kxRsm79ad9LWMkDThPn4Mcgpbd9Doky3fX2IubA6wmvKv4XemYHSLt 8FabgI94lsEGxTNuzvzvg2tuD5eGP/jQX+/pWz19CWEXnwuwMGAInYbNigJBwfNqAXkQ Y9trrilA+YtBMww71ASpqRvRfImGrLaEL+yZObCcq/97LXeMmI3a6o0LdkJx2aY4/GhX IOCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lXhXw6gw2mHmJ9Say6lfS63FssmiQ2xQJb+o3xFUf34=; b=GiryWOmmNWdwUkO630VcmZ3z24VISQAHdZgOQIm7+MFPYbBfowaovZ2PN7IRaSyVWn dApzSufHZ9VOsjtkd4vqgEdmcZkjdhamuXe2sh59lnhYckTSMuMmPo/L7uJzDhsCfVym FVC6VLgghNxamgAm3Z/4F6UqmGDspo6vthERFeNsj9DzW2KWJXiElDvbpsCh8xj2SIum lR72ybDkBQOfMaP8t7XODxQ/0SYPK80AcPGPiTQRNMj6oSQMUUMGnfXxC44DD9jSYgZc VSAJbJlZY9T4iRFcs/s3geYuq/wpWGGCeeGKI4dt34XjQPrsIaTGXTixYszXZY7V990k P9aQ== X-Gm-Message-State: AOAM530ImtQXrsadKBRncYLvIWrq39NjhsJJ0BsLIP6Sm8t2XCNdI1Eq 9pAgkzAxg0Jvk55LTJmjsdGIOJFF X-Google-Smtp-Source: ABdhPJzVe2jkEa7XevmysGxEov7CVQX9Xjx6o7FSE+FdPUQgf+fKxVXEDSf0N3C1OuCCKppIMFQdzw== X-Received: by 2002:a05:651c:110:: with SMTP id a16mr12283ljb.152.1598948839148; Tue, 01 Sep 2020 01:27:19 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id c5sm111252lfb.24.2020.09.01.01.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 01:27:18 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] cpuidle: psci: Enable s2idle when using OSI with the PM domain topology Date: Tue, 1 Sep 2020 10:27:07 +0200 Message-Id: <20200901082707.106860-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901082707.106860-1-ulf.hansson@linaro.org> References: <20200901082707.106860-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To select domain idle states for cpuidle-psci, the PM domains via genpd are being managed by using runtime PM. This works fine for the regular idle path, but it doesn't when doing s2idle. More precisely, the domain idle states becomes temporarily disabled, which is because the PM core disables runtime PM for devices during system suspend. Even if genpd tries to power off the PM domain in the suspend_noirq phase, that doesn't help to properly select a domain idle state, as this needs to be done on per CPU basis. Let's address the issue by enabling the syscore flag for the attached CPU devices. This prevents genpd from trying to power off the corresponding PM domains in the suspend_noirq phase. Moreover, let's assign a specific ->enter_s2idle() callback for the corresponding domain idle state and let it invoke pm_genpd_syscore_poweroff|poweron(), rather than using runtime PM. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 2 ++ drivers/cpuidle/cpuidle-psci.c | 30 +++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) -- 2.25.1 diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index b6e9649ab0da..65437ba5fa78 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -324,6 +324,8 @@ struct device *psci_dt_attach_cpu(int cpu) if (cpu_online(cpu)) pm_runtime_get_sync(dev); + dev_pm_syscore_device(dev, true); + return dev; } diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 74463841805f..6322d55a0a7d 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -52,8 +53,9 @@ static inline int psci_enter_state(int idx, u32 state) return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); } -static int psci_enter_domain_idle_state(struct cpuidle_device *dev, - struct cpuidle_driver *drv, int idx) +static int __psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx, + bool s2idle) { struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); u32 *states = data->psci_states; @@ -66,7 +68,10 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return -1; /* Do runtime PM to manage a hierarchical CPU toplogy. */ - pm_runtime_put_sync_suspend(pd_dev); + if (s2idle) + pm_genpd_syscore_poweroff(pd_dev); + else + pm_runtime_put_sync_suspend(pd_dev); state = psci_get_domain_state(); if (!state) @@ -74,7 +79,10 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, ret = psci_cpu_suspend_enter(state) ? -1 : idx; - pm_runtime_get_sync(pd_dev); + if (s2idle) + pm_genpd_syscore_poweron(pd_dev); + else + pm_runtime_get_sync(pd_dev); cpu_pm_exit(); @@ -83,6 +91,19 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return ret; } +static int psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx) +{ + return __psci_enter_domain_idle_state(dev, drv, idx, false); +} + +static int psci_enter_s2idle_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int idx) +{ + return __psci_enter_domain_idle_state(dev, drv, idx, true); +} + static int psci_idle_cpuhp_up(unsigned int cpu) { struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); @@ -170,6 +191,7 @@ static int psci_dt_cpu_init_topology(struct cpuidle_driver *drv, * deeper states. */ drv->states[state_count - 1].enter = psci_enter_domain_idle_state; + drv->states[state_count - 1].enter_s2idle = psci_enter_s2idle_domain_idle_state; psci_cpuidle_use_cpuhp = true; return 0;