CN114461546A - Memory control method and device, storage medium and electronic equipment - Google Patents
Memory control method and device, storage medium and electronic equipment Download PDFInfo
- Publication number
- CN114461546A CN114461546A CN202011242674.4A CN202011242674A CN114461546A CN 114461546 A CN114461546 A CN 114461546A CN 202011242674 A CN202011242674 A CN 202011242674A CN 114461546 A CN114461546 A CN 114461546A
- Authority
- CN
- China
- Prior art keywords
- bandwidth
- memory
- processor
- target
- cache
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/08—Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
- G06F12/0802—Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
- G06F12/0893—Caches characterised by their organisation or structure
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/08—Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
- G06F12/0802—Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
- G06F12/0877—Cache access modes
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
本申请实施例提供一种内存控制方法、装置、存储介质和电子设备,本申请通过获取处理器中的高速缓存在单位时长内的缓存缺失数量,利用处理器缓存缺失时从内存获取数据的特性,进一步根据缓存缺失数量获取内存所需提供的目标带宽,该目标带宽即反映了处理器访问内存的数据量实际需求,从而将内存的带宽调整为目标带宽即可满足处理器对内存的访问需求。相较于相关技术,本申请并不在固定的几个带宽宽度中进行选择,而是去分析对内存的实际带宽需求,从而根据实际带宽需求对内存的带宽进行实时调整,以此来满足对内存访问性能的使用需求。同时,由于对内存调整后的带宽是与实际带宽需求所匹配的,不存在带宽的浪费,还能够避免功耗的浪费。
The embodiments of the present application provide a memory control method, device, storage medium, and electronic device. The present application uses the feature of acquiring data from the memory when the processor cache is missing by obtaining the number of cache misses per unit time in the cache of the processor. , and further obtain the target bandwidth required by the memory according to the number of cache misses. The target bandwidth reflects the actual demand for the data volume of the processor to access the memory, so that the memory bandwidth can be adjusted to the target bandwidth to meet the processor's access requirements to the memory. . Compared with the related art, the present application does not select from several fixed bandwidth widths, but analyzes the actual bandwidth requirements of the memory, so as to adjust the bandwidth of the memory in real time according to the actual bandwidth requirements, so as to meet the needs of the memory. Access performance usage requirements. At the same time, since the bandwidth after adjusting the memory is matched with the actual bandwidth requirement, there is no waste of bandwidth, and waste of power consumption can also be avoided.
Description
技术领域technical field
本申请涉及处理器技术领域,特别涉及一种内存控制方法、装置、存储介质和电子设备。The present application relates to the technical field of processors, and in particular, to a memory control method, apparatus, storage medium and electronic device.
背景技术Background technique
内存也称内存储器或主存储器,它用于暂时存放处理器中的运算数据,与外部存储器交换的数据等。如智能手机、平板电脑等电子设备通常配置有内存,电子设备部署的所有应用的运行都是在内存中进行的,因此处理器需要频繁的对内存进行访问。处理器对内存的访问性能取决于内存所能提供的带宽,带宽越高,相应访问性能也就越高,但同时功耗也越高。Memory, also known as internal memory or main memory, is used to temporarily store operational data in the processor and data exchanged with external memory. Electronic devices such as smart phones, tablet computers and other electronic devices are usually configured with memory, and all applications deployed by the electronic devices are executed in the memory, so the processor needs to access the memory frequently. The access performance of the processor to the memory depends on the bandwidth that the memory can provide. The higher the bandwidth, the higher the corresponding access performance, but the higher the power consumption.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供一种内存控制方法、装置、存储介质和电子设备,既能满足对内存访问性能的使用需求,还能避免功耗的浪费。The embodiments of the present application provide a memory control method, apparatus, storage medium and electronic device, which can not only meet the usage requirements for memory access performance, but also avoid waste of power consumption.
本申请公开一种内存控制方法,包括:The present application discloses a memory control method, including:
获取处理器中的高速缓存在单位时长内的缓存缺失数量;Get the number of cache misses in the processor's cache per unit time;
根据所述缓存缺失数量获取内存所需提供的目标带宽;The target bandwidth required to obtain memory according to the number of cache misses;
将所述内存的带宽调整为所述目标带宽。Adjust the bandwidth of the memory to the target bandwidth.
本申请还公开一种内存控制装置,包括:The present application also discloses a memory control device, comprising:
数量获取模块,用于获取处理器中的高速缓存在单位时长内的缓存缺失数量;A quantity acquisition module, which is used to acquire the number of cache misses within a unit time of the cache in the processor;
带宽获取模块,用于根据所述缓存缺失数量获取内存所需提供的目标带宽;a bandwidth obtaining module, configured to obtain the target bandwidth required to be provided by the memory according to the number of cache misses;
带宽调整模块,用于将所述内存的带宽调整为所述目标带宽。A bandwidth adjustment module, configured to adjust the bandwidth of the memory to the target bandwidth.
本申请还公开一种存储介质,其上存储有计算机程序,当所述计算机程序被处理器加载时执行本申请提供的内存控制方法。The present application also discloses a storage medium on which a computer program is stored, and when the computer program is loaded by a processor, the memory control method provided by the present application is executed.
本申请还公开一种电子设备,包括处理器、存储器和内存,所述存储器存储有计算机程序,所述处理器通过加载所述计算机程序执行本申请提供的内存控制方法。The present application also discloses an electronic device including a processor, a memory and a memory, wherein the memory stores a computer program, and the processor executes the memory control method provided by the present application by loading the computer program.
本申请实施例中,通过获取处理器中的高速缓存在单位时长内的缓存缺失数量,利用处理器缓存缺失时从内存获取数据的特性,进一步根据缓存缺失数量获取内存所需提供的目标带宽,该目标带宽即反映了处理器访问内存的数据量实际需求,从而将内存的带宽调整为目标带宽即可满足处理器对内存的访问需求。相较于相关技术,本申请并不在固定的几个带宽宽度中进行选择,而是去分析对内存的实际带宽需求,从而根据实际带宽需求对内存的带宽进行实时调整,以此来满足对内存访问性能的使用需求。同时,由于对内存调整后的带宽是与实际带宽需求所匹配的,不存在带宽的浪费,还能够避免功耗的浪费。In the embodiment of the present application, by obtaining the number of cache misses of the cache in the processor per unit time, using the feature of acquiring data from the memory when the processor cache misses, and further obtaining the target bandwidth required by the memory according to the number of cache misses, The target bandwidth reflects the actual demand for the amount of data the processor needs to access the memory, so that the memory bandwidth can be adjusted to the target bandwidth to meet the processor's demand for memory access. Compared with the related art, the present application does not select from several fixed bandwidth widths, but analyzes the actual bandwidth demand of the memory, so as to adjust the bandwidth of the memory in real time according to the actual bandwidth demand, so as to meet the needs of the memory. Access performance usage requirements. At the same time, since the bandwidth after adjusting the memory is matched with the actual bandwidth requirement, there is no waste of bandwidth, and waste of power consumption can also be avoided.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the accompanying drawings that are used in the description of the embodiments.
图1为本申请提供的内存控制方法的一流程示意图。FIG. 1 is a schematic flowchart of a memory control method provided by the present application.
图2为本申请实施例中处理器访问内存的一示意图。FIG. 2 is a schematic diagram of a processor accessing a memory according to an embodiment of the present application.
图3为本申请实施例中处理器访问内存的另一示意图。FIG. 3 is another schematic diagram of a processor accessing a memory in an embodiment of the present application.
图4为本申请提供的内存控制方法的另一流程示意图。FIG. 4 is another schematic flowchart of the memory control method provided by the present application.
图5为本申请提供的内存控制装置的结构示意图。FIG. 5 is a schematic structural diagram of a memory control device provided by the present application.
图6为本申请提供的电子设备的结构示意图。FIG. 6 is a schematic structural diagram of an electronic device provided by the present application.
具体实施方式Detailed ways
本申请实施例提供的技术方案可以应用于各种需要进行数据通信的场景,本申请实施例对此并不限定。The technical solutions provided in the embodiments of the present application can be applied to various scenarios where data communication is required, which is not limited in the embodiments of the present application.
请参照图1,本申请提供一种内存控制方法、内存控制装置、存储介质以及电子设备。其中,该内存控制方法的执行主体可以是本申请实施例提供的内存控制装置,或者集成了该内存控制装置的电子设备,其中该内存控制装置可以采用硬件或者软件的方式实现。其中,电子设备可以是智能手机、平板电脑、掌上电脑、笔记本电脑等移动式电子设备、或者台式电脑、广告机等固定式电子设备。Referring to FIG. 1 , the present application provides a memory control method, a memory control device, a storage medium, and an electronic device. The execution body of the memory control method may be the memory control apparatus provided in the embodiments of the present application, or an electronic device integrating the memory control apparatus, where the memory control apparatus may be implemented in hardware or software. Wherein, the electronic device may be a mobile electronic device such as a smart phone, a tablet computer, a palmtop computer, and a notebook computer, or a stationary electronic device such as a desktop computer and an advertising machine.
请参照图1,图1为本申请实施例提供的内存控制方法的流程示意图,本申请实施例提供的内存控制方法的具体流程可以如下:Please refer to FIG. 1. FIG. 1 is a schematic flowchart of a memory control method provided by an embodiment of the present application. A specific process of the memory control method provided by an embodiment of the present application may be as follows:
在110中,获取处理器中的高速缓存在单位时长内的缓存缺失数量。In 110, the number of cache misses per unit time period of the cache in the processor is obtained.
应当说明的是,请参照图2,处理器中通常配置有高速缓存,或称高速缓冲存储器,其作用是为了更好的利用局部性原理(包括时间局部性和空间局部性),即最近被处理器访问的内存中的数据,短期内处理器还要访问(时间局部性);被处理器访问的数据附近的其它数据,处理器短期内还要访问(空间局部性)。因此如果处理器将刚刚访问过的数据缓存在高速缓存中,那么下次访问时,处理器可以直接从高速缓存中获取,而无需再从内存中获取,从而使得处理器的访问速度可以得到数量级的提高。It should be noted that, referring to FIG. 2, a cache, or cache memory, is usually configured in the processor, and its function is to better utilize the principle of locality (including temporal locality and spatial locality), that is, the most recent The data in the memory accessed by the processor will also be accessed by the processor in the short term (temporal locality); other data near the data accessed by the processor will also be accessed by the processor in the short term (spatial locality). Therefore, if the processor caches the data that has just been accessed in the cache, then the next time the processor accesses it, the processor can directly fetch it from the cache without having to fetch it from the memory, so that the access speed of the processor can be improved by an order of magnitude. improvement.
基于以上相关描述,当处理器要访问的数据在高速缓存中有缓存时,称为“命中”,而当处理器要访问的数据在高速缓存中未缓存时,称为“缺失”。基于此,本申请中首先获取处理器中的高速缓存在单位时长(该单位时长可由本领域普通技术人员根据实际需要取经验值,例如,可将单位时长配置为1秒)内的缓存缺失数量,也即是在单位时长内,处理器访问数据时,高速缓存中未缓存处理器所需访问数据的次数。比如,在单位时长1秒内,处理器访问高速缓存10000次,其中有5000次访问的数据是缓存于高速缓存中的,而另外5000次访问的数据未缓存于高速缓存中,需要从内存中读取,因此,可以得到高速缓存的缓存缺失数量为5000。Based on the above related descriptions, when the data to be accessed by the processor is cached in the cache, it is called a "hit", and when the data to be accessed by the processor is not cached in the cache, it is called a "miss". Based on this, in the present application, firstly, the cache misses in the cache in the processor in a unit duration (the unit duration can be obtained from an empirical value according to actual needs by those of ordinary skill in the art, for example, the unit duration can be configured as 1 second) The number of cache misses is obtained. , that is, the number of times that the processor needs to access data that is not cached in the cache when the processor accesses data within a unit time. For example, in a unit duration of 1 second, the processor accesses the cache 10,000 times, of which 5,000 access data is cached in the cache, while the other 5,000 access data is not cached in the cache, and needs to be accessed from the memory. Reads, therefore, can get a cache miss count of 5000.
在120中,根据缓存缺失数量获取内存所需提供的目标带宽。In 120, the target bandwidth required to be provided by the memory is obtained according to the number of cache misses.
如上所述,可以理解的是,对于高速缓存中缺失的数据,处理器需要从内存中获取,而处理器是否能够稳定的从内存中获取到所需的数据,取决于内存是否能够提供足够的带宽。比如,处理器单位时长1秒内从内存所需的数据量为512Mb,则内存至少需要提供512Mb/s的带宽,才能供处理器稳定的访问。As mentioned above, it can be understood that for the data missing from the cache, the processor needs to obtain the required data from the memory, and whether the processor can stably obtain the required data from the memory depends on whether the memory can provide enough bandwidth. For example, if the amount of data required by the processor from the memory in one second per unit time is 512Mb, the memory needs to provide at least 512Mb/s of bandwidth in order for the processor to access it stably.
由上可知,高速缓存在单位时长的缓存缺失数量与内存所需提供的带宽正相关,也即是高速缓存的缓存缺失数量越大,内存所需提供的带宽也就越大,而当高速缓存的缓存缺失数量越小,内存所需提供的带宽也就越小。因此,可根据高速缓存在单位时长内的缓存缺失数量获取到内存所需提供的带宽,将处理器访问内存所需的带宽记为目标带宽。It can be seen from the above that the number of cache misses per unit time of the cache is positively related to the bandwidth required by the memory, that is, the larger the number of cache misses in the cache, the greater the bandwidth required by the memory, and when the cache The smaller the number of cache misses, the less bandwidth the memory needs to provide. Therefore, the bandwidth required by the memory can be obtained according to the number of cache misses in the cache per unit time, and the bandwidth required by the processor to access the memory is recorded as the target bandwidth.
在130中,将内存的带宽调整为目标带宽。At 130, the bandwidth of the memory is adjusted to the target bandwidth.
根据以上相关描述,可以理解的是,内存提供目标带宽即可供处理器稳定的访问,也即是说,当内存所提供的带宽小于目标带宽时,内存无法确保处理器的稳定访问,而当内存所提供的带宽大于目标带宽时,内存提供的带宽将有所浪费。因此,本申请实施例中,在根据高速缓存在单位时长内的缓存缺失数量获取到处理器访问内存所需的目标带宽之后,即可将内存的带宽调整为前述目标带宽,由此来确保处理器对内存的稳定访问,同时也不会存在带宽的浪费。According to the above related descriptions, it can be understood that the memory provides the target bandwidth for the processor to access stably, that is to say, when the bandwidth provided by the memory is less than the target bandwidth, the memory cannot ensure the stable access of the processor, and when the bandwidth provided by the memory is less than the target bandwidth When the bandwidth provided by the memory is greater than the target bandwidth, the bandwidth provided by the memory will be wasted. Therefore, in the embodiment of the present application, after obtaining the target bandwidth required by the processor to access the memory according to the number of cache misses in the cache per unit time, the bandwidth of the memory can be adjusted to the aforementioned target bandwidth, thereby ensuring processing This ensures stable access to memory by the server without wasting bandwidth.
由上可知,本申请通过获取处理器中的高速缓存在单位时长内的缓存缺失数量,利用处理器缓存缺失时从内存获取数据的特性,进一步根据缓存缺失数量获取内存所需提供的目标带宽,该目标带宽即反映了处理器访问内存的数据量实际需求,从而将内存的带宽调整为目标带宽即可满足处理器对内存的访问需求。相较于相关技术,本申请并不在固定的几个带宽宽度中进行选择,而是去分析对内存的实际带宽需求,从而根据实际带宽需求对内存的带宽进行实时调整,以此来满足对内存访问性能的使用需求。同时,由于对内存调整后的带宽是与实际带宽需求所匹配的,不存在带宽的浪费,还能够避免功耗的浪费。It can be seen from the above that the present application obtains the number of cache misses of the cache in the processor per unit time, and utilizes the feature of acquiring data from the memory when the processor cache misses, and further obtains the target bandwidth required by the memory according to the number of cache misses, The target bandwidth reflects the actual demand for the amount of data the processor needs to access the memory, so that the memory bandwidth can be adjusted to the target bandwidth to meet the processor's demand for memory access. Compared with the related art, the present application does not select from several fixed bandwidth widths, but analyzes the actual bandwidth demand of the memory, so as to adjust the bandwidth of the memory in real time according to the actual bandwidth demand, so as to meet the needs of the memory. Access performance usage requirements. At the same time, since the bandwidth after adjusting the memory is matched with the actual bandwidth requirement, there is no waste of bandwidth, and waste of power consumption can also be avoided.
可选地,在一实施例中,在处理器包括性能监控单元时,获取处理器中的高速缓存在单位时长内的缓存缺失数量,包括:Optionally, in an embodiment, when the processor includes a performance monitoring unit, acquiring the number of cache misses of the cache in the processor within a unit duration, including:
从性能监控单元获取处理器中的高速缓存在单位时长内的缓存缺失数量。Obtains the number of cache misses per unit time from the cache in the processor from the performance monitoring unit.
应当说明的是,对于某些型号的处理器,提供有性能监控单元,性能监控单元为用于记录处理器访问信息的硬件模块,如图3所示。比如,ARM架构的处理器通常配置有性能监控单元,用于记录处理器在单位时长内访问的数据在高速缓存中的数量,以及访问的数据不在高速缓存中的数量等。It should be noted that, for some models of processors, a performance monitoring unit is provided, and the performance monitoring unit is a hardware module for recording processor access information, as shown in FIG. 3 . For example, a processor of the ARM architecture is usually configured with a performance monitoring unit, which is used to record the number of data accessed by the processor in the cache within a unit time, and the number of accessed data that is not in the cache.
因此,本申请实施例中,在处理器包括性能监控单元时,可以直接从该性能监控单元获取到处理器中的高速缓存在单位时长内的缓存缺失数量。Therefore, in this embodiment of the present application, when the processor includes a performance monitoring unit, the number of cache misses within a unit duration of the cache in the processor may be directly obtained from the performance monitoring unit.
可选地,在一实施例中,在处理器不包括性能监控单元时,获取处理器中的高速缓存在单位时长内的缓存缺失数量,包括:Optionally, in an embodiment, when the processor does not include a performance monitoring unit, acquiring the number of cache misses of the cache in the processor within a unit duration, including:
(1)获取处理器在单位时长内访问目标数据的访问时延,得到多个访问时延;(1) Obtain the access delay of the processor accessing the target data within a unit time, and obtain multiple access delays;
(2)根据多个访问时延预测处理器中的高速缓存在单位时长内的缓存缺失数量。(2) Predicting the number of cache misses within a unit time length of the cache in the processor according to multiple access delays.
应当说明的是,存储器是分层次的,离处理器越近的存储器,访问速度越快,每字节的成本也越高,同时容量也因此越小。寄存器离CPU最近,访问速度最快,其次是高速缓存(高速缓存也分层级,比如一级缓存、二级缓存、三级缓存等),再次是主存(即内存)。通常的,处理器对一级缓存的访问时延在5-10纳秒,处理器对二级缓存的访问时延在40-60纳秒,处理器对内存的访问时延在100-150纳秒。因此,利用处理器访问数据所需的访问时延即可大致判断出处理器是访问的内存,还是访问的高速缓存,进而可以预测出高速缓存的缓存缺失数量。It should be noted that the memory is hierarchical. The closer the memory is to the processor, the faster the access speed, the higher the cost per byte, and the smaller the capacity. The register is closest to the CPU and has the fastest access speed, followed by the cache (the cache is also hierarchical, such as the first level cache, the second level cache, the third level cache, etc.), and then the main memory (ie memory). Generally, the access latency of the processor to the first level cache is 5-10 nanoseconds, the access delay of the processor to the second level cache is 40-60 nanoseconds, and the access delay of the processor to the memory is 100-150 nanoseconds second. Therefore, the access delay required by the processor to access data can roughly determine whether the processor is accessing the memory or the cache, and then the number of cache misses in the cache can be predicted.
其中,在处理器不包括性能监控单元时,也就无法直接从性能监控单元获取到高速缓存在单位时长内的缓存缺失数量,因此,在本申请实施例中,对处理器访问目标数据时所花费的访问时延进行记录,其中,处理器每次访问的目标数据可以相同,也可以不同。相应的,在获取处理器中的高速缓存在单位时长内的缓存缺失数量时,可以获取到单位时长内记录的处理器访问目标数据的访问时延,得到多个访问时延。比如,在单位时长1秒内,记录了处理器10000次对目标数据的访问时延,相应的,将获取到10000个访问时延。Wherein, when the processor does not include the performance monitoring unit, the number of cache misses in the cache per unit time cannot be directly obtained from the performance monitoring unit. Therefore, in the embodiment of the present application, when the processor accesses the target data, the The spent access delay is recorded, wherein the target data accessed by the processor each time may be the same or different. Correspondingly, when acquiring the number of cache misses in the cache of the processor within a unit time, the access delay of the processor accessing the target data recorded in the unit time can be obtained, and multiple access delays can be obtained. For example, in a unit duration of 1 second, 10,000 access delays of the processor to the target data are recorded, and correspondingly, 10,000 access delays will be obtained.
基于以上相关描述,访问时延长短能够在一定程度上反映处理器的所访问的目标数据位于高速缓存中,还是位于内存中,因此,本申请实施例预设配置一用于判定目标数据位于高速缓存还是内存中的时延阈值,记为预设时延阈值,可由本领域普通技术人员根据高速缓存以及内存的实际读写性能进行配置,此处不对预设时延阈值的取值作具体限制。Based on the above related descriptions, the lengthening of the access time can reflect to a certain extent that the target data accessed by the processor is located in the cache or in the memory. Therefore, in the embodiment of the present application, the default configuration 1 is used to determine whether the target data is located in the cache. The cache is also the delay threshold in the memory, which is recorded as the preset delay threshold, which can be configured by those of ordinary skill in the art according to the actual read and write performance of the cache and memory. The value of the preset delay threshold is not specifically limited here. .
相应的,在获取到单位时长内所记录的多个访问时延后,可进一步确定出多个访问时延中大于或等于预设时延阈值的访问时延的数量,将该数量设为高速缓存在单位时长内的缓存缺失数量。比如,共获取到单位时长内记录的10000个访问时延,若其中2000个访问时延大于或等于预设时延阈值,则可确定高速缓存在单位时长内的缓存缺失数量为2000。Correspondingly, after obtaining the multiple access delays recorded in the unit time, the number of access delays greater than or equal to the preset delay threshold among the multiple access delays can be further determined, and the number is set as the high speed. The number of cache misses cached per unit duration. For example, a total of 10,000 access delays recorded in a unit duration are obtained. If 2,000 access delays are greater than or equal to the preset delay threshold, it can be determined that the number of cache misses in the cache per unit duration is 2,000.
可选地,在一实施例中,将内存的带宽调整为目标带宽,包括:Optionally, in an embodiment, adjusting the bandwidth of the memory to the target bandwidth includes:
(1)根据带宽和时钟频率的对应关系,获取内存提供目标带宽所需的目标时钟频率;(1) According to the corresponding relationship between bandwidth and clock frequency, obtain the target clock frequency required by the memory to provide the target bandwidth;
(2)将内存的时钟频率调整至目标时钟频率,以将内存的带宽调整为目标带宽。(2) Adjust the clock frequency of the memory to the target clock frequency to adjust the bandwidth of the memory to the target bandwidth.
应当说明的是,内存所能提供的带宽与其时钟频率存在如下对应关系:It should be noted that the bandwidth provided by the memory has the following correspondence with its clock frequency:
带宽=时钟频率×总线位数×倍增系数/8;Bandwidth=clock frequency×bus bits×multiplication factor/8;
以DDR400内存为例,它的运行频率为200MHz,总线位数为64bit,由于上升沿和下降沿都传输数据,因此倍增系数为2,此时带宽为:200×64×2/8=3.2GB/s。Taking DDR400 memory as an example, its operating frequency is 200MHz and the number of bus bits is 64bit. Since data is transmitted on both the rising and falling edges, the multiplication factor is 2, and the bandwidth is: 200×64×2/8=3.2GB /s.
其中,内存的总线位数和倍增系数是固定的,在内存的硬件电路确定时,其总线位数以及倍增系数相应确定。换言之,通过改变内存运行的时钟频率,即可达到改变内存所提供带宽的目的。Among them, the number of bits of the bus and the multiplication factor of the memory are fixed. When the hardware circuit of the memory is determined, the number of bits of the bus and the multiplication factor of the memory are determined accordingly. In other words, by changing the clock frequency at which the memory runs, you can change the bandwidth provided by the memory.
相应的,在本申请实施例中,在将内存的带宽调整为目标带宽时,可以根据以上带宽和时钟频率的对应关系,获取到对应前述目标带宽的时钟频率,记为内存提供目标带宽所需的目标带宽。之后,将内存运行的时钟频率调整为目标时钟频率,即可将内存所提供的带宽调整为目标带宽。Correspondingly, in the embodiment of the present application, when the bandwidth of the memory is adjusted to the target bandwidth, the clock frequency corresponding to the aforementioned target bandwidth can be obtained according to the corresponding relationship between the above bandwidth and the clock frequency, which is recorded as the memory required to provide the target bandwidth. target bandwidth. After that, adjusting the clock frequency of the memory operation to the target clock frequency, the bandwidth provided by the memory can be adjusted to the target bandwidth.
可选地,在一实施例中,将内存的时钟频率调整至目标时钟频率之后,还包括:Optionally, in an embodiment, after adjusting the clock frequency of the memory to the target clock frequency, the method further includes:
根据预设的时钟频率和工作电压的对应关系,将内存的工作电压调整为对应目标时钟频率的目标工作电压。According to the preset corresponding relationship between the clock frequency and the working voltage, the working voltage of the memory is adjusted to the target working voltage corresponding to the target clock frequency.
应当说明的是,内存是否能够稳定的工作在一时钟频率,取决于是否向内存提供一对应的工作电压,这与内存自身的硬件电路相关。It should be noted that whether the memory can work stably at a clock frequency depends on whether a corresponding working voltage is provided to the memory, which is related to the hardware circuit of the memory itself.
因此,对于一内存,可以预先标定其在不同时钟频率稳定工作所需的工作电压,由此得到预设的时钟频率和工作电压的对应关系。Therefore, for a memory, the working voltage required for stable operation at different clock frequencies can be pre-calibrated, thereby obtaining the preset corresponding relationship between the clock frequency and the working voltage.
本申请实施例中,为了确保内存能够稳定的工作在调整后的目标带宽,还根据预设的时钟频率和工作电压的对应关系,确定对应于前述的目标时钟频率的工作电压,记为目标电压。然后,将内存的工作电压调整为对应目标时钟频率的目标工作电压。In the embodiment of the present application, in order to ensure that the memory can stably work at the adjusted target bandwidth, the working voltage corresponding to the aforementioned target clock frequency is also determined according to the preset corresponding relationship between the clock frequency and the working voltage, which is recorded as the target voltage . Then, the working voltage of the memory is adjusted to the target working voltage corresponding to the target clock frequency.
可选地,在一实施例中,根据缓存缺失数量获取内存所需提供的目标带宽,包括:Optionally, in an embodiment, obtaining the target bandwidth required to be provided by the memory according to the number of cache misses includes:
(1)根据缓存缺失数量以及高速缓存的缓存行的数据量,获取处理器在单位时长内访问内存的所需的数据带宽;(1) According to the number of cache misses and the data volume of cache lines in the cache, obtain the required data bandwidth for the processor to access the memory within a unit time;
(2)获取高速缓存在单位时长内执行清理操作所需的清理带宽;(2) Obtain the cleaning bandwidth required for the cache to perform the cleaning operation within a unit time;
(3)根据数据带宽以及清理带宽获取前述目标带宽。(3) Obtain the aforementioned target bandwidth according to the data bandwidth and the cleaning bandwidth.
其中,清理操作是指:对于高速缓存中脏的(也即被改写过的)缓存行数据,将其强制写到内存中,并把缓存行中的脏位清零。The cleaning operation refers to: for the dirty (that is, overwritten) cache line data in the cache, forcibly writing it into the memory, and clearing the dirty bit in the cache line.
相应的,本申请实施例中,在根据缓存缺失数量获取内存所需提供的目标带宽时,可以根据缓存缺失数量以及高速缓存的缓存行的数据量,获取处理在单位时长内访问内存所需的带宽,记为数据带宽。应当说明的是,处理器每次从内存中读取数据都是按照缓存行的数据量来获取的。Correspondingly, in the embodiment of the present application, when obtaining the target bandwidth required by the memory according to the number of cache misses, the required bandwidth for accessing the memory within a unit time can be obtained according to the number of cache misses and the data volume of the cache line in the cache. Bandwidth, denoted as data bandwidth. It should be noted that each time the processor reads data from the memory, the data is obtained according to the data amount of the cache line.
比如,高速缓存的每一缓存行的数据量是32字节,若高速缓存在单位时长1秒内的缓存缺失数量为5000,那么处理器在单位时长1秒内访问内存的数据量为5000*32=160000(字节),相应的,处理器在单位时长1秒内访问内存所需的数据带宽为160000字节/秒。For example, the data volume of each cache line in the cache is 32 bytes. If the number of cache misses in the cache per unit duration is 5000, then the amount of data accessed by the processor in the unit duration 1 second is 5000* 32=160000 (bytes), correspondingly, the data bandwidth required by the processor to access the memory within 1 second per unit time is 160000 bytes/second.
如上所述,除了处理器对内存的正常访问需要占用带宽,在对高速缓存执行清理操作时需将高速缓存中相应的数据写到内存中,会对内存进行写操作,也会占用内存的带宽,因此,还获取高速缓存单元在单位时长内执行清理操作所需的清理带宽。As mentioned above, in addition to the normal access of the processor to the memory that requires bandwidth, when the cache is cleaned up, the corresponding data in the cache needs to be written to the memory, and the write operation to the memory will also occupy the bandwidth of the memory. , therefore, also obtains the cleaning bandwidth required by the cache unit to perform the cleaning operation within a unit time.
在获取到以上数据带宽以及清理带宽之后,即可根据前述数据带宽以及清理带宽获取到内存所需提供的目标带宽。比如,可以直接计算前述数据带宽以及清理带宽的带宽和值,作为内存所需提供的目标带宽。After the above data bandwidth and cleaning bandwidth are obtained, the target bandwidth required by the memory can be obtained according to the foregoing data bandwidth and cleaning bandwidth. For example, the bandwidth and value of the aforementioned data bandwidth and cleanup bandwidth can be directly calculated as the target bandwidth that the memory needs to provide.
可选地,在一实施例中,根据数据带宽、第一操作带宽以及第二操作带宽获取目标带宽,包括:Optionally, in an embodiment, acquiring the target bandwidth according to the data bandwidth, the first operating bandwidth, and the second operating bandwidth includes:
(1)计算数据带宽和清理带宽的和值,设为候选带宽;(1) Calculate the sum of data bandwidth and cleanup bandwidth and set it as a candidate bandwidth;
(2)获取处理器运行的前台应用的应用类型,并根据预设的应用类型与修正系数的对应关系,确定对应前述应用类型的目标修正系数;(2) obtaining the application type of the foreground application run by the processor, and determining the target correction coefficient corresponding to the aforementioned application type according to the preset correspondence between the application type and the correction coefficient;
(3)根据目标修正系数对候选带宽进行修正,将修正后的候选带宽设为目标带宽。(3) Modify the candidate bandwidth according to the target correction coefficient, and set the corrected candidate bandwidth as the target bandwidth.
应当说明的是,处理器在运行不同类型的应用程序时,处理器对内存带宽需求的变化程度不同,比如,处理器在运行A类应用程序,处理器对内存带宽需求的变化程度较小,而当处理器在运行B类应用程序时,处理器对内存带宽需求的变化程度较大。基于此,本申请预先针对处理器运行不同类型应用程序时对内存带宽需求的变化程度进行统计,并相应分配修正系数。其中,以修正系数与变化程度正相关为约束,可由本领域普通技术人员根据实际需要进行修正系数的分配,由此形成应用类型与修正系数的对应关系。It should be noted that when the processor runs different types of applications, the processor's memory bandwidth requirements vary to a different degree. For example, when the processor is running a class A application, the processor's memory bandwidth requirements vary to a lesser extent. When the processor is running a class B application, the processor's memory bandwidth requirements vary to a greater extent. Based on this, the present application performs statistics on the degree of change of memory bandwidth requirements when the processor runs different types of application programs in advance, and allocates correction coefficients accordingly. Wherein, with the positive correlation between the correction coefficient and the degree of change as a constraint, a person of ordinary skill in the art can allocate the correction coefficient according to actual needs, thereby forming a corresponding relationship between the application type and the correction coefficient.
相应的,在根据数据带宽和清理带宽获取内存所需提供的目标带宽时,可以首先计算前述数据带宽与前述带宽的和值,将计算得到和值记为内存所需提供的候选带宽;然后,进一步获取处理器运行的前台应用的应用类型,并根据预设的应用类型与修正系数,确定对应前台应用的应用类型的修正系数,记为目标修正系数;最后,根据目标修正系数对候选带宽进行修正,可以表示为:Correspondingly, when obtaining the target bandwidth required to be provided by the memory according to the data bandwidth and the cleaning bandwidth, the sum of the aforementioned data bandwidth and the aforementioned bandwidth may be calculated first, and the calculated sum value may be recorded as the candidate bandwidth provided by the memory; then, Further obtain the application type of the foreground application run by the processor, and determine the correction coefficient corresponding to the application type of the foreground application according to the preset application type and correction coefficient, which is recorded as the target correction coefficient; correction, which can be expressed as:
W’=W*r;W'=W*r;
其中,W表示候选带宽,W’表示修正后的候选带宽,r表示目标修正系数。Among them, W represents the candidate bandwidth, W' represents the modified candidate bandwidth, and r represents the target correction coefficient.
如上,在完成对候选带宽的修正之后,将修正后的候选带宽设为内存所需提供的目标带宽。As above, after the modification of the candidate bandwidth is completed, the modified candidate bandwidth is set as the target bandwidth required to be provided by the memory.
图4本申请实施例提供的内存控制方法的另一流程示意图。以下以该内存控制方法的执行主体为电子设备中的处理器为例进行说明。如图4所示,本申请实施例提供的内存控制方法的流程可以如下:FIG. 4 is another schematic flowchart of a memory control method provided by an embodiment of the present application. The following description is given by taking an example where the execution body of the memory control method is a processor in an electronic device. As shown in FIG. 4 , the process of the memory control method provided by the embodiment of the present application may be as follows:
在210中,处理器从性能监控单元获取高速缓存在单位时长内的缓存缺失数量。In 210, the processor obtains, from the performance monitoring unit, the number of cache misses in the cache within a unit duration.
应当说明的是,请参照图3,处理器中通常配置有高速缓存,或称高速缓冲存储器,其作用是为了更好的利用局部性原理(包括时间局部性和空间局部性),即最近被处理器访问的内存中的数据,短期内处理器还要访问(时间局部性);被处理器访问的数据附近的其它数据,处理器短期内还要访问(空间局部性)。因此如果处理器将刚刚访问过的数据缓存在高速缓存中,那么下次访问时,处理器可以直接从高速缓存中获取,而无需再从内存中获取,从而使得处理器的访问速度可以得到数量级的提高。It should be noted that, referring to FIG. 3 , a cache, or cache memory, is usually configured in the processor, and its function is to make better use of the principle of locality (including temporal locality and spatial locality), that is, the most recent The data in the memory accessed by the processor will also be accessed by the processor in the short term (temporal locality); other data near the data accessed by the processor will also be accessed by the processor in the short term (spatial locality). Therefore, if the processor caches the data that has just been accessed in the cache, then the next time the processor accesses it, the processor can directly fetch it from the cache without having to fetch it from the memory, so that the access speed of the processor can be improved by an order of magnitude. improvement.
基于以上相关描述,当处理器要访问的数据在高速缓存中有缓存时,称为“命中”,而当处理器要访问的数据在高速缓存中未缓存时,称为“缺失”。基于此,本申请中首先获取处理器中的高速缓存在单位时长(该单位时长可由本领域普通技术人员根据实际需要取经验值,例如,可将单位时长配置为1秒)内的缓存缺失数量,也即是在单位时长内,处理器访问数据时,高速缓存中未缓存处理器所需访问数据的次数。比如,在单位时长1秒内,处理器访问高速缓存10000次,其中有5000次访问的数据是缓存于高速缓存中的,而另外5000次访问的数据未缓存于高速缓存中,需要从内存中读取,因此,可以得到高速缓存的缓存缺失数量为5000。Based on the above related descriptions, when the data to be accessed by the processor is cached in the cache, it is called a "hit", and when the data to be accessed by the processor is not cached in the cache, it is called a "miss". Based on this, in the present application, firstly, the cache misses in the cache in the processor in a unit duration (the unit duration can be obtained from an empirical value according to actual needs by those of ordinary skill in the art, for example, the unit duration can be configured as 1 second) The number of cache misses is obtained. , that is, the number of times that the processor needs to access data that is not cached in the cache when the processor accesses data within a unit time. For example, in a unit duration of 1 second, the processor accesses the cache 10,000 times, of which 5,000 access data is cached in the cache, while the other 5,000 access data is not cached in the cache, and needs to be accessed from the memory. Reads, therefore, can get a cache miss count of 5000.
应当说明的是,对于某些型号的处理器,提供有性能监控单元,性能监控单元为用于记录处理器访问信息的硬件模块,如图3所示。比如,ARM架构的处理器通常配置有性能监控单元,用于记录处理器在单位时长内访问的数据在高速缓存中的数量,以及访问的数据不在高速缓存中的数量等。It should be noted that, for some models of processors, a performance monitoring unit is provided, and the performance monitoring unit is a hardware module for recording processor access information, as shown in FIG. 3 . For example, a processor of the ARM architecture is usually configured with a performance monitoring unit, which is used to record the number of data accessed by the processor in the cache within a unit time, and the number of accessed data that is not in the cache.
因此,本申请实施例中,在处理器包括性能监控单元时,可以直接从该性能监控单元获取到处理器中的高速缓存在单位时长内的缓存缺失数量。Therefore, in this embodiment of the present application, when the processor includes a performance monitoring unit, the number of cache misses within a unit duration of the cache in the processor may be directly obtained from the performance monitoring unit.
在220中,处理器根据缓存缺失数量以及高速缓存的缓存行的数据量,获取处理器在单位时长内访问内存的所需的数据带宽。In 220, the processor obtains the data bandwidth required by the processor to access the memory within a unit time period according to the number of cache misses and the data amount of the cache line in the cache.
如上所述,可以理解的是,对于高速缓存中缺失的数据,处理器需要从内存中获取,而处理器是否能够稳定的从内存中获取到所需的数据,取决于内存是否能够提供足够的带宽。比如,处理器单位时长1秒内从内存所需的数据量为512Mb,则内存至少需要提供512Mb/s的带宽,才能供处理器稳定的访问。As mentioned above, it can be understood that for the data missing from the cache, the processor needs to obtain the required data from the memory, and whether the processor can stably obtain the required data from the memory depends on whether the memory can provide enough bandwidth. For example, if the amount of data required by the processor from the memory in one second per unit time is 512Mb, the memory needs to provide at least 512Mb/s of bandwidth in order for the processor to access it stably.
由上可知,高速缓存在单位时长的缓存缺失数量与内存所需提供的带宽正相关,也即是高速缓存的缓存缺失数量越大,内存所需提供的带宽也就越大,而当高速缓存的缓存缺失数量越小,内存所需提供的带宽也就越小。It can be seen from the above that the number of cache misses per unit time of the cache is positively related to the bandwidth required by the memory, that is, the larger the number of cache misses in the cache, the greater the bandwidth required by the memory, and when the cache The smaller the number of cache misses, the less bandwidth the memory needs to provide.
应当说明的是,除了正常的访问操作会占用内存的带宽之外,高速缓存执行清理操作时也会占用内存的带宽。因此,本申请实施例中,根据处理器的访问操作以及对高速缓存的清理操作来确定处理器所需提供的目标带宽。It should be noted that in addition to normal access operations that consume memory bandwidth, cache cleanup operations also consume memory bandwidth. Therefore, in this embodiment of the present application, the target bandwidth required to be provided by the processor is determined according to the access operation of the processor and the cleaning operation of the cache.
相应的,本申请实施例中,在根据缓存缺失数量获取内存所需提供的目标带宽时,可以根据缓存缺失数量以及高速缓存的缓存行的数据量,获取处理在单位时长内访问内存所需的带宽,记为数据带宽。应当说明的是,处理器每次从内存中读取数据都是按照缓存行的数据量来获取的。Correspondingly, in the embodiment of the present application, when obtaining the target bandwidth required by the memory according to the number of cache misses, the required bandwidth for accessing the memory within a unit time can be obtained according to the number of cache misses and the data volume of the cache line in the cache. Bandwidth, denoted as data bandwidth. It should be noted that each time the processor reads data from the memory, the data is obtained according to the data amount of the cache line.
比如,高速缓存的每一缓存行的数据量是32字节,若高速缓存在单位时长1秒内的缓存缺失数量为5000,那么处理器在单位时长1秒内访问内存的数据量为5000*32=160000(字节),相应的,处理器在单位时长1秒内访问内存所需的数据带宽为160000字节/秒。For example, the data volume of each cache line in the cache is 32 bytes. If the number of cache misses in the cache per unit duration is 5000, then the amount of data accessed by the processor in the unit duration 1 second is 5000* 32=160000 (bytes), correspondingly, the data bandwidth required by the processor to access the memory within 1 second per unit time is 160000 bytes/second.
在230中,处理器获取高速缓存在单位时长内执行清理操作所需的清理带宽。In 230, the processor obtains the flushing bandwidth required by the cache to perform the flushing operation per unit time.
如上所述,除了处理器对内存的正常访问需要占用带宽,在对高速缓存执行清理操作时也会占用内存的带宽,因此,还获取高速缓存单元在单位时长内执行清理操作所需的清理带宽。As mentioned above, in addition to the normal access of the processor to the memory that needs to occupy the bandwidth, the memory bandwidth is also occupied when the cache cleaning operation is performed. Therefore, the cleaning bandwidth required by the cache unit to perform the cleaning operation per unit time is also obtained. .
在240中,处理器计算数据带宽和清理带宽的和值,设为候选带宽。At 240, the processor calculates the sum of the data bandwidth and the cleaning bandwidth as a candidate bandwidth.
应当说明的是,处理器在运行不同类型的应用程序时,处理器对内存带宽需求的变化程度不同,比如,处理器在运行A类应用程序,处理器对内存带宽需求的变化程度较小,而当处理器在运行B类应用程序时,处理器对内存带宽需求的变化程度较大。基于此,本申请预先针对处理器运行不同类型应用程序时对内存带宽需求的变化程度进行统计,并相应分配修正系数。其中,以修正系数与变化程度正相关为约束,可由本领域普通技术人员根据实际需要进行修正系数的分配,由此形成应用类型与修正系数的对应关系。It should be noted that when the processor runs different types of applications, the processor's memory bandwidth requirements vary to a different degree. For example, when the processor is running a class A application, the processor's memory bandwidth requirements vary to a lesser extent. When the processor is running a class B application, the processor's memory bandwidth requirements vary to a greater extent. Based on this, the present application performs statistics on the degree of change of memory bandwidth requirements when the processor runs different types of application programs in advance, and allocates correction coefficients accordingly. Wherein, with the positive correlation between the correction coefficient and the degree of change as a constraint, a person of ordinary skill in the art can allocate the correction coefficient according to actual needs, thereby forming a corresponding relationship between the application type and the correction coefficient.
相应的,可以首先计算前述数据带宽与前述带宽的和值,将计算得到和值记为内存所需提供的候选带宽。Correspondingly, the sum of the foregoing data bandwidth and the foregoing bandwidth may be calculated first, and the calculated sum may be recorded as the candidate bandwidth required to be provided by the memory.
在250中,处理器获取自身运行的前台应用的应用类型,并根据预设的应用类型与修正系数的对应关系,确定对应应用类型的目标修正系数。In 250, the processor obtains the application type of the foreground application running by itself, and determines the target correction coefficient corresponding to the application type according to the preset correspondence between the application type and the correction coefficient.
其中,处理器进一步获取自身运行的前台应用的应用类型,并根据预设的应用类型与修正系数,确定对应前台应用的应用类型的修正系数,记为目标修正系数。The processor further acquires the application type of the foreground application running by itself, and determines the correction coefficient corresponding to the application type of the foreground application according to the preset application type and correction coefficient, which is recorded as the target correction coefficient.
在260中,处理器根据目标修正系数对候选带宽进行修正,将修正后的候选带宽设为目标带宽。In 260, the processor modifies the candidate bandwidth according to the target modification coefficient, and sets the modified candidate bandwidth as the target bandwidth.
根据目标修正系数对候选带宽进行修正,可以表示为:The candidate bandwidth is modified according to the target modification coefficient, which can be expressed as:
W’=W*r;W'=W*r;
其中,W表示候选带宽,W’表示修正后的候选带宽,r表示目标修正系数。Among them, W represents the candidate bandwidth, W' represents the modified candidate bandwidth, and r represents the target correction coefficient.
如上,在完成对候选带宽的修正之后,将修正后的候选带宽设为内存所需提供的目标带宽。As above, after the modification of the candidate bandwidth is completed, the modified candidate bandwidth is set as the target bandwidth required to be provided by the memory.
在270中,处理器根据带宽和时钟频率的对应关系,获取内存提供目标带宽所需的目标时钟频率,并将内存的时钟频率调整至目标时钟频率,以将内存的带宽调整为目标带宽。In 270, the processor obtains the target clock frequency required by the memory to provide the target bandwidth according to the corresponding relationship between the bandwidth and the clock frequency, and adjusts the clock frequency of the memory to the target clock frequency, so as to adjust the bandwidth of the memory to the target bandwidth.
应当说明的是,内存所能提供的带宽与其时钟频率存在如下对应关系:It should be noted that the bandwidth provided by the memory has the following correspondence with its clock frequency:
带宽=时钟频率×总线位数×倍增系数/8;Bandwidth=clock frequency×bus bits×multiplication factor/8;
以DDR400内存为例,它的运行频率为200MHz,总线位数为64bit,由于上升沿和下降沿都传输数据,因此倍增系数为2,此时带宽为:200×64×2/8=3.2GB/s。Taking DDR400 memory as an example, its operating frequency is 200MHz, and the number of bus bits is 64bit. Since data is transmitted on both the rising and falling edges, the multiplication factor is 2. At this time, the bandwidth is: 200×64×2/8=3.2GB /s.
其中,内存的总线位数和倍增系数是固定的,在内存的硬件电路确定时,其总线位数以及倍增系数相应确定。换言之,通过改变内存运行的时钟频率,即可达到改变内存所提供带宽的目的。Among them, the number of bus bits and the multiplication factor of the memory are fixed, and when the hardware circuit of the memory is determined, the number of bits of the bus and the multiplication factor are determined accordingly. In other words, by changing the clock frequency at which the memory runs, you can change the bandwidth provided by the memory.
相应的,在本申请实施例中,在将内存的带宽调整为目标带宽时,可以根据以上带宽和时钟频率的对应关系,获取到对应前述目标带宽的时钟频率,记为内存提供目标带宽所需的目标带宽。之后,将内存运行的时钟频率调整为目标时钟频率,即可将内存所提供的带宽调整为目标带宽。Correspondingly, in the embodiment of the present application, when the bandwidth of the memory is adjusted to the target bandwidth, the clock frequency corresponding to the aforementioned target bandwidth can be obtained according to the corresponding relationship between the above bandwidth and the clock frequency, which is recorded as the memory required to provide the target bandwidth. target bandwidth. After that, adjust the clock frequency of the memory operation to the target clock frequency, and the bandwidth provided by the memory can be adjusted to the target bandwidth.
在280中,处理器根据预设的时钟频率和工作电压的对应关系,将内存的工作电压调整为对应目标时钟频率的目标工作电压。In 280, the processor adjusts the operating voltage of the memory to a target operating voltage corresponding to the target clock frequency according to the preset correspondence between the clock frequency and the operating voltage.
应当说明的是,内存是否能够稳定的工作在一时钟频率,取决于是否向内存提供一对应的工作电压,这与内存自身的硬件电路相关。It should be noted that whether the memory can work stably at a clock frequency depends on whether a corresponding working voltage is provided to the memory, which is related to the hardware circuit of the memory itself.
因此,对于一内存,可以预先标定其在不同时钟频率稳定工作所需的工作电压,由此得到预设的时钟频率和工作电压的对应关系。Therefore, for a memory, the working voltage required for stable operation at different clock frequencies can be pre-calibrated, thereby obtaining the preset corresponding relationship between the clock frequency and the working voltage.
本申请实施例中,为了确保内存能够稳定的工作在调整后的目标带宽,还根据预设的时钟频率和工作电压的对应关系,确定对应于前述的目标时钟频率的工作电压,记为目标电压。然后,将内存的工作电压调整为对应目标时钟频率的目标工作电压。In the embodiment of the present application, in order to ensure that the memory can stably work at the adjusted target bandwidth, the working voltage corresponding to the aforementioned target clock frequency is also determined according to the preset corresponding relationship between the clock frequency and the working voltage, which is recorded as the target voltage . Then, the working voltage of the memory is adjusted to the target working voltage corresponding to the target clock frequency.
请参照图5,图5为本申请实施例提供的内存控制装置的结构示意图。该内存控制装置应用于本申请提供的电子设备。如图5所示,内存控制装置可以包括:Please refer to FIG. 5 , which is a schematic structural diagram of a memory control apparatus provided by an embodiment of the present application. The memory control device is applied to the electronic equipment provided in this application. As shown in Figure 5, the memory control device may include:
数量获取模块310,用于获取处理器中的高速缓存在单位时长内的缓存缺失数量;A quantity acquisition module 310, configured to acquire the cache miss quantity of the cache in the processor within a unit time length;
带宽获取模块320,用于根据缓存缺失数量获取内存所需提供的目标带宽;a bandwidth obtaining module 320, configured to obtain the target bandwidth required to be provided by the memory according to the number of cache misses;
带宽调整模块330,用于将内存的带宽调整为目标带宽。The bandwidth adjustment module 330 is configured to adjust the bandwidth of the memory to the target bandwidth.
可选地,在一实施例中,若处理器包括性能监控单元,则在获取处理器中的高速缓存在单位时长内的缓存缺失数量时,数量获取模块310用于:Optionally, in an embodiment, if the processor includes a performance monitoring unit, when acquiring the number of cache misses of the cache in the processor within a unit duration, the number acquiring module 310 is configured to:
从性能监控单元获取缓存缺失数量。Get the number of cache misses from the performance monitoring unit.
可选地,在一实施例中,若处理器不包括性能监控单元,则在获取处理器中的高速缓存在单位时长内的缓存缺失数量时,数量获取模块310用于:Optionally, in an embodiment, if the processor does not include a performance monitoring unit, when acquiring the number of cache misses of the cache in the processor within a unit duration, the number acquiring module 310 is configured to:
获取处理器在单位时长内访问目标数据的访问时延,得到多个访问时延;Obtain the access delay of the processor accessing the target data within a unit time, and obtain multiple access delays;
根据多个访问时延预测缓存缺失数量。Predict the number of cache misses based on multiple access latencies.
可选地,在一实施例中,在将内存的带宽调整为目标带宽时,带宽调整模块330用于:Optionally, in an embodiment, when adjusting the bandwidth of the memory to the target bandwidth, the bandwidth adjustment module 330 is configured to:
根据带宽和时钟频率的对应关系,获取内存提供目标带宽所需的目标时钟频率;According to the corresponding relationship between bandwidth and clock frequency, obtain the target clock frequency required by the memory to provide the target bandwidth;
将内存的时钟频率调整至目标时钟频率,以将内存的带宽调整为目标带宽。Adjust the clock frequency of the memory to the target clock frequency to adjust the bandwidth of the memory to the target bandwidth.
可选地,在一实施例中,在将内存的时钟频率调整至目标时钟频率之后,带宽调整模块330还用于:Optionally, in an embodiment, after adjusting the clock frequency of the memory to the target clock frequency, the bandwidth adjustment module 330 is further configured to:
根据预设的时钟频率和工作电压的对应关系,将内存的工作电压调整为对应目标时钟频率的目标工作电压。According to the preset corresponding relationship between the clock frequency and the working voltage, the working voltage of the memory is adjusted to the target working voltage corresponding to the target clock frequency.
可选地,在一实施例中,在根据缓存缺失数量获取内存所需提供的目标带宽时,带宽获取模块320用于:Optionally, in an embodiment, when acquiring the target bandwidth required to be provided by the memory according to the number of cache misses, the bandwidth acquiring module 320 is configured to:
根据缓存缺失数量以及高速缓存的缓存行的数据量,获取处理器在单位时长内访问内存的所需的数据带宽;According to the number of cache misses and the data volume of cache lines in the cache, obtain the data bandwidth required by the processor to access the memory in a unit time;
获取高速缓存在单位时长内执行清理操作所需的清理带宽;Obtain the cleaning bandwidth required for the cache to perform cleaning operations within a unit time;
根据数据带宽和清理带宽获取目标带宽。Get target bandwidth based on data bandwidth and cleaning bandwidth.
可选地,在一实施例中,在根据数据带宽和清理带宽获取目标带宽时,带宽获取模块320用于:Optionally, in an embodiment, when obtaining the target bandwidth according to the data bandwidth and the cleaning bandwidth, the bandwidth obtaining module 320 is configured to:
计算数据带宽和清理带宽的和值,设为候选带宽;Calculate the sum of data bandwidth and cleanup bandwidth and set it as a candidate bandwidth;
获取处理器运行的前台应用的应用类型,并根据预设的应用类型与修正系数的对应关系,确定对应应用类型的目标修正系数;Acquire the application type of the foreground application run by the processor, and determine the target correction coefficient corresponding to the application type according to the preset correspondence between the application type and the correction coefficient;
根据目标修正系数对候选带宽进行修正,将修正后的候选带宽设为目标带宽。The candidate bandwidth is corrected according to the target correction coefficient, and the corrected candidate bandwidth is set as the target bandwidth.
应当说明的是,本申请实施例提供的内存控制装置与上文实施例中的内存控制方法属于同一构思,内存控制装置可以运行内存控制方法实施例中提供的任一方法,其具体实现过程详见以上相关实施例,此处不再赘述。It should be noted that the memory control device provided by the embodiments of the present application and the memory control method in the above embodiments belong to the same concept, and the memory control device can execute any method provided in the memory control method embodiment, and the specific implementation process is detailed. See the above related embodiments, and details are not repeated here.
本申请实施例还提供一种存储介质,其上存储有计算机程序,当其存储的计算机程序被电子设备的处理器加载时执行如本申请实施例提供的内存控制方法中的步骤。其中,存储介质可以是磁碟、光盘、只读存储器(Read Only Memory,ROM)或者随机存取器(Random Access Memory,RAM)等。Embodiments of the present application further provide a storage medium on which a computer program is stored, and when the stored computer program is loaded by a processor of an electronic device, the steps in the memory control method provided by the embodiments of the present application are executed. The storage medium may be a magnetic disk, an optical disk, a read only memory (Read Only Memory, ROM), or a random access device (Random Access Memory, RAM), or the like.
本申请实施例还提供一种电子设备,请参照图6,电子设备包括处理器410和存储器420。An embodiment of the present application further provides an electronic device. Referring to FIG. 6 , the electronic device includes a
本申请实施例中的处理器是通用处理器410,比如ARM架构的处理器。The processor in this embodiment of the present application is a general-
存储器420中存储有计算机程序,其可以为高速随机存取存储器,还可以为非易失性存储器,比如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件等。A computer program is stored in the
内存430可以为任意类型的内存(也称主存),比DDR(Double Data Rate,双倍速率)内存。The memory 430 can be any type of memory (also called main memory), which is higher than DDR (Double Data Rate, double data rate) memory.
此外,存储器420还可以包括存储器控制器,以提供处理器410对存储器420的访问,处理器410通过加载存储器420中的计算机程序实现如下功能:In addition, the
获取处理器中的高速缓存在单位时长内的缓存缺失数量;Get the number of cache misses in the processor's cache per unit time;
根据缓存缺失数量获取内存430所需提供的目标带宽;The target bandwidth required to obtain the memory 430 according to the number of cache misses;
将内存430的带宽调整为目标带宽。Adjust the bandwidth of the memory 430 to the target bandwidth.
可选地,在一实施例中,若处理器包括性能监控单元,则在获取处理器中的高速缓存在单位时长内的缓存缺失数量时,处理器410用于执行:Optionally, in an embodiment, if the processor includes a performance monitoring unit, when acquiring the number of cache misses of the cache in the processor within a unit duration, the
从性能监控单元获取缓存缺失数量。Get the number of cache misses from the performance monitoring unit.
可选地,在一实施例中,若处理器不包括性能监控单元,则在获取处理器中的高速缓存在单位时长内的缓存缺失数量时,处理器410用于执行:Optionally, in an embodiment, if the processor does not include a performance monitoring unit, when acquiring the number of cache misses of the cache in the processor within a unit duration, the
获取处理器在单位时长内访问目标数据的访问时延,得到多个访问时延;Obtain the access delay of the processor accessing the target data within a unit time, and obtain multiple access delays;
根据多个访问时延预测缓存缺失数量。Predict the number of cache misses based on multiple access latencies.
可选地,在一实施例中,在将内存430的带宽调整为目标带宽时,处理器410用于执行:Optionally, in an embodiment, when adjusting the bandwidth of the memory 430 to the target bandwidth, the
根据带宽和时钟频率的对应关系,获取内存430提供目标带宽所需的目标时钟频率;According to the corresponding relationship between the bandwidth and the clock frequency, obtain the target clock frequency required by the memory 430 to provide the target bandwidth;
将内存430的时钟频率调整至目标时钟频率,以将内存430的带宽调整为目标带宽。The clock frequency of the memory 430 is adjusted to the target clock frequency to adjust the bandwidth of the memory 430 to the target bandwidth.
可选地,在一实施例中,在将内存430的时钟频率调整至目标时钟频率之后,处理器410还用于执行:Optionally, in an embodiment, after adjusting the clock frequency of the memory 430 to the target clock frequency, the
根据预设的时钟频率和工作电压的对应关系,将内存430的工作电压调整为对应目标时钟频率的目标工作电压。According to the preset corresponding relationship between the clock frequency and the working voltage, the working voltage of the memory 430 is adjusted to the target working voltage corresponding to the target clock frequency.
可选地,在一实施例中,在根据缓存缺失数量获取内存430所需提供的目标带宽时,处理器410用于执行:Optionally, in an embodiment, when acquiring the target bandwidth required to be provided by the memory 430 according to the number of cache misses, the
根据缓存缺失数量以及高速缓存的缓存行的数据量,获取处理器在单位时长内访问内存430的所需的数据带宽;Obtain the required data bandwidth for the processor to access the memory 430 within a unit time according to the number of cache misses and the data amount of the cache line in the cache;
获取高速缓存在单位时长内执行清理操作所需的清理带宽;Obtain the cleaning bandwidth required for the cache to perform cleaning operations within a unit time;
根据数据带宽和清理带宽获取目标带宽。Get target bandwidth based on data bandwidth and cleaning bandwidth.
可选地,在一实施例中,在根据数据带宽和清理带宽获取目标带宽时,处理器410用于执行:Optionally, in an embodiment, when acquiring the target bandwidth according to the data bandwidth and the cleaning bandwidth, the
计算数据带宽和清理带宽的和值,设为候选带宽;Calculate the sum of data bandwidth and cleanup bandwidth and set it as a candidate bandwidth;
获取处理器运行的前台应用的应用类型,并根据预设的应用类型与修正系数的对应关系,确定对应应用类型的目标修正系数;Acquire the application type of the foreground application run by the processor, and determine the target correction coefficient corresponding to the application type according to the preset correspondence between the application type and the correction coefficient;
根据目标修正系数对候选带宽进行修正,将修正后的候选带宽设为目标带宽。The candidate bandwidth is corrected according to the target correction coefficient, and the corrected candidate bandwidth is set as the target bandwidth.
应当说明的是,本申请实施例提供的电子设备与上文实施例中的内存控制方法属于同一构思,在电子设备上可以运行内存控制方法实施例中提供的任一方法,其具体实现过程详见以上实施例,此处不再赘述。It should be noted that the electronic device provided by the embodiment of the present application and the memory control method in the above embodiment belong to the same concept, and any method provided in the memory control method embodiment can be executed on the electronic device, and the specific implementation process is detailed. See the above embodiments, and details are not repeated here.
以上对本申请实施例所提供的一种内存控制方法、存储介质及电子设备进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。A memory control method, a storage medium, and an electronic device provided by the embodiments of the present application have been described in detail above. The principles and implementations of the present application are described with specific examples. The descriptions of the above embodiments are only used for Help to understand the method of the present application and its core idea; meanwhile, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation and application scope. In summary, the content of this specification does not It should be understood as a limitation of this application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011242674.4A CN114461546B (en) | 2020-11-09 | 2020-11-09 | Memory control method, memory control device, storage medium and electronic equipment |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202011242674.4A CN114461546B (en) | 2020-11-09 | 2020-11-09 | Memory control method, memory control device, storage medium and electronic equipment |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN114461546A true CN114461546A (en) | 2022-05-10 |
| CN114461546B CN114461546B (en) | 2025-08-12 |
Family
ID=81404374
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202011242674.4A Active CN114461546B (en) | 2020-11-09 | 2020-11-09 | Memory control method, memory control device, storage medium and electronic equipment |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114461546B (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN120336220A (en) * | 2025-06-19 | 2025-07-18 | 沐曦集成电路(上海)股份有限公司 | A bandwidth management system |
Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130044647A1 (en) * | 2010-06-17 | 2013-02-21 | Telefonaktiebolaget L M Ericsson (Publ) | Bandwidth extension in a multipoint conference unit |
| CN103218285A (en) * | 2013-03-25 | 2013-07-24 | 北京百度网讯科技有限公司 | Method and device for monitoring memory performance based on CPU (Central Processing Unit) register |
| CN104133789A (en) * | 2013-04-30 | 2014-11-05 | 三星电子株式会社 | Apparatus and method for adjusting memory bandwidth |
| US20180004670A1 (en) * | 2016-06-29 | 2018-01-04 | Oracle International Corporation | Prefetch bandwidth throttling by dynamically adjusting miss buffer prefetch-dropping thresholds |
| CN108241484A (en) * | 2016-12-26 | 2018-07-03 | 上海寒武纪信息科技有限公司 | Neural computing device and method based on high bandwidth memory |
| WO2018121118A1 (en) * | 2016-12-26 | 2018-07-05 | 上海寒武纪信息科技有限公司 | Calculating apparatus and method |
| CN109669882A (en) * | 2018-12-28 | 2019-04-23 | 贵州华芯通半导体技术有限公司 | Dynamic caching replacement method, device, system and the medium of bandwidth aware |
| CN109992458A (en) * | 2019-03-29 | 2019-07-09 | 苏州浪潮智能科技有限公司 | A kind of UPI bandwidth detection method, apparatus, equipment and readable storage medium storing program for executing |
| CN110389833A (en) * | 2019-06-28 | 2019-10-29 | 北京大学深圳研究生院 | Processor performance scheduling method and system |
| CN111258927A (en) * | 2019-11-13 | 2020-06-09 | 北京大学 | A Sampling-Based Prediction Method for the Missing Rate Curve of the Last-Level Cache of Application Programs |
-
2020
- 2020-11-09 CN CN202011242674.4A patent/CN114461546B/en active Active
Patent Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130044647A1 (en) * | 2010-06-17 | 2013-02-21 | Telefonaktiebolaget L M Ericsson (Publ) | Bandwidth extension in a multipoint conference unit |
| CN103218285A (en) * | 2013-03-25 | 2013-07-24 | 北京百度网讯科技有限公司 | Method and device for monitoring memory performance based on CPU (Central Processing Unit) register |
| CN104133789A (en) * | 2013-04-30 | 2014-11-05 | 三星电子株式会社 | Apparatus and method for adjusting memory bandwidth |
| US20180004670A1 (en) * | 2016-06-29 | 2018-01-04 | Oracle International Corporation | Prefetch bandwidth throttling by dynamically adjusting miss buffer prefetch-dropping thresholds |
| CN108241484A (en) * | 2016-12-26 | 2018-07-03 | 上海寒武纪信息科技有限公司 | Neural computing device and method based on high bandwidth memory |
| WO2018121118A1 (en) * | 2016-12-26 | 2018-07-05 | 上海寒武纪信息科技有限公司 | Calculating apparatus and method |
| CN109669882A (en) * | 2018-12-28 | 2019-04-23 | 贵州华芯通半导体技术有限公司 | Dynamic caching replacement method, device, system and the medium of bandwidth aware |
| CN109992458A (en) * | 2019-03-29 | 2019-07-09 | 苏州浪潮智能科技有限公司 | A kind of UPI bandwidth detection method, apparatus, equipment and readable storage medium storing program for executing |
| CN110389833A (en) * | 2019-06-28 | 2019-10-29 | 北京大学深圳研究生院 | Processor performance scheduling method and system |
| CN111258927A (en) * | 2019-11-13 | 2020-06-09 | 北京大学 | A Sampling-Based Prediction Method for the Missing Rate Curve of the Last-Level Cache of Application Programs |
Non-Patent Citations (3)
| Title |
|---|
| 张斯伟;: "多处理器系统内存读写效率研究", 电脑知识与技术, no. 36, 25 December 2012 (2012-12-25) * |
| 曹蕾;余丽红;李智;: "一种基于GPU的宽带数字信号多路下变频器的高效实现", 电子器件, no. 02, 6 May 2019 (2019-05-06) * |
| 沈秀红;赵朝君;孟建熠;项晓燕;: "基于基地址寄存器映射的数据缓存研究", 计算机工程, no. 05, 15 May 2013 (2013-05-15) * |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN120336220A (en) * | 2025-06-19 | 2025-07-18 | 沐曦集成电路(上海)股份有限公司 | A bandwidth management system |
| CN120336220B (en) * | 2025-06-19 | 2025-08-15 | 沐曦集成电路(上海)股份有限公司 | Bandwidth management system |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114461546B (en) | 2025-08-12 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11500797B2 (en) | Computer memory expansion device and method of operation | |
| KR102500661B1 (en) | Cost-optimized single-level cell-mode non-volatile memory for multi-level cell-mode non-volatile memory | |
| KR101419615B1 (en) | Read and write aware cache | |
| US9009414B2 (en) | Prefetch address hit prediction to reduce memory access latency | |
| KR102553539B1 (en) | A mechanism for adapting garbage collection resource allocation on solid-state drives. | |
| JP2018181336A (en) | Method for reducing read-modify-write overhead in hybrid DRAM / NAND memory and memory cache controller therefor | |
| US20220350484A1 (en) | Machine learning to improve caching efficiency in a storage system | |
| CN103999057B (en) | Metadata Management and Support for Phase Change Memory (PCMS) with Switches | |
| US10691613B1 (en) | Caching algorithms for multiple caches | |
| JP6711121B2 (en) | Information processing apparatus, cache memory control method, and cache memory control program | |
| CN107430554B (en) | Improving storage cache performance by using compressibility of data as a criterion for cache insertion | |
| US20050060533A1 (en) | Method, device, software and apparatus for adjusting a system parameter value, such as a page closing time | |
| US11138104B2 (en) | Selection of mass storage device streams for garbage collection based on logical saturation | |
| US10496550B2 (en) | Multi-port shared cache apparatus | |
| US10120806B2 (en) | Multi-level system memory with near memory scrubbing based on predicted far memory idle time | |
| CN111984188A (en) | Hybrid memory data management method, device and storage medium | |
| US20190042153A1 (en) | Mass storage device capable of fine grained read and/or write operations | |
| WO2025208699A1 (en) | Data prefetching method and apparatus, and electronic device, electronic apparatus and medium | |
| US10152410B2 (en) | Magnetoresistive random-access memory cache write management | |
| CN114461546A (en) | Memory control method and device, storage medium and electronic equipment | |
| US11645209B2 (en) | Method of cache prefetching that increases the hit rate of a next faster cache | |
| CN102779017B (en) | The control method of data buffer area in a kind of solid-state disk | |
| CN114168495A (en) | Enhanced read-ahead capabilities for storage devices | |
| US9158697B2 (en) | Method for cleaning cache of processor and associated processor | |
| US20250110887A1 (en) | Preemptive Flushing of Processing-in-Memory Data Structures |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| TA01 | Transfer of patent application right |
Effective date of registration: 20241021 Address after: 6th Floor, No.1 Chongqing Road, Banqiao District, Xinbei City, Taiwan, China, China Applicant after: Weiguang Co.,Ltd. Country or region after: Samoa Address before: Room 01, 8th floor, No.1 Lane 61, shengxia Road, China (Shanghai) pilot Free Trade Zone, Pudong New Area, Shanghai, 200120 Applicant before: Zheku Technology (Shanghai) Co.,Ltd. Country or region before: China |
|
| TA01 | Transfer of patent application right | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |