Skip to content

Commit

Permalink
ledger: Replace saturating_add_assign with Saturating<T> (#3954)
Browse files Browse the repository at this point in the history
  • Loading branch information
roryharr authored Dec 7, 2024
1 parent 8e6b2f8 commit 34069c4
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use {
genesis_config::GenesisConfig,
hash::Hash,
pubkey::Pubkey,
saturating_add_assign,
signature::{Keypair, Signature},
transaction::{
Result, SanitizedTransaction, TransactionError, TransactionVerificationMode,
Expand All @@ -63,6 +62,7 @@ use {
solana_vote::vote_account::VoteAccountsHashMap,
std::{
collections::{HashMap, HashSet},
num::Saturating,
ops::{Index, Range},
path::PathBuf,
result,
Expand Down Expand Up @@ -342,8 +342,8 @@ fn execute_batches_internal(
total_thread_execute_timings.accumulate(&timings);
})
.or_insert(ThreadExecuteTimings {
total_thread_us: execute_batches_us,
total_transactions_executed: transaction_count,
total_thread_us: Saturating(execute_batches_us),
total_transactions_executed: Saturating(transaction_count),
execute_timings: timings,
});
result
Expand Down Expand Up @@ -1258,7 +1258,7 @@ pub struct BatchExecutionTiming {

/// Wall clock time used by the transaction execution part of pipeline.
/// [`ConfirmationTiming::replay_elapsed`] includes this time. In microseconds.
wall_clock_us: u64,
wall_clock_us: Saturating<u64>,

/// Time used to execute transactions, via `execute_batch()`, in the thread that consumed the
/// most time (in terms of total_thread_us) among rayon threads. Note that the slowest thread
Expand Down Expand Up @@ -1286,7 +1286,7 @@ impl BatchExecutionTiming {

// These metric fields aren't applicable for the unified scheduler
if !is_unified_scheduler_enabled {
saturating_add_assign!(*wall_clock_us, new_batch.execute_batches_us);
*wall_clock_us += new_batch.execute_batches_us;

totals.saturating_add_in_place(TotalBatchesLen, new_batch.total_batches_len);
totals.saturating_add_in_place(NumExecuteBatches, 1);
Expand Down Expand Up @@ -1316,8 +1316,8 @@ impl BatchExecutionTiming {

#[derive(Debug, Default)]
pub struct ThreadExecuteTimings {
pub total_thread_us: u64,
pub total_transactions_executed: u64,
pub total_thread_us: Saturating<u64>,
pub total_transactions_executed: Saturating<u64>,
pub execute_timings: ExecuteTimings,
}

Expand All @@ -1327,8 +1327,8 @@ impl ThreadExecuteTimings {
datapoint_info!(
"replay-slot-end-to-end-stats",
("slot", slot as i64, i64),
("total_thread_us", self.total_thread_us as i64, i64),
("total_transactions_executed", self.total_transactions_executed as i64, i64),
("total_thread_us", self.total_thread_us.0 as i64, i64),
("total_transactions_executed", self.total_transactions_executed.0 as i64, i64),
// Everything inside the `eager!` block will be eagerly expanded before
// evaluation of the rest of the surrounding macro.
// Pass false because this code-path is never touched by unified scheduler.
Expand All @@ -1339,11 +1339,8 @@ impl ThreadExecuteTimings {

pub fn accumulate(&mut self, other: &ThreadExecuteTimings) {
self.execute_timings.accumulate(&other.execute_timings);
saturating_add_assign!(self.total_thread_us, other.total_thread_us);
saturating_add_assign!(
self.total_transactions_executed,
other.total_transactions_executed
);
self.total_thread_us += other.total_thread_us;
self.total_transactions_executed += other.total_transactions_executed;
}
}

Expand Down Expand Up @@ -1384,7 +1381,7 @@ impl ReplaySlotStats {
let execute_batches_us = if is_unified_scheduler_enabled {
None
} else {
Some(self.batch_execute.wall_clock_us as i64)
Some(self.batch_execute.wall_clock_us.0 as i64)
};

lazy! {
Expand Down

0 comments on commit 34069c4

Please sign in to comment.