-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24d03e8
commit 1e2d60e
Showing
59 changed files
with
1,514 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CPPFLAGS+=-O3 -ffast-math -fno-associative-math -fno-reciprocal-math | ||
CPPFLAGS+=-DFD_HAS_OPTIMIZATION=1 | ||
FD_HAS_OPTIMIZATION:=1 | ||
RUST_PROFILE:=release | ||
# CPPFLAGS+=-O3 -ffast-math -fno-associative-math -fno-reciprocal-math | ||
# CPPFLAGS+=-DFD_HAS_OPTIMIZATION=1 | ||
# FD_HAS_OPTIMIZATION:=1 | ||
# RUST_PROFILE:=release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
pub use crate::generated::{ | ||
fd_fctl_cfg_done, | ||
fd_fctl_cfg_rx_add, | ||
fd_fctl_delete, | ||
fd_fctl_join, | ||
fd_fctl_leave, | ||
fd_fctl_new, | ||
fd_fctl_private_rx_t, | ||
fd_fctl_rx_cr_return, | ||
fd_fctl_t, | ||
fd_fctl_tx_cr_update, | ||
FD_FCTL_ALIGN, | ||
FD_FCTL_RX_MAX_MAX, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub use crate::generated::{ | ||
fd_xdp_clear_listeners, | ||
fd_xdp_listen_udp_port, | ||
fd_xdp_listen_udp_ports, | ||
fd_xdp_release_udp_port, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pub use crate::generated::{ | ||
fd_rng_delete, | ||
fd_rng_idx, | ||
fd_rng_idx_set, | ||
fd_rng_int, | ||
fd_rng_join, | ||
fd_rng_leave, | ||
fd_rng_long, | ||
fd_rng_new, | ||
fd_rng_schar, | ||
fd_rng_seq, | ||
fd_rng_seq_set, | ||
fd_rng_short, | ||
fd_rng_t, | ||
fd_rng_uchar, | ||
fd_rng_uint, | ||
fd_rng_ulong, | ||
fd_rng_ushort, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub use crate::generated::{ | ||
fd_tempo_async_min, | ||
fd_tempo_async_reload, | ||
fd_tempo_lazy_default, | ||
fd_tempo_tick_per_ns, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ pub use crate::generated::{ | |
fd_wksp_pod_map, | ||
fd_wksp_pod_unmap, | ||
fd_wksp_t, | ||
fd_wksp_private, | ||
fd_wksp_unmap, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "firedancer" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Firedancer Contributors <[email protected]>"] | ||
description = "Safe high level wrappers for Firedancer" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
paste = "1.0.12" | ||
firedancer-sys = { path = "../firedancer-sys" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
macro_rules! align_up { | ||
( $x:expr, $a:expr ) => { | ||
($x + ($a - 1)) & !($a - 1) | ||
}; | ||
} | ||
|
||
macro_rules! layout { | ||
( value=$value:expr, ) => { $value }; | ||
( value=$value:expr, ($align:expr, $size:expr), $($tail:tt)*) => { | ||
layout!( value=align_up!($value, $align) + $size, $($tail)*) | ||
}; | ||
( align=$align:expr, [ $($tail:tt)* ]) => { | ||
align_up!(layout!(value = 0, $($tail)*), $align) | ||
}; | ||
} | ||
|
||
pub(crate) use { | ||
align_up, | ||
layout, | ||
}; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn test_align_up() { | ||
let zeros = 0u64; | ||
let ones = u64::MAX; | ||
|
||
for i in 0..64 { | ||
let align = 1u64 << i; | ||
let lo = (1u64 << i) - 1; | ||
let hi = !lo; | ||
|
||
assert_eq!(align_up!(zeros, align), zeros); | ||
assert_eq!(align_up!(ones, align), if i == 0 { ones } else { zeros }); | ||
for j in 0..64 { | ||
let x = 1u64 << j; | ||
assert_eq!(align_up!(x, align), (x + lo) & hi); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::ffi::c_ulong; | ||
use std::ptr::{ | ||
read_volatile, | ||
write_volatile, | ||
}; | ||
use firedancer_sys::*; | ||
|
||
use crate::*; | ||
|
||
pub struct Cnc { | ||
laddr: *mut tango::fd_cnc_t, | ||
diagnostic: *mut c_ulong, | ||
_workspace: Workspace, | ||
} | ||
|
||
impl Drop for Cnc { | ||
fn drop(&mut self) { | ||
unsafe { tango::fd_cnc_leave(self.laddr) }; | ||
} | ||
} | ||
|
||
#[repr(u32)] | ||
#[derive(Copy, Clone, Debug)] | ||
pub enum CncSignal { | ||
Run = tango::FD_CNC_SIGNAL_RUN, | ||
Boot = tango::FD_CNC_SIGNAL_BOOT, | ||
Fail = tango::FD_CNC_SIGNAL_FAIL, | ||
Halt = tango::FD_CNC_SIGNAL_HALT, | ||
} | ||
|
||
#[repr(u32)] | ||
#[derive(Copy, Clone, Debug)] | ||
pub enum CncDiag { | ||
InBackpressure = tango::FD_CNC_DIAG_IN_BACKP, | ||
BackpressureCount = tango::FD_CNC_DIAG_BACKP_CNT, | ||
} | ||
|
||
impl Cnc { | ||
pub unsafe fn join<T: Into<GlobalAddress>>(gaddr: T) -> Result<Self, ()> { | ||
let workspace = Workspace::map(gaddr)?; | ||
let laddr = tango::fd_cnc_join(workspace.laddr.as_ptr()); | ||
if laddr.is_null() { | ||
Err(()) | ||
} else { | ||
let diagnostic = tango::fd_cnc_app_laddr(laddr) as *mut c_ulong; | ||
if diagnostic.is_null() { | ||
Err(()) | ||
} else { | ||
Ok(Self { | ||
laddr, | ||
diagnostic, | ||
_workspace: workspace, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
pub fn query(&self) -> u64 { | ||
unsafe { tango::fd_cnc_signal_query(self.laddr) } | ||
} | ||
|
||
pub fn signal(&self, signal: u64) { | ||
unsafe { tango::fd_cnc_signal(self.laddr, signal) } | ||
} | ||
|
||
pub unsafe fn set(&self, diag: u64, value: u64) { | ||
write_volatile(self.diagnostic.offset(diag as isize), value) | ||
} | ||
|
||
pub unsafe fn increment(&self, diag: u64, value: u64) { | ||
let offset = self.diagnostic.offset(diag as isize); | ||
write_volatile(offset, read_volatile(offset) + value) | ||
} | ||
|
||
pub fn heartbeat(&self, now: i64) { | ||
unsafe { tango::fd_cnc_heartbeat(self.laddr, now) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use firedancer_sys::*; | ||
|
||
use std::ffi::c_void; | ||
|
||
use crate::*; | ||
|
||
pub struct DCache { | ||
laddr: *mut u8, | ||
wksp: *mut util::fd_wksp_t, | ||
_workspace: Workspace, | ||
} | ||
|
||
impl Drop for DCache { | ||
fn drop(&mut self) { | ||
unsafe { tango::fd_dcache_leave(self.laddr) }; | ||
} | ||
} | ||
|
||
impl DCache { | ||
pub unsafe fn join<T: Into<GlobalAddress>>(gaddr: T) -> Result<Self, ()> { | ||
let workspace = Workspace::map(gaddr)?; | ||
let laddr = tango::fd_dcache_join(workspace.laddr.as_ptr()); | ||
if laddr.is_null() { | ||
return Err(()); | ||
} | ||
|
||
let wksp = util::fd_wksp_containing(laddr as *const c_void); | ||
Ok(Self { | ||
laddr, | ||
wksp, | ||
_workspace: workspace, | ||
}) | ||
} | ||
|
||
pub unsafe fn slice<'a>(&self, chunk: u64, offset: u64, len: u64) -> &'a[u8] { | ||
let laddr = tango::fd_chunk_to_laddr_const(self.wksp as *const c_void, chunk); | ||
std::slice::from_raw_parts(laddr.offset(offset as isize) as *const u8, len as usize) | ||
} | ||
} |
Oops, something went wrong.