Comments (7)
Note that setting HERMIT_CPUS=2
fixes the symptoms, even when having three or more threads.
from hermit-rs.
I found that the behavior is identical when running on QEMU. One CPU does not preempt, more than one do.
from hermit-rs.
I don't really have any knowledge about the APIC or the scheduler implementation, but here my two cents on the symptoms:
AFAIK the scheduler in rusty-hermit has some concept of priorities. It seems possible to me that the priority of threads generated via thread::spawn
is lower than that of the main thread. In that case, the main thread would always be scheduled (if only a single core is available). Linux uses CFS (Completly Fair Scheduler) by default, so the main thread can't starve the spawned thread on Linux.
You could set a breakpoint / debug print in the scheduler to see if it really is never called.
from hermit-rs.
Thanks for the fast reply, @jschwe!
Good idea with the priorities! With two cores, the above code also fires the timer handler often, which calls the scheduler, but with one core, it does not. Not firing the interrupt handler is suspicious, but the starving could still be caused by priorities. The timer interrupt seems to operate in one-shot mode and not fire periodically, so if the scheduler would not want to preempt the current thread again in the future because of priorities, this might fit.
Another setup stills seems weird though:
Spawn a second thread, which does not print to Stdout
:
use std::thread;
fn main() {
thread::spawn(|| loop {
println!(" 2")
});
thread::spawn(|| loop {});
loop {
println!("1 ")
}
}
Running this code on uhyve with two cores only prints “ 2”, which I interpret as the first thread running on one core and the second thread and the main thread on the other core with the second thread starving the main thread. When printing in the second thread as well, I can read all three outputs again. So to me, it seems like something is going wrong with the one-shot timer setup when not yielding to the kernel by waiting on Stdout
's mutex hidden in println!
in this case.
I hope this makes some sense.
from hermit-rs.
I don't have any further ideas or time to investigate this currently. Pinging @stlankes since it looks like he might have overlooked this.
from hermit-rs.
RustyHermit uses currently a cooperative scheduler. If you not block a task, the task will never give up the CPU. Your main loop should call std::thread::yield_now
.
from hermit-rs.
All right, that makes sense. Thanks for the clarification!
from hermit-rs.
Related Issues (20)
- failed to run rusty-hermit on QEMU qemu-system-aarch64 HOT 1
- Where do we mention that RustyHermit supports `aarch64`?
- Hermit doesn't work on aarch64: rusty-loader can't find DTB for aarch64 HOT 1
- Include `tcp` in the default features of `hermit-sys`
- hermit-abi 0.3.2 git tag and yanking explanation HOT 4
- Add platform support document to Rust docs HOT 1
- Enable generate-link-to-definition
- Support automatic rebuilds for path dependencies of kernel HOT 1
- Can't build with khronos-egl as dependency HOT 3
- Become a Tier 2 Rust target
- Newer kernel submodule required for RISC-V support HOT 4
- Compilation with Hermit dependency as part of a workspace fails HOT 1
- Networking config file HOT 4
- Benchmarking HOT 8
- Hermit randomness API
- Unable to read directory entries HOT 1
- perf: rework laplace demo with ndarray
- Cargo configuration file messes with kernel compilation when using `hermit` crate HOT 1
- Lost TCP packets
- UDP capped at 1472 Bytes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hermit-rs.