Kernel statistics

The operating system maintains a significant amount of statistical information about what is going on in the kernel. As much of this is maintained by the scheduler, this is a suitable place to introduce it.

7.2.4.1 Scheduler-specific information

Figure 7.9, from kernel/sched.c, shows some data structures used to record scheduling statistics.

101 static union {

102 struct schedule_data {

103 struct task_struct * curr;

104 cycles_t last_schedule;

105 }schedule_data;

106 char_pad [SMP_CACHE_BYTES];

107 } aligned_data [NR_CPUS]_cacheline_aligned = {{{&init_task,0}}};

109 #define cpu_curr(cpu) aligned_data[(cpu)].schedule_data.curr

110 #definelast_schedule(cpu)

aligned_data[(cpu)].schedule_data.last_schedule

112 struct kernel_stat kstat; Figure 7.9 Recording scheduling information

101-107 this array contains scheduling data on a per-CPU basis.

103 this contains a pointer to the task_struct of the process currently running on that CPU.

104 this is the clock cycle count when that process began on that CPU.

106 each element is padded out to fill one line in the cache.

107 all elements are initialised pointing to init_task (Section 3.3.1), with a count of 0, aligned on a cacheline boundary, to prevent cacheline 'ping pong'.

109 this macro converts a CPU number into a pointer to the task_struct representing the current process assigned to that CPU.

110 this macro converts a CPU number into the machine cycle count on that CPU at the time of the last context switch.

112 this structure contains kernel-wide statistics. It is described in detail in Section 7.2.4.2.

7.2.4.2 Kernel statistics

The structure kernel_stat is declared in <linux/kernel_stat.h> (see Figure 7.10). It is used to maintain statistics on a kernel-wide basis. Most of the fields deal with IO, memory management, and networking. Only those relevant to the process manager will be discussed here.

15 #define DK_MAX_MAJOR 16

16 #define DK_MAX_DISK 16

18 struct kernel_stat {

19 unsigned int per_cpu_user[NR_CPUS],

20 per_cpu_nice[NR_CPUS],

21 per_cpu_system[NR_CPUS];

22 unsigned int dk_drive [DK_MAX_MAJOR][DK_MAX_DISK] ;

23 unsigned int dk_drive_rio[DK_MAX_MAJOR][DK_MAX_DISK];

24 unsigned int dk_drive_wio[DK_MAX_MAJOR][DK_MAX_DISK];

25 unsigned int dk_drive_rblk[DK_MAX_MAJOR][DK_MAX_DISK];

26 unsigned int dk_drive_wblk[DK_MAX_MAJOR][DK_MAX_DISK];

27 unsigned int pgpgin, pgpgout;

28 unsigned int pswpin, pswpout;

29 #if!defined(CONFIG_ARCH_S390)

30 unsigned int irqs[NR_CPUS][NR_IRQS];

31 #endif

32 unsigned int ipackets, opackets;

33 unsigned int ierrors, oerrors;

34 unsigned int collisions;

35 unsigned int context_swtch;

Figure 7.10 Structure for storing kernel statistics

15-16 these are constants that determine the size of arrays used to maintain information about the IO subsystem.

19-21 these three fields are updated by the update_process_times() function (see Section 15.1.3.1).

19 this is the total amount of time each CPU has spent running in user mode.

20 this is the total amount of time each CPU has spent running in user mode, with reduced priority.

21 this is the total amount of time each CPU has spent running in system mode.

22 -26 cumulative statistics for the IO manager are maintained in these fields.

27-28 cumulative statistics for the memory manager are maintained in these fields.

30 cumulative statistics for each interrupt line on each CPU are maintained in these fields (see Section 12.4.1).

32-34 cumulative statistics for the network manager are maintained in these fields.

35 this gives the number of context switches executed since the system was booted. See Section 7.3.4, where this field is updated.

Continue reading here: Clone flags

Was this article helpful?

0 0