From patchwork Wed Aug 29 22:40:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 10581033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C621F139B for ; Wed, 29 Aug 2018 22:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B66122B915 for ; Wed, 29 Aug 2018 22:40:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA7332B91F; Wed, 29 Aug 2018 22:40: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 0E6882B915 for ; Wed, 29 Aug 2018 22:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727981AbeH3Cj6 (ORCPT ); Wed, 29 Aug 2018 22:39:58 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40942 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727471AbeH3Cj6 (ORCPT ); Wed, 29 Aug 2018 22:39:58 -0400 Received: by mail-pg1-f193.google.com with SMTP id a13-v6so260762pgt.7 for ; Wed, 29 Aug 2018 15:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OLju93SEpozhs0sjr9r+bpvl5QmnEOjxlyIVCHoHahc=; b=SOD5UW437ssCfBjrFfnT4UlvmicQAzxSDyqgznIIhg9qBmo0JgahmqkN9JnmFiSwWM T62Gge/IzCXPRkJQzRxgUTGpRr8liZwnP5elTtyAhVdrW8h7+64F/BKDhJ1742DcneVZ sqpzwmD7ZNtuEFVaglwvvtRk3N9ZEnwyhKxho= 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:mime-version :content-transfer-encoding; bh=OLju93SEpozhs0sjr9r+bpvl5QmnEOjxlyIVCHoHahc=; b=aS/Hf8xGF0ejlmTr2x/Vk8F5iKOEz7NmxaG8hTF0p+rsKPjppPbfvwSyD6od798cmD c8RS0jm1jsLAh12Z/jPCE6OxF0HqVkO46DOsUjM4YNqzUpJ6i4MA1MHGs/uz3IJqjwa/ nthbEEgYDXnfMqRSYKnVpzOPknW6NL5eUR/7t2JX6bEdz4P+YGk5M0+LFWgJaHQbW1Px 5nEoylPaRHWx/DUir+6Z9tDvcqlPoN5faIKuw9cTkvOJ/j8pZ5gBs7HhcwS4qnzX7sDJ 2MmOwsaQLbcPrxdylMPIn58Utad0qmYl0bXZifxXU2Tzw3YcyHBZzRVCXQaGb4tY5GmM 01Lg== X-Gm-Message-State: APzg51AXwC3Ah+XeqhNZJmTiwM9Td865ZucO3A86O8Ysi1NKCVMEuAFP IoW0EGEAAmTntnXmrD3Z2YqDqg== X-Google-Smtp-Source: ANB0VdYlFg6eBORT1Hu82Ay/deXZCXEmDqdDZqs8+HA9aXs9GPJy+fMr/8kjxRSfSMTbsXyazBqlrQ== X-Received: by 2002:a62:1605:: with SMTP id 5-v6mr7746545pfw.11.1535582454463; Wed, 29 Aug 2018 15:40:54 -0700 (PDT) Received: from mka.mtv.corp.google.com ([2620:15c:202:1:b6af:f85:ed6c:ac6a]) by smtp.gmail.com with ESMTPSA id l6-v6sm6758039pfl.169.2018.08.29.15.40.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Aug 2018 15:40:54 -0700 (PDT) From: Matthias Kaehlcke To: Viresh Kumar , Nishanth Menon , Stephen Boyd , Chanwoo Choi Cc: linux-pm@vger.kernel.org, MyungJoo Ham , Kyungmin Park , Brian Norris , Matthias Kaehlcke Subject: [RFC PATCH] PM/OPP: Add disable count Date: Wed, 29 Aug 2018 15:40:14 -0700 Message-Id: <20180829224014.70036-1-mka@chromium.org> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog MIME-Version: 1.0 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 devfreq sub-system uses the OPP API to determine which frequencies are available. A devfreq cooling device (drivers/thermal/devfreq_cooling.c) may disable certain OPPs depending on temperature input and the thermal policy. The WIP throttler driver (https://lore.kernel.org/patchwork/project/lkml/list/?series=357937) can also limit the frequency range of devfreq devices. The current version does this by introducing a function similar to cpufreq's cpufreq_verify_within_limits(), however devfreq maintainer Chanwoo Choi wants the throttler to use the OPP interface for limiting the frequency range. A devfreq cooling device and the throttler manipulate OPPs independently from each other, one might enable an OPP, the other disable it. This patch adds a 'disable count' to the OPP, to allow to track how often the OPP was disabled without a subsequent opp_enable(). The OPP is considered disabled when the disable count is > 0 , even directly after a opp_enable() call. This patch is an initial draft, intended to get feedback from OPP maintainers on the general idea. Suggested-by: Chanwoo Choi Signed-off-by: Matthias Kaehlcke --- Even though I sent this patch I have reservations about it, some of general nature. and others in the context of devfreq/throttler/cooling device: - possible race conditions, devfreq may end up using a disabled OPP (cooling device and throttler run asynchronously to devfreq). This is not really a new issue though, I think this can already happen today with devfreq and cooling device. It doesn't cause problems since currently disabling an OPP doesn't results in disabling regulators, clocks or other components - all OPPs could end up disabled since multiple drivers manipulate OPPs independently without any arbitration - a crashing/buggy driver can leave OPPs disabled forever - a typical caller would expect a OPP to be enabled after opp_enable(), this is not always the case - added complexity for callers of opp_enable/disable() to keep track which OPPs they enabled/disabled previously --- drivers/opp/core.c | 9 +++++++++ drivers/opp/opp.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 31ff03dbeb83..a6d23e8560d2 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1072,6 +1072,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, if (!_opp_supported_by_regulators(new_opp, opp_table)) { new_opp->available = false; + new_opp->disable_count = 1; dev_warn(dev, "%s: OPP not supported by regulators (%lu)\n", __func__, new_opp->rate); } @@ -1592,10 +1593,18 @@ static int _opp_set_availability(struct device *dev, unsigned long freq, goto unlock; } + if (availability_req) + opp->disable_count--; + else + opp->disable_count++; + /* Is update really needed? */ if (opp->available == availability_req) goto unlock; + if (availability_req && opp->disable_count > 0) + goto unlock; + opp->available = availability_req; dev_pm_opp_get(opp); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 7c540fd063b2..a72acb16c364 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -55,6 +55,8 @@ extern struct list_head opp_tables; * order. * @kref: for reference count of the OPP. * @available: true/false - marks if this OPP as available or not + * @disable_count: tracks the number of times the OPP has been disabled + * (without re-enabling it). * @dynamic: not-created from static DT entries. * @turbo: true if turbo (boost) OPP * @suspend: true if suspend OPP @@ -74,6 +76,7 @@ struct dev_pm_opp { struct kref kref; bool available; + unsigned int disable_count; bool dynamic; bool turbo; bool suspend;