-
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
06b4917
commit 0c97869
Showing
49 changed files
with
1,159 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
CPPFLAGS+=-O3 -ffast-math -fno-associative-math -fno-reciprocal-math | ||
CPPFLAGS+=-DFD_HAS_OPTIMIZATION=1 | ||
FD_HAS_OPTIMIZATION:=1 | ||
# CPPFLAGS+=-O3 -ffast-math -fno-associative-math -fno-reciprocal-math | ||
# CPPFLAGS+=-DFD_HAS_OPTIMIZATION=1 | ||
# FD_HAS_OPTIMIZATION:=1 |
File renamed without changes.
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
File renamed without changes.
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
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) | ||
} | ||
} |
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,99 @@ | ||
use std::ffi::c_void; | ||
use std::marker::PhantomData; | ||
use std::mem::{ | ||
align_of, | ||
size_of, | ||
}; | ||
use std::ptr::null_mut; | ||
|
||
use firedancer_sys::*; | ||
|
||
use crate::*; | ||
|
||
macro_rules! footprint { | ||
( $rx_max:expr ) => { | ||
layout!( | ||
align = tango::FD_FCTL_ALIGN as usize, | ||
[ | ||
( | ||
align_of::<tango::fd_fctl_t>(), | ||
size_of::<tango::fd_fctl_t>() | ||
), | ||
( | ||
align_of::<tango::fd_fctl_private_rx_t>(), | ||
$rx_max * size_of::<tango::fd_fctl_private_rx_t>() | ||
), | ||
] | ||
) | ||
}; | ||
} | ||
|
||
pub struct FCtl<'a, 'b> { | ||
_stack: [u8; footprint!(1)], | ||
shmem: *mut c_void, | ||
fctl: *mut tango::fd_fctl_t, | ||
_seq: PhantomData<&'a u64>, | ||
_slow: PhantomData<&'b mut u64>, | ||
} | ||
|
||
impl<'a, 'b> Drop for FCtl<'a, 'b> { | ||
fn drop(&mut self) { | ||
unsafe { tango::fd_fctl_leave(self.fctl) }; | ||
unsafe { tango::fd_fctl_delete(self.shmem) }; | ||
} | ||
} | ||
|
||
impl<'a, 'b> FCtl<'a, 'b> { | ||
pub fn new( | ||
cr_burst: u64, | ||
cr_max: u64, | ||
cr_resume: u64, | ||
cr_refill: u64, | ||
fseq: &FSeq, | ||
) -> Result<Self, ()> { | ||
let mut stack = [0; footprint!(1usize)]; | ||
let shmem = unsafe { tango::fd_fctl_new(&mut stack as *mut _ as *mut c_void, 1) }; | ||
if shmem.is_null() { | ||
return Err(()); | ||
} | ||
|
||
let fctl = unsafe { tango::fd_fctl_join(shmem) }; | ||
if fctl.is_null() { | ||
return Err(()); | ||
} | ||
|
||
let fctl = unsafe { | ||
tango::fd_fctl_cfg_rx_add( | ||
fctl, | ||
cr_max, | ||
fseq.laddr, | ||
fseq.diagnostic.offset(FSeqDiag::SlowCount as isize), | ||
) | ||
}; | ||
if fctl.is_null() { | ||
return Err(()); | ||
} | ||
|
||
let fctl = unsafe { tango::fd_fctl_cfg_done(fctl, cr_burst, cr_max, cr_resume, cr_refill) }; | ||
|
||
Ok(FCtl { | ||
_stack: stack, | ||
shmem, | ||
fctl, | ||
_seq: PhantomData, | ||
_slow: PhantomData, | ||
}) | ||
} | ||
|
||
pub fn tx_cr_update(&self, cr_avail: u64, mcache: &MCache) -> u64 { | ||
unsafe { tango::fd_fctl_tx_cr_update(self.fctl, cr_avail, mcache.sequence_number) } | ||
} | ||
} | ||
|
||
pub fn housekeeping_default_interval_nanos(cr_max: u64) -> i64 { | ||
unsafe { util::fd_tempo_lazy_default(cr_max) } | ||
} | ||
|
||
pub fn minimum_housekeeping_tick_interval(lazy: i64) -> u64 { | ||
unsafe { util::fd_tempo_async_min(lazy, 1, util::fd_tempo_tick_per_ns(null_mut()) as f32) } | ||
} |
Oops, something went wrong.