mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: Yaxiong Tian <iambestgod@qq.com>,
	"kbusch@kernel.org" <kbusch@kernel.org>,
	"axboe@kernel.dk" <axboe@kernel.dk>, "hch@lst.de" <hch@lst.de>,
	"sagi@grimberg.me" <sagi@grimberg.me>
Cc: "linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Yaxiong Tian <tianyaxiong@kylinos.cn>
Subject: Re: [PATCH v2 2/3] nvme: add sysfs interface for APST table updates
Date: Tue, 1 Apr 2025 02:55:15 +0000	[thread overview]
Message-ID: <d89c3460-cacf-4df1-bc31-3b710671d699@nvidia.com> (raw)
In-Reply-To: <tencent_29C768845246A8732C6D233A857EC74B6809@qq.com>

On 3/27/25 18:40, Yaxiong Tian wrote:
> From: Yaxiong Tian <tianyaxiong@kylinos.cn>
>
> Currently, the APST (Autonomous Power State Transition) table can only be
> updated during module initialization via module parameters or indirectly
> by setting QoS latency requirements. This patch adds a direct sysfs
> interface to allow dynamic updates to the APST table at runtime.
>
> The new sysfs entry is created at:
> /sys/class/nvme/<controller>/apst_update
>
> This provides more flexibility in power management tuning without
> requiring module reload or QoS latency changes.
>
> Example usage:
> update nvme module parameters.
> echo 1  > /sys/class/nvme/nvme0/apst_update
>
> Signed-off-by: Yaxiong Tian  <tianyaxiong@kylinos.cn>

by any chance can you please provide a use-case in which scenario
you need to dynamically updating APST ?

> ---
>   drivers/nvme/host/core.c  |  9 +++++++--
>   drivers/nvme/host/nvme.h  |  2 ++
>   drivers/nvme/host/sysfs.c | 23 +++++++++++++++++++++++
>   3 files changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index fb0404fee551..9dea1046b8b4 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2654,7 +2654,7 @@ static bool nvme_apst_get_transition_time(u64 total_latency,
>    *
>    * Users can set ps_max_latency_us to zero to turn off APST.
>    */
> -static int nvme_configure_apst(struct nvme_ctrl *ctrl)
> +int nvme_configure_apst(struct nvme_ctrl *ctrl)
>   {
>   	struct nvme_feat_auto_pst *table;
>   	unsigned apste = 0;
> @@ -2778,8 +2778,11 @@ static void nvme_set_latency_tolerance(struct device *dev, s32 val)
>   
>   	if (ctrl->ps_max_latency_us != latency) {
>   		ctrl->ps_max_latency_us = latency;
> -		if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE)
> +		if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE) {
> +			mutex_lock(&ctrl->apst_lock);
>   			nvme_configure_apst(ctrl);
> +			mutex_unlock(&ctrl->apst_lock);
> +		}
>   	}
>   }
>   
> @@ -4852,6 +4855,8 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
>   	ctrl->ka_cmd.common.opcode = nvme_admin_keep_alive;
>   	ctrl->ka_last_check_time = jiffies;
>   
> +	mutex_init(&ctrl->apst_lock);
> +
>   	BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
>   			PAGE_SIZE);
>   	ctrl->discard_page = alloc_page(GFP_KERNEL);
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 51e078642127..7f8e10f5bf7a 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -385,6 +385,7 @@ struct nvme_ctrl {
>   	key_serial_t tls_pskid;
>   
>   	/* Power saving configuration */
> +	struct mutex apst_lock;
>   	u64 ps_max_latency_us;
>   	bool apst_enabled;
>   
> @@ -828,6 +829,7 @@ void nvme_unfreeze(struct nvme_ctrl *ctrl);
>   void nvme_wait_freeze(struct nvme_ctrl *ctrl);
>   int nvme_wait_freeze_timeout(struct nvme_ctrl *ctrl, long timeout);
>   void nvme_start_freeze(struct nvme_ctrl *ctrl);
> +int nvme_configure_apst(struct nvme_ctrl *ctrl);
>   
>   static inline enum req_op nvme_req_op(struct nvme_command *cmd)
>   {
> diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> index 6d31226f7a4f..5003cb294d65 100644
> --- a/drivers/nvme/host/sysfs.c
> +++ b/drivers/nvme/host/sysfs.c
> @@ -684,6 +684,28 @@ static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR,
>   	nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store);
>   #endif
>   
> +static ssize_t apst_update_store(struct device *dev,
> +					      struct device_attribute *attr,
> +					      const char *buf, size_t size)
> +{
> +	int err;
> +	bool bool_data = false;
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);

reverse tree ?

+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	bool bool_data = false;
+	int err;

> +	err = kstrtobool(buf, &bool_data);

add new line above after all the declarations ?

-ck



  reply	other threads:[~2025-04-01  2:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-28  1:38 [PATCH v2 0/3] nvme: Add sysfs interface for APST configuration management Yaxiong Tian
2025-03-28  1:40 ` [PATCH v2 1/3] nvme: Add warning for PST table memory allocation failure in nvme_configure_apst Yaxiong Tian
2025-04-01  2:49   ` Chaitanya Kulkarni
2025-03-28  1:40 ` [PATCH v2 2/3] nvme: add sysfs interface for APST table updates Yaxiong Tian
2025-04-01  2:55   ` Chaitanya Kulkarni [this message]
2025-04-01  8:56     ` Yaxiong Tian
2025-03-28  1:40 ` [PATCH v2 3/3] nvme: add per-controller sysfs interface for APST configuration Yaxiong Tian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d89c3460-cacf-4df1-bc31-3b710671d699@nvidia.com \
    --to=chaitanyak@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=iambestgod@qq.com \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    --cc=tianyaxiong@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®