Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp923610ybg; Fri, 18 Oct 2019 09:19:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwi8piX2AtWWef1Egy2LQtNIEMauy5iPM97olq/tulpsxdwo3EOBrADujFMdyBR5Ue8RTbu X-Received: by 2002:aa7:d145:: with SMTP id r5mr10338913edo.275.1571415564471; Fri, 18 Oct 2019 09:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571415564; cv=none; d=google.com; s=arc-20160816; b=tdoqdW2c4X4qyjaPE9SvkepNy/wdgCD2aEI2biQow04ZT3t3tkeqSlb4NhUYqtHPo1 nNw8Vpz1dEFtrJUAv+AmzVk8lzwK3M3vh/YCJNb1sgByX53AAXzt0bi7efpSZ/6OaPoP Ff02RFA/BmTeuYkrAqbO5yTkxzEpCP58cRVTsDSqizLXxiXhj9NlxWKboStPKoKoy8TV 8tQqkCMGNNjEDYw5nib7C3/kaa3+1Zc93bxThsZIISHDufgN3Eaetz4OPfKtQ/EiALIg q7kBLV2kjZPg1AHOvzn3z518QvT2ln2fhMjCP4oGwGPN4vjuvDNXdDGMuspCUXLW3BO6 ZicA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=ONhbG1YIvRehChglKAzYSee1XpDEhwyMKjBcNaf717M=; b=Ejh+6HNb0rTFKs02oLMFBX9S8WjeF1HIeQoLf2C364hXuu5k2I3WaCIDJEN7trlOVQ ihrlol4zYZB1WXW6LMlVHqezM2qNULZqDq3d7wrsLuHkHSEr+plft1CFKp0NnLop4LrU cLIgM82greICSeQyiqrv+V3MGHYHFr0tenrMpmgdONvekXdYr8ttFMVfGK/DqVbpJfdW +NLyfb8r0WY31aPIdXME32Jky5s5SXqSnrGYb4UzULjf+xEwtsO4I+8D6nxXYBgGpVci l89DVyiZH9bP+dxhnC5ac/NePHbn7GuxNKLHTnFHEbsK8/e1Nd9wZJdNjIGUw8Q2aZii xVJg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j14si3929424edt.298.2019.10.18.09.18.59; Fri, 18 Oct 2019 09:19:24 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437585AbfJQOQz (ORCPT + 99 others); Thu, 17 Oct 2019 10:16:55 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:42042 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727314AbfJQOQz (ORCPT ); Thu, 17 Oct 2019 10:16:55 -0400 Received: by mail-ot1-f67.google.com with SMTP id c10so2005874otd.9; Thu, 17 Oct 2019 07:16:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ONhbG1YIvRehChglKAzYSee1XpDEhwyMKjBcNaf717M=; b=izYqhpkanZhv6t0j6kpBClORLQTasyQsD+0Gzo76AmET09Nwz3oCwVeKVvCnWqcK3E TyNOXkW5dT3P6CGt/Rx+x8sB1Ik3a4xLeZxeJ4iothxjWl1AZzK4fOylTazICZ6zKUf8 aNBuum4P1RUU3bwxE7c5fd37wXj5rq9hNiUlNyDy5ygC2p10LL8nAoNPbMfqPWMIenHM baUab7D5jGKyK8itXAroeTcFaJO7fVzcKzHRWvIg9h6oWQY4M30FiSKKRfmhXAkuMIlO zPlxiix8uiprFHAQTLcWR7KUHqBkxfMy+eliO50LAOeCbyf73Jfhr277xi1qg8xmaudT edSQ== X-Gm-Message-State: APjAAAUnML6+NPnhv4RauepLt73ZKemZOIaPGtPZrT5Um9P/0GMzRlCy LQP/KMTVXoJC39QM0VEkM/pNzkvkmeVdIVr/XYA= X-Received: by 2002:a9d:5a0f:: with SMTP id v15mr3351385oth.266.1571321813586; Thu, 17 Oct 2019 07:16:53 -0700 (PDT) MIME-Version: 1.0 References: <2811202.iOFZ6YHztY@kreacher> <4551555.oysnf1Sd0E@kreacher> <20191017094143.fhmhgltv6ujccxlp@vireshk-i7> In-Reply-To: <20191017094143.fhmhgltv6ujccxlp@vireshk-i7> From: "Rafael J. Wysocki" Date: Thu, 17 Oct 2019 16:16:40 +0200 Message-ID: Subject: Re: [RFT][PATCH 1/3] PM: QoS: Introduce frequency QoS To: Viresh Kumar Cc: "Rafael J. Wysocki" , Linux PM , Linux ACPI , LKML , Sudeep Holla , Dmitry Osipenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 17, 2019 at 11:41 AM Viresh Kumar wrote: > > On 16-10-19, 12:41, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > Introduce frequency QoS, based on the "raw" low-level PM QoS, to > > represent min and max frequency requests and aggregate constraints. > > > > The min and max frequency requests are to be represented by > > struct freq_qos_request objects and the aggregate constraints are to > > be represented by struct freq_constraints objects. The latter are > > expected to be initialized with the help of freq_constraints_init(). > > > > The freq_qos_read_value() helper is defined to retrieve the aggregate > > constraints values from a given struct freq_constraints object and > > there are the freq_qos_add_request(), freq_qos_update_request() and > > freq_qos_remove_request() helpers to manipulate the min and max > > frequency requests. It is assumed that the the helpers will not > > run concurrently with each other for the same struct freq_qos_request > > object, so if that may be the case, their uses must ensure proper > > synchronization between them (e.g. through locking). > > > > In addition, freq_qos_add_notifier() and freq_qos_remove_notifier() > > are provided to add and remove notifiers that will trigger on aggregate > > constraint changes to and from a given struct freq_constraints object, > > respectively. > > > > Signed-off-by: Rafael J. Wysocki > > --- > > include/linux/pm_qos.h | 44 ++++++++ > > kernel/power/qos.c | 240 +++++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 284 insertions(+) > > > > Index: linux-pm/include/linux/pm_qos.h > > =================================================================== > > --- linux-pm.orig/include/linux/pm_qos.h > > +++ linux-pm/include/linux/pm_qos.h > > @@ -267,4 +267,48 @@ static inline s32 dev_pm_qos_raw_resume_ > > } > > #endif > > > > +#define FREQ_QOS_MIN_DEFAULT_VALUE 0 > > +#define FREQ_QOS_MAX_DEFAULT_VALUE (-1) > > + > > +enum freq_qos_req_type { > > + FREQ_QOS_MIN = 1, > > + FREQ_QOS_MAX, > > +}; > > + > > +struct freq_constraints { > > + struct pm_qos_constraints min_freq; > > + struct blocking_notifier_head min_freq_notifiers; > > + struct pm_qos_constraints max_freq; > > + struct blocking_notifier_head max_freq_notifiers; > > +}; > > + > > +struct freq_qos_request { > > + enum freq_qos_req_type type; > > + struct plist_node pnode; > > + struct freq_constraints *qos; > > +}; > > + > > +static inline int freq_qos_request_active(struct freq_qos_request *req) > > +{ > > + return !IS_ERR_OR_NULL(req->qos); > > +} > > + > > +void freq_constraints_init(struct freq_constraints *qos); > > + > > +s32 freq_qos_read_value(struct freq_constraints *qos, > > + enum freq_qos_req_type type); > > + > > +int freq_qos_add_request(struct freq_constraints *qos, > > + struct freq_qos_request *req, > > + enum freq_qos_req_type type, s32 value); > > +int freq_qos_update_request(struct freq_qos_request *req, s32 new_value); > > +int freq_qos_remove_request(struct freq_qos_request *req); > > + > > +int freq_qos_add_notifier(struct freq_constraints *qos, > > + enum freq_qos_req_type type, > > + struct notifier_block *notifier); > > +int freq_qos_remove_notifier(struct freq_constraints *qos, > > + enum freq_qos_req_type type, > > + struct notifier_block *notifier); > > + > > #endif > > Index: linux-pm/kernel/power/qos.c > > =================================================================== > > --- linux-pm.orig/kernel/power/qos.c > > +++ linux-pm/kernel/power/qos.c > > @@ -650,3 +650,243 @@ static int __init pm_qos_power_init(void > > } > > > > late_initcall(pm_qos_power_init); > > + > > +/* Definitions related to the frequency QoS below. */ > > + > > +/** > > + * freq_constraints_init - Initialize frequency QoS constraints. > > + * @qos: Frequency QoS constraints to initialize. > > + */ > > +void freq_constraints_init(struct freq_constraints *qos) > > +{ > > + struct pm_qos_constraints *c; > > + > > + c = &qos->min_freq; > > + plist_head_init(&c->list); > > + c->target_value = FREQ_QOS_MIN_DEFAULT_VALUE; > > + c->default_value = FREQ_QOS_MIN_DEFAULT_VALUE; > > + c->no_constraint_value = FREQ_QOS_MIN_DEFAULT_VALUE; > > + c->type = PM_QOS_MAX; > > should this be MIN ? No, it shouldn't. For the min frequency, the effective constraint needs to be the maximum of all requests, because that satisfies all of them (each request means "the frequency cannot be less than this"). > > + c->notifiers = &qos->min_freq_notifiers; > > + BLOCKING_INIT_NOTIFIER_HEAD(c->notifiers); > > + > > + c = &qos->max_freq; > > + plist_head_init(&c->list); > > + c->target_value = FREQ_QOS_MAX_DEFAULT_VALUE; > > + c->default_value = FREQ_QOS_MAX_DEFAULT_VALUE; > > + c->no_constraint_value = FREQ_QOS_MAX_DEFAULT_VALUE; > > + c->type = PM_QOS_MIN; > > and this MAX ? Likewise, for the max frequency, the effective constraint needs to be the minimum of all requests, as each of them means "the frequency cannot be more than this"). [Also note that the current code in device PM QoS uses MIN and MAX here in the same way. :-)]