From patchwork Thu Jun 3 09:34:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 453238 Delivered-To: patches@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp114816jao; Thu, 3 Jun 2021 02:34:47 -0700 (PDT) X-Received: by 2002:a19:691e:: with SMTP id e30mr25466992lfc.302.1622712887298; Thu, 03 Jun 2021 02:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622712887; cv=none; d=google.com; s=arc-20160816; b=xAtqwDn2UJWJeZb+OFirAix+4q4rjjZkWVrZ9sH6WyUAQ6+Jiu+SgpEa+LGn7UYyns /q4qNZ4hQRQ5V/upBygRE0u8Tg+OCM9qH+N+0huPuOItxhCsf9vHqzz1Koh6npmHaH+Q FeYLvPi9KnPcOhjSCjrAd5Lg3u1wcM7pQWN38AGqNz9MAMCpKx5vRbZHJLHel4ksNtfm wDpcyV6b0CEpVUspIh57V9aHuz8djDAKuiL6v5iIVs5u8IkhWAr9xT8f3CxNMnKy5auT FA+jUGzj6OOGEpr9wvRiFhSLvWztBybMCnI530XTkzNcufONrKZAHlfrQzwcxKWZe2xT 8Ifg== 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=4rVASeO6Y6OcFufLMrsc56Y+VubvwdMfYIrrp6oq4r4=; b=IVWzeIDvmtj6KEZOLUrylR+NCCP+EJB5IaBn+1cKPNeNnDkjz5G9UUqmr3LkAhXFwb mPCl08tpzel+8Oj7s6WiqKpiYeN0P4MY4O0C4By3du3mW9z6egCVMxioCSdAWuy6UPOX 3SLeEy8Ufk70ylxJCDqTcwiKkFQlDhNBW8nQ7dQ+BmnOIYCmp38Ah4s2437XEBJ6iDmn +Ow1o4Gb3lmN1fbb73YRXhFrFSMNTJUly/BPdwvMewQY6omhMtn1eFs6P+re68WATzgl 5+0EC0wM4WJYXkkfX2UnziLU8VtV8Wk1L3pZJ2U/BAclRdyH2MQigJ0605qDbD96BJxf A10g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ttTV9dS3; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id e26sor512285lfn.128.2021.06.03.02.34.47 for (Google Transport Security); Thu, 03 Jun 2021 02:34:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ttTV9dS3; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=4rVASeO6Y6OcFufLMrsc56Y+VubvwdMfYIrrp6oq4r4=; b=ttTV9dS3FVDeh8gdxlsfE9fqeYyL4RbcrkOc2YpayXaxhjHVSYzHdSkYf8gZGF03ao FTogbxZRc6drk/Se9oX7peJvwggvDgXeGtDkyw/3Xv08d9EXgUxfFAxWP7R44czFhBxy YRp8d1xzO9W2w2WTbeLM/SXB4WmVUNrPmKHSY+ytmhEPVMbT1SAjeWGwL5t2SWQJjQuO EtV3pNVRyEYfFSK8vxVt+DnxeT0KTLj7s7EYNRrVYfL+2GZ7WUeOnjOue+Sp5vkkozMK JpZ6S/xnkX2a8JkxH42ozOzEKXBVmz9TURd2ykPpNXhzqc0krruQGo/0dWSw05UgWUqD SW2Q== 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=4rVASeO6Y6OcFufLMrsc56Y+VubvwdMfYIrrp6oq4r4=; b=g1dkzbMsiVYR4+Jc9S4T6szssYP8hjb0zVQC2nBdBDLunc1yVKuGMqbCTJ5g18L+jh zgUJolhPBE6Q9d1j9lYlna0HX6m4V/Z1qeEm/5V5O6wY/ysqvT0z/WXB1gnrQbi1OEvG CQb2MeWaAhaLdPbv6KkJLbYcJQ8perXs8Y7kgwzHdHwfIcopmjExXk8ThpDJOqx6tgHJ cIbyT5PIR4hzzbX9qLOAdVDNk/LLtdxfsE7tAol8LeW7MvgvnhsSGtdzXsbR40bfK7fF V+XXdDO67/eF5tiIapJi+2WDHK2RPV7HoPmmWHERUAt6E0VCfZco1pypCYL0QZPLVF/6 tMhg== X-Gm-Message-State: AOAM531NvniorGQYoadMUVo+MEeWF83L/hC4M/n5D2U2wAnsNU22NUJs xXsOqk+OyonCRZFMs4xbwGCNP03G X-Google-Smtp-Source: ABdhPJwTfUiqI1PTAa4Ti9ScSuSpJMZh9fZH533X9DuesqyiUwYZtT+W7JazvFs90129yoD0c46yiQ== X-Received: by 2002:ac2:5a4b:: with SMTP id r11mr18051551lfn.338.1622712886936; Thu, 03 Jun 2021 02:34:46 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id q4sm263373lfc.172.2021.06.03.02.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 02:34:45 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Dmitry Osipenko , Jonathan Hunter , Thierry Reding , Rajendra Nayak , Stephan Gerhold , Roja Rani Yarubandi , Bjorn Andersson , Vincent Guittot , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] PM: domains: Split code in dev_pm_genpd_set_performance_state() Date: Thu, 3 Jun 2021 11:34:35 +0200 Message-Id: <20210603093438.138705-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603093438.138705-1-ulf.hansson@linaro.org> References: <20210603093438.138705-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To prepare some of the code in dev_pm_genpd_set_performance_state() to be re-used from subsequent changes, let's split it up into two functions. Reviewed-by: Viresh Kumar Signed-off-by: Ulf Hansson --- Changes in v2: - A small cosmetic update and added Viresh's tag. --- drivers/base/power/domain.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index b6a782c31613..5c476ed1c6c9 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -379,6 +379,24 @@ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, return ret; } +static int genpd_set_performance_state(struct device *dev, unsigned int state) +{ + struct generic_pm_domain *genpd = dev_to_genpd(dev); + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); + unsigned int prev_state; + int ret; + + prev_state = gpd_data->performance_state; + gpd_data->performance_state = state; + state = _genpd_reeval_performance_state(genpd, state); + + ret = _genpd_set_performance_state(genpd, state, 0); + if (ret) + gpd_data->performance_state = prev_state; + + return ret; +} + /** * dev_pm_genpd_set_performance_state- Set performance state of device's power * domain. @@ -397,8 +415,6 @@ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) { struct generic_pm_domain *genpd; - struct generic_pm_domain_data *gpd_data; - unsigned int prev; int ret; genpd = dev_to_genpd_safe(dev); @@ -410,16 +426,7 @@ int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) return -EINVAL; genpd_lock(genpd); - - gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); - prev = gpd_data->performance_state; - gpd_data->performance_state = state; - - state = _genpd_reeval_performance_state(genpd, state); - ret = _genpd_set_performance_state(genpd, state, 0); - if (ret) - gpd_data->performance_state = prev; - + ret = genpd_set_performance_state(dev, state); genpd_unlock(genpd); return ret; From patchwork Thu Jun 3 09:34:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 453239 Delivered-To: patches@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp114832jao; Thu, 3 Jun 2021 02:34:49 -0700 (PDT) X-Received: by 2002:a19:4085:: with SMTP id n127mr26727700lfa.415.1622712889000; Thu, 03 Jun 2021 02:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622712888; cv=none; d=google.com; s=arc-20160816; b=s5euG7a8dG1QZY2hj9HCNd3a8M5Wtp4xJE5yQzoE8IifAavk9qXHUu4Pv9DqRk52I5 6oxLWlzolDEGZ6eHaTw/4yCnDzFygufMewqFia+PGsQay4IRKtNCEf0QvOq7D+eiKT6H OUsrPOSyOueHHbr2JmxEklQr1D3UZARN0FekT3/6x8ibHSMLeRvkGjiDJFZTylhiIg9I z4O5cfr1K5aLaSNCJ005Pc6tiL2+2DSUhHQlNJkdDDfjpRtATkB2Tb0rOEXnHeLCx16l nN/WSrk05lCuRMrxzWygF4JQpypWWg6R4Vmqk06Fl4Vf9uicj933A1n6kKb9rGxkrd6b GN4g== 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=lFoDekDYb/UgHdylIZARPBsEDFKjhn6BdLJDbtckeQE=; b=GJ6ikXSdKGNky0t9aCgubKQeFLtsIVw//p994ZpfYDRGG4txbzwF8ZDNvxRHaw7y43 174Y0FORXEer4CV8p+TcYRP/9z0qs5B2dARWvfTlFFFieSev+UePV1xuo4aiNm25hzwt PNj0Wpj0xsM/DcLYz4blDoO+kRbH9irL9yBcp4xyY+5Ls6sNUxSoFJiZuWLbxd81IYGM tAIpy6G/zcSc2XYjhTlomLONanHJRWXXVDxYrk4lyicnWqS6S/3C5TvRmO0But+wYfXe Z8urX6pACKbtM0CTT4JlVWzkWYyfdUgKXexBAN7dN5rxZCM4BU/DPw33CNkV7u/DvuNh hEeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JwdfSDzJ; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id e16sor1109512ljk.22.2021.06.03.02.34.48 for (Google Transport Security); Thu, 03 Jun 2021 02:34:48 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JwdfSDzJ; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=lFoDekDYb/UgHdylIZARPBsEDFKjhn6BdLJDbtckeQE=; b=JwdfSDzJpLBesUo4+88/C3oqVb/3B86q53A6DEJr2ZBkKnyTIRPbDaSACI/sePRLIp gwg+b6LjuKTGQI/vxI2t9qZrQtdgJTaGhkMl02vSnx+QbSvvdaZn44F72bqAfLFY6wKo GFxgoPbOcNT8sJJd690+WTKApuI3sWs1NsKPt/HEqrPCJVmGrpfh46PaEp3eGZOKLN0d b5n3chr1U+LbMeJHTigal0Oc7hYVdmo6DwpAH4gkrBdIW0jBgiLFgDDFbvmn8K9uw+Pl uYkXHmfMTdXpFwK8IDnr68gi50LJ8pMRtBuotoQZo9dZ1lQPDJi8ldsN8OZLe6ay0DQy klnA== 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=lFoDekDYb/UgHdylIZARPBsEDFKjhn6BdLJDbtckeQE=; b=Ls3OLBm0onJaJ5Jnhvja8znhgfyrocwICXcR3KrsP9+UY55IfDfiAZ4YSDkzh7v3UQ vkZbrwVfqlvYFheUBpeMBCZ6xSF/AaX8i4v+Xdr0ticQoGgHyomCSL7cKnR4DnqT5SHt 8OuBGVu/d4SQYB/njrBQ3TAaaCn4hBEM4IHAw0hyPy+Efx5+k+6NBRtEosqkyLDbcgl3 vwU1CEI0RLzC/bQRIWdOnLDmPTeViRbUUbGHptAI74zVGScK3oj05IPSYJmB5R8Inysd tK7hUjPR2E9mpu1KVJpxW8gHIUnq6YXPkYkYNEjiQF6abSyZKpnyGJjw2q1GLFm6ik1k d+2A== X-Gm-Message-State: AOAM532GTZ92KyxZlUfKRBeUDdUPtJNANwioP2FkmiWAB+oWKl+62Qtd B6P+WdoY4pEqoXhgxPuw+N/4sdYl X-Google-Smtp-Source: ABdhPJwg8KCHV0Hm4Ebc/CXC0Dea/8+lkoKKVArxsAIppRYHAbwPcXW5vLK4PJ8lxuaB3Ecfq3EHaA== X-Received: by 2002:a2e:a594:: with SMTP id m20mr29675302ljp.114.1622712888689; Thu, 03 Jun 2021 02:34:48 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id q4sm263373lfc.172.2021.06.03.02.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 02:34:47 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Dmitry Osipenko , Jonathan Hunter , Thierry Reding , Rajendra Nayak , Stephan Gerhold , Roja Rani Yarubandi , Bjorn Andersson , Vincent Guittot , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] PM: domains: Return early if perf state is already set for the device Date: Thu, 3 Jun 2021 11:34:36 +0200 Message-Id: <20210603093438.138705-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603093438.138705-1-ulf.hansson@linaro.org> References: <20210603093438.138705-1-ulf.hansson@linaro.org> MIME-Version: 1.0 When dev_pm_genpd_set_performance_state() gets called to set a new performance state for the device, let's take a quicker path by doing an early return, if it turns out that the new state is already set for the device. Suggested-by: Viresh Kumar Signed-off-by: Ulf Hansson --- Changes in v2: - New patch. --- drivers/base/power/domain.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5c476ed1c6c9..ef25a5b18587 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -387,6 +387,9 @@ static int genpd_set_performance_state(struct device *dev, unsigned int state) int ret; prev_state = gpd_data->performance_state; + if (prev_state == state) + return 0; + gpd_data->performance_state = state; state = _genpd_reeval_performance_state(genpd, state); From patchwork Thu Jun 3 09:34:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 453240 Delivered-To: patches@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp114849jao; Thu, 3 Jun 2021 02:34:50 -0700 (PDT) X-Received: by 2002:a05:6512:2316:: with SMTP id o22mr27113622lfu.510.1622712890761; Thu, 03 Jun 2021 02:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622712890; cv=none; d=google.com; s=arc-20160816; b=pw7K1PFu3qnupGJ0sN3+C9O5Y0RDk/17dTHfz1/zVkgYO422GiFZGKhLTQcj+bOshy Fl1t+NLHsBrJffLtwWz7mSDp2sVErsLpmiA4nE0uJQLHfdAPiyY59xZFSOiievMyVNEq TFmkvbWnpthM4Dct204q0iMAJ7Gf/4IlCx8ZY5W5w5FdGCwEENAOnrW3Zc2fsUvVIOmT CV4DRJBAVO8jPrAJRJpEbvnPsD+ynhDdWhki1LNI2tETyyQod4r45yUH/VOqN38dOzkv 48m7c9XSCYSDkvxpURgOAGjVEk8wUXGvsungdg92SE8YlVgYMtDQGYQ4UMeLrw00gekc 0foA== 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=nq0h2Rai/tpUtSdSLeC5esAyt1vXtkpXm4C0UDmlQDU=; b=x9+isC3kKnBRZYaSAQQMz9mHEmlaedii4f0ECx7Dm6IuAAQxAst0SMvjIElEzCGdVk HITGtu5iSpEcj4meo6CFQvHji6WcMsXfKpInb2HlaSvQa6f+bQqLemceRZRPZRfkyjYJ WE0nUXHxOWsE9zUtUcclMZ5/gWmUzryzNWtw9hw2WuSR0/tM8xf1mnpYeDFM5mOvnQxa cyYXunTyCWWVN1tQ4aA8GcHpjk0q9slHhqTjBNa8lwIs8Ovlvrnl7oN6ttC5jZaLnfgQ 1o9iyxDdCRKs1loJRWom7cHCBro8mfaMIjeNmBslHiIRXjeVevM3JZcVUw8AN0kjMQgi RjKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hvMBLrYH; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id v124sor540722lfa.124.2021.06.03.02.34.50 for (Google Transport Security); Thu, 03 Jun 2021 02:34:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hvMBLrYH; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=nq0h2Rai/tpUtSdSLeC5esAyt1vXtkpXm4C0UDmlQDU=; b=hvMBLrYHCWMkWfU02Uc00BYq14sjtXmNCStD4dBtsXGCWBEjBBlJ9efW5N1AKdpqP7 qrJnw+wWMzym/dBQYz45G2EhMvy/qWPkOd0m1PVBGC1NSzC2zxptrE01rJ1oJMSx3+nR ynDBRJO3tF4ZGcO7EWiBJUrx/5yloKy28jlr91fFiFglRRVejNwXUBgGhYWx6+i8ao3t qI/5ZevLBZwv7jGf9yxW/MJ0wLcoReVVlDUNbJWNCpxwb478Sb/fCg93UmihIUKSNe6D GfXjjW9ftXQfcPuz0+XRQJeqK+HNi6BZlMMF9jy5IWfTZurZ5d+GNelIO0vMeiP5Gs6K 1YRg== 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=nq0h2Rai/tpUtSdSLeC5esAyt1vXtkpXm4C0UDmlQDU=; b=DJcZ6YAkYJnZON4htHCEBPrYJJJ4UPAE9GniIS2Fodh0sUZnnd/F1+xkKN/zUhCQ7i cDL/Ha/VjL0O8wmGQ4YNzAk2N6zVuJRhTFFu3ges5wdTUYfB73s2popLH15L+dSX/DKb 3vxQu1Xq3NbMPMEzVW9JvHtxkvkeh342Ywt7a2F/PGix1pqvraaj8Qkipj4+RYhj9ykC +h5xWgX0gCHgEF/XOZ/zwhupEgPuw9VR3zkj3lk+BYCK0xwcGgkGuAL565TkRYfLKL9W VlOlG394WLoTMJ2b5lIFL/wZMXrFxLRRcEgOPSWvel8HI6/BZTE/in3NO5lDY/WFoms8 XTqA== X-Gm-Message-State: AOAM531RU/RiExr+PHLtQqnr9dAMqWwrfqggdSN/6IqHRLFO0QNVkQNH MvY/sCjNVNLgBoP0EmAEQ8GTHGop X-Google-Smtp-Source: ABdhPJxpFSsYKrqvgqC4Q7kRSbSGZehZRwk2RDVpSloOM744iqlLBfS8I/728O1G7Wf6U2RfB4aqgQ== X-Received: by 2002:a19:484d:: with SMTP id v74mr17856139lfa.396.1622712890381; Thu, 03 Jun 2021 02:34:50 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id q4sm263373lfc.172.2021.06.03.02.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 02:34:49 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Dmitry Osipenko , Jonathan Hunter , Thierry Reding , Rajendra Nayak , Stephan Gerhold , Roja Rani Yarubandi , Bjorn Andersson , Vincent Guittot , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] PM: domains: Drop/restore performance state votes for devices at runtime PM Date: Thu, 3 Jun 2021 11:34:37 +0200 Message-Id: <20210603093438.138705-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603093438.138705-1-ulf.hansson@linaro.org> References: <20210603093438.138705-1-ulf.hansson@linaro.org> MIME-Version: 1.0 A subsystem/driver that need to manage OPPs for its device, should typically drop its vote for the OPP when the device becomes runtime suspended. In this way, the corresponding aggregation of the performance state votes that is managed in genpd for the attached PM domain, may find that the aggregated vote can be decreased. Hence, it may allow genpd to set the lower performance state for the PM domain, thus avoiding to waste energy. To accomplish this, typically a subsystem/driver would need to call dev_pm_opp_set_rate|opp() for its device from its ->runtime_suspend() callback, to drop the vote for the OPP. Accordingly, it needs another call to dev_pm_opp_set_rate|opp() to restore the vote for the OPP from its ->runtime_resume() callback. To avoid boilerplate code in subsystems/driver to deal with these things, let's instead manage this internally in genpd. Signed-off-by: Ulf Hansson --- Changes in v2: - Rebased. - A few minor cosmetic changes. - Deal with the error path in genpd_runtime_resume(). --- drivers/base/power/domain.c | 27 +++++++++++++++++++++++++-- include/linux/pm_domain.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) -- 2.25.1 Tested-by: Dmitry Osipenko diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index ef25a5b18587..e5d97174c254 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -400,6 +400,23 @@ static int genpd_set_performance_state(struct device *dev, unsigned int state) return ret; } +static int genpd_drop_performance_state(struct device *dev) +{ + unsigned int prev_state = dev_gpd_data(dev)->performance_state; + + if (!genpd_set_performance_state(dev, 0)) + return prev_state; + + return 0; +} + +static void genpd_restore_performance_state(struct device *dev, + unsigned int state) +{ + if (state) + genpd_set_performance_state(dev, state); +} + /** * dev_pm_genpd_set_performance_state- Set performance state of device's power * domain. @@ -842,7 +859,8 @@ static int genpd_runtime_suspend(struct device *dev) { struct generic_pm_domain *genpd; bool (*suspend_ok)(struct device *__dev); - struct gpd_timing_data *td = &dev_gpd_data(dev)->td; + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); + struct gpd_timing_data *td = &gpd_data->td; bool runtime_pm = pm_runtime_enabled(dev); ktime_t time_start; s64 elapsed_ns; @@ -899,6 +917,7 @@ static int genpd_runtime_suspend(struct device *dev) return 0; genpd_lock(genpd); + gpd_data->rpm_pstate = genpd_drop_performance_state(dev); genpd_power_off(genpd, true, 0); genpd_unlock(genpd); @@ -916,7 +935,8 @@ static int genpd_runtime_suspend(struct device *dev) static int genpd_runtime_resume(struct device *dev) { struct generic_pm_domain *genpd; - struct gpd_timing_data *td = &dev_gpd_data(dev)->td; + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); + struct gpd_timing_data *td = &gpd_data->td; bool runtime_pm = pm_runtime_enabled(dev); ktime_t time_start; s64 elapsed_ns; @@ -940,6 +960,8 @@ static int genpd_runtime_resume(struct device *dev) genpd_lock(genpd); ret = genpd_power_on(genpd, 0); + if (!ret) + genpd_restore_performance_state(dev, gpd_data->rpm_pstate); genpd_unlock(genpd); if (ret) @@ -978,6 +1000,7 @@ static int genpd_runtime_resume(struct device *dev) err_poweroff: if (!pm_runtime_is_irq_safe(dev) || genpd_is_irq_safe(genpd)) { genpd_lock(genpd); + gpd_data->rpm_pstate = genpd_drop_performance_state(dev); genpd_power_off(genpd, true, 0); genpd_unlock(genpd); } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index dfcfbcecc34b..21a0577305ef 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -198,6 +198,7 @@ struct generic_pm_domain_data { struct notifier_block *power_nb; int cpu; unsigned int performance_state; + unsigned int rpm_pstate; ktime_t next_wakeup; void *data; }; From patchwork Thu Jun 3 09:34:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 453241 Delivered-To: patches@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp114869jao; Thu, 3 Jun 2021 02:34:52 -0700 (PDT) X-Received: by 2002:a05:651c:119c:: with SMTP id w28mr28733607ljo.164.1622712892578; Thu, 03 Jun 2021 02:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622712892; cv=none; d=google.com; s=arc-20160816; b=ZPYL9SYMPfMwfy3FoiCyf3DmWnJq86hn80ltoA9BmyTTCFAJr44oZ1fDlN+dsyVHf4 edMUnjKFbdrvqnKbaBpH/w62BGQeGL8Z8PbqsWhL3HFBnMraL4GfHTs4I+BjUvrawS2v s51ZwnQO+ceuFmV24/99OwIPDedlyX17uzVd9U3CTy6vn9rUFIGsiInnvXSHyRMuY9Ta iCecERW+aGNNNY4Lse5hfbamGTHSibj/uIQc7ZEPGz/gwKSZi3LoO4bV6djiKlJk7a76 ie6uyixSprT4a7wnOJB83nTpAaXybgu8E5KxiYdv/SGP7dRfl/tH3qiJ6ufpF8UAUKhZ MCAg== 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=2Eupuj1h7Dw7kPQa+fb7IRdjjpTjghXD/2FhQTKixNA=; b=C+NioJ1hpp/WPBHPRThpC6spemr+f/lrNqEzzX4RXcykCdQWBPz2ilRY223jqfMvVN 38fcAGsWEd4F5ihqtPadrgGJOKSnyY0yv+VIlF4jDNKLdLGgeE/ArAZFgxW6I42fCS6x FnKTBNRmzZTMZYkVh9nFLihuZBvdpyeP/LJzjssGEdHGYoKSliVZbl+WEDhsaMu0ZhiS Eem/YxW5bDIY/GGrzSuWMeOv0IFQbhxavNdYYPHr5U4a6nWSgowT1Vbt8gtDI56erAa1 Nw+3zBaj0z6dEoVSU5UKOfQEoG3DU63XFg0z5DUb1d9wnjv6S/uROAVvtb/huz9z6o0M nIZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hcQbwMN5; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id v14sor542883lfa.31.2021.06.03.02.34.52 for (Google Transport Security); Thu, 03 Jun 2021 02:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hcQbwMN5; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=2Eupuj1h7Dw7kPQa+fb7IRdjjpTjghXD/2FhQTKixNA=; b=hcQbwMN5/aI9WJKYvwHHz/GG3QksGXbdsVkkESP4IrK/59OH/YfL+BT1qQEz4yOYJF pM1eUjngP4f4YU9m6RKyRwmxLYNcMSTeVU3SWwPHCt3N0LELKL5kkYTqppQ/kuIS8OwI 5H3DLjClqpVU3XzggiO0evKdjKd3oBVRn93YwIJJ/mDs+kRAts5iD33T4SUrMblAEOgT uNvU1jPYQnA7TYp0Z9lCCo7UYSFkAM2m1yLGB/bkE7qpbae4RwbQ0q59A0KCTjonfvBG /jr0QhgiI2imH57Xmr/4wALgz0lRX0s2e+aAJBcTBg+cm9HerJmp6K+aFYrttViuL7Zm ha1A== 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=2Eupuj1h7Dw7kPQa+fb7IRdjjpTjghXD/2FhQTKixNA=; b=n+fCaI9yAO0Ycx4DHPUln13J5jVfAO79DZ6d/sAbKro+IYCmkRBSOJ7UXQcJNXpTQ9 X45XfcSSdZrrN4Aq1P4ngpCMgXk5if5Swfd62MAmIkrnnp36oo2dbRmMUglI9p357o3p frcbu5RDH9eAEzSv3Zx82WYRC8sAB6+kDfNaX56ZsX9xJI66PfedMr1ZJotzGiBef9Ae zFjrt/p0Jlce2AHpDFBVpl8SpI4y2NGItNML/yZeRBD/eEWcHgyDWNeDkcjwJp2Rsb6W WoXuxYfAMP52hpvxhKT9o39nozbvn1ltRGVcui4ewSUdRR6I9UxlKBJ+x+0RlzvniBqp 7JpQ== X-Gm-Message-State: AOAM533SlTRjRoPKVRrFC5SBWdH28pMiOxqM3N45FUhXGc6G9rhoKdNV wtj/hDAykScEyituXgf/PoMVuqFR X-Google-Smtp-Source: ABdhPJzfFepIAELPykTVo92DbsNR/ePHrcAl9pHysFlUDtDOoxKp4oHrS5nShW8i+ND8w/C6Am15zw== X-Received: by 2002:a05:6512:696:: with SMTP id t22mr26277864lfe.581.1622712892227; Thu, 03 Jun 2021 02:34:52 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id q4sm263373lfc.172.2021.06.03.02.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 02:34:51 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Dmitry Osipenko , Jonathan Hunter , Thierry Reding , Rajendra Nayak , Stephan Gerhold , Roja Rani Yarubandi , Bjorn Andersson , Vincent Guittot , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] PM: domains: Drop/restore performance state votes for devices at system PM Date: Thu, 3 Jun 2021 11:34:38 +0200 Message-Id: <20210603093438.138705-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603093438.138705-1-ulf.hansson@linaro.org> References: <20210603093438.138705-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Recent changes in genpd drops and restore performance state votes for devices during runtime PM. For the similar reasons, but to avoid the same kind of boilerplate code in device PM callbacks for system sleep in subsystems/drivers, let's drop and restore performance states votes in genpd for the attached devices during system sleep. Signed-off-by: Ulf Hansson --- Changes in v2: - Rebased. - A few cosmetic changes. --- drivers/base/power/domain.c | 9 +++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 10 insertions(+) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index e5d97174c254..a33e5b341f3f 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1171,6 +1171,7 @@ static int genpd_prepare(struct device *dev) */ static int genpd_finish_suspend(struct device *dev, bool poweroff) { + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); struct generic_pm_domain *genpd; int ret = 0; @@ -1201,6 +1202,7 @@ static int genpd_finish_suspend(struct device *dev, bool poweroff) } genpd_lock(genpd); + gpd_data->pm_pstate = genpd_drop_performance_state(dev); genpd->suspended_count++; genpd_sync_power_off(genpd, true, 0); genpd_unlock(genpd); @@ -1245,6 +1247,7 @@ static int genpd_resume_noirq(struct device *dev) genpd_lock(genpd); genpd_sync_power_on(genpd, true, 0); genpd->suspended_count--; + genpd_restore_performance_state(dev, dev_gpd_data(dev)->pm_pstate); genpd_unlock(genpd); if (genpd->dev_ops.stop && genpd->dev_ops.start && @@ -1364,6 +1367,7 @@ static int genpd_restore_noirq(struct device *dev) } genpd_sync_power_on(genpd, true, 0); + genpd_restore_performance_state(dev, dev_gpd_data(dev)->pm_pstate); genpd_unlock(genpd); if (genpd->dev_ops.stop && genpd->dev_ops.start && @@ -1409,23 +1413,28 @@ static void genpd_complete(struct device *dev) static void genpd_switch_state(struct device *dev, bool suspend) { struct generic_pm_domain *genpd; + struct generic_pm_domain_data *gpd_data; bool use_lock; genpd = dev_to_genpd_safe(dev); if (!genpd) return; + gpd_data = dev_gpd_data(dev); + use_lock = genpd_is_irq_safe(genpd); if (use_lock) genpd_lock(genpd); if (suspend) { + gpd_data->pm_pstate = genpd_drop_performance_state(dev); genpd->suspended_count++; genpd_sync_power_off(genpd, use_lock, 0); } else { genpd_sync_power_on(genpd, use_lock, 0); genpd->suspended_count--; + genpd_restore_performance_state(dev, gpd_data->pm_pstate); } if (use_lock) diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 21a0577305ef..f6e9dc28621c 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -199,6 +199,7 @@ struct generic_pm_domain_data { int cpu; unsigned int performance_state; unsigned int rpm_pstate; + unsigned int pm_pstate; ktime_t next_wakeup; void *data; };