From patchwork Tue Oct 30 16:48:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo Zhang X-Patchwork-Id: 1671321 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id EB3EF3FD2B for ; Tue, 30 Oct 2012 16:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964957Ab2J3Qu5 (ORCPT ); Tue, 30 Oct 2012 12:50:57 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:55905 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964929Ab2J3QuB (ORCPT ); Tue, 30 Oct 2012 12:50:01 -0400 Received: by mail-bk0-f46.google.com with SMTP id jk13so281014bkc.19 for ; Tue, 30 Oct 2012 09:50:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=TVssZPxAjlJZqWSqPC4rGAb2nNSc9mgEioPGuo+amD0=; b=caumd76DMqbPZJO/QEq4SAaZ1kg6B78eZTPGxCRCegsmP3+P0hJNeWqTQkjJz4Cp2m GqaTO1BShgPVsX9BbGu1t+3hZHKb+BTal8uEycQEHV+TfCuK8hKFzJMInqiasiOm/Pa4 GQzAUT35IsBGbL0teGGyQg28ezqBxjpdyoRQLFsQLeCoix8ebFBks9Cl/lPek9EkSlYe 56DNcWmkrwW9QByE+t9vYJQlUYKNpv53WCUAfYRqkYw53RNv7hP+O2YDGCi+v1W0UDns JnnieX1a+itQIeNtgpjAGr5BZJHYLUeYOL/LHJvDanA2KZJShUhUCvcbVefPFQUZchoy Q5/g== Received: by 10.204.5.204 with SMTP id 12mr10612805bkw.89.1351615800365; Tue, 30 Oct 2012 09:50:00 -0700 (PDT) Received: from localhost.localdomain ([91.224.175.20]) by mx.google.com with ESMTPS id v14sm1673891bkv.10.2012.10.30.09.49.58 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Oct 2012 09:49:59 -0700 (PDT) From: "hongbo.zhang" To: linaro-dev@lists.linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rui.zhang@intel.com, amit.kachhap@linaro.org Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, STEricsson_nomadik_linux@list.st.com, kernel@igloocommunity.org, "hongbo.zhang" Subject: [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list. Date: Tue, 30 Oct 2012 17:48:59 +0100 Message-Id: <1351615741-24134-4-git-send-email-hongbo.zhang@linaro.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1351615741-24134-1-git-send-email-hongbo.zhang@linaro.com> References: <1351079900-32236-1-git-send-email-hongbo.zhang@linaro.com> <1351615741-24134-1-git-send-email-hongbo.zhang@linaro.com> X-Gm-Message-State: ALoCoQkU00O9ERj6DqUzM8kwCpAMhIRpjE4+dpHsOTqT4dUbMBc8OZiWruzGPIHIModcjcVwPNoO Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: "hongbo.zhang" Problem of using this list is that the cpufreq_get_max_state callback will be called when register cooling device by thermal_cooling_device_register, but this list isn't ready at this moment. What's more, there is no need to maintain such a list, we can get cpufreq_cooling_device instance by the private thermal_cooling_device.devdata. Signed-off-by: hongbo.zhang Reviewed-by: Francesco Lavra Reviewed-by: Amit Daniel Kachhap --- drivers/thermal/cpu_cooling.c | 91 +++++++++---------------------------------- 1 file changed, 19 insertions(+), 72 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index bfd62b7..392d57d 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -58,8 +58,9 @@ struct cpufreq_cooling_device { }; static LIST_HEAD(cooling_cpufreq_list); static DEFINE_IDR(cpufreq_idr); +static DEFINE_MUTEX(cooling_cpufreq_lock); -static struct mutex cooling_cpufreq_lock; +static unsigned int cpufreq_dev_count; /* notify_table passes value to the CPUFREQ_ADJUST callback function. */ #define NOTIFY_INVALID NULL @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) { - int ret = -EINVAL, i = 0; - struct cpufreq_cooling_device *cpufreq_device; - struct cpumask *maskPtr; + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; + struct cpumask *maskPtr = &cpufreq_device->allowed_cpus; unsigned int cpu; struct cpufreq_frequency_table *table; unsigned long count = 0; + int i = 0; - mutex_lock(&cooling_cpufreq_lock); - list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { - if (cpufreq_device && cpufreq_device->cool_dev == cdev) - break; - } - if (cpufreq_device == NULL) - goto return_get_max_state; - - maskPtr = &cpufreq_device->allowed_cpus; cpu = cpumask_any(maskPtr); table = cpufreq_frequency_get_table(cpu); if (!table) { *state = 0; - ret = 0; - goto return_get_max_state; + return 0; } for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, if (count > 0) { *state = --count; - ret = 0; + return 0; } -return_get_max_state: - mutex_unlock(&cooling_cpufreq_lock); - return ret; + return -EINVAL; } /** @@ -288,20 +277,10 @@ return_get_max_state: static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) { - int ret = -EINVAL; - struct cpufreq_cooling_device *cpufreq_device; + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; - mutex_lock(&cooling_cpufreq_lock); - list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { - if (cpufreq_device && cpufreq_device->cool_dev == cdev) { - *state = cpufreq_device->cpufreq_state; - ret = 0; - break; - } - } - mutex_unlock(&cooling_cpufreq_lock); - - return ret; + *state = cpufreq_device->cpufreq_state; + return 0; } /** @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { - int ret = -EINVAL; - struct cpufreq_cooling_device *cpufreq_device; + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; - mutex_lock(&cooling_cpufreq_lock); - list_for_each_entry(cpufreq_device, &cooling_cpufreq_list, node) { - if (cpufreq_device && cpufreq_device->cool_dev == cdev) { - ret = 0; - break; - } - } - if (!ret) - ret = cpufreq_apply_cooling(cpufreq_device, state); - - mutex_unlock(&cooling_cpufreq_lock); - - return ret; + return cpufreq_apply_cooling(cpufreq_device, state); } /* Bind cpufreq callbacks to thermal cooling device ops */ @@ -351,14 +317,11 @@ struct thermal_cooling_device *cpufreq_cooling_register( { struct thermal_cooling_device *cool_dev; struct cpufreq_cooling_device *cpufreq_dev = NULL; - unsigned int cpufreq_dev_count = 0, min = 0, max = 0; + unsigned int min = 0, max = 0; char dev_name[THERMAL_NAME_LENGTH]; int ret = 0, i; struct cpufreq_policy policy; - list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node) - cpufreq_dev_count++; - /*Verify that all the clip cpus have same freq_min, freq_max limit*/ for_each_cpu(i, clip_cpus) { /*continue if cpufreq policy not found and not return error*/ @@ -380,9 +343,6 @@ struct thermal_cooling_device *cpufreq_cooling_register( cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); - if (cpufreq_dev_count == 0) - mutex_init(&cooling_cpufreq_lock); - ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); if (ret) { kfree(cpufreq_dev); @@ -401,12 +361,12 @@ struct thermal_cooling_device *cpufreq_cooling_register( cpufreq_dev->cool_dev = cool_dev; cpufreq_dev->cpufreq_state = 0; mutex_lock(&cooling_cpufreq_lock); - list_add_tail(&cpufreq_dev->node, &cooling_cpufreq_list); /* Register the notifier for first cpufreq cooling device */ if (cpufreq_dev_count == 0) cpufreq_register_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); + cpufreq_dev_count++; mutex_unlock(&cooling_cpufreq_lock); return cool_dev; @@ -419,33 +379,20 @@ EXPORT_SYMBOL(cpufreq_cooling_register); */ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) { - struct cpufreq_cooling_device *cpufreq_dev = NULL; - unsigned int cpufreq_dev_count = 0; + struct cpufreq_cooling_device *cpufreq_dev = cdev->devdata; mutex_lock(&cooling_cpufreq_lock); - list_for_each_entry(cpufreq_dev, &cooling_cpufreq_list, node) { - if (cpufreq_dev && cpufreq_dev->cool_dev == cdev) - break; - cpufreq_dev_count++; - } - - if (!cpufreq_dev || cpufreq_dev->cool_dev != cdev) { - mutex_unlock(&cooling_cpufreq_lock); - return; - } - - list_del(&cpufreq_dev->node); + cpufreq_dev_count--; /* Unregister the notifier for the last cpufreq cooling device */ - if (cpufreq_dev_count == 1) { + if (cpufreq_dev_count == 0) { cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, CPUFREQ_POLICY_NOTIFIER); } mutex_unlock(&cooling_cpufreq_lock); + thermal_cooling_device_unregister(cpufreq_dev->cool_dev); release_idr(&cpufreq_idr, cpufreq_dev->id); - if (cpufreq_dev_count == 1) - mutex_destroy(&cooling_cpufreq_lock); kfree(cpufreq_dev); } EXPORT_SYMBOL(cpufreq_cooling_unregister);