Binding a process or thread to a (virtual) processor

Binding threads/processes to a CPU

You can bind your process or threads within the process onto a particular CPU (or thread context) using the following methods:
  • bind using an external pbind utility that takes process id as an argument
  • bind from within your program using processor_bind system call. Check out a code example here. To compile the program use Sun Studio cc compiler.
  • use an external program runbind (written by Sasha Fedorova) that launches your program after binding it to the specified CPU.

    You can grab a program for Solaris/Sparc from /cs/systems/Tools/Solaris-SPARC/Bind/Runbind/runbind, and for Solaris/x86 from /cs/systems/Tools/Solaris-x86/Bind/Runbind/runbind

    To see how to run this program run runbind -h.

    In the same directory as the program there is an example program hello_world. You can try
    runbinding a single or multple instances of hello_world like this:

    ./runbind -p0 ./hello_world 1 2 3 -p1 ./hello_world 4 5 6

    You will see that each program prints its arguments and the CPU id to which it is bound. The runbind program will exit after launching the two programs, but the programs will continue to run on the background.

    In an event you want to runbind a program whose arguments contain "-p", you need to use "runbind-one-command" program. You will be able to runbind one program at a time. So if you want to run multiple programs simultaneously, run multiple instances of runbind-one-command to launch multiple programs.
  • Note on Niagara:  to bind threads to a specific core, you need to use four consecutive CPU id's starting from a core ID. A core ID is any id evenly divisible by 4. For example, to bind four threads to core 0, you will use CPU ids 0, 1, 2, 3.