![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Linux Device Drivers-Chapter 6 : Flow of Time
Số trang: 53
Loại file: pdf
Dung lượng: 410.84 KB
Lượt xem: 16
Lượt tải: 0
Xem trước 6 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu linux device drivers-chapter 6 : flow of time, công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Linux Device Drivers-Chapter 6 : Flow of TimeChapter 6 : Flow of TimeAt this point, we know the basics of how to write a full-featured charmodule. Real-world drivers, however, need to do more than implement thenecessary operations; they have to deal with issues such as timing, memorymanagement, hardware access, and more. Fortunately, the kernel makes anumber of facilities available to ease the task of the driver writer. In the nextfew chapters well fill in information on some of the kernel resources that areavailable, starting with how timing issues are addressed. Dealing with timeinvolves the following, in order of increasing complexity: Understanding kernel timing Knowing the current time Delaying operation for a specified amount of time Scheduling asynchronous functions to happen after a specified time lapseTime Intervals in the KernelThe first point we need to cover is the timer interrupt, which is themechanism the kernel uses to keep track of time intervals. Interrupts areasynchronous events that are usually fired by external hardware; the CPU isinterrupted in its current activity and executes special code (the InterruptService Routine, or ISR) to serve the interrupt. Interrupts and ISRimplementation issues are covered in Chapter 9, Interrupt Handling.Timer interrupts are generated by the systems timing hardware at regularintervals; this interval is set by the kernel according to the value of HZ,which is an architecture-dependent value defined in .Current Linux versions define HZ to be 100 for most platforms, but someplatforms use 1024, and the IA-64 simulator uses 20. Despite what yourpreferred platform uses, no driver writer should count on any specific valueof HZ.Every time a timer interrupt occurs, the value of the variable jiffies isincremented. jiffies is initialized to 0 when the system boots, and is thusthe number of clock ticks since the computer was turned on. It is declared in as unsigned long volatile, and willpossibly overflow after a long time of continuous system operation (but noplatform features jiffy overflow in less than 16 months of uptime). Mucheffort has gone into ensuring that the kernel operates properly whenjiffies overflows. Driver writers do not normally have to worry aboutjiffies overflows, but it is good to be aware of the possibility.It is possible to change the value of HZ for those who want systems with adifferent clock interrupt frequency. Some people using Linux for hard real-time tasks have been known to raise the value of HZ to get better responsetimes; they are willing to pay the overhead of the extra timer interrupts toachieve their goals. All in all, however, the best approach to the timerinterrupt is to keep the default value for HZ, by virtue of our complete trustin the kernel developers, who have certainly chosen the best value.Processor-Specific RegistersIf you need to measure very short time intervals or you need extremely highprecision in your figures, you can resort to platform-dependent resources,selecting precision over portability.Most modern CPUs include a high-resolution counter that is incrementedevery clock cycle; this counter may be used to measure time intervalsprecisely. Given the inherent unpredictability of instruction timing on mostsystems (due to instruction scheduling, branch prediction, and cachememory), this clock counter is the only reliable way to carry out small-scaletimekeeping tasks. In response to the extremely high speed of modernprocessors, the pressing demand for empirical performance figures, and theintrinsic unpredictability of instruction timing in CPU designs caused by thevarious levels of cache memories, CPU manufacturers introduced a way tocount clock cycles as an easy and reliable way to measure time lapses. Mostmodern processors thus include a counter register that is steadilyincremented once at each clock cycle.The details differ from platform to platform: the register may or may not bereadable from user space, it may or may not be writable, and it may be 64 or32 bits wide -- in the latter case you must be prepared to handle overflows.Whether or not the register can be zeroed, we strongly discourage resettingit, even when hardware permits. Since you can always measure differencesusing unsigned variables, you can get the work done without claimingexclusive ownership of the register by modifying its current value.The most renowned counter register is the TSC (timestamp counter),introduced in x86 processors with the Pentium and present in all CPUdesigns ever since. It is a 64-bit register that counts CPU clock cycles; it canbe read from both kernel space and user space.After including (for machine-specific registers), you canuse one of these macros:rdtsc(low,high);rdtscl(low);The former atomically reads the 64-bit value into two 32-bit variables; thelatter read ...
Nội dung trích xuất từ tài liệu:
Linux Device Drivers-Chapter 6 : Flow of TimeChapter 6 : Flow of TimeAt this point, we know the basics of how to write a full-featured charmodule. Real-world drivers, however, need to do more than implement thenecessary operations; they have to deal with issues such as timing, memorymanagement, hardware access, and more. Fortunately, the kernel makes anumber of facilities available to ease the task of the driver writer. In the nextfew chapters well fill in information on some of the kernel resources that areavailable, starting with how timing issues are addressed. Dealing with timeinvolves the following, in order of increasing complexity: Understanding kernel timing Knowing the current time Delaying operation for a specified amount of time Scheduling asynchronous functions to happen after a specified time lapseTime Intervals in the KernelThe first point we need to cover is the timer interrupt, which is themechanism the kernel uses to keep track of time intervals. Interrupts areasynchronous events that are usually fired by external hardware; the CPU isinterrupted in its current activity and executes special code (the InterruptService Routine, or ISR) to serve the interrupt. Interrupts and ISRimplementation issues are covered in Chapter 9, Interrupt Handling.Timer interrupts are generated by the systems timing hardware at regularintervals; this interval is set by the kernel according to the value of HZ,which is an architecture-dependent value defined in .Current Linux versions define HZ to be 100 for most platforms, but someplatforms use 1024, and the IA-64 simulator uses 20. Despite what yourpreferred platform uses, no driver writer should count on any specific valueof HZ.Every time a timer interrupt occurs, the value of the variable jiffies isincremented. jiffies is initialized to 0 when the system boots, and is thusthe number of clock ticks since the computer was turned on. It is declared in as unsigned long volatile, and willpossibly overflow after a long time of continuous system operation (but noplatform features jiffy overflow in less than 16 months of uptime). Mucheffort has gone into ensuring that the kernel operates properly whenjiffies overflows. Driver writers do not normally have to worry aboutjiffies overflows, but it is good to be aware of the possibility.It is possible to change the value of HZ for those who want systems with adifferent clock interrupt frequency. Some people using Linux for hard real-time tasks have been known to raise the value of HZ to get better responsetimes; they are willing to pay the overhead of the extra timer interrupts toachieve their goals. All in all, however, the best approach to the timerinterrupt is to keep the default value for HZ, by virtue of our complete trustin the kernel developers, who have certainly chosen the best value.Processor-Specific RegistersIf you need to measure very short time intervals or you need extremely highprecision in your figures, you can resort to platform-dependent resources,selecting precision over portability.Most modern CPUs include a high-resolution counter that is incrementedevery clock cycle; this counter may be used to measure time intervalsprecisely. Given the inherent unpredictability of instruction timing on mostsystems (due to instruction scheduling, branch prediction, and cachememory), this clock counter is the only reliable way to carry out small-scaletimekeeping tasks. In response to the extremely high speed of modernprocessors, the pressing demand for empirical performance figures, and theintrinsic unpredictability of instruction timing in CPU designs caused by thevarious levels of cache memories, CPU manufacturers introduced a way tocount clock cycles as an easy and reliable way to measure time lapses. Mostmodern processors thus include a counter register that is steadilyincremented once at each clock cycle.The details differ from platform to platform: the register may or may not bereadable from user space, it may or may not be writable, and it may be 64 or32 bits wide -- in the latter case you must be prepared to handle overflows.Whether or not the register can be zeroed, we strongly discourage resettingit, even when hardware permits. Since you can always measure differencesusing unsigned variables, you can get the work done without claimingexclusive ownership of the register by modifying its current value.The most renowned counter register is the TSC (timestamp counter),introduced in x86 processors with the Pentium and present in all CPUdesigns ever since. It is a 64-bit register that counts CPU clock cycles; it canbe read from both kernel space and user space.After including (for machine-specific registers), you canuse one of these macros:rdtsc(low,high);rdtscl(low);The former atomically reads the 64-bit value into two 32-bit variables; thelatter read ...
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin thủ thuật máy tính tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 437 1 0
-
24 trang 365 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 325 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 318 0 0 -
74 trang 307 0 0
-
96 trang 303 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 295 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 289 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 289 1 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0