This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3.2] New functions pthread_[sg]etattr_default_np for default thread attributes
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: "Carlos O'Donell" <carlos at redhat dot com>
- Cc: Roland McGrath <roland at hack dot frob dot com>, libc-alpha at sourceware dot org
- Date: Thu, 13 Jun 2013 23:22:47 +0530
- Subject: Re: [PATCH v3.2] New functions pthread_[sg]etattr_default_np for default thread attributes
- References: <CAAHN_R13bRF0UY_XZ7Rj6tSeSgq8c_0j4bbEH6m9BbGD32EycQ at mail dot gmail dot com> <20130528220730 dot 33C262C06F at topped-with-meat dot com> <20130529065138 dot GF2145 at spoyarek dot pnq dot redhat dot com> <20130529224222 dot 8A87F2C07E at topped-with-meat dot com> <20130606131212 dot GZ13968 at spoyarek dot pnq dot redhat dot com> <20130612000601 dot 54C9F2C06E at topped-with-meat dot com> <20130612101128 dot GB19582 at spoyarek dot pnq dot redhat dot com> <20130612231757 dot CCC752C07F at topped-with-meat dot com> <20130613035538 dot GL19582 at spoyarek dot pnq dot redhat dot com> <51B9EDAE dot 7020702 at redhat dot com>
On Thu, Jun 13, 2013 at 12:05:02PM -0400, Carlos O'Donell wrote:
> On 06/12/2013 11:55 PM, Siddhesh Poyarekar wrote:
> > +verify_affinity_result (pthread_attr_t *attr)
> > +{
> > + cpu_set_t cpuset;
> > +
> > + RETURN_IF_FAIL (pthread_attr_getaffinity_np, attr, sizeof (cpuset), &cpuset);
>
> This will fail if booted on a system with more than 1024 possible CPUs.
>
> You need to use sysconf(_SC_PROCESSORS_ONLN); to get the size of the
> required set, allocate it, and then use that size in the call.
>
Apparently, it won't. pthread_attr_getaffinity_np (as opposed to
pthread_getaffinity_np) does not query the kernel. It only copies
over the cpuset from the pthread_attr_t and does not fail as long as
the mask in the attributes does not have a cpu set beyond the size of
the cpu_set_t we pass to the function. The actual sched_getaffinity
query is in pthread_getattr_np, where it starts from an estimate of a
million CPUs. There's probably a better way to do that, but it's
probably an exercise for later.
Since I control the cpu_set in the test, this test will not fail even
for cases where the system has a very large number of CPUs.
That said, I found a bug in pthread_attr_getaffinity_np, where passing
it a cpuset size smaller than that present in the attributes results
in a buffer overrun. I'll post a separate patch and test for it.
Siddhesh