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
2a35a362
There was an error fetching the commit references. Please try again later.
Commit
2a35a362
authored
6 years ago
by
Subv
Browse files
Options
Downloads
Patches
Plain Diff
Kernel/SVC: Signal the highest priority threads first in svcSignalProcessWideKey.
parent
c74f2555
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/svc.cpp
+68
-51
68 additions, 51 deletions
src/core/hle/kernel/svc.cpp
with
68 additions
and
51 deletions
src/core/hle/kernel/svc.cpp
+
68
−
51
View file @
2a35a362
...
@@ -608,61 +608,78 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
...
@@ -608,61 +608,78 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
NGLOG_TRACE
(
Kernel_SVC
,
"called, condition_variable_addr=0x{:X}, target=0x{:08X}"
,
NGLOG_TRACE
(
Kernel_SVC
,
"called, condition_variable_addr=0x{:X}, target=0x{:08X}"
,
condition_variable_addr
,
target
);
condition_variable_addr
,
target
);
u32
processed
=
0
;
auto
RetrieveWaitingThreads
=
[](
size_t
core_index
,
std
::
vector
<
SharedPtr
<
Thread
>>&
waiting_threads
,
VAddr
condvar_addr
)
{
const
auto
&
scheduler
=
Core
::
System
::
GetInstance
().
Scheduler
(
core_index
);
auto
&
thread_list
=
scheduler
->
GetThreadList
();
for
(
auto
&
thread
:
thread_list
)
{
if
(
thread
->
condvar_wait_address
==
condvar_addr
)
waiting_threads
.
push_back
(
thread
);
}
};
// Retrieve a list of all threads that are waiting for this condition variable.
std
::
vector
<
SharedPtr
<
Thread
>>
waiting_threads
;
RetrieveWaitingThreads
(
0
,
waiting_threads
,
condition_variable_addr
);
RetrieveWaitingThreads
(
1
,
waiting_threads
,
condition_variable_addr
);
RetrieveWaitingThreads
(
2
,
waiting_threads
,
condition_variable_addr
);
RetrieveWaitingThreads
(
3
,
waiting_threads
,
condition_variable_addr
);
// Sort them by priority, such that the highest priority ones come first.
std
::
sort
(
waiting_threads
.
begin
(),
waiting_threads
.
end
(),
[](
const
SharedPtr
<
Thread
>&
lhs
,
const
SharedPtr
<
Thread
>&
rhs
)
{
return
lhs
->
current_priority
<
rhs
->
current_priority
;
});
// Only process up to 'target' threads, unless 'target' is -1, in which case process
// them all.
size_t
last
=
waiting_threads
.
size
();
if
(
target
!=
-
1
)
last
=
target
;
// If there are no threads waiting on this condition variable, just exit
if
(
last
>
waiting_threads
.
size
())
return
RESULT_SUCCESS
;
auto
signal_process_wide_key
=
[
&
](
size_t
core_index
)
{
for
(
size_t
index
=
0
;
index
<
last
;
++
index
)
{
const
auto
&
scheduler
=
Core
::
System
::
GetInstance
().
Scheduler
(
core_index
);
auto
&
thread
=
waiting_threads
[
index
];
for
(
auto
&
thread
:
scheduler
->
GetThreadList
())
{
if
(
thread
->
condvar_wait_address
!=
condition_variable_addr
)
continue
;
// Only process up to 'target' threads, unless 'target' is -1, in which case process
ASSERT
(
thread
->
condvar_wait_address
==
condition_variable_addr
);
// them all.
if
(
target
!=
-
1
&&
processed
>=
target
)
break
;
// If the mutex is not yet acquired, acquire it.
u32
mutex_val
=
Memory
::
Read32
(
thread
->
mutex_wait_address
);
if
(
mutex_val
==
0
)
{
// We were able to acquire the mutex, resume this thread.
Memory
::
Write32
(
thread
->
mutex_wait_address
,
thread
->
wait_handle
);
ASSERT
(
thread
->
status
==
THREADSTATUS_WAIT_MUTEX
);
thread
->
ResumeFromWait
();
auto
lock_owner
=
thread
->
lock_owner
;
if
(
lock_owner
)
lock_owner
->
RemoveMutexWaiter
(
thread
);
thread
->
lock_owner
=
nullptr
;
thread
->
mutex_wait_address
=
0
;
thread
->
condvar_wait_address
=
0
;
thread
->
wait_handle
=
0
;
}
else
{
// Couldn't acquire the mutex, block the thread.
Handle
owner_handle
=
static_cast
<
Handle
>
(
mutex_val
&
Mutex
::
MutexOwnerMask
);
auto
owner
=
g_handle_table
.
Get
<
Thread
>
(
owner_handle
);
ASSERT
(
owner
);
ASSERT
(
thread
->
status
!=
THREADSTATUS_RUNNING
);
thread
->
status
=
THREADSTATUS_WAIT_MUTEX
;
thread
->
wakeup_callback
=
nullptr
;
// Signal that the mutex now has a waiting thread.
Memory
::
Write32
(
thread
->
mutex_wait_address
,
mutex_val
|
Mutex
::
MutexHasWaitersFlag
);
owner
->
AddMutexWaiter
(
thread
);
Core
::
System
::
GetInstance
().
CpuCore
(
thread
->
processor_id
).
PrepareReschedule
();
}
++
processed
;
// If the mutex is not yet acquired, acquire it.
}
u32
mutex_val
=
Memory
::
Read32
(
thread
->
mutex_wait_address
);
};
if
(
mutex_val
==
0
)
{
// We were able to acquire the mutex, resume this thread.
Memory
::
Write32
(
thread
->
mutex_wait_address
,
thread
->
wait_handle
);
ASSERT
(
thread
->
status
==
THREADSTATUS_WAIT_MUTEX
);
thread
->
ResumeFromWait
();
signal_process_wide_key
(
0
);
auto
lock_owner
=
thread
->
lock_owner
;
signal_process_wide_key
(
1
);
if
(
lock_owner
)
signal_process_wide_key
(
2
);
lock_owner
->
RemoveMutexWaiter
(
thread
);
signal_process_wide_key
(
3
);
thread
->
lock_owner
=
nullptr
;
thread
->
mutex_wait_address
=
0
;
thread
->
condvar_wait_address
=
0
;
thread
->
wait_handle
=
0
;
}
else
{
// Couldn't acquire the mutex, block the thread.
Handle
owner_handle
=
static_cast
<
Handle
>
(
mutex_val
&
Mutex
::
MutexOwnerMask
);
auto
owner
=
g_handle_table
.
Get
<
Thread
>
(
owner_handle
);
ASSERT
(
owner
);
ASSERT
(
thread
->
status
!=
THREADSTATUS_RUNNING
);
thread
->
status
=
THREADSTATUS_WAIT_MUTEX
;
thread
->
wakeup_callback
=
nullptr
;
// Signal that the mutex now has a waiting thread.
Memory
::
Write32
(
thread
->
mutex_wait_address
,
mutex_val
|
Mutex
::
MutexHasWaitersFlag
);
owner
->
AddMutexWaiter
(
thread
);
Core
::
System
::
GetInstance
().
CpuCore
(
thread
->
processor_id
).
PrepareReschedule
();
}
}
return
RESULT_SUCCESS
;
return
RESULT_SUCCESS
;
}
}
...
...
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