On Nov 29, 2005, at 2:51 PM, Paul H. Hargrove wrote:
> The result is the following, which I've tried in limited testing:
Holy Crimminey, Batman -- this message slipped by me in my INBOX.
This is friggen' amazing.
Many thanks, Paul!
> enum {
> SCHED_SETAFFINITY_TAKES_2_ARGS,
> SCHED_SETAFFINITY_TAKES_3_ARGS_THIRD_IS_LONG,
> SCHED_SETAFFINITY_TAKES_3_ARGS_THIRD_IS_CPU_SET,
> SCHED_SETAFFINITY_UNKNOWN
> };
>
> /* We want to call by this prototype, even if it is not the real
> one */
> extern sched_setaffinity(int pid, unsigned int len, void *mask);
>
> int probe_setaffinity(void) {
> unsigned long mask[511];
> int rc;
>
> memset(mask, 0, sizeof(mask));
> mask[0] = 1;
> rc = sched_setaffinity(0, sizeof(mask), mask);
>
> if (rc >= 0) {
> /* Kernel truncates over-length masks -> successful call */
> return SCHED_SETAFFINITY_TAKES_3_ARGS_THIRD_IS_CPU_SET;
> } else if (errno == EINVAL) {
> /* Kernel returns EINVAL when len != sizeof(long) */
> return SCHED_SETAFFINITY_TAKES_3_ARGS_THIRD_IS_LONG;
> } else if (errno == EFAULT) {
> /* Kernel returns EFAULT having rejected len as an address */
> return SCHED_SETAFFINITY_TAKES_2_ARGS;
> }
> return SCHED_SETAFFINITY_UNKNOWN;
> };
--
{+} Jeff Squyres
{+} The Open MPI Project
{+} http://www.open-mpi.org/
|