Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce InstalledSchedulerPool trait #33934

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ edition = "2021"

[workspace.dependencies]
Inflector = "0.11.4"
aquamarine = "0.3.2"
aes-gcm-siv = "0.10.3"
ahash = "0.8.6"
anyhow = "1.0.75"
Expand Down
22 changes: 21 additions & 1 deletion ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,9 @@ pub mod tests {
genesis_utils::{
self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
},
installed_scheduler_pool::{MockInstalledScheduler, WaitReason},
installed_scheduler_pool::{
MockInstalledScheduler, MockInstalledSchedulerPool, WaitReason,
},
},
solana_sdk::{
account::{AccountSharedData, WritableAccount},
Expand Down Expand Up @@ -4532,6 +4534,11 @@ pub mod tests {

let mut mocked_scheduler = MockInstalledScheduler::new();
let mut seq = mockall::Sequence::new();
mocked_scheduler
.expect_context()
.times(1)
.in_sequence(&mut seq)
.returning(|| None);
mocked_scheduler
.expect_schedule_execution()
.times(txs.len())
Expand All @@ -4542,6 +4549,19 @@ pub mod tests {
.times(1)
.in_sequence(&mut seq)
.returning(|_| None);
mocked_scheduler
.expect_pool()
.times(1)
.in_sequence(&mut seq)
.returning(move || {
let mut mocked_pool = MockInstalledSchedulerPool::new();
mocked_pool
.expect_return_to_pool()
.times(1)
.in_sequence(&mut seq)
.returning(|_| ());
Arc::new(mocked_pool)
});
let bank = BankWithScheduler::new(bank, Some(Box::new(mocked_scheduler)));

let batch = bank.prepare_sanitized_batch(&txs);
Expand Down
34 changes: 34 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
aquamarine = { workspace = true }
arrayref = { workspace = true }
base64 = { workspace = true }
bincode = { workspace = true }
Expand Down
23 changes: 21 additions & 2 deletions runtime/src/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use {
crate::{
accounts_background_service::{AbsRequestSender, SnapshotRequest, SnapshotRequestKind},
bank::{epoch_accounts_hash_utils, Bank, SquashTiming},
installed_scheduler_pool::BankWithScheduler,
installed_scheduler_pool::{
BankWithScheduler, InstalledSchedulerPoolArc, SchedulingContext,
},
snapshot_config::SnapshotConfig,
},
log::*,
Expand Down Expand Up @@ -72,6 +74,7 @@ pub struct BankForks {
last_accounts_hash_slot: Slot,
in_vote_only_mode: Arc<AtomicBool>,
highest_slot_at_startup: Slot,
scheduler_pool: Option<InstalledSchedulerPoolArc>,
}

impl Index<u64> for BankForks {
Expand Down Expand Up @@ -203,6 +206,7 @@ impl BankForks {
last_accounts_hash_slot: root,
in_vote_only_mode: Arc::new(AtomicBool::new(false)),
highest_slot_at_startup: 0,
scheduler_pool: None,
}));

for bank in bank_forks.read().unwrap().banks.values() {
Expand All @@ -215,11 +219,26 @@ impl BankForks {
bank_forks
}

pub fn install_scheduler_pool(&mut self, pool: InstalledSchedulerPoolArc) {
info!("Installed new scheduler_pool into bank_forks: {:?}", pool);
assert!(
self.scheduler_pool.replace(pool).is_none(),
"Reinstalling scheduler pool isn't supported"
);
}

pub fn insert(&mut self, mut bank: Bank) -> BankWithScheduler {
bank.check_program_modification_slot =
self.root.load(Ordering::Relaxed) < self.highest_slot_at_startup;

let bank = BankWithScheduler::new_without_scheduler(Arc::new(bank));
let bank = Arc::new(bank);
let bank = if let Some(scheduler_pool) = &self.scheduler_pool {
let context = SchedulingContext::new(bank.clone());
let scheduler = scheduler_pool.take_from_pool(context);
BankWithScheduler::new(bank, Some(scheduler))
} else {
BankWithScheduler::new_without_scheduler(bank)
};
let prev = self.banks.insert(bank.slot(), bank.clone_with_scheduler());
assert!(prev.is_none());
let slot = bank.slot();
Expand Down
Loading