[Mesa-dev] [PATCH] gallium/util: don't let children of fork & exec inherit our thread affinity
Nicholas Miell
nmiell at gmail.com
Fri Sep 14 16:54:51 UTC 2018
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.
More information about the mesa-dev
mailing list