The Linux Kernel/Processing
Processing: from process to CPU
Processes and Tasks
Process is a running user space program. Kernel can start a process with function do_execve. Processes occupy system resources, like memory, CPU time. System calls sys_fork and sys_execve are used to create new processes from user space. The process exit with an sys_exit system call.
How are the process handled within the kernel?
What are kernel threads?
How are kernel threads handled ?
- ULK3 Chapter 3. Processes
- ULK3 Chapter 4. Interrupts and Exceptions
- ULK3 Chapter 5. Kernel Synchronization
- ULK3 Chapter 6. Timing Measurements
- ULK3 Chapter 7. Process Scheduling
- cat /proc/self/
- "Process Scheduling in Linux" About kernel 3.1.10 (December 13 2013)
- completion - use completion for synchronization task with ISR and task or two tasks.
- has owner and usage constrains
- more easy to debug then semaphore
- #include <linux/mutex.h>
- spinlock_t, timer_list, wait_queue_head_t
- semaphore - use mutex instead semaphore if possible
- #include <include/linux/semaphore.h>
- atomic operations
- LKD2: Chapter 9. Kernel Synchronization Methods
- LDD3:Concurrency and Race Conditions
Low level kernel synchronization: futex
A futex (short for "fast userspace mutex") is a kernel system call that programmers can use to implement basic locking, or as a building block for higher-level locking abstractions such as semaphores and POSIX mutexes or condition variables.
A futex consists of a kernelspace wait queue that is attached to an aligned integer in userspace. Multiple processes or threads operate on the integer entirely in userspace (using atomic operations to avoid interfering with one another), and only resort to relatively expensive system calls to request operations on the wait queue (for example to wake up waiting processes, or to put the current process on the wait queue). A properly programmed futex-based lock will not use system calls except when the lock is contended; since most operations do not require arbitration between processes, this will not happen in most cases.
The basic operations of futexes are based on only two central operations —WAIT and WAKE— though some futex implementations (depending on the exact version of the Linux kernel) have a few more operations for more specialized cases.
- WAIT (addr, val)
- Checks if the value stored at the address addr is val, and if it is puts the current thread to sleep.
- WAKE (addr, val)
- Wakes up val number of threads waiting on the address addr.
Time and Timers
- LDD3:Interrupt Handling
- tasklet is a softirq, runs in interrupt context, for time critical operations
- softirq is internal system facility and should not be used directly. Use tasklet.
- BH - Removed in 2.5
- Task queues - Removed in 2.5