-
Notifications
You must be signed in to change notification settings - Fork 666
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
Tracking: Remove static global variables in kernel (process.rs) #1043
Comments
For the updates to In this version, the It seems like most of the @ppannuto thoughts? |
On the one hand, I think that someday, some ability to write "kernel app(let)s" will be useful, under the arguments of performance/timing/etc. However, I agree that the first pass at that is pretty cumbersome and a little too hacked together, I won't be so sad to see it go. The changes to Debug look pretty good to me, especially if we virtualize the console |
A note that having |
I tried to take a stab at removing the static process array, and found very quickly that because we handle Process as |
On attempt number 3 of moving the /// Main object for the kernel. Each board will need to create one.
pub struct Kernel {
/// How many "to-do" items exist at any given time. These include
/// outstanding callbacks and processes in the Running state.
work: Cell<usize>,
/// This holds a pointer to the static array of Process pointers.
processes: TakeCell<'static, [Option<&'static mut Process<'static>>]>,
} Then many structs defined in the kernel crate need a pointer to the kernel something like this: pub struct Grant<T: Default> {
kernel: &'static Kernel,
grant_num: usize,
ptr: PhantomData<T>,
} Then all uses of the impl Allocator {
pub fn alloc<T>(&mut self, data: T) -> Result<Owned<T>, Error> {
unsafe {
let app_id = self.app_id;
self.kernel.process_map_or(Err(Error::NoSuchApp), app_id, |process| {
process.alloc(size_of::<T>())
.map_or(Err(Error::OutOfMemory), |arr| {
...
})
})
}
}
} where the impl Kernel {
...
crate fn process_map_or<F, R>(&self, default: R, process_index: usize, closure: F) -> R
where
F: FnOnce(&mut Process) -> R,
{
let processes_len = self.processes.map_or(0, |processes| processes.len());
if process_index > processes_len {
return default;
}
self.processes.map_or_else(|| panic!("boo"), |processes| {
processes[process_index].as_mut().map_or(default, |mut val| {
closure(val)
})
})
}
...
} The issue is that the kernel immediately takes the processes array inside of the takecell, so all future calls that try to use that array have nothing there (and the code shown panics). So...this approach seems like it won't work. The only other idea I have is to make the Am I missing any other approaches? |
@bradjc, I don't think you're missing anything. Make Another approach could be to explicitly pass around |
Do we care about moving the Line 11 in af55345
It could also move to the |
I think this one belongs in the grant module. |
Should we think about some mechanism to detect calling |
Support for this is in master. |
Right now there are two key variables in process.rs that the kernel uses extensively:
Having these global variables is probably not the best design choice, and doesn't match how the rest of Tock is structured. Plus removing them would remove a bunch of
unsafe
uses. This tracking issue is a place to work on what it would take to "tockify" those variables.debug.rs
(Refactor debug.rs to not be implemented as a kernel process #1046)Kernel
struct that would hold this kernel-crate global state (kernel: make HAVE_WORK a member variable #1044)Kernel
struct somehow (Kernel: MovePROCS
array toKernel
struct #1111)CONTAINER_COUNTER
toKernel
so we can ensure grants are created before process memory is setup.APP_FAULT
andSCB_REGISTERS
to /arch crates. (Move architecture-dependent syscall code to arch/cortex-m #1113, Move architecture-dependent debugging print code to arch/cortex-m #1115)debug.rs makes it hard to refactor code in the kernel because it is so different from how the rest of the kernel is structured. It is predicated on the idea of "kernel processes", or code in the kernel that looks like any other app to capsules. These feel a bit bolted on and have lead to some difficult-to-maintain code. A possible replacement would be to make debug.rs not look like apps, and instead use a dedicated kernel interface from a capsule instead. Since we haven't had any other uses for kernel processes this seems reasonable.
Making process.rs not cortex-m specific will remove the global static variables that are used to move information from interrupt handlers to the kernel (like
APP_FAULT
andSCB_REGISTERS
.The text was updated successfully, but these errors were encountered: