Function stack maintenance method, function stack access method and electronic hardware
By setting up a hot stack storage area inside the CPU and dynamically adjusting the data storage area, the problem of low access efficiency for hot data in the CPU function stack is solved, enabling fast access to hot data and performance improvement.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANGHAI SMARTLOGIC TECHNOLOGY LTD
- Filing Date
- 2026-02-12
- Publication Date
- 2026-05-12
AI Technical Summary
In existing technologies, hot data access efficiency of the CPU function stack is low, leading to issues such as cache line misses and performance degradation.
A hot stack storage area is set up inside the CPU, and hot stack space is allocated to store hot data. Cold data is moved to the cold stack storage area in DDR. The data ratio of the storage area is adjusted through burst transmission to avoid data crowding out the DataCache.
It improves the speed of random memory access for hot data, reduces cache line misses, and enhances CPU performance.
Smart Images

Figure CN122019016A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method for maintaining a function stack, a method for accessing a function stack, and electronic hardware. Background Technology
[0002] Currently, the function stack of a CPU (Central Processing Unit) uses a software stack, which means that a memory region is allocated and managed on DDR (Double Data Rate Synchronous Dynamic Random Access Memory) by the program.
[0003] Typically, the top of the software stack stores frequently accessed "hot data," such as input parameters and local variables of the currently running function. The bottom of the software stack typically stores local variables of the top-level calling function of the currently running function, which are rarely accessed and are therefore considered "cold data."
[0004] Even with modern caching structures like DataCache, frequently accessed hot data at the top of the software stack often suffers from low memory access efficiency and cache line misses. Summary of the Invention
[0005] To address one of the aforementioned technical deficiencies, this application provides a method for maintaining a function stack, a method for accessing a function stack, and electronic hardware.
[0006] The first aspect of this application provides a method for maintaining a function stack, the method comprising: In the function preamble, when a stack space allocation statement is executed, hot stack space is allocated; the hot stack space is located in the hot stack storage area inside the central processing unit (CPU). In subsequent parts of the function, when a stack space deallocation statement is executed, the allocated hot stack space is released.
[0007] Optionally, the page table entry or physical memory attribute (PMA) corresponding to the hot stack storage region is configured to be uncacheable.
[0008] Optionally, in the function preamble, after allocating hot stack space when executing the stack space allocation statement, the following may also be included: If the amount of data stored in the hot stack storage area exceeds the first proportion threshold, the data at the bottom of the hot stack storage area will be moved to the cold stack storage area through burst transmission.
[0009] Optionally, in the subsequent part of the function, after the stack space is released when the stack space deallocation statement is executed, the function may also include: If the amount of data stored in the hot stack storage area is less than the second proportion threshold, the data at the top of the cold stack storage area will be moved to the hot stack storage area through burst transmission.
[0010] Optionally, the cold stack storage area is located in Double Data Rate Synchronous Dynamic Random Access Memory (DDR).
[0011] Optionally, the page table entries or PMA corresponding to the cold stack storage area are configured as cacheable.
[0012] Optionally, the amount of data moved each time is determined based on the CPU and DDR.
[0013] Optionally, the method further includes: Record the data movement process of functions that have been executed; When the CPU executes a function call statement, it reserves hot stack space in the hot stack memory area according to the data movement of the called function, or loads the data to be accessed in the hot stack memory area.
[0014] In a second aspect, this application provides a method for accessing a function stack, characterized in that the function stack is maintained by the function stack maintenance method described in the first aspect above; The methods for accessing the function stack include: When the memory access data of a function is data of another function, the address of the memory access data is arbitrated. If the memory access data address is within the hot stack storage area, then the memory access data within the hot stack storage area is accessed directly; If the memory access data address is within the cold stack storage area, the memory access data is accessed through the data cache.
[0015] A third aspect of this application provides electronic hardware, which includes: a processor; A processor for performing the method as described in the first aspect above, or for performing the method as described in the second aspect above.
[0016] This application provides a method for maintaining a function stack, a method for accessing a function stack, and electronic hardware. The method includes: allocating hot stack space during the pre-function execution when a stack space allocation statement is executed; wherein the hot stack space is located within the hot stack storage area inside the CPU; and releasing the allocated hot stack space during the subsequent function execution when a stack space release statement is executed. The method provided by this application improves the random access speed of hot data by utilizing the hot stack storage area inside the CPU. Attached Figure Description
[0017] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 This is a schematic diagram of the structure of an assembly function in the prior art; Figure 2 This is a schematic diagram of a type of storage in the prior art; Figure 3 This is a schematic diagram of an assembly function call and stack space allocation in the prior art; Figure 4 A flowchart illustrating a method for maintaining a function stack provided in an embodiment of this application; Figure 5 A schematic diagram of storage provided for an embodiment of this application; Figure 6 This is a schematic diagram illustrating data transfer between a hot stack storage area and a cold stack storage area, provided as an embodiment of this application. Detailed Implementation
[0018] To make the technical solutions and advantages of the embodiments of this application clearer, the exemplary embodiments of this application will be described in further detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not an exhaustive list of all embodiments. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be combined with each other.
[0019] In the process of developing this application, the inventors discovered that, taking the x86 architecture as an example, the structure of a typical assembly function is as follows: Figure 1 As shown. At the beginning of the function, the `sub esp` statement allocates N bytes of stack space for the current function. During the initial part of the function, multiple `push` statements sequentially store their corresponding registers into the newly allocated stack space, with the stack address automatically incrementing with each push. In the function return section, multiple `pop` statements restore their corresponding registers from the stack. Before the function returns, the `mov esp` statement releases the stack space allocated by the current function by restoring the value of the `esp` register.
[0020] In existing implementations, each push corresponds to a store of data in DDR (Double Data Rate Synchronous Dynamic Random Access Memory), and each pop corresponds to a load of data in DDR. Figure 2As shown in the existing technology, every read and write operation of data from DDR has to go through the DataCache, which has a high probability of CacheLineMiss. In particular, there will definitely be a Miss when the data is read for the first time. Then the CPU moves the data from DDR to the DataCache before it can be read and written quickly.
[0021] Taking the function call process A->B->C as an example, function A calls function B, and during the execution of function B, it calls function C. The function call flow and the process of allocating stack space are as follows: Figure 3 As shown, function A calls function B by executing the `call B` statement, and function B calls function C by executing the `call C` statement. The `ret` statement in each function indicates that the function returns. When a function returns (`ret`), its stack space is released.
[0022] It's important to note that the stack space allocation explanation above only applies to the call chain A->B->C. If the call chain is D->E->C, then during the execution of function C, stack space will be allocated for the functions FuncD, FuncE, and FuncC.
[0023] Assuming the current function call chain is A->B->C, the stack space of FuncC is at the top, and FuncA is at the bottom. In the function stack, data closer to the top ("Hot") is considered hotter, and data closer to the bottom ("Colder") is considered colder. Hot data indicates more frequent memory access. Because function C is currently running, the data on FuncC's stack, as local variables, will be frequently accessed, hence it's hotter. The data on FuncA's stack will only be frequently accessed after function C and function B return, returning to the FuncA function body; therefore, FuncA's stack data is colder.
[0024] like Figure 2 As shown, in existing technologies, variables in the function stack are stored in the Stack area of DDR, and these variables are cached by a specific cache line in the DataCache. In existing solutions, several typical situations can lead to the same cache line being repeatedly missed and reloaded, resulting in a significant increase in CPU data read time and a sharp decline in performance. These typical situations include: 1. False Sharing: Multiple threads / cores frequently write to different variables, but these variables happen to fall in the same cache line.
[0025] 2. True Sharing: When the same variable (or adjacent variables) is frequently modified by multiple cores, this is true sharing, which can lead to repeated cache line misses and bus storms.
[0026] 3. When the CPU reads a variable from the stack for the first time, a cache line miss will also occur, resulting in high data access latency and performance degradation.
[0027] To address the aforementioned problems, this application provides a method and electronic hardware for maintaining a function stack. The method includes: allocating hot stack space during the pre-function execution when a stack space allocation statement is executed; wherein the hot stack space is located within the hot stack storage area inside the CPU; and releasing the allocated hot stack space during the subsequent function execution when a stack space release statement is executed. The method provided in this application improves the random access speed of hot data by utilizing the hot stack storage area inside the CPU.
[0028] See Figure 4 This embodiment provides a method for maintaining a function stack, and the implementation process of this method is as follows: 401. In the preamble of a function, when a stack space allocation statement is executed, hot stack space is allocated.
[0029] The hot stack space is located within the hot stack storage area inside the CPU (Central Processing Unit).
[0030] Page table entries or PMAs (Physical Memory Attributes) corresponding to the hot stack storage area are configured as Uncacheable to prevent data in the hot stack storage area from crowding out space in the DataCache, thereby improving the capacity and utilization of the DataCache.
[0031] PMA defines the basic characteristics of a memory region, such as whether it can be cached, whether it is an I / O region, and access alignment requirements. Uncacheable means that this memory region completely bypasses the CPU cache, and all read and write operations interact directly with main memory.
[0032] Furthermore, during the pre-function invocation, when stack space allocation statements are executed, after allocating hot stack space, the CPU can dynamically adjust the length of data stored in the hot stack storage area without requiring assembly code intervention. For example, if the amount of data stored in the hot stack storage area exceeds a first proportion threshold, the data at the bottom of the hot stack storage area is moved to the cold stack storage area via burst transfer, thus reserving some allocated space for the hot stack storage area.
[0033] The cold stack storage area is located in DDR (Double Data Rate Synchronous Dynamic Random Access Memory).
[0034] The page table entries or PMA corresponding to the cold stack storage area are configured as cacheable, meaning that data access in the cold stack storage area can be cached and accelerated through DataCache.
[0035] Since cold data is located at the bottom of the hot stack storage area, when the proportion of data stored in the hot stack storage area exceeds the first proportion threshold, the data at the bottom of the hot stack storage area is moved to the cold stack storage area through burst transmission. In this way, the data in the traditional function stack is divided into cold data (CodeData) and hot data (Hot Data) according to their position. Cold data is stored in the cold stack storage area in DDR, and hot data is stored in the hot stack cache area inside the CPU.
[0036] Taking a first ratio threshold of 2 / 3 as an example, if the amount of data stored in the hot stack storage area accounts for more than 2 / 3 of the total amount of data in the hot stack storage area, then some data at the bottom of the hot stack storage area will be moved to the cold stack storage area through a burst transfer.
[0037] If some data consists of 512 bytes, that is, if the amount of data stored in the hot stack storage area accounts for more than 2 / 3 of the total amount of the hot stack storage area, it is considered that the hot stack storage area is about to be full. At this time, the CPU can move the 512 bytes of data at the bottom of the hot stack storage area to the cold stack storage area through a burst transfer, thereby automatically increasing the capacity of the hot stack storage area.
[0038] In a burst transfer, the CPU provides a starting address, and memory can continuously output the entire following long string of data (64 bytes or more). The characteristic of this transfer is that a single command (Address) is given, and multiple data entries are retrieved.
[0039] In the specific implementation, step 401 is executed in the function prequel. When step 401 is executed, the hot stack space of the function is quickly allocated in the hot stack storage area, and the data in the register is quickly pushed to the storage area corresponding to the hot stack space. If the data stored in the hot stack storage area exceeds 2 / 3, the dynamic adjustment of the hot stack storage area is automatically triggered.
[0040] 402. In the subsequent function, when the stack space release statement is executed, the allocated hot stack space is released.
[0041] Furthermore, when executing a stack space release statement, after releasing the allocated hot stack space, the CPU can dynamically adjust the length of data stored in the hot stack memory area without requiring assembly code intervention. For example, if the amount of data stored in the hot stack memory area is less than a second threshold, the topmost data in the cold stack memory area is moved to the hot stack memory area via a burst transfer, thereby loading the data to be read or written into the hot stack memory area.
[0042] Taking the second ratio threshold of 1 / 3 as an example, if the amount of data stored in the hot stack storage area accounts for less than 1 / 3 of the total amount of data in the hot stack storage area, then the data at the top of the cold stack storage area will be moved to the hot stack storage area through burst transmission.
[0043] If some data consists of 512 bytes, that is, if the amount of data stored in the hot stack storage area accounts for less than 1 / 3 of the total amount of data in the hot stack storage area, it is considered that the storage space of the hot stack storage area is about to be released. At this time, the CPU can move the top 512 bytes of data in the cold stack storage area to the hot stack storage area through a burst transfer, so that the data in the cold stack can be accessed more quickly.
[0044] In the specific implementation, step 402 is executed after the function (i.e. when the function returns). When step 402 is executed, the data in the hot stack space in the hot stack storage area is quickly popped into the register, and the corresponding hot stack space in the hot stack storage area is released. If the data stored in the storage area is less than 1 / 3 after the hot stack space is released, the dynamic adjustment of the hot stack storage area is automatically triggered.
[0045] If the hot stack storage area is dynamically adjusted, the data of the function may be stored not only in the hot stack storage area (such as in the hot stack space allocated in step 401), but also in the cold stack storage area (such as in the cold stack space). Therefore, in step 402, in addition to releasing the allocated hot stack space, the cold stack space in the cold stack storage area that stores the data of the function will also be released.
[0046] Access to the hot stack and cold stack storage areas can be achieved through the address arbitration module, such as... Figure 5 As shown. Figure 5In this architecture, the hot stack and cold stack are used for memory access. When the address of the data being accessed is in the hot stack, the access is performed directly within the hot stack. When the address is not in the hot stack, such as in the cold stack, the CPU's existing cache can be fully utilized (e.g., ...). Figure 5 In the CPU's DataCache, when the CPU needs to access data in the cold stack storage area, it can cache the data through the CPU's DataCache. Because the data access frequency in the cold stack storage area is low, even if it is cached through the DataCache, it will not cause too many cache line misses.
[0047] For example, in the function call chain A->B->C->D, the process of accessing the data on the stack of function B when function D is running.
[0048] Its code structure is roughly as follows (using C language style as an example): int A(void){ … int var1 = 45; B(&var1); … } void B (int ip2){ … C(ip2); … } void C (int ip3){ … D(ip3); … } void D (int ip4){ … ip4 = SomeFunction(); … } As shown in the code above, when function A is executed, function A calls function B, function B calls function C, and function C calls function D. The local variable var1 from function A's stack space is passed all the way to function D, where var1 is read and written. At this point, there are two possibilities: if the data on the stack of the accessed function B is stored in the hot stack memory area, then the CPU will... Figure 5The address arbitration module shown directly accesses data in the hot stack storage area. If the data of the accessed B function stack is stored in the cold stack storage area, the CPU accesses it through... Figure 5 The address arbitration module shown accesses DataCache to access data in the cold stack storage area.
[0049] In addition, whether moving data from the hot stack storage area to the cold stack storage area or from the cold stack storage area to the hot stack storage area, the amount of data moved each time is determined by the CPU and DDR. That is, the value with the highest transmission efficiency is selected based on the CPU design specifications and the parameters of the DDR memory, such as 64 bytes or 512 bytes of data moved each time.
[0050] It should be noted that the dynamic adjustment of the hot stack storage area (including moving the data at the bottom of the hot stack storage area to the cold stack storage area via burst transfer and moving the data at the top of the cold stack storage area to the hot stack storage area via burst transfer) is executed multiple times during function stack maintenance, not just once. That is, whenever the proportion of data stored in the hot stack storage area exceeds a first threshold, the data at the bottom of the hot stack storage area is moved to the cold stack storage area via burst transfer. Conversely, whenever the proportion of data stored in the hot stack storage area falls below a second threshold, the data at the top of the cold stack storage area is moved to the hot stack storage area via burst transfer. This makes the hot stack storage area different from the CPU cache in existing technologies. When the hot stack storage area is nearly full, it can automatically move less frequently accessed data to the cold stack storage area, thereby dynamically expanding the storage space of the hot stack storage area. When the hot stack storage area is nearly empty, it can automatically move data from the cold stack storage area to the hot stack storage area, thereby automatically loading data with high usage frequency and ensuring dynamic adjustment of the hot stack storage area.
[0051] During the data migration process, such as Figure 6 As shown ( Figure 6The bold arrows indicate that data can be automatically moved between the hot and cold stack regions (the shaded areas represent the stored data). The top of the hot stack region is Top1, and the bottom is Bottom1. The top of the cold stack region is Top2, and the bottom is Bottom2. Because the addresses of the data stored in the hot and cold stack regions are always contiguous, Bottom1 is always equal to Top2. Furthermore, the data movement between the hot and cold stack regions is an automatic control process within the hot stack region and does not require application control. The data in the hot stack region plus the data in the cold stack region equals the total data in the function stack. In other words, moving data from the hot stack region to the cold stack region reduces the data space in the hot stack region by the same amount as it increases in the cold stack region, and vice versa.
[0052] The function stack maintenance method provided in this embodiment is executed during the execution of each function. For example, if there is a function call chain A->B->C->D, then step 401, "When executing a stack space allocation statement," will be executed before functions A, B, C, and D, allocating hot stack space. During hot stack space allocation, the CPU will adjust the stack pointer register (e.g., the x86 ESP register, sub esp, N). When the stack space release statement is executed after functions A, B, C, and D, the allocated hot stack space will be released (if data corresponding to the function exists in the cold stack storage area, the corresponding cold stack space will also be released simultaneously). During hot stack space release, the CPU will adjust the stack pointer register (e.g., the x86 ESP register, mov esp, ebp). If the CPU is executing other instructions, it will continuously monitor the changes in the stack pointer register to determine whether the currently executing assembly instruction is allocating or releasing the function stack.
[0053] Furthermore, in practical implementation, the data movement of executed functions can be recorded (such as recording the space occupied by executed functions and the call chain). When the CPU executes a function call statement, it reserves hot stack space in the hot stack memory area based on the data movement of the called function, or loads the data to be accessed into the hot stack memory area. This enables the prediction and advance movement of data in automatic batches between the hot and cold stack memory areas.
[0054] Since data is moved from the hot stack storage area to the cold stack storage area during the pre-function execution when stack space is allocated to the function, a hash table can be created inside the CPU to record and update the number of times data is moved from the hot stack storage area to the cold stack storage area during each function execution.
[0055] For example, when executing assembly instructions inside function A, if data is moved from the hot stack to the cold stack, the corresponding hash table entry is incremented by 1; if no data is moved from the hot stack to the cold stack when executing function A, the corresponding hash table entry is decremented by 1.
[0056] Similarly, data is moved from the cold stack storage area to the hot stack storage area when the stack space is released for the function after the function execution. Therefore, a hash table can be made inside the CPU to record and update the number of times data is moved from the cold stack storage area to the hot stack storage area during each function execution.
[0057] For example, when executing assembly instructions inside function A, if data is moved from the cold stack to the hot stack, the corresponding hash table entry is incremented by 1; if no data is moved from the cold stack to the hot stack when executing function A, the corresponding hash table entry is decremented by 1.
[0058] During function execution, the values in the hash table are dynamically updated with each function call and return, facilitating accurate prediction of data movement between the cold and hot stack storage areas. For example, when the CPU executes a function call statement, it records the data movement of the executed functions (such as the space occupied by the executed functions and the call chain) and stores this data movement information in the hash. Based on the previous call chain of the function, the stack space required by the function and its sub-functions is predicted in advance, and storage space is reserved for the function in the hot stack storage area in advance based on the predicted stack space size.
[0059] The Hash table is shown in Table 1. The key value of the Hash can be several low bits of the entry address of each function (i.e., the address of the first line of assembly of the function), such as [11:0].
[0060] Table 1
[0061] Based on data in the hash table, predict data migration between the hot and cold stack storage areas in advance, and perform the data migration ahead of time. This includes: Predict data movement from the hot stack to the cold stack and perform the movement in advance. For example, when the statement calling function A (e.g., Call AFunction;) is executed, the entry address of function A is used to look up the number of times data has been moved from the hot stack to the cold stack in the hash table. If the recorded number exceeds a threshold N1, then M1 data items from the hot stack are moved to the cold stack while the Call AFunction statement is being executed, thus reserving storage space for the hot stack in advance.
[0062] Predict the data movement from the cold stack to the hot stack and perform the data movement in advance. For example, during CPU prefetching (note that this is the prefetching phase, which is several or even a dozen cycles earlier than the execution phase), up to the statement that function A returns (e.g., Return;), look up the number of times data has been moved from the cold stack to the hot stack based on the entry address of function A in the aforementioned hash table. If the recorded number exceeds a threshold N2, then while the CallAFunction statement is being executed, start moving M2 pieces of data from the cold stack to the hot stack, thus loading the data that will be accessed into the hot stack in advance.
[0063] The function stack maintenance method provided in this embodiment maintains a dynamically adjusted hardware function stack, employing two different storage methods for hot and cold data: 1) the hot stack storage area constitutes the hot stack, storing hot data; 2) the cold stack storage area constitutes the cold stack, storing cold data. By using these two different storage methods, the advantages of fast random access speed for hot data and fast overall access speed for cold data are achieved.
[0064] The function stack maintenance method provided in this embodiment maintains a function stack with a hot stack storage area (i.e., function hot stack) set up inside the CPU. The hot stack storage area stores the data at the top of the function stack and caches local variables that are frequently pushed and popped in the currently running function, thus avoiding the situation where the performance of existing technologies drops sharply in certain typical scenarios.
[0065] This embodiment provides a method for maintaining a function stack. In the pre-function statement, when a stack space allocation statement is executed, hot stack space is allocated; this hot stack space is located within the CPU's internal hot stack storage area. In the subsequent function statements, when a stack space release statement is executed, the allocated hot stack space is released. This method improves the random access speed of hot data by utilizing the CPU's internal hot stack storage area.
[0066] Based on the same inventive concept as the above-mentioned function stack maintenance method, this embodiment provides a function stack access method.
[0067] The function stack accessed by this method is... Figure 4 The function stack maintenance method provided in the illustrated embodiment maintains: For example, in the preamble of a function, when a stack allocation statement is executed, hot stack space is allocated. This hot stack space resides within the hot stack storage area inside the CPU (Central Processing Unit). Later in the function, when a stack deallocation statement is executed, the allocated hot stack space is released.
[0068] Among them, the page table entries or PMAs (Physical Memory Attributes) corresponding to the hot stack storage area are configured as Uncacheable.
[0069] In the function preamble, after allocating hot stack space when executing the stack space allocation statement, the following steps are also included: If the amount of data stored in the hot stack storage area exceeds the first proportion threshold, the data at the bottom of the hot stack storage area will be moved to the cold stack storage area through burst transmission.
[0070] In the subsequent part of the function, when the stack space release statement is executed, after releasing the allocated hot stack space, it also includes: If the amount of data stored in the hot stack storage area is less than the second proportion threshold, the data at the top of the cold stack storage area will be moved to the hot stack storage area through burst transmission.
[0071] The cold stack storage area is located in DDR (Double Data Rate Synchronous Dynamic Random Access Memory).
[0072] Among them, the page table entries or PMA corresponding to the cold stack storage area are configured as cacheable.
[0073] The amount of data moved each time is determined by the CPU and DDR.
[0074] This also records the data movement of executed functions. When the CPU executes a function call statement, it reserves hot stack space in the hot stack memory area based on the data movement of the called function, or loads the data to be accessed into the hot stack memory area.
[0075] The access process for the function stack maintained in the above process is as follows: Accessing the function stack within a function can be done quickly using push and pop. If accessing data in the stack storage area of another function within a function is required, it is done through steps 701-703.
[0076] 701. When the memory access data of a function is data of another function, the address of the memory access data is arbitrated.
[0077] 702. If the memory access address is within the hot stack storage area, then the memory access data within the hot stack storage area is accessed directly.
[0078] 703. If the memory access data address is in the cold stack storage area, the memory access data is accessed through the data cache.
[0079] Steps 701-703 can be used to arbitrate the memory access data address. If the memory access data address is on the hot stack storage area, the data is accessed directly through the hot stack storage area; if the memory access data address is on the cold stack storage area, the data is accessed through the DataCache.
[0080] The arbitration process can be implemented through the address arbitration module, such as... Figure 5 As shown. Figure 5 In this architecture, the hot stack storage area is called HotStack, and the cold stack storage area is called ColdStack. When the address of the data to be accessed is in the hot stack storage area, the data access is performed directly within the hot stack storage area. When the address of the data to be accessed is not in the hot stack storage area, such as in the cold stack storage area, the existing data cache in the CPU can be fully utilized (e.g., ...). Figure 5 In the CPU's DataCache, when the CPU needs to access data in the cold stack storage area, it can cache the data through the CPU's DataCache. Because the data access frequency in the cold stack storage area is low, even if it is cached through the DataCache, it will not cause too many cache line misses.
[0081] For example, in the function call chain A->B->C->D, the process of accessing the data on the stack of function B when function D is running.
[0082] Its code structure is roughly as follows (using C language style as an example): int A(void){ … int var1 = 45; B(&var1); … } void B (int ip2){ … C(ip2); … } void C (int ip3){ … D(ip3); … } void D (int ip4){ … ip4 = SomeFunction(); … } As shown in the code above, when function A is executed, function A calls function B, function B calls function C, and function C calls function D. The local variable var1 from function A's stack space is passed all the way to function D, where var1 is read and written. At this point, there are two possibilities: if the data on the stack of the accessed function B is stored in the hot stack memory area, then the CPU will... Figure 5 The address arbitration module shown directly accesses data in the hot stack storage area. If the data of the accessed B function stack is stored in the cold stack storage area, the CPU accesses it through... Figure 5 The address arbitration module shown accesses DataCache to access data in the cold stack storage area.
[0083] This application provides a method for accessing the function stack, which improves the random access speed of hot data by utilizing the hot stack storage area inside the CPU.
[0084] Based on the same inventive concept of the above-mentioned function stack maintenance method, this embodiment provides an electronic hardware, which includes: a processor.
[0085] The processor is used to execute the aforementioned function stack maintenance methods.
[0086] For example: In the preamble of a function, when a stack space allocation statement is executed, hot stack space is allocated. This hot stack space is located within the hot stack storage area inside the central processing unit (CPU).
[0087] In subsequent parts of the function, when a stack space deallocation statement is executed, the allocated hot stack space is released.
[0088] Optionally, the page table entry or physical memory attribute (PMA) corresponding to the hot stack storage region is configured to be uncacheable.
[0089] Optionally, in the function preamble, after allocating hot stack space when executing the stack space allocation statement, the following may also be included: If the amount of data stored in the hot stack storage area exceeds the first proportion threshold, the data at the bottom of the hot stack storage area will be moved to the cold stack storage area through burst transmission.
[0090] Optionally, in the subsequent part of the function, after the stack space is released when the stack space deallocation statement is executed, the function may also include: If the amount of data stored in the hot stack storage area is less than the second proportion threshold, the data at the top of the cold stack storage area will be moved to the hot stack storage area through burst transmission.
[0091] Optionally, the cold stack storage area is located in Double Data Rate Synchronous Dynamic Random Access Memory (DDR).
[0092] Optionally, the page table entries or PMA corresponding to the cold stack storage area are configured as cacheable.
[0093] Optionally, the amount of data moved each time is determined based on the CPU and DDR.
[0094] Optionally, the method further includes: Record the data movement process of functions that have been executed.
[0095] When the CPU executes a function call statement, it reserves hot stack space in the hot stack memory area according to the data movement of the called function, or loads the data to be accessed in the hot stack memory area.
[0096] The electronic hardware provided in this embodiment improves the random access speed of hot data by utilizing the hot stack storage area inside the CPU.
[0097] Based on the same inventive concept of the above-mentioned function stack access method, this embodiment provides an electronic hardware, which includes: a processor.
[0098] The processor is used to execute the access methods of the function stack mentioned above.
[0099] For example: The methods for accessing the function stack include: When the memory access data of a function is data from another function, the address of the memory access data is arbitrated.
[0100] If the memory access address is within the hot stack storage area, the memory access data within the hot stack storage area will be accessed directly.
[0101] If the memory access data address is within the cold stack storage area, the memory access data is accessed through the data cache.
[0102] The electronic hardware provided in this embodiment improves the random access speed of hot data by utilizing the hot stack storage area inside the CPU.
[0103] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The solutions in the embodiments of this application can be implemented using various computer languages, such as the object-oriented programming language C++ and the hardware description language SystemVerilog.
[0104] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0105] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0106] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0107] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0108] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for maintaining a function stack, characterized in that, The method includes: In the function preamble, when a stack space allocation statement is executed, hot stack space is allocated; wherein, the hot stack space is located in the hot stack storage area inside the central processing unit (CPU). In subsequent parts of the function, when a stack space deallocation statement is executed, the allocated hot stack space is released.
2. The method according to claim 1, characterized in that, The page table entry or physical memory attribute (PMA) corresponding to the hot stack storage area is configured to be uncacheable.
3. The method according to claim 1, characterized in that, In the function preamble, after allocating hot stack space when executing the stack space allocation statement, the following is also included: If the amount of data stored in the hot stack storage area exceeds a first proportion threshold, the data at the bottom of the hot stack storage area will be moved to the cold stack storage area via burst transmission.
4. The method according to claim 1, characterized in that, The description of "in the subsequent function, when the stack space release statement is executed, after releasing the allocated hot stack space" also includes: If the amount of data stored in the hot stack storage area is less than the second proportion threshold, then the data at the top of the cold stack storage area will be moved to the hot stack storage area via burst transmission.
5. The method according to claim 3 or 4, characterized in that, The cold stack storage area is located in Double Data Rate Synchronous Dynamic Random Access Memory (DDR).
6. The method according to claim 5, characterized in that, The page table entries or PMAs corresponding to the cold stack storage area are configured as cacheable.
7. The method according to claim 5, characterized in that, The amount of data moved each time depends on the CPU and DDR.
8. The method according to claim 3 or 4, characterized in that, The method further includes: Record the data movement process of functions that have been executed; When the CPU executes a function call statement, it reserves hot stack space in the hot stack memory area according to the data movement of the called function, or loads the data to be accessed in the hot stack memory area.
9. A method for accessing a function stack, characterized in that, The function stack is maintained by the function stack maintenance method of any one of claims 1-8; The methods for accessing the function stack include: When the memory access data of a function is data of another function, the address of the memory access data is arbitrated. If the memory access data address is within the hot stack storage area, then the memory access data within the hot stack storage area is accessed directly; If the memory access data address is within the cold stack storage area, the memory access data is accessed through the data cache.
10. An electronic hardware device, characterized in that, The electronic hardware includes: a processor; The processor is configured to perform the method as described in any one of claims 1-8, or to perform the method as described in claim 9.