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: 9996981 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8C0760216 for ; Tue, 10 Oct 2017 18:13:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE40628701 for ; Tue, 10 Oct 2017 18:13:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1AC128708; Tue, 10 Oct 2017 18:13:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5345328701 for ; Tue, 10 Oct 2017 18:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932317AbdJJSE5 (ORCPT ); Tue, 10 Oct 2017 14:04:57 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:52925 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756531AbdJJSE4 (ORCPT ); Tue, 10 Oct 2017 14:04:56 -0400 Received: by mail-wm0-f44.google.com with SMTP id k4so7701125wmc.1 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=B3HrIjGU9dRXV+ka+3X4zvF4Yms7VoShieexeQdlvde/rMoVupt1grYcmlPg/SeIoo IEcekEyCUYq3gkw5NTnV9D25cbRa3bPB2Eew5MAm3Q3g4weu+uHTVb1qADRdt9MKF0Lr Xdym3v9Vzy35kmqLJSs7WlTl9ywsjnGAUYZwVTaN9Y4Veci2BX+4jPYQiYVn/BoydOZE NNKR3LkmiFAZbK9xDHogbUwwgMfpVQ1VFJNJfUakykNkBciRvSlgvFHcykubBobeXkxz 1ppQ4lwoeihBLhfrXij7pK673tNaRP9MniWY7o4CLujbgJ15Jhu0NS9kG6LwKJzpmkPA cc2g== X-Gm-Message-State: AMCzsaWb0oR3+x9CBkThdTt3pBu4oai5kowIz/pN9QYhOQR5UUCwBLDd n6mbGbT0gUJxqPDi19ciMVTVZw== 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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; } }