Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
fbd7afef
There was an error fetching the commit references. Please try again later.
Commit
fbd7afef
authored
6 years ago
by
bunnei
Browse files
Options
Downloads
Patches
Plain Diff
thread: Support core change on ResumeFromWait and improve ChangeCore.
parent
91af2f94
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/hle/kernel/thread.cpp
+68
-37
68 additions, 37 deletions
src/core/hle/kernel/thread.cpp
with
68 additions
and
37 deletions
src/core/hle/kernel/thread.cpp
+
68
−
37
View file @
fbd7afef
...
@@ -154,6 +154,18 @@ void Thread::CancelWakeupTimer() {
...
@@ -154,6 +154,18 @@ void Thread::CancelWakeupTimer() {
CoreTiming
::
UnscheduleEvent
(
ThreadWakeupEventType
,
callback_handle
);
CoreTiming
::
UnscheduleEvent
(
ThreadWakeupEventType
,
callback_handle
);
}
}
static
boost
::
optional
<
s32
>
GetNextProcessorId
(
u64
mask
)
{
for
(
s32
index
=
0
;
index
<
Core
::
NUM_CPU_CORES
;
++
index
)
{
if
(
mask
&
(
1ULL
<<
index
))
{
if
(
!
Core
::
System
().
GetInstance
().
Scheduler
(
index
)
->
GetCurrentThread
())
{
// Core is enabled and not running any threads, use this one
return
index
;
}
}
}
return
{};
}
void
Thread
::
ResumeFromWait
()
{
void
Thread
::
ResumeFromWait
()
{
ASSERT_MSG
(
wait_objects
.
empty
(),
"Thread is waking up while waiting for objects"
);
ASSERT_MSG
(
wait_objects
.
empty
(),
"Thread is waking up while waiting for objects"
);
...
@@ -188,7 +200,36 @@ void Thread::ResumeFromWait() {
...
@@ -188,7 +200,36 @@ void Thread::ResumeFromWait() {
wakeup_callback
=
nullptr
;
wakeup_callback
=
nullptr
;
status
=
THREADSTATUS_READY
;
status
=
THREADSTATUS_READY
;
scheduler
->
ScheduleThread
(
this
,
current_priority
);
boost
::
optional
<
s32
>
new_processor_id
=
GetNextProcessorId
(
mask
);
if
(
!
new_processor_id
)
{
new_processor_id
=
processor_id
;
}
if
(
ideal_core
!=
-
1
&&
Core
::
System
().
GetInstance
().
Scheduler
(
ideal_core
)
->
GetCurrentThread
()
==
nullptr
)
{
new_processor_id
=
ideal_core
;
}
ASSERT
(
*
new_processor_id
<
4
);
// Add thread to new core's scheduler
auto
&
next_scheduler
=
Core
::
System
().
GetInstance
().
Scheduler
(
*
new_processor_id
);
if
(
*
new_processor_id
!=
processor_id
)
{
// Remove thread from previous core's scheduler
scheduler
->
RemoveThread
(
this
);
next_scheduler
->
AddThread
(
this
,
current_priority
);
}
processor_id
=
*
new_processor_id
;
// If the thread was ready, unschedule from the previous core and schedule on the new core
scheduler
->
UnscheduleThread
(
this
,
current_priority
);
next_scheduler
->
ScheduleThread
(
this
,
current_priority
);
// Change thread's scheduler
scheduler
=
next_scheduler
;
Core
::
System
::
GetInstance
().
CpuCore
(
processor_id
).
PrepareReschedule
();
Core
::
System
::
GetInstance
().
CpuCore
(
processor_id
).
PrepareReschedule
();
}
}
...
@@ -267,7 +308,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
...
@@ -267,7 +308,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
thread
->
last_running_ticks
=
CoreTiming
::
GetTicks
();
thread
->
last_running_ticks
=
CoreTiming
::
GetTicks
();
thread
->
processor_id
=
processor_id
;
thread
->
processor_id
=
processor_id
;
thread
->
ideal_core
=
processor_id
;
thread
->
ideal_core
=
processor_id
;
thread
->
mask
=
1
<<
processor_id
;
thread
->
mask
=
1
ULL
<<
processor_id
;
thread
->
wait_objects
.
clear
();
thread
->
wait_objects
.
clear
();
thread
->
mutex_wait_address
=
0
;
thread
->
mutex_wait_address
=
0
;
thread
->
condvar_wait_address
=
0
;
thread
->
condvar_wait_address
=
0
;
...
@@ -417,55 +458,45 @@ void Thread::UpdatePriority() {
...
@@ -417,55 +458,45 @@ void Thread::UpdatePriority() {
lock_owner
->
UpdatePriority
();
lock_owner
->
UpdatePriority
();
}
}
static
s32
GetNextProcessorId
(
u64
mask
)
{
s32
processor_id
{};
for
(
s32
index
=
0
;
index
<
Core
::
NUM_CPU_CORES
;
++
index
)
{
if
(
mask
&
(
1ULL
<<
index
))
{
if
(
!
Core
::
System
().
GetInstance
().
Scheduler
(
index
)
->
GetCurrentThread
())
{
// Core is enabled and not running any threads, use this one
return
index
;
}
// Core is enabled, but running a thread, less ideal
processor_id
=
index
;
}
}
return
processor_id
;
}
void
Thread
::
ChangeCore
(
u32
core
,
u64
mask
)
{
void
Thread
::
ChangeCore
(
u32
core
,
u64
mask
)
{
const
s32
new_processor_id
{
GetNextProcessorId
(
mask
)};
ideal_core
=
core
;
mask
=
mask
;
ASSERT
(
ideal_core
==
core
);
// We're not doing anything with this yet, so assert the expected
ASSERT
(
new_processor_id
<
Core
::
NUM_CPU_CORES
);
if
(
new_processor_id
==
processor_id
)
{
if
(
status
!=
THREADSTATUS_READY
)
{
// Already running on ideal core, nothing to do here
return
;
return
;
}
}
ASSERT
(
status
!=
THREADSTATUS_RUNNING
);
// Unsupported
boost
::
optional
<
s32
>
new_processor_id
{
GetNextProcessorId
(
mask
)};
processor_id
=
new_processor_id
;
if
(
!
new_processor_id
)
{
ideal_core
=
core
;
new_processor_id
=
processor_id
;
mask
=
mask
;
}
if
(
ideal_core
!=
-
1
&&
Core
::
System
().
GetInstance
().
Scheduler
(
ideal_core
)
->
GetCurrentThread
()
==
nullptr
)
{
new_processor_id
=
ideal_core
;
}
ASSERT
(
new_processor_id
<
4
);
// Add thread to new core's scheduler
// Add thread to new core's scheduler
auto
&
next_scheduler
=
Core
::
System
().
GetInstance
().
Scheduler
(
new_processor_id
);
auto
&
next_scheduler
=
Core
::
System
().
GetInstance
().
Scheduler
(
*
new_processor_id
);
next_scheduler
->
AddThread
(
this
,
current_priority
);
if
(
status
==
THREADSTATUS_READY
)
{
if
(
*
new_processor_id
!=
processor_id
)
{
//
If th
e thread
was ready, unschedule from the
previous core
and
schedule
on the new core
//
Remov
e thread
from
previous core
's
schedule
r
scheduler
->
Unschedul
eThread
(
this
,
current_priority
);
scheduler
->
Remov
eThread
(
this
);
next_scheduler
->
Schedule
Thread
(
this
,
current_priority
);
next_scheduler
->
Add
Thread
(
this
,
current_priority
);
}
}
// Remove thread from previous core's scheduler
processor_id
=
*
new_processor_id
;
scheduler
->
RemoveThread
(
this
);
// If the thread was ready, unschedule from the previous core and schedule on the new core
scheduler
->
UnscheduleThread
(
this
,
current_priority
);
next_scheduler
->
ScheduleThread
(
this
,
current_priority
);
// Change thread's scheduler
// Change thread's scheduler
scheduler
=
next_scheduler
;
scheduler
=
next_scheduler
;
Core
::
System
::
GetInstance
().
CpuCore
(
processor_id
).
PrepareReschedule
();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment