lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tencent_092C538875C434A7CA16B453FBF7B3E46705@qq.com>
Date: Tue, 1 Apr 2025 16:56:09 +0800
From: Yaxiong Tian <iambestgod@...com>
To: Chaitanya Kulkarni <chaitanyak@...dia.com>,
 "kbusch@...nel.org" <kbusch@...nel.org>, "axboe@...nel.dk"
 <axboe@...nel.dk>, "hch@....de" <hch@....de>,
 "sagi@...mberg.me" <sagi@...mberg.me>
Cc: "linux-nvme@...ts.infradead.org" <linux-nvme@...ts.infradead.org>,
 "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
 Yaxiong Tian <tianyaxiong@...inos.cn>
Subject: Re: [PATCH v2 2/3] nvme: add sysfs interface for APST table updates



On 2025/4/1 10:55, Chaitanya Kulkarni wrote:
> On 3/27/25 18:40, Yaxiong Tian wrote:
>> From: Yaxiong Tian <tianyaxiong@...inos.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@...inos.cn>
> 
> by any chance can you please provide a use-case in which scenario
> you need to dynamically updating APST ?
Yes,In desktop systems, users can choose between power-saving mode and 
performance mode. These two modes involve different trade-offs between 
NVMe performance and power efficiency, thus requiring dynamic updates to 
APST. I will update the commit message.
> 
>> ---
>>    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
> 
> 
Thanks, I'll update this in the V3 patch.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ