How to find processor queue length on Linux

An attempt to determine the length of the processor queue (the number of processes that are ready to start, but are currently not available) on the linux machine. Windows has a WMI call for this metric, but I don’t know much about Linux. I am trying to get / proc and "top" for information. Is there a way to determine the queue length for a processor?

Edit to add: Microsoft's words regarding their metric: "Collecting one or more threads that are ready but cannot run on the processor due to another active thread that is currently running is called the processor queue."

+7
source share
4 answers

sar -q will indicate the length of the queue, the length of the task list, and three average load values.

Example:

 matli@tornado :~$ sar -q 1 0 Linux 2.6.27-9-generic (tornado) 01/13/2009 _i686_ 11:38:32 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 11:38:33 PM 0 305 1.26 0.95 0.54 11:38:34 PM 4 305 1.26 0.95 0.54 11:38:35 PM 1 306 1.26 0.95 0.54 11:38:36 PM 1 306 1.26 0.95 0.54 ^C 
+9
source

vmstat

 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- rb swpd free buff cache si so bi bo in cs us sy id wa 2 0 256368 53764 75980 220564 2 28 60 54 774 1343 15 4 78 2 

The first column (r) is the execution queue - 2 on my machine right now

Edit: Surprised there is no way to just get a number

A quick "n" dirty way to get a number (may vary slightly on different machines):

  vmstat|tail -1|cut -d" " -f2 
+6
source

uptime will give you the latest average load, which is approximately the average number of active processes. uptime reports the average load for the last 1, 5, and 15 minutes. This is a measurement for each system, not for each processor.

Not sure if the processor queue length on Windows, hope it is close enough to this?

+2
source

The metrics you are looking for exist in /proc/schedstat .

The format of this file is described in sched-stats.txt in the kernel source code. In particular, you need the cpu<N> lines:

 CPU statistics -------------- cpu<N> 1 2 3 4 5 6 7 8 9 First field is a sched_yield() statistic: 1) # of times sched_yield() was called Next three are schedule() statistics: 2) This field is a legacy array expiration count field used in the O(1) scheduler. We kept it for ABI compatibility, but it is always set to zero. 3) # of times schedule() was called 4) # of times schedule() left the processor idle Next two are try_to_wake_up() statistics: 5) # of times try_to_wake_up() was called 6) # of times try_to_wake_up() was called to wake up the local cpu Next three are statistics describing scheduling latency: 7) sum of all time spent running by tasks on this processor (in jiffies) 8) sum of all time spent waiting to run by tasks on this processor (in jiffies) 9) # of timeslices run on this cpu 

In particular, field 8. To find the length of the execution queue, you must:

  1. Observe field 8 for each processor and record the value.
  2. Wait for some interval.
  3. Review field 8 for each CPU again and calculate how much the value has increased.
  4. Dividing this difference by the length of the expected time interval (in jiffies), according to Little Law , we get the average length of the scheduler's execution queue per interval.

Unfortunately, I do not know of any utility for automating this process, which is usually installed or even packaged into a Linux distribution. I have not used it, but the kernel documentation suggests http://eaglet.rain.com/rick/linux/schedstat/v12/latency.c , which unfortunately refers to a domain that can no longer be resolved. Fortunately, it is available on the way back of the car .


Why not sar or vmstat ?

These tools report the number of processes currently running. Of course, if this number exceeds the number of processors, some of them must wait. However, processes can still be expected, even when the number of processes is less than the number of processors, for a number of reasons:

  • A process can be assigned to a specific processor.
  • The scheduler may decide to plan the process on a specific CPU for better use of the cache or for reasons of NUMA optimization.
  • The scheduler can deliberately idle the CPU to allow more time for a competing process with a higher priority on another CPU that uses the same execution core (hyper-threading optimization).
  • Hardware interrupts can only be processed on specific processors for various hardware and software reasons.

Moreover, the number of running processes is determined only in one instant. In many cases, this number can fluctuate quickly, and there may be a conflict between the moments of the metric sample.

These things mean that the number of processes executed minus the number of processors is not a reliable indicator of processor conflict.

0
source

All Articles