From patchwork Tue Feb 12 11:06:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 158151 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3695793jaa; Tue, 12 Feb 2019 03:06:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbLmRM0M6HWUcMbl7l/4Qlc+WTPokz97YO1mJLY8GoVF8FvOSXOCyZXGJ5+waEKqE72SecB X-Received: by 2002:aa7:9102:: with SMTP id 2mr3335759pfh.179.1549969573768; Tue, 12 Feb 2019 03:06:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549969573; cv=none; d=google.com; s=arc-20160816; b=b/oyRaxo+88soj3z9J6g4xcudABVb8tb37Lx/uk3Q+h5c+2jnhU41Z3JZkl0xX5ayJ C66IgfAnapy0KTmAazl76oo89FmBso83rCeMdRS+U3nykidmSNNUXB65TrkSgqYoEEMw PnIJaoslC97iqY3IWiTvDrt1vyEoqXX8pg3ZB8dDDdGwxJAVV8x+M2VzbF3RH4pQxaz5 r9kbCyo4Q5RioTffTyR6xpcK4gDXaWtCbvSsSZPjr2/ft6VhNrj7/Uh9vjnMasurFBq8 +jUArT7uaICaAn87d4NgKWB3vYVjlNfNDpkpGe4Z86KMBG8U5C0W6xYZkJA7sCKG3WRb dRIQ== 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=eInlvY5FKDw6XUYNat+PshXZTd4NDkDRgZK+3JHQYNc=; b=XenuANCTk5bm4wAgRguTulU7v9d2N4zrtO5cG+NLHhiDCs4ALLJPfMt+pJB+3uhKdi OAxtn79pscAge4kPStfJ3QLjOoD1qLZ4NnrG9IyW51FS6rCGV8X5sZGlOoR8KHEXsyc7 wDgeMlaPq4GFCIiyJWcxWXgp25qGy73L8LJoZwDDmV8os/m0Rtp7xhGdLrfk1hElfblp 1q9CoH7G7n+2qwBK8Cnu1bmAW6daxJe3VwbWkwATGECWgw0GRJ5tHtLFvgdaLxYbszbu B81NqoiTs3OLIvhCpwLNife3hCyXBb3V/JESarm3RoNDsRK+8ydzS4HmHvLGrpMjzUVc KBMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X7zr7M1m; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 g21si12805846pfg.49.2019.02.12.03.06.13; Tue, 12 Feb 2019 03:06:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=X7zr7M1m; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1728864AbfBLLGN (ORCPT + 11 others); Tue, 12 Feb 2019 06:06:13 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45894 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728859AbfBLLGM (ORCPT ); Tue, 12 Feb 2019 06:06:12 -0500 Received: by mail-pf1-f195.google.com with SMTP id j3so1115671pfi.12 for ; Tue, 12 Feb 2019 03:06:11 -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=eInlvY5FKDw6XUYNat+PshXZTd4NDkDRgZK+3JHQYNc=; b=X7zr7M1mBBhPgZRnWEr8FDlVXEw2I+jreFQ6+3EzulF10/Y4ubePPASDVHZXEZmQGI VvWNDiJMM3PXmULr9CmCYhGg5oRcRVuVIgpdqLag0wnm4jguulaJIoM3/dXvVWeISycZ lC0uwqV7TkVRvVEzbitBhyqa6QSdCwmyr1zJitLc4joWCdlqJGBuWfFSE9R4W7GXPqAq pXZ8aKLOXpMpXKGnLCBI3b5W6fPfKQ8dhMms9Vw/xX9vr7oU+6JFh9vYpmXF1HY0m1go Kxm8GiFr9tAW8VewcZ1SzTWubsRGC9oGG4bmCRqSjCsv+zgKOfes9H2fiRDHldWSiDve iAKA== 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=eInlvY5FKDw6XUYNat+PshXZTd4NDkDRgZK+3JHQYNc=; b=aJTK9sEzH4NtjIc0CLtoSkzc9hTks77GOxfWj1JGpsIditi7G+IZzZHYXPcGUZhrS7 BF2kTA9XHdtdxq7e9PeIGD3fEaFEWwFs7DCciEciFOzJZS3tQOUPnbw/8bRr6MD+iNDz Kza1YHimJqN7wlNKIs4qsf2O76A6eVEKaDIuwm2X+fxIMDQKCDr4UxK8zsjUh2BiJjDj cKl6FtDpNe5eTmQ71bYvHiBcZtUNrFl7WcJtuYj3xManxWyoeHm7W3B4xMCs8dZ0vnnp Y696rSnUXLSW47M3pBRxOvme1/dQKqaQVP0G/UyRdgXBqTfvzl+mSyjq2CWgxCG00Iuu rx2A== X-Gm-Message-State: AHQUAuaI8q/urh17LJeYAjXMHAfqIQG/GRfMxZvXTSJlY+0hBZd/bdG2 sQmMhcqS9VNLddD9oABMHQYCtQ== X-Received: by 2002:a63:481f:: with SMTP id v31mr3127660pga.29.1549969571419; Tue, 12 Feb 2019 03:06:11 -0800 (PST) Received: from localhost ([122.172.102.63]) by smtp.gmail.com with ESMTPSA id c7sm24160206pfa.24.2019.02.12.03.06.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 03:06:10 -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 V4 1/2] cpufreq: Allow light-weight tear down and bring up of CPUs Date: Tue, 12 Feb 2019 16:36:04 +0530 Message-Id: <7fcdface56ccc5df0e50738253eb3e696b2f8980.1549969209.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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 --- V3->V4: - Use != instead of ^ drivers/cpufreq/cpufreq.c | 58 +++++++++++++++++++++++++-------------- include/linux/cpufreq.h | 2 ++ 2 files changed, 40 insertions(+), 20 deletions(-) -- 2.20.1.321.g9e740568ce00 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 96a69c67a545..55e9795801a4 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); + } } /** @@ -2488,7 +2505,8 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) driver_data->target) || (driver_data->setpolicy && (driver_data->target_index || driver_data->target)) || - (!!driver_data->get_intermediate != !!driver_data->target_intermediate)) + (!!driver_data->get_intermediate != !!driver_data->target_intermediate) || + (!driver_data->online != !driver_data->offline)) return -EINVAL; pr_debug("trying to register driver %s\n", driver_data->name); 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);