Implementation of hardware and GLIBC Library details of C language programming in Linux system

Source: Internet
Author: User
Keywords Hardware C language LINUX GLIBC Library
Tags application basic computer counter cpu function hardware high

After familiar with the basic programming method, our interest lies in how does the computer achieve all this? What does the operating system and the library function do between the application-layer APIs and the underlying system hardware?

First look at the general process of Linux time processing:

Figure 1. Time Process

The application section has been covered in detail in the first section, and in the second part I will introduce some general overviews of hardware and GlibC related implementations.

Hardware

The common clock hardware in the PC is as follows.

RTC (Real time Clock, live clock)

When people need to know the time, they can look at the clocks. The hardware of a clock in a computer system is an external clock. It relies on the battery on the motherboard to maintain the accuracy of the clock when the system is powered down. When the computer needs to know the time, it needs to read the clock.

In the x86 system, this clock is generally called real time Clock. The RTC is a http://www.aliyun.com/zixun/aggregation/19282.html ">cmos chip on the motherboard, such as Motorola 146818, which is independent of CPUs and other chips and can be passed through 0x70 and 0x71 Port Operation RTC. The RTC can periodically trigger interrupts on IRQ 8, but with low precision, from 2HZ to 8192HZ.

In the case of Motorola 146818, the software can read and write the following values through the I/O instruction:

Figure 2. Motorola 146818

As you can see, the RTC provides real-time time values that are accurate to seconds.

TSC (Time Stamp Counter)

CPU execution instructions require an external oscillator to generate a clock signal from the CLK pin input. x86 provides a TSC register that adds one to each time a clock signal is received. For example, CPU frequency of 1GHZ, then every second time, the TSC register will increase the value of 1G times, or every nanosecond plus. x86 also provides RTDSC instructions to read the value, so the TSC can also be used as a clock device. TSC provides a higher precision time than the RTC, the nanosecond time precision.

PIT (programmable Interval Timer)

PIT is the abbreviation of programmable Interval timer, the 11585.html "> Hardware device can be interrupted periodically. The early pit devices, which are 8254, can now be integrated into Intel's I/O control Hub circuitry and can access the pit via port 0x40~0x43. The system uses PIT to generate periodic clock interrupts, and clock interrupts are reported to the CPU via 8259A IRQ0. Its accuracy is not high, its entrance clock frequency is 1MHz, theoretically can produce the highest clock frequency slightly less than 0.5MHz. The actual system often uses 100 or 1000Hz of PIT.

Hpet (High Precision Event Timer)

Pit accuracy is low and hpet is designed to provide high-precision clock interrupts (at least 10MHz) in lieu of pits. It was developed jointly by Microsoft and Intel 17872.html. A hpet includes a fixed-frequency numeric increment counter and 3 to 32 independent timers, each of which has a comparator and a register (holding a value indicating when the interrupt is triggered). Each comparer compares the values in the counter with the values in the registers, and when the two values are equal, an interrupt occurs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.