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 Kachhap X-Patchwork-Id: 4262911 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 91FEC9F333 for ; Thu, 29 May 2014 08:18:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C01812034A for ; Thu, 29 May 2014 08:18:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D64162012E for ; Thu, 29 May 2014 08:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933316AbaE2IQC (ORCPT ); Thu, 29 May 2014 04:16:02 -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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=SYjD+/H7JWpPdqUWvE/mbzm2xil4DBGAvjPBImBARHw=; b=iLAmyEcvDiZ3svXrm/IzvYOuU44xCWSppNRF19Xozw58wcy/y/lgvnJFVl8NiXa7Fu GUaqi2gh3gYHQUw8D9XY59IGnQ2Y8xu5d+OLqIEnpDyImSo9uSBu5GFNRO7f8Ljv/sof uKyr7CRxtDiexw2gnMb2g8pBR+fMaq9bAbX6HJPx4nYFXltR3A6/GarNxCftYvUBkvkE qgbK7JzLeZ4tqWrzpyWcv4helfrVj6gOQzM7s8Jtu7lE88vkho1On4+cd55arMHzsYAL +tTfzB5xsPyPYGcFzwJFlWSOY4u5hEgHQSCS1kOa71diT/48cJCkzcTR6/XkNp0KbUmZ G5hg== 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;