From nobody Fri Dec 19 15:50:11 2025 Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C98D187FFA for ; Wed, 26 Mar 2025 10:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.137 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742984114; cv=none; b=G4yKHdYzBaL71q4iUr4n/XDSDG+qy5lCWmSiSUVq3ZojXbHW2n5YzDLZH+E4khkuIXPWqhEEKipEYTqDuhxCk8xSqgXpRPjBEQDvFtcayUK8CPUsyN60Dj0b5yebPhsbSKjIO/P27SLmKrfSo1XNCZQ0Ajv4WC98gY9+QxBWHlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742984114; c=relaxed/simple; bh=CdInnaW2IoMquTqrJ0EaLqunLOWjgUx9zTs/KAhtqgA=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=kOzUnkz96t/zDqQCU255/TfRc6MLYksdlwn8H7iiQEYp+80txx53QZ54O5bcFBqCFeA+pcUApxpbTQZS/degJGqx20PkElA/LQDkBuA5MjW3WAfe4RhHMyTrbcgWbIgTbIyiFHdfCZK5vuau6pBJ1pO4guikYBsIJDtizOdV7no= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=wi+fRXn0; arc=none smtp.client-ip=162.62.57.137 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="wi+fRXn0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1742984107; bh=PjXUOGWXY+dEUkurv+VbTf8nEAUGXROEdkAf6TL7DIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wi+fRXn0vlqTGbsDsCqCf/OO72c4cxz78MqWCvsFE+t6RrunMMW4Tc3FunG61vZEQ nC40zRQiEYYX5y4ErIKodiSsGmbWe19vMOHZJFNHpqu4v8WCR9KQ2uJCMuvrXrgR6g I59Ja6KE17RNjDYRzWaqgX01j9jirawEr0xpUL0U= Received: from localhost.localdomain ([116.128.244.169]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 3C53A2C6; Wed, 26 Mar 2025 18:15:05 +0800 X-QQ-mid: xmsmtpt1742984105tcv5o0dar Message-ID: X-QQ-XMAILINFO: OakVxA/3u/8RmOETleq5qSYaxMMIZGSFHnTuqvXwD+wdwhyhxE3ajGIfwmEmYX 7rN/G8ggiWvIGXiq6qzeqkhu19z285WgraWDfHA2xlH0Xij4AfdR0uOulp46tASOUrcvkDyuf3Mk +p+hc9sVa/+eXR9mKZ82HvCnI+MVxlSDLwOl+m3zWxcGJ5XjQD75SvFVHPj0axcafhq0+20woQwT BwdNvBObmKGj5JfPHlbNlmooaZDiy9sAoPtYpoYXs5l1spBbspPdHxFDvwr6jZM1iDmJoF2vr6/i v4kPWgYJnwkInJ8hG3wxJirJixPpkFxTVSQOLhBSwpWM8909p4xgMhAdT2+MJplO0lH9tgJwoZi5 4u352/QJmWSYgevQ3L3TY599RxTybjgtsaxchGyzpXZQNhfUEk0Q5OoMZbr7j4k5+/vQCNWiZ1Op o+QPEC76E0KBQwZfc4SB58ppb7jPV0vDizTbh3sovw1NUEw1CIGiRJZ1FcdxHxeQe0YEu0aZ0qsV 0umS5y2RtZxQtXdg3sotFBmaZLaqJeYHfN1VfqMHa+QoXcacsf/hC4HobN/kT3jUppWZYEqYBwc/ X4jvW/9GMenGGTowETfGPKb2pBVsozHUD8rehlFIw9jtBui+K+6n5c0japyFVzdEsD9opXmpETsW pvOBSydFZj19ky8u2WbyDJ7yaT0qP+on9wAYO5TSgCrxgSt0x3NwQkYVnscvVqGrHXUrQWieZbDp /lRXUjHQGzBBCjxp86VcZOt0HeWl1p7QBM43NAcfvaOaDsy1jLtC78DeljYLiS+JZVxw/wIbz1jj mpgtCI8qv8unColQed8KJlqpV/QfwFap3GeV7Dt9q01oTE4+74juLPPCbJUg+lLurDEPq9ER7r30 KCOLBs6O0zwcOGKEmwuKotwUGj390MJJQuXCccQoE3hGdax7tvHkS+siLxQl0PYeEAtcj5G2/QVs P9nDz0yz0= X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= From: Yaxiong Tian 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 Subject: [PATCH 1/3] nvme: Add warning for PST table memory allocation failure in nvme_configure_apst Date: Wed, 26 Mar 2025 18:15:02 +0800 X-OQ-MSGID: <20250326101502.1348301-1-iambestgod@qq.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yaxiong Tian Currently the function fails silently on PST table memory allocation failur= e. Add warning messages to improve error visibility. Signed-off-by: Yaxiong Tian --- drivers/nvme/host/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index c2d89fac86c5..fb0404fee551 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2678,8 +2678,10 @@ static int nvme_configure_apst(struct nvme_ctrl *ctr= l) } =20 table =3D kzalloc(sizeof(*table), GFP_KERNEL); - if (!table) + if (!table) { + dev_warn(ctrl->device, "Failed to allocate pst table; not using APST\n"); return 0; + } =20 if (!ctrl->apst_enabled || ctrl->ps_max_latency_us =3D=3D 0) { /* Turn off APST. */ --=20 2.25.1 From nobody Fri Dec 19 15:50:11 2025 Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 218631C84D3 for ; Wed, 26 Mar 2025 10:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742984599; cv=none; b=B9C7MVBBhmR7ZiAU1YIBAbsPqn6bX0cFMJqR5q4IOfSsQi0ut+cKAlkm57wuxxSXPwFPxbiQFoHsXl2T73zoWMGAYdFgseRHvjTNl+SvG/u+ThfvPu3O3DSh4cfqtH5EQPX+9agAi0M3d9FqBo1xmhvTOn3SCkH9HzfFI0M7TmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742984599; c=relaxed/simple; bh=VRbt9M7GxKWMUSjZmb14cR0Em9o5VMrCRIUA6byEed4=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=hdQuk+lAWqYsprboMRjvk00po4aNgBiDlPWsoWWfoD84HVQNH069fKDr0LgxyRFCAjCkYxPcEv3gEiXLqAsp3hNvweVuKspTvSuEvAKUzvb839JDoSHOD4MoZMbOeDlTr7VWckWMCzLHY2o9icJDtQ6AIZQj5/ijV4qQ4Zzmi/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=K+MJBcRF; arc=none smtp.client-ip=203.205.221.205 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="K+MJBcRF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1742984586; bh=CXOxzSBc81SY9jtwgQfdy/KYkhvUkVXESNbfLq9w2L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K+MJBcRF6OszIxfoDFvYh2uItEZUj8EPw8IwOlsHEyqCvZBuxEbqDlSFHn7TQ4h6T XexjBbvEdPw8RwTWsIwvHYY/XEshW2TE39GhzzjurBdHlaXpy0QFytmSbWYdrKvBO0 u1QHD/HBuKsoLgxfy5u5j9ZyujeT9l8zf8fA98kg= Received: from localhost.localdomain ([116.128.244.169]) by newxmesmtplogicsvrszc13-0.qq.com (NewEsmtp) with SMTP id 42821883; Wed, 26 Mar 2025 18:16:40 +0800 X-QQ-mid: xmsmtpt1742984200t5ml4h1h7 Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9UdRif9mToAQRMObCgm5SPPK0FZCAWaSNErEipKDq/qJrxMW39K Hf48/mxKaoCJI+ntbYnarguqxERydJLbYfn2iYg37vur+LlanSprL/7FNiwLrukYRtcgxIc/Rhhw uGk7jIoUNgb7OL1kqNUG2h9IbubhvEpgykqAi3JViilsu5GqNUeRDZHV4hkUxUcNKsp+l8CVAn1Z ddv6jIAauhLylInwIoWrpLjwVPgj5hixc+QCCsjpV/xO2uAjCouGzFoSXZfrYwvwWYNX5OJUk0rp KHvrrOlOy1iWHNJeSi7vCe8hLibTKjwE8V2dokN20iONZ82aoSJf0VmyYcay2QSd/YLDgHoJHi7+ Jrkg6VD2Lxl/raKGTFtxD0LA21cyJaV6nEh7dfZFHGFQrnauQqKdJ/srNaYep/DiL/8iGePdg/jF Bnp+x9f7gc3oGDtJ40CqJ1IX71tCLayXj4wWJ3U8NDuBEMB9W6L7qvOMWuWWCwzdc4T/iKjT1xlW iTp2eEAeVYXhHSLUrnCDRoKmGOObEcVd4Z/oMTZghEWj7bYqRbRDP0X+OED+ldUcOcgMQV0sqDa8 Z25CYLprgI64CuZj2AvjGgNfXaI5UpBwuGzfVz06cGZ+vqf89VaK66xqeTalVjdh42o0q+oJkEHu 3VRWqi7ZDoO6mmO4d0U75IJYQgds1zhkE9wL5vIaeRBe0WrtGYvSxj850t9KW1qz8hvnGwf0+nml W4i2Z6G1q3nIV1xLU5ZfzU116R2uocPAY9F+3eEeLlJyGLE+xB0foMKW6IBuKbRiq3S+5aLi0pgq dl6MT2f96apYG1CL/MSUoXU2mtEkrFcXBPaN5Azqrvzl73eFwbSe+13rJ4kieHocEca5CZw7BL9G lZxBH05X862IGewuvAQcii6GSzHSDjy3o/Uy0Jl9nbDVQGLi678bOQrndA1p/pGo3cfmN2X+feir RN8KDwxt0JrYlP/XPpCAMdwjGFFG6HE/Pj+vlGyZ0= X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Yaxiong Tian 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 Subject: [PATCH 2/3] nvme: add sysfs interface for APST table updates Date: Wed, 26 Mar 2025 18:16:38 +0800 X-OQ-MSGID: <20250326101638.1353393-1-iambestgod@qq.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yaxiong Tian 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//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 --- drivers/nvme/host/core.c | 4 +++- drivers/nvme/host/nvme.h | 2 ++ drivers/nvme/host/sysfs.c | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index fb0404fee551..cfce433c5553 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_l= atency, * * 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 =3D 0; @@ -4852,6 +4852,8 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct dev= ice *dev, ctrl->ka_cmd.common.opcode =3D nvme_admin_keep_alive; ctrl->ka_last_check_time =3D jiffies; =20 + mutex_init(&ctrl->apst_lock); + BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) > PAGE_SIZE); ctrl->discard_page =3D 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; =20 /* Power saving configuration */ + struct mutex apst_lock; u64 ps_max_latency_us; bool apst_enabled; =20 @@ -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); =20 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_IWU= SR, nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store); #endif =20 +static ssize_t apst_update_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int err; + bool bool_data =3D false; + struct nvme_ctrl *ctrl =3D dev_get_drvdata(dev); + err =3D kstrtobool(buf, &bool_data); + + if (err) + return err; + + if (bool_data && nvme_ctrl_state(ctrl) =3D=3D NVME_CTRL_LIVE) { + mutex_lock(&ctrl->apst_lock); + nvme_configure_apst(ctrl); + mutex_unlock(&ctrl->apst_lock); + } + + return size; +} +static DEVICE_ATTR_WO(apst_update); + static struct attribute *nvme_dev_attrs[] =3D { &dev_attr_reset_controller.attr, &dev_attr_rescan_controller.attr, @@ -712,6 +734,7 @@ static struct attribute *nvme_dev_attrs[] =3D { &dev_attr_dhchap_ctrl_secret.attr, #endif &dev_attr_adm_passthru_err_log_enabled.attr, + &dev_attr_apst_update.attr, NULL }; =20 --=20 2.25.1 From nobody Fri Dec 19 15:50:11 2025 Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B70C1B393A for ; Wed, 26 Mar 2025 10:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.62.57.137 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742984891; cv=none; b=lO+RTOxoHp8wEpVZn0415C4WN+jy+8uDkqDeby7wqfTn7wdIjVeF71mzPJz5niGCTV7t4rWPPhjXnhnFiBFmLfIA5BtQcyqAMOU1/4lvV4mNPY6EAR1ewCbYkcfiP/wMvjX3dujkJfFbP9xsd3ZSHWisCeMrZ8wQla/iO+pZ/Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742984891; c=relaxed/simple; bh=A7g5erTEnWIkdsckGVi5/bPrn40Wn5Avc/udvTqcAlU=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=n/nvv4FyAKe9mRKGijlrcfD7HWT9NH4kwgBQSNdT6zjB5a6DEnk7zNAgkfchry+SmuRfZ34RnCBvuQIIUxl2aNa5Gt41tbIR+K/qotFN0enXYrK5ASOyJGn3iPmTggTscedbeq30h8f3RN374KvnBegVX7Z6s+WLnM4sfsPXr80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b=qzi9hM7q; arc=none smtp.client-ip=162.62.57.137 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="qzi9hM7q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1742984582; bh=nIaOFhNr84R9BlJ0iJwxhdXvtzXEDs/CGd+I1BsLjh0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qzi9hM7q5fW8H7Vf9Juf3Klw6OcWMHhF591iQupFGjYf7KkUohxbPh3bG6H2Le5OH jqSGKTT3enKWJ7GtsvJbtpf2wp2LhvfIa8Feyy0JBhtPYzPXk33bf1Cgs6lFOx609t Ud38oRujYXH2MOmYZ2POrBKUFPLRQjC0f+CmB2vU= Received: from localhost.localdomain ([116.128.244.169]) by newxmesmtplogicsvrsza29-0.qq.com (NewEsmtp) with SMTP id 43082E52; Wed, 26 Mar 2025 18:16:48 +0800 X-QQ-mid: xmsmtpt1742984208tkq0zmhro Message-ID: X-QQ-XMAILINFO: NafziRg7Bx696PoZE8VmuxEuxwmZMVJQIksu4ZfLmGJoCOTEgcoPo1ff7ggK/H Kod8y2SAecEIqw1/OwCgUmU4jTQq6brgETveUD72MbRi/Juz0waQQEpmOWnclXYtQ+N9c0RByNUp PImdAy9GM9nodXP7FH0B+gM18NNKPJmM0UYGzVNK2XHE0eBJ/0S33pu0rdUPsERP/2UJFQjx4Zsj gJEBvoJcMeaxjJ9puxyPjdoQnAcpAqHKm2fsuXHPprpQS08dZjZf4wEaXVM3tLPD7D842ZRTB49K mLZlo/u7eeAzT830/OsthGur6+eg8P1EHKuXa9m5/PbfNFIcqbz/wT4+ZO33yq2DYPcRx6atiJHB ttstHL8YUQ2qG1rKwKkF1RlKc0m8/zt6r1UaUyk3hu9XwZ85kg+Nt+IlN3DDVGZlQoyxEgPkZ0MT busOxDFBx8iP6fOSgU/RI2HB3JF43d52gU3UqocmMpDJwIQv1v7sQxCUZ80RLyGzxLxt2JPXXIDq /LWS9QpmcZaEk4v07jxN/sFkCUvfUiL9U0AT+xM7/j6I7hK9hfotleEVimUydlUpCLarRC8XLx6F Bm3n+hFjhn4XrLZd0PYHCyPhAI8vfc37e6iEEJMNecDbGEzwXwzcrxOEvijeAugUMpS0YsiWbCb4 +NvlyxkT7Id7bA6G9gQot54teUOGBMxMpQ0KUyHcKRDOVhBoRSE5vqIYGPKTS1L3+kXeIYV02NEr /XisoCNbu2Oo4frtE89gwGwIE0fYcvMCN3SBqlATpMYHdTjX2M/APkYkQBs7kxIEn5eDmnzM0JEY QtOShWsyxMLtX3k3cvP6aBMDcikFZOcuC1nb48l3s7UpLJWofSzlYqv4inFNh+Fzh1WKh0598zDn +kW6IGSv6hoX9/NJNYRJtqIr2WHvczkkBggt/YANdQqq+56/0P5wcAgK1NpAHwznw6At4AoUdQBY L1I7+TNHjaWoCoOwmtOA== X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= From: Yaxiong Tian 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 Subject: [PATCH 3/3] nvme: add per-controller sysfs interface for APST configuration Date: Wed, 26 Mar 2025 18:16:47 +0800 X-OQ-MSGID: <20250326101647.1353882-1-iambestgod@qq.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yaxiong Tian 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: 1. Timeout values for primary/secondary states 2. Latency tolerance requirements The existing module parameters are retained for backward compatibility but now only serve as default values for new controllers. Signed-off-by: Yaxiong Tian --- 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 cfce433c5553..812e0a1f3b53 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 tota= l_latency, u64 *transition_time, unsigned *last_index) { - if (total_latency <=3D apst_primary_latency_tol_us) { + if (total_latency <=3D ctrl->apst_primary_latency_tol_us) { if (*last_index =3D=3D 1) return false; *last_index =3D 1; - *transition_time =3D apst_primary_timeout_ms; + *transition_time =3D ctrl->apst_primary_timeout_ms; return true; } if (apst_secondary_timeout_ms && - total_latency <=3D apst_secondary_latency_tol_us) { + total_latency <=3D ctrl->apst_secondary_latency_tol_us) { if (*last_index <=3D 2) return false; *last_index =3D 2; - *transition_time =3D apst_secondary_timeout_ms; + *transition_time =3D 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 { @@ -4853,6 +4853,10 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct de= vice *dev, ctrl->ka_last_check_time =3D jiffies; =20 mutex_init(&ctrl->apst_lock); + ctrl->apst_primary_timeout_ms =3D apst_primary_timeout_ms; + ctrl->apst_secondary_timeout_ms =3D apst_secondary_timeout_ms; + ctrl->apst_primary_latency_tol_us =3D apst_primary_latency_tol_us; + ctrl->apst_secondary_latency_tol_us =3D apst_secondary_latency_tol_us; =20 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; =20 /* 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_IWU= SR, nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store); #endif =20 +#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 =3D 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 =3D 0; \ + struct nvme_ctrl *ctrl =3D dev_get_drvdata(dev); \ + err =3D kstrtou64(buf, 0, &data); \ + if (err < 0) \ + return err; \ + \ + mutex_lock(&ctrl->apst_lock); \ + ctrl->field =3D 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[] =3D { &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 }; --=20 2.25.1