From patchwork Tue Oct 10 18:02:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 115443 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4047043qgn; Tue, 10 Oct 2017 11:13:11 -0700 (PDT) X-Received: by 10.98.210.129 with SMTP id c123mr11521607pfg.77.1507659191892; Tue, 10 Oct 2017 11:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507659191; cv=none; d=google.com; s=arc-20160816; b=EBpPWHmuj0TfGGHuusyWMbLGytbIQqPTYuPzG2eoSVn2woyISyyIRMAseGPlJIJgjV eY168uHRbXwmyBY1EaZ7NNLdp3iafgzc2bHxBkEX70WZ8SBtue+xASCxROGHyERcm8C4 7KI9KEtXf50+6r0wiimbiqH9U3jX4ZC3AjcHvDLxXzn/L21sQyr7NWZ3lgxQUcwWwqBF D4EDlTnQuJ6QvhgMI4+LyggZRspPQVm0zzfh0F0NYF0GSbMXjwJPtV42xJeWrZnp9tp3 G+oc3PH/zeC3cXWkZ30JP40J+S2ugeKR4pdnjEtdjLWiBwY8XzhO0ZH91BhdHsTMBCaX 53vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=LcCqOg6R5HLIWn70fOZmoXFqfJp/EJeqARoLFLmxNCE=; b=GvaPL31hcyJyiG1ZeEB3218pzb4JlRpx/6m5jjmlO9YqlMPkb48WkY3OseMqOt+lkr xh8soJD4lt0I3Byc/qou9omM0QjTd+OFZRx0BqLQK4xQEP3ZySsrEWPpzDPv3amDvcKa LaqvhRDPARvsQwI7SCdN747hHHO0nE3LYER+gtSxr+L1EWZPjtwQz02S4kcw83YYMTtD GN20UCENtmgCvB2TJyuScWQfbc14RkI0kt2p2e9dfCRC6LKF3ZP1nmtHW5H3PS/+shAG IRoNbKtR14GMb8IMSEWE49IuhlErceGQFBG8UJ2OkiAyFRGILUD4i6vtdIKKVra6whLl TYvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZzhh7os; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q81si9081475pfg.32.2017.10.10.11.13.11; Tue, 10 Oct 2017 11:13:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZzhh7os; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932492AbdJJSFA (ORCPT + 26 others); Tue, 10 Oct 2017 14:05:00 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:54691 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756528AbdJJSE4 (ORCPT ); Tue, 10 Oct 2017 14:04:56 -0400 Received: by mail-wm0-f43.google.com with SMTP id i124so7673181wmf.3 for ; Tue, 10 Oct 2017 11:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LcCqOg6R5HLIWn70fOZmoXFqfJp/EJeqARoLFLmxNCE=; b=IZzhh7os62neEmnbVv0GnceX/VN9hawtAnNg/m7d2Qyz9zCLlDwbJrnxczb4vQBts5 pjs88il4iTVRBm/1UQzPS/LeYIr1bMrdOgUVdQkPxGM/HGH2SSQi7GlaP4u2A0/n9pdj XxBmXM9PPGmsJ0GLbuTnDsiFoiVjibE9owjhg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LcCqOg6R5HLIWn70fOZmoXFqfJp/EJeqARoLFLmxNCE=; b=qRb9azhzF2uXLpCmuqq519DIde7XNN68Bkj2S89/WQFT3aVqaVQOwnuxo7/W8MV/H7 Kt04vbMCrIbp4YusgXd4ZKdlcBZy5/3A3AXX8DrCYsaA+1thYulH2FJtObgaw6pJAVhb BVPbpWovylKgDheKRdqBm5uNM7/GCtpnV1KCAdsr5biJmveyEuGzrb78re8YdYI4kdv2 aLinJ9MEjpGWejkMCnbX5IqP/FEKJjKKISpKqeomZbPmSxLOVV5xexnyoU/WpNXlmkAC 8ZiZROKWxFL6ncD5a0jWkDJU11yjG8AFAkP19Gkaa8LkDqFzf1N0huJEC6DpwhV/nPtJ EXXA== X-Gm-Message-State: AMCzsaWulw1xMFvWtel+83DU3u3lxexMv5dtCD9PQVlAFG+hAtSS5k/4 ptyHi0eluv+xWoGkD5+EzzvbMA== X-Google-Smtp-Source: AOwi7QDgVOnqnrHReNjkvusuTOc11CxneaW3HQ4P0kEZLFJN3AzJuZ6BpO+NieKZ9oclF56xq4QA6Q== X-Received: by 10.28.52.5 with SMTP id b5mr13035066wma.135.1507658694807; Tue, 10 Oct 2017 11:04:54 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:4f9:3ae1:43d2:31ae]) by smtp.gmail.com with ESMTPSA id l73sm12513428wmd.47.2017.10.10.11.04.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:04:54 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kevin.wangtao@linaro.org, Leo Yan Subject: [PATCH 05/25] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Tue, 10 Oct 2017 20:02:30 +0200 Message-Id: <1507658570-32675-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507658570-32675-1-git-send-email-daniel.lezcano@linaro.org> References: <79a5f10c-0fb7-3e4f-caac-c1625904b137@linaro.org> <1507658570-32675-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DT specifies a threshold of 65000, we setup the register with a value in the temperature resolution for the controller, 64656. When we reach 64656, the interrupt fires, the interrupt is disabled. Then the irq thread runs and calls thermal_zone_device_update() which will call in turn hisi_thermal_get_temp(). The function will look if the temperature decreased, assuming it was more than 65000, but that is not the case because the current temperature is 64656 (because of the rounding when setting the threshold). This condition being true, we re-enable the interrupt which fires immediately after exiting the irq thread. That happens again and again until the temperature goes to more than 65000. Potentially, there is here an interrupt storm if the temperature stabilizes at this temperature. A very unlikely case but possible. In any case, it does not make sense to handle dozens of alarm interrupt for nothing. Fix this by rounding the threshold value to the controller resolution so the check against the threshold is consistent with the one set in the controller. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 04eb5e2..1b44bfe 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -90,6 +90,12 @@ static inline long hisi_thermal_temp_to_step(long temp) return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } +static inline long hisi_thermal_round_temp(int temp) +{ + return hisi_thermal_step_to_temp( + hisi_thermal_temp_to_step(temp)); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -221,7 +227,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) sensor = &data->sensors; dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp / 1000); + sensor->thres_temp); mutex_unlock(&data->thermal_lock); thermal_zone_device_update(data->sensors.tzd, @@ -255,7 +261,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->thres_temp = trip[i].temperature; + sensor->thres_temp = hisi_thermal_round_temp(trip[i].temperature); break; } }