11.6.4.4 preempt and remain-cpu

Because Oracle Linux is a preemptive system, higher priority threads preempt lower priority ones. Preemption can induce a significant latency bubble in the lower priority thread, so you might want to know which threads are being preempted by which other threads. The following example shows how to use the preempt and remain-cpu probes to display this information:

#pragma D option quiet

sched:::preempt
{
  self->preempt = 1;
}

sched:::remain-cpu
/self->preempt/
{
  self->preempt = 0;
}

sched:::off-cpu
/self->preempt/
{
  /*
   * If we were told to preempt ourselves, see who we ended up giving
   * the CPU to.
   */
  @[stringof(args[1]->pr_fname), args[0]->pr_pri, execname,
    curlwpsinfo->pr_pri] = count();
  self->preempt = 0;
}

END
{
  printf("%30s %3s %30s %3s %5s\n", "PREEMPTOR", "PRI",
    "PREEMPTED", "PRI", "#");
  printa("%30s %3d %30s %3d %5@d\n", @);
}

Running the above script for several seconds on a desktop system results in output similar to the following example:

# dtrace -s whopreempt.d 
^C
                     PREEMPTOR PRI                      PREEMPTED PRI     #
                       firefox 120                    kworker/0:0 120     1
                   gnome-panel 120                        swapper 120     1
                   gnome-panel 120                    wnck-applet 120     1
                   jbd2/dm-0-8 120                        swapper 120     1
                    khugepaged 139                    kworker/0:0 120     1
                   ksoftirqd/1 120                    kworker/0:0 120     1
                   kworker/0:0 120                 gnome-terminal 120     1
                   kworker/0:2 120                           Xorg 120     1
                   kworker/0:2 120                           java 120     1
                   kworker/1:0 120                           Xorg 120     1
                      nautilus 120                           Xorg 120     1
                  rtkit-daemon   0                   rtkit-daemon 120     1
                  rtkit-daemon 120                        swapper 120     1
                    watchdog/0   0                        swapper 120     1
                    watchdog/1   0                    kworker/0:0 120     1
                   wnck-applet 120                           Xorg 120     1
                   wnck-applet 120                        swapper 120     1
                     automount 120                    kworker/0:0 120     2
               gnome-power-man 120                    kworker/0:0 120     2
                   kworker/0:0 120                        swapper 120     2
                   kworker/1:0 120                         dtrace 120     2
                      metacity 120                    kworker/0:0 120     2
               notification-da 120                        swapper 120     2
                 udisks-daemon 120                    kworker/0:0 120     2
                     automount 120                        swapper 120     3
                   gnome-panel 120                           Xorg 120     3
               gnome-settings- 120                           Xorg 120     3
               gnome-settings- 120                        swapper 120     3
                gnome-terminal 120                        swapper 120     3
                          java 120                    kworker/0:0 120     3
                   ksoftirqd/0 120                        swapper 120     3
                   kworker/0:2 120                        swapper 120     3
                      metacity 120                           Xorg 120     3
                      nautilus 120                    kworker/0:0 120     3
                         qpidd 120                        swapper 120     3
                      metacity 120                        swapper 120     4
               gvfs-afc-volume 120                        swapper 120     5
                          java 120                           Xorg 120     5
               notification-da 120                           Xorg 120     5
               notification-da 120                    kworker/0:0 120     5
                          Xorg 120                    kworker/0:0 120     6
                   wnck-applet 120                    kworker/0:0 120    10
                   VBoxService 120                        swapper 120    13
                        dtrace 120                        swapper 120    14
                   kworker/1:0 120                    kworker/0:0 120    16
                        dtrace 120                    kworker/0:0 120    20
                          Xorg 120                        swapper 120    90
               hald-addon-inpu 120                        swapper 120   100
                          java 120                        swapper 120   108
                gnome-terminal 120                    kworker/0:0 120   110