re PR libgomp/43706 (scheduling two threads on one core leads to starvation)
PR libgomp/43706 * config/linux/affinity.c (gomp_init_affinity): Decrease gomp_available_cpus if affinity mask confines the process to fewer CPUs. * config/linux/proc.c (get_num_procs): If gomp_cpu_affinity is non-NULL, just return gomp_available_cpus. From-SVN: r158565
This commit is contained in:
parent
5221d7a91b
commit
e4ba7a600e
|
@ -1,5 +1,12 @@
|
||||||
2010-04-20 Jakub Jelinek <jakub@redhat.com>
|
2010-04-20 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
PR libgomp/43706
|
||||||
|
* config/linux/affinity.c (gomp_init_affinity): Decrease
|
||||||
|
gomp_available_cpus if affinity mask confines the process to fewer
|
||||||
|
CPUs.
|
||||||
|
* config/linux/proc.c (get_num_procs): If gomp_cpu_affinity is
|
||||||
|
non-NULL, just return gomp_available_cpus.
|
||||||
|
|
||||||
PR libgomp/43569
|
PR libgomp/43569
|
||||||
* sections.c (gomp_sections_init): Initialize ws->mode.
|
* sections.c (gomp_sections_init): Initialize ws->mode.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
/* Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||||
Contributed by Jakub Jelinek <jakub@redhat.com>.
|
Contributed by Jakub Jelinek <jakub@redhat.com>.
|
||||||
|
|
||||||
This file is part of the GNU OpenMP Library (libgomp).
|
This file is part of the GNU OpenMP Library (libgomp).
|
||||||
|
@ -39,8 +39,9 @@ static unsigned int affinity_counter;
|
||||||
void
|
void
|
||||||
gomp_init_affinity (void)
|
gomp_init_affinity (void)
|
||||||
{
|
{
|
||||||
cpu_set_t cpuset;
|
cpu_set_t cpuset, cpusetnew;
|
||||||
size_t idx, widx;
|
size_t idx, widx;
|
||||||
|
unsigned long cpus = 0;
|
||||||
|
|
||||||
if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset), &cpuset))
|
if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset), &cpuset))
|
||||||
{
|
{
|
||||||
|
@ -51,10 +52,18 @@ gomp_init_affinity (void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPU_ZERO (&cpusetnew);
|
||||||
for (widx = idx = 0; idx < gomp_cpu_affinity_len; idx++)
|
for (widx = idx = 0; idx < gomp_cpu_affinity_len; idx++)
|
||||||
if (gomp_cpu_affinity[idx] < CPU_SETSIZE
|
if (gomp_cpu_affinity[idx] < CPU_SETSIZE
|
||||||
&& CPU_ISSET (gomp_cpu_affinity[idx], &cpuset))
|
&& CPU_ISSET (gomp_cpu_affinity[idx], &cpuset))
|
||||||
gomp_cpu_affinity[widx++] = gomp_cpu_affinity[idx];
|
{
|
||||||
|
if (! CPU_ISSET (gomp_cpu_affinity[idx], &cpusetnew))
|
||||||
|
{
|
||||||
|
cpus++;
|
||||||
|
CPU_SET (gomp_cpu_affinity[idx], &cpusetnew);
|
||||||
|
}
|
||||||
|
gomp_cpu_affinity[widx++] = gomp_cpu_affinity[idx];
|
||||||
|
}
|
||||||
|
|
||||||
if (widx == 0)
|
if (widx == 0)
|
||||||
{
|
{
|
||||||
|
@ -66,6 +75,8 @@ gomp_init_affinity (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
gomp_cpu_affinity_len = widx;
|
gomp_cpu_affinity_len = widx;
|
||||||
|
if (cpus < gomp_available_cpus)
|
||||||
|
gomp_available_cpus = cpus;
|
||||||
CPU_ZERO (&cpuset);
|
CPU_ZERO (&cpuset);
|
||||||
CPU_SET (gomp_cpu_affinity[0], &cpuset);
|
CPU_SET (gomp_cpu_affinity[0], &cpuset);
|
||||||
pthread_setaffinity_np (pthread_self (), sizeof (cpuset), &cpuset);
|
pthread_setaffinity_np (pthread_self (), sizeof (cpuset), &cpuset);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
/* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
|
||||||
|
Free Software Foundation, Inc.
|
||||||
Contributed by Jakub Jelinek <jakub@redhat.com>.
|
Contributed by Jakub Jelinek <jakub@redhat.com>.
|
||||||
|
|
||||||
This file is part of the GNU OpenMP Library (libgomp).
|
This file is part of the GNU OpenMP Library (libgomp).
|
||||||
|
@ -104,26 +105,13 @@ get_num_procs (void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
size_t idx;
|
|
||||||
static int affinity_cpus;
|
|
||||||
|
|
||||||
/* We can't use pthread_getaffinity_np in this case
|
/* We can't use pthread_getaffinity_np in this case
|
||||||
(we have changed it ourselves, it binds to just one CPU).
|
(we have changed it ourselves, it binds to just one CPU).
|
||||||
Count instead the number of different CPUs we are
|
Count instead the number of different CPUs we are
|
||||||
using. */
|
using. gomp_init_affinity updated gomp_available_cpus to
|
||||||
CPU_ZERO (&cpuset);
|
the number of CPUs in the GOMP_AFFINITY mask that we are
|
||||||
if (affinity_cpus == 0)
|
allowed to use though. */
|
||||||
{
|
return gomp_available_cpus;
|
||||||
int cpus = 0;
|
|
||||||
for (idx = 0; idx < gomp_cpu_affinity_len; idx++)
|
|
||||||
if (! CPU_ISSET (gomp_cpu_affinity[idx], &cpuset))
|
|
||||||
{
|
|
||||||
cpus++;
|
|
||||||
CPU_SET (gomp_cpu_affinity[idx], &cpuset);
|
|
||||||
}
|
|
||||||
affinity_cpus = cpus;
|
|
||||||
}
|
|
||||||
return affinity_cpus;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef _SC_NPROCESSORS_ONLN
|
#ifdef _SC_NPROCESSORS_ONLN
|
||||||
|
|
Loading…
Reference in New Issue