本文共 17701 字,大约阅读时间需要 59 分钟。
你可以使用mod_timer()修改my_timer的到期时间,使用del_timer()取消定时器,或使用timer_pending()以查看my_timer当前是否处于pending状态。查看kernel/timer.c源代码,你会发现schedule_timeout()内部就使用了这些API。
老的信号量接口 互斥体接口代替了老的信号量接口(semaphore),它互斥体诞生于-rt树,在2.6.16内核中被融入主线内核。 尽管如此,但是老的信号量仍然在内核和驱动中被广泛使用。信号量接口的基本用法如下: #include <asm/semaphore.h> /* Architecture dependent header */ /* Statically declare a semaphore. To dynamically create a semaphore, use init_MUTEX() */ static DECLARE_MUTEX(mysem); down(&mysem); /* Acquire the semaphore */ /* ... Critical Section code ... */ up(&mysem); /* Release the semaphore */ 信号量可以被配置为允许多个预定数量的线程同时进入临界区,但是,这种用法非常罕见。 |
-rt 树 实时(-rt)树,也被称作CONFIG_PREEMPT_RT补丁集,实现了内核中一些针对低延时的修改。该补丁集可以从下载,它允许内核的大部分位置可被抢占,但是用自旋锁代替了一些互斥体。它也合并了一些高精度的定时器。数个-rt功能已经被融入了主线内核。在工程的wiki页上,能找到详细的文档,地址为。 |
数据结构 | 位置 | 描述 |
HZ | include/asm-your-arch/param.h | Number of times the system timer ticks in 1 second |
loops_per_jiffy | init/main.c | Number of times the processor executes an internal delay-loop in 1 jiffy |
timer_list | include/linux/timer.h | Used to hold the address of a routine that you want to execute at some point in the future |
timeval | include/linux/time.h | Timestamp |
spinlock_t | include/linux/spinlock_types.h | A busy-locking mechanism to ensure that only a single thread enters a critical section |
semaphore | include/asm-your-arch/semaphore.h | A sleep-locking mechanism that allows a predetermined number of users to enter a critical section |
mutex | include/linux/mutex.h | The new interface that replaces semaphore |
rwlock_t | include/linux/spinlock_types.h | Reader-writer spinlock |
page | include/linux/mm_types.h | Kernel's representation of a physical memory page |
内核接口 | 位置 | 描述 |
time_after() time_after_eq() time_before() ime_before_eq() | include/linux/jiffies.h | Compares the current value of jiffies with a specified future value |
schedule_timeout() | kernel/timer.c | Schedules a process to run after a specified timeout has elapsed |
wait_event_timeout() | include/linux/wait.h | Resumes execution if a specified condition becomes true or if a timeout occurs |
DEFINE_TIMER() | include/linux/timer.h | Statically defines a timer |
init_timer() | kernel/timer.c | Dynamically defines a timer |
add_timer() | include/linux/timer.h | Schedules the timer for execution after the timeout has elapsed |
mod_timer() | kernel/timer.c | Changes timer expiration |
timer_pending() | include/linux/timer.h | Checks if a timer is pending at the moment |
udelay() | include/asm-your-arch/delay.h arch/your-arch/lib/delay.c | Busy-waits for the specified number of microseconds |
rdtsc() | include/asm-x86/msr.h | Gets the value of the TSC on Pentium-compatible processors |
do_gettimeofday() | kernel/time.c | Obtains wall time |
local_irq_disable() | include/asm-your-arch/system.h | Disables interrupts on the local CPU |
local_irq_enable() | include/asm-your-arch/system.h | Enables interrupts on the local CPU |
local_irq_save() | include/asm-your-arch/system.h | Saves interrupt state and disables interrupts |
local_irq_restore() | include/asm-your-arch/system.h | Restores interrupt state to what it was when the matching local_irq_save() was called |
spin_lock() | include/linux/spinlock.h kernel/spinlock.c | Acquires a spinlock. |
spin_unlock() | include/linux/spinlock.h | Releases a spinlock |
spin_lock_irqsave() | include/linux/spinlock.h kernel/spinlock.c | Saves interrupt state, disables interrupts and preemption on local CPU, and locks their critical section to regulate access by other CPUs |
spin_unlock_irqrestore() | include/linux/spinlock.h kernel/spinlock.c | Restores interrupt state and preemption and releases the lock |
DEFINE_MUTEX() | include/linux/mutex.h | Statically declares a mutex |
mutex_init() | include/linux/mutex.h | Dynamically declares a mutex |
mutex_lock() | kernel/mutex.c | Acquires a mutex |
mutex_unlock() | kernel/mutex.c | Releases a mutex |
DECLARE_MUTEX() | include/asm-your-arch/semaphore.h | Statically declares a semaphore |
init_MUTEX() | include/asm-your-arch/semaphore.h | Dynamically declares a semaphore |
up() | arch/your-arch/kernel/semaphore.c | Acquires a semaphore |
down() | arch/your-arch/kernel/semaphore.c | Releases a semaphore |
atomic_inc() atomic_inc_and_test() atomic_dec() atomic_dec_and_test() clear_bit() set_bit() test_bit() test_and_set_bit() | include/asm-your-arch/atomic.h | Atomic operators to perform lightweight operations |
read_lock() read_unlock() read_lock_irqsave() read_lock_irqrestore() write_lock() write_unlock() write_lock_irqsave() write_lock_irqrestore() | include/linux/spinlock.h kernel/spinlock.c | Reader-writer variant of spinlocks |
down_read() up_read() down_write() up_write() | kernel/rwsem.c | Reader-writer variant of semaphores |
read_seqbegin() read_seqretry() write_seqlock() write_sequnlock() | include/linux/seqlock.h | Seqlock operations |
kmalloc() | include/linux/slab.h mm/slab.c | Allocates physically contiguous memory from ZONE_NORMAL |
kzalloc() | include/linux/slab.h mm/util.c | Obtains zeroed kmalloced memory |
kfree() | mm/slab.c | Releases kmalloced memory |
vmalloc() | mm/vmalloc.c | Allocates virtually contiguous memory that is not guaranteed to be physically contiguous. |
本文转自 21cnbao 51CTO博客,原文链接:http://blog.51cto.com/21cnbao/120804,如需转载请自行联系原作者