From patchwork Tue Jan 27 08:36:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 43820 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CBE8A2409D for ; Tue, 27 Jan 2015 08:37:06 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id y19sf6815134wgg.2 for ; Tue, 27 Jan 2015 00:37:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=1o1v6Pczjg4K9YsamnChRF7UAFtmJFu/V8xNRMoAmG8=; b=G/ZCkJ3KIz7/qgFI9MVqGR0J1Yx/CXpPTL6sBo9ky/hU5QkTNO7CDZTXf8gnUhmLfU ofqedGBeT3jWM4noiCVuAqFVUBoH7pnyK9aFZP0qX6DGIsFyWGWuGbyGvRk74UuvmyfV sBst66dK5iJCrQM1U5FKrZNLXAHft7MWV1bFkVXYZTrlwpiUUhokKXh/qCEdiwsuK1a2 KMXAteGeSxZDep5TaxNkrCuXLPmlsyf0qX6IHyvD0TF//3oMaL5ehLY4mFWMvL3TLso7 AjhdYsfK3JhVVsraXLoz0Ny/AnyRqRLMU1JiuS8GdI1BhqotPPfr37P1K00VZE1KD0gO 87Xg== X-Gm-Message-State: ALoCoQlL1YeNHzhRfg8moshWL3DtphV0twPKAZ8M9J5Iydx5TQLzDJHl6dK1ZQvgT2lbk6pYpn/8 X-Received: by 10.194.86.1 with SMTP id l1mr37783wjz.0.1422347826149; Tue, 27 Jan 2015 00:37:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.226 with SMTP id m2ls1837laa.82.gmail; Tue, 27 Jan 2015 00:37:05 -0800 (PST) X-Received: by 10.152.28.37 with SMTP id y5mr64979lag.55.1422347825749; Tue, 27 Jan 2015 00:37:05 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id 8si529882lam.85.2015.01.27.00.37.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:37:05 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id 10so11810471lbg.10 for ; Tue, 27 Jan 2015 00:37:05 -0800 (PST) X-Received: by 10.152.20.169 with SMTP id o9mr174920lae.50.1422347825628; Tue, 27 Jan 2015 00:37:05 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1025451lbj; Tue, 27 Jan 2015 00:37:04 -0800 (PST) X-Received: by 10.68.68.145 with SMTP id w17mr214830pbt.82.1422347819597; Tue, 27 Jan 2015 00:36:59 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id vr2si685254pbc.134.2015.01.27.00.36.58; Tue, 27 Jan 2015 00:36:59 -0800 (PST) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753188AbbA0Ig6 (ORCPT + 11 others); Tue, 27 Jan 2015 03:36:58 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:40427 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753886AbbA0Ig4 (ORCPT ); Tue, 27 Jan 2015 03:36:56 -0500 Received: by mail-pa0-f42.google.com with SMTP id bj1so17200657pad.1 for ; Tue, 27 Jan 2015 00:36:56 -0800 (PST) X-Received: by 10.70.36.204 with SMTP id s12mr72745pdj.3.1422347816231; Tue, 27 Jan 2015 00:36:56 -0800 (PST) Received: from localhost ([122.178.198.250]) by mx.google.com with ESMTPSA id gr7sm786286pbc.75.2015.01.27.00.36.54 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 27 Jan 2015 00:36:55 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org, Viresh Kumar Subject: [PATCH 04/18] cpufreq: Manage fallback policies in a list Date: Tue, 27 Jan 2015 14:06:10 +0530 Message-Id: <43d728016b775d1b0fc02c981eb0520ac08297f5.1422346933.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.3.0.rc0.44.ga94655d In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Policies manage a group of CPUs and tracking them on per-cpu basis isn't the best approach for sure. The obvious loss is the amount of memory consumed for keeping a per-cpu copy of the same pointer. But the bigger problem is managing such a data structure as we need to update it for all policy->cpus. To make it simple, lets manage fallback CPUs in a list rather than a per-cpu variable. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 51 +++++++++++++++++++++++++++-------------------- include/linux/cpufreq.h | 5 ++++- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index cf8ce523074f..f253cf45f910 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -37,6 +37,11 @@ static LIST_HEAD(cpufreq_policy_list); #define for_each_policy(__policy) \ list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) +/* Iterate over offline CPUs policies */ +static LIST_HEAD(cpufreq_fallback_list); +#define for_each_fallback_policy(__policy) \ + list_for_each_entry(__policy, &cpufreq_fallback_list, fallback_list) + /* Iterate over governors */ static LIST_HEAD(cpufreq_governor_list); #define for_each_governor(__governor) \ @@ -49,7 +54,6 @@ static LIST_HEAD(cpufreq_governor_list); */ static struct cpufreq_driver *cpufreq_driver; static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); -static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback); static DEFINE_RWLOCK(cpufreq_driver_lock); DEFINE_MUTEX(cpufreq_governor_lock); @@ -999,13 +1003,16 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu) { - struct cpufreq_policy *policy; + struct cpufreq_policy *policy = NULL, *temp; unsigned long flags; read_lock_irqsave(&cpufreq_driver_lock, flags); - - policy = per_cpu(cpufreq_cpu_data_fallback, cpu); - + for_each_fallback_policy(temp) { + if (cpumask_test_cpu(cpu, temp->related_cpus)) { + policy = temp; + break; + } + } read_unlock_irqrestore(&cpufreq_driver_lock, flags); if (policy) @@ -1029,6 +1036,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(void) goto err_free_cpumask; INIT_LIST_HEAD(&policy->policy_list); + INIT_LIST_HEAD(&policy->fallback_list); init_rwsem(&policy->rwsem); spin_lock_init(&policy->transition_lock); init_waitqueue_head(&policy->transition_wait); @@ -1142,6 +1150,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) policy = cpufreq_policy_alloc(); if (!policy) goto nomem_out; + } else { + /* Don't need fallback list anymore */ + write_lock_irqsave(&cpufreq_driver_lock, flags); + list_del(&policy->fallback_list); + write_unlock_irqrestore(&cpufreq_driver_lock, flags); } /* @@ -1296,11 +1309,8 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) if (cpufreq_driver->exit) cpufreq_driver->exit(policy); err_set_policy_cpu: - if (recover_policy) { - /* Do not leave stale fallback data behind. */ - per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL; + if (recover_policy) cpufreq_policy_put_kobj(policy); - } cpufreq_policy_free(policy); nomem_out: @@ -1333,21 +1343,22 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, pr_debug("%s: unregistering CPU %u\n", __func__, cpu); - write_lock_irqsave(&cpufreq_driver_lock, flags); - policy = per_cpu(cpufreq_cpu_data, cpu); - - /* Save the policy somewhere when doing a light-weight tear-down */ - if (cpufreq_suspended) - per_cpu(cpufreq_cpu_data_fallback, cpu) = policy; - - write_unlock_irqrestore(&cpufreq_driver_lock, flags); - if (!policy) { pr_debug("%s: No cpu_data found\n", __func__); return -EINVAL; } + down_read(&policy->rwsem); + cpus = cpumask_weight(policy->cpus); + up_read(&policy->rwsem); + + /* Save the policy when doing a light-weight tear-down of last cpu */ + write_lock_irqsave(&cpufreq_driver_lock, flags); + if (cpufreq_suspended && cpus == 1) + list_add(&policy->fallback_list, &cpufreq_fallback_list); + write_unlock_irqrestore(&cpufreq_driver_lock, flags); + if (has_target()) { ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); if (ret) { @@ -1359,10 +1370,6 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, policy->governor->name, CPUFREQ_NAME_LEN); } - down_read(&policy->rwsem); - cpus = cpumask_weight(policy->cpus); - up_read(&policy->rwsem); - if (cpu != policy->cpu) { sysfs_remove_link(&dev->kobj, "cpufreq"); } else if (cpus > 1) { diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 2ee4888c1f47..df6af4cfa26a 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -87,7 +87,10 @@ struct cpufreq_policy { struct cpufreq_real_policy user_policy; struct cpufreq_frequency_table *freq_table; - struct list_head policy_list; + /* Internal lists */ + struct list_head policy_list; /* policies of online CPUs */ + struct list_head fallback_list; /* policies of offline CPUs */ + struct kobject kobj; struct completion kobj_unregister;