rt: a tally adds only the metrics it counted
The encoder change's tally visited all 25 metrics at each add, at every
encoder's end and again at every commit: on a burst of command buffers of one
dispatch each that is two 25-step loops per command buffer. On the Iris Xe
host (job m3-max-47513, i9-13900H pinned to its performance cores) burst_2000
took 29,285 user-space instructions per command buffer at bfaf8ca194 against
28,581 at 69af14bd22, with the encode time the same (5,852 against 5,788 ns).
The tally now keeps a bit per metric counted, and the add visits those alone:
one atomic add for each metric counted, none for a tally that counted
nothing (a commit with no command between its encoders). Expected to take
the per-command-buffer instructions back under the tip's; to be measured.
This commit is contained in:
1 parent
d2436a1887
commit
9d966c54df
1 file changed
+14
-6
@@ -124,12 +124,18 @@ const _: () = {
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Tally {
|
||||
counts: [u64; METRICS],
|
||||
/// The metrics counted since the tally was last added, a bit each at its index.
|
||||
counted: u32,
|
||||
}
|
||||
|
||||
// Each metric has its bit in a tally's `counted`.
|
||||
const _: () = assert!(METRICS <= u32::BITS as usize);
|
||||
|
||||
impl Tally {
|
||||
/// Counts one more of `metric`.
|
||||
pub(crate) fn count(&mut self, metric: Metric) {
|
||||
self.counts[metric as usize] += 1;
|
||||
self.counted |= 1 << metric as usize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,13 +313,15 @@ impl Counters {
|
||||
self.metric(metric).fetch_add(1, Relaxed);
|
||||
}
|
||||
|
||||
/// Adds what `tally` counted, and leaves it at zero.
|
||||
/// Adds what `tally` counted, and leaves it at zero: one atomic add for each metric it
|
||||
/// counted, and none where it counted nothing.
|
||||
pub(crate) fn add(&self, tally: &mut Tally) {
|
||||
for (metric, count) in METRIC_ORDER.iter().zip(&mut tally.counts) {
|
||||
if *count > 0 {
|
||||
self.metric(*metric).fetch_add(*count, Relaxed);
|
||||
*count = 0;
|
||||
}
|
||||
while tally.counted != 0 {
|
||||
let at = tally.counted.trailing_zeros() as usize;
|
||||
tally.counted &= tally.counted - 1;
|
||||
let count = tally.counts[at];
|
||||
tally.counts[at] = 0;
|
||||
self.metric(METRIC_ORDER[at]).fetch_add(count, Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user