TAILIEUCHUNG - linux device drivers 2nd edition phần 6

để hạn chế số lượng bộ nhớ đang được quản lý. Ví dụ, một trong những tác giả của bạn sử dụng mem = 126 m để dự trữ 2 MB trong một hệ thống mà thực sự có 128 MB RAM. Sau đó, trong thời gian chạy, bộ nhớ này có thể được phân bổ và sử dụng bởi các trình điều khiển thiết bị. | Race Conditions It s interesting to note that only a producer-and-consumer situation can be addressed with a circular buffer. A programmer must often deal with more complex data structures to solve the concurrent-access problem. The producer con-sumer situation is actually the simplest class of these problems other structures such as linked lists simply don t lend themselves to a circular buffer implementation. Using Spinlocks We have seen spinlocks before for example in the scull driver. The discussion thus far has looked only at a few uses of spinlocks in this section we cover them in rather more detail. A spinlock remember works through a shared variable. A function may acquire the lock by setting the variable to a specific value. Any other function needing the lock will query it and seeing that it is not available will spin in a busy-wait loop until it is available. Spinlocks thus need to be used with care. A function that holds a spinlock for too long can waste much time because other CPUs are forced to wait. Spinlocks are represented by the type spinlock_t which along with the various spinlock functions is declared in asm . Normally a spinlock is declared and initialized to the unlocked state with a line like spinlock_t my_lock SPIN_LOCK_UNLOCKED If instead it is necessary to initialize a spinlock at runtime use spin_lock_init spin_lock_init my_lock There are a number of functions actually macros that work with spinlocks spin_lock spinlock_t lock Acquire the given lock spinning if necessary until it is available. On return from spin_lock the calling function owns the lock. spin_lock_irqsave spinlock_t lock unsigned long flags This version also acquires the lock in addition it disables interrupts on the local processor and stores the current interrupt state in flags. Note that all of the spinlock primitives are defined as macros and that the flags argument is passed directly not as a pointer. spin_lock_irq spinlock_t lock This function acts like .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.