From patchwork Thu Dec 17 19:13:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 7876351 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B33ED9F32E for ; Thu, 17 Dec 2015 19:14:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1A6C20437 for ; Thu, 17 Dec 2015 19:14:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D72942040F for ; Thu, 17 Dec 2015 19:14:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755031AbbLQTNv (ORCPT ); Thu, 17 Dec 2015 14:13:51 -0500 Received: from mail-pf0-f178.google.com ([209.85.192.178]:36811 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755558AbbLQTNh (ORCPT ); Thu, 17 Dec 2015 14:13:37 -0500 Received: by mail-pf0-f178.google.com with SMTP id o64so35465130pfb.3; Thu, 17 Dec 2015 11:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9ZMGcBRdxow4BxjWNSGB/kgFTuPJXjUyIARCZE6YV6I=; b=c0J/BCtJWDkgMbEGmyF7FBmjL70CFQA9RWH2O5jsDkAH+8FrlkXlKp9m7uqYmPmrad LIGXG576dqYnaNk4xw5TpLVjBGRBQd4IQBkxmM0G6ZLAbIaSNAu3ojLTuif+97etQpns se3phTAzRMbcTY1ffPfqAq4p3Z7WRj2wQXtwBeWYEM96I136gorfnpTRjy4vb3rvD8RD egKGdU20xBWxs+qniHbOUXrXNF8V/f44QUnVXvEMPDJLRjsoaZyNWffsaz29lZll5iAN 82+jzheVldydza1olG/s++7KX6etfX4/bOEJHrHHfie1KuitmE5w4Il/mbxXPgCfVVdO FmkQ== X-Received: by 10.98.0.195 with SMTP id 186mr16751969pfa.84.1450379616993; Thu, 17 Dec 2015 11:13:36 -0800 (PST) Received: from localhost ([209.119.72.78]) by smtp.gmail.com with ESMTPSA id r8sm12990287pfi.44.2015.12.17.11.13.35 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 17 Dec 2015 11:13:36 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCHv2 3/3] thermal: improve hot trip handling Date: Thu, 17 Dec 2015 11:13:29 -0800 Message-Id: <1450379609-7826-4-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1450379609-7826-1-git-send-email-edubezval@gmail.com> References: <1450379609-7826-1-git-send-email-edubezval@gmail.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=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 The idea is to add the choice to be notified only when temperature crosses trip points. The trip points affected are the non-passive trip points. It will check last temperature and current temperature against the trip point temperature and its hysteresis. In case the check shows temperature has changed enought indicating a trip point crossing, a uevent will be sent to userspace. The uevent contains the thermal zone type, the current temperature, the last temperature and the trip point in which the current temperature now resides. The behavior of ops->notify() callback remains the same. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- V1->V2: none --- drivers/thermal/thermal_core.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index a229c84..e0f1f4e 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -423,6 +423,56 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz, def_governor->throttle(tz, trip); } +static void thermal_tripped_notify(struct thermal_zone_device *tz, + int trip, enum thermal_trip_type trip_type, + int trip_temp) +{ + char tuv_name[THERMAL_NAME_LENGTH + 15], tuv_temp[25], + tuv_ltemp[25], tuv_trip[25], tuv_type[25]; + char *msg[6] = { tuv_name, tuv_temp, tuv_ltemp, tuv_trip, tuv_type, + NULL }; + int upper_trip_hyst, upper_trip_temp, trip_hyst = 0; + int ret = 0; + + snprintf(tuv_name, sizeof(tuv_name), "THERMAL_ZONE=%s", tz->type); + snprintf(tuv_temp, sizeof(tuv_temp), "TEMP=%d", tz->temperature); + snprintf(tuv_ltemp, sizeof(tuv_ltemp), "LAST_TEMP=%d", + tz->last_temperature); + snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip); + snprintf(tuv_type, sizeof(tuv_type), "TRIP_TYPE=%d", trip_type); + + mutex_lock(&tz->lock); + + /* crossing up */ + if (tz->last_temperature < trip_temp && trip_temp < tz->temperature) + kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg); + + if (tz->ops->get_trip_hyst) + tz->ops->get_trip_hyst(tz, trip, &trip_hyst); + + /* crossing down, check for hyst */ + trip_temp -= trip_hyst; + if (tz->last_temperature > trip_temp && trip_temp > tz->temperature) { + snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip - 1); + kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg); + } + + ret = tz->ops->get_trip_temp(tz, trip + 1, &upper_trip_temp); + if (ret) + goto unlock; + + if (tz->ops->get_trip_hyst) + tz->ops->get_trip_hyst(tz, trip + 1, &upper_trip_hyst); + + upper_trip_temp -= upper_trip_hyst; + if (tz->last_temperature > upper_trip_temp && + upper_trip_temp > tz->temperature) + kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg); + +unlock: + mutex_unlock(&tz->lock); +} + static void handle_critical_trips(struct thermal_zone_device *tz, int trip, enum thermal_trip_type trip_type) { @@ -430,6 +480,8 @@ static void handle_critical_trips(struct thermal_zone_device *tz, tz->ops->get_trip_temp(tz, trip, &trip_temp); + thermal_tripped_notify(tz, trip, trip_type, trip_temp); + /* If we have not crossed the trip_temp, we do not care. */ if (trip_temp <= 0 || tz->temperature < trip_temp) return;