Open MPI logo

PLPA Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all PLPA Users mailing list

From: Bert Wesarg (wesarg_at_[hidden])
Date: 2006-02-12 11:17:26


Hello list,

i'm a little confused by the 'cpusetsize' argument to sched_setaffinity().
i found the following in your code

from plpa-1.0.2/src/libplpa/plpa_dispatch.c:
> 32: case PLPA_PROBE_OK:
> 33: /* This shouldn't happen, but check anyway */
> 34: if (cpusetsize > PLPA_BITMASK_NUM_ELEMENTS) {
here 'cpusetsize' is asumed to be a number of 'unsigned long int' for the
'struct cpu_set_t'

> 35: return EINVAL;
> 36: }

> 48: if (cpusetsize < PLPA_NAME(len)) {
'cpusetsize' and 'len' is assumed to be the number of bits

> 49: memset(&tmp, 0, sizeof(tmp));
> 50: for (i = 0; i < cpusetsize * 8; ++i) {
'cpusetsize' is assumed to be a number of bytes

> 51: if (PLPA_CPU_ISSET(i, cpuset)) {
> 52: PLPA_CPU_SET(i, &tmp);
> 53: }
> 54: }
> 55: }

> 63: else if (cpusetsize > PLPA_NAME(len)) {
same as in line 48

> 64: for (i = PLPA_NAME(len); i < cpusetsize * 8; ++i) {
'len' number of bits, 'cpusetsize' number of bytes

> 65: if (PLPA_CPU_ISSET(i, cpuset)) {
> 66: return EINVAL;
> 67: }

> 71: memset(&tmp, 0, sizeof(tmp));
> 72: for (i = 0; i < PLPA_NAME(len); ++i) {
'len' is assumed to be the number of bits

> 73: if (PLPA_CPU_ISSET(i, cpuset)) {
> 74: PLPA_CPU_SET(i, &tmp);
> 75: }
> 76: }
> 77: }
> 78:
> 79: /* Otherwise, the user supplied a buffer that is exactly the
> 80: right size. Just for clarity of code, copy the user's
> 81: buffer into the temporary and use that. */
> 82: else {
> 83: memcpy(&tmp, cpuset, cpusetsize);
'cpusetsize' number of bytes
> 84: }
> 85:
> 86: /* Now do the syscall */
> 87: ret = syscall(__NR_sched_setaffinity, 0, PLPA_NAME(len), &tmp);
at least my kernel (2.6.14) expects the 'len' parameter to be the number
of bytes (sizeof(cpu_set_t)):

from kernel/sched.c:
static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned
len,
                             cpumask_t *new_mask)
{
        if (len < sizeof(cpumask_t)) {
                memset(new_mask, 0, sizeof(cpumask_t));
        } else if (len > sizeof(cpumask_t)) {
                len = sizeof(cpumask_t);
        }
        return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0;
}

/**
 * sys_sched_setaffinity - set the cpu affinity of a process
 * @pid: pid of the process
 * @len: length in bytes of the bitmask pointed to by user_mask_ptr
 * @user_mask_ptr: user-space pointer to the new cpu mask
 */
asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
                                      unsigned long __user *user_mask_ptr)
{
        cpumask_t new_mask;
        int retval;

        retval = get_user_cpu_mask(user_mask_ptr, len, &new_mask);
        if (retval)
                return retval;

        return sched_setaffinity(pid, new_mask);
}

i count 3 'definitions' for 'cpusetsize'! my question is wich 'definition'
should i use for the call to PLPA_NAME(sched_setaffinity)()? i can't find
even a definition in any documentation from the package!

best regards
bert wesarg