Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
  • Loading branch information
tsoutsman committed Sep 6, 2023
1 parent 5eac123 commit 0eae81f
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 145 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 61 additions & 60 deletions applications/rq/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,76 @@
#![no_std]
extern crate alloc;
#[macro_use] extern crate app_io;

extern crate apic;
extern crate getopts;
extern crate task;
// extern crate alloc;
// #[macro_use] extern crate app_io;

use getopts::Options;
use alloc::{
fmt::Write,
string::{
String,
ToString,
},
vec::Vec,
};
use apic::get_lapics;
// extern crate apic;
// extern crate getopts;
// extern crate task;

pub fn main(args: Vec<String>) -> isize {
let mut opts = Options::new();
opts.optflag("h", "help", "print this help menu");
// use getopts::Options;
// use alloc::{
// fmt::Write,
// string::{
// String,
// ToString,
// },
// vec::Vec,
// };
// use apic::get_lapics;

let matches = match opts.parse(args) {
Ok(m) => { m }
Err(_f) => { println!("{} \n", _f);
return -1; }
};
// pub fn main(args: Vec<String>) -> isize {
// let mut opts = Options::new();
// opts.optflag("h", "help", "print this help menu");

if matches.opt_present("h") {
return print_usage(opts)
}
// let matches = match opts.parse(args) {
// Ok(m) => { m }
// Err(_f) => { println!("{} \n", _f);
// return -1; }
// };

let all_lapics = get_lapics();
for lapic in all_lapics.iter() {
let lapic = lapic.1;
let apic_id = lapic.read().apic_id();
let processor = lapic.read().processor_id();
let is_bootstrap_cpu = lapic.read().is_bootstrap_cpu();
let core_type = if is_bootstrap_cpu { "Boot CPU" } else { "Secondary CPU" };
// if matches.opt_present("h") {
// return print_usage(opts)
// }

println!("\n{} (apic: {}, proc: {})", core_type, apic_id, processor);
// let all_lapics = get_lapics();
// for lapic in all_lapics.iter() {
// let lapic = lapic.1;
// let apic_id = lapic.read().apic_id();
// let processor = lapic.read().processor_id();
// let is_bootstrap_cpu = lapic.read().is_bootstrap_cpu();
// let core_type = if is_bootstrap_cpu { "Boot CPU" } else { "Secondary CPU" };

// println!("\n{} (apic: {}, proc: {})", core_type, apic_id, processor);

if let Some(runqueue) = runqueue::get_runqueue(apic_id.value() as u8).map(|rq| rq.read().clone()) {
let mut runqueue_contents = String::new();
for task in runqueue.iter() {
writeln!(runqueue_contents, " {} ({}) {}",
task.name,
task.id,
if task.is_running() { "*" } else { "" }
)
.expect("Failed to write to runqueue_contents");
}
print!("{}", runqueue_contents);
}
// if let Some(runqueue) = runqueue::get_runqueue(apic_id.value() as u8).map(|rq| rq.read().clone()) {
// let mut runqueue_contents = String::new();
// for task in runqueue.iter() {
// writeln!(runqueue_contents, " {} ({}) {}",
// task.name,
// task.id,
// if task.is_running() { "*" } else { "" }
// )
// .expect("Failed to write to runqueue_contents");
// }
// print!("{}", runqueue_contents);
// }

else {
println!("Can't retrieve runqueue for core {}", apic_id);
return -1;
}
}
// else {
// println!("Can't retrieve runqueue for core {}", apic_id);
// return -1;
// }
// }

println!("");
0
}
// println!("");
// 0
// }

fn print_usage(opts: Options) -> isize {
let mut brief = "Usage: rq \n \n".to_string();
// fn print_usage(opts: Options) -> isize {
// let mut brief = "Usage: rq \n \n".to_string();

brief.push_str("Prints each CPU's ID, the tasks on its runqueue ('*' identifies the currently running task), and whether it is the boot CPU or not");
// brief.push_str("Prints each CPU's ID, the tasks on its runqueue ('*' identifies the currently running task), and whether it is the boot CPU or not");

println!("{} \n", opts.usage(&brief));
// println!("{} \n", opts.usage(&brief));

0
}
// 0
// }
132 changes: 66 additions & 66 deletions applications/rq_access_eval/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
#![no_std]

extern crate alloc;
// extern crate alloc;

use alloc::{string::String, vec::Vec};
use app_io::println;
use time::{now, Duration, Monotonic};
// use alloc::{string::String, vec::Vec};
// use app_io::println;
// use time::{now, Duration, Monotonic};

pub fn main(args: Vec<String>) -> isize {
let guard = irq_safety::hold_interrupts();
let mut options = getopts::Options::new();
options
.optflag("h", "help", "Display this message")
.optflag("l", "least-busy", "Get the least busy core")
.optopt("c", "core", "Get <core>'s runqueue", "<core>")
.optopt("n", "num", "Perform <num> iterations", "<num>");
// pub fn main(args: Vec<String>) -> isize {
// let guard = irq_safety::hold_interrupts();
// let mut options = getopts::Options::new();
// options
// .optflag("h", "help", "Display this message")
// .optflag("l", "least-busy", "Get the least busy core")
// .optopt("c", "core", "Get <core>'s runqueue", "<core>")
// .optopt("n", "num", "Perform <num> iterations", "<num>");

let matches = match options.parse(args) {
Ok(matches) => matches,
Err(e) => {
println!("{}", e);
print_usage(options);
return 1;
}
};
// let matches = match options.parse(args) {
// Ok(matches) => matches,
// Err(e) => {
// println!("{}", e);
// print_usage(options);
// return 1;
// }
// };

let least_busy = matches.opt_present("l");
let core = matches.opt_get::<u8>("c").expect("failed to parse core");
// let least_busy = matches.opt_present("l");
// let core = matches.opt_get::<u8>("c").expect("failed to parse core");

if least_busy && core.is_some() {
panic!("both the least-busy and core flags can't be specified");
}
// if least_busy && core.is_some() {
// panic!("both the least-busy and core flags can't be specified");
// }

let num = matches
.opt_get_default("n", 1_000_000)
.expect("failed to parse num");
// let num = matches
// .opt_get_default("n", 1_000_000)
// .expect("failed to parse num");

let duration = if least_busy {
run(
|_| {
runqueue::get_least_busy_core();
},
num,
)
} else if let Some(core) = core {
run(
|_| {
runqueue::get_runqueue(core);
},
num,
)
} else {
let cpu_count = cpu::cpu_count();
run(
|count| {
runqueue::get_runqueue((count % cpu_count) as u8);
},
num,
)
};
drop(guard);
// let duration = if least_busy {
// run(
// |_| {
// runqueue::get_least_busy_core();
// },
// num,
// )
// } else if let Some(core) = core {
// run(
// |_| {
// runqueue::get_runqueue(core);
// },
// num,
// )
// } else {
// let cpu_count = cpu::cpu_count();
// run(
// |count| {
// runqueue::get_runqueue((count % cpu_count) as u8);
// },
// num,
// )
// };
// drop(guard);

println!("time: {:#?}", duration);
// println!("time: {:#?}", duration);

0
}
// 0
// }

fn run(f: impl Fn(u32), num: u32) -> Duration {
let start = now::<Monotonic>();
for i in 0..num {
f(i);
}
now::<Monotonic>().duration_since(start)
}
// fn run(f: impl Fn(u32), num: u32) -> Duration {
// let start = now::<Monotonic>();
// for i in 0..num {
// f(i);
// }
// now::<Monotonic>().duration_since(start)
// }

fn print_usage(options: getopts::Options) {
let brief = alloc::format!("Usage: {} [OPTIONS]", env!("CARGO_CRATE_NAME"));
println!("{}", options.usage(&brief));
}
// fn print_usage(options: getopts::Options) {
// let brief = alloc::format!("Usage: {} [OPTIONS]", env!("CARGO_CRATE_NAME"));
// println!("{}", options.usage(&brief));
// }
12 changes: 6 additions & 6 deletions applications/test_scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub fn main(_args: Vec<String>) -> isize {
.pin_on_cpu(cpu_1)
.spawn().expect("failed to initiate task");

if let Err(e) = scheduler::set_priority(&taskref1, 30) {
error!("scheduler_eval(): Could not set priority to taskref1: {}", e);
if !scheduler::set_priority(&taskref1, 30) {
error!("scheduler_eval(): Could not set priority to taskref1");
}

debug!("Spawned Task 1");
Expand All @@ -33,8 +33,8 @@ pub fn main(_args: Vec<String>) -> isize {
.pin_on_cpu(cpu_1)
.spawn().expect("failed to initiate task");

if let Err(e) = scheduler::set_priority(&taskref2, 20) {
error!("scheduler_eval(): Could not set priority to taskref2: {}", e);
if !scheduler::set_priority(&taskref2, 20) {
error!("scheduler_eval(): Could not set priority to taskref2");
}

debug!("Spawned Task 2");
Expand All @@ -44,8 +44,8 @@ pub fn main(_args: Vec<String>) -> isize {
.pin_on_cpu(cpu_1)
.spawn().expect("failed to initiate task");

if let Err(e) = scheduler::set_priority(&taskref3, 10) {
error!("scheduler_eval(): Could not set priority to taskref3: {}", e);
if !scheduler::set_priority(&taskref3, 10) {
error!("scheduler_eval(): Could not set priority to taskref3");
}

debug!("Spawned Task 3");
Expand Down
2 changes: 1 addition & 1 deletion kernel/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use interrupts::{self, CPU_LOCAL_TIMER_IRQ, interrupt_handler, eoi, EoiBehaviour};

/// A re-export of [`task::schedule()`] for convenience and legacy compatibility.
pub use task::schedule;
pub use task::scheduler::{get_priority, schedule, set_priority};


/// Initializes the scheduler on this system using the policy set at compiler time.
Expand Down
1 change: 1 addition & 0 deletions kernel/task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ no_drop = { path = "../no_drop" }
preemption = { path = "../preemption" }
stack = { path = "../stack" }
sync_irq = { path = "../../libs/sync_irq" }
sync_preemption = { path = "../sync_preemption" }
task_struct = { path = "../task_struct" }
waker_generic = { path = "../waker_generic" }
Loading

0 comments on commit 0eae81f

Please sign in to comment.