Update default AZStd thread priority on Apple platforms to avoid being prevented from using 100% of a core (#7295)

PAL-ified default thread priority for pthread platforms.
Fix threads not getting named on Apple platforms by setting the thread name ptr on the thread_info struct.

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>
monroegm-disable-blank-issue-2
rgba16f 4 years ago committed by GitHub
parent c514e1b490
commit 0a5e61b834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,5 +36,12 @@ namespace AZStd
{ {
pthread_setname_np(tId, name); pthread_setname_np(tId, name);
} }
uint8_t GetDefaultThreadPriority()
{
// pthread priority is an integer between >=1 and <=99 (although only range 1<=>32 is guaranteed)
// Don't use a scheduling policy value (e.g. SCHED_OTHER or SCHED_FIFO) here.
return 1;
}
} }
} }

@ -35,7 +35,7 @@ namespace AZStd
void SetThreadPriority(int priority, pthread_attr_t& attr) void SetThreadPriority(int priority, pthread_attr_t& attr)
{ {
if (priority == -1) if (priority <= -1)
{ {
pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
} }
@ -59,5 +59,18 @@ namespace AZStd
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)& policyData, 1); thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)& policyData, 1);
} }
} }
//////////////////////////////////////////////////////////////////////////////////
// Apple pthread -> NSThread quality of service level map
// QOS class name | min pthread priority | max pthread priority | comment
// QOS_CLASS_USER_INTERACTIVE | 38 | 47 | Per-frame work
// QOS_CLASS_USER_INITIATED | 32 | 37 | Asynchronous / Cross frame work
// QOS_CLASS_DEFAULT | 21 | 31 | Streaming / Multiple frames deadline
// QOS_CLASS_UTILITY | 5 | 20 | Background asset download
// QOS_CLASS_BACKGROUN | 0 | 4 | Will be prevented from using whole core.
uint8_t GetDefaultThreadPriority()
{
return 10;
}
} }
} }

@ -21,6 +21,7 @@ namespace AZStd
void PreCreateSetThreadAffinity(int cpuId, pthread_attr_t& attr); void PreCreateSetThreadAffinity(int cpuId, pthread_attr_t& attr);
void SetThreadPriority(int priority, pthread_attr_t& attr); void SetThreadPriority(int priority, pthread_attr_t& attr);
void PostCreateThread(pthread_t tId, const char * name, int cpuId); void PostCreateThread(pthread_t tId, const char * name, int cpuId);
uint8_t GetDefaultThreadPriority();
} }
namespace Internal namespace Internal
@ -60,12 +61,13 @@ namespace AZStd
} }
else else
{ {
priority = SCHED_OTHER; priority = Platform::GetDefaultThreadPriority();
} }
if (desc->m_name) if (desc->m_name)
{ {
name = desc->m_name; name = desc->m_name;
} }
ti->m_name = name;
cpuId = desc->m_cpuId; cpuId = desc->m_cpuId;
pthread_attr_setdetachstate(&attr, desc->m_isJoinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, desc->m_isJoinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED);

@ -55,5 +55,12 @@ namespace AZStd
{ {
pthread_setname_np(tId, name); pthread_setname_np(tId, name);
} }
uint8_t GetDefaultThreadPriority()
{
// pthread priority is an integer between >=1 and <=99 (although only range 1<=>32 is guaranteed)
// Don't use a scheduling policy value (e.g. SCHED_OTHER or SCHED_FIFO) here.
return 1;
}
} }
} }

Loading…
Cancel
Save