From patchwork Thu Jan 18 21:01:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 125046 Delivered-To: patch@linaro.org Received: by 10.46.64.27 with SMTP id n27csp297380lja; Thu, 18 Jan 2018 13:06:46 -0800 (PST) X-Google-Smtp-Source: ACJfBouP2Zx1zX1J/SogGw4zWRl7UhUlsrjW4m53qfWsGGgQx1YQcBGgnERY9f5Sn5tovwqt4XyR X-Received: by 2002:a17:902:968d:: with SMTP id n13-v6mr415286plp.33.1516309606261; Thu, 18 Jan 2018 13:06:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516309606; cv=none; d=google.com; s=arc-20160816; b=bWxGGiLW4fcFFiBnA13Pscf1riECmTL4qM0bIuq5KegvtHkbWurxPt2fUcHCX9Gzq0 yu3ty45TccwcQ4DpddPFWhT+3agkCsKnECghyMySd9ESj6lYpdlIK/xugUlnESJfnF3x 7Z0eSUu9e6mVHMCg9l0yX9Kn3pEJDdRgcikm31wv6Y4fHA17W0kuZ0vhhV95XLtnz01x 5/4hXY+bq+VyTtwjfuzFm6OVRNGLK+ip3uKu0WnRORdXwVpotSSPxPu3sB8qS7tMmFGi HQnB7pN0pbOTUhFqdlwuQnIgORjuxf3jmsqFgur8pKqRFPaKXQE91lyEJSAYEf5n5YZJ XVPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=G6dn1ZPSiJKBDw4bpEP8f3yf9/5MsRDcWOouK1AOc1I=; b=fgalvr8fwf3qhJiTlp+Y4w506tX9mnabmcW9MWhvok1+ugQZywSILg0kLEMS2oL6yd U/+KeweEj+LlpK0oLo69xAVCp5uBFYNuOl0P478qJXQiknd7kbHFFbPrFQAG10rKdsgV AJ34rpas9wfIP2KvoAQFAlTVMzk35qBnZNMt1YjX8whu2GpcukH9wA0hrSj8pf+VZvz0 kpxL4XQGZ4eL7GQZH71IC55z+qqsoxEjdEOGSXD039VCqgthrNB3P3Ufhdfl4rDnof53 o5LypaOoVtNaPjuI6I4mkbmJNR9veq0yJJNicEzftacXyWz7CF0HTzqtW9Pxfj0bVZXs FdGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=eM84MnJl; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s22si6131684pfh.396.2018.01.18.13.06.46; Thu, 18 Jan 2018 13:06:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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=@microsoft.com header.s=selector1 header.b=eM84MnJl; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932606AbeARVGp (ORCPT + 10 others); Thu, 18 Jan 2018 16:06:45 -0500 Received: from mail-bn3nam01on0116.outbound.protection.outlook.com ([104.47.33.116]:17152 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755045AbeARVGa (ORCPT ); Thu, 18 Jan 2018 16:06:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=G6dn1ZPSiJKBDw4bpEP8f3yf9/5MsRDcWOouK1AOc1I=; b=eM84MnJl7TYzszoIT7+kafXyTqCvKTd+ogH5HImyqOiAwRXJKTTJE6JWGaB+UOpvN6C9IFSZ0U/f+fGCU+XxpWioffYVIp70IbgALZfHvtZh7OCLBtMu5ybBq4fuhq9pQMCt60RCknD4e305BWfwACe0WuiExN8muTvC3Lw/waE= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0887.namprd21.prod.outlook.com (52.132.132.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.428.7; Thu, 18 Jan 2018 21:06:28 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0428.008; Thu, 18 Jan 2018 21:06:28 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Daniel Lezcano , Eduardo Valentin , Sasha Levin Subject: [added to the 4.1 stable tree] thermal/drivers/step_wise: Fix temperature regulation misbehavior Thread-Topic: [added to the 4.1 stable tree] thermal/drivers/step_wise: Fix temperature regulation misbehavior Thread-Index: AQHTkJ+O495d92NJoE6RS7tydgYi2A== Date: Thu, 18 Jan 2018 21:01:48 +0000 Message-ID: <20180118205908.3220-269-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [167.220.60.9] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0887; 7:/VtrCjOQ8b4tc7H94YabpstIeR/5I5NHvgXt1LH3Pa1QB8pUn3yg53iu/5VI6I3mV3KQ9hzYuJ3qfijUMB6pUlwBNkWAEnwAz6JDz4pOufJwDASpNPAuLjvrpvAh1e3ah3atHDIBRCMiffwuOZ3DGl/AH+Z5UI3kTrzJZX3pU4CX11BFagYgHaCYvmR5nTTgATx0qzrGhI1bSwS7vdloZpdpH+61kVGsTbfYYBTJaK/FMBchOv7FQR/P2uyDBLps x-ms-office365-filtering-correlation-id: 7a07ed5f-d577-4466-b9bd-08d55eb75788 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(48565401081)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7193020); SRVR:DM5PR2101MB0887; x-ms-traffictypediagnostic: DM5PR2101MB0887: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(31051911155226)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(6040495)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231046)(2400067)(944501161)(10201501046)(6055026)(61426038)(61427038)(6041282)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:DM5PR2101MB0887; BCL:0; PCL:0; RULEID:(100000803126)(100110400120); SRVR:DM5PR2101MB0887; x-forefront-prvs: 05568D1FF7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(39380400002)(396003)(366004)(376002)(346002)(199004)(189003)(22452003)(2501003)(6666003)(2950100002)(7736002)(81166006)(68736007)(99286004)(81156014)(86362001)(5250100002)(110136005)(102836004)(8936002)(5660300001)(86612001)(97736004)(6506007)(316002)(76176011)(3280700002)(6486002)(26005)(10290500003)(6512007)(54906003)(25786009)(39060400002)(105586002)(66066001)(478600001)(6346003)(36756003)(3660700001)(6436002)(8676002)(10090500001)(59450400001)(6116002)(14454004)(53936002)(107886003)(2900100001)(3846002)(72206003)(106356001)(4326008)(2906002)(1076002)(305945005)(22906009); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0887; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: sYQq+qsH9yymVTICN9dtAz5JVAjap0Rpl/6MPBXVmlgl+79DfavGlMt64WibTdyTLdSBUrPnKCQ9VFzfHvsA/Q== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <81FAC8D5F3311643B4B517828B094AFA@namprd21.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a07ed5f-d577-4466-b9bd-08d55eb75788 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2018 21:01:48.6487 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0887 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Lezcano This patch has been added to the stable tree. If you have any objections, please let us know. -- 2.11.0 =============== [ Upstream commit 07209fcf33542c1ff1e29df2dbdf8f29cdaacb10 ] There is a particular situation when the cooling device is cpufreq and the heat dissipation is not efficient enough where the temperature increases little by little until reaching the critical threshold and leading to a SoC reset. The behavior is reproducible on a hikey6220 with bad heat dissipation (eg. stacked with other boards). Running a simple C program doing while(1); for each CPU of the SoC makes the temperature to reach the passive regulation trip point and ends up to the maximum allowed temperature followed by a reset. This issue has been also reported by running the libhugetlbfs test suite. What is observed is a ping pong between two cpu frequencies, 1.2GHz and 900MHz while the temperature continues to grow. It appears the step wise governor calls get_target_state() the first time with the throttle set to true and the trend to 'raising'. The code selects logically the next state, so the cpu frequency decreases from 1.2GHz to 900MHz, so far so good. The temperature decreases immediately but still stays greater than the trip point, then get_target_state() is called again, this time with the throttle set to true *and* the trend to 'dropping'. From there the algorithm assumes we have to step down the state and the cpu frequency jumps back to 1.2GHz. But the temperature is still higher than the trip point, so get_target_state() is called with throttle=1 and trend='raising' again, we jump to 900MHz, then get_target_state() is called with throttle=1 and trend='dropping', we jump to 1.2GHz, etc ... but the temperature does not stabilizes and continues to increase. [ 237.922654] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 237.922678] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 237.922690] thermal cooling_device0: cur_state=0 [ 237.922701] thermal cooling_device0: old_target=0, target=1 [ 238.026656] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 238.026680] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=1 [ 238.026694] thermal cooling_device0: cur_state=1 [ 238.026707] thermal cooling_device0: old_target=1, target=0 [ 238.134647] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 238.134667] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 238.134679] thermal cooling_device0: cur_state=0 [ 238.134690] thermal cooling_device0: old_target=0, target=1 In this situation the temperature continues to increase while the trend is oscillating between 'dropping' and 'raising'. We need to keep the current state untouched if the throttle is set, so the temperature can decrease or a higher state could be selected, thus preventing this oscillation. Keeping the next_target untouched when 'throttle' is true at 'dropping' time fixes the issue. The following traces show the governor does not change the next state if trend==2 (dropping) and throttle==1. [ 2306.127987] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2306.128009] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 2306.128021] thermal cooling_device0: cur_state=0 [ 2306.128031] thermal cooling_device0: old_target=0, target=1 [ 2306.231991] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2306.232016] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=1 [ 2306.232030] thermal cooling_device0: cur_state=1 [ 2306.232042] thermal cooling_device0: old_target=1, target=1 [ 2306.335982] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2306.336006] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=1 [ 2306.336021] thermal cooling_device0: cur_state=1 [ 2306.336034] thermal cooling_device0: old_target=1, target=1 [ 2306.439984] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2306.440008] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=0 [ 2306.440022] thermal cooling_device0: cur_state=1 [ 2306.440034] thermal cooling_device0: old_target=1, target=0 [ ... ] After a while, if the temperature continues to increase, the next state becomes 2 which is 720MHz on the hikey. That results in the temperature stabilizing around the trip point. [ 2455.831982] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2455.832006] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=0 [ 2455.832019] thermal cooling_device0: cur_state=1 [ 2455.832032] thermal cooling_device0: old_target=1, target=1 [ 2455.935985] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2455.936013] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=0 [ 2455.936027] thermal cooling_device0: cur_state=1 [ 2455.936040] thermal cooling_device0: old_target=1, target=1 [ 2456.043984] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2456.044009] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=0 [ 2456.044023] thermal cooling_device0: cur_state=1 [ 2456.044036] thermal cooling_device0: old_target=1, target=1 [ 2456.148001] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2456.148028] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 2456.148042] thermal cooling_device0: cur_state=1 [ 2456.148055] thermal cooling_device0: old_target=1, target=2 [ 2456.252009] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2456.252041] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=0 [ 2456.252058] thermal cooling_device0: cur_state=2 [ 2456.252075] thermal cooling_device0: old_target=2, target=1 IOW, this change is needed to keep the state for a cooling device if the temperature trend is oscillating while the temperature increases slightly. Without this change, the situation above leads to a catastrophic crash by a hardware reset on hikey. This issue has been reported to happen on an OMAP dra7xx also. Signed-off-by: Daniel Lezcano Cc: Keerthy Cc: John Stultz Cc: Leo Yan Tested-by: Keerthy Reviewed-by: Keerthy Signed-off-by: Eduardo Valentin Signed-off-by: Sasha Levin --- drivers/thermal/step_wise.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index ec4ea5940bf7..96932e88464d 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -31,8 +31,7 @@ * If the temperature is higher than a trip point, * a. if the trend is THERMAL_TREND_RAISING, use higher cooling * state for this trip point - * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling - * state for this trip point + * b. if the trend is THERMAL_TREND_DROPPING, do nothing * c. if the trend is THERMAL_TREND_RAISE_FULL, use upper limit * for this trip point * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit @@ -94,9 +93,11 @@ static unsigned long get_target_state(struct thermal_instance *instance, if (!throttle) next_target = THERMAL_NO_TARGET; } else { - next_target = cur_state - 1; - if (next_target > instance->upper) - next_target = instance->upper; + if (!throttle) { + next_target = cur_state - 1; + if (next_target > instance->upper) + next_target = instance->upper; + } } break; case THERMAL_TREND_DROP_FULL: