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

[dependencies.awkernel_async_lib]
path = "../../../awkernel_async_lib"
default-features = false

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.

Activate the dvfs feature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's already enabled in userland: the test_dvfs_task feature in userland/Cargo.toml enables awkernel/dvfs.

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.

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.

@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
romancardenas
romancardenas previously approved these changes Nov 19, 2026

@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

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.
task_info.take_preempt_context()
} {
#[cfg(feature = "dvfs")]
super::apply_task_freq(cpu_id, freq);

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.

Raspberry Pi does not support per-core DVFS, but this call can still synchronously query the firmware for frequency limits with interrupts disabled before the backend returns NotSupported. Could we check whether per-core DVFS is supported and return early before making any firmware queries?

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.

On a side note: I plan to implement it "per-core" DVFS for Raspberry Pi. The idea is that there will be an array of requested frequencies and, every time set_cpu_freq is executed, it will resolve the highest frequency and apply it globally.

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