This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3.2] New functions pthread_[sg]etattr_default_np for default thread attributes


On 06/13/2013 01:52 PM, Siddhesh Poyarekar wrote:
> 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.

You're right.

I misremembered pthread_getffinity_np vs. pthread_attr_getaffinity_np.
The former does a sched_getaffinity call to compute the mask size.
I thought that getting the affinity from the attr might also do a
kernel cpu mask size check (but it doesn't, thought it probably
should).

> 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.

Right.
 
> 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.

Yes, I see that too. 

You can only copy the minimum of the sizes?

- void *p = mempcpy (cpuset, iattr->cpuset, iattr->cpusetsize);
+ void *p = mempcpy (cpuset, iattr->cpuset, MIN(cpusetsize, iattr->cpusetsize));

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]