Date: Thu, 24 Sep 2015 21:32:46 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Jason Schulz <schulz.j@gmail.com> Cc: freebsd-threads@freebsd.org Subject: Re: pthread_getaffinity_np issue Message-ID: <20150924183246.GK67105@kib.kiev.ua> In-Reply-To: <20150924181127.GC3104@gmail.com> References: <20150924181127.GC3104@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150924183246.GK67105>