From patchwork Tue Oct 29 16:44:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 178041 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp52016ill; Tue, 29 Oct 2019 09:45:00 -0700 (PDT) X-Received: by 2002:a2e:80c1:: with SMTP id r1mr3359863ljg.195.1572367500598; Tue, 29 Oct 2019 09:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572367500; cv=none; d=google.com; s=arc-20160816; b=scnX5+DVzzPe7qSC8lygn/A5ukzDR4pVnhn1l5N1GVXRNFw/UEeVz8k6q/rkPEgRnc ec/6o/kxdTqOQvnSBiiSY6Mw8vLljWDt9sr5k35/yrdRgo2q8VAtpR/wK3+x8DMGQyMP +qcWU9xHr8COKVS8P+5sr+92jI3Ez5r3CeTxQNSfqbzGL3SH0L+490hLNc3DDUiNa1iF 0EmDqPj2IZAQ4+f4lr13KU8BgatvpnHBrJLAyGPag1mXdJHh5iDVGZH95k/LXO5R6I+7 LnHAWbL5y0vhvvlXaNLNv/EUpITq8b+YqXt+ynDy/H59nH9KHYihIjo2fPf6rpBGbdzO uyGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rmTg5S9BzhED65UVWftQq6ljq1LQZhA0EBbzU9hhqeQ=; b=WvBAHkYiDVyqQOIo+51LF39L+h0efR+drF6tpJPiz2Nxz77rXbdwrbsrFaXNg/Bvpl rhWCsFhQTcRFFZAp1jUB32U6kcROwIyNxdRTmOt1FbV/Ga1/Typ3KCAA+h8ClApZ5mVh 6S4s0Z+PdeeNEd94sCzIeFDg35BgqO4jTiReHUmED72VU7Ctn588jVddF8A0wapCZ++N wQMMZiYeSU03MRhLMR+2xiERhKAZa+5KJ1TUmncH4Ygq1vgIs7aq0K6z1ckN+8WeTdW9 L3pkEIb4vy6RYoj++dpsCJbF+VK9bTgj1sEsqzQtF2/+JaaNY0+DqnofiSXMS0lGfZxB +n0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aqzEO0G1; 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 o15sor8254497ljc.19.2019.10.29.09.45.00 for (Google Transport Security); Tue, 29 Oct 2019 09:45:00 -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=aqzEO0G1; 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; bh=rmTg5S9BzhED65UVWftQq6ljq1LQZhA0EBbzU9hhqeQ=; b=aqzEO0G1RyLhLQmCiDT2JleGD1IdETwghK3gyCVpU3BoJ9IuHC/mJJtZqyEw7OS5bY 8Pt4WTtjZ+5IeX1WyaqK0oxx9v79xIuTQqk2y4zsdW41U0BO6JplWCJNK0dtZpODoM0L 0lKghAQnovyr1JsLBsc29QAhAX43dJTSGZc4b1wvan915ofokrkC+6XjliyFzkzr/lyG NG0DkvysJMRGehwK4eH/+gmFLoocqpJy2k/jfeIAAVJjfDpLGzFhNnCrBqv5ZeazYjAn JlUcvaviVU0GvIb7r3OWkBXXWrrW+mGtVJequx0KFAO2HlykGcmi2A0fAv9aJQmGLA+b GqIA== 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; bh=rmTg5S9BzhED65UVWftQq6ljq1LQZhA0EBbzU9hhqeQ=; b=kwEz3UfICMnStW4ToVyeIje2zBV0eN37kLNSc/+X+Muol2eaCB1sV1pLmaVNEk7tb/ WeXJMFDiEVDfghnRYVcvwFZ5JbZkKRhMaKF7pyt2sC8LbRoEFJlYtsvL10nzvlNzg+Dy 88FgIovSoi9sQBgwe0RrROAxRqY2r4a/FNW7XsheyVj5GHXd/ivBe5+zlMohXQzCXlnk cn3jB4lguR/002SpVTTzxU2kTswf6E6kg3tMEzuiTMFd3nBMgcd6tsIpvhH6TiiBaOT/ ghx7SjC2anAjnpPz7OGNk7DmxGzn82s+fE283rQBns3ohNKNbjxJLFDEqSUzCD71bMsZ o7zg== X-Gm-Message-State: APjAAAWFXXEOIWGnnP8yhShBW3fkRlNSdOQvQXswt2/OU3VYEhsrsS6A AaqB6kclaJhg4d1F2AJ9KBmKnM/3 X-Google-Smtp-Source: APXvYqzEL/7R3mVVyBqWfGuEW21GUqv79UeOF7RbekoESh7r+dEmrlO8kUYeAvjCF8KRrW5zWEFfXw== X-Received: by 2002:a2e:8113:: with SMTP id d19mr3480037ljg.229.1572367500173; Tue, 29 Oct 2019 09:45:00 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id f28sm2048161lfh.35.2019.10.29.09.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 09:44:59 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH v2 10/13] cpuidle: psci: Prepare to use OS initiated suspend mode via PM domains Date: Tue, 29 Oct 2019 17:44:35 +0100 Message-Id: <20191029164438.17012-11-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029164438.17012-1-ulf.hansson@linaro.org> References: <20191029164438.17012-1-ulf.hansson@linaro.org> The per CPU variable psci_power_state, contains an array of fixed values, which reflects the corresponding arm,psci-suspend-param parsed from DT, for each of the available CPU idle states. This isn't sufficient when using the hierarchical CPU topology in DT, in combination with having PSCI OS initiated (OSI) mode enabled. More precisely, in OSI mode, Linux is responsible of telling the PSCI FW what idle state the cluster (a group of CPUs) should enter, while in PSCI Platform Coordinated (PC) mode, each CPU independently votes for an idle state of the cluster. For this reason, introduce a per CPU variable called domain_state and implement two helper functions to read/write its value. Then let the domain_state take precedence over the regular selected state, when entering and idle state. Finally, let's also avoid sprinkling the existing non-OSI path with operations being specific for OSI. Co-developed-by: Lina Iyer Signed-off-by: Lina Iyer Signed-off-by: Ulf Hansson --- Changes in v2: - Rebased. --- drivers/cpuidle/cpuidle-psci.c | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 167249d0493f..4b0183d010e0 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -29,14 +29,55 @@ struct psci_cpuidle_data { }; static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); +static DEFINE_PER_CPU(u32, domain_state); + +static inline void psci_set_domain_state(u32 state) +{ + __this_cpu_write(domain_state, state); +} + +static inline u32 psci_get_domain_state(void) +{ + return __this_cpu_read(domain_state); +} + +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_state(int idx, struct psci_cpuidle_data *data) +{ + int ret; + u32 *states = data->psci_states; + u32 state = psci_get_domain_state(); + + if (!state) + state = states[idx]; + + ret = _psci_enter_state(idx, state); + + /* Clear the domain state to start fresh when back from idle. */ + psci_set_domain_state(0); + return ret; +} + +static int psci_enter_state(int idx, struct psci_cpuidle_data *data) +{ + u32 *states = data->psci_states; + + return _psci_enter_state(idx, states[idx]); +} static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { - u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); + + if (!data->dev) + return psci_enter_state(idx, data); - return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, - idx, state[idx]); + return psci_enter_domain_state(idx, data); } static struct cpuidle_driver psci_idle_driver __initdata = {