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 .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Check

on:
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always
Expand All @@ -20,4 +19,4 @@ jobs:
with:
tool: just
- name: Run checks
run: just ci
run: just check
7 changes: 2 additions & 5 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Format

on:
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always
Expand All @@ -15,13 +14,11 @@ jobs:
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1
with:
persist-credentials: 'false'
- name: Install Rust nightly with rustfmt
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- name: Install just
uses: taiki-e/install-action@7ea35f098a7369cd23488403f58be9c491a6c55f # v2.77.0
with:
tool: just
- name: Install rustfmt
run: rustup component add rustfmt
- name: Check formatting
run: just fmt-check
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Test

on:
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2021"
license = "BSD-3-Clause-Clear"
repository = "https://github.com/zama-ai/ra2m"
readme = "Readme.md"
rust-version="1.94"

[workspace.dependencies]
# Main publishable crates
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ publish-check:
# ── CI ────────────────────────────────────────────────────────────────────────

# Full check suite: format → lint → test
ci: fmt-check clippy test
ci: fmt-check check test

# ── Git hooks ─────────────────────────────────────────────────────────────────
# List of supported git hook
Expand Down
2 changes: 1 addition & 1 deletion ra2m_cpn/src/test/traffic_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ra2m_sim::prelude::*;
use super::*;

use getset::CopyGetters;
use rand::{RngExt, SeedableRng, rngs::StdRng};
use rand::{rngs::StdRng, RngExt, SeedableRng};
use std::sync::{Arc, Mutex};
use tokio::sync::mpsc;

Expand Down
9 changes: 3 additions & 6 deletions ra2m_ffi/examples/ipc_demo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use clap::Parser;
use rand::{
rngs::StdRng,
{Rng, SeedableRng},
};
use rand::{rngs::StdRng, RngExt};

use ra2m_ffi::ipc::prelude::*;

Expand Down Expand Up @@ -40,9 +37,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
} else {
// Randomly generate data
let mut rng: StdRng = SeedableRng::from_os_rng();
let mut rng: StdRng = rand::make_rng();
for _ in 0..size_b {
data.push(rng.r#gen::<u8>());
data.push(rng.random::<u8>());
}
}

Expand Down
5 changes: 3 additions & 2 deletions ra2m_sim/ra2m_sim_kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
//! * delay: Custom future used by Hw process to wait for a given amount of simulated time
//! * event: Custom future used by Hw process to wait/regiter or trigger an Hw event
//! * module: Define module abstraction that ease the generic management of distinct module
//! definition (eg. Module of different kind with distinct behavior)
//! definition (eg. Module of different kind with distinct behavior)
//! * port: Inter-process communication primitive. Rely on async channel and correctly hooked up
//! * within the scheduler to prevent deadlock
//! * memport: Leverage port abstraction to build memory mapped inter-process communication (eg. request/response protocol)
//! * memport: Leverage port abstraction to build memory mapped inter-process communication
//! (eg. request/response protocol)
//! * scheduler: provide utility function for Hw process interaction and a simulate function that
//! run the simulation for a given amount of time
//!
Expand Down
2 changes: 0 additions & 2 deletions ra2m_sim/ra2m_sim_kernel/src/port/full_duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ where
}
}

/// Issue burst request in background and wait for associated response

/// Issue burst request in background and wait for associated response
/// Request issued in background to enable burst size bigger that port outstanding
/// Response awaited in foreground
Expand Down
19 changes: 12 additions & 7 deletions ra2m_sim/ra2m_sim_kernel/src/port/half_duplex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,18 @@ where
let mut rx = self.0.lock().await;
let mut pkt = {
let pkt = rx.recv().await;
if uid.is_none() || pkt.uid() == uid.unwrap() {
pkt
} else {
log!(|rx| log::Category::Protocol, log::Verbosity::Warning
=> rx.name, pkt.uid(), uid
=> "Packet UID mismatch, reordering occur due to multiple outstanding or reset. In case of multiple outstanding, you should use a more evolved req/resp handling (Cf. req_burst/wait_pkt)");
return Err(PacketError::UidMismatch(pkt.uid(), uid.unwrap()).into());
match uid {
None => pkt,
Some(u) => {
if pkt.uid() == u {
pkt
} else {
log!(|rx| log::Category::Protocol, log::Verbosity::Warning
=> rx.name, pkt.uid(), uid
=> "Packet UID mismatch, reordering occur due to multiple outstanding or reset. In case of multiple outstanding, you should use a more evolved req/resp handling (Cf. req_burst/wait_pkt)");
return Err(PacketError::UidMismatch(pkt.uid(), u).into());
}
}
}
};

Expand Down
1 change: 1 addition & 0 deletions ra2m_sim/ra2m_sim_kernel/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub enum EndpointError {
/// * RxOnly => SlavePort endpoint
/// * TxRxReq => ReqRespPort (or DispatchPort) endpoint with Request flavor
/// * TxRxResp => ReqRespPort (or DispatchPort) endpoint with Response flavor
///
/// Gathering port handle in a enum enable custom splitting and gathering of port handle.
/// Like binding an ReqRespPort on two distinct port instances of port (eg. Master, Slave) or the
/// opposite
Expand Down
14 changes: 4 additions & 10 deletions ra2m_sim/ra2m_sim_kernel/src/port/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ impl<T> Packet<T> {
/// Handle communication delay
/// => Await until ready tick of the packet
pub async fn handle_delay(&mut self) {
if self.timed {
if self.ready_at > time::TimeKeeper::cur_tick() {
tokio::task::yield_now().await; // TODO understand resolved MT issue
delay::Delay::wait_until(self.ready_at).await;
}
if self.timed && self.ready_at > time::TimeKeeper::cur_tick() {
tokio::task::yield_now().await; // TODO understand resolved MT issue
delay::Delay::wait_until(self.ready_at).await;
}
}

Expand Down Expand Up @@ -98,11 +96,7 @@ impl<T> Packet<T> {
pub fn delay(&self) -> time::Tick {
let cur_tick = time::TimeKeeper::cur_tick();

if self.ready_at <= cur_tick {
0
} else {
self.ready_at - cur_tick
}
self.ready_at.saturating_sub(cur_tick)
}
}

Expand Down
4 changes: 2 additions & 2 deletions ra2m_sim/ra2m_sim_kernel/src/protocol/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl From<&SubRangeAddr> for Traceable {
/// Access pattern encoding:
/// * Simple: access on contiguous chunk of memory
/// * Stride: access on non-contiguous chunk of memory. Encoded as chunk size, stride offset and
/// required repetition.
/// NB: Stride pattern should be refine to match AHB/AXI4 specification
/// required repetition.
/// NB: Stride pattern should be refine to match AHB/AXI4 specification
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Pattern {
Unset(),
Expand Down
2 changes: 1 addition & 1 deletion ra2m_sim/ra2m_sim_kernel/src/protocol/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
pattern: Pattern,
packet_options: Option<PacketOptions>,
) -> Packet<Self> {
let options = packet_options.unwrap_or(Default::default());
let options = packet_options.unwrap_or_default();
Packet::wrap_payload(Self::new(read_from, write_to, pattern), options)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ra2m_sim/ra2m_sim_kernel/src/protocol/membus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl MemBus {
data: Option<&[u8]>,
packet_options: Option<PacketOptions>,
) -> Packet<Self> {
let options = packet_options.unwrap_or(Default::default());
let options = packet_options.unwrap_or_default();
Packet::wrap_payload(Self::new(from_uid, cmd, addr, pattern, data), options)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ra2m_sim/ra2m_sim_kernel/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub mod network;
/// A Traceable object have a dedicated store for handler history and provide two methods:
/// * One to extend the history with a given handler
/// * One to finish() the history stream with a Base Handler (done in trace! macro)
/// TODO: Should expose the Custom handler type as parameters
// TODO: Should expose the Custom handler type as parameters
///
/// Aims of this traits is also to give hints for formatting into a DataFrame,
/// to prevent boilerplate code a derive macro is available.
Expand All @@ -63,7 +63,7 @@ pub trait Trace: Sized + serde::Serialize {
fn wrap_up(&mut self, uid: usize);

fn export_as_traceable_map(
vec: &Vec<Self>,
vec: &[Self],
) -> std::collections::HashMap<&'static str, Vec<Traceable>>;
}

Expand Down
6 changes: 3 additions & 3 deletions ra2m_sim/ra2m_sim_kernel/src/protocol/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ where
payload: P,
packet_options: Option<PacketOptions>,
) -> Packet<Self> {
let options = packet_options.unwrap_or(Default::default());
let options = packet_options.unwrap_or_default();
Packet::wrap_payload(Self::new(from, to, payload), options)
}
}
Expand All @@ -92,7 +92,7 @@ where
pub fn inner_unwrap(self) -> Packet<P> {
// Extract current options
let timed = self.timed();
let sid = self.sid().clone();
let sid = *self.sid();
let delay = self.delay();

let Network { payload, .. } = self.unwrap_payload();
Expand All @@ -104,7 +104,7 @@ where
pub fn inner_wrap(from: T, to: T, inner: Packet<P>) -> Self {
// Extract current options
let timed = inner.timed();
let sid = inner.sid().clone();
let sid = *inner.sid();
let delay = inner.delay();

let payload = inner.unwrap_payload();
Expand Down
2 changes: 1 addition & 1 deletion ra2m_sim/ra2m_sim_kernel/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl FromStr for Frequency {

// Parse units
match val_unit[1].to_lowercase().as_str() {
"Hz" => Ok(value.Hz()),
"hz" => Ok(value.Hz()),
"khz" => Ok(value.kHz()),
"mhz" => Ok(value.MHz()),
"ghz" => Ok(value.GHz()),
Expand Down
35 changes: 16 additions & 19 deletions ra2m_sim/ra2m_sim_macros/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ pub fn expand(ast: &DeriveInput, name: &Ident) -> Result<TokenStream> {
port_fields.push(field_name);
} else {
// Check for required types
match type_name.as_str() {
"Arc<Properties>" => {
if properties_field.is_some() {
return Err(Error::new(
field_name.span(),
"Only one Arc<Properties> field is allowed",
));
}
properties_field = Some(field_name);
if type_name.as_str() == "Arc<Properties>" {
if properties_field.is_some() {
return Err(Error::new(
field_name.span(),
"Only one Arc<Properties> field is allowed",
));
}
_ => {}
properties_field = Some(field_name);
}
}
}
Expand Down Expand Up @@ -111,7 +108,7 @@ pub fn expand(ast: &DeriveInput, name: &Ident) -> Result<TokenStream> {
}
};

Ok(TokenStream::from(module_impl))
Ok(module_impl)
}

pub fn expand_init(ast: &ItemFn, fn_name: &Ident) -> Result<proc_macro2::TokenStream> {
Expand Down Expand Up @@ -141,10 +138,10 @@ pub fn expand_init(ast: &ItemFn, fn_name: &Ident) -> Result<proc_macro2::TokenSt
}
};

Ok(TokenStream::from(quote!(
Ok(quote!(
#binding
#ast
)))
))
}

pub fn expand_default_init(ast: &ItemImpl, impl_name: &Ident) -> Result<proc_macro2::TokenStream> {
Expand All @@ -158,10 +155,10 @@ pub fn expand_default_init(ast: &ItemImpl, impl_name: &Ident) -> Result<proc_mac
}
};

Ok(TokenStream::from(quote!(
Ok(quote!(
#default
#ast
)))
))
}

pub fn expand_teardown(ast: &ItemFn, fn_name: &Ident) -> Result<proc_macro2::TokenStream> {
Expand Down Expand Up @@ -191,10 +188,10 @@ pub fn expand_teardown(ast: &ItemFn, fn_name: &Ident) -> Result<proc_macro2::Tok
}
};

Ok(TokenStream::from(quote!(
Ok(quote!(
#binding
#ast
)))
))
}

pub fn expand_default_teardown(
Expand All @@ -211,8 +208,8 @@ pub fn expand_default_teardown(
}
};

Ok(TokenStream::from(quote!(
Ok(quote!(
#default
#ast
)))
))
}
14 changes: 7 additions & 7 deletions ra2m_sim/ra2m_sim_macros/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn expand(ast: &DeriveInput, name: &Ident) -> Result<TokenStream> {
fn wrap_up(&mut self, uid: usize) {
self.#history_field_ident.push(types::Handler::base(uid))
}
fn export_as_traceable_map(vec: &Vec<Self>) -> std::collections::HashMap<&'static str, Vec<Traceable>>{
fn export_as_traceable_map(vec: &[Self]) -> std::collections::HashMap<&'static str, Vec<Traceable>>{
// convert Vec<Struct> in Vec<Tuple> where spans were expanded and traced field inserted
let vec_tuple = vec.iter().enumerate().flat_map(|(id, x)| {
let spans = x.get_history().spans();
Expand All @@ -110,7 +110,7 @@ pub fn expand(ast: &DeriveInput, name: &Ident) -> Result<TokenStream> {
}
};

Ok(TokenStream::from(expanded))
Ok(expanded)
}

fn extract_history_field(attrs: &[Attribute], name: &Ident) -> Result<Ident> {
Expand All @@ -120,10 +120,10 @@ fn extract_history_field(attrs: &[Attribute], name: &Ident) -> Result<Ident> {
return Ok(ident);
}
}
return Err(Error::new(
Err(Error::new(
name.span(),
"#[derive(Trace)] expect `history(_)` or `default_history` attributes",
));
))
}

fn extract_custom_type(attrs: &[Attribute], name: &Ident) -> Result<Type> {
Expand All @@ -135,10 +135,10 @@ fn extract_custom_type(attrs: &[Attribute], name: &Ident) -> Result<Type> {
return Ok(cust_type);
}
}
return Err(Error::new(
Err(Error::new(
name.span(),
"#[derive(Trace)] expect `custom_trace(_)` attribute",
));
))
}

pub fn expand_default_history(
Expand Down Expand Up @@ -168,5 +168,5 @@ pub fn expand_default_history(
ast.attrs.push(history_marker);

// Emit the code
Ok(TokenStream::from(quote! {#ast }))
Ok(quote! {#ast })
}
Loading