Skip to content

Commit

Permalink
rename variables
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Oct 16, 2024
1 parent 29a7e6b commit d5fccc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions tokio-epoll-uring/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ use once_cell::sync::Lazy;
pub struct Metrics {
pub systems_created: u64,
pub systems_destroyed: u64,
pub waiters_queue_depth: Vec<u64>,
pub slots_waiters_queue_depth: Vec<u64>,
}

pub(crate) struct MetricsStorage {
pub(crate) systems_created: AtomicU64,
pub(crate) systems_destroyed: AtomicU64,
/// Waiters queue depth for active system, indexed by system id.
pub(crate) waiters_queue_depth: Lazy<RwLock<HashMap<usize, AtomicU64>>>,
pub(crate) slots_waiters_queue_depth: Lazy<RwLock<HashMap<usize, AtomicU64>>>,
}

impl MetricsStorage {
pub(crate) const fn new_const() -> Self {
MetricsStorage {
systems_created: AtomicU64::new(0),
systems_destroyed: AtomicU64::new(0),
waiters_queue_depth: Lazy::new(|| RwLock::new(HashMap::new())),
slots_waiters_queue_depth: Lazy::new(|| RwLock::new(HashMap::new())),
}
}
}
Expand All @@ -36,31 +36,31 @@ impl MetricsStorage {
pub(crate) fn new_system(&self, id: usize) {
self.systems_created.fetch_add(1, Ordering::Relaxed);
// write lock needed to insert a new waiters queue depth entry.
let mut g = self.waiters_queue_depth.write().unwrap();
let mut g = self.slots_waiters_queue_depth.write().unwrap();
g.insert(id, AtomicU64::new(0));
}

/// Updates metrics at system destruction.
pub(crate) fn destroy_system(&self, id: usize) {
self.systems_destroyed.fetch_add(1, Ordering::Relaxed);
// write lock needed to remove a waiters queue depth entry.
let mut g = self.waiters_queue_depth.write().unwrap();
let mut g = self.slots_waiters_queue_depth.write().unwrap();
g.remove(&id);
}

/// Updates waiters queue depth metric for system with `id`.
pub(crate) fn update_waiters_queue_depth(&self, id: usize, depth: u64) {
pub(crate) fn update_slots_waiters_queue_depth(&self, id: usize, depth: u64) {
// Since each waiters queue depth value is atomic, only take a read lock to reduce contention.
let g = self.waiters_queue_depth.read().unwrap();
let g = self.slots_waiters_queue_depth.read().unwrap();
g.get(&id).unwrap().store(depth, Ordering::Relaxed);
}

fn make_pub(&self) -> Metrics {
Metrics {
systems_created: GLOBAL_STORAGE.systems_created.load(Ordering::Relaxed),
systems_destroyed: GLOBAL_STORAGE.systems_destroyed.load(Ordering::Relaxed),
waiters_queue_depth: {
let g = GLOBAL_STORAGE.waiters_queue_depth.read().unwrap();
slots_waiters_queue_depth: {
let g = GLOBAL_STORAGE.slots_waiters_queue_depth.read().unwrap();
g.values().map(|x| x.load(Ordering::Relaxed)).collect()
},
}
Expand Down
6 changes: 3 additions & 3 deletions tokio-epoll-uring/src/system/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl SlotsInner {
clear_slot(&mut self.storage[idx]);
while let Some(waiter) = waiters.pop_front() {
self.metrics_storage
.update_waiters_queue_depth(self.id, waiters.len() as u64);
.update_slots_waiters_queue_depth(self.id, waiters.len() as u64);
match waiter.send(SlotHandle {
slots_weak: myself.clone(),
idx,
Expand Down Expand Up @@ -345,7 +345,7 @@ impl Slots<{ co_owner::COMPLETION_SIDE }> {
inner_guard.state = SlotsInnerState::Draining;
inner_guard
.metrics_storage
.update_waiters_queue_depth(self.id, 0);
.update_slots_waiters_queue_depth(self.id, 0);
}
SlotsInnerState::Draining => {}
}
Expand Down Expand Up @@ -422,7 +422,7 @@ impl Slots<{ co_owner::SUBMIT_SIDE }> {
waiters.push_back(wake_up_tx);
inner
.metrics_storage
.update_waiters_queue_depth(inner.id, waiters.len() as u64);
.update_slots_waiters_queue_depth(inner.id, waiters.len() as u64);
TryGetSlotResult::NoSlots(wake_up_rx)
}
},
Expand Down

0 comments on commit d5fccc5

Please sign in to comment.