Patchwork [gomp] : Unbreak bootstrap on glibc-2.5

login
register
mail settings
Submitter Uros Bizjak
Date Aug. 3, 2011, 8:36 a.m.
Message ID <CAFULd4YwgorfY52U4pjEQBqMjqONXcQBRzF6NMPOeQS+yGGHSg@mail.gmail.com>
Download mbox | patch
Permalink /patch/108051/
State New
Headers show

Comments

Uros Bizjak - Aug. 3, 2011, 8:36 a.m.
Hello!

We should not call CPU_COUNT when not defined in glibc.

2011-08-03  Uros Bizjak  <ubizjak@gmail.com>

	* config/linux/proc.c (gomp_cpuset_popcount): Rename from
	cpuset_popcount.  No more static.
	(gomp_init_num_threads): Update call to cpuset_popcount.
	(get_num_procs): Ditto.
	* config/linux/affinity.c: Call gomp_cpuset_popcount.
	* libgomp.h (gomp_cpuset_popcount): Declare.

Bootstrapped on x86_64-pc-linux-gnu, testing in progress.

OK if it passes?

Uros.
Jakub Jelinek - Aug. 3, 2011, 9:11 a.m.
On Wed, Aug 03, 2011 at 10:36:47AM +0200, Uros Bizjak wrote:
> We should not call CPU_COUNT when not defined in glibc.

Oops, forgot that old glibcs don't have it.

> 2011-08-03  Uros Bizjak  <ubizjak@gmail.com>
> 
> 	* config/linux/proc.c (gomp_cpuset_popcount): Rename from
> 	cpuset_popcount.  No more static.
> 	(gomp_init_num_threads): Update call to cpuset_popcount.
> 	(get_num_procs): Ditto.
> 	* config/linux/affinity.c: Call gomp_cpuset_popcount.
> 	* libgomp.h (gomp_cpuset_popcount): Declare.
> 
> Bootstrapped on x86_64-pc-linux-gnu, testing in progress.
> 
> OK if it passes?

I don't like the prototype in libgomp.h, for one sched.h isn't included
in libgomp.h thus cpu_set_t is not defined type.  Plus it isn't a generic
API, but a Linux private function.
So, IMHO either just don't provide any prototype in a header
and put
extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
into config/linux/affinity.c, or introduce
config/linux/proc.h header containing
#include <sched.h>
#ifdef HAVE_PTHREAD_AFFINITY_NP
extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
#endif
and
#include "config/linux/proc.h"
in config/linux/{proc.c,affinity.c}.
Ok with those changes, thanks.

	Jakub

Patch

Index: libgomp.h
===================================================================
--- libgomp.h	(revision 177229)
+++ libgomp.h	(working copy)
@@ -463,6 +463,10 @@  extern unsigned gomp_resolve_num_threads
 
 /* proc.c (in config/) */
 
+#ifdef HAVE_PTHREAD_AFFINITY_NP
+extern unsigned long gomp_cpuset_popcount (cpu_set_t *);
+#endif
+
 extern void gomp_init_num_threads (void);
 extern unsigned gomp_dynamic_max_threads (void);
 
Index: config/linux/proc.c
===================================================================
--- config/linux/proc.c	(revision 177229)
+++ config/linux/proc.c	(working copy)
@@ -40,8 +40,8 @@ 
 #endif
 
 #ifdef HAVE_PTHREAD_AFFINITY_NP
-static unsigned long
-cpuset_popcount (cpu_set_t *cpusetp)
+unsigned long
+gomp_cpuset_popcount (cpu_set_t *cpusetp)
 {
 #ifdef CPU_COUNT
   /* glibc 2.6 and above provide a macro for this.  */
@@ -76,7 +76,7 @@  gomp_init_num_threads (void)
   if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset), &cpuset) == 0)
     {
       /* Count only the CPUs this process can use.  */
-      gomp_global_icv.nthreads_var = cpuset_popcount (&cpuset);
+      gomp_global_icv.nthreads_var = gomp_cpuset_popcount (&cpuset);
       if (gomp_global_icv.nthreads_var == 0)
 	gomp_global_icv.nthreads_var = 1;
       return;
@@ -99,7 +99,7 @@  get_num_procs (void)
       if (pthread_getaffinity_np (pthread_self (), sizeof (cpuset),
 				  &cpuset) == 0)
 	{
-	  int ret = cpuset_popcount (&cpuset);
+	  int ret = gomp_cpuset_popcount (&cpuset);
 	  return ret != 0 ? ret : 1;
 	}
     }
Index: config/linux/affinity.c
===================================================================
--- config/linux/affinity.c	(revision 177229)
+++ config/linux/affinity.c	(working copy)
@@ -56,7 +56,7 @@  gomp_init_affinity (void)
   CPU_ZERO (&cpusetnew);
   if (gomp_cpu_affinity_len == 0)
     {
-      unsigned long count = CPU_COUNT (&cpuset);
+      unsigned long count = gomp_cpuset_popcount (&cpuset);
       if (count >= 65536)
 	count = 65536;
       gomp_cpu_affinity = malloc (count * sizeof (unsigned short));