[lkml]   [2004]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] cpumask 5/10 rewrite cpumask.h - single bitmap based implementation
William Lee Irwin III wrote:
> Some interface is needed to export NR_CPUS

Well ... technically ... such an interface already exists.
However the word "interface" might be too kind a description.

* Ugly hack to get size of cpumask - keep calling sched_getaffinity
* with masks of increasing size until it stops complaining -EINVAL
* that the mask is too small. Determines size of kernel cpumask,
* in number of bytes. Size will always be some multiple of the
* size of an unsigned long. Since it's ok to be too big, and since
* kernel NR_CPUS is usually a power of two, just try each power
* of two, until one works. Contrary to the man page, a successful
* sched_getaffinity() returns a positive number (the sizeof(cpumask_t),
* to be exact), not zero. Consider any return >= 0 to mean success.

#include <errno.h>
extern int errno;

int cpumasksz()
int nbytes;
unsigned long *mask = 0;

for (nbytes = sizeof(unsigned long); nbytes < 10000; nbytes *= 2) {
int r;
mask = (unsigned long *)realloc(mask, nbytes);
if (mask == 0)
return -ENOMEM;
errno = 0;
r = sched_getaffinity(0, nbytes, mask);
if (r < 0 && errno == EINVAL)
if (r >= 0)
return -errno;
return nbytes;

I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <> 1.650.933.1373
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 14:03    [W:0.288 / U:5.756 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site