[Mesa-dev] [PATCH] gallium/util: don't let children of fork & exec inherit our thread affinity
Marek Olšák
maraeo at gmail.com
Sat Sep 15 01:00:33 UTC 2018
On Fri, Sep 14, 2018 at 12:54 PM, Nicholas Miell <nmiell at gmail.com> wrote:
> On 09/12/2018 05:40 PM, Marek Olšák wrote:
>> +static void
>> +util_set_full_cpu_affinity(void)
>> +{
>> + cpu_set_t cpuset;
>> +
>> + CPU_ZERO(&cpuset);
>> + for (unsigned i = 0; i < CPU_SETSIZE; i++)
>> + CPU_SET(i, &cpuset);
>> +
>> + pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
>> +}
>>
>> static void
>> -util_init_cache_number(void)
>> +util_init_thread_pinning(void)
>> {
>> /* Get a semi-random number. */
>> int64_t t = os_time_get_nano();
>> L3_cache_number = (t ^ (t >> 8) ^ (t >> 16));
>> +
>> + /* Reset thread affinity for all children of fork and exec to prevent
>> + * spawned processes and threads from inheriting the current thread's
>> + * affinity.
>> + *
>> + * What happens if a driver is unloaded and the app creates a thread?
>> + */
>> + pthread_atfork(NULL, NULL, util_set_full_cpu_affinity);
>> }
>>
>
> You should probably save and restore the application's affinity mask
> rather than assuming the mask is set to all CPUs.
The affinity mask references a random CCX for each OpenGL context, and
we don't know which thread called fork in the child.
Marek
More information about the mesa-dev
mailing list