Skip to content

Commit

Permalink
Apple M1 compatibility (solana-labs#16346)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Drappi <christiandrappi@Christians-MacBook-Pro.local>
  • Loading branch information
cdrappi and Christian Drappi authored Apr 10, 2021
1 parent 8bc0bdd commit 54a04ba
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 269 deletions.
72 changes: 8 additions & 64 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ $ sudo apt-get update
$ sudo apt-get install libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang make
```

On Mac M1s, make sure you set up your terminal & homebrew [to use](https://5balloons.info/correct-way-to-install-and-use-homebrew-on-m1-macs/) Rosetta. You can install it with:

```bash
$ softwareupdate --install-rosetta
```

## **2. Download the source code.**

```bash
Expand Down
3 changes: 1 addition & 2 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use solana_ledger::{
blockstore::Blockstore, blockstore_processor::TransactionStatusSender,
entry::hash_transactions, leader_schedule_cache::LeaderScheduleCache,
};
use solana_measure::{measure::Measure, thread_mem_usage};
use solana_measure::measure::Measure;
use solana_metrics::{inc_new_counter_debug, inc_new_counter_info};
use solana_perf::{
cuda_runtime::PinnedVec,
Expand Down Expand Up @@ -224,7 +224,6 @@ impl BankingStage {
Builder::new()
.name("solana-banking-stage-tx".to_string())
.spawn(move || {
thread_mem_usage::datapoint("solana-banking-stage-tx");
Self::process_loop(
my_pubkey,
&verified_receiver,
Expand Down
3 changes: 0 additions & 3 deletions core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use rayon::prelude::*;
use rayon::{ThreadPool, ThreadPoolBuilder};
use serde::ser::Serialize;
use solana_measure::measure::Measure;
use solana_measure::thread_mem_usage;
use solana_metrics::{inc_new_counter_debug, inc_new_counter_error};
use solana_net_utils::{
bind_common, bind_common_in_range, bind_in_range, find_available_port_in_range,
Expand Down Expand Up @@ -1938,7 +1937,6 @@ impl ClusterInfo {
let mut generate_pull_requests = true;
loop {
let start = timestamp();
thread_mem_usage::datapoint("solana-gossip");
if self.contact_debug_interval != 0
&& start - last_contact_info_trace > self.contact_debug_interval
{
Expand Down Expand Up @@ -3215,7 +3213,6 @@ impl ClusterInfo {
_ => error!("gossip run_listen failed: {}", err),
}
}
thread_mem_usage::datapoint("solana-listen");
}
})
.unwrap()
Expand Down
2 changes: 0 additions & 2 deletions core/src/fetch_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::banking_stage::HOLD_TRANSACTIONS_SLOT_OFFSET;
use crate::poh_recorder::PohRecorder;
use crate::result::{Error, Result};
use solana_measure::thread_mem_usage;
use solana_metrics::{inc_new_counter_debug, inc_new_counter_info};
use solana_perf::packet::PacketsRecycler;
use solana_perf::recycler::Recycler;
Expand Down Expand Up @@ -140,7 +139,6 @@ impl FetchStage {
let fwd_thread_hdl = Builder::new()
.name("solana-fetch-stage-fwd-rcvr".to_string())
.spawn(move || loop {
thread_mem_usage::datapoint("solana-fetch-stage-fwd-rcvr");
if let Err(e) =
Self::handle_forwarded_packets(&forward_receiver, &sender, &poh_recorder)
{
Expand Down
32 changes: 1 addition & 31 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use solana_ledger::{
entry::VerifyRecyclers,
leader_schedule_cache::LeaderScheduleCache,
};
use solana_measure::{measure::Measure, thread_mem_usage};
use solana_measure::measure::Measure;
use solana_metrics::inc_new_counter_info;
use solana_runtime::{
accounts_background_service::AbsRequestSender, bank::Bank, bank_forks::BankForks,
Expand Down Expand Up @@ -319,15 +319,11 @@ impl ReplayStage {
let mut voted_signatures = Vec::new();
let mut has_new_vote_been_rooted = !wait_for_vote_to_start_leader;
loop {
let allocated = thread_mem_usage::Allocatedp::default();

thread_mem_usage::datapoint("solana-replay-stage");
// Stop getting entries if we get exit signal
if exit.load(Ordering::Relaxed) {
break;
}

let start = allocated.get();
let mut generate_new_bank_forks_time =
Measure::start("generate_new_bank_forks_time");
Self::generate_new_bank_forks(
Expand All @@ -338,11 +334,9 @@ impl ReplayStage {
&mut progress,
);
generate_new_bank_forks_time.stop();
Self::report_memory(&allocated, "generate_new_bank_forks", start);

let mut tpu_has_bank = poh_recorder.lock().unwrap().has_bank();

let start = allocated.get();
let mut replay_active_banks_time = Measure::start("replay_active_banks_time");
let ancestors = bank_forks.read().unwrap().ancestors();
let descendants = bank_forks.read().unwrap().descendants().clone();
Expand All @@ -364,11 +358,8 @@ impl ReplayStage {
&descendants,
);
replay_active_banks_time.stop();
Self::report_memory(&allocated, "replay_active_banks", start);

let forks_root = bank_forks.read().unwrap().root();
let start = allocated.get();

// Reset any duplicate slots that have been confirmed
// by the network in anticipation of the confirmed version of
// the slot
Expand Down Expand Up @@ -455,7 +446,6 @@ impl ReplayStage {
.select_forks(&frozen_banks, &tower, &progress, &ancestors, &bank_forks);
select_forks_time.stop();

Self::report_memory(&allocated, "select_fork", start);

let mut select_vote_and_reset_forks_time =
Measure::start("select_vote_and_reset_forks");
Expand Down Expand Up @@ -493,8 +483,6 @@ impl ReplayStage {
}
heaviest_fork_failures_time.stop();

let start = allocated.get();

let mut voting_time = Measure::start("voting_time");
// Vote on a fork
if let Some((ref vote_bank, ref switch_fork_decision)) = vote_bank {
Expand Down Expand Up @@ -535,9 +523,6 @@ impl ReplayStage {
};
voting_time.stop();

Self::report_memory(&allocated, "votable_bank", start);
let start = allocated.get();

let mut reset_bank_time = Measure::start("reset_bank");
// Reset onto a fork
if let Some(reset_bank) = reset_bank {
Expand Down Expand Up @@ -605,12 +590,9 @@ impl ReplayStage {
}
}
}
Self::report_memory(&allocated, "reset_bank", start);
}
reset_bank_time.stop();
Self::report_memory(&allocated, "reset_bank", start);

let start = allocated.get();
let mut start_leader_time = Measure::start("start_leader_time");
if !tpu_has_bank {
Self::maybe_start_leader(
Expand All @@ -636,7 +618,6 @@ impl ReplayStage {
}
}
start_leader_time.stop();
Self::report_memory(&allocated, "start_leader", start);

let mut wait_receive_time = Measure::start("wait_receive_time");
if !did_complete_bank {
Expand Down Expand Up @@ -749,17 +730,6 @@ impl ReplayStage {
(progress, heaviest_subtree_fork_choice)
}

fn report_memory(
allocated: &solana_measure::thread_mem_usage::Allocatedp,
name: &'static str,
start: u64,
) {
datapoint_debug!(
"replay_stage-memory",
(name, (allocated.get() - start) as i64, i64),
);
}

#[allow(dead_code)]
fn reset_duplicate_slots(
duplicate_slots_reset_receiver: &DuplicateSlotsResetReceiver,
Expand Down
10 changes: 1 addition & 9 deletions core/src/serve_repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use bincode::serialize;
use rand::distributions::{Distribution, WeightedIndex};
use solana_ledger::{blockstore::Blockstore, shred::Nonce};
use solana_measure::measure::Measure;
use solana_measure::thread_mem_usage;
use solana_metrics::{datapoint_debug, inc_new_counter_debug};
use solana_metrics::inc_new_counter_debug;
use solana_perf::packet::{limited_deserialize, Packets, PacketsRecycler};
use solana_sdk::{
clock::Slot,
Expand Down Expand Up @@ -307,7 +306,6 @@ impl ServeRepair {
Self::report_reset_stats(&me, &mut stats);
last_print = Instant::now();
}
thread_mem_usage::datapoint("solana-repair-listen");
}
})
.unwrap()
Expand All @@ -322,9 +320,7 @@ impl ServeRepair {
stats: &mut ServeRepairStats,
) {
// iter over the packets
let allocated = thread_mem_usage::Allocatedp::default();
packets.packets.iter().for_each(|packet| {
let start = allocated.get();
let from_addr = packet.meta.addr();
limited_deserialize(&packet.data[..packet.meta.size])
.into_iter()
Expand All @@ -336,10 +332,6 @@ impl ServeRepair {
let _ignore_disconnect = response_sender.send(rsp);
}
});
datapoint_debug!(
"solana-serve-repair-memory",
("serve_repair", (allocated.get() - start) as i64, i64),
);
});
}

Expand Down
15 changes: 14 additions & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,20 @@ fn report_target_features() {
}
);

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
// We exclude Mac OS here to be compatible with computers that have Mac M1 chips.
// For these computers, one must install rust/cargo/brew etc. using Rosetta 2,
// which allows them to run software targeted for x86_64 on an aarch64.
// Hence the code below will run on these machines (target_arch="x86_64")
// if we don't exclude with target_os="macos".
//
// It's going to require more more work to get Solana building
// on Mac M1's without Rosetta,
// and when that happens we should remove this
// (the feature flag for code targeting that is target_arch="aarch64")
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(target_os = "macos")
))]
{
unsafe { check_avx() };
}
Expand Down
3 changes: 2 additions & 1 deletion crate-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ edition = "2018"
[dependencies]
backtrace = { version = "0.3.33", features = ["serialize-serde"] }
bytes = { version = "0.4.12", features = ["either"] }
cc = { version = "1.0.45", features = ["jobserver", "num_cpus", "parallel"]}
cc = { version = "1.0.67", features = ["jobserver", "parallel"]}
curve25519-dalek = { version = "2" }
either= { version = "1.5.2" }
lazy_static = { version = "1.4.0", features = ["spin", "spin_no_std"] }
libc = { version = "0.2.62", features = ["extra_traits"] }
rand_chacha = { version = "0.2.2" }
regex-syntax = { version = "0.6.12" }
reqwest = { version = "0.11.2", default-features = false, features = ["blocking", "rustls-tls", "json"] }
ring = { version = "0.16.17" }
serde = { version = "1.0.100", features = ["rc"] }
ed25519-dalek = { version = "=1.0.1", features = ["serde"] }
syn_0_15 = { package = "syn", version = "0.15.42", features = ["extra-traits", "fold", "full"] }
Expand Down
Loading

0 comments on commit 54a04ba

Please sign in to comment.