summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorKunhai Dai <daikunhai@didiglobal.com>2026-10-19 08:54:12 -0400
committerJens Axboe <axboe@kernel.dk>2026-10-29 07:38:28 -0600
commit0150554a3f38e1850d5964102eb89a720c5fe789 (patch)
tree382bdf6f48b5a19c7486e7a4fce18e8b05f276be /tools
parentc810ee88cdab27f443c32270dc7c0eaad2cca3f8 (diff)
blk-iocost: publish hweights as one atomic value
current_hweight() publishes the cache generation and both weights with separate stores. Refreshers running on different CPUs can interleave their stores and leave a new generation paired with weights from an older calculation. The compiler can also reorder the generation store before the weight stores, so a reader that sees the new generation can accept stale weights. A stale weight is not only a reporting artifact. It feeds the cost calculation and the donation logic, where an inconsistent combination can lead to a zero divisor in transfer_surpluses(). In addition, the slow path rereads iocg->hweight_active/inuse after publishing them, so the value it returns can be the one written by another refresher instead of the locally computed one. Pack the generation and both weights into a single atomic64_t and publish them with one atomic write. Readers take one atomic snapshot and return the local values. Weights are in [1, WEIGHT_ONE]; storing each minus one preserves the full range in 16 bits and leaves 32 bits for the generation. The two weight fields remain as the donation workspace used under ioc->lock. Tracepoints decode the packed cache without refreshing it and iocost_monitor.py is updated accordingly. Developed with assistance from Claude Code (Anthropic): the assistant drafted the packed representation, the helpers and the tracepoint/monitor changes, and ran the checks listed below. The author reviewed the result and remains responsible for it. Fixes: 7caa47151ab2 ("blkcg: implement blk-iocost") Signed-off-by: Kunhai Dai <daikunhai@didiglobal.com> Tested-by: Tao Cui <cuitao@kylinos.cn> Reviewed-by: Tao Cui <cuitao@kylinos.cn> Acked-by: Tejun Heo <tj@kernel.org> Link: https://patch.msgid.link/20261019125412.3123895-3-daikunhai@didiglobal.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'tools')
-rw-r--r--tools/cgroup/iocost_monitor.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/cgroup/iocost_monitor.py b/tools/cgroup/iocost_monitor.py
index bdd78ba271b0..8a4f844c98d4 100644
--- a/tools/cgroup/iocost_monitor.py
+++ b/tools/cgroup/iocost_monitor.py
@@ -149,8 +149,11 @@ class IocgStat:
self.weight = iocg.weight.value_() / WEIGHT_ONE
self.active = iocg.active.value_() / WEIGHT_ONE
self.inuse = iocg.inuse.value_() / WEIGHT_ONE
- self.hwa_pct = iocg.hweight_active.value_() * 100 / WEIGHT_ONE
- self.hwi_pct = iocg.hweight_inuse.value_() * 100 / WEIGHT_ONE
+ hweight_cache = iocg.hweight_cache.counter.value_()
+ hwa = ((hweight_cache >> 16) & (WEIGHT_ONE - 1)) + 1
+ hwi = (hweight_cache & (WEIGHT_ONE - 1)) + 1
+ self.hwa_pct = hwa * 100 / WEIGHT_ONE
+ self.hwi_pct = hwi * 100 / WEIGHT_ONE
self.address = iocg.value_()
vdone = iocg.done_vtime.counter.value_()