From owner-freebsd-threads@freebsd.org Thu Sep 24 18:32:53 2015 Return-Path: Delivered-To: freebsd-threads@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B571EA085A8 for ; Thu, 24 Sep 2015 18:32:53 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 310591A06 for ; Thu, 24 Sep 2015 18:32:53 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t8OIWkA8041618 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 24 Sep 2015 21:32:47 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua t8OIWkA8041618 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t8OIWkjj041617; Thu, 24 Sep 2015 21:32:46 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 24 Sep 2015 21:32:46 +0300 From: Konstantin Belousov To: Jason Schulz Cc: freebsd-threads@freebsd.org Subject: Re: pthread_getaffinity_np issue Message-ID: <20150924183246.GK67105@kib.kiev.ua> References: <20150924181127.GC3104@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150924181127.GC3104@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Sep 2015 18:32:53 -0000 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 before including sys/cpuset.h.