Re: [PATCH] 2.5: (better) syscalls for setting task affinity

Robert Love (rml@tech9.net)
27 Feb 2002 19:13:47 -0500


--=-M3NU0m+3AwUm6J9gDJSG
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2002-02-27 at 18:45, Robert Love wrote:

> The attached patch implements a syscall interface for setting and
> retrieving a task's CPU affinity (task->cpus_allowed):

I should posted a test program to demonstrate the syscalls - find such
an attachment below. It demonstrates using sched_get_affinity to find
the length of the cpu bitmask and then get and set a new value.

`pid_t p' is the process in question.
`unsigned long new_mask' is the new bitmask.

Robert Love

--=-M3NU0m+3AwUm6J9gDJSG
Content-Disposition: attachment; filename=affinity.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c; charset=ISO-8859-1

/*
* Example of sched_set_affinity and sched_get_affinity
* Robert Love, 20020227
*/

#include <stdio.h>
#include <stdlib.h>
#include <linux/unistd.h>
#include <unistd.h>

#define __NR_sched_set_affinity 239
#define __NR_sched_get_affinity 240

_syscall3 (int, sched_set_affinity, pid_t, pid, unsigned int, len, unsigned=
long *, new_mask_ptr)
_syscall3 (int, sched_get_affinity, pid_t, pid, unsigned int *, user_len_pt=
r, unsigned long *, user_mask_ptr)

int main(int argc, char * argv[])
{
unsigned long new_mask =3D 2;
unsigned int len;
unsigned long cur_mask;
pid_t p =3D getpid();
int ret;

ret =3D sched_get_affinity(p, &len, NULL);
printf(" len =3D %u\n", len);

ret =3D sched_get_affinity(p, &len, &cur_mask);
printf(" sched_get_affinity =3D %d, cur_mask =3D %ld\n", ret, cur_mask);

ret =3D sched_set_affinity(p, len, &new_mask);
printf(" sched_set_affinity =3D %d, new_mask =3D %ld\n", ret, new_mask);

ret =3D sched_get_affinity(p, &len, &cur_mask);
printf(" sched_get_affinity =3D %d, cur_mask =3D %ld\n", ret, cur_mask);

return 0;
}

--=-M3NU0m+3AwUm6J9gDJSG--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/