-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
feat(sched): add sched_yield #766
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use system_error::SystemError; | ||
|
||
use crate::arch::cpu::current_cpu_id; | ||
use crate::exception::InterruptArch; | ||
use crate::process::ProcessManager; | ||
use crate::sched::CurrentIrqArch; | ||
use crate::sched::Scheduler; | ||
use crate::syscall::Syscall; | ||
|
||
use super::fair::CompletelyFairScheduler; | ||
use super::{cpu_rq, schedule, SchedMode}; | ||
|
||
impl Syscall { | ||
pub fn do_sched_yield() -> Result<usize, SystemError> { | ||
// 禁用中断 | ||
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() }; | ||
|
||
let pcb = ProcessManager::current_pcb(); | ||
let rq = cpu_rq(pcb.sched_info().on_cpu().unwrap_or(current_cpu_id()).data() as usize); | ||
let (rq, guard) = rq.self_lock(); | ||
|
||
// TODO: schedstat_inc(rq->yld_count); | ||
|
||
CompletelyFairScheduler::yield_task(rq); | ||
|
||
pcb.preempt_disable(); | ||
|
||
drop(guard); | ||
drop(irq_guard); | ||
|
||
pcb.preempt_enable(); // sched_preempt_enable_no_resched(); | ||
|
||
schedule(SchedMode::SM_NONE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以的~ |
||
|
||
Ok(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的
preempt_disable
和preempt_enable
似乎没有什么必要?,这里已经禁用中断,是不会被时钟中断调度走的,所以我感觉可以不需要这个两个调用。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里完全参考linux实现,应该是保证在一些特殊情况下也不会被抢占,保证drop(guard)和drop(irq_guard)成功执行。可以暂时先保持原状。