Linux Process Manager: The Internals of Scheduling, Interrupts and Signals

Free Download

Authors:

ISBN: 9780470847718, 0470847719

Size: 5 MB (5596745 bytes)

Pages: 848/848

File format:

Language:

Publishing Year:

Category:

John O’Gorman9780470847718, 0470847719

* An ideal resource to understand the internals, line by line* Looks at architecture dependent code for PC version* Addresses process creation, timers, software and hardware interrupts, signals, tracing processes, and the virtual 8086 mode

Table of contents :
The Linux Process
Manager……Page 5
Copyright……Page 6
Contents……Page 7
Preface……Page 13
In Memoriam……Page 15
Overview of contents……Page 17
References……Page 19
1 Introduction……Page 21
1.1 Overview of the process manager……Page 22
1.1.2 Multiprocessors……Page 23
1.1.3 Threads……Page 24
1.2.1 C language features……Page 25
1.2.2 Assembly language features……Page 27
1.3.1 Starting the kernel……Page 29
1.3.2 Scheduler initialisation……Page 30
1.3.3 Starting and the idle process……Page 31
2.1 Important fields hard coded at the beginning……Page 33
2.1.1 Line 285:……Page 34
2.1.2 Line 286:……Page 35
2.1.3 Line 296:……Page 37
2.2 Scheduling fields……Page 38
2.3 General process information……Page 42
2.5 Credentials and limits……Page 47
2.6 Miscellaneous information……Page 50
2.7 Volatile environment and input ¨C output……Page 51
2.8 Signal handlers……Page 57
2.10 Conclusions……Page 59
3.1 Manipulating the linked list of task structures……Page 61
3.1.1 Removing a……Page 62
3.3.2 Inserting a……Page 63
3.1.3 Searching the process list……Page 65
3.2.1 The process hash table……Page 66
3.2.3 Insert a into the hash table……Page 67
3.2.4 Remove a from the hash table……Page 69
3.3.1 The of the initial process……Page 70
3.3.2 The of the initial process……Page 72
3.3.3 Resource limits for the initial process……Page 75
3.4.1 Setting up the idle thread…….Page 76
3.4.2 Initialise the idle thread……Page 77
3.4.3 The default idle function……Page 78
4.1.1 Declaring and initialising wait queue entries……Page 81
4.1.2 Wait queue headers……Page 83
4.1.3 Debugging code……Page 86
4.2.1 Adding an entry to a wait queue……Page 89
4.2.2 Removing an entry from a wait queue……Page 91
4.3.1 Declaring and initialising list entries……Page 93
4.3.2 Inserting entries……Page 94
4.3.3 Deleting entries……Page 95
4.3.4 Miscellaneous functions……Page 96
4.4 Wait queue locks……Page 99
4.5.1 Common code……Page 100
4.5.2 Putting a process to sleep interruptibly……Page 101
4.5.3 Sleeping interruptibly with a timeout……Page 102
4.6 Conditionally waiting on an event……Page 103
4.6.1 Conditional uninterruptible sleep……Page 104
4.6.2 Conditional interruptible sleep……Page 106
4.7.1 Wake- up macros……Page 108
4.7.2 Locking the wait queue and wake up……Page 109
4.7.3 Finding a process to wake up……Page 110
4.7.4 Trying to wake up a specific process……Page 112
4.8.1 Add a to the runqueue……Page 113
4.8.3 Removing a from the runqueue……Page 114
4.8.4 Checking if a is on the runqueue……Page 115
5.1.1 Setting a bit……Page 117
5.1.2 Clearing a bit……Page 118
5.1.4 Testing and setting a bit……Page 119
5.1.6 Finding the first bit clear……Page 121
5.2.1 Basic definitions……Page 122
5.2.3 Atomic subtraction……Page 123
5.2.5 Atomic increment……Page 124
5.2.7 Atomic decrement and test for zero……Page 125
5.2.9 Atomically add and test for negative result……Page 126
5.2.10 Atomically exchanging a value……Page 127
5.3.1 Spinlocks with no debugging……Page 129
5.3.3 Spinlocks with full debugging……Page 131
5.4.2 Initialising a spinlock……Page 134
5.4.3 Operations on spinlocks……Page 135
5.5.2 Multiprocessor implementation……Page 140
5.6 Single- processor version of read ¨C write locks……Page 143
5.7.1 Data structures and initialisation……Page 144
5.7.2 Operations on read ¨C write locks……Page 145
5.7.3 Macros to operate on read locks……Page 148
5.7.4 Macros to operate on write locks……Page 151
5.7.5 Assembly language helper routines for read ¨C write locks……Page 152
6.1 Kernel semaphores……Page 155
6.1.1 Semaphore data structures and macros……Page 156
6.1.2 Operations on semaphores……Page 158
6.1.3 Intermediate- level routines……Page 162
6.1.4 Semaphore worker functions……Page 166
6.2.1 Data structures……Page 172
6.2.2 High- level manipulation of read ¨C write semaphores……Page 176
6.2.3 Acquiring and releasing a read ¨C write semaphore……Page 177
6.2.4 Interaction with the scheduler……Page 183
6.2.5 Atomic operations on read ¨C write semaphore values……Page 191
6.3 Completions……Page 192
6.3.2 Signalling a completion……Page 193
6.3.3 Waiting for completion……Page 194
7.1.1 Scheduling policies in Linux……Page 197
7.1.2 The Linux scheduler……Page 198
7.2.1 Scheduler- related data structures and macros……Page 199
7.2.2 Global scheduler structures……Page 201
7.2.3 Task state segment……Page 202
7.2.4 Kernel statistics……Page 205
7.3.1 Eliminating exceptions……Page 207
7.3.2 Scheduling preliminaries……Page 209
7.3.3 Selecting the next process to run……Page 210
7.3.4 Recording a scheduling decision……Page 212
7.3.5 Context switching……Page 213
7.4.1 Scheduling macros……Page 215
7.4.2 Calculating the of a process……Page 216
7.4.3 Determining the quantum for a process……Page 218
7.5 Context switching……Page 219
7.5.1 Preparing to context switch……Page 220
7.5.2 Switching the computer processing unit context……Page 222
7.5.3 Loading a debug register……Page 223
7.5.4 Cleaning up after the context switch……Page 224
7.5.5 Releasing a computer processing unit……Page 226
7.6.1 Trying the computer processing unit on which the process last ran……Page 227
7.6.2 Finding another computer processing unit……Page 228
7.6.3 The uniprocessor case……Page 231
7.6.4 Comparing suitabilities of two processes……Page 232
8.1.1 Process manager variables……Page 233
8.1.2 Initialisation routine……Page 234
8.2.1 Checking permissions and allocating data structure……Page 235
8.2.2 Initialising fields in the new……Page 236
8.2.3 Initialising time- related fields……Page 239
8.2.4 Copying external process information……Page 240
8.2.5 Linking into process structure……Page 241
8.2.6 Error handling……Page 243
8.3.1 Clone flags……Page 246
8.3.3 Allocating a process identification number……Page 247
8.3.4 Copying signal handlers……Page 251
8.3.5 Setting up the structure for a child process……Page 252
8.3.6 The child¡¯s return path……Page 255
8.4.1 User identification structures……Page 256
8.4.2 The user hash structure……Page 257
8.4.3 Allocating a user structure……Page 258
8.4.4 Deallocating a user structure……Page 261
8.5 Creating a kernel thread……Page 263
9.1 Terminating a process……Page 265
9.2.1 Notifying other processes of termination……Page 268
9.2.2 Notifying child processes of the death of the parent……Page 271
9.2.3 Determining if a process group is orphaned……Page 273
9.2.4 Checking if there is a stopped process in a group……Page 274
9.3 Waiting for a child process to exit……Page 275
9.3.1 Parameter checking and initial setup……Page 276
9.3.2 Searching for a zombie child……Page 277
9.3.3 Waiting for a child to exit……Page 281
9.4.2 Removing the……Page 283
9.4.3 Usage statistics……Page 286
10 Interrupting Linux……Page 291
10.1.1 Data structures……Page 292
10.1.2 Initialising the interrupt descriptor table……Page 294
10.1.3 The default interrupt handler……Page 295
10.2.1 Setting up gates……Page 296
10.2.2 System entries in the interrupt descriptor table……Page 299
10.3.1 Format of saved registers on the stack……Page 301
10.3.2 Saving registers……Page 304
10.3.4 Finding the current……Page 305
10.3.5 Offsets into the……Page 306
10.4.1 The Intel binary specification entry point……Page 307
10.4.3 The Linux system call entry……Page 309
10.5.1 Divide error……Page 313
10.5.2 Co- processor errors……Page 316
10.5.4 The nonmaskable interrupt……Page 318
10.5.5 Exceptions requiring trivial handling……Page 319
10.5.6 Exceptions with error code provided by the computer processing unit……Page 321
10.6 Returning from an interrupt……Page 322
10.6.2 Returning from exceptions and interrupts……Page 323
10.6.3 Detecting a pending signal……Page 325
10.6.5 Summary……Page 327
11.1.1 Generating the handlers……Page 329
11.1.2 The generating macros……Page 330
11.1.3 The generic handler function……Page 332
11.2.1 Debug registers……Page 334
11.2.2 The debug exception handler……Page 335
11.3.1 Second- level handler for the nonmaskable interrupt……Page 338
11.3.2 Checking if the computer processing unit is locked up……Page 340
11.3.4 Parity error on an expansion card……Page 343
11.3.5 Unidentifiable reason for nonmaskable interrupt……Page 344
11.4 General protection……Page 345
11.6.1 Wrapper for machine check handler……Page 347
11.6.2 Second- level handler for machine check……Page 348
11.6.3 Machine- specific registers……Page 351
11.6.4 Reading and writing machine- specific registers……Page 352
11.7.1 No floating point unit present……Page 353
11.7.2 Floating point unit registers not valid……Page 354
11.8.2 The main handler for a co- processor error……Page 355
11.9.1 Error in a non- SIMD co- processor……Page 358
11.9.2 SIMD co- processor errors……Page 360
11.10.1 Checking for additional features……Page 362
11.10.2 Manipulating floating point unit registers……Page 363
11.10.3 Retrieving values from structure……Page 367
11.10.4 Terminating a process……Page 368
12.1 Programmable interrupt controller……Page 371
12.2.2 Status bits……Page 373
12.2.3 Descriptor for an interrupt handler……Page 374
12.2.4 Table of hardware interrupt line descriptors……Page 375
12.2.5 Default functions for an interrupt controller…….Page 376
12.3 First- level handlers for hardware interrupts……Page 377
12.3.1 Table of first- level handlers……Page 378
12.3.2 Generating first- level interrupt handlers……Page 379
12.4.1 Generic second- level interrupt handling……Page 382
12.4.2 Running the handlers for a hardware interrupt……Page 385
12.5.1 Initialising hardware interrupts……Page 387
12.5.2 Initialising the array for a programmable interrupt controller……Page 390
12.5.4 Initialising irq13 and irq2……Page 392
12.5.5 Handler for irq13……Page 393
12.6.1 Requesting an interrupt line……Page 394
12.6.2 Freeing an interrupt line……Page 399
12.6.3 Disabling an irq……Page 401
12.6.4 Enabling an irq line……Page 403
12.7 The 8259A programmable interrupt controller……Page 404
12.7.1 Programming the programmable interrupt controller……Page 405
12.7.2 Data structures……Page 406
12.7.3 Initialising the programmable interrupt controller……Page 408
12.7.5 Enable……Page 410
12.7.6 Disable……Page 411
12.7.7 Acknowledge……Page 412
12.7.9 Determining if an interrupt is pending……Page 416
12.8 Interrupt- safe locks……Page 417
12.8.1 Macros for interrupt- safe locks……Page 418
12.8.2 Generic interrupt macros……Page 419
12.9 Functions for reading and writing input ¨C output ports……Page 420
12.9.1 Single input ¨C output functions……Page 421
12.9.2 String input ¨C ouput functions……Page 424
12.9.3 Pausing an input ¨C output operation……Page 426
13 Advanced programmable interrupt controllers……Page 429
13.1.1 Identification and priority……Page 430
13.1.2 Interrupt handling registers……Page 431
13.1.3 Interrupt command register……Page 433
13.1.4 The local vector table……Page 435
13.2.1 Sanity checks and APIC identification……Page 438
13.2.2 Enabling the APIC……Page 439
13.2.3 The local interrupt pins……Page 440
13.2.4 Error handling on a local APIC……Page 442
13.2.5 Setup virtual wire mode……Page 443
13.3.1 Interface functions for a local APIC……Page 444
13.3.2 Generic functions for manipulating a local APIC……Page 446
13.4.1 Basic functions for accessing APICs……Page 449
13.4.2 An APIC needing read before write……Page 450
13.5.2 The call function interrupt……Page 451
13.5.3 Shortcut addressing for sending interprocessor interrupts……Page 454
13.5.4 Low- level functions to send an interprocessor interrupt……Page 456
13.6.1 Instantiating first- level handlers for APIC interrupts……Page 461
13.6.2 Macros to build first- level handlers for APIC interrupts……Page 462
13.7.1 The reschedule interrupt……Page 464
13.7.2 The call function interrupt……Page 465
13.7.3 Local APIC timer interrupt……Page 466
13.7.4 The local error interrupt……Page 470
13.7.6 Resending an irq……Page 471
14.1 Interrupt configuration tables in Linux……Page 473
14.1.1 Data structures……Page 474
14.1.2 Reading the interrupt configuration tables……Page 477
14.1.3 Getting the polarity and trigger type of an irq line……Page 481
14.1.4 The array……Page 488
14.2.1 General APIC registers……Page 490
14.2.2 Routing registers……Page 491
14.2.3 Initialising the IO APIC……Page 495
14.2.4 Disabling an IO APIC before rebooting……Page 501
14.3.1 Edge triggered interrupts on an IO APIC……Page 504
14.3.2 Level triggered interrupts on an IO APIC……Page 506
14.4.1 Masking and unmasking irqs on an IO APIC……Page 509
14.4.2 Macros to generate masking and unmasking functions……Page 510
14.4.3 Macro to manipulate an IO APIC register……Page 511
14.4.4 Setting affinity for an IO APIC……Page 512
14.4.5 Reading and writing IO APICs……Page 513
14.5.1 The global interrupt request lock……Page 514
14.5.2 Enabling and disabling interrupts globally……Page 519
14.5.3 Global flags……Page 521
15.1.1 Variables used by timer interrupt handler……Page 525
15.1.3 Subsidiary functions……Page 526
15.1.4 Second- level timer interrupt handling……Page 531
15.2.1 Delayed timer processing……Page 532
15.2.2 Maintaining the time of day……Page 533
15.2.3 Updating the time- of- day clock by one tick……Page 534
15.2.4 Refining the accuracy of the clock……Page 538
15.2.5 Generating load statistics……Page 547
15.3 Event timers……Page 550
15.3.1 Event timer data structures……Page 551
15.3.2 Timer management……Page 554
15.3.3 Sleeping for a fixed length of time……Page 560
15.3.4 Handling expired timers……Page 563
16 Software interrupts……Page 569
16.1.1 Data structures……Page 570
16.1.2 Initialising software interrupts……Page 571
16.1.3 Running a software interrupt……Page 572
16.1.4 The software interrupt kernel thread……Page 575
16.1.5 Raising a software interrupt……Page 578
16.2.1 Data structures……Page 580
16.2.3 Scheduling standard- priority tasklets……Page 582
16.2.4 Scheduling high- priority tasklets……Page 584
16.2.5 Enabling and disabling tasklets……Page 585
16.2.6 The standard priority tasklet software interrupt……Page 587
16.2.7 The high- priority tasklet software interrupt……Page 589
16.2.8 Tasklet locking……Page 591
16.3.1 Data structures……Page 592
16.3.2 Executing bottom halves……Page 594
16.4 Task queues……Page 595
16.4.2 Inserting a task on a queue……Page 596
16.4.3 Run queued tasks……Page 597
16.4.4 Predefined task queues……Page 599
16.5.1 Data structures and macros……Page 600
16.5.2 Nesting software interrupts……Page 602
16.5.3 Manipulating interrupt counters……Page 604
17.1.1 Basic definitions……Page 607
17.1.2 Signal definitions……Page 608
17.1.3 Process- specific signal handling information……Page 611
17.1.4 Queue of pending signals……Page 614
17.1.5 Extended information about a signal……Page 615
17.2.1 Manipulating a specific bit in a bitmap……Page 623
17.2.2 Manipulating whole bitmaps……Page 625
17.2.3 Manipulating subsets of a bitmap……Page 629
17.3 Installing a signal handler……Page 631
17.4.1 Deallocating handler and queue head structures……Page 633
17.4.2 Deallocating all queued signals……Page 634
17.4.3 Flushing all pending signals for a process……Page 635
17.4.4 Flushing all handlers for a process……Page 636
17.5.2 Deactivating the callback function……Page 637
17.6.1 Alternate signal stack……Page 638
17.6.2 Setting or getting an alternate stack context……Page 639
17.6.3 Checking for an alternate signal stack……Page 642
18.1.1 Sending a signal, with extra information……Page 643
18.1.2 Subsidiary functions……Page 645
18.1.3 Posting a signal to the target process……Page 650
18.2.1 Forcing the delivery of a signal……Page 655
18.2.2 Sending a signal to all processes in a group……Page 656
18.2.3 Sending a signal to a session leader……Page 657
18.2.4 Sending a signal to a specific process identification number……Page 658
18.2.5 Sending a signal to a range of processes……Page 659
18.2.6 Sending signals to a parent……Page 661
18.2.7 Backward compatibility functions for sending signals……Page 664
18.3.1 Checking the field……Page 665
18.3.3 Recalculating the signal state……Page 666
18.4 Delivering a pending signal……Page 667
18.4.1 Identifing the pending signal……Page 668
18.4.2 Signal pending to a traced process……Page 669
18.4.3 Ignoring a signal……Page 670
18.4.4 Default handling for a signal……Page 671
18.4.5 Signal with a user- defined handler……Page 673
18.4.6 Restarting an interrupted system call……Page 674
18.5.1 Dequeue a signal……Page 675
18.5.2 Subsidiary functions……Page 677
19.1 Handling a signal……Page 683
19.2.1 Structure of a stack frame……Page 686
19.2.2 Registering context for handling a signal……Page 687
19.2.3 Extended context information for a signal handler……Page 688
19.2.4 Floating point state……Page 689
19.3.1 Setting up a standard stack frame……Page 691
19.3.2 Setting up an extended stack frame……Page 694
19.3.3 Getting a pointer to the stack frame in user space……Page 697
19.4.1 Copying extra signal information to user space……Page 699
19.4.2 Copying the register state to user stack……Page 700
19.4.3 Copying the floating point unit state to the user stack……Page 702
19.5.1 Returning from a standard stack frame……Page 709
19.5.2 Returning from an extended stack frame……Page 711
19.6.1 Restoring signal context from user space……Page 713
19.6.3 Restoring the floating point unit state from the user stack……Page 716
20.1.1 Defined capabilities……Page 723
20.1.2 Capability bitmaps……Page 726
20.2.1 Converting between capability types……Page 727
20.2.3 Combining two capability sets……Page 728
20.2.5 Removing specified bits from a capability bitmap……Page 729
20.2.7 Miscellaneous macros……Page 730
20.3.1 Setting capabilities for all processes……Page 731
20.4.1 Checking for a particular capability……Page 732
20.4.2 Checking for root privileges……Page 733
20.4.4 Checking a security setting……Page 734
21.1.1 Personality types……Page 737
21.1.3 Manipulating personalities……Page 739
21.2.1 The structure……Page 740
21.2.2 The execution domain list……Page 741
21.2.3 The default system service handler……Page 742
21.3 Registering and unregistering execution domains……Page 743
21.3.1 Registering a new execution domain……Page 744
21.3.2 Unregistering an execution domain……Page 745
21.3.3 Adjusting execution domain module usecounts……Page 746
21.4.2 Changing personality……Page 747
21.4.3 Finding the execution domain corresponding to a personality……Page 749
22.1 Setting up a process to be traced……Page 753
22.2.1 Architecture- independent disabling of tracing……Page 756
22.3 Accessing the memory space of a traced process……Page 757
22.3.1 Reading data from a traced process……Page 758
22.3.2 Writing data to a traced process……Page 759
22.4.1 Writing to a register……Page 760
22.4.2 Reading from a register……Page 762
22.4.3 Manipulating the stack of the traced process……Page 764
22.5 Traced process handling a system call……Page 766
22.6.1 Displaying interrupt and bottom- half state……Page 767
22.6.2 Displaying stack values……Page 769
22.6.3 Displaying call frames on the stack……Page 770
22.6.4 Displaying register contents……Page 771
23.1.1 Variables used by the accounting subsystem……Page 775
23.1.2 The format of an accounting record……Page 776
23.2.1 Marking that free space needs checking……Page 778
23.2.2 Checking free space……Page 779
23.3.1 Checking that there is an accounting file……Page 781
23.3.2 Writing an accounting record……Page 782
23.4 Encoding an unsigned long……Page 785
24.1.1 Information supplied by user……Page 787
24.1.2 Stack layout……Page 791
24.1.3 Information in the structure……Page 794
24.2.1 Bits in the register……Page 795
24.2.3 Getting the virtual flags……Page 797
24.2.4 Setting values in the virtual flags register……Page 798
24.2.5 Manipulating bits in the virtual flags register……Page 799
24.3.1 Emulating instructions……Page 800
24.3.2 Reading values from memory……Page 803
24.4.1 The system call……Page 805
24.4.2 Internal processing……Page 806
24.5 Trap handling in vm86 mode……Page 809
24.6 Handling faults in vm86 mode……Page 811
24.6.1 Macros and local variables……Page 812
24.6.2 Two- byte instructions……Page 813
24.6.3 Single- byte instructions……Page 815
24.7.1 Handling a vectored interrupt in vm86 mode……Page 819
24.7.2 Checking the revectored bitmap……Page 821
24.8.1 Returning to protected mode……Page 822
24.8.2 Writing vm86 state to user space……Page 823
24.8.3 Returning values from vm86 mode……Page 825
Index……Page 827

Reviews

There are no reviews yet.

Be the first to review “Linux Process Manager: The Internals of Scheduling, Interrupts and Signals”
Shopping Cart
Scroll to Top