From patchwork Thu May 29 08:15:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 31099 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EA9EE203E6 for ; Thu, 29 May 2014 08:16:23 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id m1sf61893293oag.2 for ; Thu, 29 May 2014 01:16:22 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=F7uvpTF0/LEHMW4kVuySVOIo5r5c/+rb2/4UDXoRIz4=; b=cbVdb+odYUZ49i6ffnxswR39WqMMUdXbgub8sKEF6uFkTfCnGGEjYoCQw+hTDw7w7f wpqaZeKn4VqTzAlHDT0J1MsugQhDWtvHqovIuVfSo2iBzmQrSZraG9bWcuJo8bPcYwJS 7GwxSElEP+ZwVO04i1woOd+nz9UrRAVZxYtGbJ9KAqepK2Q/voG3Vbk6hO1H6HVPGmdb xzyNP8eOBNAVth3mlOt6c3tFA//PFRxNSY/DAAytJoa5clHdOQV0NGI5o6p76v8SuJJu XDWyAoHS3Vcxi0jNu5RMTVFTyPf7tjTjH8aS4lUSo0cLTeJQzKLfufm5wuDhPQR8gQPL ru2Q== X-Gm-Message-State: ALoCoQlQUdsfJumT5n4Nh7jbsrSy9ykYm5u+jqJAJG1MXXVPU4qTw7XVKQdM4/d1stsgRVm7GpR6 X-Received: by 10.43.103.136 with SMTP id di8mr2047081icc.14.1401351382787; Thu, 29 May 2014 01:16:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.143 with SMTP id s15ls445022qga.33.gmail; Thu, 29 May 2014 01:16:22 -0700 (PDT) X-Received: by 10.52.97.202 with SMTP id ec10mr264993vdb.55.1401351382637; Thu, 29 May 2014 01:16:22 -0700 (PDT) Received: from mail-vc0-x22a.google.com (mail-vc0-x22a.google.com [2607:f8b0:400c:c03::22a]) by mx.google.com with ESMTPS id lx4si12679799veb.29.2014.05.29.01.16.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 May 2014 01:16:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) client-ip=2607:f8b0:400c:c03::22a; Received: by mail-vc0-f170.google.com with SMTP id la4so484909vcb.29 for ; Thu, 29 May 2014 01:16:22 -0700 (PDT) X-Received: by 10.58.23.6 with SMTP id i6mr5210249vef.12.1401351382533; Thu, 29 May 2014 01:16:22 -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.220.221.72 with SMTP id ib8csp9473vcb; Thu, 29 May 2014 01:16:22 -0700 (PDT) X-Received: by 10.66.122.208 with SMTP id lu16mr6295515pab.129.1401351381676; Thu, 29 May 2014 01:16:21 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qs6si26980277pbc.21.2014.05.29.01.16.21 for ; Thu, 29 May 2014 01:16:21 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-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 S933484AbaE2IQG (ORCPT + 27 others); Thu, 29 May 2014 04:16:06 -0400 Received: from mail-pb0-f51.google.com ([209.85.160.51]:44299 "EHLO mail-pb0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932560AbaE2IP6 (ORCPT ); Thu, 29 May 2014 04:15:58 -0400 Received: by mail-pb0-f51.google.com with SMTP id ma3so12736618pbc.10 for ; Thu, 29 May 2014 01:15:57 -0700 (PDT) X-Received: by 10.68.231.35 with SMTP id td3mr6354227pbc.137.1401351357673; Thu, 29 May 2014 01:15:57 -0700 (PDT) Received: from localhost.localdomain ([14.140.216.146]) by mx.google.com with ESMTPSA id ee5sm5006897pbc.47.2014.05.29.01.15.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 29 May 2014 01:15:57 -0700 (PDT) From: Amit Daniel Kachhap To: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Zhang Rui , linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, edubezval@gmail.com, rjw@rjwysocki.net, linux-arm-kernel@lists.infradead.org, lenb@kernel.org Subject: [PATCH v1 1/6] thermal: cpu_cooling: Fix the notification mechanism by using per cpu structure Date: Thu, 29 May 2014 13:45:29 +0530 Message-Id: <1401351334-11210-2-git-send-email-amit.daniel@samsung.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1401351334-11210-1-git-send-email-amit.daniel@samsung.com> References: <1401351334-11210-1-git-send-email-amit.daniel@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: amit.daniel@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@ 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: , Currently the notification data is supplied to the thermal notifiers using a single global pointer. This method will have race condition if cpu cooling interfaces are used by more than 1 clients (more than 1 cdev) to cause cpufreq clipping. Also the notifier data is presented as per cpu cpufreq policy structure. This was needed as same cpu is used later in thermal cpufreq handler function. Signed-off-by: Amit Daniel Kachhap --- drivers/thermal/cpu_cooling.c | 38 +++++++++++++++----------------------- 1 files changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 4246262..16388b0 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -58,7 +58,7 @@ static unsigned int cpufreq_dev_count; /* notify_table passes value to the CPUFREQ_ADJUST callback function. */ #define NOTIFY_INVALID NULL -static struct cpufreq_cooling_device *notify_device; +static DEFINE_PER_CPU(struct cpufreq_cooling_device *, notify_device); /** * get_idr - function to get a unique id. @@ -98,23 +98,6 @@ static void release_idr(struct idr *idr, int id) /* Below code defines functions to be used for cpufreq as cooling device */ -/** - * is_cpufreq_valid - function to check frequency transitioning capability. - * @cpu: cpu for which check is needed. - * - * This function will check the current state of the system if - * it is capable of changing the frequency for a given @cpu. - * - * Return: 0 if the system is not currently capable of changing - * the frequency of given cpu. !0 in case the frequency is changeable. - */ -static int is_cpufreq_valid(int cpu) -{ - struct cpufreq_policy policy; - - return !cpufreq_get_policy(&policy, cpu); -} - enum cpufreq_cooling_property { GET_LEVEL, GET_FREQ, @@ -294,11 +277,18 @@ static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device, cpufreq_device->cpufreq_state = cooling_state; cpufreq_device->cpufreq_val = clip_freq; - notify_device = cpufreq_device; for_each_cpu(cpuid, mask) { - if (is_cpufreq_valid(cpuid)) + if (cpufreq_get_policy(&policy, cpu) == 0) { + /* + * Store the notification data in the cpu pointed by + * cpufreq policy structure. This is needed as this cpu + * will be used later to fetch correct data pointer. + */ + per_cpu(notify_device, policy.cpu) = cpufreq_device; cpufreq_update_policy(cpuid); + per_cpu(notify_device, policy.cpu) = NOTIFY_INVALID; + } } notify_device = NOTIFY_INVALID; @@ -323,12 +313,14 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, { struct cpufreq_policy *policy = data; unsigned long max_freq = 0; + struct cpufreq_cooling_device *cpufreq_device + = per_cpu(notify_device, policy->cpu); - if (event != CPUFREQ_ADJUST || notify_device == NOTIFY_INVALID) + if (event != CPUFREQ_ADJUST || cpufreq_device == NOTIFY_INVALID) return 0; - if (cpumask_test_cpu(policy->cpu, ¬ify_device->allowed_cpus)) - max_freq = notify_device->cpufreq_val; + if (cpumask_test_cpu(policy->cpu, &cpufreq_device->allowed_cpus)) + max_freq = cpufreq_device->cpufreq_val; else return 0;