Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp657437pxb; Fri, 28 Jan 2022 07:23:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHNE10+cosX8JDv6SE3nw2irKoU67l2ZR0JdXaFQLn7gkR+42onC63IP7qN+UDsVmcfiuh X-Received: by 2002:a05:6402:2802:: with SMTP id h2mr8796657ede.255.1643383421238; Fri, 28 Jan 2022 07:23:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643383421; cv=none; d=google.com; s=arc-20160816; b=G2YKCsxs901AV4jEkZ0n+xlsa8AJ2r/ZbLNN76/tdoPRV93pDRddwvqwVtN9qwVCWG ZgPLRyoGCVWVxxhHF7TADm9wP1LYWhCH6n45VZtfBG1J5OL6tU94E3ZtccGfD7MOi4/O 4PJ3eG3etGx+Q/EdcvzC2UIFQRYPZTTfJgkCFdxwOfDc825JSnRg0BQZJ1gccM/Sfus4 mwE6dA/+D46OnDE9n2+M5DDZaz32vpWP437L1K9cIkdWbiUXQ2INoOcy7FH80U1es0X8 kAQF1nQG0Rnw+tpnoBxpT5BCEjeiXZJ1LhCRQpaYMLpj+D6ZC7yySzQcZwsklXDpCJ0h s3+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=FdW+3XOlJ+0fgLrgyEWrXgNEBmSSsSV3d6HeRGSVQo4=; b=hUHtMbsaK1ocQxqf30U2pcYju6IA3SGlgqCez7dGiGTN370EwjvR2GN+jOGxAONtlj HTmHCVIG6lLMJvdlvN8YiufXNMcn5RceowAs6WdWq6yZVlJmNzEDVA4kWjzTRVo0uKrd C0IQi30GZh2j+uVUvcHDIh+e0gnr9UTM2KhxRmLAmIND3+ZR+m2kAOj7c5XLkc55rDZH tecHntTqXNeSOiJpLAC+o4NiaU55gyz8FAhjxFK7QQul9icAUNTVd40nfRc4GNyVyL8/ Wp70spFQD9GirAiyReZaeMR3TlhjsoTMmcycm0abmkkJTLqjg/YQuUUFh3jwaqXEZXv/ TxhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=SZgzDToB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i16si3317956ejo.352.2022.01.28.07.23.08; Fri, 28 Jan 2022 07:23:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=SZgzDToB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245315AbiA0SMh (ORCPT + 99 others); Thu, 27 Jan 2022 13:12:37 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:45676 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245617AbiA0SLt (ORCPT ); Thu, 27 Jan 2022 13:11:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1643307109; x=1674843109; h=from:to:cc:subject:date:message-id:mime-version; bh=FdW+3XOlJ+0fgLrgyEWrXgNEBmSSsSV3d6HeRGSVQo4=; b=SZgzDToBF/lK8bdjGD8kUNtrBQ+NVu8FXdAZaGOfNobVj6oGNsg8qG6H +lBAlqfJomlzr/DOBCJk70ZWJVukr/YcyJh3yWqTMjm4GCqc358dELE7R EA7jSOBGlMMDda9A5lLShF+TDMIvxDxOXxeK8fgxC6dtMRthL9EvVcm+7 c=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 27 Jan 2022 10:11:49 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 10:11:48 -0800 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Thu, 27 Jan 2022 10:11:48 -0800 Received: from codeaurora.org (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Thu, 27 Jan 2022 10:11:45 -0800 From: Manaf Meethalavalappu Pallikunhi To: Lukasz Luba , "Rafael J . Wysocki" , Daniel Lezcano , "Amit Kucheria" , Zhang Rui CC: , , "Manaf Meethalavalappu Pallikunhi" Subject: [PATCH v5] drivers: thermal: clear all mitigation when thermal zone is disabled Date: Thu, 27 Jan 2022 23:41:33 +0530 Message-ID: <1643307093-22501-1-git-send-email-quic_manafm@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whenever a thermal zone is in trip violated state, there is a chance that the same thermal zone mode can be disabled either via thermal core API or via thermal zone sysfs. Once it is disabled, the framework bails out any re-evaluation of thermal zone. It leads to a case where if it is already in mitigation state, it will stay the same state forever. To avoid above mentioned issue, add support to bind/unbind governor from thermal zone during thermal zone mode change request and clear all existing throttling in governor unbind_from_tz() callback. Suggested-by: Daniel Lezcano Signed-off-by: Manaf Meethalavalappu Pallikunhi --- drivers/thermal/gov_power_allocator.c | 3 +++ drivers/thermal/gov_step_wise.c | 26 ++++++++++++++++++++++++++ drivers/thermal/thermal_core.c | 31 +++++++++++++++++++++++++++---- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 13e3757..9ff0c5f 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -696,6 +696,9 @@ static void power_allocator_unbind(struct thermal_zone_device *tz) dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id); + tz->passive = 0; + allow_maximum_power(tz, true); + if (params->allocated_tzp) { kfree(tz->tzp); tz->tzp = NULL; diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c index 12acb12..2d2186b 100644 --- a/drivers/thermal/gov_step_wise.c +++ b/drivers/thermal/gov_step_wise.c @@ -168,6 +168,31 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) } /** + * step_wise_unbind() - unbind the step_wise governor to a thermal zone + * @tz: thermal zone to unbind it to + * + * Clear all previous throttling and reset passive counter. + * + */ +static void step_wise_unbind(struct thermal_zone_device *tz) +{ + struct thermal_instance *instance; + + dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id); + + mutex_lock(&tz->lock); + tz->passive = 0; + list_for_each_entry(instance, &tz->thermal_instances, tz_node) { + instance->initialized = false; + instance->target = THERMAL_NO_TARGET; + mutex_lock(&instance->cdev->lock); + __thermal_cdev_update(instance->cdev); + mutex_unlock(&instance->cdev->lock); + } + mutex_unlock(&tz->lock); +} + +/** * step_wise_throttle - throttles devices associated with the given zone * @tz: thermal_zone_device * @trip: trip point index @@ -196,6 +221,7 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip) static struct thermal_governor thermal_gov_step_wise = { .name = "step_wise", + .unbind_from_tz = step_wise_unbind, .throttle = step_wise_throttle, }; THERMAL_GOVERNOR_DECLARE(thermal_gov_step_wise); diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 82654dc..34726d3 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -274,6 +274,26 @@ static int __init thermal_register_governors(void) return ret; } +static void thermal_governor_attach(struct thermal_zone_device *tz) +{ + mutex_lock(&thermal_governor_lock); + if (tz->governor && tz->governor->bind_to_tz) { + if (tz->governor->bind_to_tz(tz)) + dev_err(&tz->device, + "governor %s failed to bind to thermal zone %s\n", + tz->governor->name, tz->type); + } + mutex_unlock(&thermal_governor_lock); +} + +static void thermal_governor_detach(struct thermal_zone_device *tz) +{ + mutex_lock(&thermal_governor_lock); + if (tz->governor && tz->governor->unbind_from_tz) + tz->governor->unbind_from_tz(tz); + mutex_unlock(&thermal_governor_lock); +} + /* * Zone update section: main control loop applied to each zone while monitoring * @@ -449,12 +469,15 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz, mutex_unlock(&tz->lock); - thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); - - if (mode == THERMAL_DEVICE_ENABLED) + if (mode == THERMAL_DEVICE_ENABLED) { + thermal_governor_attach(tz); + thermal_zone_device_init(tz); + thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); thermal_notify_tz_enable(tz->id); - else + } else { + thermal_governor_detach(tz); thermal_notify_tz_disable(tz->id); + } return ret; }