Schedulerrelated data structures and macros

This section introduces data structures, functions, and macros used extensively throughout the kernel. Even in the SMP case they are relatively trivial, but it is still necessary to introduce them. Number of computer processing units

Some information needed for SMP management is shown in Figure 7.1 from arch/i386/kernel/smpboot.c.

60 int smp_num_siblings = 1;

978 int cpu_sibling_map[NR_CPUS]_cacheline_aligned;

Figure 7.1 Number of computer processing units this global variable contains the total count of active CPUs. It is statically initialised to 1, as there must always be at least one CPU to begin with. It is incremented as each new one CPU booted.

60 this is the number of sibling CPUs packaged together. It is also statically initialised to 1; it may be incremented to 2 if a dual package is encountered at bootup.

978 each CPU has an entry in this array. If there are siblings packaged together, then each entry in this array contains the number of its sibling. Mapping of computer processing unit numbers

Each active CPU is identified in Linux by an identification (ID) number. Although on the i386 architecture these are sequential, they may not be so on all architectures, so the two functions shown in Figure 7.2 from <asm-i386/smp. h>, have to be supplied for mapping between logical and physical numbering.

57 extern unsigned long cpu_online_map;

57 this is a bitmap, with bits set corresponding to CPUs that are currently on-line, not disabled.

77 although this is an identity mapping on an i386, on another architecture it could map between the physical CPU number, corresponding to its place on the motherboard, and its logical number, as used within the kernel.

81 although this is also an identity mapping on an i386, on another architecture it could map between the logical number by which a CPU is identified within the kernel and its physical place on the motherboard. Identifying the current process

Figure 7.3, from <asm-i386/current ,h>, shows a function that returns a pointer to the task_struct of the currently executing process (i.e. the process executing the code that calls it). There is also a macro that simplifies the use of this function, by condensing it down to one word. This macro is used extensively throughout the kernel.

80 81 82

57 extern unsigned long cpu_online_map;

80 81 82

Figure 7.2 Numbering of computer processing units

static inline struct task_struct * get_current(void) {

struct task_struct *current;

_asm_("andl%%esp,%0;":"=r" (current) : "" (~8191UL));

return current;

13 #define current get_current() Figure 7.3 Identifying the current process

9 the value of the kernel stack pointer is somewhere within the task_union; 8191 decimal is 0001 1111 1111 1111. Inverting that gives 1110 0000 0000 0000. This effectively strips off the low-order 13 bits of the stack pointer value, aligning it at the beginning of the task_union. This is also the beginning of the task_struct.

7.21.4 Identifying the current processor

The macro shown in Figure 7.4 from <asm-i386/smp.h>, returns the ID of the processor on which the current process is executing. It gets this information from the processor field of its task_struct. The current macro is defined in Section

107 #definesmp_processor_id()(current->processor) Figure 7.4 Identifying the current process

The Ultimate Computer Repair Guide

The Ultimate Computer Repair Guide

Read how to maintain and repair any desktop and laptop computer. This Ebook has articles with photos and videos that show detailed step by step pc repair and maintenance procedures. There are many links to online videos that explain how you can build, maintain, speed up, clean, and repair your computer yourself. Put the money that you were going to pay the PC Tech in your own pocket.

Get My Free Ebook

Post a comment