- Hands-On System Programming with C++
- Dr. Rian Quinn
- 406字
- 2021-07-02 14:42:28
Time
Some readers might find it surprising to know that even performing simple tasks such as getting the current date and time require system calls to ask the operating system for this information. Even to this day, a dedicated chip (with a battery, in case of loss of power) is provided on the system to maintain the current date and time.
If this information is needed, a system call must be made to request it. When this happens, the operating system will ask the device driver responsible for managing the chip what date and time it is currently storing, and then this information will be returned to the application.
It should be noted that not all time interfaces require system calls. For example, most high-resolution timers, which are designed to compare a high-resolution number before and after an operation has taken place, do not need the operating system to perform this action. This is because these high-resolution timers usually exist directly in the CPU, and their values can be extracted using a simple instruction.
The downside to these types of timers is that their values in and of themselves are usually meaningless (that is, the difference between the values returned is what provides meaning, not the values themselves). Essentially, these timers are usually nothing more than a counter that increments each time the CPU ticks (that is, executes an instruction).
Since modern CPUs can dynamically change their frequency, the values these counters store depends on how long the CPU has executed since the previous power cycle, and at what frequency the CPU was set while it was executing.
There isn't even a guarantee that the value in one counter will be the same as the value read in another counter on another physical core, as each physical core is capable of changing its own frequency independently of other cores on multi-core CPUs.
The benefit of high-resolution timers is that they can be executed extremely quickly (as you are just executing an instruction that reads a counter in the CPU). The difference between two measured values can be used to carry out tasks such as measuring how long it takes to execute small functions—a task that usually doesn't work with standard timers, as they don't have enough granularity.
In Chapter 11, Time Interfaces in Unix, we will go over these details and even provide an example of how to do this yourself.
- 數據浪潮
- 數據庫應用實戰
- 劍破冰山:Oracle開發藝術
- Modern Programming: Object Oriented Programming and Best Practices
- 云計算服務保障體系
- Scratch 3.0 藝術進階
- 數據科學工程實踐:用戶行為分析與建模、A/B實驗、SQLFlow
- 視覺大數據智能分析算法實戰
- 跨領域信息交換方法與技術(第二版)
- SQL Server 2012實施與管理實戰指南
- 貫通SQL Server 2008數據庫系統開發
- 數據庫查詢優化器的藝術:原理解析與SQL性能優化
- Spring Boot 2.0 Cookbook(Second Edition)
- 企業大數據處理:Spark、Druid、Flume與Kafka應用實踐
- PostgreSQL高可用實戰