Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use {
IndexOfAccount, InstructionAccount, TransactionAccount, TransactionContext,
MAX_ACCOUNTS_PER_TRANSACTION,
},
solana_type_overrides::sync::{atomic::Ordering, Arc},
solana_type_overrides::sync::Arc,
std::{
alloc::Layout,
cell::RefCell,
Expand Down Expand Up @@ -593,7 +593,6 @@ impl<'a> InvokeContext<'a> {
_ => None,
}
.ok_or(InstructionError::UnsupportedProgramId)?;
entry.ix_usage_counter.fetch_add(1, Ordering::Relaxed);

let program_id = *instruction_context.get_program_key(self.transaction_context)?;
self.transaction_context
Expand Down
137 changes: 69 additions & 68 deletions program-runtime/src/loaded_programs.rs

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ pub fn deploy_program(
old_entry.tx_usage_counter.load(Ordering::Relaxed),
Ordering::Relaxed,
);
executor.ix_usage_counter.store(
old_entry.ix_usage_counter.load(Ordering::Relaxed),
Ordering::Relaxed,
);
}
load_program_metrics.program_id = program_id.to_string();
program_cache_for_tx_batch.store_modified_entry(*program_id, Arc::new(executor));
Expand Down Expand Up @@ -452,7 +448,6 @@ pub(crate) fn process_instruction_inner(
get_or_create_executor_time.stop();
invoke_context.timings.get_or_create_executor_us += get_or_create_executor_time.as_us();

executor.ix_usage_counter.fetch_add(1, Ordering::Relaxed);
match &executor.program {
ProgramCacheEntryType::FailedVerification(_)
| ProgramCacheEntryType::Closed
Expand Down Expand Up @@ -4105,8 +4100,7 @@ mod tests {
account_size: 0,
deployment_slot: 0,
effective_slot: 0,
tx_usage_counter: AtomicU64::new(100),
ix_usage_counter: AtomicU64::new(100),
tx_usage_counter: Arc::new(AtomicU64::new(100)),
latest_access_slot: AtomicU64::new(0),
};
invoke_context
Expand All @@ -4128,10 +4122,6 @@ mod tests {
updated_program.tx_usage_counter.load(Ordering::Relaxed),
100
);
assert_eq!(
updated_program.ix_usage_counter.load(Ordering::Relaxed),
100
);
}

#[test]
Expand All @@ -4149,8 +4139,7 @@ mod tests {
account_size: 0,
deployment_slot: 0,
effective_slot: 0,
tx_usage_counter: AtomicU64::new(100),
ix_usage_counter: AtomicU64::new(100),
tx_usage_counter: Arc::new(AtomicU64::new(100)),
latest_access_slot: AtomicU64::new(0),
};
invoke_context
Expand All @@ -4170,6 +4159,5 @@ mod tests {

assert_eq!(program2.deployment_slot, 2);
assert_eq!(program2.tx_usage_counter.load(Ordering::Relaxed), 0);
assert_eq!(program2.ix_usage_counter.load(Ordering::Relaxed), 0);
}
}
5 changes: 1 addition & 4 deletions programs/loader-v4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use {
solana_sbpf::{declare_builtin_function, memory_region::MemoryMapping},
solana_sdk_ids::{bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4},
solana_transaction_context::{BorrowedAccount, InstructionContext},
solana_type_overrides::sync::{atomic::Ordering, Arc},
solana_type_overrides::sync::Arc,
std::{cell::RefCell, rc::Rc},
};

Expand Down Expand Up @@ -499,9 +499,6 @@ fn process_instruction_inner(
get_or_create_executor_time.stop();
invoke_context.timings.get_or_create_executor_us += get_or_create_executor_time.as_us();
drop(program);
loaded_program
.ix_usage_counter
.fetch_add(1, Ordering::Relaxed);
match &loaded_program.program {
ProgramCacheEntryType::FailedVerification(_)
| ProgramCacheEntryType::Closed
Expand Down
50 changes: 31 additions & 19 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,15 +1447,15 @@ impl Bank {
report_loaded_programs_stats(
&parent
.transaction_processor
.program_cache
.global_program_cache
.read()
.unwrap()
.stats,
parent.slot(),
);

new.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.stats
Expand All @@ -1466,7 +1466,7 @@ impl Bank {

pub fn set_fork_graph_in_program_cache(&self, fork_graph: Weak<RwLock<BankForks>>) {
self.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.set_fork_graph(fork_graph);
Expand All @@ -1490,15 +1490,19 @@ impl Bank {
.checked_div(2)
.unwrap();

let mut program_cache = self.transaction_processor.program_cache.write().unwrap();
let mut program_cache = self
.transaction_processor
.global_program_cache
.write()
.unwrap();

if program_cache.upcoming_environments.is_some() {
if let Some((key, program_to_recompile)) = program_cache.programs_to_recompile.pop() {
let effective_epoch = program_cache.latest_root_epoch.saturating_add(1);
drop(program_cache);
let environments_for_epoch = self
.transaction_processor
.program_cache
.global_program_cache
.read()
.unwrap()
.get_environments_for_epoch(effective_epoch);
Expand All @@ -1516,14 +1520,11 @@ impl Bank {
.load(Ordering::Relaxed),
Ordering::Relaxed,
);
recompiled.ix_usage_counter.fetch_add(
program_to_recompile
.ix_usage_counter
.load(Ordering::Relaxed),
Ordering::Relaxed,
);
let mut program_cache =
self.transaction_processor.program_cache.write().unwrap();
let mut program_cache = self
.transaction_processor
.global_program_cache
.write()
.unwrap();
program_cache.assign_program(key, recompiled);
}
}
Expand All @@ -1533,7 +1534,11 @@ impl Bank {
// Anticipate the upcoming program runtime environment for the next epoch,
// so we can try to recompile loaded programs before the feature transition hits.
drop(program_cache);
let mut program_cache = self.transaction_processor.program_cache.write().unwrap();
let mut program_cache = self
.transaction_processor
.global_program_cache
.write()
.unwrap();
let program_runtime_environment_v1 = create_program_runtime_environment_v1(
&upcoming_feature_set.runtime_features(),
&compute_budget,
Expand Down Expand Up @@ -1567,15 +1572,15 @@ impl Bank {

pub fn prune_program_cache(&self, new_root_slot: Slot, new_root_epoch: Epoch) {
self.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.prune(new_root_slot, new_root_epoch);
}

pub fn prune_program_cache_by_deployment_slot(&self, deployment_slot: Slot) {
self.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.prune_by_deployment_slot(deployment_slot);
Expand Down Expand Up @@ -3607,7 +3612,10 @@ impl Bank {
if executed_tx.was_successful() && !programs_modified_by_tx.is_empty() {
cache
.get_or_insert_with(|| {
self.transaction_processor.program_cache.write().unwrap()
self.transaction_processor
.global_program_cache
.write()
.unwrap()
})
.merge(programs_modified_by_tx);
}
Expand Down Expand Up @@ -5542,7 +5550,7 @@ impl Bank {

// Unload a program from the bank's cache
self.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.remove_programs([*old_address].into_iter());
Expand Down Expand Up @@ -5927,7 +5935,11 @@ impl Bank {
ProgramCacheForTxBatch::new_from_cache(
slot,
self.epoch_schedule.get_epoch(slot),
&self.transaction_processor.program_cache.read().unwrap(),
&self
.transaction_processor
.global_program_cache
.read()
.unwrap(),
)
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank/builtin_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ mod tests_core_bpf_migration {
// Run `finish_init` to simulate starting up from a snapshot.
// Clear all builtins to simulate a fresh bank init.
bank.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.remove_programs(
Expand Down Expand Up @@ -586,7 +586,7 @@ mod tests_core_bpf_migration {
// Run `finish_init` to simulate starting up from a snapshot.
// Clear all builtins to simulate a fresh bank init.
bank.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.remove_programs(
Expand Down
14 changes: 11 additions & 3 deletions runtime/src/bank/builtins/core_bpf_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ impl Bank {
let mut program_cache_for_tx_batch = ProgramCacheForTxBatch::new_from_cache(
self.slot,
self.epoch,
&self.transaction_processor.program_cache.read().unwrap(),
&self
.transaction_processor
.global_program_cache
.read()
.unwrap(),
);

// Configure a dummy `InvokeContext` from the runtime's current
Expand Down Expand Up @@ -206,7 +210,7 @@ impl Bank {
// Update the program cache by merging with `programs_modified`, which
// should have been updated by the deploy function.
self.transaction_processor
.program_cache
.global_program_cache
.write()
.unwrap()
.merge(&program_cache_for_tx_batch.drain_modified_entries());
Expand Down Expand Up @@ -592,7 +596,11 @@ pub(crate) mod tests {
.contains(&self.target_program_address));

// The cache should contain the target program.
let program_cache = bank.transaction_processor.program_cache.read().unwrap();
let program_cache = bank
.transaction_processor
.global_program_cache
.read()
.unwrap();
let entries = program_cache.get_flattened_entries(true, true);
let target_entry = entries
.iter()
Expand Down
Loading
Loading