Processor (cont.) cache

Source: Internet
Author: User

4. Processor (cont.) caching (cache) 4.1 Hardware processing speed

Due to economic factors, the processor and memory used by the semiconductor process, the difference between the process caused the processor and memory speed difference, the processor always waits for memory, the processor speed is much larger than the memory. Therefore, it is necessary to increase the cache between the two.
Typical: v processing > v Processor Internal Register > v cache > v Memory > Vflash

4.2 Locality of Program Access

The program runs with a feature that in a short period of time, the processor accesses the storage space is a very small range.
A. Time locality: A storage unit is likely to be accessed again in a short period of time
B. Spatial locality: Adjacent units of a storage unit may also be accessed in a short period of time
4.3 cache
The cache is a small-capacity, high-speed memory with access speeds of almost the same magnitude as the processor, and modern computers are typically placed inside the processor chip.
The cache is set between the processor and the memory, and the instructions and data that are frequently accessed in memory are copied to the cache. In most cases, the processor can get instructions and data directly from the cache.

4.4 Mapping between memory and cache

The simplest method of mapping between memory and cache is the direct mapping method. The feature is that any memory address can be mapped to a fixed location in the cache.

Direct Mapping method

? Divide the cache and memory into fixed-size blocks (such as 512byte/blocks)
? Each piece of memory has a fixed mapping location in the cache
The mapping formula is: Pos_cache = memory block number% cache Total block number, as shown:

Address Division:
![](http://i2.51cto.com/images/blog/201803/09/1037cd3857ebfbac7c4c45dc02e2a74c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
Mapping principle:

Locate the corresponding block in the cache based on the C bit in the access address, comparing the T-bit in the address with the flag of the corresponding block number.
The same, the data is read directly according to the intra-block address as an offset
, which indicates that the memory data to be accessed is not in the cache, the block contents are copied from memory to the cache.

Example of direct mapping method:

Features of the direct mapping method:

Advantages: The mapping process is simple and takes a short time
Cons: When a short-time access address has a congruence conflict (two memory corresponding to the same cache), the cache will be invalidated.

4.5 Cache principle Software application:

Background: The log system has a great impact on system efficiency, it is not easy to analyze, can not print binary data efficiently, need to customize the parsing format of the log, and can classify the log, control its output.
The original plan: to develop a log parsing software, with the script to implement the log parsing, each log has its own corresponding resolver. When a log comes in, the corresponding resolver is found through the log type.
Issue: There is a large number of logs that need to be printed in a short period of time and performance cannot meet the requirements. The bottleneck of performance is that it takes too much time to find frequent lookups.
Solution: Based on the cache principle, set level two cache to avoid lookups as much as possible.

Processor (cont.) cache

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.