From patchwork Thu Oct 19 17:05:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116431 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp726460qgn; Thu, 19 Oct 2017 10:13:28 -0700 (PDT) X-Received: by 10.84.215.9 with SMTP id k9mr1977202pli.284.1508433208006; Thu, 19 Oct 2017 10:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508433207; cv=none; d=google.com; s=arc-20160816; b=K9hVfHwFg9Ic0NNgICSdJxA6+LVIcl1IMl9sw66+lcDRiHbPQ/fSE4DBqSM+Ezwqe1 nLSMSAWYYOJuk1zkJHtvQwlkpSn00BfKAGM+b07uwc+SqlbsdEm9Qe/lY3i5PYldWlKy YZmY2QQ2yDqLqS29cifyJIUC0Lw8Kq1dvS241CiDISXW5Yic3CDCoYTMovMqhIDrkJvI y53AONqAgEOSY08qk4cklyYiQesF+pH5DUJ4yhiy1hwjjZeDRLruAFP5fnud3G/mtfXj XsSuCit1EQ/S3Z7RXN6bWM8SLft1Wyf82D/+7b4PwmE7RIiO4YKRbKXRf5Fp6vo7gFRd ZuVA== 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=Vp4PTMx+ebx7Vrj4LaLKq9EHkAAhULHx07D+Lf510c+MDgM9JVQqF7aP7Uigl/eiua TWb38l8fN4fMnFwjXwn+KcUmCXlThp8O0bn5At2IzxD8byMSQLlwmroGxiK0G7xzpxLn JfaAYkYrTkWbNxy0vmlCeB50djtYxvNMukTTQI0SxACE+IXOp3sebXR46/2gZvOv9e9H xiUg2NjU2JAA8K24tLoN6TiKyeD05nxvxXr7L41vtnVwcmOLlkTj5EmQSe1KyQcLKAst k/xbTdBJcjSAFhDe+s9VzhWApBiyhRtGVrrHXWwcIMAIrm+ooePHT0e363zqDMmlWn1/ n/cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fLlkdUnk; 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 d10si8101669pfb.458.2017.10.19.10.13.27; Thu, 19 Oct 2017 10:13:27 -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=fLlkdUnk; 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 S1753701AbdJSRNZ (ORCPT + 27 others); Thu, 19 Oct 2017 13:13:25 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:52625 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755018AbdJSRIh (ORCPT ); Thu, 19 Oct 2017 13:08:37 -0400 Received: by mail-wr0-f195.google.com with SMTP id k62so9037255wrc.9 for ; Thu, 19 Oct 2017 10:08:37 -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=fLlkdUnk+uUXYW1zNvxmm/6SH6zHJMLAB8OFN7hzFCXtSEz4mKuPMCFCn94lt4V1aE BnilSnUqPZbEXmxMhz8lOC8Mvdkhq4G8LnHkkui7lENNkrPAS9ldjfeOhdG6WZu/giHt GGDuCs0R60S3aLKZI8NnwacplMe3H9Dy9KD78= 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=OpEbbUVCFhZLvd9UMNbKGB31EPizzs6+bLbD6XaCS2uaM7u9JOciEvdJ6364zT10v3 iaZpt4Vc/iyqrQJzzKnVK92H6pX3Km0VR2vUgfn1hKH+i6EQdrZXWf7QntbOtMYQRdbw vnpclwJYcglpfO7++njrKQjkaBz5vW0GAl54vMqXJjRD28uCGf7vjlFf9mHx2feN4nl3 2CAuXOWWLwiLYgi0tgSpq7wHYK77lFN1jNTZ6ahNCVf9mnG9NUs82BL7FdGKD2G1NjP6 FFvFi6fdeRkv5xSCK4LuyCBksMV1D8wP+S9MVobZ/VDOJRv14Hzx8zX4dmDVhh5nWSNg jihw== X-Gm-Message-State: AMCzsaWHbYHoHo+tfKfMY0nu7DYJvzqlpMP6mm0dwUeUu6UMTAaLEws0 8nEwUdL0ecfp6lXKCgWX5jZuu3sErJM= X-Google-Smtp-Source: ABhQp+R0mJ02LkZB9RBnxEDig9J0EUS1574EwBe1JlHRFoC1s+wiQipKJmY9ULJEwOl81wacbeZMLw== X-Received: by 10.223.150.76 with SMTP id c12mr2335345wra.10.1508432916400; Thu, 19 Oct 2017 10:08:36 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:35 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/18] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Thu, 19 Oct 2017 19:05:47 +0200 Message-Id: <1508432760-17847-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-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; } }