Skip to content
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

[kernel][schedule] reduce unnecessary schedule by comparing new ready thread's priority and current #5959

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
modify rt_thread_resume for necessary schedule judgment
  • Loading branch information
blta committed May 17, 2022
commit 2f798e1086f8fb41916ca8ac118720395f93c2c3
21 changes: 17 additions & 4 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,13 +875,16 @@ RTM_EXPORT(rt_thread_suspend);
*
* @param thread is the thread to be resumed.
*
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
* If the return value is any other values, it means this operation failed.
* @return Return the operation status.
* When the return value is RT_EOK, the new ready thread have highest priority, need to schedule immediately
* When the return value is RT_EBUSY, although have readied the thread but its priority is not the highest.
* If the return value is any other values, it means this operation failed.
*/
rt_err_t rt_thread_resume(rt_thread_t thread)
{
rt_base_t level;

rt_err_t result = RT_EOK;
extern rt_uint8_t rt_current_priority;
/* parameter check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
Expand All @@ -907,11 +910,21 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
/* insert to schedule ready list */
rt_schedule_insert_thread(thread);

/* compare the priority with rt_current_priority*/
if(thread->current_priority < rt_current_priority)
{
result == RT_EOK;
}
else
{
result == RT_EBUSY;
}

/* enable interrupt */
rt_hw_interrupt_enable(level);

RT_OBJECT_HOOK_CALL(rt_thread_resume_hook, (thread));
return RT_EOK;
return result;
}
RTM_EXPORT(rt_thread_resume);

Expand Down