Repository navigation
feat(task): add per-task CPU frequency - #808
Kanata9020 wants to merge 1 commit into
Conversation
|
|
||
| [dependencies.awkernel_async_lib] | ||
| path = "../../../awkernel_async_lib" | ||
| default-features = false |
There was a problem hiding this comment.
Activate the dvfs feature?
There was a problem hiding this comment.
It's already enabled in userland: the test_dvfs_task feature in userland/Cargo.toml enables awkernel/dvfs.
There was a problem hiding this comment.
While it is enabled in userland, this example needs the awkernel_async_lib/dvfs feature to compile. Thus, I think it is a good practice to also activate it here.
Now, you are using Awkernel's userland, which does all the feature heavy-lifting. However, if you also activate the feature here, third-party users could also use you example on their custom userlands.
47f27b4 to
25a7bb1
Compare
romancardenas
left a comment
There was a problem hiding this comment.
Thanks! A minor comment
25a7bb1 to
d2074af
Compare
| #[cfg(feature = "dvfs")] | ||
| match freq { | ||
| Some(f) => { | ||
| if let Err(e) = awkernel_lib::dvfs::set_cpu_freq_clamped(f) { |
There was a problem hiding this comment.
Could we also apply the incoming task’s frequency policy when resuming a preempted task? This code only runs before Future::poll. Both yield_and_pool(ctx) in run_main() and the direct switch to a saved context in preempt.rs bypass it. For example, if a max-frequency task preempts a task running at half speed, the latter can resume without its half-speed request being reapplied. Both switch paths should apply the incoming task’s requested frequency, or max if it has no explicit request.
There was a problem hiding this comment.
Thanks. Both switch paths now apply the incoming task's requested frequency, or max if it has no explicit request, before switching: yield_and_pool(ctx) in run_main() and the switch to a saved context in do_preemption(). I moved the frequency policy into a helper, apply_task_freq(), which these two paths and the existing pre-poll path all call.
| // CPU#0 is the primary CPU and does not run tasks. | ||
| let min = get_min_cpu_freq(); | ||
| for core in 1..num_cpu() { | ||
| let handle = awkernel_async_lib::spawn( |
There was a problem hiding this comment.
This probe is spawned without a frequency request, so run_main() requests the maximum frequency before the probe calls get_curr_cpu_freq(). The reading is taken while the probe is running, so it can’t tell us whether the scheduler requested the minimum frequency when the CPU went idle. Could we record the result of set_min_cpu_freq() in the idle path and check it afterward instead?
There was a problem hiding this comment.
Thanks. The scheduler now keeps a per-CPU record: the idle path stores whether set_min_cpu_freq() succeeded, and the record is reset when a task runs on that CPU. The test no longer spawns probes. It reads the records of all worker CPUs from the CPU running the test and skips that CPU. It reads all records before logging, because logging wakes the logger task, which resets the record of the CPU it runs on.
Result on real hardware (x86_64):
[4889 INFO] dvfs_task 2 finished
[4986 INFO] after all tasks: CPU#1 requested the minimum frequency when idle
[4986 INFO] after all tasks: CPU#2 requested the minimum frequency when idle
[4986 INFO] after all tasks: CPU#3 requested the minimum frequency when idle
[4986 INFO] after all tasks: CPU#4 is running this test, skipped
[4986 INFO] after all tasks: CPU#5 requested the minimum frequency when idle
[4986 INFO] after all tasks: CPU#6 requested the minimum frequency when idle
[4986 INFO] after all tasks: CPU#7 requested the minimum frequency when idle
...
[4987 INFO] after all tasks: CPU#23 requested the minimum frequency when id
Add `task::spawn_with_freq()` to run a task at a given CPU frequency. A task without a frequency runs at the maximum, and an idle CPU runs at the minimum. The `dvfs` feature enables this. - Add `freq` to `TaskInfo`. - Add `awkernel_lib::dvfs::set_min_cpu_freq()`. - Add test_dvfs_task.
d2074af to
e90ea14
Compare
Description
Add
task::spawn_with_freq()to run a task at a given CPU frequency. Thedvfsfeature ofawkernel_async_libenables this, and thedvfsfeature of the kernel now turns it on.run_main()sets the CPU frequency as follows:flowchart TD Start([start]) --> C1{"ready task in queue?"} C1 -- Yes --> P1[retrieve task] C1 -- No --> P0[set min frequency] P1 --> C2{"task has frequency?"} C2 -- Yes --> P3A[set CPU frequency] C2 -- No --> P3B[set max frequency] P3A --> P4[execute task] P3B --> P4 P4 --> C1 P0 --> C1Related links
How was this PR tested?
scripts/ci.shpasses on my machine.Notes for reviewers
test_dvfs.test_dvfschanges the CPU frequency directly instead of usingtask::spawn_with_freq(), sorun_main()overwrites its frequency.test_dvfsshould be removed in the future.test_dvfs_taskprints logs withlog::info!(). The logger task that prints them has no frequency, sorun_main()sets the CPU to the maximum frequency whenever it runs. Printing logs in another way in the future would fix this.