From patchwork Tue Aug 11 10:21:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javi Merino X-Patchwork-Id: 6991211 X-Patchwork-Delegate: eduardo.valentin@ti.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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 037609F39D for ; Tue, 11 Aug 2015 10:23:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 16F81203DC for ; Tue, 11 Aug 2015 10:22:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1948220671 for ; Tue, 11 Aug 2015 10:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934266AbbHKKWF (ORCPT ); Tue, 11 Aug 2015 06:22:05 -0400 Received: from foss.arm.com ([217.140.101.70]:52998 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934197AbbHKKWE (ORCPT ); Tue, 11 Aug 2015 06:22:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 97E7875; Tue, 11 Aug 2015 03:22:01 -0700 (PDT) Received: from e104805.cambridge.arm.com (e104805.cambridge.arm.com [10.2.131.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 83A9B3F5C3; Tue, 11 Aug 2015 03:22:02 -0700 (PDT) From: Javi Merino To: linux-pm@vger.kernel.org Cc: dmitry.torokhov@gmail.com, cywang@chromium.org, linux-kernel@vger.kernel.org, punit.agrawal@arm.com, Javi Merino Subject: [PATCH v2 3/4] thermal: power_allocator: don't require tzp to be present for the thermal zone Date: Tue, 11 Aug 2015 11:21:32 +0100 Message-Id: <1439288493-19740-4-git-send-email-javi.merino@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1439288493-19740-1-git-send-email-javi.merino@arm.com> References: <1439222692-3535-1-git-send-email-javi.merino@arm.com> <1439288493-19740-1-git-send-email-javi.merino@arm.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.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Thermal zones created using thermal_zone_device_create() may not have tzp. As the governor gets its parameters from there, allocate it while the governor is bound to the thermal zone so that it can operate in it. In this case, tzp is freed when the thermal zone switches to another governor. --- While this would be easier to do by just ignoring the thermal zone if there was no tzp, I think the approach in this patch provides a better behavior. drivers/thermal/power_allocator.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allocator.c index 257c9af20f22..38beea721e18 100644 --- a/drivers/thermal/power_allocator.c +++ b/drivers/thermal/power_allocator.c @@ -58,6 +58,8 @@ static inline s64 div_frac(s64 x, s64 y) /** * struct power_allocator_params - parameters for the power allocator governor + * @allocated_tzp: whether we have allocated tzp for this thermal zone and + * it needs to be freed on unbind * @err_integral: accumulated error in the PID controller. * @prev_err: error in the previous iteration of the PID controller. * Used to calculate the derivative term. @@ -70,6 +72,7 @@ static inline s64 div_frac(s64 x, s64 y) * controlling for. */ struct power_allocator_params { + bool allocated_tzp; s64 err_integral; s32 prev_err; int trip_switch_on; @@ -473,8 +476,7 @@ static void allow_maximum_power(struct thermal_zone_device *tz) * Initialize the PID controller parameters and bind it to the thermal * zone. * - * Return: 0 on success, -EINVAL if the thermal zone doesn't have tzp or -ENOMEM - * if we ran out of memory. + * Return: 0 on success, or -ENOMEM if we ran out of memory. */ static int power_allocator_bind(struct thermal_zone_device *tz) { @@ -483,13 +485,20 @@ static int power_allocator_bind(struct thermal_zone_device *tz) unsigned long switch_on_temp, control_temp; u32 sustainable_power, temperature_threshold; - if (!tz->tzp) - return -EINVAL; - params = devm_kzalloc(&tz->device, sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; + if (!tz->tzp) { + tz->tzp = kzalloc(sizeof(*tz->tzp), GFP_KERNEL); + if (!tz->tzp) { + ret = -ENOMEM; + goto free_params; + } + + params->allocated_tzp = true; + } + if (!tz->tzp->sustainable_power) dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); @@ -531,11 +540,24 @@ static int power_allocator_bind(struct thermal_zone_device *tz) tz->governor_data = params; return 0; + +free_params: + devm_kfree(&tz->device, params); + + return ret; } static void power_allocator_unbind(struct thermal_zone_device *tz) { + struct power_allocator_params *params = tz->governor_data; + dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id); + + if (params->allocated_tzp) { + kfree(tz->tzp); + tz->tzp = NULL; + } + devm_kfree(&tz->device, tz->governor_data); tz->governor_data = NULL; }