Skip to content

feat(task): add per-task CPU frequency - #808

Open
Kanata9020 wants to merge 1 commit into
tier4:mainfrom
azu-lab:task-dvfs-freq
Open

Kanata9020 wants to merge 1 commit into
tier4:mainfrom
azu-lab:task-dvfs-freq

Conversation

@Kanata9020

Copy link
Copy Markdown
Contributor

Description

Add task::spawn_with_freq() to run a task at a given CPU frequency. The dvfs feature of awkernel_async_lib enables this, and the dvfs feature 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 --> C1
Loading

Related links

How was this PR tested?

  • scripts/ci.sh passes on my machine.

Notes for reviewers

  • This PR breaks test_dvfs. test_dvfs changes the CPU frequency directly instead of using task::spawn_with_freq(), so run_main() overwrites its frequency. test_dvfs should be removed in the future.
  • test_dvfs_task prints logs with log::info!(). The logger task that prints them has no frequency, so run_main() sets the CPU to the maximum frequency whenever it runs. Printing logs in another way in the future would fix this.

Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_lib/src/dvfs.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved

@romancardenas romancardenas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A minor comment

Comment thread awkernel_async_lib/src/task.rs Resolved
Comment thread awkernel_async_lib/src/task.rs Resolved
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.

@romancardenas romancardenas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

#[cfg(feature = "dvfs")]
match freq {
Some(f) => {
if let Err(e) = awkernel_lib::dvfs::set_cpu_freq_clamped(f) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// 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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants