From: Yaxiong Tian <iambestgod@qq.com>
To: kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me
Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
Yaxiong Tian <tianyaxiong@kylinos.cn>
Subject: [PATCH v2 3/3] nvme: add per-controller sysfs interface for APST configuration
Date: Fri, 28 Mar 2025 09:40:40 +0800 [thread overview]
Message-ID: <tencent_584C480878642207D716B173FEF7ADA47C05@qq.com> (raw)
In-Reply-To: <tencent_4A5421BA11BD9C5B5BF3CEA95FD212AB3107@qq.com>
From: Yaxiong Tian <tianyaxiong@kylinos.cn>
Currently, APST (Autonomous Power State Transition) parameters are
configured as module parameters affecting all controllers uniformly,
This lacks flexibility for heterogeneous systems.
This patch introduces per-controller sysfs attributes under each NVMe
controller's sysfs directory:
- apst_primary_timeout_ms
- apst_secondary_timeout_ms
- apst_primary_latency_tol_us
- apst_secondary_latency_tol_us
The attributes allow runtime configuration of: Timeout values for
primary/secondary states.
The existing module parameters are retained for backward compatibility
but now only serve as default values for new controllers.
Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
---
drivers/nvme/host/core.c | 16 ++++++++++------
drivers/nvme/host/nvme.h | 4 ++++
drivers/nvme/host/sysfs.c | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9dea1046b8b4..c999bd905d10 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2608,22 +2608,22 @@ static int nvme_configure_host_options(struct nvme_ctrl *ctrl)
* timeout value is returned and the matching tolerance index (1 or 2) is
* reported.
*/
-static bool nvme_apst_get_transition_time(u64 total_latency,
+static bool nvme_apst_get_transition_time(struct nvme_ctrl *ctrl, u64 total_latency,
u64 *transition_time, unsigned *last_index)
{
- if (total_latency <= apst_primary_latency_tol_us) {
+ if (total_latency <= ctrl->apst_primary_latency_tol_us) {
if (*last_index == 1)
return false;
*last_index = 1;
- *transition_time = apst_primary_timeout_ms;
+ *transition_time = ctrl->apst_primary_timeout_ms;
return true;
}
if (apst_secondary_timeout_ms &&
- total_latency <= apst_secondary_latency_tol_us) {
+ total_latency <= ctrl->apst_secondary_latency_tol_us) {
if (*last_index <= 2)
return false;
*last_index = 2;
- *transition_time = apst_secondary_timeout_ms;
+ *transition_time = ctrl->apst_secondary_timeout_ms;
return true;
}
return false;
@@ -2728,7 +2728,7 @@ int nvme_configure_apst(struct nvme_ctrl *ctrl)
* for higher power states.
*/
if (apst_primary_timeout_ms && apst_primary_latency_tol_us) {
- if (!nvme_apst_get_transition_time(total_latency_us,
+ if (!nvme_apst_get_transition_time(ctrl, total_latency_us,
&transition_ms, &last_lt_index))
continue;
} else {
@@ -4856,6 +4856,10 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
ctrl->ka_last_check_time = jiffies;
mutex_init(&ctrl->apst_lock);
+ ctrl->apst_primary_timeout_ms = apst_primary_timeout_ms;
+ ctrl->apst_secondary_timeout_ms = apst_secondary_timeout_ms;
+ ctrl->apst_primary_latency_tol_us = apst_primary_latency_tol_us;
+ ctrl->apst_secondary_latency_tol_us = apst_secondary_latency_tol_us;
BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
PAGE_SIZE);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 7f8e10f5bf7a..ed9afc3c6781 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -387,6 +387,10 @@ struct nvme_ctrl {
/* Power saving configuration */
struct mutex apst_lock;
u64 ps_max_latency_us;
+ u64 apst_primary_timeout_ms;
+ u64 apst_secondary_timeout_ms;
+ u64 apst_primary_latency_tol_us;
+ u64 apst_secondary_latency_tol_us;
bool apst_enabled;
/* PCIe only: */
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 5003cb294d65..afa61e9c1366 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -684,6 +684,37 @@ static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR,
nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store);
#endif
+#define nvme_apst_show_and_store_function(field) \
+static ssize_t field##_show(struct device *dev, \
+ struct device_attribute *attr, char *buf) \
+{ \
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
+ return sysfs_emit(buf, "%llu\n", ctrl->field); \
+} \
+ \
+static ssize_t field##_store(struct device *dev, \
+ struct device_attribute *attr, \
+ const char *buf, size_t size) \
+{ \
+ int err; \
+ u64 data = 0; \
+ struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
+ err = kstrtou64(buf, 0, &data); \
+ if (err < 0) \
+ return err; \
+ \
+ mutex_lock(&ctrl->apst_lock); \
+ ctrl->field = data; \
+ mutex_unlock(&ctrl->apst_lock); \
+ return size; \
+} \
+static DEVICE_ATTR_RW(field);
+
+nvme_apst_show_and_store_function(apst_primary_timeout_ms);
+nvme_apst_show_and_store_function(apst_secondary_timeout_ms);
+nvme_apst_show_and_store_function(apst_primary_latency_tol_us);
+nvme_apst_show_and_store_function(apst_secondary_latency_tol_us);
+
static ssize_t apst_update_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
@@ -734,6 +765,11 @@ static struct attribute *nvme_dev_attrs[] = {
&dev_attr_dhchap_ctrl_secret.attr,
#endif
&dev_attr_adm_passthru_err_log_enabled.attr,
+
+ &dev_attr_apst_primary_timeout_ms.attr,
+ &dev_attr_apst_secondary_timeout_ms.attr,
+ &dev_attr_apst_primary_latency_tol_us.attr,
+ &dev_attr_apst_secondary_latency_tol_us.attr,
&dev_attr_apst_update.attr,
NULL
};
--
2.25.1
prev parent reply other threads:[~2025-03-28 1:46 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
2025-04-01 8:56 ` Yaxiong Tian
2025-03-28 1:40 ` Yaxiong Tian [this message]
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=tencent_584C480878642207D716B173FEF7ADA47C05@qq.com \
--to=iambestgod@qq.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--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®