Skip to content
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

Microoptimizations #82

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ jobs:

rustfmt:
runs-on: ubuntu-latest
container: rustlang/rust:nightly
container: docker.io/rust
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Add rustfmt component
run: rustup component add rustfmt
- name: Run cargo-fmt
run: cargo fmt --check

Expand Down
3 changes: 0 additions & 3 deletions rustfmt.toml

This file was deleted.

5 changes: 1 addition & 4 deletions src/coap_handler/v0_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use core::convert::TryInto;
use coap_handler_0_2::{Attribute, Handler, Record, Reporting};

use coap_message_0_3::{
error::RenderableOnMinimal,
MinimalWritableMessage,
MutableWritableMessage,
ReadableMessage,
error::RenderableOnMinimal, MinimalWritableMessage, MutableWritableMessage, ReadableMessage,
};

use crate::coap_message::ResponseMessage;
Expand Down
5 changes: 1 addition & 4 deletions src/coap_message/impl_0_2.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use coap_message_0_2::{
MessageOption,
MinimalWritableMessage,
MutableWritableMessage,
ReadableMessage,
MessageOption, MinimalWritableMessage, MutableWritableMessage, ReadableMessage,
WithSortedOptions,
};

Expand Down
9 changes: 2 additions & 7 deletions src/coap_message/impl_0_3.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use coap_message_0_3::{
error::RenderableOnMinimal,
Code,
MessageOption,
MinimalWritableMessage,
MutableWritableMessage,
ReadableMessage,
WithSortedOptions,
error::RenderableOnMinimal, Code, MessageOption, MinimalWritableMessage,
MutableWritableMessage, ReadableMessage, WithSortedOptions,
};

use crate::error::NumericError;
Expand Down
6 changes: 1 addition & 5 deletions src/gcoap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ fn link_encoder_safe<H: WithLinkEncoder>(
}
}


impl<'a, H> SingleHandlerListener<'a, H>
where
H: 'a + Handler + WithLinkEncoder,
Expand Down Expand Up @@ -336,10 +335,7 @@ pub trait WithLinkEncoder {
}

use riot_sys::{
coap_opt_add_opaque,
coap_opt_add_uint,
coap_opt_get_next,
gcoap_register_listener,
coap_opt_add_opaque, coap_opt_add_uint, coap_opt_get_next, gcoap_register_listener,
gcoap_resp_init,
};

Expand Down
10 changes: 2 additions & 8 deletions src/gnrc_pktbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ use core::marker::PhantomData;
use core::mem::forget;

use riot_sys::{
gnrc_netif_hdr_build,
gnrc_nettype_t,
gnrc_pktbuf_add,
gnrc_pktbuf_hold,
gnrc_pktbuf_realloc_data,
gnrc_pktbuf_release_error,
gnrc_pktsnip_t,
GNRC_NETERR_SUCCESS,
gnrc_netif_hdr_build, gnrc_nettype_t, gnrc_pktbuf_add, gnrc_pktbuf_hold,
gnrc_pktbuf_realloc_data, gnrc_pktbuf_release_error, gnrc_pktsnip_t, GNRC_NETERR_SUCCESS,
};

/// Error type for pktsnip operations that need free buffer space
Expand Down
4 changes: 1 addition & 3 deletions src/gnrc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use crate::thread::KernelPID;
#[cfg(riot_module_gnrc_udp)]
use riot_sys::gnrc_nettype_t_GNRC_NETTYPE_UDP as GNRC_NETTYPE_UDP;
use riot_sys::{
gnrc_netif_hdr_t,
gnrc_nettype_t_GNRC_NETTYPE_NETIF as GNRC_NETTYPE_NETIF,
udp_hdr_t,
gnrc_netif_hdr_t, gnrc_nettype_t_GNRC_NETTYPE_NETIF as GNRC_NETTYPE_NETIF, udp_hdr_t,
};

/// Trait of data structures that store all the information needed to respond to a Pktsnip in some
Expand Down
6 changes: 1 addition & 5 deletions src/microbit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
//! [microbit module]: https://doc.riot-os.org/group__boards__common__microbit.html

use embedded_graphics::{
drawable::Pixel,
geometry::Point,
geometry::Size,
pixelcolor::BinaryColor,
DrawTarget,
drawable::Pixel, geometry::Point, geometry::Size, pixelcolor::BinaryColor, DrawTarget,
};

use crate::Never;
Expand Down
22 changes: 7 additions & 15 deletions src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
fn panic(info: &::core::panic::PanicInfo) -> ! {
use crate::thread;

let os_can_continue = crate::thread::InThread::new()
// Panics with IRQs off are fatal because we can't safely re-enable them
.map(|i| i.irq_is_enabled())
// Panics in ISRs are always fatal because continuing in threads would signal to the
// remaining system that the ISR terminated
.unwrap_or(false);
let os_can_continue = !cfg!(feature = "panic_handler_crash")
&& crate::thread::InThread::new()
// Panics with IRQs off are fatal because we can't safely re-enable them
.map(|i| i.irq_is_enabled())
// Panics in ISRs are always fatal because continuing in threads would signal to the
// remaining system that the ISR terminated
.unwrap_or(false);

if !os_can_continue {
// We can't abort on stable -- but even if we could: Set a breakpoint and wait for the
Expand Down Expand Up @@ -49,15 +50,6 @@ fn panic(info: &::core::panic::PanicInfo) -> ! {
let _ = stdio.write_str("!\n");
}

if cfg!(feature = "panic_handler_crash") {
unsafe {
riot_sys::core_panic(
riot_sys::core_panic_t_PANIC_GENERAL_ERROR,
cstr::cstr!("RUST PANIC").as_ptr() as _,
)
}
}

// Not trying any unwinding -- this thread is just dead, won't be re-claimed, any mutexes it
// holds are just held indefinitely rather than throwing poison errors.
loop {
Expand Down
1 change: 0 additions & 1 deletion src/saul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use error::NegativeErrorExt;

pub mod registration;


/// A discovered SAUL registry entry
pub struct RegistryEntry(*mut riot_sys::saul_reg);

Expand Down
1 change: 0 additions & 1 deletion src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ pub fn new() -> impl CommandList {
CommandListEnd
}


/// Make a function whose signature is `fn(&mut `[`Stdio`](stdio::Stdio)`, `[`Args`]`<'b>) -> impl `[`Termination`](crate::main::Termination) available through
/// XFA in any RIOT shell, even when called throuch C. (The function's signature may be more
/// generic, eg. accepting an `impl `[`Write`](core::fmt::Write) and an `impl `[`IntoIterator`]`<&str>`).
Expand Down
1 change: 0 additions & 1 deletion src/socket_embedded_nal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl<'a, const UDPCOUNT: usize> StackAccessor<'a, UDPCOUNT> {
// that the stack is available for 'a and won't move.
let socket: &'a mut _ = unsafe { &mut *socket };


handle.socket = Some(socket);

Ok(())
Expand Down
8 changes: 1 addition & 7 deletions src/spi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use crate::Never;
use embedded_hal_0_2::blocking;
use riot_sys::{
spi_acquire,
spi_clk_t,
spi_cs_t,
spi_mode_t,
spi_release,
spi_t,
spi_transfer_bytes,
spi_acquire, spi_clk_t, spi_cs_t, spi_mode_t, spi_release, spi_t, spi_transfer_bytes,
};

pub struct SPIDevice(#[deprecated(note = "Use constructor instead")] pub spi_t);
Expand Down
5 changes: 5 additions & 0 deletions src/thread/riot_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ impl KernelPID {
}

pub fn get_name(&self) -> Option<&str> {
// Shortcut through an otherwise unoptimizable function
if !cfg!(riot_develhelp) {
return None;
}

let ptr = unsafe { raw::thread_getname(self.0) };

// If the thread stops, the name might be not valid any more, but then again the getname
Expand Down
1 change: 0 additions & 1 deletion src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ impl Drop for File {
}
}


/// A directory in the file system
///
/// The directory can be iterated over, producing directory entries one by one.
Expand Down
1 change: 0 additions & 1 deletion src/ztimer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ impl embedded_hal_async::delay::DelayNs for Delay {
}
}


impl<const F: u32> embedded_hal::delay::DelayNs for Clock<F> {
// FIXME: Provide delay_us and delay_ms, at least for the clocks where those fit, to avoid the
// loops where the provided function wakes up every 4.3s
Expand Down
Loading