CLI: start a process from tuna

Currently it is possible to set the CPU affinity and sched tunables for
threads running on a system. However, tuna does not permit to start a
new application with these parameters set.

This patch adds the ability to start a new process with its affinity
and sched tunable set before it starts to run.

To do so, one parameter was added to tuna's command line. This
parameter is the Action -r, --run=:

   -r, --run="COMMAND"
	  Run the COMMAND. If arguments are passed, the entire com‐
	  mand line must be provided inside "quotes". Modifiers  -c
	  and -p can be used to set the affinity and scheduler tun‐
	  ables of the given COMMAND. The arg[0] (i.e. the command)
	  will  be set in THREAD-LIST. Likewise the -t, the COMMAND
	  accepts the prefix + and - as wildcards in  order  to  be
	  appended or removed from THREAD-LIST, respectively.

The option -r will fork a new process, set the sched tunables and
affinity, and execute the new application's binary.

Tuna will wait for the new process to return, and then continue
its execution. That means that it is possible to execute many Actions
after the creation of a new process, including the start of many process
in a single command line.

Example of use:

[root@kiron tuna]# tuna -p fifo:1 -t bash -c 1,2 -r +httpd -P
                      thread       ctxt_switches
    pid SCHED_ rtpri affinity voluntary nonvoluntary             cmd
  10550  OTHER     0  0,1,2,3       300           81            bash
  12898  OTHER     0  0,1,2,3        30            6            bash
  12930  OTHER     0  0,1,2,3       246           27            bash
  13022   FIFO     1      1,2         1            0           httpd

In this example, the schedule policy:prio fifo:1 is saved for future
Actions, "bash" is set in Thread list, cpus 1,2 are set in the cpulist,
the command "httpd" is appended to the Thread list and is started.
Finally, the threads in Thread list are printed.

Signed-off-by: Daniel Bristot de Oliveira <daniel@bristot.me>
Signed-off-by: John Kacur <jkacur@redhat.com>
Signed-off-by: Jiri Kastner <jkastner@redhat.com>
2 files changed