From patchwork Thu Jul 23 08:13:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 51385 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id D060622A9E for ; Thu, 23 Jul 2015 08:16:05 +0000 (UTC) Received: by lbcjj5 with SMTP id jj5sf30504778lbc.1 for ; Thu, 23 Jul 2015 01:16:04 -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=b7DGE8FxP/d1KGHvi/Pc96Kxfe+8oYmNys2h1SW4Z7U=; b=mdSBgmccRXu49DBcTkQSMACQ5Jeim48Cnr45pe3ggkqiZhy0kIWZFn0RyUL+sp5muv Ol5KQS0I/Q3HUtTD8FQi6OefFDh9Jxr/ipu7PSN6h+JSigDIN1BwM+8AwxmMBWG9WFeI 82Iq8pSP4RZL/AvKbwzv1qkY86jLBmuPzJI5Yq5+kRgTGqyzte/krbGgRw1seXAARdld 3w+KL8W3Lu8saYAZRx93DVzH+31YEE+r5ct8EoCOHN/P/5Vj22wj4r5q9lxDZQUdnIct NA64I0qa7PypfWVdvUA5wGV1U4CT24ob35H7VE+txbgHhdMY5DWweexSgmXzNOHrEtb9 vNSQ== X-Gm-Message-State: ALoCoQnO6M5Jx5JRoTj0VpJI3nlOMMYtc2q2jCnegoDfoXB0Kc7/JNEtu6uZ507QAsge4RLfCPpI X-Received: by 10.112.215.67 with SMTP id og3mr3163561lbc.8.1437639364819; Thu, 23 Jul 2015 01:16:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.5.9 with SMTP id ci9ls207665lad.69.gmail; Thu, 23 Jul 2015 01:16:04 -0700 (PDT) X-Received: by 10.152.4.163 with SMTP id l3mr6509260lal.35.1437639364598; Thu, 23 Jul 2015 01:16:04 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id o10si3445622laj.148.2015.07.23.01.16.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Jul 2015 01:16:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by lagw2 with SMTP id w2so152616002lag.3 for ; Thu, 23 Jul 2015 01:16:04 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr6385430lbb.36.1437639364243; Thu, 23 Jul 2015 01:16:04 -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.112.7.198 with SMTP id l6csp400590lba; Thu, 23 Jul 2015 01:16:03 -0700 (PDT) X-Received: by 10.107.17.13 with SMTP id z13mr11139832ioi.97.1437639362627; Thu, 23 Jul 2015 01:16:02 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kc7si10140465pad.145.2015.07.23.01.16.01; Thu, 23 Jul 2015 01:16:02 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752424AbbGWIPq (ORCPT + 12 others); Thu, 23 Jul 2015 04:15:46 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:36594 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbbGWINf (ORCPT ); Thu, 23 Jul 2015 04:13:35 -0400 Received: by pdjr16 with SMTP id r16so156025029pdj.3 for ; Thu, 23 Jul 2015 01:13:34 -0700 (PDT) X-Received: by 10.70.136.129 with SMTP id qa1mr15613864pdb.81.1437639214821; Thu, 23 Jul 2015 01:13:34 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id cz1sm7326798pdb.44.2015.07.23.01.13.33 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 23 Jul 2015 01:13:34 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux@arm.linux.org.uk, Viresh Kumar , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/3] cpufreq: Create links for offline CPUs that got added earlier Date: Thu, 23 Jul 2015 13:43:19 +0530 Message-Id: <7e3b8b132812be7d8b80b065517d115a121b3c48.1437639021.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: <20150723060938.GD5322@linux> 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.215.45 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: , If subsys callback ->add_dev() is called for an offline CPU, before its policy is allocated, we will miss adding its sysfs symlink. Fix this by tracking such CPUs in a separate mask. Fixes: 9b07109f06a1 ("cpufreq: Fix double addition of sysfs links") Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 74 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 84504ae3fb38..d01cad993fa7 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -31,6 +31,12 @@ #include #include +/* + * CPUs that were offline when a request to allocate policy was issued, symlinks + * for them should be created once the policy is available for them. + */ +cpumask_t linked_cpus_pending; + static LIST_HEAD(cpufreq_policy_list); static inline bool policy_is_inactive(struct cpufreq_policy *policy) @@ -938,6 +944,47 @@ void cpufreq_sysfs_remove_file(const struct attribute *attr) } EXPORT_SYMBOL(cpufreq_sysfs_remove_file); +static int cpufreq_add_symlink(struct cpufreq_policy *policy, + struct device *dev) +{ + int ret, cpu = dev->id; + + dev_dbg(dev, "%s: Adding symlink for CPU: %u\n", __func__, cpu); + ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); + if (ret) { + dev_err(dev, "%s: Failed to create link (%d)\n", __func__, ret); + return ret; + } + + /* Track CPUs for which sysfs links are created */ + cpumask_set_cpu(cpu, policy->linked_cpus); + return 0; +} + +/* + * Create symlinks for CPUs which are already added via subsys callbacks (and + * were offline then), before the policy was created. + */ +static int cpufreq_add_pending_symlinks(struct cpufreq_policy *policy) +{ + struct cpumask mask; + int cpu, ret; + + cpumask_and(&mask, policy->related_cpus, &linked_cpus_pending); + + if (cpumask_empty(&mask)) + return 0; + + for_each_cpu(cpu, &mask) { + ret = cpufreq_add_symlink(policy, get_cpu_device(cpu)); + if (ret) + return ret; + cpumask_clear_cpu(cpu, &linked_cpus_pending); + } + + return 0; +} + static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, struct device *dev) { @@ -968,7 +1015,7 @@ static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, return ret; } - return 0; + return cpufreq_add_pending_symlinks(policy); } static int cpufreq_init_policy(struct cpufreq_policy *policy) @@ -1170,24 +1217,21 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) /* sysfs links are only created on subsys callback */ if (sif && policy) { - pr_debug("%s: Adding symlink for CPU: %u\n", __func__, cpu); - ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); - if (ret) { - dev_err(dev, "%s: Failed to create link (%d)\n", - __func__, ret); + ret = cpufreq_add_symlink(policy, dev); + if (ret) return ret; - } - - /* Track CPUs for which sysfs links are created */ - cpumask_set_cpu(cpu, policy->linked_cpus); } /* * A hotplug notifier will follow and we will take care of rest * of the initialization then. */ - if (cpu_is_offline(cpu)) + if (cpu_is_offline(cpu)) { + /* symlink should be added for this CPU later */ + if (!policy) + cpumask_set_cpu(cpu, &linked_cpus_pending); return 0; + } /* Check if this CPU already has a policy to manage it */ if (policy && !policy_is_inactive(policy)) { @@ -1440,8 +1484,10 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); int ret; - if (!policy) + if (!policy) { + cpumask_clear_cpu(cpu, &linked_cpus_pending); return 0; + } if (cpu_online(cpu)) { ret = __cpufreq_remove_dev_prepare(dev, sif); @@ -2533,10 +2579,14 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver) /* Protect against concurrent cpu hotplug */ get_online_cpus(); + subsys_interface_unregister(&cpufreq_interface); if (cpufreq_boost_supported()) cpufreq_sysfs_remove_file(&boost.attr); + if (WARN_ON(!cpumask_empty(&linked_cpus_pending))) + cpumask_clear(&linked_cpus_pending); + unregister_hotcpu_notifier(&cpufreq_cpu_notifier); write_lock_irqsave(&cpufreq_driver_lock, flags);