mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
move more crates into stardized formatting
This commit is contained in:
parent
fd4e047d62
commit
340048aac9
5 changed files with 108 additions and 54 deletions
|
|
@ -1,12 +1,10 @@
|
|||
# if you want to format 'em, then you maintain 'em!
|
||||
ignore = [
|
||||
"services/graphics-server",
|
||||
"services/com",
|
||||
"services/keyboard",
|
||||
#"services/trng",
|
||||
"services/gam",
|
||||
"services/status",
|
||||
"services/benchmark",
|
||||
"services/benchmark-target",
|
||||
"services/ime-frontend",
|
||||
"services/ime-plugin-shell",
|
||||
"services/shellchat",
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@ pub struct TestStruct {
|
|||
}
|
||||
impl TestStruct {
|
||||
pub fn new() -> Self {
|
||||
TestStruct {
|
||||
challenge: [0; 8],
|
||||
}
|
||||
TestStruct { challenge: [0; 8] }
|
||||
}
|
||||
}
|
||||
|
||||
pub const SERVER_NAME_BENCHMARK: &str= "_Benchmark target_";
|
||||
pub const SERVER_NAME_BENCHMARK: &str = "_Benchmark target_";
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
|
|
|
|||
|
|
@ -3,13 +3,21 @@
|
|||
pub mod api;
|
||||
use api::*;
|
||||
|
||||
use xous::{CID, send_message};
|
||||
use num_traits::ToPrimitive;
|
||||
use xous::{send_message, CID};
|
||||
use xous_ipc::Buffer;
|
||||
use num_traits::{ToPrimitive};
|
||||
|
||||
pub fn test_scalar(cid: CID, testvar: u32) -> Result<u32, xous::Error> {
|
||||
let response = send_message(cid,
|
||||
xous::Message::new_blocking_scalar(Opcode::TestScalar.to_usize().unwrap(), testvar as usize, 0, 0, 0))?;
|
||||
let response = send_message(
|
||||
cid,
|
||||
xous::Message::new_blocking_scalar(
|
||||
Opcode::TestScalar.to_usize().unwrap(),
|
||||
testvar as usize,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)?;
|
||||
if let xous::Result::Scalar1(r) = response {
|
||||
Ok(r as u32)
|
||||
} else {
|
||||
|
|
@ -22,7 +30,8 @@ pub fn test_memory(cid: CID, testvar: u32) -> Result<u32, xous::Error> {
|
|||
reg.challenge[0] = testvar;
|
||||
|
||||
let mut buf = Buffer::into_buf(reg).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(cid, Opcode::TestMemory.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(cid, Opcode::TestMemory.to_u32().unwrap())
|
||||
.or(Err(xous::Error::InternalError))?;
|
||||
|
||||
let result = buf.as_flat::<TestStruct, _>().unwrap();
|
||||
Ok(result.challenge[0])
|
||||
|
|
@ -33,6 +42,7 @@ pub fn test_memory_send(cid: CID, testvar: u32) -> Result<u32, xous::Error> {
|
|||
reg.challenge[0] = testvar;
|
||||
|
||||
let mut buf = Buffer::into_buf(reg).or(Err(xous::Error::InternalError))?;
|
||||
buf.send(cid, Opcode::TestMemorySend.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
Ok(testvar+2)
|
||||
buf.send(cid, Opcode::TestMemorySend.to_u32().unwrap())
|
||||
.or(Err(xous::Error::InternalError))?;
|
||||
Ok(testvar + 2)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ use xous::msg_blocking_scalar_unpack;
|
|||
|
||||
use log::{error, info};
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
use xous_ipc::Buffer;
|
||||
use num_traits::{FromPrimitive};
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
|
|
@ -16,7 +16,9 @@ fn xmain() -> ! {
|
|||
info!("BENCHTARGET: my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let bench_sid = xns.register_name(api::SERVER_NAME_BENCHMARK, None).expect("BENCHTARGET: can't register server");
|
||||
let bench_sid = xns
|
||||
.register_name(api::SERVER_NAME_BENCHMARK, None)
|
||||
.expect("BENCHTARGET: can't register server");
|
||||
info!("BENCHTARGET: registered with NS -- {:?}", bench_sid);
|
||||
|
||||
let mut state: u32 = 0;
|
||||
|
|
@ -25,22 +27,28 @@ fn xmain() -> ! {
|
|||
match FromPrimitive::from_usize(envelope.body.id()) {
|
||||
Some(Opcode::TestScalar) => msg_blocking_scalar_unpack!(envelope, val, _, _, _, {
|
||||
xous::return_scalar(envelope.sender, (val + 1) as usize)
|
||||
.expect("BENCHTARGET: couldn't return TestScalar request");
|
||||
.expect("BENCHTARGET: couldn't return TestScalar request");
|
||||
}),
|
||||
Some(Opcode::TestMemory) => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(envelope.body.memory_message_mut().unwrap()) };
|
||||
let mut buffer = unsafe {
|
||||
Buffer::from_memory_message_mut(envelope.body.memory_message_mut().unwrap())
|
||||
};
|
||||
let reg = buffer.to_original::<TestStruct, _>().unwrap();
|
||||
|
||||
let mut ret = TestStruct::new();
|
||||
ret.challenge[0] = reg.challenge[0] + 1;
|
||||
buffer.replace(ret).unwrap();
|
||||
},
|
||||
}
|
||||
Some(Opcode::TestMemorySend) => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(envelope.body.memory_message_mut().unwrap()) };
|
||||
let mut buffer = unsafe {
|
||||
Buffer::from_memory_message_mut(envelope.body.memory_message_mut().unwrap())
|
||||
};
|
||||
let reg = buffer.to_original::<TestStruct, _>().unwrap();
|
||||
state += reg.challenge[0];
|
||||
}
|
||||
None => {error!("BENCHTARGET: couldn't convert opcode");}
|
||||
None => {
|
||||
error!("BENCHTARGET: couldn't convert opcode");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
NOTE: this assumes that you turn off the watchdog timer. This code does not include enough sleeps to reset the WDT
|
||||
Do this by removing the watchdog feature in the ticktimer-server Cargo.toml crate
|
||||
****************/
|
||||
use blitstr::GlyphStyle;
|
||||
use blitstr_ref as blitstr;
|
||||
use blitstr::{GlyphStyle};
|
||||
use core::fmt::Write;
|
||||
use graphics_server::{DrawStyle, PixelColor, Point, Rectangle, TextView, TextBounds, TextOp};
|
||||
use graphics_server::{DrawStyle, PixelColor, Point, Rectangle, TextBounds, TextOp, TextView};
|
||||
|
||||
use log::{error, info};
|
||||
use num_traits::{ToPrimitive, FromPrimitive};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub enum Opcode {
|
||||
|
|
@ -19,7 +19,7 @@ pub enum Opcode {
|
|||
Stop,
|
||||
}
|
||||
|
||||
const SERVER_NAME_SHELL: &str = "_Shell_";
|
||||
const SERVER_NAME_SHELL: &str = "_Shell_";
|
||||
|
||||
fn stopwatch_thread() {
|
||||
info!("BENCHMARK|stopwatch: starting");
|
||||
|
|
@ -27,7 +27,9 @@ fn stopwatch_thread() {
|
|||
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let shell_conn = xns.request_connection_blocking(SERVER_NAME_SHELL).expect("BENCHMARK|stopwatch: can't connect to main program");
|
||||
let shell_conn = xns
|
||||
.request_connection_blocking(SERVER_NAME_SHELL)
|
||||
.expect("BENCHMARK|stopwatch: can't connect to main program");
|
||||
let mut last_time: u64 = ticktimer.elapsed_ms();
|
||||
let mut start_sent = false;
|
||||
loop {
|
||||
|
|
@ -35,23 +37,35 @@ fn stopwatch_thread() {
|
|||
if false {
|
||||
if elapsed_time - last_time > 500 && !start_sent {
|
||||
last_time = elapsed_time;
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Start.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
xous::send_message(
|
||||
shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Start.to_usize().unwrap(), 0, 0, 0, 0),
|
||||
)
|
||||
.expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
start_sent = true;
|
||||
} else if elapsed_time - last_time > 10_000 && start_sent {
|
||||
last_time = elapsed_time;
|
||||
start_sent = false;
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Stop.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
xous::send_message(
|
||||
shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Stop.to_usize().unwrap(), 0, 0, 0, 0),
|
||||
)
|
||||
.expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
}
|
||||
} else {
|
||||
// send a start loop message
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Start.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
xous::send_message(
|
||||
shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Start.to_usize().unwrap(), 0, 0, 0, 0),
|
||||
)
|
||||
.expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
ticktimer.sleep_ms(10_000).expect("couldn't sleep");
|
||||
// send a stop loop message
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Stop.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
xous::send_message(
|
||||
shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Stop.to_usize().unwrap(), 0, 0, 0, 0),
|
||||
)
|
||||
.expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
// give a moment for the result to update
|
||||
ticktimer.sleep_ms(500).expect("couldn't sleep");
|
||||
}
|
||||
|
|
@ -68,29 +82,46 @@ fn shell_main() -> ! {
|
|||
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let shell_server = xns.register_name(SERVER_NAME_SHELL, None).expect("BENCHMARK: can't register server");
|
||||
let shell_server = xns
|
||||
.register_name(SERVER_NAME_SHELL, None)
|
||||
.expect("BENCHMARK: can't register server");
|
||||
|
||||
let gfx = graphics_server::Gfx::new(&xns).unwrap();
|
||||
let target_conn = xns.request_connection_blocking(benchmark_target::api::SERVER_NAME_BENCHMARK).expect("BENCHMARK: can't connect to COM");
|
||||
let target_conn = xns
|
||||
.request_connection_blocking(benchmark_target::api::SERVER_NAME_BENCHMARK)
|
||||
.expect("BENCHMARK: can't connect to COM");
|
||||
|
||||
xous::create_thread_0(stopwatch_thread).unwrap();
|
||||
info!("BENCHMARK: stopwatch thread started");
|
||||
|
||||
let screensize = gfx.screen_size().expect("Couldn't get screen size");
|
||||
|
||||
let font_h: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16;
|
||||
let font_h: i16 = gfx
|
||||
.glyph_height_hint(GlyphStyle::Small)
|
||||
.expect("couldn't get glyph height") as i16;
|
||||
|
||||
let status_clipregion =
|
||||
Rectangle::new_coords_with_style(4, 0, screensize.x, font_h as i16 * 4, DrawStyle::new(PixelColor::Light, PixelColor::Light, 1));
|
||||
let status_clipregion = Rectangle::new_coords_with_style(
|
||||
4,
|
||||
0,
|
||||
screensize.x,
|
||||
font_h as i16 * 4,
|
||||
DrawStyle::new(PixelColor::Light, PixelColor::Light, 1),
|
||||
);
|
||||
|
||||
gfx.draw_rectangle(Rectangle::new_with_style(Point::new(0, 0), screensize,
|
||||
DrawStyle::new(PixelColor::Light, PixelColor::Light, 0)
|
||||
))
|
||||
.expect("unable to clear region");
|
||||
gfx.draw_rectangle(Rectangle::new_with_style(
|
||||
Point::new(0, 0),
|
||||
screensize,
|
||||
DrawStyle::new(PixelColor::Light, PixelColor::Light, 0),
|
||||
))
|
||||
.expect("unable to clear region");
|
||||
|
||||
let mut result_tv = TextView::new(graphics_server::Gid::new([0, 0, 0, 0]),
|
||||
TextBounds::BoundingBox(Rectangle::new(Point::new(0,0),
|
||||
Point::new(screensize.x, screensize.y - 1))));
|
||||
let mut result_tv = TextView::new(
|
||||
graphics_server::Gid::new([0, 0, 0, 0]),
|
||||
TextBounds::BoundingBox(Rectangle::new(
|
||||
Point::new(0, 0),
|
||||
Point::new(screensize.x, screensize.y - 1),
|
||||
)),
|
||||
);
|
||||
result_tv.set_op(TextOp::Render);
|
||||
result_tv.clip_rect = Some(status_clipregion.into());
|
||||
result_tv.untrusted = false;
|
||||
|
|
@ -115,11 +146,11 @@ fn shell_main() -> ! {
|
|||
match FromPrimitive::from_usize(envelope.body.id()) {
|
||||
Some(Opcode::Start) => {
|
||||
start_time = ticktimer.elapsed_ms();
|
||||
},
|
||||
}
|
||||
Some(Opcode::Stop) => {
|
||||
stop_time = ticktimer.elapsed_ms();
|
||||
update_result = true;
|
||||
},
|
||||
}
|
||||
None => {
|
||||
error!("BENCHMARK: couldn't convert opcode");
|
||||
}
|
||||
|
|
@ -136,7 +167,8 @@ fn shell_main() -> ! {
|
|||
// xous v0.8
|
||||
// 29729 per 10s = 2972.9/s (hardware)
|
||||
// 485 per 10s = 48.5/s (hosted)
|
||||
count = benchmark_target::test_scalar(target_conn, count).expect("BENCHMARK: couldn't send test message");
|
||||
count = benchmark_target::test_scalar(target_conn, count)
|
||||
.expect("BENCHMARK: couldn't send test message");
|
||||
check_count = check_count + 1;
|
||||
} else {
|
||||
if false {
|
||||
|
|
@ -146,11 +178,13 @@ fn shell_main() -> ! {
|
|||
// xous v0.8
|
||||
// 9,928 per 10s = 992.8/s (hardware)
|
||||
// 243 per 10s = 24.3/s (hosted)
|
||||
count = benchmark_target::test_memory(target_conn, count).expect("BENCHMARK: couldn't send test message");
|
||||
count = benchmark_target::test_memory(target_conn, count)
|
||||
.expect("BENCHMARK: couldn't send test message");
|
||||
check_count = check_count + 1;
|
||||
} else {
|
||||
// simple send benchmark, instead of lend
|
||||
count = benchmark_target::test_memory_send(target_conn, count).expect("BENCHMARK: couldn't send test message");
|
||||
count = benchmark_target::test_memory_send(target_conn, count)
|
||||
.expect("BENCHMARK: couldn't send test message");
|
||||
check_count = check_count + 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -159,11 +193,17 @@ fn shell_main() -> ! {
|
|||
update_result = false;
|
||||
|
||||
gfx.draw_rectangle(status_clipregion)
|
||||
.expect("unable to clear region");
|
||||
.expect("unable to clear region");
|
||||
|
||||
result_tv.clear_str();
|
||||
write!(&mut result_tv, "Elapsed: {}, count: {}, check: {}",
|
||||
stop_time - start_time, count, check_count).unwrap();
|
||||
write!(
|
||||
&mut result_tv,
|
||||
"Elapsed: {}, count: {}, check: {}",
|
||||
stop_time - start_time,
|
||||
count,
|
||||
check_count
|
||||
)
|
||||
.unwrap();
|
||||
gfx.draw_textview(&mut result_tv).unwrap();
|
||||
gfx.flush().expect("unable to draw to screen");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue