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

rust: thread: Add Thread wrapper #109

Open
wants to merge 2 commits into
base: rust
Choose a base branch
from
Open
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: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ jobs:
grep '] rust_sync: Value: 10$' qemu-stdout.log
grep '] rust_sync: Rust synchronisation primitives sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_thread: Rust thread APIs sample (init)$' qemu-stdout.log
grep '] rust_thread: Rust thread APIs sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_chrdev: Rust character device sample (init)$' qemu-stdout.log
grep '] rust_chrdev: Rust character device sample (exit)$' qemu-stdout.log
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-arm64-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-ppc64le-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-ppc64le-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-riscv64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-riscv64-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-x86_64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/kernel-x86_64-release.config
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ CONFIG_SAMPLE_RUST_MINIMAL=m
CONFIG_SAMPLE_RUST_PRINT=m
CONFIG_SAMPLE_RUST_MODULE_PARAMETERS=m
CONFIG_SAMPLE_RUST_SYNC=m
CONFIG_SAMPLE_RUST_THREAD=m
CONFIG_SAMPLE_RUST_CHRDEV=m
CONFIG_SAMPLE_RUST_MISCDEV=m
CONFIG_SAMPLE_RUST_STACK_PROBING=m
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/qemu-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ busybox rmmod rust_module_parameters.ko
busybox insmod rust_sync.ko
busybox rmmod rust_sync.ko

busybox insmod rust_thread.ko
busybox rmmod rust_thread.ko

busybox insmod rust_chrdev.ko
busybox rmmod rust_chrdev.ko

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/qemu-initramfs.desc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ file /rust_minimal.ko samples/rust/rust_minimal.ko 0755
file /rust_print.ko samples/rust/rust_print.ko 0755 0 0
file /rust_module_parameters.ko samples/rust/rust_module_parameters.ko 0755 0 0
file /rust_sync.ko samples/rust/rust_sync.ko 0755 0 0
file /rust_thread.ko samples/rust/rust_thread.ko 0755 0 0
file /rust_chrdev.ko samples/rust/rust_chrdev.ko 0755 0 0
file /rust_miscdev.ko samples/rust/rust_miscdev.ko 0755 0 0
file /rust_stack_probing.ko samples/rust/rust_stack_probing.ko 0755 0 0
Expand Down
1 change: 1 addition & 0 deletions rust/kernel/bindings_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <linux/cdev.h>
#include <linux/errname.h>
#include <linux/fs.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/slab.h>
Expand Down
2 changes: 0 additions & 2 deletions rust/kernel/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ macro_rules! from_kernel_result {
/// }
/// }
/// ```
// TODO: remove `dead_code` marker once an in-kernel client is available.
#[allow(dead_code)]
pub(crate) fn from_kernel_err_ptr<T>(ptr: *mut T) -> Result<*mut T> {
// CAST: casting a pointer to `*const c_types::c_void` is always valid.
let const_ptr: *const c_types::c_void = ptr.cast();
Expand Down
1 change: 1 addition & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub mod print;
pub mod random;
mod static_assert;
pub mod sync;
pub mod thread;

#[cfg(any(CONFIG_SYSCTL, doc))]
#[doc(cfg(CONFIG_SYSCTL))]
Expand Down
10 changes: 10 additions & 0 deletions rust/kernel/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ impl Task {
// SAFETY: By the type invariant, we know that `self.ptr` is non-null and valid.
unsafe { bindings::signal_pending(self.ptr) != 0 }
}

/// Wakes up the task.
pub fn wake_up(&self) {
// SAFETY: By the type invariant, we know that `self.ptr` is non-null and valid.
// And `wake_up_process` is safe to be called for any valid task, even if the task is
// running.
unsafe {
bindings::wake_up_process(self.ptr);
}
}
}

impl PartialEq for Task {
Expand Down
Loading