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: 10807409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FC7B14E1 for ; Tue, 12 Feb 2019 07:07:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F6812AB0E for ; Tue, 12 Feb 2019 07:07:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22E562AB1E; Tue, 12 Feb 2019 07:07:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C042AB0E for ; Tue, 12 Feb 2019 07:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727677AbfBLHG6 (ORCPT ); Tue, 12 Feb 2019 02:06:58 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37155 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727533AbfBLHG5 (ORCPT ); Tue, 12 Feb 2019 02:06:57 -0500 Received: by mail-pl1-f194.google.com with SMTP id b5so861010plr.4 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=pIk6G2pOtcz11nU0yNxYF8KUAXvsLOpIyxQi07qg2qCxbxBNb8DPe5ciyHb0RcvWPX TLBRxam358Ho/X68QjEZIpANGIcXF79VrjPENRBZ3oZsNyaS3GMolEURrtTx/4RVyhpW QupFde2cmC3aono1KlBUa0nX5JlfMRCP3BKVnLXFvRKvHhmDaCWReR+LA3lx7io3mwqn PBrQd/SZrdQ39Y0a3xl4sL/rfTVPRAqrOOcqFkklqkLnGoZxk8VLLaaj+mp5jlF1Loz3 8xaIKVk3LNkH6N8m1ct73Pa53utfSUk6Ry/Ue7wJfWH+B9O3TEIZmDYdxum/+jpq71/n mi2w== X-Gm-Message-State: AHQUAubRjggNeBHEBBU+o18O9EkgKVumXRqTVcsfAMQugty1T8E2wIT+ JZcFtP894zmOKhUyTfsxt79EYA== X-Google-Smtp-Source: AHgI3IYt3BhEobnqyYIdZ63zzhIoEgHFDH1kABML2CYDbVInZYnmGBO2FC8BYQ7aGn7EKiuWAJ0vaA== 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);