pthread_getaffinity_np issue
Jason Schulz
schulz.j at gmail.com
Thu Sep 24 19:11:31 UTC 2015
Hey Konstantin,
Thanks for the quick response. The version I'm developing with is the latest release.
[jason at fb ~/development/git/uxcn/yafd]$ uname -a
FreeBSD fb 10.2-RELEASE FreeBSD 10.2-RELEASE #0 r286666: Wed Aug 12 15:26:37 UTC 2015 root at releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
I was able to narrow it down to the following,
#include <stdio.h>
#include <pthread.h>
#include <pthread_np.h>
int main(int argc, char* argv[argc]) {
long cs = 0;
pthread_t this = pthread_self();
cpuset_t cpus;
CPU_ZERO(&cpus);
int err = pthread_getaffinity_np(this, sizeof(cpus), &cpus);
if (err)
return err;
cs = (long) CPU_COUNT(&cpus);
printf("num cpus... %li\n", cs);
return 0;
}
Compiling with '-D_XOPEN_SOURCE=700',
[jason at fb /tmp]$ clang -D_XOPEN_SOURCE=700 -pthread -o num_cpus num_cpus.c
num_cpus.c:21:15: warning: implicit declaration of function '__bitcountl' is invalid in C99 [-Wimplicit-function-declaration]
cs = (long) CPU_COUNT(&cpus);
^
/usr/include/sys/cpuset.h:63:24: note: expanded from macro 'CPU_COUNT'
#define CPU_COUNT(p) BIT_COUNT(CPU_SETSIZE, p)
^
/usr/include/sys/bitset.h:185:14: note: expanded from macro 'BIT_COUNT'
__count += __bitcountl((p)->__bits[__i]); \
^
1 warning generated.
/tmp/num_cpus-560a33.o: In function `main':
num_cpus.c:(.text+0xbd): undefined reference to `__bitcountl'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
However compiling without '-D_XOPEN_SOURCE=700' works,
[jason at fb /tmp]$ clang -pthread -o num_cpus num_cpus.c
[jason at fb /tmp]$
Should I file a bug report?
-J
On Thu, Sep 24, 2015 at 09:32:46PM +0300, Konstantin Belousov wrote:
> On Thu, Sep 24, 2015 at 11:11:27AM -0700, Jason Schulz wrote:
> > I'm having an issue using the non-posix thread affinity methods. Specifically, I'm having trouble using CPU_COUNT. I'm trying to use the following code to get the current number of processors in a processes affinity...
> >
> >
> >
> > long cs = 0;
> >
> > #if defined(HAVE_LINUX) || defined(HAVE_FREEBSD)
> >
> > pthread_t this = pthread_self();
> >
> > cpu_set_t cpus;
> >
> > CPU_ZERO(&cpus);
> >
> > int err = pthread_getaffinity_np(this, sizeof(cpus), &cpus);
> >
> > if (err)
> > return err;
> >
> > cs = (long) CPU_COUNT(&cpus);
> >
> >
> >
> > However, I get the compiler error...
> >
> >
> >
> > clang -DHAVE_CONFIG_H -I. -g -O2 -D_THREAD_SAFE -pthread -pipe -std=c99 -D_XOPEN_SOURCE=700 -pedantic -Wall -Wextra -Wsign-conversion -Wconversion -Werror -MT thread.o -MD -MP -MF .deps/thread.Tpo -c -o thread.o thread.c
> > thread.c:85:15: error: implicit declaration of function '__bitcountl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
> > cs = (long) CPU_COUNT(&cpus);
> > ^
> > /usr/include/sys/cpuset.h:63:24: note: expanded from macro 'CPU_COUNT'
> > #define CPU_COUNT(p) BIT_COUNT(CPU_SETSIZE, p)
> > ^
> > /usr/include/sys/bitset.h:185:14: note: expanded from macro 'BIT_COUNT'
> > __count += __bitcountl((p)->__bits[__i]); \
> > ^
> > 1 error generated.
> >
> >
> >
> > I'm able to use CPU_ISSET to the same effect, but obviously I'd rather use CPU_COUNT. Suggestions?
> >
>
> Show the minimal example demonstrating the issue, specify the version
> of the system and which you use. My guess is that you did not added
> #include <sys/types.h> before including sys/cpuset.h.
More information about the freebsd-threads
mailing list