![[LWN Logo]](/images/lcorner.png) |
|
![[LWN.net]](/images/Included.png) |
From: Robert Love <rml@tech9.net>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 2.5: (better) syscalls for setting task affinity
Date: 27 Feb 2002 19:13:47 -0500
Cc: torvalds@transmeta.com, mingo@elte.hu
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
/*
* 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_ptr, unsigned long *, user_mask_ptr)
int main(int argc, char * argv[])
{
unsigned long new_mask = 2;
unsigned int len;
unsigned long cur_mask;
pid_t p = getpid();
int ret;
ret = sched_get_affinity(p, &len, NULL);
printf(" len = %u\n", len);
ret = sched_get_affinity(p, &len, &cur_mask);
printf(" sched_get_affinity = %d, cur_mask = %ld\n", ret, cur_mask);
ret = sched_set_affinity(p, len, &new_mask);
printf(" sched_set_affinity = %d, new_mask = %ld\n", ret, new_mask);
ret = sched_get_affinity(p, &len, &cur_mask);
printf(" sched_get_affinity = %d, cur_mask = %ld\n", ret, cur_mask);
return 0;
}