mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-01 17:35:19 +00:00
virtio-devices: block: Fix latency counter for average read/write
The cumulative average formula [1] requires to use signed integers for proper calculations, while calculated result (e.g. cumulative average) is always positive. This patch reflects the above requirements in our code. [1] https://en.wikipedia.org/wiki/Moving_average#Cumulative_average Fixes: #5745 Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
e151483f70
commit
b76d0e8b50
@ -309,9 +309,13 @@ impl BlockEpollHandler {
|
|||||||
read_avg = if read_avg == u64::MAX {
|
read_avg = if read_avg == u64::MAX {
|
||||||
latency * LATENCY_SCALE
|
latency * LATENCY_SCALE
|
||||||
} else {
|
} else {
|
||||||
read_avg
|
// Cumulative average is guaranteed to be
|
||||||
+ ((latency * LATENCY_SCALE) - read_avg)
|
// positive if being calculated properly
|
||||||
/ (read_ops_last + read_ops.0)
|
(read_avg as i64
|
||||||
|
+ ((latency * LATENCY_SCALE) as i64 - read_avg as i64)
|
||||||
|
/ (read_ops_last + read_ops.0) as i64)
|
||||||
|
.try_into()
|
||||||
|
.unwrap()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
RequestType::Out => {
|
RequestType::Out => {
|
||||||
@ -339,10 +343,14 @@ impl BlockEpollHandler {
|
|||||||
write_avg = if write_avg == u64::MAX {
|
write_avg = if write_avg == u64::MAX {
|
||||||
latency * LATENCY_SCALE
|
latency * LATENCY_SCALE
|
||||||
} else {
|
} else {
|
||||||
write_avg
|
// Cumulative average is guaranteed to be
|
||||||
+ ((latency * LATENCY_SCALE) - write_avg)
|
// positive if being calculated properly
|
||||||
/ (write_ops_last + write_ops.0)
|
(write_avg as i64
|
||||||
};
|
+ ((latency * LATENCY_SCALE) as i64 - write_avg as i64)
|
||||||
|
/ (write_ops_last + write_ops.0) as i64)
|
||||||
|
.try_into()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user