Changeset - 435cb6e4699f
[Not reviewed]
mh - 3 years ago 2022-02-08 15:11:11
contact@maxhenger.nl
Add (defaultly disabled) flag for debug logging
7 files changed with 27 insertions and 14 deletions:
0 comments (0 inline, 0 general)
bin-compiler/src/main.rs
Show inline comments
 
@@ -25,6 +25,12 @@ fn main() {
 
                .help("number of runtime threads")
 
                .default_value("1")
 
                .takes_value(true)
 
        )
 
        .arg(
 
            Arg::new("debug")
 
                .long("debug")
 
                .short('d')
 
                .help("enable debug logging")
 
        );
 

	
 
    // Retrieve arguments and convert
 
@@ -51,6 +57,8 @@ fn main() {
 
        }
 
    };
 

	
 
    let debug_enabled = app.is_present("debug");
 

	
 
    // Add input files to file buffer
 
    let input_files = input_files.unwrap();
 
    assert!(input_files.len() > 0); // because arg is required
 
@@ -95,7 +103,7 @@ fn main() {
 

	
 
    // Make sure there is a nameless module with a main component
 
    print!("Creating main component ... ");
 
    let runtime = rw::runtime2::Runtime::new(num_threads, protocol_description);
 
    let runtime = rw::runtime2::Runtime::new(num_threads, debug_enabled, protocol_description);
 
    if let Err(err) = runtime.create_component(b"", b"main") {
 
        use rw::ComponentCreationError as CCE;
 
        let reason = match err {
src/runtime2/component/component_pdl.rs
Show inline comments
 
@@ -672,7 +672,6 @@ impl CompPDL {
 
                    },
 
                    None => {
 
                        // Peer port remains with creator component.
 
                        println!("DEBUG: Setting peer for port {:?} of component {:?} to {:?}", created_port_info.self_id, reservation.id(), creator_ctx.id);
 
                        created_port_info.peer_comp_id = creator_ctx.id;
 
                        created_ctx.add_peer(pair.created_handle, sched_ctx, creator_ctx.id, None);
 
                    }
src/runtime2/runtime.rs
Show inline comments
 
@@ -158,7 +158,8 @@ pub struct Runtime {
 
}
 

	
 
impl Runtime {
 
    pub fn new(num_threads: u32, protocol_description: ProtocolDescription) -> Runtime {
 
    // TODO: debug_logging should be removed at some point
 
    pub fn new(num_threads: u32, debug_logging: bool, protocol_description: ProtocolDescription) -> Runtime {
 
        assert!(num_threads > 0, "need a thread to perform work");
 
        let runtime_inner = Arc::new(RuntimeInner {
 
            protocol: protocol_description,
 
@@ -173,7 +174,7 @@ impl Runtime {
 
        };
 

	
 
        for thread_index in 0..num_threads {
 
            let mut scheduler = Scheduler::new(runtime.inner.clone(), thread_index);
 
            let mut scheduler = Scheduler::new(runtime.inner.clone(), thread_index, debug_logging);
 
            let thread_handle = std::thread::spawn(move || {
 
                scheduler.run();
 
            });
src/runtime2/scheduler.rs
Show inline comments
 
@@ -8,42 +8,49 @@ use super::runtime::*;
 
pub(crate) struct Scheduler {
 
    runtime: Arc<RuntimeInner>,
 
    scheduler_id: u32,
 
    debug_logging: bool,
 
}
 

	
 
pub(crate) struct SchedulerCtx<'a> {
 
    pub runtime: &'a RuntimeInner,
 
    pub id: u32,
 
    pub comp: u32,
 
    pub logging_enabled: bool,
 
}
 

	
 
impl<'a> SchedulerCtx<'a> {
 
    pub fn new(runtime: &'a RuntimeInner, id: u32) -> Self {
 
    pub fn new(runtime: &'a RuntimeInner, id: u32, logging_enabled: bool) -> Self {
 
        return Self {
 
            runtime,
 
            id,
 
            comp: 0,
 
            logging_enabled,
 
        }
 
    }
 

	
 
    pub(crate) fn log(&self, text: &str) {
 
        println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text);
 
        if self.logging_enabled {
 
            println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text);
 
        }
 
    }
 

	
 
    // TODO: Obviously remove, but useful for testing
 
    pub(crate) fn log_special(&self, text: &str) {
 
        println!("[s:{:02}, c:{:03}] *** *** {}", self.id, self.comp, text);
 
        if self.logging_enabled {
 
            println!("[s:{:02}, c:{:03}] *** *** {}", self.id, self.comp, text);
 
        }
 
    }
 
}
 

	
 
impl Scheduler {
 
    // public interface to thread
 

	
 
    pub fn new(runtime: Arc<RuntimeInner>, scheduler_id: u32) -> Self {
 
        return Scheduler{ runtime, scheduler_id }
 
    pub fn new(runtime: Arc<RuntimeInner>, scheduler_id: u32, debug_logging: bool) -> Self {
 
        return Scheduler{ runtime, scheduler_id, debug_logging }
 
    }
 

	
 
    pub fn run(&mut self) {
 
        let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, self.scheduler_id);
 
        let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, self.scheduler_id, self.debug_logging);
 

	
 
        'run_loop: loop {
 
            // Wait until we have something to do (or need to quit)
src/runtime2/tests/mod.rs
Show inline comments
 
@@ -23,7 +23,7 @@ fn test_component_creation() {
 
        auto b = 5 + a;
 
    }
 
    ").expect("compilation");
 
    let rt = Runtime::new(1, pd);
 
    let rt = Runtime::new(1, true, pd);
 

	
 
    for i in 0..20 {
 
        create_component(&rt, "", "nothing_at_all", no_args());
 
@@ -80,6 +80,6 @@ fn test_component_communication() {
 
        new sender(o_mrmm, 5, 5);
 
        new receiver(i_mrmm, 5, 5);
 
    }").expect("compilation");
 
    let rt = Runtime::new(3, pd);
 
    let rt = Runtime::new(3, true, pd);
 
    create_component(&rt, "", "constructor", no_args());
 
}
 
\ No newline at end of file
testdata/basic-modules/producer.pdl
Show inline comments
 
#module producer
 

	
 
primitive producer(out<u32> output) {
 
    print("P: Going to send a value");
 
    sync {
 
        print("P: Going to send a value!");
 
        put(output, 1337);
testdata/basic/testing.pdl
Show inline comments
 
@@ -8,7 +8,6 @@ primitive consumer(in<u32> input) {
 
}
 

	
 
primitive producer(out<u32> output) {
 
    print("P: Going to send a value");
 
    sync {
 
        print("P: Going to send a value!");
 
        put(output, 1337);
0 comments (0 inline, 0 general)