WO2023273766A1 - Compilation optimization method and apparatus - Google Patents

Compilation optimization method and apparatus Download PDF

Info

Publication number
WO2023273766A1
WO2023273766A1 PCT/CN2022/096071 CN2022096071W WO2023273766A1 WO 2023273766 A1 WO2023273766 A1 WO 2023273766A1 CN 2022096071 W CN2022096071 W CN 2022096071W WO 2023273766 A1 WO2023273766 A1 WO 2023273766A1
Authority
WO
WIPO (PCT)
Prior art keywords
member variable
address
variable
electronic device
storage
Prior art date
Application number
PCT/CN2022/096071
Other languages
French (fr)
Chinese (zh)
Inventor
季柯丞
李文韬
彭卓立
邱榆
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2023273766A1 publication Critical patent/WO2023273766A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/61Installation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the embodiments of the present application relate to the field of electronic equipment, and in particular, to a compiling optimization method and device.
  • the electronic device can read data from the memory into the cache during operation, so as to use the fast read and write capabilities of the cache to improve the operating efficiency of the electronic device.
  • the electronic device can search the member variable from the cache. If the member variable is not found in the cache, the electronic device can search the member variable from the memory, and read the member variable into the cache, so as to call the member variable from the cache.
  • Embodiments of the present application provide a compiling optimization method and device, which can reduce inefficiency caused by filling operations while reading multiple frequently accessed data (such as member variables) at one time.
  • a compiling optimization method which is applied to electronic devices, and the method includes: when installing an application program, or after installing the application program, when compiling the application program, sorting the application program according to the access frequency
  • the storage order of the member variables of the first structure of the program, the member variables include the first member variable and the second member variable, the access frequency of the first member variable is higher than that of the second member variable, the storage of the first member variable order before this second member variable.
  • the member variable is byte-aligned by padding.
  • the first padding field is used for byte alignment of the first member variable.
  • the size of the first padding field is greater than or equal to the size of the second member variable.
  • a solution for optimizing the storage of member variables is provided. It can be understood that by storing the frequently accessed member variables at the front position, the electronic device can read the frequently accessed member variables more quickly for use, thereby reducing the read time required for reading the frequently accessed member variables. Fetch operations, thereby reducing latency and power consumption.
  • the electronic device can also fill smaller member variables into the address segment filled in the front position, so that the electronic device can reduce the proportion of the filled address segment while reading high-frequency member variables , to increase the proportion of valid data in the read data. In this way, it is possible to reduce the reduction in data reading efficiency caused by the filling operation.
  • the method further includes: adjusting access to the member according to the storage address of the first member variable and/or the second member variable The offset of the variable. Based on this solution, after adjusting the storage order of different member variables in the memory, the processor can also adjust the offsets in instructions that call these member variables. Therefore, the corresponding member variables can be correctly called according to the optimized storage order.
  • the method before sorting the storage order of the member variables of the first structure of the application program according to the access frequency, the method further includes: acquiring the first structure during the operation of the electronic device The access frequency of each of this member variables in .
  • a scheme before sorting member variables is provided. For example, the access frequency of each member variable during operation can be obtained. In this way, the storage order of the member variables is optimized and adjusted according to the access frequency. For example, member variables with high access frequency can be stored before member variables with low access frequency.
  • the method further includes: searching for a second address of an unstored member variable, where the second address is the first address in the current storage order 2.
  • the first address of the filled field After the second address, a third member variable is searched, the storage address of the third member variable is after the second address, and the size of the fifth member variable is smaller than the size of the second filling field.
  • the data of the third member variable is stored in the second filling field.
  • Fig. 5 is a schematic diagram of optimizing the sequence of member variables
  • Fig. 6 is a schematic diagram of an optimized member variable sequence
  • Fig. 7 is a schematic diagram of optimizing the order of member variables
  • FIG. 8 is a schematic composition diagram of an electronic device provided by an embodiment of the present application.
  • FIG. 9 is a software structural block diagram of an electronic device provided in an embodiment of the present application.
  • FIG. 10 is a schematic flowchart of a compiling optimization method provided in the embodiment of the present application.
  • Figure 11 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application.
  • Figure 12 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application.
  • Figure 13 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application.
  • Figure 14 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application.
  • Figure 15 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application.
  • FIG. 20 is a schematic composition diagram of a chip system provided by an embodiment of the present application.
  • the read/write capability of the CPU may be identified by the read/write bandwidth of the CPU.
  • the read and write bandwidth of the CPU is much higher than the data read and write speed provided by the memory. In this way, by setting the cache, the inefficiency caused by the difference between the read and write bandwidth of the CPU and the read and write speed of the memory can be alleviated.
  • a cache in an electronic device may include multiple layers. Different layers have different read and write speeds. For example, refer to FIG. 2 . Take the cache includes level 1 cache (L1 cache, L1), level 2 cache (L2 cache, L2), and level 3 cache (L3 cache, L3) as an example.
  • L1, L2 and L3 can all be integrated in the CPU.
  • the read and write speeds of different layers are in order from fast to slow: L1 is faster than L2 and faster than L3.
  • caches with higher read/write speeds have higher power consumption and cost. Therefore, in some embodiments, the capacities of different layers are in descending order: L3 is greater than L2 and greater than L1.
  • the CPU When the CPU needs to retrieve data, it can find out whether there is required data from L1. If not, look in L2. If the data is found in L2, then the CPU can read the data from L2 into L1 to get the data through L1. Conversely, if the data is still not found in L2, the CPU can continue to search in L3. Similar to the processing mechanism in L2, if the data is found in L3, the CPU can read the data into L1 through L2, so as to obtain the data through L1. Conversely, if the data is still not encountered in L3, the CPU can look for the data in the memory. It is understandable that if the CPU does not find the required data in L1, L2, and L3, it means that the CPU fails to find the data in the cache, which will cause a cache miss. Similar to the processing mechanism in the cache, if the CPU finds the required data in the memory, the CPU can read the data into L1 through L3 and L2, so as to obtain the data through L1.
  • the program can include:
  • the electronic device may perform instrumentation (or called dotting) on the code when compiling the code of the structure member for the first time.
  • members of the structure include member 1 , member 2 , member 3 and member 4 as an example.
  • the electronic device can insert the detection identifier into the code segment corresponding to each member in the code of the structure member.
  • the detection identifier 1 is inserted before the first byte of the code segment corresponding to member 1.
  • Insert detection flag 2 before the first byte of the code segment corresponding to member 2.
  • Insert detection flag 3 before the first byte of the code segment corresponding to member 3.
  • Insert detection flag 4 before the first byte of the code segment corresponding to member 4.
  • the position of the stub may also be the middle or the end of the code segment corresponding to the member.
  • the number of visits of stub insertion may correspond to the number of visits of the inserted detection identifier.
  • the electronic device may obtain the code segment after running the above instrumentation.
  • the electronic device can provide the required runtime (runtime) for running the code segment through a related process.
  • runtime the electronic device can access the code segment obtained after instrumentation as shown in FIG. 4 , thereby simulating the access frequency of each member during the running of the application program.
  • each member inserts the detection identifier in the form of instrumentation. Therefore, the electronic device can determine the access frequency of the corresponding member by detecting the identified access frequency.
  • the electronic device determines that the detection flag 1 has been called a times, the detection flag 2 has been called b times, and the detection flag 3 has been called c times. Identity 4 is called d times. Then, the electronic device can determine that the visit frequency of member 1 is a times, the visit frequency of member 2 is b times, the visit frequency of member 3 is c times, and the visit frequency of member 4 is d times.
  • the electronic device can acquire the access information of each member.
  • the visit information of member 1 includes a visit frequency of a times.
  • Member 2's visit information includes a visit frequency of b times.
  • the visit information of member 3 includes a visit frequency of c times.
  • the visit information of member 4 includes a visit frequency of d times.
  • the electronic device can adjust the declaration order of different members according to the access information of each member (such as the access frequency in the access information), so that the declaration order of high-frequency members can be adjusted to adjacent or similar Location.
  • the order of declaration can also be the order in which members are stored in memory.
  • the electronic device may advance the declarations of members with high access frequency and backward the declarations of members with low access frequency.
  • the declaration order of member 1-member 4 may be: member 1-member 2-member 3-member 4. Take the descending order of each access frequency as a>c>d>b as an example.
  • the adjusted declaration order of member 1-member 4 may be: member 1-member 3-member 4-member 2. It can be seen that through the adjustment of the order of declaration, member 2 with the lowest access frequency is adjusted to the end of the code of the structure. Therefore, when the electronic device calls the structure from the memory to the cache, it can preferentially call the members with higher access frequency.
  • zygote64 AOSP virtual machine process
  • the corresponding application sub-process running process will be started based on the shared library, and the member access frequency information corresponding to each structure object will be counted. Access the corresponding cfi_info members of the CompileMethod class, and less access to the vmap_table members. After the JIT thread completes the access to the members of the CompileMethod class for many times, it will backfill the access information to the profile file of the data partition through the buffer.
  • the sum of the data volumes of Member 1 and Member 3 is less than the read bandwidth of the CPU. Therefore, the CPU can read all the data of Member 1 and Member 3 into the cache with one read. middle.
  • the read bandwidth of the CPU can not only cover all the data of member 1 and member 3, but also cover part of the data of member 4. Since the read bandwidth of the CPU limits the start address when the CPU reads data (that is, the start address is generally an integer multiple of the CPU read bandwidth), therefore, when the CPU needs to read all the data of member 4 into the cache, It is necessary to read the data of 0x00-0x07 and the data of 0x08-0x0f respectively. That is, two read operations are performed to read the full amount of data of member 4 into the cache.
  • the read bandwidth of the CPU is generally greater than the data volume of the member variables. Therefore, it is inefficient to use two reads to read one member variable into the cache.
  • padding can be used to adjust the first address of the member variables that cannot be read into the cache at one time among the member variables after data structure optimization to the CPU reading bandwidth.
  • the first address and the last address of the data of member 4 will span one read bandwidth of the CPU (such as 0x00-0x07).
  • the electronic device can adjust the addresses of the member variables in the structure again. For example, the electronic device can fill invalid data (or fill empty data) between the next address of the end address of member 3 and the end address of the current CPU read bandwidth, so as to adjust the first address of the data of member 4 to that of the CPU. The location of the first address of the next read bandwidth.
  • the first address of member 4 can be 0x08. In this way, when the CPU needs to read member 4 into the cache, it can perform a read operation on the address 0x08-0x1f, thereby realizing the effect of reading the full amount of data of member 4 into the cache.
  • the filling operation shown in FIG. 7 above inefficiency in the data reading process can be avoided.
  • the filling operation will significantly increase the data volume of the structure. For example, referring to FIG. 7 , after the filling operation, compared with before the filling operation, the invalid data between member 3 and member 4, and the invalid data between member 4 and member 2 are added to the structure. In this way, a large amount of memory space will be occupied and the space utilization rate will be reduced.
  • multiple member variables can be read in with one read operation, but due to the filling of the high-frequency member variables at the front position , which may cause a read operation to fail to read these infrequently accessed member variables. This also leads to inefficiencies at the system level.
  • the embodiment of the present application provides a data structure optimization solution, which enables the electronic device to read multiple frequently accessed data (such as member variables) at one time, while reducing the inefficiency caused by the filling operation.
  • the data structure optimization solution shown in FIG. 3 is called member variable rearrangement
  • the filling operation shown in FIG. 7 is called data alignment optimization.
  • the electronic device involved in the embodiment of the present application may be a mobile phone, a tablet computer, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) device,
  • PDA personal digital assistant
  • AR augmented reality
  • VR virtual reality
  • a portable mobile device such as a media player
  • the electronic device can also be a wearable electronic device such as a smart watch.
  • the embodiment of the present application does not specifically limit the specific form of the device.
  • FIG. 8 is a schematic structural diagram of an electronic device 800 provided by an embodiment of the present application.
  • the electronic device 800 may include a processor 810, an external memory interface 820, an internal memory 821, and a universal serial bus (universal serial bus, USB) interface 830, charging management module 840, power management module 841, battery 842, antenna 1, antenna 2, mobile communication module 850, wireless communication module 860, audio module 870, speaker 870A, receiver 870B, microphone 870C, earphone jack 870D, sensor module 880, button 890, motor 891, indicator 892, camera 893, display screen 894, subscriber identification module (subscriber identification module, SIM) card interface 895, etc.
  • SIM subscriber identification module
  • the sensor module 880 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.
  • the structure shown in this embodiment does not constitute a specific limitation on the electronic device 800 .
  • the electronic device 800 may include more or fewer components than shown, or combine certain components, or separate certain components, or arrange different components.
  • the illustrated components can be realized in hardware, software or a combination of software and hardware.
  • the controller may be the nerve center and command center of the electronic device 800 .
  • the controller can generate an operation control signal according to the instruction opcode and timing signal, and complete the control of fetching and executing the instruction.
  • processor 810 may include one or more interfaces.
  • the interface 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 transmitter (universal asynchronous receiver/transmitter, UART) interface, mobile industry processor 810 interface (mobile industry processor interface, MIPI), general-purpose input and output (general-purpose input/output, GPIO) interface, subscriber identity module (subscriber identity module, SIM) interface, And/or a universal serial bus (universal serial bus, USB) interface, etc.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous transmitter
  • mobile industry processor 810 interface mobile industry processor interface, MIPI
  • general-purpose input and output general-purpose input/output, GPIO
  • subscriber identity module subscriber identity
  • the electronic device 800 can realize the shooting function through an ISP, a camera 893 , a video codec, a GPU, a display screen 894 , and an application processor.
  • the ISP is used to process the data fed back by the camera 893 .
  • the light is transmitted to the photosensitive element of the camera 893 through the lens, the light signal is converted into an electrical signal, and the photosensitive element of the camera 893 transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye.
  • ISP can also perform algorithm optimization on image noise, brightness, and skin color. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene.
  • the ISP may be located in the camera 893 .
  • Camera 893 is used to capture still images or video.
  • the object generates an optical image through the lens and projects it to the photosensitive element.
  • the photosensitive element may be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor.
  • CMOS complementary metal-oxide-semiconductor
  • the photosensitive element converts the light signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal.
  • the ISP outputs the digital image signal to the DSP for processing.
  • DSP converts digital image signals into standard RGB, YUV and other image signals.
  • the electronic device 800 may include one or more cameras 893 .
  • Video codecs are used to compress or decompress digital video.
  • the electronic device 800 may support one or more video codecs.
  • the electronic device 800 can play or record videos in various encoding formats, for example: moving picture experts group (moving picture experts group, MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
  • MPEG moving picture experts group
  • the charging management module 840 is configured to receive charging input from the charger.
  • the charger may be a wireless charger or a wired charger.
  • the charging management module 840 can receive the charging input of the wired charger through the USB interface 830 .
  • the charging management module 840 may receive wireless charging input through a wireless charging coil of the electronic device 800 . While the charging management module 840 is charging the battery 842 , it can also supply power to the electronic device 800 through the power management module 841 .
  • the power management module 841 is used for connecting the battery 842 , the charging management module 840 and the processor 810 .
  • the power management module 841 receives the input of the battery 842 and/or the charging management module 840, and provides power for the processor 810, the internal memory 821, the external memory, the display screen 894, the camera 893, and the wireless communication module 860, etc.
  • the power management module 841 can also be used to monitor parameters such as the capacity of the battery 842 , the number of cycles of the battery 842 , and the state of health of the battery 842 (leakage, impedance).
  • the power management module 841 may also be set in the processor 810 .
  • the power management module 841 and the charging management module 840 may also be set in the same device.
  • Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals.
  • Each antenna in electronic device 800 may be used to cover single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas.
  • Antenna 1 can be multiplexed as a diversity antenna of a wireless local area network.
  • the antenna may be used in conjunction with a tuning switch.
  • the wireless communication module 860 can provide wireless local area networks (wireless local area networks, WLAN) (such as wireless fidelity (Wireless fidelity, Wi-Fi) network), bluetooth (bluetooth, BT), global navigation satellite, etc. System (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR) and other wireless communication solutions.
  • the wireless communication module 860 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 860 receives electromagnetic waves via the antenna 2 , frequency-modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 810 .
  • the wireless communication module 860 can also receive the signal to be sent from the processor 810, frequency-modulate it, amplify it, and convert it into electromagnetic waves through the antenna 2 to radiate out.
  • the display screen 894 is used to display images, videos and the like.
  • Display 894 includes a display panel.
  • the display panel can adopt liquid crystal display 894 (liquid crystal display, LCD), organic light-emitting diode (organic light-emitting diode, OLED), active matrix organic light-emitting diode or active-matrix organic light-emitting diode (active-matrix organic light emitting diode, AMOLED), flexible light-emitting diode (flex light-emitting diode, FLED), Miniled, MicroLed, Micro-oLed, quantum dot light emitting diodes (quantum dot light emitting diodes, QLED), etc.
  • the electronic device 800 may include 1 or N display screens 894, where N is a positive integer greater than 1.
  • the external memory interface 820 can be used to connect an external memory card, such as a Micro SD card, to expand the storage resources of the electronic device 800.
  • the external memory card communicates with the processor 810 through the external memory interface 820 to realize the data storage function. Such as saving music, video and other files in the external memory card.
  • the audio module 870 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signal.
  • the audio module 870 may also be used to encode and decode audio signals.
  • the audio module 870 may be set in the processor 810 , or some functional modules of the audio module 870 may be set in the processor 810 .
  • Receiver 870B also called “earpiece” is used to convert audio electrical signals into sound signals.
  • the receiver 870B can be placed close to the human ear to receive the voice.
  • Microphone 870C also known as “microphone” or “microphone” is used to convert sound signals into electrical signals.
  • the user can make a sound by approaching the microphone 870C with a human mouth, and input the sound signal into the microphone 870C.
  • the electronic device 800 may be provided with at least one microphone 870C.
  • the electronic device 800 may be provided with two microphones 870C, which may also implement a noise reduction function in addition to collecting sound signals.
  • the electronic device 800 can also be provided with three, four or more microphones 870C to collect sound signals, reduce noise, identify sound sources, and realize directional recording functions, etc.
  • the gyro sensor can be used to determine the motion posture of the electronic device 800 .
  • the angular velocity of the electronic device 800 around three axes may be determined by a gyro sensor.
  • the gyro sensor can be used for image stabilization. Exemplarily, when the shutter is pressed, the gyro sensor detects the shaking angle of the electronic device 800, calculates the distance that the lens module needs to compensate according to the angle, and allows the lens to counteract the shaking of the electronic device 800 through reverse movement to achieve anti-shake.
  • Gyroscope sensors can also be used for navigation and somatosensory game scenes.
  • Magnetic sensors include Hall sensors.
  • the electronic device 800 may use a magnetic sensor to detect opening and closing of the flip leather case.
  • the electronic device 800 may detect opening and closing of the flip according to the magnetic sensor.
  • features such as automatic unlocking of the flip cover are set.
  • the acceleration sensor can detect the acceleration of the electronic device 800 in various directions (generally three axes). When the electronic device 800 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device 800, and can be used in applications such as horizontal and vertical screen switching, pedometers, etc.
  • the electronic device 800 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 800 may use a distance sensor to measure a distance to achieve fast focusing.
  • the ambient light sensor is used to sense the ambient light brightness.
  • the electronic device 800 can adaptively adjust the brightness of the display screen 894 according to the perceived ambient light brightness.
  • the ambient light sensor can also be used to automatically adjust the white balance when taking pictures.
  • the ambient light sensor can also cooperate with the proximity light sensor to detect whether the electronic device 800 is in the pocket, so as to prevent false touches.
  • the fingerprint sensor is used to collect fingerprints.
  • the electronic device 800 can use the collected fingerprint characteristics to implement fingerprint unlocking, access to application locks, take pictures with fingerprints, answer incoming calls with fingerprints, and the like.
  • a temperature sensor is used to detect temperature.
  • the electronic device 800 uses the temperature detected by the temperature sensor to implement a temperature processing strategy. For example, when the temperature reported by the temperature sensor exceeds the threshold, the electronic device 800 may reduce the performance of the processor 810 located near the temperature sensor, so as to reduce power consumption and implement thermal protection.
  • the electronic device 800 heats the battery 842 to prevent the electronic device 800 from being shut down abnormally due to the low temperature.
  • the electronic device 800 boosts the output voltage of the battery 842 to avoid abnormal shutdown caused by low temperature.
  • Bone conduction sensors can pick up vibration signals.
  • the bone conduction sensor can acquire the vibration signal of the vibrating bone mass of the human voice.
  • Bone conduction sensors can also contact the human pulse and receive blood pressure beating signals.
  • the bone conduction sensor can also be disposed in the earphone, combined into a bone conduction earphone.
  • the audio module 870 can analyze the voice signal based on the vibration signal of the vibrating bone mass of the vocal part acquired by the bone conduction sensor, so as to realize the voice function.
  • the application processor can analyze the heart rate information based on the blood pressure beating signal acquired by the bone conduction sensor, so as to realize the heart rate detection function.
  • the keys 890 include a power key, a volume key and the like.
  • the key 890 may be a mechanical key 890 . It can also be a touch button 890 .
  • the electronic device 800 can receive the key 890 input, and generate key signal input related to the user setting and function control of the electronic device 800 .
  • the motor 891 can generate a vibrating prompt.
  • the motor 891 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.
  • touch operations applied to different applications may correspond to different vibration feedback effects.
  • the motor 891 can also correspond to different vibration feedback effects for touch operations on different areas of the display screen 894 .
  • Different application scenarios for example: time reminder, receiving information, alarm clock, games, etc.
  • the touch vibration feedback effect can also support customization.
  • the indicator 892 can be an indicator light, and can be used to indicate charging status, power change, and can also be used to indicate messages, missed calls, notifications, and the like.
  • the SIM card interface 895 is used for connecting a SIM card.
  • the SIM card can be connected and separated from the electronic device 800 by inserting it into the SIM card interface 895 or pulling it out from the SIM card interface 895 .
  • the electronic device 800 may support 1 or N SIM card interfaces 895, where N is a positive integer greater than 1.
  • SIM card interface 895 can support Nano SIM card, Micro SIM card, SIM card, etc. Multiple cards can be inserted into the same SIM card interface 895 at the same time. The types of the multiple cards may be the same or different.
  • the SIM card interface 895 is also compatible with different types of SIM cards.
  • the SIM card interface 895 is also compatible with external memory cards.
  • the electronic device 800 interacts with the network through the SIM card to implement functions such as calling and data communication.
  • the electronic device 800 adopts an eSIM, that is, an embedded SIM card.
  • the eSIM card can be embedded in the electronic device 800 and cannot be separated from the electronic device 800 .
  • the electronic device 800 may include more components, or, the electronic device 800 may simplify some components in the composition as shown in FIG. .
  • a software system may run in the electronic device 800 .
  • the software system may adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture.
  • the software structure of the electronic device 800 will be described below by taking the Android system with a layered architecture as an example of the software system in the electronic device 800 .
  • the layered architecture provided by the embodiment of the present application can divide the software into several layers, and each layer has a clear role and division of labor. Layers communicate through software interfaces.
  • FIG. 9 is a software structural block diagram of an electronic device provided in an embodiment of the present application.
  • the Android system may include 3 software layers. From top to small are application 901 , runtime (runtime) 902 , and kernel 903 .
  • the application 901 may also include an application layer and an application framework layer.
  • the application framework layer can provide an application programming interface (application programming interface, API) and a programming framework for applications in the application layer.
  • the application framework layer may also include some predefined functions.
  • the application framework layer may include a window manager, a content provider, a view system, a resource manager, a notification manager, an event manager, an input manager, and the like.
  • the resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and so on.
  • the notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages, and can automatically disappear after a short stay without user interaction.
  • the notification manager is used to notify the download completion, message reminder, etc.
  • the notification manager can also be a notification that appears on the top status bar of the system in the form of a chart or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, issuing a prompt sound, vibrating the electronic device, and flashing the indicator light, etc.
  • the activity manager can provide activity management service (Activity Manager Service, AMS), AMS can be used for system components (such as activities, services, content providers, broadcast receivers) to start, switch, schedule, and manage and schedule application processes .
  • the input manager can provide input management service (Input Manager Service, IMS), and IMS can be used to manage the input of the system, such as touch screen input, key input, sensor input, etc.
  • IMS fetches events from input device nodes, and distributes events to appropriate windows through interaction with WMS.
  • the runtime 902 can provide the runtime environment in the current operating system.
  • the runtime 902 may include the Android runtime.
  • the electronic device runs multiple applications at the same time, different applications may be configured with their own independent runtimes, and the runtimes may correspond to the virtual machines described above.
  • the Android runtime can be used to convert source code into machine code.
  • Android runtime can support profile technology and JIT compilation technology.
  • the core library can be used to provide the functionality of the basic ART class library.
  • libraries such as basic data structures, mathematics, input/output (IO), tools, databases, and networks.
  • the core library provides APIs for users to develop Android applications.
  • runtime 902 may also include language libraries such as native C/C++ libraries.
  • Multiple functional modules can be included.
  • surface manager surface manager
  • media framework Media Framework
  • libc OpenGL ES
  • SQLite Webkit
  • Webkit a language library
  • the surface manager is used to manage the display subsystem, and provides the fusion of 2D and 3D layers for multiple applications.
  • the media framework supports playback and recording of various commonly used audio and video formats, as well as still image files.
  • the media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
  • OpenGL ES provides the drawing and manipulation of 2D graphics and 3D graphics in applications.
  • SQLite provides a lightweight relational database for the application of the electronic device 100 .
  • a hardware abstraction layer may also be set between the runtime 902 and the kernel 903 .
  • the hardware is abstracted to run in user space, encapsulates the kernel 903 driver, and provides a call interface to the upper layer.
  • the software combination shown in FIG. 9 is only a possible implementation, and does not constitute any limitation to the solution provided by the embodiment of the present application.
  • the runtime 902 and the kernel 903 may also be divided into a virtual layer.
  • the following S1004 may be executed continuously.
  • the electronic device can dump the data of B to the address segment filled with 1 anywhere in the .
  • the electronic device may dump the data of B to a location where the first address of the address segment in filling 1 is used as a starting point. That is to say, after dumping, the first address of B can be the same as the first address filled with 1 before dumping.
  • the first address of B can be 0x02. It can be understood that, in other implementations of the present application, the address segment corresponding to B after dumping may also have the same end address as the address segment corresponding to filling 1 before dumping.
  • FIG. 14 shows a data structure after dumping the first member variable.
  • the electronic device can read the three member variables of ABF into the cache through one read operation. Compared with directly reading the data structure shown in Figure 12, more member variables can be read at one time, and at the same time, invalid storage due to padding in the cache can be reduced.
  • the electronic device after the electronic device dumps the first member variable into the first filling field, it can fill in the address segment where the first member variable was originally stored, so as to release the corresponding storage space.
  • the electronic device after dumping B to fill 1, the electronic device can fill in the address segment where B was originally stored.
  • this part of the space after filling can correspond to fill 5 as shown in FIG. 5 .
  • the electronic device may also combine padding 5 with adjacent padding 2 to form a continuous padding field.
  • FIG. 15 shows a schematic of this example after Fill 2 growth. It can be seen that after padding 2 grows, its first address is the same as the first address of the address segment where B was originally stored. Thus, the purpose of releasing the storage space of the address segment of B originally stored is achieved.
  • S1004 can be executed repeatedly after S1005 is executed, so that the electronic device can Reuse the member variables that meet the requirements to fill in the front filling fields, so that the overall data structure of the structure is more compact, and the filling fields occupy less storage space.
  • the electronic device may acquire the data structure shown in FIG. 11 .
  • the member variables in the data structure corresponding to the second optimization result may form a stack.
  • the distribution of data in the stack can be the same as the data structure shown in FIG. 11 . That is to say, in this stack, the member variables can be: AFBCDGE according to the sequence of addresses.
  • the electronic device can realize the effects of S1005-S1006 in the following manner.
  • the electronic device can traverse the data stored in the structure starting from the first address of the member variable of the data structure (such as 0x00 in the above example) (such as executing S1601).
  • the electronic device can determine whether the stored data at the current address is a member variable (for example, execute S1602). If it is a member variable, execute the following S1603. It can be understood that if the data stored at the current address is a member variable, it indicates that the filling field has not been found yet. Then the electronic device can pop the variable stored at the address from the stack, and read the content of the next address bit (that is, execute S1603).
  • the electronic device may repeatedly execute S1602 until the content of the current address bit is invalid data filled in during the fill operation, then the electronic device may execute the following S1604. It can be understood that when the content of the current address is invalid data filled by the filling operation, it indicates that the current address is the first address of the filling field generated by the filling operation (such as corresponding to the first address of the first filling field in the above example). That is to say, through the above S1601-S1603, the first padding field as in S1004 can be determined.
  • the electronic device may traverse the member variables in the stack after the current address, so as to obtain the first member variable that meets the requirements (that is, execute S1604).
  • the electronic device may continue to perform traversal backwards. until obtaining a member variable whose size is less than or equal to the size of the first filled field (corresponding to the first member variable that meets the requirements in the above example).
  • the electronic device may replace the content of the first member variable into the filled first address of the current stack (for example, execute S1605). In this way, the transfer of the first member variable to the first filling field can be realized. It can be understood that when S1603 is executed, the member variable before the filling field has been popped out, therefore, when the first member variable is dumped, the first filling address of the current stack is the first filling address of the first filling field .
  • FIG. 17 shows a schematic diagram of the effect of performing multiple optimizations on the data structure of the structure according to the solution provided by the embodiment of the present application.
  • the electronic device can dump C into the address segment corresponding to filling 1 as shown in (a) in FIG. 17 .
  • a data structure as shown in (b) in FIG. 17 can be obtained.
  • the electronic device can also dump D into the address segment corresponding to filling 2.
  • a data structure as shown in (c) in FIG. 17 can be obtained.
  • the electronic device can also dump E into the address segment corresponding to filling 2.
  • a data structure as shown in (d) in FIG. 17 can be obtained.
  • the storage space of the memory can be utilized to a greater extent, and the CPU can read more valid data into the cache through one read operation, and at the same time reduce invalid storage
  • the consumption of memory and cache improves the utilization of storage space.
  • the embodiments of the present application may divide the involved devices into functional modules according to the above method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or in the form of software function modules. It should be noted that the division of modules in the embodiment of the present application is schematic, and is only a logical function division, and there may be other division methods in actual implementation.
  • the device further includes: an adjusting unit 1804, configured to, after storing the second member variable into the first filling field, according to the storage of the first member variable and/or the second member variable Address, adjust the offset to access the member variable.
  • an adjusting unit 1804 configured to, after storing the second member variable into the first filling field, according to the storage of the first member variable and/or the second member variable Address, adjust the offset to access the member variable.
  • the device further includes: an acquisition unit 1805, configured to acquire the storage order of the member variables of the first structure of the application program according to the access frequency, and acquire the , the access frequency of each member variable in the first structure.
  • an acquisition unit 1805 configured to acquire the storage order of the member variables of the first structure of the application program according to the access frequency, and acquire the , the access frequency of each member variable in the first structure.
  • the first byte width is determined according to the read bandwidth of the processor of the electronic device, and the read bandwidth of the processor is when the processor performs a read operation, it can read the maximum amount of data.
  • the device further includes: a search unit 1806, configured to search for the member variable of the first structure of the application program before storing the second member variable in the first filling field. After the sequence is stored, the first address of the member variable is not stored, and the first address is the first address of the first filled field.
  • the search unit 1806 is further configured to search for the second member variable after the first address, the storage address of the second member variable is after the first address, and the size of the second member variable is smaller than that of the first padding field size.
  • the storage unit 1803 is configured to store the data of the fourth member variable in the first filling field.
  • the storage unit 1803 is configured to fill the storage address of the second member variable after the storage order of the member variables of the first structure of the application program with invalid data.
  • the device further includes: a deleting unit 1807, configured to delete the data in the storage address of the second member variable after the storage order of the member variables of the first structure of the application program.
  • FIG. 19 shows a schematic composition diagram of an electronic device 1900 .
  • the electronic device 1900 may include: a processor 1901 and a memory 1902 .
  • the memory 1902 is used to store computer-executable instructions.
  • the processor 1901 executes the instructions stored in the memory 1902
  • the electronic device 1900 may be made to execute the compilation optimization method shown in any one of the above embodiments.
  • FIG. 20 shows a schematic composition diagram of a chip system 2000 .
  • the chip system 2000 may include: a processor 2001 and a communication interface 2002, configured to support related devices to implement the functions involved in the foregoing embodiments.
  • the chip system further includes a memory for saving necessary program instructions and data of the terminal.
  • the system-on-a-chip may consist of chips, or may include chips and other discrete devices.
  • the communication interface 2002 may also be called an interface circuit.
  • the functions or actions or operations or steps in the above-mentioned embodiments may be fully or partially implemented by software, hardware, firmware or any combination thereof.
  • a software program When implemented using a software program, it 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 the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application will be generated in whole or in part.
  • the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices.

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

A compilation optimization method and apparatus, which relate to the field of electronic devices, enabling an electronic device to reduce low efficiency caused by padding operations while reading multiple pieces of high-frequency access data at a time. A specific solution is as follows: according to access frequency, sorting the storage order of member variables of a first struct of an application, the member variables comprising a first member variable and a second member variable, the access frequency of the first member variable being higher than that of the second member variable, and the storage order of the first member variable comes before that of the second member variable; and according to the width of a first byte, performing byte alignment on the member variables by means of padding fields, wherein a first padding field is used to perform byte alignment on the first member variable, the second member variable is stored in the first padding field, and the size of the first padding field is greater than or equal to that of the second member variable.

Description

一种编译优化方法和装置A compilation optimization method and device
本申请要求于2021年06月30日提交国家知识产权局、申请号为202110738730.1、申请名称为“一种编译优化方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202110738730.1 and the application title "A method and device for compiling optimization" submitted to the State Intellectual Property Office on June 30, 2021, the entire contents of which are incorporated in this application by reference middle.
技术领域technical field
本申请实施例涉及电子设备领域,尤其涉及一种编译优化方法和装置。The embodiments of the present application relate to the field of electronic equipment, and in particular, to a compiling optimization method and device.
背景技术Background technique
电子设备可以在运行的过程中,从内存将数据读入缓存,以便利用缓存的快速读写能力提升电子设备的运行效率。The electronic device can read data from the memory into the cache during operation, so as to use the fast read and write capabilities of the cache to improve the operating efficiency of the electronic device.
可以理解的是,电子设备在运行过程中,需要调用不同的成员变量。比如,电子设备可以在需要使用成员变量时,从缓存中查找该成员变量。如果在缓存中没有查找到该成员变量,那么电子设备可以从内存中查找该成员变量,并将该成员变量读入缓存中,以便从缓存中调用该成员变量。It can be understood that, during the operation of the electronic device, different member variables need to be called. For example, when the electronic device needs to use the member variable, it can search the member variable from the cache. If the member variable is not found in the cache, the electronic device can search the member variable from the memory, and read the member variable into the cache, so as to call the member variable from the cache.
由于缓存的容量有限,一般无法存储大量的成员变量。因此,电子设备就会频繁地由于无法从缓存中查找到需要的成员变量,而需要从内存中进行读取操作。由此会带来显著的访问延迟以及大量读取操作引入的功耗开销。Due to the limited capacity of the cache, it is generally impossible to store a large number of member variables. Therefore, the electronic device will frequently need to read from the memory because it cannot find the required member variables from the cache. This results in significant access latency and power consumption overhead from a large number of read operations.
发明内容Contents of the invention
本申请实施例提供一种编译优化方法和装置,能够使得电子设备可以一次性读取多个高频访问的数据(如成员变量)的同时,降低由于填充操作导致的低效率。Embodiments of the present application provide a compiling optimization method and device, which can reduce inefficiency caused by filling operations while reading multiple frequently accessed data (such as member variables) at one time.
为了达到上述目的,本申请实施例采用如下技术方案:In order to achieve the above purpose, the embodiment of the present application adopts the following technical solutions:
第一方面,提供一种编译优化方法,应用于电子设备,该方法包括:在安装应用程序时,或者安装该应用程序之后,在对该应用程序进行编译时,根据该访问频率,排序该应用程序的第一结构体的成员变量的存储顺序,该成员变量包括第一成员变量和第二成员变量,该第一成员变量的访问频率高于该第二成员变量,该第一成员变量的存储顺序在该第二成员变量之前。根据第一字节宽度,通过填充字段对该成员变量进行字节对齐。其中,第一填充字段用于对该第一成员变量进行字节对齐。将该第二成员变量存入该第一填充字段。该第一填充字段的大小大于或等于该第二成员变量的大小。In the first aspect, a compiling optimization method is provided, which is applied to electronic devices, and the method includes: when installing an application program, or after installing the application program, when compiling the application program, sorting the application program according to the access frequency The storage order of the member variables of the first structure of the program, the member variables include the first member variable and the second member variable, the access frequency of the first member variable is higher than that of the second member variable, the storage of the first member variable order before this second member variable. Based on the first byte width, the member variable is byte-aligned by padding. Wherein, the first padding field is used for byte alignment of the first member variable. Store the second member variable into the first filling field. The size of the first padding field is greater than or equal to the size of the second member variable.
基于该方案,提供了一种优化成员变量的存储的方案。可以理解的是,通过将高频访问的成员变量存储在靠前的位置,能够使得电子设备可以更加快速地读取高频成员变量进行使用,由此可以减少读取高频成员变量需要的读取操作的数量,从而减少时延和功耗。在本示例中,电子设备还可以将较小的成员变量填充到靠前位置中填充的地址段中,从而使得电子设备在读取高频成员变量的同时,能够减少填充的地址段的占比,提升读取数据中的有效数据的占比。由此就可以达到降低由于填充操作导致的数据读取效率降低情况发生。Based on this solution, a solution for optimizing the storage of member variables is provided. It can be understood that by storing the frequently accessed member variables at the front position, the electronic device can read the frequently accessed member variables more quickly for use, thereby reducing the read time required for reading the frequently accessed member variables. Fetch operations, thereby reducing latency and power consumption. In this example, the electronic device can also fill smaller member variables into the address segment filled in the front position, so that the electronic device can reduce the proportion of the filled address segment while reading high-frequency member variables , to increase the proportion of valid data in the read data. In this way, it is possible to reduce the reduction in data reading efficiency caused by the filling operation.
在一种可能的设计中,在该将第二成员变量存入第一填充字段之后,该方法还包括:根据该第一成员变量和/或该第二成员变量的存储地址,调整访问该成员变量的偏 移量。基于该方案,在调整不同成员变量在内存中的存储顺序之后,处理器还可以调整调用这些成员变量的指令中的偏移量。从而能够根据优化后的存储顺序正确调用对应的成员变量。In a possible design, after storing the second member variable into the first padding field, the method further includes: adjusting access to the member according to the storage address of the first member variable and/or the second member variable The offset of the variable. Based on this solution, after adjusting the storage order of different member variables in the memory, the processor can also adjust the offsets in instructions that call these member variables. Therefore, the corresponding member variables can be correctly called according to the optimized storage order.
在一种可能的设计中,在该根据该访问频率,排序该应用程序的第一结构体的成员变量的存储顺序之前,该方法还包括:获取该电子设备运行过程中,该第一结构体中的每个该成员变量的访问频率。基于该方案,提供了一种对成员变量进行排序之前的方案示例。比如,可以获取各个成员变量在运行过程中的访问频率。从而根据访问频率对成员变量的存储顺序进行优化调整。比如可以将访问频率较高的成员变量存储在访问频率较低的成员变量之前。In a possible design, before sorting the storage order of the member variables of the first structure of the application program according to the access frequency, the method further includes: acquiring the first structure during the operation of the electronic device The access frequency of each of this member variables in . Based on this scheme, an example of a scheme before sorting member variables is provided. For example, the access frequency of each member variable during operation can be obtained. In this way, the storage order of the member variables is optimized and adjusted according to the access frequency. For example, member variables with high access frequency can be stored before member variables with low access frequency.
在一种可能的设计中,该第一字节宽度是根据该电子设备的处理器的读取带宽确定的,该处理器的读取带宽是该处理器执行一次读取操作时,能够读取的最大数据量。基于该方案,提供了一种第一字节宽度的示例。比如,第一字节宽度可以是根据处理器的读取带宽确定的。作为一种示例,根据不同的处理器的架构,其读取带宽可以不同。以64位***为例,其读取带宽可以为2比特,4比特,8比特等。In a possible design, the first byte width is determined according to the read bandwidth of the processor of the electronic device, and the read bandwidth of the processor is when the processor performs a read operation, it can read the maximum amount of data. Based on this solution, an example of the first byte width is provided. For example, the first byte width may be determined according to the read bandwidth of the processor. As an example, according to different processor architectures, their read bandwidths may be different. Taking a 64-bit system as an example, its read bandwidth can be 2 bits, 4 bits, 8 bits, etc.
在一种可能的设计中,该获取该电子设备运行过程中,该第一结构体中的每个该成员变量的访问频率,包括:对该第一结构体中每个该成员变量执行插桩操作,根据该应用程序进行编译过程中,***各个成员变量的检测标识的调用次数,确定每个该成员变量的访问频率。基于该方案,提供了一种确定成员变量的读取频率的方案示例。在本示例中,每个成员变变量可以通过插桩***各自对应的检测标识。根据检测标识的调用次数,就能够确定对应成员变量的访问频率。In a possible design, the obtaining the access frequency of each member variable in the first structure during the operation of the electronic device includes: performing instrumentation on each member variable in the first structure According to the operation, during the compilation process of the application program, the calling times of the detection identification of each member variable are inserted, and the access frequency of each member variable is determined. Based on this solution, an example of a solution for determining the reading frequency of member variables is provided. In this example, each member variable can be inserted into its corresponding detection identifier through instrumentation. According to the calling times of the detection flag, the access frequency of the corresponding member variable can be determined.
在一种可能的设计中,在将该第二成员变量存入该第一填充字段之前,该方法还包括:查找该排序该应用程序的第一结构体的成员变量的存储顺序后,未存储成员变量的第一地址,该第一地址是该第一填充字段的首地址。在该第一地址之后,查找该第二成员变量,该第二成员变量的存储地址在该第一地址之后,该第二成员变量的大小小于该第一填充字段的大小。该将该第一优化结果中,第一成员变量存入第一填充字段,包括:将该第四成员变量的数据,存储的到该第一填充字段中。基于该方案,提供了一种具体的使用存储靠后的成员变量补充填充区域的方案示例。比如,可以根据首地址未存储有效的成员变量数据确定该首地址为第一填充字段的首地址。对应的,还可以在该第一填充字段之后,查找首地址存储有有效的成员变量的存储段,则该存储段的内容就可以是一个成员变量。当该成员变量的存储地址的下一个地址存储有无效数据时,则该存储地址就可以是当前成员变量的长度。类似的,电子设备可以确定第一填充字段的长度,并在后续存储地址中查找长度不超过第一填充字段的长度的成员变量。这样,将该符合要求的成员变量填充到填充字段,就能够实现减小填充字段的效果。同时,电子设备原先读取该第一填充字段的读取操作可以同时读入第二成员变量,这样也能够提升读取操作的效率。In a possible design, before storing the second member variable into the first filling field, the method further includes: after searching for the storage order of the member variables of the first structure of the application program, the unstored The first address of the member variable, where the first address is the first address of the first filled field. After the first address, the second member variable is searched, the storage address of the second member variable is after the first address, and the size of the second member variable is smaller than the size of the first filling field. The storing the first member variable of the first optimization result into the first filling field includes: storing the data of the fourth member variable into the first filling field. Based on this solution, a specific example of using member variables stored later to supplement the filling area is provided. For example, it may be determined that the first address is the first address of the first filling field according to the fact that no effective member variable data is stored in the first address. Correspondingly, after the first filling field, it is also possible to search for a storage segment in which a valid member variable is stored in the first address, and then the content of the storage segment can be a member variable. When invalid data is stored in the address next to the storage address of the member variable, the storage address may be the length of the current member variable. Similarly, the electronic device may determine the length of the first padding field, and search for a member variable whose length does not exceed the length of the first padding field in subsequent storage addresses. In this way, filling the required member variable into the filling field can realize the effect of reducing the filling field. At the same time, the original read operation of the electronic device to read the first filling field can simultaneously read the second member variable, which can also improve the efficiency of the read operation.
在一种可能的设计中,该方法还包括:对该第二成员变量在该排序该应用程序的第一结构体的成员变量的存储顺序后的存储地址填充无效数据。或者,删除该第二成员变量在该排序该应用程序的第一结构体的成员变量的存储顺序后的存储地址中的数据。基于该方案,提供了一种成员变量被填充到填充字段之后,原先存储该成员变量 的地址段的处理机制。示例性的,可以将该原先存储该成员变量的地址段中的数据删除,由此释放对应的存储空间,或者可以在原先存储该成员变量的地址段中填充无效数据,从而避免该第四成员变量的重复存储和读取。In a possible design, the method further includes: filling the storage address of the second member variable after the storage order of the member variables of the first structure of the application program with invalid data. Or, delete the data in the storage address of the second member variable after the storage order of the member variables of the first structure of the application program. Based on this scheme, a processing mechanism for the address segment where the member variable is originally stored after the member variable is filled into the filled field is provided. Exemplarily, the data in the address segment that originally stored the member variable can be deleted, thereby releasing the corresponding storage space, or the address segment that originally stored the member variable can be filled with invalid data, thereby avoiding the fourth member Repeated storage and reading of variables.
在一种可能的设计中,在将该第二成员变量存入该第一填充字段之后,该方法还包括:查找未存储成员变量的第二地址,该第二地址是当前存储顺序中的第二填充字段的首地址。在该第二地址之后,查找第三成员变量,该第三成员变量的存储地址在该第二地址之后,该第五成员变量的大小小于该第二填充字段的大小。将该第三成员变量的数据,存储的到该第二填充字段中。基于该方案,在完成了对第一填充字段的成员变量的填充之后,还可以对后续的填充字段(如第二填充字段)进行填充。由此就能够进一步缩小填充字段在存储空间中的占比,从而提升读取效率。In a possible design, after storing the second member variable into the first filling field, the method further includes: searching for a second address of an unstored member variable, where the second address is the first address in the current storage order 2. The first address of the filled field. After the second address, a third member variable is searched, the storage address of the third member variable is after the second address, and the size of the fifth member variable is smaller than the size of the second filling field. The data of the third member variable is stored in the second filling field. Based on this solution, after completing the filling of the member variables of the first filling field, subsequent filling fields (such as the second filling field) may also be filled. In this way, the proportion of the filling field in the storage space can be further reduced, thereby improving the reading efficiency.
第二方面,提供一种编译优化装置,应用于电子设备,该装置包括:排序单元,用于,在安装应用程序时,或者安装该应用程序之后,在对该应用程序进行编译时,根据该访问频率,排序该应用程序的第一结构体的成员变量的存储顺序,该成员变量包括第一成员变量和第二成员变量,该第一成员变量的访问频率高于该第二成员变量,该第一成员变量的存储顺序在该第二成员变量之前。填充单元,用于根据第一字节宽度,通过填充字段对该成员变量进行字节对齐。其中,第一填充字段用于对该第一成员变量进行字节对齐。存储单元,用于将该第二成员变量存入该第一填充字段。该第一填充字段的大小大于或等于该第二成员变量的大小。In a second aspect, a compiling optimization device is provided, which is applied to an electronic device, and the device includes: a sorting unit, configured to, when installing an application program, or after installing the application program, compile the application program according to the access frequency, sort the storage order of the member variables of the first structure of the application program, the member variables include the first member variable and the second member variable, the access frequency of the first member variable is higher than the second member variable, the The storage sequence of the first member variable is before the second member variable. The padding unit is used to perform byte alignment on the member variable through the padding field according to the first byte width. Wherein, the first padding field is used for byte alignment of the first member variable. The storage unit is used to store the second member variable into the first filling field. The size of the first padding field is greater than or equal to the size of the second member variable.
在一种可能的设计中,该装置还包括:调整单元,用于在该将第二成员变量存入第一填充字段之后,根据该第一成员变量和/或该第二成员变量的存储地址,调整访问该成员变量的偏移量。In a possible design, the device further includes: an adjustment unit, configured to, after storing the second member variable into the first filling field, according to the storage address of the first member variable and/or the second member variable , adjust the offset to access the member variable.
在一种可能的设计中,该装置还包括:获取单元,用于在该根据该访问频率,排序该应用程序的第一结构体的成员变量的存储顺序之前,获取该电子设备运行过程中,该第一结构体中的每个该成员变量的访问频率。In a possible design, the device further includes: an acquisition unit, configured to acquire, before sorting the storage order of the member variables of the first structure of the application program according to the access frequency, during the operation of the electronic device, The access frequency of each member variable in the first structure.
在一种可能的设计中,该第一字节宽度是根据该电子设备的处理器的读取带宽确定的,该处理器的读取带宽是该处理器执行一次读取操作时,能够读取的最大数据量。In a possible design, the first byte width is determined according to the read bandwidth of the processor of the electronic device, and the read bandwidth of the processor is when the processor performs a read operation, it can read the maximum amount of data.
在一种可能的设计中,获取单元,用于对该第一结构体中每个该成员变量执行插桩操作,根据该应用程序进行编译过程中,***各个成员变量的检测标识的调用次数,确定每个该成员变量的访问频率。In a possible design, the acquisition unit is configured to perform an instrumentation operation for each member variable in the first structure, and according to the number of calls of the detection identifier of each member variable inserted during the compilation process of the application program, Determines the access frequency for each of this member variables.
在一种可能的设计中,该装置还包括:查找单元,用于在将该第二成员变量存入该第一填充字段之前,查找该排序该应用程序的第一结构体的成员变量的存储顺序后,未存储成员变量的第一地址,该第一地址是该第一填充字段的首地址。查找单元,还用于在该第一地址之后,查找该第二成员变量,该第二成员变量的存储地址在该第一地址之后,该第二成员变量的大小小于该第一填充字段的大小。存储单元,用于将该第四成员变量的数据,存储的到该第一填充字段中。In a possible design, the device further includes: a lookup unit, configured to look up the storage of the member variable of the first structure of the application program before storing the second member variable into the first filling field After the sequence, the first address of the member variable is not stored, and the first address is the first address of the first filled field. The search unit is also used to search for the second member variable after the first address, the storage address of the second member variable is after the first address, and the size of the second member variable is smaller than the size of the first padding field . The storage unit is used to store the data of the fourth member variable in the first filling field.
在一种可能的设计中,存储单元,用于对该第二成员变量在该排序该应用程序的第一结构体的成员变量的存储顺序后的存储地址填充无效数据。或者,该装置还包括:删除单元,用于删除该第二成员变量在该排序该应用程序的第一结构体的成员变量的存储顺序后的存储地址中的数据。In a possible design, the storage unit is configured to fill the storage address of the second member variable after the storage order of the member variables of the first structure of the application program with invalid data. Alternatively, the device further includes: a deletion unit, configured to delete the data in the storage address of the second member variable after the storage order of the member variables of the first structure of the application program.
在一种可能的设计中,查找单元,用于在将该第二成员变量存入该第一填充字段之后,查找未存储成员变量的第二地址,该第二地址是当前存储顺序中的第二填充字段的首地址。查找单元,用于在该第二地址之后,查找第三成员变量,该第三成员变量的存储地址在该第二地址之后,该第五成员变量的大小小于该第二填充字段的大小。存储单元,用于将该第三成员变量的数据,存储的到该第二填充字段中。In a possible design, the search unit is configured to search for a second address of an unstored member variable after the second member variable is stored in the first filling field, and the second address is the first address in the current storage order 2. The first address of the filled field. The search unit is configured to search for a third member variable after the second address, the storage address of the third member variable is after the second address, and the size of the fifth member variable is smaller than the size of the second padding field. The storage unit is used to store the data of the third member variable in the second filling field.
第三方面,提供一种电子设备,电子设备包括一个或多个处理器和一个或多个存储器;一个或多个存储器与一个或多个处理器耦合,一个或多个存储器存储有计算机指令;当一个或多个处理器执行计算机指令时,使得电子设备执行如上述第一方面以及各种可能的设计中任一种的编译优化方法。In a third aspect, an electronic device is provided, and the electronic device includes one or more processors and one or more memories; the one or more memories are coupled to the one or more processors, and the one or more memories store computer instructions; When one or more processors execute computer instructions, the electronic device is made to execute the compiling optimization method in the above first aspect and any one of various possible designs.
第四方面,提供一种芯片***,芯片***包括接口电路和处理器;接口电路和处理器通过线路互联;接口电路用于从存储器接收信号,并向处理器发送信号,信号包括存储器中存储的计算机指令;当处理器执行计算机指令时,芯片***执行如上述第一方面以及各种可能的设计中任一种的编译优化方法。In the fourth aspect, a chip system is provided, the chip system includes an interface circuit and a processor; the interface circuit and the processor are interconnected through lines; the interface circuit is used to receive signals from the memory and send signals to the processor, and the signals include the data stored in the memory Computer instruction: when the processor executes the computer instruction, the system-on-a-chip executes the compiling optimization method in any one of the first aspect and various possible designs.
第五方面,提供一种计算机可读存储介质,计算机可读存储介质包括计算机指令,当计算机指令运行时,执行如上述第一方面以及各种可能的设计中任一种的编译优化方法。In a fifth aspect, a computer-readable storage medium is provided, the computer-readable storage medium includes computer instructions, and when the computer instructions are run, the compilation optimization method in the above-mentioned first aspect and any one of various possible designs is executed.
第六方面,提供一种计算机程序产品,计算机程序产品中包括指令,当计算机程序产品在计算机上运行时,使得计算机可以根据指令执行如上述第一方面以及各种可能的设计中任一种的编译优化方法。According to the sixth aspect, a computer program product is provided, and the computer program product includes instructions. When the computer program product is run on the computer, the computer can execute any one of the above-mentioned first aspect and various possible designs according to the instructions. Compile optimization method.
应当理解的是,上述第二方面,第三方面,第四方面,第五方面以及第六方面提供的技术方案,其技术特征均可对应到第一方面及其可能的设计中提供的方案,因此能够达到的有益效果类似,此处不再赘述。It should be understood that the technical features of the technical solutions provided by the second aspect, the third aspect, the fourth aspect, the fifth aspect and the sixth aspect can all correspond to the solutions provided in the first aspect and its possible designs, Therefore, the beneficial effects that can be achieved are similar and will not be repeated here.
附图说明Description of drawings
图1为一种电子设备中的存储介质的组成示意图;FIG. 1 is a schematic diagram of the composition of a storage medium in an electronic device;
图2为一种存储介质的组成示意图;Fig. 2 is a schematic composition diagram of a storage medium;
图3为一种数据结构优化的方案示意图;Fig. 3 is a schematic diagram of a data structure optimization scheme;
图4为一种插桩的示意图;Fig. 4 is a schematic diagram of pile insertion;
图5为一种优化成员变量顺序的示意图;Fig. 5 is a schematic diagram of optimizing the sequence of member variables;
图6为一种优化成员变量顺序的示意图;Fig. 6 is a schematic diagram of an optimized member variable sequence;
图7为一种优化成员变量顺序的示意图;Fig. 7 is a schematic diagram of optimizing the order of member variables;
图8为本申请实施例提供的一种电子设备的组成示意图;FIG. 8 is a schematic composition diagram of an electronic device provided by an embodiment of the present application;
图9为本申请实施例提供的一种电子设备的软件结构框图;FIG. 9 is a software structural block diagram of an electronic device provided in an embodiment of the present application;
图10为本申请实施例提供的一种编译优化方法的流程示意图;FIG. 10 is a schematic flowchart of a compiling optimization method provided in the embodiment of the present application;
图11为本申请实施例提供的一种成员变量的分布示意图;Figure 11 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application;
图12为本申请实施例提供的一种成员变量的分布示意图;Figure 12 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application;
图13为本申请实施例提供的一种成员变量的分布示意图;Figure 13 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application;
图14为本申请实施例提供的一种成员变量的分布示意图;Figure 14 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application;
图15为本申请实施例提供的一种成员变量的分布示意图;Figure 15 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application;
图16为本申请实施例提供的一种编译优化方法的流程示意图;FIG. 16 is a schematic flowchart of a compiling optimization method provided in the embodiment of the present application;
图17为本申请实施例提供的一种成员变量的分布示意图;Figure 17 is a schematic diagram of the distribution of a member variable provided by the embodiment of the present application;
图18为本申请实施例提供的一种数据结构的优化装置组成示意图;FIG. 18 is a schematic diagram of the composition of a data structure optimization device provided by the embodiment of the present application;
图19为本申请实施例提供的一种电子设备的组成示意图;FIG. 19 is a schematic diagram of the composition of an electronic device provided by an embodiment of the present application;
图20为本申请实施例提供的一种芯片***的组成示意图。FIG. 20 is a schematic composition diagram of a chip system provided by an embodiment of the present application.
具体实施方式detailed description
在电子设备中可以设置有存储介质,用于存储电子设备运行过程中需要的数据。在一些实施例中,电子设备中的存储介质可以包括多种类型。示例性的,结合图1,为一种电子设备中的存储介质的组成示意图。如图1所示,在该示例中,电子设备中的存储介质可以包括硬盘,内存,以及缓存(cache)。其中,硬盘可以提供较大的存储空间,可以用于存储大量的数据。电子设备在运行过程中,对硬盘中的数据的读写速度相对较慢。内存也可以提供一部分存储空间。相较于硬盘提供的存储空间,内存中的数据可以被快速读写。一般而言,处于成本等考虑,内存提供的存储空间小于硬盘提供的存储空间。在电子设备中,还可以设置有缓存。缓存具有快速的读写特性。也就是说,在电子设备运行过程中,处理器可以最快的速度对缓存中的数据执行读写操作。类似于内存与硬盘的关系,缓存可以提供如图1所示的所有存储介质中,最快的读写速度,但是出于成本以及功耗的考虑,缓存的容量一般较小。A storage medium may be provided in the electronic device for storing data required during operation of the electronic device. In some embodiments, the storage medium in the electronic device may include multiple types. Exemplarily, with reference to FIG. 1 , it is a schematic composition diagram of a storage medium in an electronic device. As shown in FIG. 1 , in this example, the storage medium in the electronic device may include a hard disk, a memory, and a cache (cache). Among them, the hard disk can provide a larger storage space and can be used to store a large amount of data. During the operation of the electronic device, the reading and writing speed of the data in the hard disk is relatively slow. Memory can also provide a portion of storage space. Compared with the storage space provided by the hard disk, the data in the memory can be read and written quickly. Generally speaking, due to cost and other considerations, the storage space provided by the memory is smaller than that provided by the hard disk. In an electronic device, a buffer may also be provided. The cache has fast read and write characteristics. That is to say, during the operation of the electronic device, the processor can perform read and write operations on the data in the cache at the fastest speed. Similar to the relationship between the memory and the hard disk, the cache can provide the fastest read and write speed among all the storage media shown in Figure 1, but due to cost and power consumption considerations, the cache capacity is generally small.
这样,通过如图1所示的存储介质的配置,电子设备就可以将数据在存储介质中进行分级存储。比如,电子设备可以将大量的数据存储在硬盘中。在电子设备运行应用程序(application,APP,简称为应用)过程时,可以从硬盘中调取运行该应用(如应用1)需要的数据,存储在内存中。在对应用1的运行过程中,电子设备可以将即将使用的部分数据(如应用1的代码中的类,结构体等)从内存中读取到缓存中,以便于在使用这些数据时,可以进行快速读写。In this way, through the configuration of the storage medium shown in FIG. 1 , the electronic device can store data in the storage medium hierarchically. For example, an electronic device can store a large amount of data in a hard disk. When an electronic device is running an application program (application, APP, referred to as an application), the data required to run the application (such as application 1) can be retrieved from the hard disk and stored in the memory. During the running of application 1, the electronic device can read some of the data to be used (such as classes and structures in the code of application 1) from the memory into the cache, so that when using these data, it can For fast reading and writing.
可以理解的是,随着电子设备的发展,处理器(Central Processing Unit,CPU)的读写能力快速提升。在一些实施例中,可以通过CPU的读写带宽标识CPU的读写能力。目前,CPU的读写带宽已经远高于内存所提供的数据读写速度。这样,通过设置缓存,就可以缓解CPU读写带宽与内存读写速度之间的差异引起的低效率。It is understandable that with the development of electronic equipment, the reading and writing capabilities of a processor (Central Processing Unit, CPU) increase rapidly. In some embodiments, the read/write capability of the CPU may be identified by the read/write bandwidth of the CPU. At present, the read and write bandwidth of the CPU is much higher than the data read and write speed provided by the memory. In this way, by setting the cache, the inefficiency caused by the difference between the read and write bandwidth of the CPU and the read and write speed of the memory can be alleviated.
在一些实施例中,电子设备中的缓存可以包括多个层。不同层的读写速度不同。示例性的,结合图2。以缓存中包括1级缓存(L1cache,L1),2级缓存(L2cache,L2),3级缓存(L3cache,L3)为例。在本申请的一些实施例中,L1、L2以及L3都可以集成在CPU中。其中,不同层的读写速度由快到慢依次为:L1快于L2快于L3。对应的,具有较高读写速度的缓存由于功耗和成本都较高,因此,在一些实施例中,不同层的容量大小由大到小依次为:L3大于L2大于L1。In some embodiments, a cache in an electronic device may include multiple layers. Different layers have different read and write speeds. For example, refer to FIG. 2 . Take the cache includes level 1 cache (L1 cache, L1), level 2 cache (L2 cache, L2), and level 3 cache (L3 cache, L3) as an example. In some embodiments of the present application, L1, L2 and L3 can all be integrated in the CPU. Among them, the read and write speeds of different layers are in order from fast to slow: L1 is faster than L2 and faster than L3. Correspondingly, caches with higher read/write speeds have higher power consumption and cost. Therefore, in some embodiments, the capacities of different layers are in descending order: L3 is greater than L2 and greater than L1.
在CPU需要调取数据时,可以从L1中寻找是否有需要的数据。如果没有,则在L2中寻找。如果在L2中找到了该数据,那么CPU可以将该数据从L2中读入L1,以便通过L1获取该数据。反之,如果在L2中依然没有找到该数据,则CPU可以继续在L3中寻找。类似于L2中的处理机制,如果在L3中找到了该数据,那么CPU就可以将该数据通过L2读入L1,以便通过L1获取该数据。反之,如果在L3中依然没有遭到该数据,则CPU就可以在内存中寻找该数据。可以理解的是,如果CPU在L1,L2以及L3中都没有找到需要的数据,那么表明CPU在缓存中的数据查找失败,由此 就会造成缓存访问缺失(cache miss)。类似于在缓存中的处理机制,如果CPU在内存中查找到了需要的数据,那么CPU就可以将该数据通过L3,L2读入L1,以便通过L1获取该数据。When the CPU needs to retrieve data, it can find out whether there is required data from L1. If not, look in L2. If the data is found in L2, then the CPU can read the data from L2 into L1 to get the data through L1. Conversely, if the data is still not found in L2, the CPU can continue to search in L3. Similar to the processing mechanism in L2, if the data is found in L3, the CPU can read the data into L1 through L2, so as to obtain the data through L1. Conversely, if the data is still not encountered in L3, the CPU can look for the data in the memory. It is understandable that if the CPU does not find the required data in L1, L2, and L3, it means that the CPU fails to find the data in the cache, which will cause a cache miss. Similar to the processing mechanism in the cache, if the CPU finds the required data in the memory, the CPU can read the data into L1 through L3 and L2, so as to obtain the data through L1.
显而易见的,CPU在缓存中读取数据时,如果出现缓存访问缺失,就会产生高额的访问延迟。Obviously, when the CPU reads data in the cache, if there is a cache access miss, high access latency will be generated.
为了尽可能地减少缓存访问缺失的出现,可以通过修改代码当中成员变量的声明顺序,达到提升数据结构的空间局部性的效果。比如,可以手动调整相近的成员变量的声明顺序。这样,CPU可以在从内存中读取某个成员变量(如成员变量1)时,一同将其他相近的成员变量(如成员变量2)读入缓存中。在CPU需要访问成员变量2时,该成员变量2就已经被读入缓存中。由此就不会出现缓存访问缺失的情况。进而避免对应的访问延迟,提升***效率。In order to reduce the occurrence of cache access misses as much as possible, the effect of improving the spatial locality of the data structure can be achieved by modifying the declaration order of the member variables in the code. For example, you can manually adjust the declaration order of adjacent member variables. In this way, when the CPU reads a certain member variable (such as member variable 1) from the memory, it can simultaneously read other similar member variables (such as member variable 2) into the cache. When the CPU needs to access the member variable 2, the member variable 2 has already been read into the cache. As a result, there will be no cache access misses. This avoids corresponding access delays and improves system efficiency.
然而,随着程序代码体量的快速增长,手动执行上述声明顺序的调整变得异常困难。However, with the rapid growth of the program code volume, it becomes extremely difficult to manually perform the adjustment of the above declaration order.
为了应对上述问题,在一些实施例中,可以在成员变量被读入缓存之前,通过编译器,基于各个成员变量的访问频率,调整各个成员变量的声明顺序。比如,将高频访问的成员变量的声明顺序调整到相邻或接近的地址。从而使得电子设备可以自动完成修改代码当中成员变量的声明顺序,达到提升数据结构的空间局部性的效果。In order to deal with the above problems, in some embodiments, before the member variables are read into the cache, the compiler can adjust the declaration order of each member variable based on the access frequency of each member variable. For example, adjust the declaration order of frequently accessed member variables to adjacent or close addresses. Thus, the electronic device can automatically modify the declaration order of the member variables in the code, so as to achieve the effect of improving the spatial locality of the data structure.
示例性的,图3示出了一种数据结构优化的方案示意。需要说明的是,为了便于说明,以下将成员变量简称为成员。Exemplarily, FIG. 3 shows a schematic diagram of a data structure optimization solution. It should be noted that, for ease of description, member variables are referred to as members for short below.
如图3所示,该方案可以包括:As shown in Figure 3, the program can include:
S301、开始。S301, start.
在一些实施例中,在电子设备的进程启动时,电子设备可以从共享库中加载类、结构体等相关信息。而在执行过程中,进程会在堆/栈上基于已加载的结构体、类信息构造对象,对对象中各成员变量的地址指针进行不同频次的访问。In some embodiments, when the process of the electronic device starts, the electronic device can load related information such as classes and structures from the shared library. During execution, the process constructs objects on the heap/stack based on the loaded structure and class information, and accesses the address pointers of each member variable in the object at different frequencies.
S302、对代码中的结构体成员插桩。S302. Insert stubs to the structure members in the code.
示例性的,电子设备可以在对结构体成员的代码进行首次编译时,对代码进行插桩(或称为打点)。Exemplarily, the electronic device may perform instrumentation (or called dotting) on the code when compiling the code of the structure member for the first time.
在一些实施例中,结合图4,以结构体成员中包括成员1,成员2,成员3以及成员4为例。电子设备可以在结构体成员的代码中各个成员对应的代码段,***检测标识。比如,在成员1对应的代码段的首字节之前,***检测标识1。在成员2对应的代码段的首字节之前,***检测标识2。在成员3对应的代码段的首字节之前,***检测标识3。在成员4对应的代码段的首字节之前,***检测标识4。在本申请的另一些实施例中,插桩的位置还可以是成员对应的代码段的中段或末尾。In some embodiments, with reference to FIG. 4 , it is taken that members of the structure include member 1 , member 2 , member 3 and member 4 as an example. The electronic device can insert the detection identifier into the code segment corresponding to each member in the code of the structure member. For example, the detection identifier 1 is inserted before the first byte of the code segment corresponding to member 1. Insert detection flag 2 before the first byte of the code segment corresponding to member 2. Insert detection flag 3 before the first byte of the code segment corresponding to member 3. Insert detection flag 4 before the first byte of the code segment corresponding to member 4. In some other embodiments of the present application, the position of the stub may also be the middle or the end of the code segment corresponding to the member.
由此即可获取插桩后的代码。可以看到,在该代码段中的每个成员,都可以通过插桩,配置有对应的检测标识。From this, the code after the instrumentation can be obtained. It can be seen that each member in this code segment can be configured with a corresponding detection flag through instrumentation.
S303、根据插桩的访问次数,确定对应成员的访问信息。S303. Determine the access information of the corresponding member according to the number of visits of the instrumentation.
在本申请实施例中,插桩的访问次数可以对应于***的检测标识的访问次数。In this embodiment of the present application, the number of visits of stub insertion may correspond to the number of visits of the inserted detection identifier.
在一些实施例中,成员的访问信息可以包括该成员的访问频率。In some embodiments, a member's access information may include the member's access frequency.
示例性的,电子设备可以在运行上述插桩之后获取的代码段。比如,电子设备可 以通过相关进程,提供运行该代码段所需的运行时(runtime)。在运行时中,电子设备可以访问如图4所示的插桩之后获取的代码段,从而模拟在应用程序运行过程中,各个成员的访问频率。Exemplarily, the electronic device may obtain the code segment after running the above instrumentation. For example, the electronic device can provide the required runtime (runtime) for running the code segment through a related process. During runtime, the electronic device can access the code segment obtained after instrumentation as shown in FIG. 4 , thereby simulating the access frequency of each member during the running of the application program.
可以理解的是,由于在运行时中运行的代码段,各个成员均通过插桩的形式***了检测标识。因此,电子设备可以通过检测标识的访问频率,确定对应成员的访问频率。It can be understood that, due to the code segment running in the runtime, each member inserts the detection identifier in the form of instrumentation. Therefore, the electronic device can determine the access frequency of the corresponding member by detecting the identified access frequency.
作为一种示例,在运行时中运行一次插桩之后获取的代码段,电子设备确定检测标识1被调用了a次,检测标识2被调用了b次,检测标识3被调用了c次,检测标识4被调用了d次。那么,电子设备就可以确定成员1的访问频率为a次,成员2的访问频率为b次,成员3的访问频率为c次,成员4的访问频率为d次。As an example, when running a code segment obtained after stubbing at runtime, the electronic device determines that the detection flag 1 has been called a times, the detection flag 2 has been called b times, and the detection flag 3 has been called c times. Identity 4 is called d times. Then, the electronic device can determine that the visit frequency of member 1 is a times, the visit frequency of member 2 is b times, the visit frequency of member 3 is c times, and the visit frequency of member 4 is d times.
由此,电子设备就可以获取各个成员的访问信息。比如,成员1的访问信息包括访问频率为a次。成员2的访问信息包括访问频率为b次。成员3的访问信息包括访问频率为c次。成员4的访问信息包括访问频率为d次。Thus, the electronic device can acquire the access information of each member. For example, the visit information of member 1 includes a visit frequency of a times. Member 2's visit information includes a visit frequency of b times. The visit information of member 3 includes a visit frequency of c times. The visit information of member 4 includes a visit frequency of d times.
S304、根据成员的访问信息,调整不同成员的声明顺序。S304. Adjust the declaration order of different members according to the access information of the members.
在本示例中,电子设备可以根据各个成员的访问信息(如访问信息中的访问频率),调整不同成员的声明顺序,由此使得高频率的成员的声明顺序可以被调整到相邻或相近的位置。另外,声明顺序也可以为各个成员在内存中的存储先后顺序。In this example, the electronic device can adjust the declaration order of different members according to the access information of each member (such as the access frequency in the access information), so that the declaration order of high-frequency members can be adjusted to adjacent or similar Location. In addition, the order of declaration can also be the order in which members are stored in memory.
示例性的,电子设备可以将访问频率高的成员的声明提前,将访问频率低的成员的声明退后。比如,结合图5。如图5所示,在调整声明顺序之前,成员1-成员4的声明顺序可以为:成员1-成员2-成员3-成员4。以各个访问频率由大到小的顺序依次为a>c>d>b为例。则调整后的成员1-成员4的声明顺序可以为:成员1-成员3-成员4-成员2。可以看到,通过声明顺序的调整,将访问频率最低点成员2调整到了结构体的代码的末尾。由此,电子设备可以在从内存中向缓存调用该结构体时,可以优先调用访问频率较高的成员。Exemplarily, the electronic device may advance the declarations of members with high access frequency and backward the declarations of members with low access frequency. For example, in conjunction with Figure 5. As shown in Figure 5, before adjusting the declaration order, the declaration order of member 1-member 4 may be: member 1-member 2-member 3-member 4. Take the descending order of each access frequency as a>c>d>b as an example. Then the adjusted declaration order of member 1-member 4 may be: member 1-member 3-member 4-member 2. It can be seen that through the adjustment of the order of declaration, member 2 with the lowest access frequency is adjusted to the end of the code of the structure. Therefore, when the electronic device calls the structure from the memory to the cache, it can preferentially call the members with higher access frequency.
以下结合示例对如图3所示的优化方案进行说明。电子设备可以在首次编译共享库的过程中,如libart.so这一虚拟机运行库,会统计对应源码的类、结构体信息,并在编译编码生成访问成员变量这一机器码逻辑前加入桩点计数逻辑。The optimization scheme shown in FIG. 3 will be described below with reference to an example. Electronic devices can compile shared libraries for the first time, such as libart.so, a virtual machine runtime library, will count the class and structure information of the corresponding source code, and add stubs before compiling and coding to generate machine code logic for accessing member variables. Point counting logic.
在信息统计过程中,会基于该共享库启动zygote64(AOSP虚拟机进程)或对应的应用子进程运行过程,统计各个构造对象对应的成员访问频次信息,如淘宝 TM应用JIT线程运行过程中会大量访问CompileMethod这一类对应的cfi_info成员,而较少的访问vmap_table成员,再JIT线程多次完成CompileMethod这一类成员的访问后,会将访问信息通过buffer回填至data分区的profile文件当中。 In the process of information statistics, zygote64 (AOSP virtual machine process) or the corresponding application sub-process running process will be started based on the shared library, and the member access frequency information corresponding to each structure object will be counted. Access the corresponding cfi_info members of the CompileMethod class, and less access to the vmap_table members. After the JIT thread completes the access to the members of the CompileMethod class for many times, it will backfill the access information to the profile file of the data partition through the buffer.
需要说明的是,CPU在从内存中向缓存将数据(如上述包括多个成员变量的结构体)读入缓存的过程中,可以基于4比特(bytes)或8bytes的倍数,从对应的内存地址开始读取数据。在本示例中,4bytes或8bytes也可称为CPU的读取带宽。以CPU的读取带宽为8bytes为例。结合图6,可以看到,在内存中0x00-0x07的8bytes中,可以存储有成员1以及成员3。那么,通过一次读取,CPU就可以从内存中读取成员1以及成员3的数据。因此,根据图3所示的数据结构优化方案,CPU可以在需要将成员1读入缓存时,一次性地将多个高访问频率的成员(如成员1以及成员3)读入 缓存,从而使得CPU在需要使用成员3时,就不需要重新执行针对内存的读取动作,从而减少CPU的读取开销。而由于成员3的为高频访问成员,因此该减少CPU的读取开销的效果更加明显。It should be noted that when the CPU reads data (such as the above-mentioned structure including multiple member variables) into the cache from the memory, it can read data from the corresponding memory address based on multiples of 4 bytes or 8 bytes. Start reading data. In this example, 4bytes or 8bytes can also be referred to as the read bandwidth of the CPU. Take the read bandwidth of the CPU as 8bytes as an example. Combining with Figure 6, it can be seen that member 1 and member 3 can be stored in 8 bytes of 0x00-0x07 in the memory. Then, with one read, the CPU can read the data of member 1 and member 3 from the memory. Therefore, according to the data structure optimization scheme shown in Figure 3, when the CPU needs to read member 1 into the cache, it can read multiple members with high access frequency (such as member 1 and member 3) into the cache at one time, so that When the CPU needs to use member 3, it does not need to re-execute the read action for the memory, thereby reducing the CPU read overhead. And because member 3 is a member with high frequency access, the effect of reducing the reading overhead of the CPU is more obvious.
在图6所述的示例中,成员1和成员3的数据量之和小于CPU的读取带宽,因此,CPU可以通过一次读取,即可将成员1和成员3的所有数据都读入缓存中。如图6所示,在该场景下,CPU的读取带宽除了可以覆盖成员1以及成员3的所有数据之外,还可以覆盖成员4的部分数据。由于CPU的读取带宽限定了CPU读取数据时的起始地址(即该起始地址一般为CPU读取带宽的整数倍),因此,在CPU需要将成员4的所有数据读入缓存时,就需要分别读取0x00-0x07的数据,以及0x08-0x0f的数据。即执行2次读取操作,才能将成员4的全量数据读入缓存中。In the example shown in Figure 6, the sum of the data volumes of Member 1 and Member 3 is less than the read bandwidth of the CPU. Therefore, the CPU can read all the data of Member 1 and Member 3 into the cache with one read. middle. As shown in Figure 6, in this scenario, the read bandwidth of the CPU can not only cover all the data of member 1 and member 3, but also cover part of the data of member 4. Since the read bandwidth of the CPU limits the start address when the CPU reads data (that is, the start address is generally an integer multiple of the CPU read bandwidth), therefore, when the CPU needs to read all the data of member 4 into the cache, It is necessary to read the data of 0x00-0x07 and the data of 0x08-0x0f respectively. That is, two read operations are performed to read the full amount of data of member 4 into the cache.
而CPU的读取带宽一般都会大于成员变量的数据量,因此,使用2次读取将1个成员变量读入缓存的操作是低效的。However, the read bandwidth of the CPU is generally greater than the data volume of the member variables. Therefore, it is inefficient to use two reads to read one member variable into the cache.
为了避免上述问题,在一些实施例中,可以采用填充(padding)的方式,将经过数据结构优化之后的成员变量中,无法被一次性读入缓存的成员变量的首地址调整到CPU读取带宽的整数倍对应的位置。In order to avoid the above problems, in some embodiments, padding can be used to adjust the first address of the member variables that cannot be read into the cache at one time among the member variables after data structure optimization to the CPU reading bandwidth. The positions corresponding to integer multiples of .
示例性的,结合图6,请参考图7。在经过数据结构优化之后,成员4的数据的首地址和末尾地址会跨越CPU的1个读取带宽(如0x00-0x07)。此时,电子设备可以再次对该结构体中的成员变量的地址进行调整。比如,电子设备可以在成员3的末尾地址的下一个地址到当前CPU读取带宽的末尾地址之间,填充无效数据(或者填充空数据),从而将成员4的数据的首地址调整到CPU的下一个读取带宽的首地址的位置。如图7所示,经过上述调整,成员4的首地址就可以是0x08。这样,CPU就可以在需要将成员4读入缓存时,针对0x08-0x1f的地址,执行1次读取操作,从而实现将成员4的全量数据读入缓存的效果。Exemplarily, in combination with FIG. 6 , please refer to FIG. 7 . After the data structure is optimized, the first address and the last address of the data of member 4 will span one read bandwidth of the CPU (such as 0x00-0x07). At this point, the electronic device can adjust the addresses of the member variables in the structure again. For example, the electronic device can fill invalid data (or fill empty data) between the next address of the end address of member 3 and the end address of the current CPU read bandwidth, so as to adjust the first address of the data of member 4 to that of the CPU. The location of the first address of the next read bandwidth. As shown in Figure 7, after the above adjustments, the first address of member 4 can be 0x08. In this way, when the CPU needs to read member 4 into the cache, it can perform a read operation on the address 0x08-0x1f, thereby realizing the effect of reading the full amount of data of member 4 into the cache.
可以理解的是,通过如图7所示的填充操作,就可以避免需要采用2次读取操作才能读入1个成员变量的情况发生。类似于成员4,如果成员4之后的成员2也无法通过一次读取操作读入缓存,那么电子设备就可以对成员2执行类似的填充操作(如图7所示的填充操作),将成员2的数据的首地址调整到0x10,由此使得在需要将成员2读入缓存时,电子设备可以通过1次读取操作,实现成员2向内存中的读入。It can be understood that, through the filling operation as shown in FIG. 7 , it is possible to avoid the situation that it takes two read operations to read one member variable. Similar to member 4, if member 2 after member 4 cannot be read into the cache through a read operation, then the electronic device can perform a similar filling operation on member 2 (the filling operation shown in Figure 7), and store member 2 The first address of the data is adjusted to 0x10, so that when member 2 needs to be read into the cache, the electronic device can read member 2 into the memory through one read operation.
通过上述图7所示的填充操作,能够避免数据读入过程中的低效率。但是,通过填充操作,会使得该结构体的数据量显著增加。比如,结合图7,在填充操作之后,相比于填充操作之前,该结构体中增加了成员3和成员4之间的无效数据,以及成员4和成员2之间的无效数据。这样,会占用大量的内存空间,降低空间利用率。另外,在未经过填充操作之前,对于一些访问频率较低的成员变量,本可以通过1次读取操作即可实现多个成员变量的读入,但是由于靠前位置的高频成员变量的填充,可能导致1次读取操作无法读入这些低频访问成员变量。这样也会导致***层面的低效率。Through the filling operation shown in FIG. 7 above, inefficiency in the data reading process can be avoided. However, the filling operation will significantly increase the data volume of the structure. For example, referring to FIG. 7 , after the filling operation, compared with before the filling operation, the invalid data between member 3 and member 4, and the invalid data between member 4 and member 2 are added to the structure. In this way, a large amount of memory space will be occupied and the space utilization rate will be reduced. In addition, before the filling operation, for some member variables with low access frequency, multiple member variables can be read in with one read operation, but due to the filling of the high-frequency member variables at the front position , which may cause a read operation to fail to read these infrequently accessed member variables. This also leads to inefficiencies at the system level.
为了解决上述问题,本申请实施例提供一种数据结构优化方案,能够使得电子设备可以一次性读取多个高频访问的数据(如成员变量)的同时,降低由于填充操作导致的低效率。为了便于说明,在以下示例中,将图3所示的数据结构优化方案称为成员变量重排,将如图7所示的填充操作称为数据对齐优化。In order to solve the above problems, the embodiment of the present application provides a data structure optimization solution, which enables the electronic device to read multiple frequently accessed data (such as member variables) at one time, while reducing the inefficiency caused by the filling operation. For ease of description, in the following examples, the data structure optimization solution shown in FIG. 3 is called member variable rearrangement, and the filling operation shown in FIG. 7 is called data alignment optimization.
以下结合附图对本申请实施例提供的方案进行详细说明。The solutions provided by the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.
需要说明的是,本申请实施例涉及的电子设备可以是手机、平板电脑、个人数字助理(personal digital assistant,PDA)、增强现实(augmented reality,AR)\虚拟现实(virtual reality,VR)设备、媒体播放器等便携式移动设备,该电子设备也可以是智能手表等可穿戴电子设备。本申请实施例对该设备的具体形态不作特殊限制。It should be noted that the electronic device involved in the embodiment of the present application may be a mobile phone, a tablet computer, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) device, A portable mobile device such as a media player, the electronic device can also be a wearable electronic device such as a smart watch. The embodiment of the present application does not specifically limit the specific form of the device.
请参考图8,为本申请实施例提供的一种电子设备800的结构示意图,如图8所示,该电子设备800可以包括处理器810,外部存储器接口820,内部存储器821,通用串行总线(universal serial bus,USB)接口830,充电管理模块840,电源管理模块841,电池842,天线1,天线2,移动通信模块850,无线通信模块860,音频模块870,扬声器870A,受话器870B,麦克风870C,耳机接口870D,传感器模块880,按键890,马达891,指示器892,摄像头893,显示屏894,以及用户标识模块(subscriber identification module,SIM)卡接口895等。其中,传感器模块880可以包括压力传感器,陀螺仪传感器,气压传感器,磁传感器,加速度传感器,距离传感器,接近光传感器,指纹传感器,温度传感器,触摸传感器,环境光传感器,骨传导传感器等。Please refer to FIG. 8, which is a schematic structural diagram of an electronic device 800 provided by an embodiment of the present application. As shown in FIG. 8, the electronic device 800 may include a processor 810, an external memory interface 820, an internal memory 821, and a universal serial bus (universal serial bus, USB) interface 830, charging management module 840, power management module 841, battery 842, antenna 1, antenna 2, mobile communication module 850, wireless communication module 860, audio module 870, speaker 870A, receiver 870B, microphone 870C, earphone jack 870D, sensor module 880, button 890, motor 891, indicator 892, camera 893, display screen 894, subscriber identification module (subscriber identification module, SIM) card interface 895, etc. Wherein, the sensor module 880 may include a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.
可以理解的是,本实施例示意的结构并不构成对电子设备800的具体限定。在另一些实施例中,电子设备800可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can be understood that the structure shown in this embodiment does not constitute a specific limitation on the electronic device 800 . In other embodiments, the electronic device 800 may include more or fewer components than shown, or combine certain components, or separate certain components, or arrange different components. The illustrated components can be realized in hardware, software or a combination of software and hardware.
处理器810可以包括一个或多个处理单元,例如:处理器810可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,存储器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器810中。The processor 810 may include one or more processing units, for example: the processor 810 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU) Wait. Wherein, different processing units may be independent devices, or may be integrated in one or more processors 810 .
控制器可以是电子设备800的神经中枢和指挥中心。控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。The controller may be the nerve center and command center of the electronic device 800 . The controller can generate an operation control signal according to the instruction opcode and timing signal, and complete the control of fetching and executing the instruction.
处理器810中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器810中的存储器为高速缓冲存储器。该存储器可以保存处理器810刚用过或循环使用的指令或数据。如果处理器810需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器810的等待时间,因而提高了***的效率。A memory may also be provided in the processor 810 for storing instructions and data. In some embodiments, the memory in processor 810 is a cache memory. The memory may hold instructions or data that the processor 810 has just used or recycled. If the processor 810 needs to use the instruction or data again, it can be directly recalled from the memory. Repeated access is avoided, and the waiting time of the processor 810 is reduced, thereby improving the efficiency of the system.
在一些实施例中,处理器810可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器810接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。In some embodiments, processor 810 may include one or more interfaces. The interface 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 transmitter (universal asynchronous receiver/transmitter, UART) interface, mobile industry processor 810 interface (mobile industry processor interface, MIPI), general-purpose input and output (general-purpose input/output, GPIO) interface, subscriber identity module (subscriber identity module, SIM) interface, And/or a universal serial bus (universal serial bus, USB) interface, etc.
电子设备800可以通过ISP,摄像头893,视频编解码器,GPU,显示屏894以及应用处理器等实现拍摄功能。The electronic device 800 can realize the shooting function through an ISP, a camera 893 , a video codec, a GPU, a display screen 894 , and an application processor.
ISP用于处理摄像头893反馈的数据。例如,拍照时,打开快门,光线通过镜头被传递到摄像头893感光元件上,光信号转换为电信号,摄像头893感光元件将所述电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头893中。The ISP is used to process the data fed back by the camera 893 . For example, when taking a picture, open the shutter, the light is transmitted to the photosensitive element of the camera 893 through the lens, the light signal is converted into an electrical signal, and the photosensitive element of the camera 893 transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on image noise, brightness, and skin color. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, the ISP may be located in the camera 893 .
摄像头893用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。在一些实施例中,电子设备800可以包括1个或多个摄像头893。Camera 893 is used to capture still images or video. The object generates an optical image through the lens and projects it to the photosensitive element. The photosensitive element may be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. DSP converts digital image signals into standard RGB, YUV and other image signals. In some embodiments, the electronic device 800 may include one or more cameras 893 .
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备800在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。Digital signal processors are used to process digital signals. In addition to digital image signals, they can also process other digital signals. For example, when the electronic device 800 selects a frequency point, the digital signal processor is used to perform Fourier transform on the energy of the frequency point.
视频编解码器用于对数字视频压缩或解压缩。电子设备800可以支持一种或多种视频编解码器。这样,电子设备800可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。Video codecs are used to compress or decompress digital video. The electronic device 800 may support one or more video codecs. In this way, the electronic device 800 can play or record videos in various encoding formats, for example: moving picture experts group (moving picture experts group, MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
NPU为神经网络(neural-network,NN)计算处理器810,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备800的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。The NPU is a neural-network (NN) computing processor 810. By referring to the biological neural network structure, such as the transfer mode between neurons in the human brain, the NPU can quickly process input information, and can also continuously self-learn. Applications such as intelligent cognition of the electronic device 800 can be realized through the NPU, such as image recognition, face recognition, speech recognition, text understanding, and the like.
充电管理模块840用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块840可以通过USB接口830接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块840可以通过电子设备800的无线充电线圈接收无线充电输入。充电管理模块840为电池842充电的同时,还可以通过电源管理模块841为电子设备800供电。The charging management module 840 is configured to receive charging input from the charger. Wherein, the charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 840 can receive the charging input of the wired charger through the USB interface 830 . In some wireless charging embodiments, the charging management module 840 may receive wireless charging input through a wireless charging coil of the electronic device 800 . While the charging management module 840 is charging the battery 842 , it can also supply power to the electronic device 800 through the power management module 841 .
电源管理模块841用于连接电池842,充电管理模块840与处理器810。电源管理模块841接收电池842和/或充电管理模块840的输入,为处理器810,内部存储器821,外部存储器,显示屏894,摄像头893,和无线通信模块860等供电。电源管理模块841还可以用于监测电池842容量,电池842循环次数,电池842健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块841也可以设置于处理器810中。在另一些实施例中,电源管理模块841和充电管理模块840也可以设置于同一个器件中。The power management module 841 is used for connecting the battery 842 , the charging management module 840 and the processor 810 . The power management module 841 receives the input of the battery 842 and/or the charging management module 840, and provides power for the processor 810, the internal memory 821, the external memory, the display screen 894, the camera 893, and the wireless communication module 860, etc. The power management module 841 can also be used to monitor parameters such as the capacity of the battery 842 , the number of cycles of the battery 842 , and the state of health of the battery 842 (leakage, impedance). In some other embodiments, the power management module 841 may also be set in the processor 810 . In some other embodiments, the power management module 841 and the charging management module 840 may also be set in the same device.
电子设备800的无线通信功能可以通过天线1,天线2,移动通信模块850,无线通信模块860,调制解调处理器以及基带处理器等实现。The wireless communication function of the electronic device 800 can be realized by the antenna 1, the antenna 2, the mobile communication module 850, the wireless communication module 860, the modem processor and the baseband processor.
天线1和天线2用于发射和接收电磁波信号。电子设备800中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开 关结合使用。Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 800 may be used to cover single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example: Antenna 1 can be multiplexed as a diversity antenna of a wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
移动通信模块850可以提供应用在电子设备800上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块850可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块850可以由天线1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块850还可以对经调制解调处理器调制后的信号放大,经天线1转为电磁波辐射出去。在一些实施例中,移动通信模块850的至少部分功能模块可以被设置于处理器810中。在一些实施例中,移动通信模块850的至少部分功能模块可以与处理器810的至少部分模块被设置在同一个器件中。The mobile communication module 850 can provide wireless communication solutions including 2G/3G/4G/5G applied on the electronic device 800 . The mobile communication module 850 may include at least one filter, switch, power amplifier, low noise amplifier (low noise amplifier, LNA) and the like. The mobile communication module 850 can receive electromagnetic waves through the antenna 1, filter and amplify the received electromagnetic waves, and send them to the modem processor for demodulation. The mobile communication module 850 can also amplify the signal modulated by the modem processor, convert it into electromagnetic wave and radiate it through the antenna 1 . In some embodiments, at least part of the functional modules of the mobile communication module 850 may be set in the processor 810 . In some embodiments, at least part of the functional modules of the mobile communication module 850 and at least part of the modules of the processor 810 may be set in the same device.
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器870A,受话器870B等)输出声音信号,或通过显示屏894显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器810,与移动通信模块850或其他功能模块设置在同一个器件中。A modem processor may include a modulator and a demodulator. Wherein, the modulator is used for modulating the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low frequency baseband signal. Then the demodulator sends the demodulated low-frequency baseband signal to the baseband processor for processing. The low-frequency baseband signal is passed to the application processor after being processed by the baseband processor. The application processor outputs sound signals through audio equipment (not limited to speaker 870A, receiver 870B, etc.), or displays images or videos through display screen 894 . In some embodiments, the modem processor may be a stand-alone device. In some other embodiments, the modem processor may be independent from the processor 810, and be set in the same device as the mobile communication module 850 or other functional modules.
无线通信模块860可以提供应用在电子设备800上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星***(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块860可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块860经由天线2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器810。无线通信模块860还可以从处理器810接收待发送的信号,对其进行调频,放大,经天线2转为电磁波辐射出去。The wireless communication module 860 can provide wireless local area networks (wireless local area networks, WLAN) (such as wireless fidelity (Wireless fidelity, Wi-Fi) network), bluetooth (bluetooth, BT), global navigation satellite, etc. System (global navigation satellite system, GNSS), frequency modulation (frequency modulation, FM), near field communication technology (near field communication, NFC), infrared technology (infrared, IR) and other wireless communication solutions. The wireless communication module 860 may be one or more devices integrating at least one communication processing module. The wireless communication module 860 receives electromagnetic waves via the antenna 2 , frequency-modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 810 . The wireless communication module 860 can also receive the signal to be sent from the processor 810, frequency-modulate it, amplify it, and convert it into electromagnetic waves through the antenna 2 to radiate out.
在一些实施例中,电子设备800的天线1和移动通信模块850耦合,天线2和无线通信模块860耦合,使得电子设备800可以通过无线通信技术与网络以及其他设备通信。所述无线通信技术可以包括全球移动通讯***(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。所述GNSS可以包括全球卫星定位***(global positioning system,GPS),全球导航卫星***(global navigation satellite system,GLONASS),北斗卫星导航***(beidou navigation satellite system,BDS),准天顶卫星***(quasi-zenith satellite system,QZSS)和/或星基增强***(satellite based augmentation systems,SBAS)。In some embodiments, the antenna 1 of the electronic device 800 is coupled to the mobile communication module 850, and the antenna 2 is coupled to the wireless communication module 860, so that the electronic device 800 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (general packet radio service, GPRS), code division multiple access (code division multiple access, CDMA), broadband 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, etc. The GNSS may include a global positioning system (global positioning system, GPS), a global navigation satellite system (global navigation satellite system, GLONASS), a Beidou navigation satellite system (beidou navigation satellite system, BDS), a quasi-zenith satellite system (quasi -zenith satellite system (QZSS) and/or satellite based augmentation systems (SBAS).
电子设备800通过GPU,显示屏894,以及应用处理器等实现显示功能。GPU为图像处理的微处理器810,连接显示屏894和应用处理器。GPU用于执行数学和几何 计算,用于图形渲染。处理器810可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。The electronic device 800 implements a display function through a GPU, a display screen 894, an application processor, and the like. The GPU is a microprocessor 810 for image processing, which is connected to the display screen 894 and the application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering. Processor 810 may include one or more GPUs that execute program instructions to generate or change display information.
显示屏894用于显示图像,视频等。显示屏894包括显示面板。显示面板可以采用液晶显示屏894(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备800可以包括1个或N个显示屏894,N为大于1的正整数。The display screen 894 is used to display images, videos and the like. Display 894 includes a display panel. The display panel can adopt liquid crystal display 894 (liquid crystal display, LCD), organic light-emitting diode (organic light-emitting diode, OLED), active matrix organic light-emitting diode or active-matrix organic light-emitting diode (active-matrix organic light emitting diode, AMOLED), flexible light-emitting diode (flex light-emitting diode, FLED), Miniled, MicroLed, Micro-oLed, quantum dot light emitting diodes (quantum dot light emitting diodes, QLED), etc. In some embodiments, the electronic device 800 may include 1 or N display screens 894, where N is a positive integer greater than 1.
外部存储器接口820可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备800的存储资源。外部存储卡通过外部存储器接口820与处理器810通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。The external memory interface 820 can be used to connect an external memory card, such as a Micro SD card, to expand the storage resources of the electronic device 800. The external memory card communicates with the processor 810 through the external memory interface 820 to realize the data storage function. Such as saving music, video and other files in the external memory card.
内部存储器821可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。处理器810通过运行存储在内部存储器821的指令,从而执行电子设备800的各种功能应用以及数据处理。内部存储器821可以包括存储程序区和存储数据区。其中,存储程序区可存储操作***,至少一个功能所需的应用(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备800使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器821可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。Internal memory 821 may be used to store computer-executable program code, which includes instructions. The processor 810 executes various functional applications and data processing of the electronic device 800 by executing instructions stored in the internal memory 821 . The internal memory 821 may include an area for storing programs and an area for storing data. Wherein, the stored program area can store an operating system, at least one application required by a function (such as a sound playing function, an image playing function, etc.) and the like. The storage data area can store data created during the use of the electronic device 800 (such as audio data, phonebook, etc.) and the like. In addition, the internal memory 821 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, flash memory device, universal flash storage (universal flash storage, UFS) and the like.
电子设备800可以通过音频模块870,扬声器870A,受话器870B,麦克风870C,耳机接口870D,以及应用处理器等实现音频功能。例如音乐播放,录音等。The electronic device 800 may implement an audio function through an audio module 870 , a speaker 870A, a receiver 870B, a microphone 870C, an earphone interface 870D, and an application processor. Such as music playback, recording, etc.
音频模块870用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块870还可以用于对音频信号编码和解码。在一些实施例中,音频模块870可以设置于处理器810中,或将音频模块870的部分功能模块设置于处理器810中。The audio module 870 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signal. The audio module 870 may also be used to encode and decode audio signals. In some embodiments, the audio module 870 may be set in the processor 810 , or some functional modules of the audio module 870 may be set in the processor 810 .
扬声器870A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备800可以通过扬声器870A收听音乐,或收听免提通话。Speaker 870A, also called "horn", is used to convert audio electrical signals into sound signals. Electronic device 800 can listen to music through speaker 870A, or listen to hands-free calls.
受话器870B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备800接听电话或语音信息时,可以通过将受话器870B靠近人耳接听语音。Receiver 870B, also called "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 800 receives a call or a voice message, the receiver 870B can be placed close to the human ear to receive the voice.
麦克风870C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息或需要通过语音助手触发电子设备800执行某些功能时,用户可以通过人嘴靠近麦克风870C发声,将声音信号输入到麦克风870C。电子设备800可以设置至少一个麦克风870C。在另一些实施例中,电子设备800可以设置两个麦克风870C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备800还可以设置三个,四个或更多麦克风870C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。Microphone 870C, also known as "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, or needing to trigger the electronic device 800 to perform certain functions through the voice assistant, the user can make a sound by approaching the microphone 870C with a human mouth, and input the sound signal into the microphone 870C. The electronic device 800 may be provided with at least one microphone 870C. In some other embodiments, the electronic device 800 may be provided with two microphones 870C, which may also implement a noise reduction function in addition to collecting sound signals. In some other embodiments, the electronic device 800 can also be provided with three, four or more microphones 870C to collect sound signals, reduce noise, identify sound sources, and realize directional recording functions, etc.
耳机接口870D用于连接有线耳机。耳机接口870D可以是USB接口830,也可以是3.5mm的开放移动电子设备800平台(open mobile terminal platform,OMTP)标准 接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。The earphone interface 870D is used to connect wired earphones. The earphone interface 870D may be a USB interface 830, or a 3.5mm open mobile terminal platform (open mobile terminal platform, OMTP) standard interface, or a cellular telecommunications industry association of the USA (CTIA) standard interface. .
触摸传感器,也称“触控面板”。触摸传感器可以设置于显示屏894,由触摸传感器与显示屏894组成触摸屏,也称“触控屏”。触摸传感器用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。在一些实施例中,可以通过显示屏894提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器也可以设置于电子设备800的表面,与显示屏894所处的位置不同。Touch sensor, also known as "touch panel". The touch sensor can be arranged on the display screen 894, and the touch sensor and the display screen 894 form a touch screen, also called “touch screen”. The touch sensor is used to detect a touch operation on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. In some embodiments, the visual output related to the touch operation can be provided through the display screen 894 . In some other embodiments, the touch sensor may also be disposed on the surface of the electronic device 800 , which is different from the position of the display screen 894 .
压力传感器用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器可以设置于显示屏894。压力传感器的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器,电极之间的电容改变。电子设备800根据电容的变化确定压力的强度。当有触摸操作作用于显示屏894,电子设备800根据压力传感器检测所述触摸操作强度。电子设备800也可以根据压力传感器的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。The pressure sensor is used to sense the pressure signal and convert the pressure signal into an electrical signal. In some embodiments, a pressure sensor may be located on the display screen 894 . There are many types of pressure sensors, such as resistive pressure sensors, inductive pressure sensors, and capacitive pressure sensors. A capacitive pressure sensor may be comprised of at least two parallel plates with conductive material. When a force is applied to the pressure sensor, the capacitance between the electrodes changes. The electronic device 800 determines the intensity of the pressure from the change in capacitance. When a touch operation acts on the display screen 894, the electronic device 800 detects the intensity of the touch operation according to the pressure sensor. The electronic device 800 may also calculate the touched position according to the detection signal of the pressure sensor. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities may correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view short messages is executed. When a touch operation whose intensity is greater than or equal to the first pressure threshold acts on the icon of the short message application, the instruction of creating a new short message is executed.
陀螺仪传感器可以用于确定电子设备800的运动姿态。在一些实施例中,可以通过陀螺仪传感器确定电子设备800围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器检测电子设备800抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备800的抖动,实现防抖。陀螺仪传感器还可以用于导航,体感游戏场景。The gyro sensor can be used to determine the motion posture of the electronic device 800 . In some embodiments, the angular velocity of the electronic device 800 around three axes (ie, x, y, and z axes) may be determined by a gyro sensor. The gyro sensor can be used for image stabilization. Exemplarily, when the shutter is pressed, the gyro sensor detects the shaking angle of the electronic device 800, calculates the distance that the lens module needs to compensate according to the angle, and allows the lens to counteract the shaking of the electronic device 800 through reverse movement to achieve anti-shake. Gyroscope sensors can also be used for navigation and somatosensory game scenes.
气压传感器用于测量气压。在一些实施例中,电子设备800通过气压传感器测得的气压值计算海拔高度,辅助定位和导航。The barometric pressure sensor is used to measure air pressure. In some embodiments, the electronic device 800 calculates the altitude based on the air pressure value measured by the air pressure sensor to assist positioning and navigation.
磁传感器包括霍尔传感器。电子设备800可以利用磁传感器检测翻盖皮套的开合。在一些实施例中,当电子设备800是翻盖机时,电子设备800可以根据磁传感器检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖自动解锁等特性。Magnetic sensors include Hall sensors. The electronic device 800 may use a magnetic sensor to detect opening and closing of the flip leather case. In some embodiments, when the electronic device 800 is a flip machine, the electronic device 800 may detect opening and closing of the flip according to the magnetic sensor. Furthermore, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, features such as automatic unlocking of the flip cover are set.
加速度传感器可检测电子设备800在各个方向上(一般为三轴)加速度的大小。当电子设备800静止时可检测出重力的大小及方向。还可以用于识别电子设备800姿态,应用于横竖屏切换,计步器等应用。The acceleration sensor can detect the acceleration of the electronic device 800 in various directions (generally three axes). When the electronic device 800 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device 800, and can be used in applications such as horizontal and vertical screen switching, pedometers, etc.
距离传感器,用于测量距离。电子设备800可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备800可以利用距离传感器测距以实现快速对焦。Distance sensor for measuring distance. The electronic device 800 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 800 may use a distance sensor to measure a distance to achieve fast focusing.
接近光传感器可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备800通过发光二极管向外发射红外光。电子设备800使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备800附近有物体。当检测到不充分的反射光时,电子设备800可以确定电子设备800附近没有物体。电子设备800可以利用接近光传感器检测用户 手持电子设备800贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。接近光传感器也可用于皮套模式,口袋模式自动解锁与锁屏。Proximity light sensors may include, for example, light emitting diodes (LEDs) and light detectors, such as photodiodes. The light emitting diodes may be infrared light emitting diodes. The electronic device 800 emits infrared light through the light emitting diode. Electronic device 800 uses photodiodes to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it may be determined that there is an object near the electronic device 800 . When insufficient reflected light is detected, the electronic device 800 may determine that there is no object near the electronic device 800 . The electronic device 800 can use the proximity light sensor to detect that the user holds the electronic device 800 close to the ear to talk, so that the screen is automatically turned off to save power. Proximity light sensor can also be used for leather case mode, pocket mode auto unlock and lock screen.
环境光传感器用于感知环境光亮度。电子设备800可以根据感知的环境光亮度自适应调节显示屏894亮度。环境光传感器也可用于拍照时自动调节白平衡。环境光传感器还可以与接近光传感器配合,检测电子设备800是否在口袋里,以防误触。The ambient light sensor is used to sense the ambient light brightness. The electronic device 800 can adaptively adjust the brightness of the display screen 894 according to the perceived ambient light brightness. The ambient light sensor can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor can also cooperate with the proximity light sensor to detect whether the electronic device 800 is in the pocket, so as to prevent false touches.
指纹传感器用于采集指纹。电子设备800可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。The fingerprint sensor is used to collect fingerprints. The electronic device 800 can use the collected fingerprint characteristics to implement fingerprint unlocking, access to application locks, take pictures with fingerprints, answer incoming calls with fingerprints, and the like.
温度传感器用于检测温度。在一些实施例中,电子设备800利用温度传感器检测的温度,执行温度处理策略。例如,当温度传感器上报的温度超过阈值,电子设备800执行降低位于温度传感器附近的处理器810的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备800对电池842加热,以避免低温导致电子设备800异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备800对电池842的输出电压执行升压,以避免低温导致的异常关机。A temperature sensor is used to detect temperature. In some embodiments, the electronic device 800 uses the temperature detected by the temperature sensor to implement a temperature processing strategy. For example, when the temperature reported by the temperature sensor exceeds the threshold, the electronic device 800 may reduce the performance of the processor 810 located near the temperature sensor, so as to reduce power consumption and implement thermal protection. In some other embodiments, when the temperature is lower than another threshold, the electronic device 800 heats the battery 842 to prevent the electronic device 800 from being shut down abnormally due to the low temperature. In some other embodiments, when the temperature is lower than another threshold, the electronic device 800 boosts the output voltage of the battery 842 to avoid abnormal shutdown caused by low temperature.
骨传导传感器可以获取振动信号。在一些实施例中,骨传导传感器可以获取人体声部振动骨块的振动信号。骨传导传感器也可以接触人体脉搏,接收血压跳动信号。在一些实施例中,骨传导传感器也可以设置于耳机中,结合成骨传导耳机。音频模块870可以基于所述骨传导传感器获取的声部振动骨块的振动信号,解析出语音信号,实现语音功能。应用处理器可以基于所述骨传导传感器获取的血压跳动信号解析心率信息,实现心率检测功能。Bone conduction sensors can pick up vibration signals. In some embodiments, the bone conduction sensor can acquire the vibration signal of the vibrating bone mass of the human voice. Bone conduction sensors can also contact the human pulse and receive blood pressure beating signals. In some embodiments, the bone conduction sensor can also be disposed in the earphone, combined into a bone conduction earphone. The audio module 870 can analyze the voice signal based on the vibration signal of the vibrating bone mass of the vocal part acquired by the bone conduction sensor, so as to realize the voice function. The application processor can analyze the heart rate information based on the blood pressure beating signal acquired by the bone conduction sensor, so as to realize the heart rate detection function.
按键890包括开机键,音量键等。按键890可以是机械按键890。也可以是触摸式按键890。电子设备800可以接收按键890输入,产生与电子设备800的用户设置以及功能控制有关的键信号输入。The keys 890 include a power key, a volume key and the like. The key 890 may be a mechanical key 890 . It can also be a touch button 890 . The electronic device 800 can receive the key 890 input, and generate key signal input related to the user setting and function control of the electronic device 800 .
马达891可以产生振动提示。马达891可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏894不同区域的触摸操作,马达891也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。The motor 891 can generate a vibrating prompt. The motor 891 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations applied to different applications (such as taking pictures, playing audio, etc.) may correspond to different vibration feedback effects. The motor 891 can also correspond to different vibration feedback effects for touch operations on different areas of the display screen 894 . Different application scenarios (for example: time reminder, receiving information, alarm clock, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
指示器892可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。The indicator 892 can be an indicator light, and can be used to indicate charging status, power change, and can also be used to indicate messages, missed calls, notifications, and the like.
SIM卡接口895用于连接SIM卡。SIM卡可以通过***SIM卡接口895,或从SIM卡接口895拔出,实现和电子设备800的接触和分离。电子设备800可以支持1个或N个SIM卡接口895,N为大于1的正整数。SIM卡接口895可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口895可以同时***多张卡。所述多张卡的类型可以相同,也可以不同。SIM卡接口895也可以兼容不同类型的SIM卡。SIM卡接口895也可以兼容外部存储卡。电子设备800通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备800采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备800中,不能和电子设备800分离。The SIM card interface 895 is used for connecting a SIM card. The SIM card can be connected and separated from the electronic device 800 by inserting it into the SIM card interface 895 or pulling it out from the SIM card interface 895 . The electronic device 800 may support 1 or N SIM card interfaces 895, where N is a positive integer greater than 1. SIM card interface 895 can support Nano SIM card, Micro SIM card, SIM card, etc. Multiple cards can be inserted into the same SIM card interface 895 at the same time. The types of the multiple cards may be the same or different. The SIM card interface 895 is also compatible with different types of SIM cards. The SIM card interface 895 is also compatible with external memory cards. The electronic device 800 interacts with the network through the SIM card to implement functions such as calling and data communication. In some embodiments, the electronic device 800 adopts an eSIM, that is, an embedded SIM card. The eSIM card can be embedded in the electronic device 800 and cannot be separated from the electronic device 800 .
本申请实施例提供的方案均可应用于具有上述图8所示的硬件组成的电子设备800中。作为一种可能的实现,本申请实施例提供的方案,能够使得电子设备800的 处理器810在对数据进行处理时,优化数据中的数据变量的结构,从而达到提升***效率的效果。The solutions provided in the embodiments of the present application can all be applied to the electronic device 800 having the hardware composition shown in FIG. 8 above. As a possible implementation, the solution provided by the embodiment of the present application can enable the processor 810 of the electronic device 800 to optimize the structure of the data variables in the data when processing the data, so as to improve the system efficiency.
需要说明的是,在本申请的另一些实施例中,电子设备800中可以包括更多的部件,或者,电子设备800中可以根据需要支持的功能精简如图8所示的组成中的部分部件。It should be noted that, in other embodiments of the present application, the electronic device 800 may include more components, or, the electronic device 800 may simplify some components in the composition as shown in FIG. .
在一些实施例中,在电子设备800中可以运行有软件***。该软件***可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。以下以电子设备800中的软件***为具有分层架构的安卓***为例,对电子设备800中的软件结构进行说明。In some embodiments, a software system may run in the electronic device 800 . The software system may adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. The software structure of the electronic device 800 will be described below by taking the Android system with a layered architecture as an example of the software system in the electronic device 800 .
本申请实施例提供的分层架构可以将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。作为一种示例,请参考图9,为本申请实施例提供的一种电子设备的软件结构框图。在该示例中,安卓***可以包括3个软件层。从上至小分别为应用901,运行时(runtime)902,以及内核903。The layered architecture provided by the embodiment of the present application can divide the software into several layers, and each layer has a clear role and division of labor. Layers communicate through software interfaces. As an example, please refer to FIG. 9 , which is a software structural block diagram of an electronic device provided in an embodiment of the present application. In this example, the Android system may include 3 software layers. From top to small are application 901 , runtime (runtime) 902 , and kernel 903 .
在一些实施例中,应用901中还可以包括应用层,以及应用框架层。In some embodiments, the application 901 may also include an application layer and an application framework layer.
其中,应用层可以包括一系列应用包。在一些实施例中,该应用包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用。电子设备可以通过运行这些应用,实现对应的功能。Wherein, the application layer may include a series of application packages. In some embodiments, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and short message. The electronic device can realize corresponding functions by running these applications.
应用框架层可以为应用层的应用提供应用编程接口(application programming interface,API)和编程框架。应用框架层还可包括一些预先定义的函数。The application framework layer can provide an application programming interface (application programming interface, API) and a programming framework for applications in the application layer. The application framework layer may also include some predefined functions.
在一些示例中,应用框架层可以包括窗口管理器,内容提供器,视图***,资源管理器,通知管理器,活动管理器,输入管理器等。In some examples, the application framework layer may include a window manager, a content provider, a view system, a resource manager, a notification manager, an event manager, an input manager, and the like.
其中,窗口管理器提供窗口管理服务(Window Manager Service,WMS),WMS可以用于窗口管理、窗口动画管理、surface管理以及作为输入***的中转站。内容提供器用来存放和获取数据,并使这些数据可以被应用访问。该数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。视图***包括可视控件,例如显示文字的控件,显示图片的控件等。视图***可用于构建应用。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。资源管理器为应用提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。通知管理器使应用可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在***顶部状态栏的通知,例如后台运行的应用的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。活动管理器可以提供活动管理服务(Activity Manager Service,AMS),AMS可以用于***组件(例如活动、服务、内容提供者、广播接收器)的启动、切换、调度以及应用进程的管理和调度工作。输入管理器可以提供输入管理服务(Input Manager Service,IMS),IMS可以用于管理***的输入,例如触摸屏输入、按键输入、传感器输入等。IMS从输入设备节点取出事件,通过和WMS的交互,将事件分配至合适的窗口。Among them, the window manager provides window management service (Window Manager Service, WMS), and WMS can be used for window management, window animation management, surface management and as a transfer station of the input system. Content providers are used to store and retrieve data, and make these data accessible to applications. This data can include videos, images, audio, calls made and received, browsing history and bookmarks, phonebook, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, and so on. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures. The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and so on. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages, and can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the download completion, message reminder, etc. The notification manager can also be a notification that appears on the top status bar of the system in the form of a chart or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, issuing a prompt sound, vibrating the electronic device, and flashing the indicator light, etc. The activity manager can provide activity management service (Activity Manager Service, AMS), AMS can be used for system components (such as activities, services, content providers, broadcast receivers) to start, switch, schedule, and manage and schedule application processes . The input manager can provide input management service (Input Manager Service, IMS), and IMS can be used to manage the input of the system, such as touch screen input, key input, sensor input, etc. IMS fetches events from input device nodes, and distributes events to appropriate windows through interaction with WMS.
运行时902可以提供当前操作***中的运行环境。比如,在安卓操作***中,该运行时902中可以包括安卓运行时。示例性的,在电子设备同时运行多个应用时,不同的应用可以被配置有各自独立的运行时,该运行时可以对应到上述说明中的虚拟机。安卓运行时可以用于将源代码转换为机器码。安卓运行时可以支持profile技术以及JIT编译技术。The runtime 902 can provide the runtime environment in the current operating system. For example, in the Android operating system, the runtime 902 may include the Android runtime. Exemplarily, when the electronic device runs multiple applications at the same time, different applications may be configured with their own independent runtimes, and the runtimes may correspond to the virtual machines described above. The Android runtime can be used to convert source code into machine code. Android runtime can support profile technology and JIT compilation technology.
在本申请实施例的一些实施例中,该运行时还可以包括核心库。In some embodiments of the embodiments of the present application, the runtime may also include a core library.
核心库可以用于提供基本的ART类库的功能。例如基础数据结构、数学、输入输出(input/output,IO)、工具、数据库、网络等库。核心库为用户进行安卓应用开发提供了API。The core library can be used to provide the functionality of the basic ART class library. For example, libraries such as basic data structures, mathematics, input/output (IO), tools, databases, and networks. The core library provides APIs for users to develop Android applications.
在一些实施例中,运行时902还可以包括原生C/C++库等语言库。可以包括多个功能模块。例如:表面管理器(surface manager),媒体框架(Media Framework),libc,OpenGL ES、SQLite、Webkit等。其中,表面管理器用于对显示子***进行管理,并且为多个应用提供了2D和3D图层的融合。媒体框架支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H.264,MP3,AAC,AMR,JPG,PNG等。OpenGL ES提供应用中2D图形和3D图形的绘制和操作。SQLite为电子设备100的应用提供轻量级关系型数据库。In some embodiments, runtime 902 may also include language libraries such as native C/C++ libraries. Multiple functional modules can be included. For example: surface manager (surface manager), media framework (Media Framework), libc, OpenGL ES, SQLite, Webkit, etc. Among them, the surface manager is used to manage the display subsystem, and provides the fusion of 2D and 3D layers for multiple applications. The media framework supports playback and recording of various commonly used audio and video formats, as well as still image files. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. OpenGL ES provides the drawing and manipulation of 2D graphics and 3D graphics in applications. SQLite provides a lightweight relational database for the application of the electronic device 100 .
内核903可以是硬件和软件之间的层。该内核903至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。通过这些驱动,能够使得上层指令可以被对应的驱动转换为能够对应硬件识别并执行的指令。由此实现软件与硬件的结合。The kernel 903 may be a layer between hardware and software. The kernel 903 includes at least a display driver, a camera driver, an audio driver, and a sensor driver. Through these drivers, the upper-layer instructions can be converted by corresponding drivers into instructions that can be recognized and executed by corresponding hardware. This realizes the combination of software and hardware.
需要说明的是,在本申请的一些实施例中,在运行时902和内核903之间还可以设置有硬件抽象层(图9中未示出)。该硬件抽象成可以运行于用户空间(user space),对内核903驱动进行封装,向上层提供调用接口。It should be noted that, in some embodiments of the present application, a hardware abstraction layer (not shown in FIG. 9 ) may also be set between the runtime 902 and the kernel 903 . The hardware is abstracted to run in user space, encapsulates the kernel 903 driver, and provides a call interface to the upper layer.
另外,如图9所示的软件组合仅为一种可能的实现,并不对本申请实施例提供的方案构成任何限制。比如,一些实施例中,运行时902还可以与内核903划分在一个虚拟层。In addition, the software combination shown in FIG. 9 is only a possible implementation, and does not constitute any limitation to the solution provided by the embodiment of the present application. For example, in some embodiments, the runtime 902 and the kernel 903 may also be divided into a virtual layer.
本申请实施例提供的方案能够应用于具有如图9所示的软件组成的电子设备中。The solutions provided by the embodiments of the present application can be applied to electronic devices with software components as shown in FIG. 9 .
以下结合附图,对本申请实施例提供的方案的具体实施过程,进行详细说明。The specific implementation process of the solutions provided by the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings.
示例性的,图10为本申请实施例提供的一种编译优化方法的流程示意图。如图10所示,该方法可以包括:Exemplarily, FIG. 10 is a schematic flowchart of a compiling optimization method provided by the embodiment of the present application. As shown in Figure 10, the method may include:
S1001、开始。S1001, start.
其中,该步骤的执行方式可以参考如图3所示的S301。其具体实现也可以互相参考,此处不再赘述。Wherein, the execution manner of this step may refer to S301 shown in FIG. 3 . The specific implementations may also refer to each other, and will not be repeated here.
S1002、根据结构体中各个成员变量的访问频率,对结构体中的成员变量执行成员变量重排,获取第一优化结果。S1002. Perform member variable rearrangement on the member variables in the structure according to the access frequency of each member variable in the structure, and obtain a first optimization result.
S1003、对第一优化结果执行数据对齐优化获取第二优化结果。S1003. Perform data alignment optimization on the first optimization result to obtain a second optimization result.
示例性的,该S1002的执行可以参考如图3所示的方案的执行过程。S1003的执行可以参考图7所示的方案。其实施过程此处不再赘述。以下结合实例进行举例说明。Exemplarily, the execution of S1002 may refer to the execution process of the solution shown in FIG. 3 . For the execution of S1003, reference may be made to the solution shown in FIG. 7 . Its implementation process will not be repeated here. The following will be illustrated in conjunction with examples.
例如,以结构体具有以下数据结构为例。For example, take a struct with the following data structure as an example.
Figure PCTCN2022096071-appb-000001
Figure PCTCN2022096071-appb-000001
Figure PCTCN2022096071-appb-000002
Figure PCTCN2022096071-appb-000002
可以看到,在该示例中,结构体中包括的成员变量可以包括:short类型的A和B;int类型的C,D以及E;char*类型的F和G。It can be seen that, in this example, the member variables included in the structure may include: A and B of short type; C, D, and E of int type; F and G of char* type.
以A的首地址为0x00为例。在64位***中,short、int、char*的大小分别为2bytes、4bytes、8bytes。也就是说,A和B的大小为2bytes,C和D以及E的大小均为4bytes,F和G的大小为8bytes。那么A对应的地址段为:0x00-0x01。B对应的地址段为:0x02-0x03。C的地址段为:0x04-0x07。D的地址段为0x08-0x0b。E的地址段为0x0c-0x0f。F的地址段为0x10-0x17。G的地址段为0x18-0x1f。在本申请中,为了便于说明,可以将成员变量的地址段的首地址,称为该成员变量的地址。比如,A的地址可以为0x00。B的地址可以为0x02。C的地址可以为0x04。D的地址可以为0x08。E的地址可以为0x0c。F的地址可以为0x10。G的地址可以为0x18。Take the first address of A as 0x00 as an example. In a 64-bit system, the sizes of short, int, and char* are 2bytes, 4bytes, and 8bytes, respectively. That is to say, the size of A and B is 2bytes, the size of C, D and E is 4bytes, and the size of F and G is 8bytes. Then the address segment corresponding to A is: 0x00-0x01. The address segment corresponding to B is: 0x02-0x03. The address segment of C is: 0x04-0x07. The address segment of D is 0x08-0x0b. The address segment of E is 0x0c-0x0f. The address segment of F is 0x10-0x17. The address segment of G is 0x18-0x1f. In this application, for the convenience of description, the first address of the address segment of the member variable may be referred to as the address of the member variable. For example, the address of A can be 0x00. The address of B can be 0x02. The address of C can be 0x04. The address of D can be 0x08. The address of E may be 0x0c. The address of F can be 0x10. The address of G can be 0x18.
那么,默认的成员变量在内存中的存储情况如图11所示。在该图11的示例中,每行可以包括8比特数据。以CPU的读取带宽为16bytes为例。则CPU每执行1次读取操作,就可以读入如图11所示的2行的成员变量的数据。比如,CPU可以在第1次读取操作中,读取如图11所示的第1行以及第2行的成员变量的数据,即一次性将ABCDE的数据从内存读入缓存中。又如,CPU可以在第2次读取操作中,读取如图11所示的第3行以及第4行的成员变量的数据,即一次向将F和G的数据从内存读入缓存中。Then, the storage situation of the default member variables in the memory is shown in Figure 11. In this example of FIG. 11, each row may include 8-bit data. Take the CPU read bandwidth as 16bytes as an example. Then, every time the CPU executes a read operation, it can read the data of the member variables of the 2 rows as shown in FIG. 11 . For example, in the first read operation, the CPU can read the data of the member variables in line 1 and line 2 shown in Figure 11, that is, read the data of ABCDE from the memory into the cache at one time. As another example, in the second read operation, the CPU can read the data of the member variables in the third line and the fourth line shown in Figure 11, that is, read the data of F and G from the memory into the cache at one time .
结合前述图3的方案说明,电子设备可以通过运行时,在线获取各个成员变量的访问频率。例如,表1示出了一种访问频率的示例。With reference to the solution description in FIG. 3 above, the electronic device can acquire the access frequency of each member variable online during runtime. For example, Table 1 shows an example of access frequency.
表1Table 1
成员变量Member variables 访问频率visit frequency
AA 100%100%
BB 60%60%
CC 20%20%
DD. 20%20%
EE. 5%5%
Ff 80%80%
GG 10%10%
这样,根据该访问频率,电子设备就可以确定成员变量按照访问频率由高到低的排序可以为AFBCDGE。In this way, according to the access frequency, the electronic device can determine that the order of the member variables in descending order of the access frequency can be AFBCDGE.
通过如图3所示的成员变量重排以及如图7所示的数据对齐优化,即可将该结构 体中的成员变量在内存中的存储顺序调整为如图12所示的情况。Through the rearrangement of member variables as shown in Figure 3 and the optimization of data alignment as shown in Figure 7, the storage order of the member variables in the structure in memory can be adjusted to the situation shown in Figure 12.
可以看到,在如图12所示的存储中,CPU可以通过1次读取操作,将同为高频访问成员的A和F读入缓存。这样,由于A和F被调用的频率较高,因此,可以节省大量的从内存中读取数据的消耗。类似的,CPU可以通过1次读取操作,将B,C和D读入缓存。CPU还可以通过1次读取操作,将G和E读入缓存。It can be seen that in the storage shown in Figure 12, the CPU can read A and F, which are both high-frequency access members, into the cache through one read operation. In this way, since A and F are called frequently, a lot of consumption of reading data from memory can be saved. Similarly, the CPU can read B, C, and D into the cache with one read operation. The CPU can also read G and E into the cache with one read operation.
然而,结合前述对图3以及图7的说明,在经过该填充之后,虽然实现了数据对齐,但是结构体的数据量从之前的32bytes膨胀到了48bytes。However, in combination with the foregoing descriptions of FIG. 3 and FIG. 7 , after the padding, although data alignment is achieved, the data volume of the structure expands from the previous 32 bytes to 48 bytes.
因此,在本申请实施例中,在获取如图12所示的数据结构之后,可以继续执行以下S1004。Therefore, in the embodiment of the present application, after the data structure shown in FIG. 12 is acquired, the following S1004 may be executed continuously.
S1004、基于第二优化结果,获取该结构体中符合要求的第一填充字段和第一成员变量。S1004. Based on the second optimization result, obtain the first filling field and the first member variable that meet the requirements in the structure.
其中,第一填充字段可以是经过成员变量重排以及数据对齐优化之后,获取的数据结构中的填充字段。第一成员变量在第二优化结果中的地址可以位于第一填充字段之后。第一成员变量的大小可以小于或等于第一填充字段的大小。Wherein, the first padding field may be a padding field in the data structure obtained after member variable rearrangement and data alignment optimization. The address of the first member variable in the second optimization result may be located after the first padding field. The size of the first member variable may be smaller than or equal to the size of the first padding field.
示例性的,结合图12。电子设备可以基于如图12所示的数据结构,查找其中的填充字段。比如,以第一填充字段为如图12所示的填充1为例。那么该填充1在内存中的地址段可以为0x02-0x07。同样以地址段中的首地址标识该地址段,那么填充1的地址可以为0x02。For example, refer to FIG. 12 . Based on the data structure shown in FIG. 12 , the electronic device can search for the filled fields therein. For example, take the first padding field as padding 1 as shown in FIG. 12 as an example. Then the address segment filled with 1 in the memory can be 0x02-0x07. Also, the first address in the address segment is used to identify the address segment, so the address filled with 1 can be 0x02.
电子设备还可以查找填充1的地址之后,大小小于或等于填充1的大小(如0x02-0x07共6个bytes)的成员变量。示例性的,继续结合图12,在填充1之后,符合要求的第一成员变量可以包括BCDE。那么,该第一成员变量就可以是BCDE中的任意一个。The electronic device can also search for member variables whose size is smaller than or equal to the size of the padding 1 (such as 0x02-0x07, a total of 6 bytes) after the padding 1 address. Exemplarily, continuing to refer to FIG. 12 , after filling 1, the first member variable that meets the requirements may include BCDE. Then, the first member variable can be any one of BCDE.
在本申请的一些实施例中,在符合要求的第一成员变量的数量大于1的情况下,电子设备可以将地址最靠前的成员变量作为该第一成员变量。示例性的,BCDE都可以符合要求,而B的地址最靠前,也就是说B的访问频率在符合要求的成员变量中最高,那么,电子设备就可以将该成员变量B作为第一成员变量。In some embodiments of the present application, when the number of first member variables meeting the requirements is greater than 1, the electronic device may use the member variable with the highest address as the first member variable. Exemplarily, BCDE can meet the requirements, and the address of B is the first, that is to say, the access frequency of B is the highest among the member variables that meet the requirements, then the electronic device can use the member variable B as the first member variable .
S1005、将第一成员变量的数据存入第一填充字段。S1005. Store the data of the first member variable into the first filling field.
在本示例中,电子设备可以将地址靠后的符合条件的成员变量(如S1004中获取的第一成员变量)填充到第一地址段中,使得之前空闲的地址段(如第一地址段)的存储能力得到使用。In this example, the electronic device can fill the qualified member variable with a later address (such as the first member variable obtained in S1004) into the first address segment, so that the previously free address segment (such as the first address segment) storage capacity is used.
示例性的,结合图12,请参考图13。以第一成员变量为B为例。电子设备可以将B的数据从原先的地址存入填充1对应的地址段。比如,电子设备可以将B的数据从0x10-0x11转存到填充1对应的地址段(如0x02-0x07)中。For example, please refer to FIG. 13 in conjunction with FIG. 12 . Take the first member variable as B as an example. The electronic device can store the data of B from the original address into the address segment corresponding to filling 1. For example, the electronic device can dump the data of B from 0x10-0x11 to the address segment corresponding to filling 1 (such as 0x02-0x07).
需要说明的是,由于B的数据量(2bytes)小于填充1的地址段的大小(6bytes),因此,在本申请的不同实现中,电子设备可以将B的数据转存到填充1的地址段中的任意位置。比如,在一些实现中,电子设备可以将B的数据转存到填充1中的地址段的首地址作为起点的位置。也就是说,在转存之后,B的首地址可以与转存之前填充1的首地址相同。比如,结合图13,转存之后,B的首地址可以为0x02。可以理解的是,在本申请的另一些实现中,转存后的B对应的地址段,也可以是与转存之前填充 1对应的地址段具有相同末尾地址。It should be noted that since the data volume of B (2 bytes) is smaller than the size of the address segment filled with 1 (6 bytes), therefore, in different implementations of this application, the electronic device can dump the data of B to the address segment filled with 1 anywhere in the . For example, in some implementations, the electronic device may dump the data of B to a location where the first address of the address segment in filling 1 is used as a starting point. That is to say, after dumping, the first address of B can be the same as the first address filled with 1 before dumping. For example, referring to Figure 13, after dumping, the first address of B can be 0x02. It can be understood that, in other implementations of the present application, the address segment corresponding to B after dumping may also have the same end address as the address segment corresponding to filling 1 before dumping.
作为一种可能的实现,图14示出了一种转存第一成员变量之后的数据结构。As a possible implementation, FIG. 14 shows a data structure after dumping the first member variable.
可以看到,在将B转存到填充1的地址段之后,响应地压缩了填充1对应的无效地址段长度。这样,电子设备就可以通过1次读取操作,将ABF三个成员变量读入缓存中。相较于直接读取如图12所示的数据结构,能够一次性读入更多的成员变量,同时还能够减少缓存中由于padding产生的无效存储。It can be seen that after dumping B to the address segment filled with 1, the length of the invalid address segment corresponding to pad 1 is correspondingly compressed. In this way, the electronic device can read the three member variables of ABF into the cache through one read operation. Compared with directly reading the data structure shown in Figure 12, more member variables can be read at one time, and at the same time, invalid storage due to padding in the cache can be reduced.
需要说明的是,在本申请的一些实施例中,在电子设备将第一成员变量转存到第一填充字段之后,可以在原先存储第一成员变量的地址段进行填充,以便释放对应的存储空间。示例性的,结合图14,在将B转存到填充1之后,电子设备可以在原先存储B的地址段进行填充,如填充之后的该部分空间可以对应如图5所示的填充5。这样就可以避免第一成员变量在数据结构中的重复存储,同时能够合理释放内存的存储空间。在本申请的另一些实施例中,电子设备还可以将填充5与相邻的填充2结合行程一个连续的填充字段。比如,电子设备可以在将B转存到填充1之后,将与原先存储B的地址段相邻的padding地址段(即填充2)向原先存储B的地址段生长,使得生长后的填充2的地址段覆盖原先存储B的地址段。由此获取更大的填充2的地址段。比如,图15示出了该示例中填充2生长之后的示意。可以看到,填充2在生长之后,其首地址与原先存储B的地址段的首地址相同。由此就达到了释放原先存储B的地址段的存储空间的目的。It should be noted that, in some embodiments of the present application, after the electronic device dumps the first member variable into the first filling field, it can fill in the address segment where the first member variable was originally stored, so as to release the corresponding storage space. Exemplarily, with reference to FIG. 14 , after dumping B to fill 1, the electronic device can fill in the address segment where B was originally stored. For example, this part of the space after filling can correspond to fill 5 as shown in FIG. 5 . In this way, repeated storage of the first member variable in the data structure can be avoided, and at the same time, the storage space of the memory can be reasonably released. In some other embodiments of the present application, the electronic device may also combine padding 5 with adjacent padding 2 to form a continuous padding field. For example, after the electronic device dumps B into padding 1, it can grow the padding address segment adjacent to the address segment originally storing B (that is, padding 2) to the address segment originally storing B, so that the grown address segment of padding 2 Overwrite the address segment where B was originally stored. Thus, a larger address segment filled with 2 is obtained. For example, Figure 15 shows a schematic of this example after Fill 2 growth. It can be seen that after padding 2 grows, its first address is the same as the first address of the address segment where B was originally stored. Thus, the purpose of releasing the storage space of the address segment of B originally stored is achieved.
为了尽量减少结构体的数据结构中填充字段的长度,同时能够将高访问频率的成员变量尽量集中,在本申请的一些实施例中,可以在执行S1005之后,重复执行S1004,以便于电子设备可以重复使用符合要求的成员变量填充字段靠前的填充字段,从而使得结构体的整体数据结构更加紧凑,填充字段占用的存储空间更少。In order to minimize the length of the padding field in the data structure of the structure and at the same time concentrate the member variables with high access frequency as much as possible, in some embodiments of the present application, S1004 can be executed repeatedly after S1005 is executed, so that the electronic device can Reuse the member variables that meet the requirements to fill in the front filling fields, so that the overall data structure of the structure is more compact, and the filling fields occupy less storage space.
为了使得本领域技术人员可以更加清楚地了解本申请实施例提供的编译优化方法,以下给出一种具体的实现该方案的示例以供参考。In order to enable those skilled in the art to understand more clearly the compilation optimization method provided by the embodiment of the present application, a specific example of implementing the solution is given below for reference.
示例性的,结合图10,在执行完成S1003获取第二优化结果之后,电子设备可以获取如图11所示的数据结构。在本示例中,该第二优化结果对应的数据结构中的成员变量可以构成一个栈。该栈中数据的分布可以与如图11所示的数据结构相同。也就是说,在该栈中,成员变量按照地址的前后顺序可以为:AFBCDGE。Exemplarily, with reference to FIG. 10 , after the execution of S1003 to acquire the second optimization result, the electronic device may acquire the data structure shown in FIG. 11 . In this example, the member variables in the data structure corresponding to the second optimization result may form a stack. The distribution of data in the stack can be the same as the data structure shown in FIG. 11 . That is to say, in this stack, the member variables can be: AFBCDGE according to the sequence of addresses.
电子设备可以按照以下方式实现S1005-S1006的效果。The electronic device can realize the effects of S1005-S1006 in the following manner.
在一些实施例中,结合图16。电子设备可以从数据结构成员变量的首地址(如上述示例中的0x00)开始遍历结构体中存储的数据(如执行S1601)。电子设备可以判断当前地址的所存储的数据是否是成员变量(如执行S1602)。如果是成员变量则执行以下S1603。可以理解的是,如果当前地址所存储的数据是成员变量,那么表明尚未发现填充字段。则电子设备可以对该地址存储的变量执行出栈,并读取下一地址位的内容(即执行S1603)。针对下一位内容,电子设备可以重复执行S1602,直到当前地址位的内容为填充操作过程中填入的无效数据为止,则电子设备可以执行以下S1604。可以理解的是,在当前地址为的内容为填充操作填充的无效数据时,则表明当前地址为填充操作产生的填充字段的首地址(如对应上述示例中的第一填充字段的首地址)。也就是说,通过上述S1601-S1603,即可确定如S1004中的第一填充字段。In some embodiments, refer to FIG. 16 . The electronic device can traverse the data stored in the structure starting from the first address of the member variable of the data structure (such as 0x00 in the above example) (such as executing S1601). The electronic device can determine whether the stored data at the current address is a member variable (for example, execute S1602). If it is a member variable, execute the following S1603. It can be understood that if the data stored at the current address is a member variable, it indicates that the filling field has not been found yet. Then the electronic device can pop the variable stored at the address from the stack, and read the content of the next address bit (that is, execute S1603). For the content of the next bit, the electronic device may repeatedly execute S1602 until the content of the current address bit is invalid data filled in during the fill operation, then the electronic device may execute the following S1604. It can be understood that when the content of the current address is invalid data filled by the filling operation, it indicates that the current address is the first address of the filling field generated by the filling operation (such as corresponding to the first address of the first filling field in the above example). That is to say, through the above S1601-S1603, the first padding field as in S1004 can be determined.
接着,电子设备可以遍历当前地址之后的栈中的成员变量,从而获取符合要求的第一成员变量(即执行S1604)。示例性的,电子设备可以在遍历的过程中,如果该成员变量的大小大于第一填充字段的大小,那么继续向后执行遍历。直到获取大小小于或等于第一填充字段的大小的成员变量(对应上述示例中的符合要求的第一成员变量)。Next, the electronic device may traverse the member variables in the stack after the current address, so as to obtain the first member variable that meets the requirements (that is, execute S1604). Exemplarily, during the traversal process, if the size of the member variable is greater than the size of the first filled field, the electronic device may continue to perform traversal backwards. until obtaining a member variable whose size is less than or equal to the size of the first filled field (corresponding to the first member variable that meets the requirements in the above example).
此后,电子设备可以将第一成员变量的内容替换到当前栈的填充首地址中(如执行S1605)。由此即可实现第一成员变量向第一填充字段的转存。可以理解的是,在执行S1603时,已经将位于填充字段之前的成员变量执行出栈处理,因此,在转存第一成员变量时,当前栈的填充首地址即为第一填充字段的首地址。Afterwards, the electronic device may replace the content of the first member variable into the filled first address of the current stack (for example, execute S1605). In this way, the transfer of the first member variable to the first filling field can be realized. It can be understood that when S1603 is executed, the member variable before the filling field has been popped out, therefore, when the first member variable is dumped, the first filling address of the current stack is the first filling address of the first filling field .
在完成上述S1601-S1605之后,电子设备就可以将第一成员变量转存到第一填充字段。在本申请的一些实施例中,在完成S1605之后,电子设备可以重复执行S1601,以便于继续优化当前结构体中的数据结构。直到电子设备在执行S1602的判断过程中,确定当前地址位为结构体的数据结构范围外的地址,那么就表明完成了对当前结构体的优化。After completing the above S1601-S1605, the electronic device can dump the first member variable into the first filling field. In some embodiments of the present application, after completing S1605, the electronic device may repeatedly execute S1601, so as to continue optimizing the data structure in the current structure. Until the electronic device determines that the current address bit is an address outside the data structure range of the structure during the judgment process of S1602, it indicates that the optimization of the current structure is completed.
示例性的,请参考图17,示出了根据本申请实施例提供的方案,对结构体的数据结构进行多次优化的效果示意图。结合图14,在获取如图14所示的数据结构之后,电子设备可以按照如图17中的(a)所示,将C转存到填充1对应的地址段中。由此可以获取如图17中的(b)所示的数据结构。电子设备还可以将D转存到填充2对应的地址段中。由此可以获取如图17中的(c)所示的数据结构。电子设备还可以将E转存到填充2对应的地址段中。由此可以获取如图17中的(d)所示的数据结构。电子设备还可以将G转存到填充3对应的地址段中。由此可以获取如图17中的(e)所示的数据结构。如图17中的(e)所示,经过上述数据结构的优化处理,电子设备可以一次性将具有较高调用频率的成员变量A和F读入缓存。同时还能够读入B和C,由此使得电子设备在读入如图17中的(e)所示的第一行和第二行数据时,不会引入无效数据占用缓存空间。类似的,电子设备可以一次性将D,E和G读入缓存,而不引入无效数据占用缓存空间。另外,优化后的结构体的数据中,能够释放两行的连续的内存空间(如图17中的(e)所示的填充4),由此也能够提升内存的使用率。For example, please refer to FIG. 17 , which shows a schematic diagram of the effect of performing multiple optimizations on the data structure of the structure according to the solution provided by the embodiment of the present application. Referring to FIG. 14 , after acquiring the data structure shown in FIG. 14 , the electronic device can dump C into the address segment corresponding to filling 1 as shown in (a) in FIG. 17 . Thus, a data structure as shown in (b) in FIG. 17 can be obtained. The electronic device can also dump D into the address segment corresponding to filling 2. Thereby, a data structure as shown in (c) in FIG. 17 can be obtained. The electronic device can also dump E into the address segment corresponding to filling 2. Thereby, a data structure as shown in (d) in FIG. 17 can be obtained. The electronic device can also dump G into the address segment corresponding to filling 3. Thereby, a data structure as shown in (e) in FIG. 17 can be obtained. As shown in (e) in FIG. 17 , after optimizing the above data structure, the electronic device can read the member variables A and F with high calling frequency into the cache at one time. At the same time, B and C can also be read, so that when the electronic device reads the first row and the second row of data as shown in (e) in FIG. 17 , invalid data will not be introduced to occupy the cache space. Similarly, the electronic device can read D, E and G into the cache at one time without introducing invalid data to occupy the cache space. In addition, in the data of the optimized structure, two rows of continuous memory space (filling 4 as shown in (e) in FIG. 17 ) can be released, thereby also improving memory usage.
结合前述说明,基于本申请实施例提供的方案,以libart.so与CompileMethod类为例,电子设备可以在二次编译共享库时,将高频访问的cfi_info、quick_code等成员进行排布顺序上的聚类,同时基于成员大小进行填充排布,最后基于类似于本申请中的Algorithm Pad Order算法,对成员布局顺序进行优化。最终基于该顺序填充的类、结构体进行编译。In combination with the foregoing description, based on the solution provided by the embodiment of the present application, taking libart.so and CompileMethod class as examples, the electronic device can arrange the frequently accessed members such as cfi_info and quick_code in the sequence when compiling the shared library for the second time. Clustering, while filling and arranging based on the member size, and finally based on the Algorithm Pad Order algorithm similar to this application, optimize the member layout order. Finally, compile based on the classes and structures filled in this order.
在获取最终的优化编译共享库libart.so后,可以作为release版本二进制发布,相比未优化的版本,其类、结构体的代码空间利用率更高,执行效率更优。可以提升如上述例子中仿淘宝在运行时的启动速度、帧率等指标。After obtaining the final optimized and compiled shared library libart.so, it can be released as a release version binary. Compared with the unoptimized version, the code space utilization rate of its classes and structures is higher, and the execution efficiency is better. It can improve the startup speed, frame rate and other indicators of imitation Taobao in the above example.
作为一种可能的实现,本申请实施例还提供实现上述图16所示方案的伪代码以供参考:As a possible implementation, the embodiment of this application also provides a pseudocode for implementing the scheme shown in Figure 16 above for reference:
Figure PCTCN2022096071-appb-000003
Figure PCTCN2022096071-appb-000003
Figure PCTCN2022096071-appb-000004
Figure PCTCN2022096071-appb-000004
这样,通过将第一成员变量存入第一填充字段,使得内存的存储空间得到更大程度的利用,CPU可以通过1次读取操作将更多的有效数据读入缓存,同时能够减少无效存储对内存和缓存的消耗,提升存储空间的利用率。In this way, by storing the first member variable in the first filling field, the storage space of the memory can be utilized to a greater extent, and the CPU can read more valid data into the cache through one read operation, and at the same time reduce invalid storage The consumption of memory and cache improves the utilization of storage space.
上述主要从电子设备的角度对本申请实施例提供的方案进行了介绍。为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。The foregoing mainly introduces the solutions provided by the embodiments of the present application from the perspective of electronic devices. In order to realize the above functions, it includes corresponding hardware structures and/or software modules for performing various functions. Those skilled in the art should easily realize that the present application can be implemented in the form of hardware or a combination of hardware and computer software in combination with the units and algorithm steps of each example described in the embodiments disclosed herein. Whether a certain function is executed by hardware or computer software drives hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present application.
本申请实施例可以根据上述方法示例对其中涉及的设备进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一 种逻辑功能划分,实际实现时可以有另外的划分方式。The embodiments of the present application may divide the involved devices into functional modules according to the above method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software function modules. It should be noted that the division of modules in the embodiment of the present application is schematic, and is only a logical function division, and there may be other division methods in actual implementation.
请参考图18,为本申请实施例提供的一种编译优化装置1800的组成示意图。示例性的,该装置可以应用于电子设备,该装置包括:排序单元1801,用于,在安装应用程序时,或者安装该应用程序之后,在对该应用程序进行编译时,根据该访问频率,排序该应用程序的第一结构体的成员变量的存储顺序,该成员变量包括第一成员变量和第二成员变量,该第一成员变量的访问频率高于该第二成员变量,该第一成员变量的存储顺序在该第二成员变量之前。填充单元1802,用于根据第一字节宽度,通过填充字段对该成员变量进行字节对齐。其中,第一填充字段用于对该第一成员变量进行字节对齐。存储单元1803,用于将该第二成员变量存入该第一填充字段。该第一填充字段的大小大于或等于该第二成员变量的大小。Please refer to FIG. 18 , which is a schematic composition diagram of a compiling optimization device 1800 provided by the embodiment of the present application. Exemplarily, the apparatus may be applied to electronic equipment, and the apparatus includes: a sorting unit 1801 configured to, according to the access frequency, when the application is installed, or after the application is installed, when the application is compiled, Sort the storage order of the member variables of the first structure of the application program, the member variables include the first member variable and the second member variable, the access frequency of the first member variable is higher than that of the second member variable, the first member variable The storage order of the variables precedes the second member variable. The filling unit 1802 is configured to perform byte alignment on the member variable through the filling field according to the first byte width. Wherein, the first padding field is used for byte alignment of the first member variable. The storage unit 1803 is configured to store the second member variable into the first filling field. The size of the first padding field is greater than or equal to the size of the second member variable.
在一种可能的设计中,该装置还包括:调整单元1804,用于在该将第二成员变量存入第一填充字段之后,根据该第一成员变量和/或该第二成员变量的存储地址,调整访问该成员变量的偏移量。In a possible design, the device further includes: an adjusting unit 1804, configured to, after storing the second member variable into the first filling field, according to the storage of the first member variable and/or the second member variable Address, adjust the offset to access the member variable.
在一种可能的设计中,该装置还包括:获取单元1805,用于在该根据该访问频率,排序该应用程序的第一结构体的成员变量的存储顺序之前,获取该电子设备运行过程中,该第一结构体中的每个该成员变量的访问频率。In a possible design, the device further includes: an acquisition unit 1805, configured to acquire the storage order of the member variables of the first structure of the application program according to the access frequency, and acquire the , the access frequency of each member variable in the first structure.
在一种可能的设计中,该第一字节宽度是根据该电子设备的处理器的读取带宽确定的,该处理器的读取带宽是该处理器执行一次读取操作时,能够读取的最大数据量。In a possible design, the first byte width is determined according to the read bandwidth of the processor of the electronic device, and the read bandwidth of the processor is when the processor performs a read operation, it can read the maximum amount of data.
在一种可能的设计中,获取单元1805,用于对该第一结构体中每个该成员变量执行插桩操作,根据该应用程序进行编译过程中,***各个成员变量的检测标识的调用次数,确定每个该成员变量的访问频率。In a possible design, the acquisition unit 1805 is configured to perform an instrumentation operation for each member variable in the first structure, and insert the number of calls of the detection identifier of each member variable during the compilation process of the application program , to determine the access frequency of each of the member variables.
在一种可能的设计中,该装置还包括:查找单元1806,用于在将该第二成员变量存入该第一填充字段之前,查找该排序该应用程序的第一结构体的成员变量的存储顺序后,未存储成员变量的第一地址,该第一地址是该第一填充字段的首地址。查找单元1806,还用于在该第一地址之后,查找该第二成员变量,该第二成员变量的存储地址在该第一地址之后,该第二成员变量的大小小于该第一填充字段的大小。存储单元1803,用于将该第四成员变量的数据,存储的到该第一填充字段中。In a possible design, the device further includes: a search unit 1806, configured to search for the member variable of the first structure of the application program before storing the second member variable in the first filling field. After the sequence is stored, the first address of the member variable is not stored, and the first address is the first address of the first filled field. The search unit 1806 is further configured to search for the second member variable after the first address, the storage address of the second member variable is after the first address, and the size of the second member variable is smaller than that of the first padding field size. The storage unit 1803 is configured to store the data of the fourth member variable in the first filling field.
在一种可能的设计中,存储单元1803,用于对该第二成员变量在该排序该应用程序的第一结构体的成员变量的存储顺序后的存储地址填充无效数据。或者,该装置还包括:删除单元1807,用于删除该第二成员变量在该排序该应用程序的第一结构体的成员变量的存储顺序后的存储地址中的数据。In a possible design, the storage unit 1803 is configured to fill the storage address of the second member variable after the storage order of the member variables of the first structure of the application program with invalid data. Alternatively, the device further includes: a deleting unit 1807, configured to delete the data in the storage address of the second member variable after the storage order of the member variables of the first structure of the application program.
在一种可能的设计中,查找单元1806,用于在将该第二成员变量存入该第一填充字段之后,查找未存储成员变量的第二地址,该第二地址是当前存储顺序中的第二填充字段的首地址。查找单元1806,用于在该第二地址之后,查找第三成员变量,该第三成员变量的存储地址在该第二地址之后,该第五成员变量的大小小于该第二填充字段的大小。存储单元1803,用于将该第三成员变量的数据,存储的到该第二填充字段中。In a possible design, the search unit 1806 is configured to search for a second address of an unstored member variable after storing the second member variable in the first filling field, and the second address is the address in the current storage sequence. The first address of the second padding field. The search unit 1806 is configured to search for a third member variable after the second address, the storage address of the third member variable is after the second address, and the size of the fifth member variable is smaller than the size of the second padding field. The storage unit 1803 is configured to store the data of the third member variable in the second filling field.
需要说明的是,上述方法实施例涉及的各步骤的所有相关内容均可以援引到对应功能模块的功能描述,在此不再赘述。It should be noted that all relevant content of the steps involved in the above method embodiments can be referred to the function description of the corresponding function module, and will not be repeated here.
图19示出了的一种电子设备1900的组成示意图。如图19所示,该电子设备1900可以包括:处理器1901和存储器1902。该存储器1902用于存储计算机执行指令。示例性的,在一些实施例中,当该处理器1901执行该存储器1902存储的指令时,可以使得该电子设备1900执行上述实施例中任一种所示的编译优化方法。FIG. 19 shows a schematic composition diagram of an electronic device 1900 . As shown in FIG. 19 , the electronic device 1900 may include: a processor 1901 and a memory 1902 . The memory 1902 is used to store computer-executable instructions. Exemplarily, in some embodiments, when the processor 1901 executes the instructions stored in the memory 1902, the electronic device 1900 may be made to execute the compilation optimization method shown in any one of the above embodiments.
需要说明的是,上述方法实施例涉及的各步骤的所有相关内容均可以援引到对应功能模块的功能描述,在此不再赘述。It should be noted that all relevant content of the steps involved in the above method embodiments can be referred to the function description of the corresponding function module, and will not be repeated here.
图20示出了的一种芯片***2000的组成示意图。该芯片***2000可以包括:处理器2001和通信接口2002,用于支持相关设备实现上述实施例中所涉及的功能。在一种可能的设计中,芯片***还包括存储器,用于保存终端必要的程序指令和数据。该芯片***,可以由芯片构成,也可以包含芯片和其他分立器件。需要说明的是,在本申请的一些实现方式中,该通信接口2002也可称为接口电路。FIG. 20 shows a schematic composition diagram of a chip system 2000 . The chip system 2000 may include: a processor 2001 and a communication interface 2002, configured to support related devices to implement the functions involved in the foregoing embodiments. In a possible design, the chip system further includes a memory for saving necessary program instructions and data of the terminal. The system-on-a-chip may consist of chips, or may include chips and other discrete devices. It should be noted that, in some implementation manners of the present application, the communication interface 2002 may also be called an interface circuit.
需要说明的是,上述方法实施例涉及的各步骤的所有相关内容均可以援引到对应功能模块的功能描述,在此不再赘述。It should be noted that all relevant content of the steps involved in the above method embodiments can be referred to the function description of the corresponding function module, and will not be repeated here.
在上述实施例中的功能或动作或操作或步骤等,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件程序实现时,可以全部或部分地以计算机程序产品的形式来实现。该计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或者数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包括一个或多个可以用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带),光介质(例如,DVD)、或者半导体介质(例如固态硬盘(solid state disk,SSD))等。The functions or actions or operations or steps in the above-mentioned embodiments may be fully or partially implemented by software, hardware, firmware or any combination thereof. When implemented using a software program, it 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 the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application will be generated in whole or in part. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website, computer, server, or data center Transmission to another website site, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer, or may include one or more data storage devices such as servers and data centers that can be integrated with the medium. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, or a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (solid state disk, SSD)), etc.
尽管结合具体特征及其实施例对本申请进行了描述,显而易见的,在不脱离本申请的精神和范围的情况下,可对其进行各种修改和组合。相应地,本说明书和附图仅仅是所附权利要求所界定的本申请的示例性说明,且视为已覆盖本申请范围内的任意和所有修改、变化、组合或等同物。显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包括这些改动和变型在内。Although the application has been described in conjunction with specific features and embodiments thereof, it will be apparent that various modifications and combinations can be made thereto without departing from the spirit and scope of the application. Accordingly, the specification and drawings are merely illustrative of the application as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of this application. Obviously, those skilled in the art can make various changes and modifications to the application without departing from the spirit and scope of the application. In this way, if these modifications and variations of the application fall within the scope of the claims of the application and their equivalent technologies, the application also intends to include these modifications and variations.

Claims (18)

  1. 一种编译优化方法,其特征在于,应用于电子设备,所述方法包括:A compiling optimization method, characterized in that it is applied to electronic equipment, the method comprising:
    在安装应用程序时,或者安装所述应用程序之后,在对所述应用程序进行编译时,When the application is installed, or after the application is installed, when the application is compiled,
    根据所述访问频率,排序所述应用程序的第一结构体的成员变量的存储顺序,所述成员变量包括第一成员变量和第二成员变量,所述第一成员变量的访问频率高于所述第二成员变量,所述第一成员变量的存储顺序在所述第二成员变量之前;根据第一字节宽度,通过填充字段对所述成员变量进行字节对齐;其中,第一填充字段用于对所述第一成员变量进行字节对齐;将所述第二成员变量存入所述第一填充字段;所述第一填充字段的大小大于或等于所述第二成员变量的大小。According to the access frequency, sort the storage order of the member variables of the first structure of the application program, the member variables include a first member variable and a second member variable, and the access frequency of the first member variable is higher than that of the first member variable The second member variable, the storage order of the first member variable is before the second member variable; according to the first byte width, the member variable is byte-aligned through the padding field; wherein, the first padding field It is used to perform byte alignment on the first member variable; store the second member variable in the first padding field; the size of the first padding field is greater than or equal to the size of the second member variable.
  2. 根据权利要求1所述的方法,其特征在于,在所述将第二成员变量存入第一填充字段之后,所述方法还包括:根据所述第一成员变量和/或所述第二成员变量的存储地址,调整访问所述成员变量的偏移量。The method according to claim 1, characterized in that, after storing the second member variable into the first filling field, the method further comprises: according to the first member variable and/or the second member The storage address of the variable, adjust the offset for accessing the member variable.
  3. 根据权利要求1或2所述的方法,其特征在于,在所述根据所述访问频率,排序所述应用程序的第一结构体的成员变量的存储顺序之前,所述方法还包括:The method according to claim 1 or 2, wherein, before sorting the storage order of the member variables of the first structure of the application according to the access frequency, the method further comprises:
    获取所述电子设备运行过程中,所述第一结构体中的每个所述成员变量的访问频率。Acquiring the access frequency of each member variable in the first structure during the operation of the electronic device.
  4. 根据权利要求1-3中任一项所述的方法,其特征在于,The method according to any one of claims 1-3, characterized in that,
    所述第一字节宽度是根据所述电子设备的处理器的读取带宽确定的,所述处理器的读取带宽是所述处理器执行一次读取操作时,能够读取的最大数据量。The first byte width is determined according to the read bandwidth of the processor of the electronic device, and the read bandwidth of the processor is the maximum amount of data that can be read when the processor performs a read operation .
  5. 根据权利要求1-4中任一项所述的方法,其特征在于,所述获取所述电子设备运行过程中,所述第一结构体中的每个所述成员变量的访问频率,包括:The method according to any one of claims 1-4, wherein the acquiring the access frequency of each member variable in the first structure during the operation of the electronic device includes:
    对所述第一结构体中每个所述成员变量执行插桩操作,performing an instrumentation operation on each of the member variables in the first structure,
    根据所述应用程序进行编译过程中,***各个成员变量的检测标识的调用次数,确定每个所述成员变量的访问频率。The access frequency of each member variable is determined according to the calling times of the detection identifiers inserted into each member variable during the compilation process of the application program.
  6. 根据权利要求1-5中任一项所述的方法,其特征在于,在将所述第二成员变量存入所述第一填充字段之前,所述方法还包括:The method according to any one of claims 1-5, wherein before storing the second member variable into the first filling field, the method further comprises:
    查找所述排序所述应用程序的第一结构体的成员变量的存储顺序后,未存储成员变量的第一地址,所述第一地址是所述第一填充字段的首地址;After searching for the storage order of the member variables of the first structure of the application program, the first address of the member variable is not stored, and the first address is the first address of the first filled field;
    在所述第一地址之后,查找所述第二成员变量,所述第二成员变量的存储地址在所述第一地址之后,所述第二成员变量的大小小于所述第一填充字段的大小;After the first address, search for the second member variable, the storage address of the second member variable is after the first address, and the size of the second member variable is smaller than the size of the first padding field ;
    所述将所述第一优化结果中,第一成员变量存入第一填充字段,包括:The storing the first member variable in the first optimization result into the first filling field includes:
    将所述第四成员变量的数据,存储的到所述第一填充字段中。Store the data of the fourth member variable into the first filling field.
  7. 根据权利要求6所述的方法,其特征在于,所述方法还包括:The method according to claim 6, further comprising:
    对所述第二成员变量在所述排序所述应用程序的第一结构体的成员变量的存储顺序后的存储地址填充无效数据;或者,删除所述第二成员变量在所述排序所述应用程序的第一结构体的成员变量的存储顺序后的存储地址中的数据。Filling the storage address of the second member variable with invalid data after the storage order of the member variables of the first structure of the application in the sorting; or, deleting the second member variable in the sorting of the application The data in the storage address after the storage order of the member variables of the first structure of the program.
  8. 根据权利要求6或7所述的方法,其特征在于,在将所述第二成员变量存入所述第一填充字段之后,所述方法还包括:The method according to claim 6 or 7, wherein after storing the second member variable into the first filling field, the method further comprises:
    查找未存储成员变量的第二地址,所述第二地址是当前存储顺序中的第二填充字 段的首地址;Find the second address of the unstored member variable, the second address is the first address of the second filled field in the current storage order;
    在所述第二地址之后,查找第三成员变量,所述第三成员变量的存储地址在所述第二地址之后,所述第五成员变量的大小小于所述第二填充字段的大小;After the second address, search for a third member variable, the storage address of the third member variable is after the second address, and the size of the fifth member variable is smaller than the size of the second padding field;
    将所述第三成员变量的数据,存储的到所述第二填充字段中。Store the data of the third member variable into the second filling field.
  9. 一种编译优化装置,其特征在于,应用于电子设备,所述装置包括:A compiling and optimizing device is characterized in that it is applied to electronic equipment, and the device includes:
    排序单元,用于在安装应用程序时,或者安装所述应用程序之后,在对所述应用程序进行编译时,根据所述访问频率,排序所述应用程序的第一结构体的成员变量的存储顺序,所述成员变量包括第一成员变量和第二成员变量,所述第一成员变量的访问频率高于所述第二成员变量,所述第一成员变量的存储顺序在所述第二成员变量之前;填充单元,用于根据第一字节宽度,通过填充字段对所述成员变量进行字节对齐;其中,第一填充字段用于对所述第一成员变量进行字节对齐;存储单元,用于将所述第二成员变量存入所述第一填充字段;所述第一填充字段的大小大于或等于所述第二成员变量的大小。The sorting unit is configured to sort the storage of the member variables of the first structure of the application program according to the access frequency when the application program is installed, or when the application program is compiled after the application program is installed order, the member variables include a first member variable and a second member variable, the access frequency of the first member variable is higher than that of the second member variable, and the storage order of the first member variable is in the second member variable Before the variable; padding unit, used to perform byte alignment on the member variable through the padding field according to the first byte width; wherein, the first padding field is used to perform byte alignment on the first member variable; storage unit , for storing the second member variable in the first padding field; the size of the first padding field is greater than or equal to the size of the second member variable.
  10. 根据权利要求9所述的装置,其特征在于,所述装置还包括:调整单元,用于在所述将第二成员变量存入第一填充字段之后,根据所述第一成员变量和/或所述第二成员变量的存储地址,调整访问所述成员变量的偏移量。The device according to claim 9, characterized in that the device further comprises: an adjusting unit, configured to, after storing the second member variable into the first padding field, according to the first member variable and/or The storage address of the second member variable adjusts the offset for accessing the member variable.
  11. 根据权利要求9或10所述的装置,其特征在于,所述装置还包括:获取单元,用于在所述根据所述访问频率,排序所述应用程序的第一结构体的成员变量的存储顺序之前,获取所述电子设备运行过程中,所述第一结构体中的每个所述成员变量的访问频率。The device according to claim 9 or 10, characterized in that the device further comprises: an acquisition unit, configured to sort the storage of the member variables of the first structure of the application program according to the access frequency Before the sequence, the access frequency of each member variable in the first structure is acquired during the operation of the electronic device.
  12. 根据权利要求9-11中任一项所述的装置,其特征在于,The device according to any one of claims 9-11, characterized in that,
    所述第一字节宽度是根据所述电子设备的处理器的读取带宽确定的,所述处理器的读取带宽是所述处理器执行一次读取操作时,能够读取的最大数据量。The first byte width is determined according to the read bandwidth of the processor of the electronic device, and the read bandwidth of the processor is the maximum amount of data that can be read when the processor performs a read operation .
  13. 根据权利要求9-12中任一项所述的装置,其特征在于,所述获取单元,用于对所述第一结构体中每个所述成员变量执行插桩操作,根据所述应用程序进行编译过程中,***各个成员变量的检测标识的调用次数,确定每个所述成员变量的访问频率。The device according to any one of claims 9-12, wherein the acquiring unit is configured to perform an instrumentation operation on each of the member variables in the first structure, according to the application In the process of compiling, insert the calling times of the detection identification of each member variable, and determine the access frequency of each said member variable.
  14. 根据权利要求9-13中任一项所述的装置,其特征在于,所述装置还包括:查找单元,用于在将所述第二成员变量存入所述第一填充字段之前,查找所述排序所述应用程序的第一结构体的成员变量的存储顺序后,未存储成员变量的第一地址,所述第一地址是所述第一填充字段的首地址;The device according to any one of claims 9-13, further comprising: a search unit, configured to search for the After sorting the storage order of the member variables of the first structure of the application program, the first address of the member variable is not stored, and the first address is the first address of the first filling field;
    所述查找单元,还用于在所述第一地址之后,查找所述第二成员变量,所述第二成员变量的存储地址在所述第一地址之后,所述第二成员变量的大小小于所述第一填充字段的大小;The search unit is further configured to search for the second member variable after the first address, the storage address of the second member variable is after the first address, and the size of the second member variable is smaller than the size of the first padding field;
    所述存储单元,用于将所述第四成员变量的数据,存储的到所述第一填充字段中。The storage unit is configured to store the data of the fourth member variable in the first filling field.
  15. 根据权利要求14所述的装置,其特征在于,所述存储单元,用于对所述第二成员变量在所述排序所述应用程序的第一结构体的成员变量的存储顺序后的存储地址填充无效数据;或者,所述装置还包括:删除单元,用于删除所述第二成员变量在所述排序所述应用程序的第一结构体的成员变量的存储顺序后的存储地址中的数据。The device according to claim 14, wherein the storage unit is configured to store the storage address of the second member variable after the storage order of the member variables of the first structure of the application program filling invalid data; or, the device further includes: a deletion unit, configured to delete the data in the storage address of the second member variable after the storage order of the member variables of the first structure of the application program .
  16. 根据权利要求14或15所述的装置,其特征在于,所述查找单元,用于查找未 存储成员变量的第二地址,所述第二地址是当前存储顺序中的第二填充字段的首地址;The device according to claim 14 or 15, wherein the search unit is configured to search for a second address of an unstored member variable, and the second address is the first address of the second filling field in the current storage order ;
    所述查找单元,用于在所述第二地址之后,查找第三成员变量,所述第三成员变量的存储地址在所述第二地址之后,所述第五成员变量的大小小于所述第二填充字段的大小;The search unit is configured to search for a third member variable after the second address, the storage address of the third member variable is after the second address, and the size of the fifth member variable is smaller than the size of the first member variable 2 the size of the padding field;
    所述存储单元,用于将所述第三成员变量的数据,存储的到所述第二填充字段中。The storage unit is configured to store the data of the third member variable in the second filling field.
  17. 一种电子设备,其特征在于,所述电子设备包括一个或多个处理器和一个或多个存储器;所述一个或多个存储器与所述一个或多个处理器耦合,所述一个或多个存储器存储有计算机指令;An electronic device, characterized in that the electronic device includes one or more processors and one or more memories; the one or more memories are coupled to the one or more processors, and the one or more a memory stores computer instructions;
    当所述一个或多个处理器执行所述计算机指令时,使得所述电子设备执行如权利要求1-8中任一项所述的编译优化方法。When the one or more processors execute the computer instructions, the electronic device is made to execute the compiling optimization method according to any one of claims 1-8.
  18. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质包括计算机指令,当所述计算机指令运行时,执行如权利要求1-8中任一项所述的编译优化方法。A computer-readable storage medium, characterized in that the computer-readable storage medium includes computer instructions, and when the computer instructions are executed, the compiling optimization method according to any one of claims 1-8 is executed.
PCT/CN2022/096071 2021-06-30 2022-05-30 Compilation optimization method and apparatus WO2023273766A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110738730.1A CN115543350A (en) 2021-06-30 2021-06-30 Compiling optimization method and device
CN202110738730.1 2021-06-30

Publications (1)

Publication Number Publication Date
WO2023273766A1 true WO2023273766A1 (en) 2023-01-05

Family

ID=84692521

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/096071 WO2023273766A1 (en) 2021-06-30 2022-05-30 Compilation optimization method and apparatus

Country Status (2)

Country Link
CN (1) CN115543350A (en)
WO (1) WO2023273766A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116991428B (en) * 2023-09-28 2023-12-15 飞腾信息技术有限公司 Compiling method, compiling device, compiler, computing device and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5940621A (en) * 1996-01-23 1999-08-17 Hewlett-Packard Company Language independent optimal size-based storage allocation
US5960454A (en) * 1996-12-19 1999-09-28 International Business Machines Corporation Avoiding cache collisions between frequently accessed, pinned routines or data structures
US20160371066A1 (en) * 2015-06-17 2016-12-22 Fujitsu Limited Computer that performs compiling, compiling method and storage medium that stores compiler program
CN111512298A (en) * 2018-04-03 2020-08-07 英特尔公司 Apparatus, method and system for conditional queuing in configurable spatial accelerators

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5940621A (en) * 1996-01-23 1999-08-17 Hewlett-Packard Company Language independent optimal size-based storage allocation
US5960454A (en) * 1996-12-19 1999-09-28 International Business Machines Corporation Avoiding cache collisions between frequently accessed, pinned routines or data structures
US20160371066A1 (en) * 2015-06-17 2016-12-22 Fujitsu Limited Computer that performs compiling, compiling method and storage medium that stores compiler program
CN111512298A (en) * 2018-04-03 2020-08-07 英特尔公司 Apparatus, method and system for conditional queuing in configurable spatial accelerators

Also Published As

Publication number Publication date
CN115543350A (en) 2022-12-30

Similar Documents

Publication Publication Date Title
WO2021083378A1 (en) Method for accelerating starting of application, and electronic device
WO2022258024A1 (en) Image processing method and electronic device
WO2020211712A1 (en) Patching method and related device, and system
WO2020093988A1 (en) Image processing method and electronic device
WO2021159746A1 (en) File sharing method and system, and related device
WO2021185352A1 (en) Version upgrade method and related apparatus
WO2021073337A1 (en) Method and apparatus for installing plug-in, and storage medium
CN113129202B (en) Data transmission method and device, data processing system and storage medium
WO2023273766A1 (en) Compilation optimization method and apparatus
WO2021104117A1 (en) Method for constructing application program resource packet, construction apparatus, and terminal device
WO2022111664A1 (en) Patching method, related apparatus, and system
CN113590346B (en) Method and electronic equipment for processing service request
WO2022033355A1 (en) Mail processing method and electronic device
WO2021238376A1 (en) Function pack loading method and apparatus, and server and electronic device
WO2022100132A1 (en) Data processing method and apparatus and electronic device
CN114828098B (en) Data transmission method and electronic equipment
CN112783418B (en) Method for storing application program data and mobile terminal
WO2023051036A1 (en) Method and apparatus for loading shader
WO2024046010A1 (en) Interface display method, and device and system
CN116709609B (en) Message delivery method, electronic device and storage medium
WO2024104095A1 (en) Data transmission method, apparatus and system
WO2023109569A1 (en) File storage method, file access method, electronic device, and storage medium
WO2023001208A1 (en) Multi-file synchronization method and electronic device
WO2023179682A1 (en) Device collaboration method
WO2024007944A1 (en) Method for extending memory isolation domain, and electronic device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22831588

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE