From: Tao Cui <cui.tao@linux.dev>
To: tj@kernel.org, josef@toxicopanda.com, axboe@kernel.dk
Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net,
linux-kselftest@vger.kernel.org, cui.tao@linux.dev,
Tao Cui <cuitao@kylinos.cn>
Subject: [RFC PATCH 5/8] blk-iocost: add ctrl=bpf per-device opt-in
Date: Tue, 8 Sep 2026 18:01:40 +0800 [thread overview]
Message-ID: <20260908100143.47598-6-cui.tao@linux.dev> (raw)
In-Reply-To: <20260908100143.47598-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
Add "bpf" to the ctrl= options in io.cost.model. Writing
"$dev ctrl=bpf" to io.cost.model switches the device to the
registered BPF cost model (if any is registered); ctrl=auto or
ctrl=user switches back to the builtin model.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
block/blk-iocost.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index bdb4bab86a116..a58c16fcb29fa 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -3465,7 +3465,8 @@ static u64 ioc_cost_model_prfill(struct seq_file *sf,
seq_printf(sf, "%s ctrl=%s model=linear "
"rbps=%llu rseqiops=%llu rrandiops=%llu "
"wbps=%llu wseqiops=%llu wrandiops=%llu\n",
- dname, ioc->user_cost_model ? "user" : "auto",
+ dname, ioc->bpf_cost_model ? "bpf" :
+ ioc->user_cost_model ? "user" : "auto",
u[I_LCOEF_RBPS], u[I_LCOEF_RSEQIOPS], u[I_LCOEF_RRANDIOPS],
u[I_LCOEF_WBPS], u[I_LCOEF_WSEQIOPS], u[I_LCOEF_WRANDIOPS]);
spin_unlock_irq(&ioc->lock);
@@ -3505,7 +3506,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
unsigned int memflags;
struct ioc *ioc;
u64 u[NR_I_LCOEFS];
- bool user;
+ bool user, bpf;
char *body, *p;
int ret;
@@ -3536,6 +3537,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
spin_lock_irq(&ioc->lock);
memcpy(u, ioc->params.i_lcoefs, sizeof(u));
user = ioc->user_cost_model;
+ bpf = ioc->bpf_cost_model;
ret = -EINVAL;
@@ -3551,11 +3553,20 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
switch (match_token(p, cost_ctrl_tokens, args)) {
case COST_CTRL:
match_strlcpy(buf, &args[0], sizeof(buf));
- if (!strcmp(buf, "auto"))
+ if (!strcmp(buf, "auto")) {
user = false;
- else if (!strcmp(buf, "user"))
+ bpf = false;
+ } else if (!strcmp(buf, "user")) {
user = true;
- else
+ bpf = false;
+#ifdef CONFIG_BLK_CGROUP_IOCOST_BPF
+ } else if (!strcmp(buf, "bpf")) {
+ if (!iocost_bpf_model_registered())
+ goto unlock;
+ user = false;
+ bpf = true;
+#endif
+ } else
goto unlock;
continue;
case COST_MODEL:
@@ -3580,6 +3591,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input,
} else {
ioc->user_cost_model = false;
}
+ WRITE_ONCE(ioc->bpf_cost_model, bpf);
ioc_refresh_params(ioc, true);
ret = 0;
--
2.43.0
next prev parent reply other threads:[~2026-09-08 10:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 10:01 [RFC PATCH 0/8] blk-iocost: BPF struct_ops cost model Tao Cui
2026-09-08 10:01 ` [RFC PATCH 1/8] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-09-08 10:01 ` [RFC PATCH 2/8] blk-iocost: define iocost_model_ops cost model interface Tao Cui
2026-09-08 20:31 ` Tejun Heo
2026-09-08 10:01 ` [RFC PATCH 3/8] blk-iocost: implement BPF struct_ops registration Tao Cui
2026-09-08 20:31 ` Tejun Heo
2026-09-08 10:01 ` [RFC PATCH 4/8] blk-iocost: dispatch cost calculation to registered BPF model Tao Cui
2026-09-08 20:31 ` Tejun Heo
2026-09-08 10:01 ` Tao Cui [this message]
2026-09-08 10:01 ` [RFC PATCH 6/8] selftests/bpf: add iocost cost model test Tao Cui
2026-09-08 20:31 ` Tejun Heo
2026-09-08 10:01 ` [RFC PATCH 7/8] selftests/bpf: add multi-stream sequentiality example model Tao Cui
2026-09-08 20:31 ` Tejun Heo
2026-09-08 10:01 ` [RFC PATCH 8/8] docs: cgroup-v2: document io.cost ctrl=bpf option Tao Cui
2026-09-08 20:31 ` [RFC PATCH 0/8] blk-iocost: BPF struct_ops cost model Tejun Heo
2026-09-09 13:12 ` Tao Cui
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=20260908100143.47598-6-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=axboe@kernel.dk \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=cuitao@kylinos.cn \
--cc=daniel@iogearbox.net \
--cc=josef@toxicopanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=tj@kernel.org \
/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®