From patchwork Tue Feb 12 07:06:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 158113 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3504244jaa; Mon, 11 Feb 2019 23:07:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IYY/VfMR4/QJ0LCiEGCY4AtXzPu9Vh8g1RbtxuYVn9hvI4pxhp6zmXCN2W9/DGyUCTTPAO6 X-Received: by 2002:a62:5b44:: with SMTP id p65mr2476396pfb.47.1549955220753; Mon, 11 Feb 2019 23:07:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549955220; cv=none; d=google.com; s=arc-20160816; b=eu3iQFH2VgI1+Ke3lXCghUPWymcy6pfXffDKTUwvPYjTK3x3VKMn5giQZtzhTlTOzn aunkahSIGOunw9zI3wwnc6cipqOhwdqOD+GDTtsK6/SYMqIVuYMztyS/DljuYtFPfEus jMJjRM4xrYNXQ5B/DRemR8qniPIdtEcmHKnx+gx1iyw7A7bc9C9zuKaR5faJNone9l7m hrddf0pZCMbJGxJgm5Om6ez09BN3vdNMNLSK0lFA2aadaxFJijYx8qkOaIjny5I4CWm2 3Kl+er3df5iAlPlEXsKkLgB1acqyfx5fqPjvFcpK0MHN2nDd1oarOi7fw/J5lT262q9v AEiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+7lnsNfda5EyHahbpmzYfHt2btioT/RL3iWR+Fw03tg=; b=vbmorhJPsxAX51Wb4oEuMsfo9rc+WrG6yv5IydoyNiFG3rTk0xj25hlSv5OP5Xhp/y kWzdoF638qfaC39D/cDxh6Wt/OrG0RjIxM1iurQ4MCIscXWF2Z7IW96aDM1pg66N9QEK SQQot9t1jBIKxqxna7cPjw/IZfegf5uHWr0oc5E+ViL8VVBQ5hqmp8rSZo9FZxOCz66v sMBLF+SUKSn4oUp6nR/uxM0ky8HaKxvzPyXaEyNua6Sqa+94TDQ6YmQaFeQoFJz6YBbM ePgYwXPJkoIUV8tFD9dhu5HGFE7FTfnefddqPe9xF+mjcAY4L1JfvTFBrx+Bj6D8+F0A +m9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLqDVeIq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 98si13186184pla.320.2019.02.11.23.07.00; Mon, 11 Feb 2019 23:07:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WLqDVeIq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727728AbfBLHG6 (ORCPT + 31 others); Tue, 12 Feb 2019 02:06:58 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39384 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbfBLHG5 (ORCPT ); Tue, 12 Feb 2019 02:06:57 -0500 Received: by mail-pl1-f194.google.com with SMTP id 101so855141pld.6 for ; Mon, 11 Feb 2019 23:06:56 -0800 (PST) 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=+7lnsNfda5EyHahbpmzYfHt2btioT/RL3iWR+Fw03tg=; b=WLqDVeIqMJBVp5hNV5D1l5ZycFPOTbvys7yMtu0CyCGNBlD+e5ZLbRICCwKrpqGAXb bgXZ8g6eQY3wf2ZgqmiQLPNa3qvk9+yg+dyRm5rzjTCEVtB34kmNtIGsztDTHRf+Fuat p1Q8uBeabL9pHG+WlTHwzQI9j/KrzJO895FV1gHF0Lygl/U8tkRRffNV3WJPlWT/x3aj J3QVCV/r5j8mbUoPM0ezOGKiRPhMyNx/Fvx+DeUfF+PC8MapBEwDBB+VEtiqDbrTDB1t j9bLJsO8jjt7ztgIU9cQoWCd8PRjoOQkkqa6bdUMG7JiLDROO7GpO89oiIQkhtgRXs/w S29w== 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=+7lnsNfda5EyHahbpmzYfHt2btioT/RL3iWR+Fw03tg=; b=nZ5EL34NuxXgvqnhz5Xvpov/v9OZRFbyqEJHyqW2yLjtX1EuUd816nbt0Bd13tln+X 2ylEJ9WgNPNauGODVzn0y7swBqo0qLhSaqQ4967043w+AY4RCFwtYgpa5xZFS+2+AN8A H0ZvtZxi2I7dVFsfxSD0Q3yYtbZ8Xl2VERmUTSXfZbDlv1mTIaLNtnSRGBjTk2mNX9Tx FeAD/afLdJ1WS1XPXtwPHDSISK2u9Wk/P5fgGJN326GtPju8Zu9jS6r1oWHkiDN+AgHt zP2/JNn2KmFWTmST4wxWVQtcc+c04Ls8XRRtN21+qqaH4j4hvCJ/yC1IJCytcKBRraOH JgFA== X-Gm-Message-State: AHQUAubcMwE5yjQqM3YaYXg1ONai+++hAry5zLq4J24BO+tGrq7jcSKg 2LWynP5NI//aIewofSYRbDfSEA== X-Received: by 2002:a17:902:b20d:: with SMTP id t13mr925676plr.41.1549955216547; Mon, 11 Feb 2019 23:06:56 -0800 (PST) Received: from localhost ([122.172.102.63]) by smtp.gmail.com with ESMTPSA id o25sm17290490pfk.185.2019.02.11.23.06.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 23:06:55 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Sudeep Holla , Marek Szyprowski , linux-kernel@vger.kernel.org Subject: [PATCH V2 1/2] cpufreq: Allow light-weight tear down and bring up of CPUs Date: Tue, 12 Feb 2019 12:36:46 +0530 Message-Id: X-Mailer: git-send-email 2.20.1.321.g9e740568ce00 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cpufreq core doesn't remove the cpufreq policy anymore on CPU offline operation, rather that happens when the CPU device gets unregistered from the kernel. This allows faster recovery when the CPU comes back online. This is also very useful during system wide suspend/resume where we offline all non-boot CPUs during suspend and then bring them back on resume. This commit takes the same idea a step ahead to allow drivers to do light weight tear-down and bring-up during CPU offline and online operations. A new set of callbacks is introduced, online/offline(). online() gets called when the first CPU of an inactive policy is brought up and offline() gets called when all the CPUs of a policy are offlined. The existing init/exit() callback get called on policy creation/destruction. They also get called instead of online/offline() callbacks if the online/offline() callbacks aren't provided. This also moves around some code to get executed only for the new-policy case going forward. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 55 +++++++++++++++++++++++++-------------- include/linux/cpufreq.h | 2 ++ 2 files changed, 38 insertions(+), 19 deletions(-) -- 2.20.1.321.g9e740568ce00 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 96a69c67a545..2b3e9d501f49 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1201,28 +1201,39 @@ static int cpufreq_online(unsigned int cpu) return -ENOMEM; } - cpumask_copy(policy->cpus, cpumask_of(cpu)); + if (!new_policy && cpufreq_driver->online) { + ret = cpufreq_driver->online(policy); + if (ret) { + pr_debug("%s: %d: initialization failed\n", __func__, + __LINE__); + goto out_exit_policy; + } - /* call driver. From then on the cpufreq must be able - * to accept all calls to ->verify and ->setpolicy for this CPU - */ - ret = cpufreq_driver->init(policy); - if (ret) { - pr_debug("initialization failed\n"); - goto out_free_policy; - } + /* Recover policy->cpus using related_cpus */ + cpumask_copy(policy->cpus, policy->related_cpus); + } else { + cpumask_copy(policy->cpus, cpumask_of(cpu)); - ret = cpufreq_table_validate_and_sort(policy); - if (ret) - goto out_exit_policy; + /* + * Call driver. From then on the cpufreq must be able + * to accept all calls to ->verify and ->setpolicy for this CPU. + */ + ret = cpufreq_driver->init(policy); + if (ret) { + pr_debug("%s: %d: initialization failed\n", __func__, + __LINE__); + goto out_free_policy; + } - down_write(&policy->rwsem); + ret = cpufreq_table_validate_and_sort(policy); + if (ret) + goto out_exit_policy; - if (new_policy) { /* related_cpus should at least include policy->cpus. */ cpumask_copy(policy->related_cpus, policy->cpus); } + down_write(&policy->rwsem); /* * affected cpus must always be the one, which are online. We aren't * managing offline cpus here. @@ -1421,11 +1432,12 @@ static int cpufreq_offline(unsigned int cpu) cpufreq_exit_governor(policy); /* - * Perform the ->exit() even during light-weight tear-down, - * since this is a core component, and is essential for the - * subsequent light-weight ->init() to succeed. + * Perform the ->offline() during light-weight tear-down, as + * that allows fast recovery when the CPU comes back. */ - if (cpufreq_driver->exit) { + if (cpufreq_driver->offline) { + cpufreq_driver->offline(policy); + } else if (cpufreq_driver->exit) { cpufreq_driver->exit(policy); policy->freq_table = NULL; } @@ -1454,8 +1466,13 @@ static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) cpumask_clear_cpu(cpu, policy->real_cpus); remove_cpu_dev_symlink(policy, dev); - if (cpumask_empty(policy->real_cpus)) + if (cpumask_empty(policy->real_cpus)) { + /* We did light-weight exit earlier, do full tear down now */ + if (cpufreq_driver->offline) + cpufreq_driver->exit(policy); + cpufreq_policy_free(policy); + } } /** diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 9db074ecbbd7..b160e98076e3 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -325,6 +325,8 @@ struct cpufreq_driver { /* optional */ int (*bios_limit)(int cpu, unsigned int *limit); + int (*online)(struct cpufreq_policy *policy); + int (*offline)(struct cpufreq_policy *policy); int (*exit)(struct cpufreq_policy *policy); void (*stop_cpu)(struct cpufreq_policy *policy); int (*suspend)(struct cpufreq_policy *policy); From patchwork Tue Feb 12 07:06:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 158114 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3504263jaa; Mon, 11 Feb 2019 23:07:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IYaGysYOcxYKWeulX6pvUDlpSf7lrnXGt1jtf4chzTlelBZrzXZyAJpRhcum2qZlBKGbQNk X-Received: by 2002:a63:2ccd:: with SMTP id s196mr2326627pgs.194.1549955224085; Mon, 11 Feb 2019 23:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549955224; cv=none; d=google.com; s=arc-20160816; b=yMHlHywB3JRNXtrrrQNBzFLe+sJv68pCxLMugVS9lHb3569meJ3yMJGSxpDFHWyVlF NEtryEjyqzQbV3vchr+/umqau1D7Yr/8pVqIKPLpWwV47FEGM7WpTAIDho7E2hrC39FH TmUdX4uyXbJWpMp4ZGsXdNDwoLfKjUC696cTqnTi8TKJBaidwr/xELXW0m7NHMkQlOke FjDXTAviGomGxumX+2YjBtR3ENIQ2lSwmvWtFhPHj8bwkW82okjubFY4qiBsROuhx3Fl 3PPrl2QMsE/1/b9oB+TUWv6m1M+VjOhnGLIJHYHv/X2QP+O0pJgcfKa/7NvUg+cfFwpY xR9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bl67EUE/XY/6X5G+dYl3utZYVkMZx8TlxGZKFfW5yh8=; b=hJdinGnvLlgJzK9JoRx0Thc8rkeLUylPX10B3mN06OO471iHLkt1s2XeiVO1hg9Q+j vIeVFILVG37p4YIED+SlOrj/1j0lHbSKdwOt8qAAeTPAjYKMNGJw+eaEMfmQtBcv4Z25 /ZLnz1tT6hHJTAhDm6n0ywAdVsN9gsQd4yaJarA38eWVe9SW9+YDfQ/kcQhiXMGg3xfQ MlZXv0SGTq2DTu05BZIcgHF2uA8qXZss0m1BO6IbQt5GsJ2mAfphmRjf67y/P1/j6ITA /PMt5OE4h/opSoZVdZGukV4yI6jxq0sYH5iAX26dehecGLikWryw5cf3gW2DkJeCJ13c gOQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y4HZ6tlh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 202si8705335pfa.136.2019.02.11.23.07.03; Mon, 11 Feb 2019 23:07:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y4HZ6tlh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727830AbfBLHHC (ORCPT + 31 others); Tue, 12 Feb 2019 02:07:02 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37158 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726238AbfBLHHA (ORCPT ); Tue, 12 Feb 2019 02:07:00 -0500 Received: by mail-pl1-f194.google.com with SMTP id b5so861078plr.4 for ; Mon, 11 Feb 2019 23:07:00 -0800 (PST) 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=Bl67EUE/XY/6X5G+dYl3utZYVkMZx8TlxGZKFfW5yh8=; b=Y4HZ6tlhiVMul1p4bXQfywgRLmphH1w3FXiaYP7OuYI9IiNUy0KC4Azirsq/dLEPBU 9Bkgi94cwcVIyJXh1y9+r7FTWLH2G7XmS8JnfQoAsoK+5JneSTVDzJS7DE4w/TLLQ/dz /loClwAiQP7aP+8zh4qnhFgVd4lmLDDDgp0wY/bYiPU7OObxEHei+WjKwYXJtmw2ru61 PNSzkWkB9eLGIs1We9Qs4Y0DwhZyb3vwwnCM5bOsbk0IhTFTEqmVwrX+5QgqCZg5kPMj UfrJS7HZYrtOfL4EcpVm2YaXIx7L6ci2y9tngggX0EFtwUehIMiyXMToCVcmZaI5WeE9 2Nlg== 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=Bl67EUE/XY/6X5G+dYl3utZYVkMZx8TlxGZKFfW5yh8=; b=SqtS/4QhtM8XL5+qghD5SqMYV8fTSmUSJd9NFcT9OGOTtWqkG+Jl5y8V6p8mE+j6pl OVJbH46W0UHgWnWA8Lw/fgUvK70hvYycAzonZHrHRvgjhR5ZCoSU7vniL1GTu4q5sXGx +6uCnBcAbjLjcVEvTyJWk4XX/LlpCY5935BcyKiY2uScnsPsn08mIwN9wL/m3rGC42/x usKuhAbKyK/ySLbjVVnDgY6vyzpLCzmiOWQjT1ANyRmWlXCEyPhcbiOOat22/9KwGjM+ CUGs9EChf4GEbzNfMa5GCOi8OAG3kbLAnIQHhR4xl6US9tjawmDX8Jz9ahLasYwDlKEy yHUQ== X-Gm-Message-State: AHQUAuZ9wUEbXBp3C4Pyu9r1/ES7XPrVFk9Sn00c8DBgjTy3z/GfAk7P /ZWrhbeYYG7HcFVmp20cjr3huA== X-Received: by 2002:a17:902:2a69:: with SMTP id i96mr2562023plb.58.1549955219631; Mon, 11 Feb 2019 23:06:59 -0800 (PST) Received: from localhost ([122.172.102.63]) by smtp.gmail.com with ESMTPSA id v13sm16233278pff.20.2019.02.11.23.06.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 23:06:58 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Sudeep Holla , Marek Szyprowski , linux-kernel@vger.kernel.org Subject: [PATCH V2 2/2] cpufreq: dt: Implement online/offline() callbacks Date: Tue, 12 Feb 2019 12:36:47 +0530 Message-Id: <8030961ef762018fc286e4d3d3a010638e900e53.1549955027.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce00 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement the light-weight tear down and bring up helpers to reduce the amount of work to do on CPU offline/online operation. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq-dt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.20.1.321.g9e740568ce00 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 7ba392911cd0..1aefaa1b0ca2 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -295,6 +295,21 @@ static int cpufreq_init(struct cpufreq_policy *policy) return ret; } +static int cpufreq_online(struct cpufreq_policy *policy) +{ + /* We did light-weight tear down earlier, nothing to do here */ + return 0; +} + +static int cpufreq_offline(struct cpufreq_policy *policy) +{ + /* + * Preserve policy->driver_data and don't free resources on light-weight + * tear down. + */ + return 0; +} + static int cpufreq_exit(struct cpufreq_policy *policy) { struct private_data *priv = policy->driver_data; @@ -319,6 +334,8 @@ static struct cpufreq_driver dt_cpufreq_driver = { .get = cpufreq_generic_get, .init = cpufreq_init, .exit = cpufreq_exit, + .online = cpufreq_online, + .offline = cpufreq_offline, .name = "cpufreq-dt", .attr = cpufreq_dt_attr, .suspend = cpufreq_generic_suspend,