From: Rusty Russell <rusty@rustcorp.com.au>
To: torvalds@transmeta.com, rml@tech9.net, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] How to write a portable "run_on" program?
Date: Thu, 08 May 2003 15:14:40 +1000 [thread overview]
Message-ID: <20030508051539.31CFA2C04B@lists.samba.org> (raw)
Hi all,
Currently you need to do the following in userspace to set
your affinity portably:
#include <limits.h>
#define BITS_PER_LONG (sizeof(long)*CHAR_BIT)
int set_cpu(int cpu)
{
size_t size = sizeof(unsigned long);
unsigned long *bitmask = NULL;
int ret;
do {
size *= 2;
bitmask = realloc(bitmask, size);
memset(bitmask, 0, size);
bitmask[cpu / BITS_PER_LONG] = (1 << (cpu % BITS_PER_LONG);
ret = sched_setaffinity(getpid(), size, bitmask);
} while (ret < 0 && errno = -EINVAL);
return ret;
}
I know Linus thinks this is natural and fine[1], but for the rest of
us, how about the following patch, which allows:
int set_cpu(int cpu)
{
size_t size = sched_getaffinity(getpid(), 0, NULL);
unsigned char bitmask[size];
memset(bitmask, 0, size);
bitmask[cpu/8] = (1 << (cpu%8));
return sched_setaffinity(getpid(), size, bitmask);
}
Thoughts?
Rusty.
[1] http://www.ussg.iu.edu/hypermail/linux/kernel/0206.2/0551.html
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.69-bk2/kernel/sched.c working-2.5.69-bk2-getaffinity/kernel/sched.c
--- linux-2.5.69-bk2/kernel/sched.c 2003-05-05 12:37:13.000000000 +1000
+++ working-2.5.69-bk2-getaffinity/kernel/sched.c 2003-05-08 15:11:30.000000000 +1000
@@ -1949,6 +1949,10 @@ asmlinkage long sys_sched_getaffinity(pi
task_t *p;
real_len = sizeof(mask);
+
+ /* This lets the user query the bitmask size. */
+ if (!len)
+ return real_len;
if (len < real_len)
return -EINVAL;
next reply other threads:[~2003-05-08 5:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-08 5:14 Rusty Russell [this message]
2003-05-08 5:31 ` Linus Torvalds
2003-05-08 7:00 ` Rusty Russell
2003-05-08 7:00 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030508051539.31CFA2C04B@lists.samba.org \
--to=rusty@rustcorp.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rml@tech9.net \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®