forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Klimenty Tsoutsman <klim@tsoutsman.com>
- Loading branch information
Showing
7 changed files
with
177 additions
and
145 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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 | ||
// } |
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,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)); | ||
// } |
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
Oops, something went wrong.