-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pull request to a new branch #1
base: mastesr
Are you sure you want to change the base?
Changes from 1 commit
3efccb2
8c236b2
6abe977
2bea3b6
c4d9c79
261a6fa
adfb73a
17b899e
a127a7f
b9f4b30
7a362ef
feccc7a
79428ef
dd60176
b30ad1f
678315f
097754b
43bbd59
5db36e7
cc2b1ae
1624a37
f87343c
5dbcd91
06c07d6
3136b8e
632c964
73a1294
ab365e7
efe0538
9840cf0
f19ea40
b1eec7b
c54e01b
4da6837
9f15eda
153db15
37b1e0b
28f49aa
d390d01
9aef4c1
b3ee694
5837a9a
847c947
1db7f0c
56199e3
55e4b57
0f8954a
2eba386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all examples should have a build script as a playground. It can be a make file or a rust build.rs. No matter which way, we should let the user run the demos using a single command line like 'make'. The example should show the users how to build bsv, how to build probe library, how to link them together, hou to run the upper app to use those probes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
hercule-karuha marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,13 @@ import FIFOF::*; | |
interface RProbe#(type get_t, type put_t); | ||
method get_t get_data(); | ||
method Action put_data(put_t data); | ||
// should be called when there is no more message to send | ||
method Action shut_down_server(); | ||
endinterface | ||
|
||
module mkRProbe#(Bit#(WORD_WIDTH) id)(RProbe#(get_t, put_t)) provisos(Bits#(get_t, wid_get), Bits#(put_t, wid_put)); | ||
Bit#(WORD_WIDTH) shut_down_id = 32'hFFFFFFFF; | ||
Bit#(WORD_WIDTH) shut_down_msg = 32'h0; | ||
Bit#(WORD_WIDTH) get_size = fromInteger(valueOf(TDiv#(wid_get, BYTE_WIDTH))); | ||
Bit#(WORD_WIDTH) put_size = fromInteger(valueOf(TDiv#(wid_put, BYTE_WIDTH))); | ||
|
||
|
@@ -30,6 +34,10 @@ module mkRProbe#(Bit#(WORD_WIDTH) id)(RProbe#(get_t, put_t)) provisos(Bits#(get_ | |
let bvec = pack(data); | ||
put(id, cycles, bvec, put_size); | ||
endmethod | ||
|
||
method Action shut_down_server(); | ||
put(shut_down_id, cycles, shut_down_msg, put_size); | ||
endmethod | ||
endmodule | ||
|
||
module mkFIFOFProbe#(Bit#(WORD_WIDTH) id, FIFOF#(t) fifo)(Empty); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since some id is kept for internal use(e.g., control shutdown), you should check if the user supplied id is conflict with those reserved ids. |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We must treat naming seriously. For the name config, it means something that can be tuned. But thoes two things here seems not. Maybe this file should be called consts.rs or something else? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub type MsgSizeType = u32; | ||
pub const MSG_SIZE_BYTES: usize = std::mem::size_of::<MsgSizeType>(); | ||
pub const SHUT_DOWN_ID:u32 = 0xFFFFFFFF; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
#[cfg(test)] | ||
#[allow(clippy::unwrap_used)] | ||
mod test; | ||
mod test; | ||
|
||
mod config; | ||
mod server; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ pub enum GetPutMessage { | |
|
||
#[derive(Serialize, Deserialize)] | ||
struct R2BMessage { | ||
id: u32, | ||
id: u32, | ||
message: Vec<u8>, | ||
} | ||
|
||
|
@@ -36,41 +36,50 @@ pub struct B2RMessage { | |
/// A server for interacting with Bluesim. | ||
/// Cache bidirectional data and send data upon receiving requests. | ||
pub struct B2RServer { | ||
socket_path: String, | ||
b2r_cache: Arc<Mutex<HashMap<u32, VecDeque<B2RMessage>>>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the simulation run a long time, will this buffer overflow or lead to OOM? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The getter poped from the cache, i think the message shouldn't wait too long to be processed in debug program. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use a channel to do cross thread communication? What you did here is almost build a channel by hand and make code verbose. |
||
r2b_cache: Arc<Mutex<HashMap<u32, VecDeque<R2BMessage>>>>, | ||
} | ||
|
||
|
||
|
||
|
||
impl Default for B2RServer { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl B2RServer { | ||
/// make a new server | ||
/// make a new server with socket: /tmp/b2rr2b | ||
pub fn new() -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this API should be removed |
||
B2RServer { | ||
socket_path: "/tmp/b2rr2b".to_string(), | ||
b2r_cache: Arc::new(Mutex::new(HashMap::new())), | ||
r2b_cache: Arc::new(Mutex::new(HashMap::new())), | ||
} | ||
} | ||
|
||
|
||
/// make a new server with a socket path | ||
/// you need to specify the B2R_SOCKET environment variable when start the bluesim | ||
pub fn new_with(path: &str) -> Self { | ||
B2RServer { | ||
socket_path: path.to_string(), | ||
b2r_cache: Arc::new(Mutex::new(HashMap::new())), | ||
r2b_cache: Arc::new(Mutex::new(HashMap::new())), | ||
} | ||
} | ||
|
||
/// Start a thread to run the server. | ||
/// Create a UnixListener at "/tmp/b2rr2b". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is outdated |
||
/// Return the JoinHandle of that thread. | ||
/// This function needs to be called before running your Bluesim program. | ||
/// the server thread returns when bluesim called shut_down_server() | ||
pub fn serve(&mut self) -> JoinHandle<()> { | ||
// let probe_infos = self.probe_infos.clone(); | ||
let b2r_cache = self.b2r_cache.clone(); | ||
let r2b_cache = self.r2b_cache.clone(); | ||
let socket_path = self.socket_path.clone(); | ||
thread::spawn(move || { | ||
let _ = fs::remove_file("/tmp/b2rr2b"); | ||
let listener = UnixListener::bind("/tmp/b2rr2b").expect("Failed to bind Unix listener"); | ||
let _ = fs::remove_file(socket_path.as_str()); | ||
let listener = UnixListener::bind(socket_path).expect("Failed to bind Unix listener"); | ||
let mut stream = match listener.incoming().next() { | ||
Some(stream_res) => stream_res.expect("Fail to connect to bluesim"), | ||
None => panic!("listener returns a None"), | ||
|
@@ -96,6 +105,10 @@ impl B2RServer { | |
} | ||
GetPutMessage::Put(b2r_message) => { | ||
// println!("receive put to id {}", b2r_message.id); | ||
// return if reveive message with SHUT_DOWN_ID | ||
if b2r_message.id == SHUT_DOWN_ID { | ||
return; | ||
} | ||
let mut b2r_cache = b2r_cache.lock().expect("Fail to lock b2r_cache"); | ||
let queue = b2r_cache.entry(b2r_message.id).or_default(); | ||
queue.push_back(b2r_message); | ||
|
@@ -105,7 +118,6 @@ impl B2RServer { | |
}) | ||
} | ||
|
||
|
||
/// Send a message to the probe with ID "id". | ||
/// Please ensure that message.len() == ceil(get_t_width/8), | ||
/// where get_t_width is the width of get_t defined in your BSV code. | ||
|
@@ -115,7 +127,6 @@ impl B2RServer { | |
let queue = r2b_cache.entry(id).or_default(); | ||
queue.push_back(r2b_message); | ||
} | ||
|
||
} | ||
|
||
fn get_msg_size(bytes: Vec<u8>) -> u32 { | ||
|
@@ -124,6 +135,8 @@ fn get_msg_size(bytes: Vec<u8>) -> u32 { | |
|
||
fn receive_getput(stream: &mut UnixStream) -> Result<GetPutMessage, Box<bincode::ErrorKind>> { | ||
// println!("connect comeing"); | ||
// the first MSG_SIZE_BYTES bytes is the size of message | ||
// use to initialize the buffer | ||
let mut sz_buf: Vec<u8> = vec![0; MSG_SIZE_BYTES]; | ||
stream | ||
.read_exact(&mut sz_buf) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated code should go into a function