Re: Question about set/get cpu affinity tool by Robert love.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



this code seems to be pretty old ..

You can try this code .. let me know if u find any issues with it....


/* bind - simple command-line tool to set CPU
 * affinity of a given task
 */

#define _GNU_SOURCE

#include <stdlib.h>
#include <stdio.h>
#include <sched.h>

int main(int argc, char *argv[])
{
    cpu_set_t new_mask;
    cpu_set_t cur_mask;
    unsigned int len = sizeof(new_mask);
    pid_t pid;

    if (argc != 3) {
   fprintf(stderr,
                "usage: %s [pid] [cpu_mask]\n",
                argv[0]);
   return -1;
    }

    pid = atol(argv[1]);

    if (sched_getaffinity(pid, len,
                          &cur_mask) < 0) {
   perror("sched_getaffinity");
   return -1;
    }

    printf("pid %d's  %08lx\n",
           pid, cur_mask);

    CPU_ZERO(&new_mask);
    CPU_SET(atoi(argv[2]), &new_mask);


    if (sched_setaffinity(pid, len, &new_mask)) {
   perror("sched_setaffinity");
   return -1;
    }

    if (sched_getaffinity(pid, len,
                          &cur_mask) < 0) {
   perror("sched_getaffinity");
   return -1;
    }

    printf(" pid %d's new affinity: %08lx\n",
           pid, cur_mask);
    return 0;
}



-Vinit

On Fri, Jul 31, 2009 at 1:42 AM, Vipul Jain <vipulsj@xxxxxxxxx> wrote:
Hi All,

   I am trying to compile the cpu affinity tool written by Robert love present at the below link:
  
   http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/067/6799/6799l1.html

   But if I try to compile the program its giving me following error:

   vipul@ubuntu:~/linux$ cc -o bind bind.c
   bind.c: In function `main':
   bind.c:29: warning: passing arg 3 of `sched_getaffinity' from incompatible pointer type
   bind.c:37: warning: passing arg 3 of `sched_setaffinity' from incompatible pointer type
   bind.c:42: warning: passing arg 3 of `sched_getaffinity' from incompatible pointer type

   I am not sure why? (looking at his explanation and code things look perfect).
   http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/067/6799

   Also, Second thing he mentions sched_get/setaffinity takes three args but after doing the cscope
   in kernel source I found that its taking 2 args only.
   [cut from kernel/sched.c]
   long sched_getaffinity(pid_t pid, struct cpumask *mask)

    I was wondering if any body could please help me with this issue, would like to run this tool and
    set/check cpu affinity.

Regards,
Vipul.



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux