From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59D71CE7A9F for ; Thu, 5 Sep 2024 21:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=K5uxU3Mym+2GWfPnVlq3auuUpj09qNie62HH+eIuAv4=; b=Eoqz1PTApjQINGkuZzxQT6fJNx WzVbKaphCWwHiuNqW/w+eUzoc9IzdpScQ5C4yMJgZNGUPtqyLuua1WkPlbzqNn93xjDubykf5ptKQ LNocO3EYJqQ/Fju9bANuq4ijesoo6vYKsm+eJVnETGriBK3m28Kcf8kCTUZftuZNUweb2xkbkHsRH 7kofCFVrKIbgMcEOB805mr5BE9FI4Upk1J/yLEM6E9rscYxqQDKZevpevB4h3AywZbBqy1yZwp42q y6bcWH9m0+UUYjBixFiRTOxG1qrhkXZwxZ4ZSnTSZfzvWD9OiCkKeqCJgeI8i2gpvJ91Uz7kDyfXf VgA6b7eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smKVG-00000009weX-1toN; Thu, 05 Sep 2024 21:58:58 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smKU9-00000009wSK-0aub for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 21:58:00 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-718d6ad6050so91405b3a.0 for ; Thu, 05 Sep 2024 14:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1725573468; x=1726178268; darn=lists.infradead.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=K5uxU3Mym+2GWfPnVlq3auuUpj09qNie62HH+eIuAv4=; b=YUAtd42V1teQwzhP4jafJGjvGZuwhvKHva1qL4bK/Qbn8P9+gx1rXaiPeSGvwNx1GB oMUMGHVnGBhthxps5l7n0/lU7zZLPQ7sfwxbMdopI+XQ5B9X6dRWPaPDGSjNcgHxu3Ks /oX8q3f5NNRt+2pNll9tyX0Hy0hTNIpFC67pTgcB9QqqC4QiuP5M+uBFv2BTrsqBJU+9 3l/Fqrpuji2uSPzRnxuy8AsrO2NrtJXzQrIA/sx4bgNV0RpLl6TL3lgihQ3yzAmwBJif G+y1vX3CLefSf/50J5jLAVXIIsKXtyAq2X5xBbfGCjsSjhBEugfGKx5HCTACkFLU0OJb Ruvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725573468; x=1726178268; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=K5uxU3Mym+2GWfPnVlq3auuUpj09qNie62HH+eIuAv4=; b=lbZs2UDVpDEJcnHMWOfoiF7fSW7JT9OyAwR0wNp7AyMnLdyS/CGMmdLkaFRI11X5rw 4/+gSHB4epzsWBdUX88sYRxxoGVuPwJdd/QO9TPhK33fSP4BXzrSqm/iMkQUa2XnbFFw ivq+7I8ovNjhFCX5UZoA47tamxnLmAa5d6emzyNfN4Chf7zT8oifv9NwHL93YRxybb51 h/EzFyiX30K6FbhqJzkYEQi9JiQhAKrKfu5L2hgr/1DWStpf4/WbOIzgAcrQiN7eQHX0 xzmZWXngVV9EzYO6WlVbvuYe0HfyFEzkqPGx98FCh9Y9CsJEdd0K6TMu8BTX3a5XmaIw phsw== X-Forwarded-Encrypted: i=1; AJvYcCUG3YlLzSIEB2ZNfdmaqCUS7M4eRgcPH65P2tWjGEMUFmAQguM5L3EV1StMNJaLg87/pd3Vi1XSdSimXCjW4IFf@lists.infradead.org X-Gm-Message-State: AOJu0YxJKqW/iKJZZSnI9I3nHND9mfmPxpy0X0QXbfUKuXVLPbeeYoi4 8TMFfM1PUdUWfeNDdLGe6bdxVcAClEvCsAKzKIGFmKWt+GQni9EAIS/QpGQsaQU= X-Google-Smtp-Source: AGHT+IHAPn3RVf2uJDWJ+hk2j9RtamPe9RCojFCbc6OeYtlorF2xMrn6wBlQMxhRU6Ra9JTw9o4xYw== X-Received: by 2002:a05:6a21:170f:b0:1c0:ede4:9a73 with SMTP id adf61e73a8af0-1cf1d059a9amr442963637.7.1725573467903; Thu, 05 Sep 2024 14:57:47 -0700 (PDT) Received: from localhost ([71.212.170.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71782eb5352sm2675469b3a.154.2024.09.05.14.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 14:57:47 -0700 (PDT) From: Kevin Hilman To: Ulf Hansson Cc: linux-pm@vger.kernel.org, Nishanth Menon , Vibhore Vardhan , Dhruva Gole , Akashdeep Kaur , Sebin Francis , Markus Schneider-Pargmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/3] pmdomain: ti_sci: add per-device latency constraint management In-Reply-To: References: <20240819-lpm-v6-10-constraints-pmdomain-v2-0-461325a6008f@baylibre.com> <20240819-lpm-v6-10-constraints-pmdomain-v2-1-461325a6008f@baylibre.com> Date: Thu, 05 Sep 2024 14:57:47 -0700 Message-ID: <7hv7z9ahlw.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_145749_208204_0EE11631 X-CRM114-Status: GOOD ( 27.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Ulf Hansson writes: > On Tue, 20 Aug 2024 at 02:00, Kevin Hilman wrote: >> >> For each device in a TI SCI PM domain, check whether the device has >> any resume latency constraints set via per-device PM QoS. If >> constraints are set, send them to DM via the new SCI constraints API. >> >> Checking for constraints happen for each device before system-wide >> suspend (via ->suspend() hook.) >> >> An important detail here is that the PM domain driver inserts itself >> into the path of both the ->suspend() and ->resume() hook path >> of *all* devices in the PM domain. This allows generic PM domain code >> to handle the constraint management and communication with TI SCI. >> >> Further, this allows device drivers to use existing PM QoS APIs to >> add/update constraints. >> >> DM firmware clears constraints during its resume, so Linux has >> to check/update/send constraints each time system suspends. >> >> Co-developed-by: Vibhore Vardhan >> Signed-off-by: Vibhore Vardhan >> Signed-off-by: Kevin Hilman >> Signed-off-by: Dhruva Gole >> --- >> drivers/pmdomain/ti/ti_sci_pm_domains.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 48 insertions(+) >> >> diff --git a/drivers/pmdomain/ti/ti_sci_pm_domains.c b/drivers/pmdomain/ti/ti_sci_pm_domains.c >> index 1510d5ddae3d..963272fa387b 100644 >> --- a/drivers/pmdomain/ti/ti_sci_pm_domains.c >> +++ b/drivers/pmdomain/ti/ti_sci_pm_domains.c >> @@ -13,6 +13,8 @@ >> #include >> #include >> #include >> +#include >> +#include >> #include >> #include >> >> @@ -51,6 +53,29 @@ struct ti_sci_pm_domain { >> >> #define genpd_to_ti_sci_pd(gpd) container_of(gpd, struct ti_sci_pm_domain, pd) >> >> +static inline bool ti_sci_pd_is_valid_constraint(s32 val) >> +{ >> + return val != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; >> +} > > Should we perhaps add a generic helper function for this? Seems like a > similar check is done at other places in the kernel too. Maybe, but I don't see a lot of this same usage under drivers/*. But I'll have a closer look for a follow-up patch that might be able to make a common helper for this. >> + >> +static int ti_sci_pd_set_lat_constraint(struct device *dev, s32 val) >> +{ > > Looks like you may want to turn this into a static void rather than > static int. At least the caller, below, doesn't care about the return > value. Yup, OK. >> + struct generic_pm_domain *genpd = pd_to_genpd(dev->pm_domain); >> + struct ti_sci_pm_domain *pd = genpd_to_ti_sci_pd(genpd); >> + const struct ti_sci_handle *ti_sci = pd->parent->ti_sci; >> + int ret; >> + >> + ret = ti_sci->ops.pm_ops.set_latency_constraint(ti_sci, val, TISCI_MSG_CONSTRAINT_SET); >> + if (ret) >> + dev_err(dev, "ti_sci_pd: set latency constraint failed: ret=%d\n", >> + ret); >> + else >> + dev_dbg(dev, "ti_sci_pd: ID:%d set latency constraint %d\n", >> + pd->idx, val); >> + >> + return ret; >> +} >> + >> /* >> * ti_sci_pd_power_off(): genpd power down hook >> * @domain: pointer to the powerdomain to power off >> @@ -79,6 +104,22 @@ static int ti_sci_pd_power_on(struct generic_pm_domain *domain) >> return ti_sci->ops.dev_ops.get_device(ti_sci, pd->idx); >> } >> >> +static int ti_sci_pd_suspend(struct device *dev) >> +{ >> + int ret; >> + s32 val; >> + >> + ret = pm_generic_suspend(dev); >> + if (ret) >> + return ret; >> + >> + val = dev_pm_qos_read_value(dev, DEV_PM_QOS_RESUME_LATENCY); >> + if (ti_sci_pd_is_valid_constraint(val)) >> + ti_sci_pd_set_lat_constraint(dev, val); >> + >> + return 0; >> +} >> + >> /* >> * ti_sci_pd_xlate(): translation service for TI SCI genpds >> * @genpdspec: DT identification data for the genpd >> @@ -188,6 +229,13 @@ static int ti_sci_pm_domain_probe(struct platform_device *pdev) >> pd->pd.power_on = ti_sci_pd_power_on; >> pd->idx = args.args[0]; >> pd->parent = pd_provider; >> + /* >> + * If SCI constraint functions are present, then firmware >> + * supports the constraints API. >> + */ >> + if (pd_provider->ti_sci->ops.pm_ops.set_device_constraint && >> + pd_provider->ti_sci->ops.pm_ops.set_latency_constraint) >> + pd->pd.domain.ops.suspend = ti_sci_pd_suspend; >> >> pm_genpd_init(&pd->pd, NULL, true); >> >> >> -- >> 2.46.0 >> > > Other than the minor things above, this looks good to me. Thanks for the review! Will spin a v3 shortly. Kevin