4.5. Examples of Using Tuna
Example 4.1. Assigning Tasks to Specific CPUs
The following example uses a system with four or more processors, and shows how to make all
ssh
threads run on CPU 0 and 1, and all http
threads on CPU 2 and 3.
#
tuna --cpus=0,1 --threads=ssh\* --move --cpus=2,3 --threads=http\* --move
The above example command performs the following operations sequentially:
- Select CPUs 0 and 1.
- Select all threads that begin with
ssh
. - Move the selected threads to the selected CPUs. Tuna sets the affinity mask of threads starting with
ssh
to the appropriate CPUs. The CPUs can be expressed numerically as 0 and 1, in hex mask as0x3
, or in binary as11
. - Reset the CPU list to 2 and 3.
- Select all threads that begin with
http
. - Move the selected threads to the selected CPUs. Tuna sets the affinity mask of threads starting with
http
to the appropriate CPUs. The CPUs can be expressed numerically as 2 and 3, in hex mask as0xC
, or in binary as1100
.
Example 4.2. Viewing Current Configurations
The following example uses the
--show_threads
(-P
) parameter to display the current configuration, and then tests if the requested changes were made as expected.
#
tuna
--threads=gnome-sc\*
\--show_threads
\--cpus=0
\--move
\--show_threads
\--cpus=1
\--move
\--show_threads
\--cpus=+0
\--move
\--show_threads
thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 3861 OTHER 0 0,1 33997 58 gnome-screensav thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 3861 OTHER 0 0 33997 58 gnome-screensav thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 3861 OTHER 0 1 33997 58 gnome-screensav thread ctxt_switches pid SCHED_ rtpri affinity voluntary nonvoluntary cmd 3861 OTHER 0 0,1 33997 58 gnome-screensav
The above example command performs the following operations sequentially:
- Select all threads that begin with
gnome-sc
. - Show the selected threads to enable the user to verify their affinity mask and RT priority.
- Select CPU 0.
- Move the
gnome-sc
threads to the selected CPU (CPU 0). - Show the result of the move.
- Reset the CPU list to CPU 1.
- Move the
gnome-sc
threads to the selected CPU (CPU 1). - Show the result of the move.
- Add CPU 0 to the CPU list.
- Move the
gnome-sc
threads to the selected CPUs (CPUs 0 and 1). - Show the result of the move.