From patchwork Thu Jul 17 05:18:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 33771 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3B6AA201F1 for ; Thu, 17 Jul 2014 05:20:17 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf12697734pdb.5 for ; Wed, 16 Jul 2014 22:20:16 -0700 (PDT) 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=w1diKdzeoWyTK6YgukgTltUy91LJZNTzatSXnuSx40Q=; b=Ki/ceoNQaAPgZYukxqmRg98mrNHfyj7ItZJigogws/f341NzaYDCx/pluEhpleKpyI RMGvD3EfDVfpY6m0IlINS2XpC28GNL0ycxBe7M38c6zMT+rZvEjP/yuvA2npsJHyyGVZ TKjCD7IjrBZvkyyFUEnjTw379RbCKP86/M894Oyf24bv6fAWW5LMhsdrqF2CsyL8J3Ha Y9reuEcbz+JlJJ5xhFTsiGba+OkIVdqqRR24OZXgdOvLO9jlmB1lsK5CwjMhW7LPrgNx 7dMHb10xbw5bTfX4yMSVL1cciLVxB4cwGVtYXDElK3PDvdW1ksLWRhr4pHtekPGF3v3o sXVQ== X-Gm-Message-State: ALoCoQn/6H8ufnV66iy5nyTv+qYMzYsEyzESoh+t9IhxCcJMzAyWwaykuX04OZmDZUl7TcUNDvZb X-Received: by 10.66.182.170 with SMTP id ef10mr17613681pac.0.1405574416564; Wed, 16 Jul 2014 22:20:16 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.210 with SMTP id 76ls602324qgp.33.gmail; Wed, 16 Jul 2014 22:20:16 -0700 (PDT) X-Received: by 10.52.185.72 with SMTP id fa8mr5219647vdc.4.1405574416454; Wed, 16 Jul 2014 22:20:16 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id ve5si1330155vcb.57.2014.07.16.22.20.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 16 Jul 2014 22:20:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id hy10so3544979vcb.4 for ; Wed, 16 Jul 2014 22:20:16 -0700 (PDT) X-Received: by 10.220.15.8 with SMTP id i8mr14393040vca.45.1405574416290; Wed, 16 Jul 2014 22:20:16 -0700 (PDT) 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.221.37.5 with SMTP id tc5csp5980vcb; Wed, 16 Jul 2014 22:20:15 -0700 (PDT) X-Received: by 10.69.26.68 with SMTP id iw4mr14770196pbd.137.1405574415382; Wed, 16 Jul 2014 22:20:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id mu3si623908pdb.77.2014.07.16.22.20.14; Wed, 16 Jul 2014 22:20:14 -0700 (PDT) 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 S1753261AbaGQFUN (ORCPT + 15 others); Thu, 17 Jul 2014 01:20:13 -0400 Received: from mail-qg0-f53.google.com ([209.85.192.53]:55364 "EHLO mail-qg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752635AbaGQFUN (ORCPT ); Thu, 17 Jul 2014 01:20:13 -0400 Received: by mail-qg0-f53.google.com with SMTP id q107so1604417qgd.12 for ; Wed, 16 Jul 2014 22:20:12 -0700 (PDT) X-Received: by 10.229.178.202 with SMTP id bn10mr54269918qcb.6.1405574412209; Wed, 16 Jul 2014 22:20:12 -0700 (PDT) Received: from localhost (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id q4sm2751087qat.15.2014.07.16.22.20.08 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 16 Jul 2014 22:20:11 -0700 (PDT) From: Viresh Kumar To: rjw@rjwysocki.net Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, arvind.chauhan@arm.com, srivatsa@mit.edu, skannan@codeaurora.org, ybu@qti.qualcomm.com, Viresh Kumar Subject: [PATCH V1 Resend 4/4] cpufreq: move policy kobj from update_policy_cpu() Date: Thu, 17 Jul 2014 10:48:28 +0530 Message-Id: X-Mailer: git-send-email 2.0.0.rc2 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.220.173 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: , We are calling kobject_move() from two separate places currently and both these places share another routine update_policy_cpu() which is handling everything around updating policy->cpu. Moving ownership of policy->kobj also lies under the role of update_policy_cpu() routine and must handled from there. So, Lets move kobject_move() to update_policy_cpu() and get rid of cpufreq_nominate_new_policy_cpu() as it doesn't have anything significant left. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 71 ++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ec25ca6..d9fdedd 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1076,10 +1076,20 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) kfree(policy); } -static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) +static int update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu, + struct device *cpu_dev) { + int ret; + if (WARN_ON(cpu == policy->cpu)) - return; + return 0; + + /* Move kobject to the new policy->cpu */ + ret = kobject_move(&policy->kobj, &cpu_dev->kobj); + if (ret) { + pr_err("%s: Failed to move kobj: %d\n", __func__, ret); + return ret; + } down_write(&policy->rwsem); @@ -1090,6 +1100,8 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) blocking_notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_UPDATE_POLICY_CPU, policy); + + return 0; } static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) @@ -1153,12 +1165,10 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) * the creation of a brand new one. So we need to perform this update * by invoking update_policy_cpu(). */ - if (recover_policy && cpu != policy->cpu) { - update_policy_cpu(policy, cpu); - WARN_ON(kobject_move(&policy->kobj, &dev->kobj)); - } else { + if (recover_policy && cpu != policy->cpu) + WARN_ON(update_policy_cpu(policy, cpu, dev)); + else policy->cpu = cpu; - } cpumask_copy(policy->cpus, cpumask_of(cpu)); @@ -1309,35 +1319,11 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) return __cpufreq_add_dev(dev, sif); } -static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, - unsigned int old_cpu) -{ - struct device *cpu_dev; - int ret; - - /* first sibling now owns the new sysfs dir */ - cpu_dev = get_cpu_device(cpumask_any_but(policy->cpus, old_cpu)); - - sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); - ret = kobject_move(&policy->kobj, &cpu_dev->kobj); - if (ret) { - pr_err("%s: Failed to move kobj: %d\n", __func__, ret); - - if (sysfs_create_link(&cpu_dev->kobj, &policy->kobj, "cpufreq")) - pr_err("%s: Failed to restore kobj link to cpu:%d\n", - __func__, cpu_dev->id); - - return ret; - } - - return cpu_dev->id; -} - static int __cpufreq_remove_dev_prepare(struct device *dev, struct subsys_interface *sif) { unsigned int cpu = dev->id, cpus; - int new_cpu, ret; + int ret; unsigned long flags; struct cpufreq_policy *policy; @@ -1377,14 +1363,23 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, if (cpu != policy->cpu) { sysfs_remove_link(&dev->kobj, "cpufreq"); } else if (cpus > 1) { - new_cpu = cpufreq_nominate_new_policy_cpu(policy, cpu); - if (new_cpu >= 0) { - update_policy_cpu(policy, new_cpu); + /* Nominate new CPU */ + int new_cpu = cpumask_any_but(policy->cpus, cpu); + struct device *cpu_dev = get_cpu_device(new_cpu); - if (!cpufreq_suspended) - pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", - __func__, new_cpu, cpu); + sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); + ret = update_policy_cpu(policy, new_cpu, cpu_dev); + if (ret) { + if (sysfs_create_link(&cpu_dev->kobj, &policy->kobj, + "cpufreq")) + pr_err("%s: Failed to restore kobj link to cpu:%d\n", + __func__, cpu_dev->id); + return ret; } + + if (!cpufreq_suspended) + pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", + __func__, new_cpu, cpu); } else if (cpufreq_driver->stop_cpu && cpufreq_driver->setpolicy) { cpufreq_driver->stop_cpu(policy); }