[go: nahoru, domu]

CN117687770A - Memory application method and related device - Google Patents

Memory application method and related device Download PDF

Info

Publication number
CN117687770A
CN117687770A CN202310745337.4A CN202310745337A CN117687770A CN 117687770 A CN117687770 A CN 117687770A CN 202310745337 A CN202310745337 A CN 202310745337A CN 117687770 A CN117687770 A CN 117687770A
Authority
CN
China
Prior art keywords
memory
function
type
application
storage unit
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
Application number
CN202310745337.4A
Other languages
Chinese (zh)
Other versions
CN117687770B (en
Inventor
齐明龙
张凯亮
胡大帅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202310745337.4A priority Critical patent/CN117687770B/en
Publication of CN117687770A publication Critical patent/CN117687770A/en
Application granted granted Critical
Publication of CN117687770B publication Critical patent/CN117687770B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Telephone Function (AREA)

Abstract

The embodiment of the application provides a memory application method and a related device, after receiving a system message indicating to store data to be stored, the application determines the memory demand required by the data to be stored, and applies for memory from a first type of storage unit under the condition that the memory demand is greater than a first threshold. The operation efficiency of the first type of storage unit is lower than that of the second type of storage unit, and the probability of applying for the memory from the first type of storage unit is higher.

Description

Memory application method and related device
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a memory application method and a related device.
Background
With the continuous development of computer science and technology, software (APP) in electronic devices is increasingly more and more. Electronic devices have many data processes during APP operation, and for example, in order to make the electronic device look smoother, the dynamic effects may be displayed when the application is turned on/off, and thus, the electronic device needs to process the effect parameters related to the dynamic effect display. Also illustratively, in order to enhance the user's listening experience, the user may select different sound effects in the music playing software to play the music, and therefore, the electronic device needs to process the effect parameters related to the sound effect playing.
Before data processing, the electronic device needs to apply for a memory for storing data. Under the conditions of more programs and insufficient memory running in the background of the electronic equipment, the memory application efficiency is low.
Disclosure of Invention
The embodiment of the application provides a memory application method and a related device, after receiving a system message indicating to store data to be stored, the application determines the memory demand required by the data to be stored, and applies for memory from a first type of storage unit under the condition that the memory demand is greater than a first threshold. The operation efficiency of the first type of storage unit is lower than that of the second type of storage unit, and the probability of applying for the memory from the first type of storage unit is higher.
In a first aspect, an embodiment of the present application provides a method for applying a memory, where the method is applied to an electronic device, and a memory of the electronic device includes a first type of storage unit and a second type of storage unit, where an operation efficiency of the second type of storage unit is higher than an operation efficiency of the first type of storage unit, and the method includes:
Receiving a system message, wherein the system message is used for indicating to store data to be stored;
determining the memory demand required by storing the data to be stored;
and applying for the memory from the first-type memory unit under the condition that the memory demand is greater than a first threshold value.
In this embodiment, the execution subject of the method may be an electronic device or a program in the electronic device. The program in the electronic device may be a kernel program, which may be understood as a An Zhuona core in the embodiment of the present application; other programs than kernel programs are also possible, such as a memory application function in the embodiments of the present application.
In this embodiment, the system message may be understood as any message for indicating to store the data to be stored, and triggers the execution body to apply for the memory to store the data to be stored. The system message may be a message sent by an upper layer of the kernel layer to a kernel program in the kernel layer, or may be a message sent by the kernel program to a memory application function. Therefore, in the case where the execution body is a kernel program, the system message may be a message sent from an upper layer of the kernel layer to the kernel program in the kernel layer, and in the case where the execution body is a memory application function, the system message may be a message sent from the kernel program to the memory application function.
In this embodiment of the present application, the system message may be the data to be stored itself, or may be a message to be parsed, and the data to be stored may be obtained after the system message is parsed. For example, when the execution body is a memory application function and the system message needs to be parsed, the memory application function may receive the system message to be parsed sent by the kernel program, and then parse the system message to obtain the data to be stored; or the kernel program can analyze the system information to obtain the data to be stored, and then send the data to be stored as the system information to the memory application function.
In this embodiment of the present application, the data to be stored may be any data that may be stored in the first type of storage unit or the second type of storage unit, for example, may be an effect parameter, or may be other data, which is not limited in this application.
In the embodiment of the application, the first type of storage unit and the second type of storage unit are storage resources of the electronic device, wherein the operation efficiency of the second type of storage unit is lower than that of the first type of storage unit. In one implementation, the first type of storage unit and the second type of storage unit may be storage units of different levels in the hierarchical storage, where the second type of storage unit is lower than the first type of storage unit, such as the second type of storage unit is a primary memory, the first type of storage unit is a secondary memory, and other levels may be analogized. In another implementation, the first type of storage unit is virtual memory and the second type of storage unit is physical memory.
The amount of memory required to store data to be stored is understood to be the size of the memory, and specific units may be bits, bytes, etc. It will be appreciated that after applying for memory from the first type of memory unit, memory (referred to as target memory for short) may be obtained, where the size of the target memory matches the memory requirement. After the target memory is obtained, the data to be stored can be stored in the target memory, and then the data to be stored is subjected to subsequent processing.
In this embodiment of the present application, the first threshold may be determined according to a success rate of applying for the memory from the first type of storage unit and the second type of storage unit, and since the operation efficiency of the first type of storage unit is lower than that of the second type of storage unit, that is, applying for the memory from the first type of storage unit is easier than applying for the memory from the second type of storage unit, assuming that the statistics result reflects that a success rate of applying for the memory smaller than a byte from the second type of storage unit is higher (for example, higher than 80%), but a success rate of applying for the memory larger than a byte is very low (for example, lower than 20%), then the first threshold may be set to a byte. In some embodiments, the first threshold may also be adjusted according to the memory occupancy, for example, the first threshold that is initially set may be adjusted to be smaller when a memory shortage is detected (the number of acquired travel processes is greater than a certain number).
With reference to the first aspect, in a possible implementation manner, the method further includes:
and applying for the memory from the second type of memory unit under the condition that the memory demand is smaller than the first threshold.
In this embodiment, the memory demand is determined first, and then the memory application mode is selected according to the memory demand, where the memory is applied from the first type of storage unit that is easy to apply to the memory when the memory demand is greater than the first threshold, and the memory is directly applied from the second type of storage unit when the memory demand is less than the first threshold, so that the memory application efficiency can be improved.
It is understood that, when the memory demand is equal to the first threshold, the memory may be applied from the second type of storage unit, or the memory may be applied from the first type of storage unit, which may be specifically set according to the actual situation, and this application is not limited thereto.
With reference to the first aspect, in a possible implementation manner, the method further includes:
and when the memory application from the second type of memory unit fails, applying the memory from the first type of memory unit.
It can be understood that the second type of storage unit is a high-efficiency memory unit, and although the memory requirement is smaller than the memory requirement, the memory is applied from the second type of storage unit, but serious shortage of the memory is unavoidable, so that even if the memory requirement is small, the memory is difficult to apply. Therefore, in the case of applying for the memory failure from the second type of memory unit, the embodiment applies for the memory from the first type of memory unit, so that the probability of the memory application failure can be reduced.
In the embodiment of the present application, when the first type of storage unit is a virtual memory and the second type of storage unit is a physical memory, a vmalloc function may be used to apply for a memory from the first type of storage unit, so as to obtain a virtual memory; applying for the memory from the second type of memory unit by using the kmalloc function to obtain the physical memory. Alternatively, in the above embodiment, the application of the memory from the second type of storage unit may be implemented by a kvmalloc function in the case that the application of the memory from the second type of storage unit fails. In the above case, the first threshold may be set to 4KB.
In the case where the execution subject is an electronic device or a kernel program, a specific implementation example of the present embodiment may refer to fig. 5.
With reference to the first aspect, in one possible implementation manner, a hook function is included in a kernel program of the electronic device; the receiving system message includes:
the memory application function receives the system message sent by the hook function, and the memory application function is other programs except the kernel program.
In this embodiment, the kernel program includes a hook function, which may be understood as including a hook point in the kernel program, and the description about the hook point may refer to the description of fig. 7 (a), which is not repeated herein.
Optionally, the execution environment of the hook function includes a function declaration of the hook function and a derivation function of the hook function; the function declaration is used for defining the function name, the function type and the input parameters of the hook function, and the export function is used for enabling the hook function to be called by the kernel program.
Optionally, the running environment of the memory application function includes a registration function of the memory application function, where the registration function is used to bind the memory application function with the hook function.
In this embodiment, the execution body is a memory application function, the hook function in the kernel program is bound to the memory application function, and the memory application function receives a system message through the hook function, so as to instruct the memory application function to determine the memory demand and apply for memory from which memory unit, for example, when the memory demand is greater than a first threshold, apply for memory from a first type of memory unit; applying for the memory from the second type of memory unit if the memory demand is less than the first threshold; and in case of memory failure application from the second type of memory unit, applying for memory from the first type of memory unit.
It is understood that the hook function belongs to a kernel program, and the memory application function is another program except the kernel program, which can be understood that the memory application function is located in a self-grinding code bin. An exemplary method for focusing on the book function and binding the hook function and the memory application function may be referred to in fig. 7 (b), and in the case that the first type of storage unit is virtual memory and the second type of storage unit is physical memory, a specific implementation example of this embodiment may be referred to in fig. 6.
It can be understood that in some areas, the code logic in the kernel program cannot be directly modified, so the embodiment decouples the memory application function through the hook function, and implements the memory application function through the memory application function, so that the embodiment can adapt to the scene that the kernel program cannot be modified.
With reference to the first aspect, in a possible implementation manner, the method further includes:
and under the condition that the memory application function fails to apply for memory from the first-type storage unit and fails to apply for memory from the second-type storage unit, the kernel program applies for memory from the second-type storage unit or applies for memory from the first-type storage unit.
It will be appreciated that the memory application function is located outside the kernel program, such as in a self-grinding code bin, there may be instances where the hook function is included in the kernel program, but the memory application function is not present in the self-grinding code bin. In this embodiment, under the condition that the application of the memory application function fails, the kernel program continues to apply for the memory, so as to reduce the probability of memory application failure caused by the failure of calling the memory application function by the quasi-kernel program.
In the case that the first type of storage unit is a virtual memory and the second type of storage unit is a physical memory, the kernel program applies for the memory from the second type of storage unit, or the kernel program applies for the memory from the first type of storage unit, the kernel program may be implemented by using a kvmalloc function, and a specific implementation example may refer to fig. 8.
In a second aspect, embodiments of the present application provide an apparatus comprising means for performing the method of the first aspect or any possible implementation of the first aspect.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor, a memory; the memory of the memory comprises a first type memory unit and a second type memory unit, and the operation efficiency of the second type memory unit is higher than that of the first type memory unit; the memory is coupled to the processor, the memory is for storing computer program code, the computer program code comprising computer instructions, the processor invoking the computer instructions to cause the method of the first aspect or any possible implementation of the first aspect to be performed.
In a fourth aspect, embodiments of the present application provide a chip, including a logic circuit and an interface, where the logic circuit and the interface are coupled; the interface is for inputting and/or outputting code instructions and the logic circuitry is for executing the code instructions to cause the method of the first aspect or any possible implementation of the first aspect to be performed. It is understood that the first type of memory cell and the second type of memory cell may be both in a chip, or the second type of memory cell may be located in a chip, and the first type of memory cell may be located off-chip.
In a fifth aspect, embodiments of the present application provide a computer program product comprising program instructions which, when executed by a processor, cause the method of the first aspect or any of the possible implementations of the first aspect to be performed.
In a sixth aspect, embodiments of the present application provide a computer readable storage medium having a computer program stored therein, which when run on a processor causes the method of the first aspect or any of the possible implementations of the first aspect to be performed.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below. It is apparent that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained from these drawings without inventive effort for a person of ordinary skill in the art.
Fig. 1 is a schematic diagram of forming memory fragments in memory allocation according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of an electronic device 100 according to an embodiment of the present application;
FIG. 3 is a block diagram of a software architecture provided by an embodiment of the subject application;
fig. 4 is a flow chart of a memory allocation method according to an embodiment of the present application;
FIG. 5 is a flowchart of a memory application method according to an embodiment of the present disclosure;
FIG. 6 is a flowchart of another memory application method according to an embodiment of the present disclosure;
FIG. 7 (a) is a flowchart illustrating the execution of a program including hook points according to an embodiment of the present application;
FIG. 7 (b) is a flowchart of binding a memory application function and a hook function according to an embodiment of the present application;
fig. 8 is a flowchart of another method for applying for memory according to an embodiment of the present application.
Detailed Description
The terminology used in the following embodiments of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms as well, unless the context clearly indicates to the contrary. It should also be understood that the term "and/or" as used in this application refers to and encompasses any or all possible combinations of one or more of the listed items.
The terms first and second and the like in the description, in the claims and in the drawings, are used for distinguishing between different objects and not for describing a particular sequential order. It should also be understood that, in the embodiments of the present application, the numbers before the steps are made for easy understanding and description of the solution, and should not be construed as limiting the order of execution of the steps.
According to the memory application method and the related device, when the electronic equipment needs to apply for the memory to store data, the memory demand required by storing the data is calculated, then the memory is applied for based on the size of the memory demand in different modes, and the application can improve the efficiency of the memory application, namely the application to the memory is faster.
For ease of understanding, the terms referred to in the embodiments of the present application are described first.
1. Effect parameters
In the embodiment of the application, the effect parameter may be understood as a parameter for affecting the sensory experience effect of the user. Illustratively, the effect parameter may be an effect parameter of an active display, such as color data of the active display; the audio playing effect parameters can also be the setting parameters of an equalizer; but also the effect parameters of the video playing, such as the setting parameters of the equalizer, color data and the like during the video playing.
Taking the effect parameters of dynamic effect display in the mobile phone as an example. Along with the popularization of mobile phones, the requirements of stability, fluency and attractiveness of a mobile phone system are higher and higher, so that in order to improve the attractiveness of the mobile phone system, mobile phone factories can increase the dynamic effect when the mobile phone starts/exits an Application (APP), so that the mobile phone looks smoother, the look and feel is better, and the user experience is improved.
In the dynamic playing process, the upper layer of the mobile phone system can send out the effect parameters, then the effect parameters are transferred to the bottom layer, and the display driver controls the screen to display better effects according to the effect parameters. Illustratively, the effect parameters issued in the playing process of the dynamic effect may be color parameters of the dynamic effect, etc.
Taking the audio playing effect parameters in the mobile phone as an example. The user can play songs through the music playing application in the mobile phone, in order to improve the hearing feeling of the user, the mobile phone provides various sound effects, and the user can select different sound effects to play songs. It can be understood that different sound effects correspond to different effect parameters, after a user selects a certain sound effect, the upper layer of the mobile phone system can issue the effect parameters, then the effect parameters are transferred to the bottom layer, and the playing effect of the song is controlled by the audio driver according to the effect parameters.
2. Memory
The electronic equipment provides a storage function for an operating system and various programs in the running process, and can be visually understood as a memory required by the running process of the programs. By way of example, the operating memory may be random access memory (random access memory, RAM) which may exchange data directly with the central processing unit (central processing unit, CPU). In the embodiment of the present application, the running memory may also be referred to as a memory or a main memory.
For example, after a user opens an application, the electronic device will allocate a certain memory space for the application and then create a process for the application. During the running process of the application, the application occupies the allocated memory, and the electronic device does not release the memory allocated for the application until the application is closed. Therefore, it can be understood that the size of the running memory can determine the programs that the electronic device can run, and the larger the running memory, the more programs can be run by the electronic device at the same time.
Physical memory may be understood as memory space obtained by a physical memory bank or as memory space that can be directly addressed by a CPU. It can be appreciated that, in the process of memory allocation, the electronic device will preferentially allocate physical memories with consecutive addresses, i.e. consecutive physical memories. With multiple consecutive physical memory allocations and releases of portions of consecutive physical memory, unallocated memory space between allocated memory may form memory fragmentation.
For ease of understanding, referring to fig. 1, fig. 1 is a schematic diagram illustrating formation of memory fragments in memory allocation according to an embodiment of the present application. Assuming that the electronic device has allocated contiguous physical memory for process a, process B, and process C, respectively, as shown in fig. 1 (a), process a occupies memory space 0-2, process B occupies memory space 3-6, and process C occupies memory space 7-13. After releasing process B, the memory space 3-6 that process B would otherwise occupy is released, as shown in FIG. 1 (B).
After the memory space occupied by the process B is released, if the newly built process D needs a memory space with a size of 10, the memory space 3-6 that is free by releasing the process B cannot be adapted to the process D, and a memory fragment is formed.
It will be appreciated that as electronic devices run more programs, the number of memory fragments will increase and the contiguous physical memory resources that can be allocated will be insufficient. To alleviate the above problems, virtual memory techniques may be employed. The electronic device may allocate virtual memory to the program through a virtual memory technique, so that the program considers itself to have continuous physical memory. In practice, however, virtual memory is a memory fragment in running memory or logical memory virtual using disk space.
In this embodiment of the present application, the effect parameters may be stored in a physical memory or may be stored in a virtual memory.
The method provided by the embodiment of the application can be executed by the electronic device, and the electronic device provided by the embodiment of the application is described next. Referring to fig. 2, fig. 2 is a schematic structural diagram of an electronic device 100 according to an embodiment of the present application.
The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charge management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a camera 193, a display 194, and a subscriber identity module (subscriber identification module, SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an acceleration sensor 180C, a fingerprint sensor 180D, a temperature sensor 180E, a touch sensor 180F, an ambient light sensor 180G, and the like.
It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, electronic device 100 may include more or fewer components than shown, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The processor 110 may include one or more processing units, such as: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and/or a neural network processor (neural-network processing unit, NPU), etc. Wherein the different processing units may be separate devices or may be integrated in one or more processors.
The controller may be a neural hub and a command center of the electronic device 100, among others. The controller can generate operation control signals according to the instruction operation codes and the time sequence signals to finish the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system.
In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (subscriber identity module, SIM) interface, and/or a universal serial bus (universal serial bus, USB) interface, among others.
The I2C interface is a bi-directional synchronous serial bus comprising a serial data line (SDA) and a serial clock line (derail clock line, SCL). In some embodiments, the processor 110 may contain multiple sets of I2C buses. The processor 110 may be coupled to the touch sensor 180F, charger, flash, camera 193, etc., respectively, through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180F through an I2C interface, such that the processor 110 communicates with the touch sensor 180F through an I2C bus interface to implement a touch function of the electronic device 100.
The I2S interface may be used for audio communication. In some embodiments, the processor 110 may contain multiple sets of I2S buses. The processor 110 may be coupled to the audio module 170 via an I2S bus to enable communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 may transmit an audio signal to the wireless communication module 160 through the I2S interface, to implement a function of answering a call through the bluetooth headset.
PCM interfaces may also be used for audio communication to sample, quantize and encode analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 may be coupled through a PCM bus interface. In some embodiments, the audio module 170 may also transmit audio signals to the wireless communication module 160 through the PCM interface to implement a function of answering a call through the bluetooth headset. Both the I2S interface and the PCM interface may be used for audio communication.
The UART interface is a universal serial data bus for asynchronous communications. The bus may be a bi-directional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, a UART interface is typically used to connect the processor 110 with the wireless communication module 160. For example: the processor 110 communicates with a bluetooth module in the wireless communication module 160 through a UART interface to implement a bluetooth function. In some embodiments, the audio module 170 may transmit an audio signal to the wireless communication module 160 through a UART interface, to implement a function of playing music through a bluetooth headset.
The MIPI interface may be used to connect the processor 110 to peripheral devices such as a display 194, a camera 193, and the like. The MIPI interfaces include camera serial interfaces (camera serial interface, CSI), display serial interfaces (display serial interface, DSI), and the like. In some embodiments, processor 110 and camera 193 communicate through a CSI interface to implement the photographing functions of electronic device 100. The processor 110 and the display 194 communicate via a DSI interface to implement the display functionality of the electronic device 100.
The GPIO interface may be configured by software. The GPIO interface may be configured as a control signal or as a data signal. In some embodiments, a GPIO interface may be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, and the like. The GPIO interface may also be configured as an I2C interface, an I2S interface, a UART interface, an MIPI interface, etc.
The USB interface 130 is an interface conforming to the USB standard specification, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, or the like. The USB interface 130 may be used to connect a charger to charge the electronic device 100, and may also be used to transfer data between the electronic device 100 and a peripheral device. And can also be used for connecting with a headset, and playing audio through the headset. The interface may also be used to connect other electronic devices, such as AR devices, etc.
It should be understood that the interfacing relationship between the modules illustrated in the embodiments of the present application is only illustrative, and does not limit the structure of the electronic device 100. In other embodiments of the present application, the electronic device 100 may also use different interfacing manners, or a combination of multiple interfacing manners in the foregoing embodiments.
The charge management module 140 is configured to receive a charge input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charge management module 140 may receive a charging input of a wired charger through the USB interface 130. In some wireless charging embodiments, the charge management module 140 may receive wireless charging input through a wireless charging coil of the electronic device 100. The charging management module 140 may also supply power to the electronic device through the power management module 141 while charging the battery 142.
The power management module 141 is used for connecting the battery 142, and the charge management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140 and provides power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, the wireless communication module 160, and the like. The power management module 141 may also be configured to monitor battery capacity, battery cycle number, battery health (leakage, impedance) and other parameters. In other embodiments, the power management module 141 may also be provided in the processor 110. In other embodiments, the power management module 141 and the charge management module 140 may be disposed in the same device.
The wireless communication function of the electronic device 100 may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, a modem processor, a baseband processor, and the like.
The antennas 1 and 2 are used for transmitting and receiving electromagnetic wave signals. Each antenna in the electronic device 100 may be used to cover a single or multiple communication bands. Different antennas may also be multiplexed to improve the utilization of the antennas. For example: the antenna 1 may be multiplexed into a diversity antenna of a wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
The mobile communication module 150 may provide a solution for wireless communication including 2G/3G/4G/5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (low noise amplifier, LNA), etc. The mobile communication module 150 may receive electromagnetic waves from the antenna 1, perform processes such as filtering, amplifying, and the like on the received electromagnetic waves, and transmit the processed electromagnetic waves to the modem processor for demodulation. The mobile communication module 150 can amplify the signal modulated by the modem processor, and convert the signal into electromagnetic waves through the antenna 1 to radiate. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be disposed in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be provided in the same device as at least some of the modules of the processor 110.
The modem processor may include a modulator and a demodulator. The modulator is used for modulating the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used for demodulating the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low frequency baseband signal to the baseband processor for processing. The low frequency baseband signal is processed by the baseband processor and then transferred to the application processor. The application processor outputs sound signals through an audio device (not limited to the speaker 170A, the receiver 170B, etc.), or displays pictures or video through the display screen 194. In some embodiments, the modem processor may be a stand-alone device. In other embodiments, the modem processor may be provided in the same device as the mobile communication module 150 or other functional module, independent of the processor 110.
The wireless communication module 160 may provide solutions for wireless communication including wireless local area network (wireless local area networks, WLAN) (e.g., wireless fidelity (wireless fidelity, wi-Fi) network), bluetooth (BT), global navigation satellite system (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field wireless communication technology (near field communication, NFC), infrared technology (IR), etc., as applied to the electronic device 100. The wireless communication module 160 may be one or more devices that integrate at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the electromagnetic wave signals, filters the electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive a signal to be transmitted from the processor 110, frequency modulate it, amplify it, and convert it to electromagnetic waves for radiation via the antenna 2.
In some embodiments, antenna 1 and mobile communication module 150 of electronic device 100 are coupled, and antenna 2 and wireless communication module 160 are coupled, such that electronic device 100 may communicate with a network and other devices through wireless communication techniques. The wireless communication techniques may include the Global System for Mobile communications (global system for mobile communications, GSM), general packet radio service (general packet radio service, GPRS), code division multiple access (code division multiple access, CDMA), wideband code division multiple access (wideband code division multiple access, WCDMA), time division code division multiple access (time-division code division multiple access, TD-SCDMA), long term evolution (long term evolution, LTE), BT, GNSS, WLAN, NFC, FM, and/or IR techniques, among others. The GNSS may include a global satellite positioning system (global positioning system, GPS), a global navigation satellite system (global navigation satellite system, GLONASS), a beidou satellite navigation system (beidou navigation satellite system, BDS), a quasi zenith satellite system (quasi-zenith satellite system, QZSS) and/or a satellite based augmentation system (satellite based augmentation systems, SBAS).
The electronic device 100 implements display functions through a GPU, a display screen 194, an application processor, and the like. The GPU is a microprocessor for image processing, and is connected to the display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
The display screen 194 is used to display pictures, videos, and the like. The display 194 includes a display panel. The display panel may employ a liquid crystal display (liquid crystal display, LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED) or an active-matrix organic light-emitting diode (matrix organic light emitting diode), a flexible light-emitting diode (flex), a mini, a Micro led, a Micro-OLED, a quantum dot light-emitting diode (quantum dot light emitting diodes, QLED), or the like. In some embodiments, the electronic device 100 may include 1 or N display screens 194, N being a positive integer greater than 1. In some embodiments, the display screen 194 may be used for a dynamic display.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to enable expansion of the memory capabilities of the electronic device 100. The external memory card communicates with the processor 110 through an external memory interface 120 to implement data storage functions. For example, files such as music, video, etc. are stored in an external memory card.
The internal memory 121 may be used to store computer executable program code including instructions. The processor 110 executes various functional applications of the electronic device 100 and data processing by executing instructions stored in the internal memory 121. The internal memory 121 may include a storage program area and a storage data area. The storage program area may store an application program (such as a sound playing function, a picture or video playing function, etc.) required for at least one function of the operating system. The storage data area may store data created during use of the electronic device 100 (e.g., audio data, phonebook, etc.), and so on. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (universal flash storage, UFS), and the like.
In some embodiments, the internal memory 121 may also be referred to as a memory, where storage resources may be allocated to various programs for use as continuous physical memory. Alternatively, part of the storage resources in the memory and part of the storage resources in the external memory card may be allocated as virtual memory for use by various programs.
The electronic device 100 may implement audio functions through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, an application processor, and the like. Such as music playing, recording, etc.
The audio module 170 is used to convert digital audio information into an analog audio signal output and also to convert an analog audio input into a digital audio signal. In some embodiments, the audio module 170 may be disposed in the processor 110, or a portion of the functional modules of the audio module 170 may be disposed in the processor 110.
The speaker 170A, also called a horn, is used to convert an audio electrical signal into a sound signal.
A receiver 170B, also called an earpiece, is used to convert the audio electrical signal into a sound signal. When electronic device 100 is answering a telephone call or voice message, voice may be received by placing receiver 170B in close proximity to the human ear.
Microphone 170C, also known as a microphone or microphone, is used to convert sound signals into electrical signals. When making a call or transmitting voice information, the user can sound near the microphone 170C through the mouth, inputting a sound signal to the microphone 170C. The electronic device 100 may be provided with at least one microphone 170C. In other embodiments, the electronic device 100 may be provided with two microphones 170C, and may implement a noise reduction function in addition to collecting sound signals. In other embodiments, the electronic device 100 may also be provided with three, four, or more microphones 170C to enable collection of sound signals, noise reduction, identification of sound sources, directional recording functions, etc.
The earphone interface 170D is used to connect a wired earphone. The earphone interface 170D may be a USB interface 130 or a 3.5mm open mobile electronic device platform (open mobile terminal platform, OMTP) standard interface.
The pressure sensor 180A is used to sense a pressure signal, and may convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A may be disposed on the display screen 194. The pressure sensor 180A is of various types, such as a resistive pressure sensor, an inductive pressure sensor, a capacitive pressure sensor, and the like. The capacitive pressure sensor may be a capacitive pressure sensor comprising at least two parallel plates with conductive material. The capacitance between the electrodes changes when a force is applied to the pressure sensor 180A.
The electronic device 100 may determine the strength of the pressure based on the change in capacitance. Illustratively, when a touch operation is applied to the display 194, the electronic apparatus 100 detects the touch operation intensity from the pressure sensor 180A. Also for example, the electronic device 100 may also calculate the position of the touch according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations that act on the same touch location, but at different touch operation strengths, may correspond to different operation instructions. For example: and executing an instruction for checking the short message when the touch operation with the touch operation intensity smaller than the first pressure threshold acts on the short message application icon. And executing an instruction for newly creating the short message when the touch operation with the touch operation intensity being greater than or equal to the first pressure threshold acts on the short message application icon.
The gyro sensor 180B may be used to determine a motion gesture of the electronic device 100. In some embodiments, the angular velocity of electronic device 100 about three axes (i.e., x, y, and z axes) may be determined by gyro sensor 180B. The gyro sensor 180B may be used for photographing anti-shake. For example, when the shutter is pressed, the gyro sensor 180B detects the shake angle of the electronic device 100, calculates the distance to be compensated by the lens module according to the angle, and makes the lens counteract the shake of the electronic device 100 through the reverse motion, so as to realize anti-shake. The gyro sensor 180B may also be used for navigating, somatosensory game scenes.
The acceleration sensor 180C may detect the magnitude of acceleration of the electronic device 100 in various directions (typically three axes). The magnitude and direction of gravity may be detected when the electronic device 100 is stationary. The electronic equipment gesture recognition method can also be used for recognizing the gesture of the electronic equipment, and is applied to horizontal and vertical screen switching, pedometers and other applications.
The fingerprint sensor 180D is used to collect a fingerprint. The electronic device 100 may utilize the collected fingerprint feature to unlock the fingerprint, access the application lock, photograph the fingerprint, answer the incoming call, etc.
The temperature sensor 180E is used to detect temperature. In some embodiments, the electronic device 100 performs a temperature processing strategy using the temperature detected by the temperature sensor 180E. For example, when the temperature reported by temperature sensor 180E exceeds a threshold, electronic device 100 performs a reduction in the performance of a processor located in the vicinity of temperature sensor 180E in order to reduce power consumption to implement thermal protection. In other embodiments, when the temperature is below another threshold, the electronic device 100 heats the battery 142 to avoid the low temperature causing the electronic device 100 to be abnormally shut down. In other embodiments, when the temperature is below a further threshold, the electronic device 100 performs boosting of the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperatures.
The touch sensor 180F is also referred to as a "touch panel". The touch sensor 180F may be disposed on the display 194, and the touch sensor 180F and the display 194 form a touch screen, which is also referred to as a "touch screen". The touch sensor 180F is used to detect a touch operation acting thereon or thereabout. The touch sensor 180F may communicate the detected touch operation to the application processor to determine the touch event type. Visual output related to touch operations may be provided through the display 194. In other embodiments, the touch sensor 180F may also be disposed on the surface of the electronic device 100 at a different location than the display 194.
The ambient light sensor 180G is used to sense ambient light level. The electronic device 100 may adaptively adjust the brightness of the display 194 based on the perceived ambient light level. The ambient light sensor 180G may also be used to automatically adjust white balance when taking a photograph. Ambient light sensor 180G may also cooperate with proximity light sensor 180G to detect whether electronic device 100 is in a pocket to prevent false touches.
The SIM card interface 195 is used to connect a SIM card. The SIM card may be inserted into the SIM card interface 195, or removed from the SIM card interface 195 to enable contact and separation with the electronic device 100. The electronic device 100 may support 1 or N SIM card interfaces, N being a positive integer greater than 1. The SIM card interface 195 may support Nano SIM cards, micro SIM cards, and the like. The same SIM card interface 195 may be used to insert multiple cards simultaneously. The types of the plurality of cards may be the same or different. The SIM card interface 195 may also be compatible with different types of SIM cards. The SIM card interface 195 may also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to realize functions such as communication and data communication. In some embodiments, the electronic device 100 employs esims, i.e.: an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
In other embodiments, the processor 110 may invoke computer instructions stored in the internal memory 121 to implement the memory application method provided in the embodiments of the present application.
For example, the processor 110 may invoke computer instructions stored in the internal memory 121 to calculate the memory requirements for storing the effect parameters, and then apply for the memory in different manners according to the memory requirements. The computer instructions may apply for contiguous physical memory, or for virtual memory, for example.
It is understood that the software system of the electronic device 100 may employ a layered architecture, an event driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture, which is not limited in this application. For ease of understanding, referring to fig. 3, fig. 3 is an exemplary block diagram of a software architecture provided in an embodiment of the present application. The layered architecture shown in fig. 3 divides the software into several layers, each layer having a distinct role and division of work, and the layers can communicate through software interfaces.
In some embodiments, the system of the electronic device may be divided into four layers, from top to bottom, an application layer, an application framework layer, a system runtime layer, a hardware abstraction layer (hardware abstraction layer, HAL), and a kernel layer, respectively. The description of the above layers is as follows:
The application layer may include a series of application packages. By way of example, application packages at the application layer may include applications such as cameras, gallery, calendar, talk, map, navigation, browser, music, video, and short messages.
The application framework layer may provide an application programming interface (application programming interface, API) and programming framework for applications in the application layer. The application framework layer may include some predefined functions.
By way of example, the application framework layers may include an activity manager (activity manager), a window manager (window manager), a content provider (content provider), a view system (view system), a telephony manager (telephony manager), a resource manager (resource manager), a notification manager (notification manager), and an accelerated graphics port (accelerated graphics port, AGP), among others. Wherein:
the activity manager may be used to manage individual application lifecycle and, typically, navigation rollback functions.
The window manager may be used to manage window programs. Illustratively, the window manager may obtain the display screen size of the electronic device 100, lock the screen, intercept the screen, determine if a status bar exists, and so forth.
The content provider may be used to store and retrieve data and make the data accessible to applications so that data may be accessed or shared between different applications. By way of example, the data may include video, images, audio, calls made and received, browsing history and bookmarks, and phonebooks, etc.
The view system includes visual controls, such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, a display interface including a text message notification icon may include a view displaying text and a view displaying a picture.
The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including making a call, hanging up a phone, etc.).
The resource manager provides various resources for the application program, such as localization strings, icons, pictures, layout files, video files, and the like.
The notification manager allows the application to display notification information in a status bar, can be used to communicate notification type messages, can automatically disappear after a short dwell, and does not require user interaction. Illustratively, a notification manager may be used to inform that the download is complete, a message reminder, and so forth. The notification manager may also be a notification in the form of a chart or scroll bar text that appears on the system top status bar, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in a status bar, a prompt tone is emitted, the electronic device vibrates, and an indicator light blinks, etc.
AGP in the application framework layer may be used to improve rendering performance of the graphics card, such as providing more buffer capacity to the graphics card for faster image processing.
The system runtime layer may include a system library and Android runtime (Android run time). Wherein:
the android runtime includes a core library and virtual machines. And the android running time is responsible for scheduling and managing an android system. The core library comprises two parts: one part is a function which needs to be called by java language, and the other part is a core library of android. The application layer and the application framework layer run in a virtual machine. The virtual machine executes java files of the application program layer and the application program framework layer as binary files. The virtual machine is used for executing the functions of object life cycle management, stack management, thread management, security and exception management, garbage collection and the like.
A system library can be understood as the support of an application framework, which is an important ligament connecting the application framework layer and the kernel layer. The system layer may include a plurality of functional modules, and may include, for example, a surface manager (surface manager), a media library (media library), a three-dimensional graphics processing library (e.g., openGL ES), a two-dimensional graphics engine (e.g., SGL), and the like. Wherein:
The surface manager may be used to manage the display subsystem, such as in the case of multiple applications executed by the electronic device 100, and is responsible for managing interactions between display and access operations. The surface manager may also be used to provide a fusion of two-dimensional and three-dimensional layers for multiple applications.
The media library may support a variety of commonly used audio, video format playback and recording, still image files, and the like. The media library may support a variety of audio and video encoding formats, such as MPEG4, h.264, MP3, AAC, AMR, JPG, PNG, etc.
The three-dimensional graphic processing library is used for realizing three-dimensional graphic drawing, image rendering, synthesis, layer processing and the like.
A two-dimensional graphics engine may be understood as a drawing engine for two-dimensional drawing.
The hardware abstraction layer provides standard interfaces such as HAL interface definition language (HAL interface definition language, HIDL) interfaces or android interface definition language (android interface definition language, AIDL) interfaces.
The kernel layer may be understood as an abstraction layer between hardware and software. The kernel layer may include security, memory management, process management, power management, network protocol management, and drive management. Illustratively, the kernel layer may include a display driver, a camera driver, an audio driver, a sensor driver, and the like. Alternatively, the kernel layer may also be referred to as An Zhuona kernel. By way of example, the hardware layers of the electronic device may include a Touch Panel (TP), a liquid crystal display (liquid crystal display, LCD), and the like.
In some embodiments, a sensor driver (e.g., a touch sensor driver) is configured to generate an event to trigger an activity manager in an application framework layer to open or close an application in response to a user operation (e.g., a click operation to open/close the application), and may also generate an event to trigger a view system in the application framework layer to create a view (view), and a display driver may control a display screen to display the created view.
In other embodiments, a sensor driver (e.g., a touch sensor driver) is configured to generate an event to trigger an AGP generation effect parameter in an application framework layer in response to a user operation (e.g., a click operation to open/close an application). Optionally, the AGP may issue the effect parameter to the An Zhuona core. The An Zhuona core can apply for the memory for storing the effect parameters to the system after receiving the effect parameters, and then the display driver can process the effect parameters and control the display screen to display according to the effect parameters.
When An Zhuona is applied to a memory for storing effect parameters of dynamic display, a method as shown in fig. 4 may be adopted, and fig. 4 is a flow chart of a memory allocation method provided in the embodiment of the present application. As shown in fig. 4, the method includes:
401: APP dynamic effect display.
In this step, the APP may be any APP installed in the electronic device, may be a system APP, or may be a third party APP, which is not limited in this application.
The electronic device may illustratively start or exit a certain APP according to user operations, and the touch sensor driver of the electronic device may illustratively detect user operations to turn the APP on or off. In the starting or exiting process, the electronic device can display dynamic effects, such as turning dynamic effects, sliding dynamic effects, gradual dynamic effects and the like. It can be appreciated that in addition to displaying the dynamic effects when starting or exiting the APP, the dynamic effects may also be displayed in the cases of hiding and displaying interface elements, interface buffering, interface transition, etc., and the AGP may also correspondingly generate the effect parameters.
It will be appreciated that the APP is located at the application layer of the software architecture, and thus, APP action display may be understood as APP ready to initiate action display at the application layer.
402: and generating an effect parameter.
When the touch sensor driver detects that the APP needs to display the dynamic effect, the AGP of the application framework layer may be triggered to generate an effect parameter, where the effect parameter may be understood as a display content parameter of the dynamic effect display, for example, a color parameter in the dynamic effect display process, and the effect parameter may specifically be a list.
In this step, the effect parameter is understood as a set (or collectively referred to) of a plurality of parameters for embodying the display content, and is not understood as one parameter.
403: memory is applied using a kvmalloc function.
After the AGP generates the effect parameters, the effect parameters may be issued to the kernel layer. At the kernel layer, the An Zhuona kernel will apply for memory using the kvmalloc function for storing the effect parameters. The kvmalloc function applies for the memory in the manner from step 4031 to step 4034 in fig. 4:
4031: the kmalloc function is used to apply for contiguous physical memory.
It will be appreciated that the kmamlloc function and the kmamlloc function are two functions, and in the logic for implementing the memory application of the kmamlloc function, the kmamlloc function is preferentially applied to the continuous physical memory, so that the kmamlloc function can be understood as a part of the kmamlloc function implementing logic.
4032: and judging whether the application to the continuous physical memory is successful or not.
If the determination result in step 4032 is no, step 4033 is executed: virtual memory is applied using vmalloc functions.
After step 4033, step 4034 is performed: and obtaining the allocated memory. In this case, the memory applied by the An Zhuona core is virtual memory, i.e. the allocated memory is virtual memory. It will be appreciated that the virtual address space of the memory allocated using the vmalloc function is contiguous and its corresponding physical memory may be discontinuous.
If the determination result in step 4032 is yes, step 4034 is executed: and obtaining the allocated memory. In this case, the memory applied by the An Zhuona core is continuous physical memory, i.e. the allocated memory is continuous physical memory.
In some embodiments, after the application to the memory (which may be understood as obtaining address information of the memory space), the applied memory may be transferred using a binary large object (binary large object, blob), and then the effect parameters of the dynamic effect may be processed and displayed.
404: a blob is created.
In the embodiments of the present application, a blob may be understood as a container for storing binary files. It can be understood that the address information of the memory space obtained after the application to the memory is also data, and the address information of the memory space can be transmitted to the related driver by creating the blob.
405: and (5) processing the effect parameters.
In this step, the display driver of the kernel layer may process the effect parameter, and display the effect parameter on the display screen according to the processing result. It will be appreciated that after the active is displayed, the kernel layer may release the memory allocated in step 4034.
The kvmalloc function is essentially that the kmaleloc function is used to apply for continuous physical memory first, and if the kmaleloc function fails, the vmalloc function is used to apply for virtual memory. It will be appreciated that, after applying for the continuous physical memory using the kmalloc function in step 4031, there is a waiting period, and if the continuous physical memory is not successfully applied for the waiting period, the An Zhuona core applies for the virtual memory using the vmalloc function.
It is easy to understand that if the number of application programs running in the background is too large, the time for An Zhuona core to apply for the memory is too long due to insufficient memory when playing the dynamic effect, so that the phenomenon of frame loss and blocking is caused, and the use experience of a user is seriously affected. Similarly, if the number of application programs running in the background is too large, after the sound effect is selected, the memory is insufficient, so that the An Zhuona core takes too long to apply for the memory, and the use experience of the user is seriously affected due to the phenomenon of playing the card.
In order to improve the efficiency of memory application, the embodiment of the application provides a memory application method. Multiplexing fig. 3, the memory application method provided in the embodiment of the present application may be implemented by a memory application module in the kernel layer.
In one possible implementation, the memory application module described above may be coupled in a An Zhuona core. For ease of understanding, refer to fig. 5, and fig. 5 is a schematic flow chart of a method for applying memory according to an embodiment of the present application.
501: APP dynamic effect display.
502: and generating an effect parameter.
The above step 501 and step 502 may refer to the relevant descriptions of the previous step 401 and step 402, and are not repeated here.
503: the amount of memory required to store the effect parameter is determined.
In this step, the An Zhuona core, after receiving the effect parameter, determines the amount of memory required to store the effect parameter. The required storage space in memory for the effect parameters can be obtained by means of a keyword sizeof, for example.
504: and judging whether the memory demand is greater than or equal to a target threshold.
In this step, the target threshold may be a value set in advance, and may specifically be determined according to the performance of the kvmalloc function. For example, the kvmalloc function may be faster when applying for continuous physical memory within 4KB, but slower when applying for continuous physical memory above 4KB, and then the target threshold may be set to 4KB. Alternatively, the target threshold may be set to be appropriately set up or down as desired.
If the determination result in step 504 is no, step 505 is executed: memory is applied using a kvmalloc function.
It can be appreciated that in the case where the memory requirement is less than the target threshold, the memory requirement for storing the effect parameter may be considered to be less, and at this time, the efficiency of applying for the memory using the kvmalloc function is higher. The specific implementation method of applying the memory using the kvmelloc function in this step may refer to the descriptions of steps 4031-4034, and will not be described herein. It will be appreciated from the description of steps 4031-4034 that the memory applied in this step may be contiguous physical memory or virtual memory.
If the determination result in step 504 is yes, step 506 is executed: virtual memory is applied using vmalloc functions.
It can be appreciated that in the case where the memory demand is greater than or equal to the target threshold, the memory demand storing the effect parameter can be considered to be greater, and the probability of applying to the continuous physical memory is smaller. In this embodiment, if the determination result in step 504 is yes, a vmalloc function is used to apply for the virtual memory.
It will be appreciated that in the above case, if the continuous physical memory is applied first, the virtual memory is applied after the continuous physical memory application fails, and the waiting time for applying the continuous physical memory is wasted. Therefore, in this embodiment, the efficiency of applying for virtual memory by directly using vmalloc function is higher.
After the memory is applied in step 505 or step 506, step 507 is executed: a blob is created.
508: and (5) processing the effect parameters.
The above steps 507 and 508 may refer to the relevant descriptions of the previous steps 404 and 405, and are not repeated here.
It will be appreciated that in some areas the code logic in the An Zhuona core cannot be modified directly, and thus in another possible implementation, the memory application function of the memory application module may be decoupled by a hook (hook) mechanism, and implemented in a self-grinding code bin. Wherein, the self-grinding code bin can be understood as a program outside the official An Zhuona core.
For ease of understanding, referring to fig. 6, fig. 6 is a schematic flow chart of another method for applying memory according to an embodiment of the present application.
601: APP dynamic effect display.
602: and generating an effect parameter.
603: and calling a memory application function through a hook function.
For ease of understanding the hook mechanism, refer to fig. 7 (a), where fig. 7 (a) is a flowchart illustrating execution of a program including hook points according to an embodiment of the present application.
It will be appreciated that, in the case where the program includes a hook point, if the program is executed to the hook point according to the original execution path of the program, the program such as the application trigger event and the background logic processing is executed step by step according to the event flow, the target function bound to the hook point will be called, and after the target function is executed, the program after the hook point is executed, so that the original execution path is restored.
In this embodiment of the present application, the hook point may also be understood as a location of the hook function in the program, and it may be understood that after the hook function is bound to the memory application function, when the program executes to the hook point, the corresponding memory application function will be automatically called. In this embodiment, the memory application function is used to implement the memory application function of the memory application module, and the processing flow of the memory application function includes steps 604-607:
604: the amount of memory required to store the effect parameter is determined.
605: and judging whether the memory demand is greater than or equal to a target threshold.
If the determination result in step 605 is no, step 606 is executed: memory is applied using a kvmalloc function.
If the determination result in step 605 is yes, step 607 is executed: virtual memory is applied using vmalloc functions.
The description of steps 604-607 may refer to steps 503-506, and will not be repeated here. The specific implementation method of applying the memory using the kvmelloc function in this step may refer to the descriptions of steps 4031-4034, and will not be described herein. It can be understood that, in this embodiment, after the memory application function is used to apply for the memory, the obtained memory may be a continuous physical memory or a virtual memory.
After applying to the memory in step 606 or step 607, step 608 is executed: a blob is created.
609: and (5) processing the effect parameters.
The description of steps 608 and 609 may refer to steps 404-405, and will not be repeated here.
In this embodiment, the memory application function in the An Zhuona core is decoupled by the hook function, and the memory application logic is optimized in the memory application function of the self-grinding code bin, that is, different memory application modes are adopted according to the effect parameters with different sizes, so that the efficiency of the memory application can be improved, and the code logic of the official An Zhuona core is not affected. Therefore, the method provided by the embodiment can be used in the areas where the An Zhuona cores are allowed to be modified, and can also be used in the areas where the An Zhuona cores are not allowed to be modified, so that the user experience of each area is improved.
It will be appreciated that prior to invoking the memory application function via the hook function (step 603), the binding of the memory application function to the hook function is also included, and the specific implementation of the binding of the memory application function to the hook function is described below. Referring to fig. 7 (b), fig. 7 (b) is a flowchart of binding a memory application function and a hook function according to an embodiment of the present application. Comprising the following steps:
701: adding a custom header file in the include/trace/hook/directory and declaring a hook function in the custom header file.
The include/trace/hooks/directories can be visually understood as hook folders for storing created hooks. In this step, the custom header file is a.h file, where the file is used to store function declarations, macro definitions, and function prototypes. For example, the name of the custom file may be drm_property.h, and it should be understood that the name of the custom header file may be modified according to actual requirements, which is not limited in this application.
Alternatively, if a module (such as a display module, an audio module or a video module) has made a book function decoupling scheme in order to solve other problems, a header file for declaring a book function must be already included under the include/trace/books/catalogs, and then a code for implementing a memory application related may be directly added to the existing header file.
In this step, after adding the custom header file under the include/trace/hooks/directory, the hook function needs to be declared in the custom header file, or it can be understood as a hook interface required for defining the memory application scheme in this application. Illustratively, the content in the custom header file may be:
1.#undef TRACE_SYSTEM
2.#define TRACE_SYSTEM drm_property
3.#undef TRACE_INCLUDE_PATH
4.#define TRACE_INCLUDE_PATH trace/hooks
5.#if!defined(_TRACE_HOOK_DRM_PROPERTY_H)||defined(TRACE_HEADER_MULTI_READ)
6.#define_TRACE_HOOK_DRM_PROPERTY_H
7.#include<trace/hooks/vendor_hooks.h>
8.DECLARE_HOOK(android_vh_drm_property_alloc,
TP_PROTO(size_t size,void*drm_property),
TP_ARGS(size,drm_property));
9.#endif
10.#include<trace/define_trace.h>
it should be understood that the numbers preceding each line of code in the embodiments of the present application are made for convenience of description, and should not be construed as necessarily including content in the code, nor as an order of execution of the code. The above row 1 and row 2 codes are defined as macros, the first row code indicating that the definition is released in the case where the trace_system is defined; the line 2 code indicates that the drm_property macro is defined as TRACE_SYSTEM, thereby avoiding duplicate definitions. Similarly, the above row 3 and row 4 codes are also defined for macros, the row 3 code representing the undefined case where TRACE_INCLUDE_PATH is defined; line 4 represents defining the dtrace/hooks macro as TRACE_INCLUDE_PATH.
Compiling the code of the 5 th line to the 9 th line under the condition that the adopted format is as follows:
# if-! defined (Condition)
Statement
#endif
Compiling the statement under the condition that the condition is satisfied, wherein the statement can be understood as a collective term of a plurality of statements; if the condition is not satisfied, the process is directly ended. Thus, the above-described line 5-9 code means that the line 6-8 code is compiled in the case of undefined_track_hook_drm_property_h and undefined track_header_multi_read.
Wherein the 6 th line code represents macro definition_trace_hook_drm_property_h. Line 7 indicates that the trace/hop/vendor_hops.h header file is included in the include/trace/hop/dram_property.h file. The code on line 8 represents the declaration HOOK function, which takes the form:
declare_hook (the name of the HOOK function,
TP pro (type of hook function entry),
tp_args (name of hook function entry);
thus, the 8 th line code is used to declare a hook function named android_vh_drm_property_alloc, and the hook function has two entries, the 1 st entry type is the unsigned integer data type size_t, named size; the type of the 2 nd entry is the type-free pointer data type void, named drm_property. In this embodiment of the present application, the 1 st parameter size is the memory requirement amount required for storing the effect parameter, and the 2 nd parameter size is a flag bit, which is used to indicate whether the hook function is successfully called, and is set to 1 if the hook function is successfully called, and is set to 0 if the hook function is not successfully called.
Similarly, the above line 10 code indicates that the trace/define_trace.h header file is included in the include/trace/hops/drm_property.h file.
702: the custom header file is declared in driver/android/vendor_hook.c file and the hook function is derived.
Illustratively, this step may be implemented by the following code:
11.#include<trace/hooks/drm_property.h>
12.EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_drm_property_alloc);
the 11 th line code is used to include the header file trace/hook/dram_property.h added in step 701, so as to include the hook function stated therein, i.e. the android_vh_dram_property_alloc function. Line 12 code is used to export the android_vh_drm_property_alloc function so that the hook function can be called.
703: adding a memory application function in the self-grinding code bin, and registering the memory application function.
In this step, the specific implementation of the memory application function may refer to step 604-step 607 in fig. 6, which is not separately described herein. Illustratively, registering the memory application function may be implemented by:
register_trace_android_vh_drm_property_alloc (memory application function name, NULL);
704: the custom hook function is called in An Zhuona core code.
Illustratively, code calling the hook function may be added to the code module of the memory application, such as may be:
14.trace_android_vh_drm_property_alloc(size,drm_property);
it will be appreciated that the 13 th code can bind the memory application function with the hook function, and when the program is executed, the code contained in the memory application function is executed by calling the hook function to the memory application function bound with the hook function after the 14 th code is added in the An Zhuona core, and then the original execution sequence of the An Zhuona core is returned.
In this embodiment of the present application, the memory application function may also be referred to as a callback function, and the hook function may also be referred to as a hook interface, that is, the An Zhuona core may implement the callback function bound to the hook interface through the hook interface.
It will be appreciated that the above content related to adding a hook function needs to be applied to google, after the application passes, the core An Zhuona may include the codes included in the steps 701, 702 and 704, and the codes of the memory application function in the step 703 are stored in a self-grinding code bin. Illustratively, the code of the registered memory application function in step 703 may be placed in the An Zhuona core or in the self-grinding code bin, where it is necessary to include a trace/hos/dram_property.h header file.
It will be appreciated that the code in the An Zhuona core will be adapted after a successful application to the hook point, but the memory application function is in a self-grinding code bin, rather than containing code to the An Zhuona core. Therefore, in order to reduce the probability of memory application failure caused by the failure of the An Zhuona core to call the memory application function, the memory application may be performed by using the method shown in fig. 8, where fig. 8 is a flow chart of another memory application method according to the embodiment of the present application, including:
801: APP dynamic effect display.
802: and generating an effect parameter.
803: and calling a memory application function through a hook function.
804: the amount of memory required to store the effect parameter is determined.
805: and judging whether the memory demand is greater than or equal to a target threshold.
If the determination result in step 805 is no, step 806 is executed: memory is applied using a kvmalloc function.
If the determination result in step 805 is yes, step 807 is executed: virtual memory is applied using vmalloc functions.
808: and judging whether the memory application function is successfully applied to the memory.
In this step, whether the memory is successfully applied can be judged by the return value of the memory application function, if the return value is empty, the memory application function can be considered to be failed to apply the memory, and if the return value is valid, the memory application function can be considered to be successful to apply the memory.
If the determination result in step 808 is no, step 809 is executed: memory is applied using a kvmalloc function.
If the determination result in step 808 is yes, it may be considered that the application to the memory is successful through the memory application function, and step 810 is executed: a blob is created.
Step 811: and (5) processing the effect parameters.
In this embodiment, after the memory application function is called through the hook interface to apply for the memory, the memory is reapplied by the method shown in fig. 4, i.e. the kvmalloc function is directly used to apply for the memory. After memory application function is called through a hook interface to apply for memory successfully, a blob is created based on the applied memory, and then effect parameters are processed. By the method, the probability of memory application failure caused by the failure of the An Zhuona core to call the memory application function can be reduced.
It will be appreciated that the above descriptions of steps 801-805, and steps 810-811 may refer to the relevant descriptions of fig. 4, and are not repeated here.
It can be understood that the methods shown in fig. 4, fig. 5, fig. 6, and fig. 8 are described above by taking the effect parameters of the dynamic display as an example, but the application scenario of the method provided in the present application is not limited thereto. The effect parameter may be an audio parameter of music playing software or video playing software, or an effect parameter used for modifying a picture in the process of editing the picture, etc.
The present application also provides a computer readable storage medium having computer code stored therein, which when run on a computer causes the computer to perform the method of the above-described embodiments.
The application also provides a chip, which comprises a logic circuit and an interface, wherein the logic circuit is coupled with the interface; the interface is configured to input and/or output code instructions, and the logic is configured to execute the code instructions, so that the method in the method of the above embodiment is performed.
The present application also provides a computer program product comprising computer code or a computer program which, when run on a computer, causes the method in the above embodiments to be performed.
As used in the above embodiments, the term "when …" may be interpreted to mean "if …" or "after …" or "in response to determination …" or "in response to detection …" depending on the context. Similarly, the phrase "at the time of determination …" or "if detected (a stated condition or event)" may be interpreted to mean "if determined …" or "in response to determination …" or "at the time of detection (a stated condition or event)" or "in response to detection (a stated condition or event)" depending on the context.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by a wired (e.g., coaxial cable, fiber optic, digital subscriber line), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk), etc.
Those of ordinary skill in the art will appreciate that implementing all or part of the above-described method embodiments may be accomplished by a computer program to instruct related hardware, the program may be stored in a computer readable storage medium, and the program may include the above-described method embodiments when executed. And the aforementioned storage medium includes: ROM or random access memory RAM, magnetic or optical disk, etc.
It should be further understood that the foregoing is merely a specific embodiment of the present application, and the scope of the present application is not limited thereto, and any person skilled in the art who is skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and it is intended to cover all those changes and substitutions within the scope of the present application. The scope of the present application is therefore intended to be limited only by the scope of the appended claims.

Claims (11)

1. The memory application method is characterized by being applied to electronic equipment, wherein the memory of the electronic equipment comprises a first type of storage unit and a second type of storage unit, and the operation efficiency of the second type of storage unit is higher than that of the first type of storage unit, and the method comprises the following steps:
Receiving a system message, wherein the system message is used for indicating to store data to be stored;
determining the memory demand required by storing the data to be stored;
and applying for the memory from the first-type storage unit under the condition that the memory demand is greater than a first threshold value.
2. The method according to claim 1, wherein the method further comprises:
and applying for the memory from the second type of storage unit under the condition that the memory demand is smaller than the first threshold value.
3. The method according to claim 2, wherein the method further comprises:
and under the condition that the application of the memory from the second type of memory unit fails, the application of the memory from the first type of memory unit is performed.
4. A method according to any of claims 1-3, characterized in that a hook function is included in a kernel program of the electronic device; the receiving system message includes:
and the memory application function receives the system message sent by the hook function, and the memory application function is other programs except the kernel program.
5. The method of claim 4, wherein the execution environment of the hook function comprises a function declaration of the hook function and a derivation function of the hook function; the function declaration is used for defining a function name, a function type and input parameters of the hook function, and the export function is used for enabling the hook function to be called by the kernel program.
6. The method of claim 4 or 5, wherein the running environment of the memory application function includes a registration function of the memory application function, the registration function being used to bind the memory application function with the hook function.
7. The method according to any one of claims 4-6, further comprising:
and under the condition that the memory application function fails to apply for the memory from the first type of storage unit and fails to apply for the memory from the second type of storage unit, the kernel program applies for the memory from the second type of storage unit, or the kernel program applies for the memory from the first type of storage unit.
8. The method of any of claims 1-7, wherein the first type of storage unit is virtual memory and the second type of storage unit is physical memory.
9. An electronic device, comprising a processor and a memory, wherein the memory is used for storing a computer program, the memory of the memory comprises a first type storage unit and a second type storage unit, and the operation efficiency of the second type storage unit is higher than that of the first type storage unit; the computer program comprising program instructions, the processor being configured to invoke the program instructions such that the method of any of claims 1-8 is performed.
10. A chip comprising logic circuitry and an interface, the logic circuitry and interface coupled; the interface being for inputting and/or outputting code instructions, the logic circuitry being for executing the code instructions to cause the method of any of claims 1-8 to be performed.
11. A computer readable storage medium, characterized in that the computer readable storage medium stores a computer program comprising program instructions which, when executed by a processor, cause the method according to any of claims 1-8 to be performed.
CN202310745337.4A 2023-06-21 2023-06-21 Memory application method and related device Active CN117687770B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310745337.4A CN117687770B (en) 2023-06-21 2023-06-21 Memory application method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310745337.4A CN117687770B (en) 2023-06-21 2023-06-21 Memory application method and related device

Publications (2)

Publication Number Publication Date
CN117687770A true CN117687770A (en) 2024-03-12
CN117687770B CN117687770B (en) 2024-09-13

Family

ID=90130751

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310745337.4A Active CN117687770B (en) 2023-06-21 2023-06-21 Memory application method and related device

Country Status (1)

Country Link
CN (1) CN117687770B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140250286A1 (en) * 2013-03-04 2014-09-04 Hitach, Ltd Computer and memory management method
CN104750855A (en) * 2015-04-16 2015-07-01 成都睿峰科技有限公司 Method and device for optimizing big data storage
CN104794190A (en) * 2015-04-16 2015-07-22 成都睿峰科技有限公司 Method and device for effectively storing big data
US20190066791A1 (en) * 2017-08-30 2019-02-28 Paolo Papa Log data storage for flash memory
CN113050886A (en) * 2021-02-23 2021-06-29 山东师范大学 Nonvolatile memory storage method and system for embedded memory database
CN113076069A (en) * 2021-04-29 2021-07-06 平安科技(深圳)有限公司 Double-cache method and device, electronic equipment and computer readable storage medium
CN115237607A (en) * 2022-09-21 2022-10-25 北京中科网威信息技术有限公司 Memory configuration method and device, electronic equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140250286A1 (en) * 2013-03-04 2014-09-04 Hitach, Ltd Computer and memory management method
CN104750855A (en) * 2015-04-16 2015-07-01 成都睿峰科技有限公司 Method and device for optimizing big data storage
CN104794190A (en) * 2015-04-16 2015-07-22 成都睿峰科技有限公司 Method and device for effectively storing big data
US20190066791A1 (en) * 2017-08-30 2019-02-28 Paolo Papa Log data storage for flash memory
CN113050886A (en) * 2021-02-23 2021-06-29 山东师范大学 Nonvolatile memory storage method and system for embedded memory database
CN113076069A (en) * 2021-04-29 2021-07-06 平安科技(深圳)有限公司 Double-cache method and device, electronic equipment and computer readable storage medium
CN115237607A (en) * 2022-09-21 2022-10-25 北京中科网威信息技术有限公司 Memory configuration method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN117687770B (en) 2024-09-13

Similar Documents

Publication Publication Date Title
WO2020108356A1 (en) Application display method and electronic device
CN114443277A (en) Memory management method and device, electronic equipment and computer readable storage medium
CN113553130B (en) Method for executing drawing operation by application and electronic equipment
CN118733254A (en) Task processing method, device, terminal and computer readable storage medium
WO2021093626A1 (en) Memory management method and electronic device
WO2021185352A1 (en) Version upgrade method and related apparatus
CN112882823A (en) Screen display method and electronic equipment
CN117130541B (en) Storage space configuration method and related equipment
CN116828100A (en) Bluetooth audio playing method, electronic equipment and storage medium
CN112783418B (en) Method for storing application program data and mobile terminal
CN114079642A (en) Mail processing method and electronic equipment
CN116662270B (en) File analysis method and related device
CN115482143B (en) Image data calling method and system for application, electronic equipment and storage medium
CN117687770B (en) Memory application method and related device
CN113590346B (en) Method and electronic equipment for processing service request
CN114691248B (en) Method, device, equipment and readable storage medium for displaying virtual reality interface
WO2021238376A1 (en) Function pack loading method and apparatus, and server and electronic device
CN114828098B (en) Data transmission method and electronic equipment
CN115081010A (en) Distributed access control method, related device and system
CN114398108A (en) Electronic device, drive loading method thereof, and medium
CN114816028A (en) Screen refreshing method, electronic device and computer-readable storage medium
CN116627855B (en) Memory processing method and related device
CN116709609B (en) Message delivery method, electronic device and storage medium
WO2024045841A1 (en) Storage method and apparatus, and electronic device
CN116703689B (en) Method and device for generating shader program and electronic equipment

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
GR01 Patent grant
GR01 Patent grant