WO2023198103A1 - 进程间通信方法和电子设备 - Google Patents

进程间通信方法和电子设备 Download PDF

Info

Publication number
WO2023198103A1
WO2023198103A1 PCT/CN2023/087802 CN2023087802W WO2023198103A1 WO 2023198103 A1 WO2023198103 A1 WO 2023198103A1 CN 2023087802 W CN2023087802 W CN 2023087802W WO 2023198103 A1 WO2023198103 A1 WO 2023198103A1
Authority
WO
WIPO (PCT)
Prior art keywords
service
service information
processor
memory
data corresponding
Prior art date
Application number
PCT/CN2023/087802
Other languages
English (en)
French (fr)
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 WO2023198103A1 publication Critical patent/WO2023198103A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication

Definitions

  • the embodiments of the present application relate to the field of computer applications, and more specifically, to an inter-process communication method and electronic device.
  • the client process communicates with the service process, generally through inter-process communication (IPC).
  • IPC inter-process communication
  • the client process can transmit information through the binder mechanism. , obtain the data in the service process.
  • Embodiments of the present application provide an inter-process communication method and an electronic device to reduce unnecessary service process calls, thereby improving the operating speed and system performance of the electronic device and enhancing user experience.
  • an inter-process communication method includes: a processor obtains a request message in which a client process initiates a communication request to a service process; determines that the service information is stored in a memory according to the service information in the request message, and the The memory is located in the kernel space; the processor obtains data corresponding to the service information from the memory; and sends the data corresponding to the service information to the client process.
  • the processor can determine that the service information is stored in the memory based on the service information in the request message, so that the data corresponding to the service information can be directly obtained from the memory and sent to the client process. . Since the memory is located in the kernel space, the client process can obtain the data corresponding to the service information from the memory located in the kernel space without accessing the service process located in the user space. This can reduce unnecessary service calls and avoid IPC operations. It can effectively reduce system resource usage, improve the operating speed and system performance of electronic devices, and enhance user experience.
  • the method before determining that the service information is stored in the memory according to the service information in the request message, the method further includes: the processor sends the request message to the service process; receives the service The process sends the data corresponding to the service information, and stores the service information and the data corresponding to the service information in the memory.
  • the processor can send the request message to the service process, obtain the data corresponding to the service information returned by the service process, and save the service information and the data corresponding to the service information in the memory, that is, The results returned by the service process are cached, so that the next time the client process calls the service, the processor can directly obtain the data corresponding to the service information from the memory and send the data to the client process, thereby reducing unnecessary Necessary service calls can avoid system freezes and other problems caused by IPC operations, effectively reduce the occupation of system resources, improve the operating speed and system performance of electronic devices, and enhance user experience.
  • the service information and the data corresponding to the service information are stored in the memory, including: when the client process initiates a communication request to the service process, the processor records the first time point; when the service process responds to the communication request initiated by the client process, the processor records the second time point; the processor determines the service waiting time based on the first time point and the second time point; when the service waiting time is greater than the threshold, the processor The service information in the communication request and data corresponding to the service information are stored in the memory.
  • the processor can detect the time consuming of the IPC operation, and by setting the threshold of the service waiting time, detect the service that causes the client process to wait for too long, and store the service information corresponding to the service and the corresponding service information.
  • the data is stored in the memory, so that when the client process calls the service again, the data corresponding to the service can be obtained directly from the memory, thereby reducing unnecessary service calls, improving the operating speed and system performance of electronic devices, and enhancing user experience.
  • the service information and the data corresponding to the service information are stored in the memory, including: when the client process initiates a communication request to the service process, the processor records the communication request times; when the number of communication requests is greater than the threshold, the processor saves the service information and data corresponding to the service information in the memory.
  • the processor can detect the number of service requests, detect frequently called services by setting a threshold for the number of service requests, and store the service information corresponding to the service and the data corresponding to the service information in the memory. Therefore, when the client process calls the service again, the data corresponding to the service can be directly obtained from the memory, thereby reducing unnecessary service calls, improving the operating speed and system performance of the electronic device, and enhancing the user experience.
  • the processor can also detect the service waiting time and the number of service requests at the same time.
  • the processor can combine the service information and the service request.
  • the data corresponding to the information is stored in the memory.
  • the threshold for service waiting time and the threshold for the number of service requests By setting the threshold for service waiting time and the threshold for the number of service requests, services that cause the client process to wait too long and initiate communication requests multiple times are detected, and the service information corresponding to these services and the data corresponding to the service information can be stored in the memory. , so that when the client process calls these services again, the data corresponding to the service can be directly obtained from the memory, thereby reducing unnecessary service calls, improving the operating speed and system performance of the electronic device, and enhancing the user experience.
  • the processor can also save such services in the memory, so that when the client process calls these services again, it can be directly retrieved from the memory. Data corresponding to these services can be obtained from the system, thereby reducing unnecessary service calls, improving the operating speed and system performance of electronic devices, and enhancing user experience.
  • data corresponding to the service information is updated by the service process.
  • service information and data corresponding to the service information are stored in the memory.
  • the service information corresponds to The data can be updated by the service process, that is to say, the data corresponding to the service information can change dynamically and in real time.
  • the service process detects that the data corresponding to the service information has changed, the data corresponding to the service information can be updated.
  • the information stored in the memory can be updated in real time by the service process, so that when the user calls the corresponding service, the accurate result corresponding to the service can be obtained.
  • the processor can actively delete the service information and the data corresponding to the service information, thereby saving storage space in the memory. , in order to store other service information and data corresponding to the service information.
  • the processor can also add the service information of the service and the data corresponding to the service information into the memory, so that when the customer When the process calls these services again, the data corresponding to these services can be directly obtained from the memory, thereby reducing unnecessary service calls, improving the operating speed and system performance of the electronic device, and enhancing the user experience.
  • the service information includes a service name and interface information corresponding to the service.
  • the processor can accurately identify the service request made by the customer based on the service name and the interface information corresponding to the service in the service information, so that it can determine whether the service is located in the memory and avoid directly requesting the service.
  • the process sends a request message.
  • the memory is a cache memory.
  • an inter-process communication device in a second aspect, includes a storage unit, a processing unit and a transceiver unit.
  • the storage unit is used to store service information and data corresponding to the service information; the processing unit is used to obtain the client process's request.
  • the service process initiates a request message for a communication request, determines that the service information is stored in the storage unit according to the service information in the request message, and obtains the data corresponding to the service information from the storage unit; the transceiver unit is used to send the data corresponding to the service information. Give the client the process.
  • the transceiver unit is also used to send the request message to the service process, and receive data corresponding to the service information sent by the service process; the processing unit is also used to, The service information and data corresponding to the service information are stored in the storage unit.
  • the processing unit is also used to: record the first time point when the client process initiates a communication request to the service process; and when the service process responds to the communication request initiated by the client process when, record the second time point; determine the service waiting time according to the first time point and the second time point; when the service waiting time is greater than the threshold, save the service information in the communication request and the data corresponding to the service information in the storage unit .
  • the processing unit is also used to: when the client process initiates a communication request to the service process, record the number of communication requests; when the number of communication requests is greater than the threshold, The service information and data corresponding to the service information are stored in the storage unit.
  • the processing unit is also configured to: when the service waiting time is greater than the threshold and the number of communication requests is greater than the threshold, save the service information and the data corresponding to the service information in in the storage unit.
  • data corresponding to the service information is updated by the service process.
  • the service information includes a service name and interface information corresponding to the service.
  • the storage unit is a cache storage unit.
  • a device in a third aspect, includes a processor, and the processor is configured to execute the technical solutions of the above-mentioned first aspect and any possible design of the first aspect.
  • an electronic device in a fourth aspect, includes: one or more processors; one or more memories, the one or more memories store service information and data corresponding to the service information; the one or more memories
  • the plurality of memories stores one or more computer programs.
  • the one or more computer programs include instructions. When the instructions are executed by the one or more processors, the electronic device performs the above-mentioned first aspect and the first aspect thereof. any possible technical solution.
  • the electronic device can control the one or more processors to execute the technical solutions of the above-mentioned first aspect and any possible design of the first aspect.
  • a chip is provided, which is coupled to a memory in an electronic device and used to call a computer program stored in the memory and execute the first aspect of the embodiment of the present application and any possible technical solution of the first aspect.
  • "Coupling" in the embodiment of this application means that two components are directly or indirectly combined with each other.
  • a computer-readable storage medium includes a computer program.
  • the computer program When the computer program is run on an electronic device, the electronic device causes the electronic device to perform the above-mentioned first aspect and any of the first aspect thereof. A possible technical solution to the design.
  • a computer program product is provided.
  • the computer program product When the computer program product is run on an electronic device, it causes the computer to execute the technical solutions of the above-mentioned first aspect and any possible design of the first aspect.
  • FIG. 1 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • Figure 2 is a schematic block diagram of a storage hierarchy provided by an embodiment of the present application.
  • FIG. 3 is a schematic diagram of the software structure of an electronic device provided by an embodiment of the present application.
  • Figure 4 is a schematic diagram of the principle of binder communication mechanism.
  • Figure 5 is a schematic flow chart of the binder communication mechanism.
  • Figure 6 is a schematic flow chart of an inter-process communication method provided by an embodiment of the present application.
  • Figure 7 is a schematic flow chart of another inter-process communication method provided by an embodiment of the present application.
  • Figure 8 is a schematic flow chart of a time-consuming detection method for inter-process communication provided by an embodiment of the present application.
  • Figure 9 is a schematic flow chart of another inter-process communication method provided by an embodiment of the present application.
  • Figure 10 is a schematic block diagram of an inter-process communication device provided by an embodiment of the present application.
  • Figure 11 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the electronic device may be a portable electronic device that also includes other functions such as a personal digital assistant and/or a music player function, such as a mobile phone, a tablet computer, a wearable electronic device with wireless communication functions (such as a smart watch) wait.
  • portable electronic devices include, but are not limited to, carrying Portable electronic devices with Harmony OS or other operating systems.
  • the above-mentioned portable electronic device may also be other portable electronic devices, such as a laptop computer (Laptop). It should also be understood that in other embodiments, the above-mentioned electronic device may not be a portable electronic device, but a desktop computer, a smart TV, a smart speaker, etc.
  • FIG. 1 shows a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • FIG. 1 shows a schematic structural diagram of an electronic device 100 .
  • the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2 , mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone interface 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and Subscriber identification module (SIM) card interface 195, etc.
  • SIM Subscriber identification module
  • the sensor module 180 may include a pressure sensor 180A, a gyro sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, and an environment.
  • the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100 .
  • the electronic device 100 may include more or fewer components than shown, or some components may be combined. parts, or splitting some parts, or different parts arrangements.
  • the components illustrated may be implemented in hardware, software, or a combination of software and hardware.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (application processor, AP), a modem processor, a 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 processing unit, NPU) etc.
  • different processing units can be independent devices or integrated in one or more processors.
  • the controller may be the nerve center and command center of the electronic device 100 .
  • the controller can generate operation control signals based on the instruction operation code and timing signals to complete the control of fetching and executing instructions.
  • the processor 110 may also be provided with a memory for storing instructions and data.
  • the memory in processor 110 is cache memory. This memory may hold instructions or data that have been recently used or recycled by processor 110 . If the processor 110 needs to use the instructions or data again, it can be called directly from the memory. Repeated access is avoided and the waiting time of the processor 110 is reduced, thus improving the efficiency of the system.
  • processor 110 may include one or more interfaces. Interfaces may include inter-integrated circuit (I2C) interface, inter-integrated circuit sound (I2S) interface, pulse code modulation (PCM) interface, universal asynchronous receiver and transmitter (universal asynchronous receiver/transmitter (UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, SIM card interface, and/or USB interface, etc.
  • I2C inter-integrated circuit
  • I2S inter-integrated circuit sound
  • PCM pulse code modulation
  • UART universal asynchronous receiver and transmitter
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM card interface SIM card interface
  • USB interface 130 is an interface that complies with USB standard specifications, and may specifically be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc.
  • the USB interface 130 can be used to connect a charger to charge the electronic device 101, and can also be used to transmit data between the electronic device 101 and peripheral devices.
  • the external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100.
  • the external memory card communicates with the processor 110 through the external memory interface 120 to implement the data storage function. Such as saving music, videos, etc. files in external memory card.
  • Internal memory 121 may be used to store one or more computer programs including instructions.
  • the processor 110 may execute the above instructions stored in the internal memory 121 .
  • the internal memory 121 may include a program storage area and a data storage area. Among them, the stored program area can store the operating system; the stored program area can also store one or more applications (such as photo galleries, contacts, etc.). The storage data area can store data created during use of the electronic device 101 (such as photos, contacts, etc.).
  • the internal memory 121 may include high-speed random access memory, and may also include non-volatile memory, such as one or more disk storage components, flash memory components, universal flash storage (UFS), embedded multimedia card ( Embedded Multi Media Card, eMMC), etc.
  • the processor 110 can cause the electronic device 101 to execute the instructions provided in the embodiments of the present application by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor 110 . methods, and other applications and data processing.
  • the electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor. For example, music playback, recording, etc.
  • Figure 2 shows a schematic block diagram of a storage hierarchy provided by an embodiment of the present application. As shown in Figure 2, the storage hierarchy is divided into four levels, from top to bottom: register memory, cache memory, Main memory, auxiliary memory.
  • the storage hierarchy is the order in which the storage system hierarchy is arranged.
  • Each layer has higher read and write speeds, lower latency, and smaller capacity than the next layer.
  • Registers are storage areas used by processors to store data and are used to temporarily store data and operation results involved in operations. Registers can be set inside the processor. Registers can often be located inside the processor.
  • Cache memory is a memory that exists between main memory and registers.
  • the capacity of cache memory is smaller, but its read and write speed is faster than that of main memory.
  • the cache memory can store part of the data in the main memory. Therefore, when the processor reads data, it will first access the cache memory. If the required data is not included in the cache memory, it will then access the main memory. Since the read and write speed of the cache memory is faster than Main memory, if the cache memory contains data needed by the processor, it can increase the speed of the electronic device.
  • Main memory is also called main memory, memory, and internal memory (i.e., 121 in Figure 1), and its function is to store instructions and data.
  • main memory When the processor needs to read data, it can first read it in the cache memory. When the data is not in the cache memory, the processor can search for the data in the main memory. When the processor finds the data in the main memory, The found data can be cached in the cache memory so that the next time the data can be read directly in the cache memory.
  • Main memory is slower than cache memory and faster than secondary memory.
  • Auxiliary memory also known as external memory (120 in Figure 1), refers to memory in electronic devices other than main memory, cache memory, and registers, such as hard disk and optical disk memory.
  • a cache may also be provided between the main memory and the auxiliary memory.
  • the cache memory may be divided into multiple levels, such as L1cache, L2cache, and L3cache.
  • FIG. 3 shows a software structure block diagram of the electronic device 100 according to the embodiment of the present application.
  • the layered architecture divides the software into several layers, and each layer has clear roles and division of labor.
  • the layers communicate through software interfaces.
  • the Android system is divided into four layers, from top to bottom: application layer, application framework layer, Android runtime and system libraries, and kernel layer.
  • the application layer can include a series of application packages.
  • the application layer can include applications such as gallery, calendar, map, navigation, call, camera, settings, video, music, and text messages.
  • the application framework layer provides an application programming interface (API) and programming framework for applications in the application layer.
  • the application framework layer can include some predefined functions.
  • the application framework layer can include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.
  • a window manager is used to manage window programs.
  • the window manager can obtain the display size, determine whether there is a status bar, lock the screen, capture the screen, etc.
  • Content providers are used to store and retrieve data and make this data accessible to applications.
  • Said data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
  • Content providers are used to store and retrieve data and make this data accessible to applications.
  • Said data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
  • the view system includes visual controls, such as controls that display text, controls that display pictures, etc.
  • a view system can be used to build applications.
  • the display interface can be composed of one or more views.
  • a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures.
  • the phone manager is used to provide communication functions of the electronic device 100 . For example, call status management (including connected, hung up, etc.).
  • the resource manager provides various resources to applications, such as localized strings, icons, pictures, layout files, video files, etc.
  • the notification manager enables applications to be in state Notification information is displayed in the bar, which can be used to convey notification-type messages. It can stay for a short time and then automatically disappear without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc.
  • the notification manager can also be notifications that appear in the status bar at the top of the system in the form of graphics or scroll bar text, for example, notifications for applications running in the background, or notifications that appear on the screen in the form of conversation windows. For another example, text information is prompted in the status bar, a prompt sound is emitted, the electronic device vibrates, the indicator light flashes, etc.
  • Android runtime includes core libraries and virtual machines. Android runtime is responsible for the scheduling and management of the Android system.
  • the core library contains two parts: one is the functional functions that need to be called by the Java language, and the other is the core library of Android.
  • the application layer and application framework layer run in virtual machines.
  • the virtual machine executes the java files of the application layer and application framework layer into binary files.
  • the virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection and other functions.
  • System libraries can include multiple functional modules. For example: surface manager (surface manager), media libraries (media libraries), 3D graphics processing libraries (for example: OpenGL ES), 2D graphics engines (for example: SGL), etc.
  • the surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications.
  • the media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc.
  • the media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
  • the 3D graphics processing library is used to implement 3D graphics drawing, image rendering, composition, and layer processing.
  • 2D Graphics Engine is a drawing engine for 2D drawing.
  • system library can also include status monitoring service modules, etc., such as the physical status recognition module, which is used to analyze and recognize user gestures; the sensor service module, which is used to monitor the sensor data uploaded by various sensors in the hardware layer, and determine the electronic The physical state of the device 100.
  • status monitoring service modules such as the physical status recognition module, which is used to analyze and recognize user gestures; the sensor service module, which is used to monitor the sensor data uploaded by various sensors in the hardware layer, and determine the electronic The physical state of the device 100.
  • the kernel layer is the layer between hardware and software.
  • the kernel layer can include display drivers, camera drivers, audio drivers, sensor drivers, binder drivers, etc.
  • Figure 4 shows the schematic diagram of the binder communication mechanism.
  • Binder is one of the very important features of the operating system. Its communication mechanism model is based on client/server (C/ S) communication mode implementation. Binder communication adopts C/S mode. From a component perspective, binder communication includes client, server, service manager and binder driver.
  • an Android process For each Android process, it can only run in the virtual address space owned by its own process.
  • an Android process corresponds to a 4GB virtual address space, of which 3GB is user space and 1GB is kernel space.
  • the size of the kernel space can be adjusted through parameter configuration.
  • the client process that is, the process that uses the service/client process
  • the server process that is, the process that provides the service/service process.
  • the kernel memory space that can be shared between processes can be used to complete the underlying communication work.
  • the client process and the server Process communication can use a function ioctl in a device driver to manage the I/O channel of the device to interact with the binder driver in the kernel space.
  • the communication process based on the binder mechanism can be summarized into the following three processes: registering services, obtaining services, and using services.
  • Register service The server process must first register the service with the service manager.
  • Obtaining services Before the client process uses a service, it must first obtain the corresponding service from the service manager.
  • Using services The client process establishes a communication channel with the server process where the service is located based on the obtained service information, and then can directly interact with the service. It can be understood that the interactions between the client process, server process and service manager in Figure 4 are all The dotted lines indicate that they do not interact directly with each other, but interact with the binder driver to achieve IPC communication.
  • the client process can also be called the client, and the server process can also be called the server.
  • the binder driver is located in the kernel space (that is, in the kernel layer), and the client process, server process and service manager are located in the user space.
  • the binder driver and service manager can be regarded as the infrastructure of the operating system, while the client process and server process are the application layer of the operating system. Users only need to customize the client process and server process, and can directly implement it with the help of the basic platform architecture of the operating system. IPC communication.
  • Figure 5 shows a schematic flow chart of the binder communication mechanism.
  • the client process and the server process interact through the binder driver.
  • the following takes the service of requesting to obtain the phone number of "Zhang San” as an example to describe in detail the specific process of the client process requesting the service.
  • the process may specifically include S501 to S505.
  • the server process registers the service with the service management.
  • the server process is a process that provides services in C/S mode, that is, a service process.
  • the server process registers the service with the service management through the binder driver.
  • the service management includes many services.
  • the service management includes the service of obtaining the phone number.
  • the server process first registers the service of obtaining the telephone number with the binder driver, and then the binder driver will send the registered service of obtaining the telephone number to the service management.
  • the client process initiates a request to obtain the service to the service management.
  • the client process is a process that uses services in C/S mode, that is, a client process.
  • the client process since the client process cannot directly interact with the service management, the client process initiates a request to obtain the service through the binder driver to the service management, passing the service name and other information.
  • the request may be a service request for obtaining a telephone number, and the service name may be obtaining a telephone service.
  • the client process first sends a request to obtain the phone number service to the binder driver, and then the binder driver sends the request to the service management.
  • the service management can know that the client process needs to obtain the relevant service information of the telephone number.
  • the service management returns service information to the client process.
  • the service management After finding the service information of the corresponding server based on the service name in the request to obtain the service sent by the client process, the service management returns the corresponding server service information to the client process through the binder driver, and implements memory mapping and other operations as follows Prepare for inter-process communication IPC.
  • the service information here can be understood as obtaining the service information corresponding to the telephone service.
  • the client process sends data to the server process.
  • the client process After the client process receives the service information corresponding to the service returned by the binder driver, it can package the data that needs to be obtained, and rely on the memory mapping created by the binder driver to send the data to the service management and/or to the server process for processing. Handle accordingly. That is to say, the client process first sends the data to be obtained to the binder driver, and then the binder driver sends the data to be obtained to the service management and/or server process.
  • the data that needs to be obtained is the data corresponding to the service information, that is, the data that the user wants to obtain.
  • This data can be, for example, the phone number of "Zhang San”.
  • the server process sends the return result to the client process through the binder driver.
  • the server process after receiving the data, the server process will take out the thread from the thread pool, unpack the data and call the target method, and finally return the processing result to the client process. That is, the server process and/or service management will Obtain the corresponding result based on the data sent by the client process, and send the result to the binder driver, which then sends the result to the client process. It should be understood that the returned result here may be, for example, the phone number of "Zhang San".
  • the user's service request can be completed through S501 to S505 (for example: obtaining the service of "Zhang San"'s phone number), and what type of service the user needs to obtain can be known through S501 to S503 (for example: obtaining the phone number of service), the specific data corresponding to the service can be obtained through S504 and S505 (for example: the phone number of "Zhang San”).
  • S501 to S503 for example: obtaining the phone number of service
  • S504 and S505 for example: the phone number of "Zhang San”
  • the client process needs to send information to the service management or server process through the binder driver.
  • the service management or server process processes the received information and then returns the corresponding information through the binder driver. the result of.
  • this application provides an inter-process communication IPC method.
  • adding a cache mechanism in the binder driver to cache the results returned by the service process thereby reducing the number of service execution times of the service process and the waiting time of the client process, thereby improving the efficiency of electronic equipment. running speed and enhance user experience.
  • Figure 6 shows a schematic flow chart of an inter-process communication method provided by an embodiment of the present application.
  • the method 600 can be executed by the processor in the electronic device.
  • the method 600 includes S601 to S604.
  • the following takes the service of obtaining the phone number of "Zhang San” as an example to explain in detail the specific process of obtaining the service by the client process. process.
  • S601 The processor obtains a request message in which the client process initiates a communication request to the service process.
  • the request message may be, for example, a service acquisition request sent by the client process in S502 to the service process, and/or a data request to be acquired by the client process in S504 sent to the service process.
  • S602 The processor determines that the service information is stored in the memory according to the service information in the request message.
  • the processor can determine which services the client process needs based on the service information in the request message sent by the client process.
  • the request message sent by the client process to the server process is used to request to obtain the phone number of "Zhang San”
  • the service information is used to instruct to obtain the phone number of "Zhang San”
  • the service information includes the service name and the interface information corresponding to the service.
  • the service name can be understood as the service name corresponding to obtaining the telephone service
  • the interface information corresponding to the service can be understood as the interface information that needs to be accessed to obtain the phone number of "Zhang San”.
  • the server process confirms what information the client process needs based on the service information, and then sends the information needed by the client process to the client process.
  • the memory is located in the kernel space (ie, the kernel layer), and the memory may be a cache memory (cache), for example.
  • the memory stores service information and data corresponding to the service information.
  • the service information includes a service name and interface information corresponding to the service.
  • the processor determines that the service information has been stored in the memory based on the service information in the request message, the processor can directly obtain the data corresponding to the service information from the memory and return the data to the client process.
  • the client process can first obtain the data corresponding to the telephone service from the memory. , and then the phone number of "Zhang San” can also be obtained from the memory. That is to say, the service information may include obtaining the service information of the phone and the interface information corresponding to the obtaining telephone number service.
  • the data corresponding to the service information may include obtaining the relevant data corresponding to the telephone number; or, the service information may include obtaining the "Zhang Zhang” service information.
  • the data corresponding to the service information may include the data of "Zhang San" telephone number.
  • the method can also execute the method shown in Figure 7.
  • services that meet the corresponding conditions can be saved in the memory, so that when the client process calls the service again, it can be directly retrieved from Obtain service information and data corresponding to the service information from the memory.
  • S603 The processor obtains data corresponding to the service information from the memory.
  • the processor determines that the service information is stored in the memory (for example, cache) based on the service information in the request message sent by the client process. Therefore, there is no need to send a request message to the server process and can directly obtain the service information from the memory (for example, cache). The data corresponding to this service information can reduce a large number of unnecessary service calls and shorten the waiting time of the client process IPC.
  • the processor can directly obtain the phone number of "Zhang San” from the cache without having to obtain the phone number of "Zhang San”.
  • the service information corresponding to the phone number is sent to the server process, and then the phone number of "Zhang San” is obtained, thereby reducing unnecessary calls to the server process.
  • the data corresponding to the service information can be updated by the service process. That is to say, the data corresponding to the service information can change dynamically and in real time.
  • the server process detects that the data corresponding to the service information has changed, the data corresponding to the service information can be updated, so that when the user calls the service, the data corresponding to the service information can be updated. Get the exact results corresponding to this service.
  • the processor can actively delete the service information and the data corresponding to the service information, thereby saving storage space in the memory. , in order to store other service information and data corresponding to the service information.
  • the processor can also store the service information of the service and the corresponding service information.
  • the data is added to the memory so that when the client process calls these services again, the data corresponding to these services can be obtained directly from the memory, thereby reducing unnecessary service calls, improving the operating speed and system performance of electronic devices, and enhancing user experience.
  • the processor sends data corresponding to the service information to the client process.
  • the processor can obtain the data corresponding to the service information from the memory (for example, cache) according to the service information, and send the data to the client process, so that the processor can use the data corresponding to the service information to perform the next step. processing.
  • the data corresponding to the service information may be the phone number of "Zhang San", etc.
  • the processor can determine that the service information is stored in the memory according to the service information in the request message, so that the data corresponding to the service information can be directly obtained from the memory, and the data can be sent Give the client the process. Since the memory is located in the kernel space, the client process can obtain the data corresponding to the service information from the memory located in the kernel space without accessing the service process located in the user space. This can reduce unnecessary service calls and avoid IPC operations. It can effectively reduce system resource usage, improve the operating speed and system performance of electronic devices, and enhance user experience.
  • Figure 7 shows a schematic flow chart of another inter-process communication method provided by an embodiment of the present application. As shown in Figure 7, the method 700 can be executed by the processor in the electronic device. The method 700 includes S701 to S704, which details the specific process of the client process obtaining the service.
  • method 700 can be executed before method 600, that is, the processor can obtain the service that needs to be saved in the memory by executing S701 to S704, and then when the client process calls the service, it can directly obtain the required service from the memory. data, eliminating the need to send request messages to the service process to obtain the required data.
  • S701 The processor obtains a request message from the client process to initiate a communication request to the service process.
  • S702 The processor sends the request message to the service process.
  • the processor can send the request message to the service process through the binder driver according to the method flow described in Figure 5, so as to obtain data in the service process corresponding to the service information in the request message.
  • S703 The processor receives the data corresponding to the service information sent by the service process, and saves the service information and the data corresponding to the service information in the memory.
  • the server process will take out the thread from the thread pool, unpack the data and call the target method, and determine the service information corresponding to the request message. data.
  • the processor receives the data corresponding to the service information sent by the server process, and saves the service information and the data corresponding to the service information in a memory (for example, cache).
  • the service information corresponding to the phone number of "Zhang San” and the related data corresponding to the phone number of "Zhang San” can be obtained ( For example: “Zhang San's” phone number) is stored in the cache, so that the next time you get “Zhang San's” phone number, you can directly get the data related to "Zhang San's” phone number from the cache without having to store it in the cache.
  • the service information and the data corresponding to the service information can be cached in the cache in the form of key-value pairs, and when specifically stored, the service information can be used as the key value, and the data corresponding to the service information can be used as the value value. Therefore, when querying the data stored in the cache, the data corresponding to the service information can be obtained from the cache according to the service information in the request message.
  • the IPC operation duration and/or the difficulty of calling the service and/or the number of service requests, etc. may be considered.
  • the processor when the client process initiates a communication request to the server process, the processor records the first time point; when the server process responds to the communication request initiated by the client process, the processor records the second time point; the processor records the second time point according to the first time point.
  • the time point and the second time point determine the service waiting time; when the preset conditions are met, the processor saves the service information in the communication request and the data corresponding to the service information in the memory.
  • the preset condition may be that the service waiting time is greater than a threshold, and the threshold may be an empirical value, such as 6 ms, 10 ms, etc., which is not limited in this application.
  • the processor when the client process initiates a communication request to the server process, the processor records the number of communication requests; when the number of communication requests is greater than the threshold, the processor can combine the service information in the communication request and the corresponding service information. Data is saved in memory.
  • the processor can also detect the service waiting time and the number of service requests at the same time.
  • the processor can also detect the communication request.
  • the service information in and the data corresponding to the service information are stored in the memory.
  • the processor sends data corresponding to the service information to the client process.
  • the processor can send the data to the client process, so that the processor can use the data corresponding to the service information to perform subsequent processing.
  • the data corresponding to the service information may be the phone number of "Zhang San", etc.
  • the processor can send the request message to the service process, obtain the data corresponding to the service information returned by the service process, and save the service information and the data corresponding to the service information in the memory. , that is, the results returned by the service process are cached, so that the next time the client process calls the service, the processor can directly obtain the data corresponding to the service information from the memory and send the data to the client process, and then It can reduce unnecessary service calls, avoid system freezes and other problems caused by IPC operations, effectively reduce the occupation of system resources, improve the operating speed and system performance of electronic devices, and enhance user experience.
  • Figure 8 shows a schematic flow chart of a time-consuming detection method for inter-process communication provided by an embodiment of the present application. As shown in Figure 8, the method 800 specifically includes S801 to S808. These steps will be introduced in detail below.
  • request messages/programs correspond to different IPC application program interfaces.
  • a request to open the address book and a request to open the camera application require access to different communication interfaces.
  • a custom hook function is written with the help of hook technology.
  • a native program app_process ie, the main entry point of the application process
  • the operating system for example, Android system
  • hook technology is a technology used to change the API execution results and can redirect the execution of the system's API functions.
  • the hook function can record the start time and end time of IPC, so that the IPC time consumption can be determined.
  • the hook function is used to record the start time and end time at the start position and the end position respectively, and determine the duration of each IPC operation (ie, the operation duration of each service).
  • the start time may correspond to the time when the client process initiates a communication request to the service process in S502
  • the end time may correspond to the time when the service process responds to the communication request initiated by the client process in S503 or S505.
  • the time detection can be the time between S502 and S503, that is, the time corresponding to the time from obtaining the service to the return of service information; it can also be the time from S502 to S505, that is, the time corresponding to the time from obtaining the service to the return of the specific data corresponding to the service. time.
  • the waiting time of the current IPC operation is obtained by the difference between the end time and the start time, and the maximum waiting time is set as the threshold.
  • the threshold for example, 5ms, 10ms
  • a waiting timeout is considered to have occurred.
  • log information such as waiting time and stack is printed for further troubleshooting and optimization.
  • this query-type IPC operation can be understood as an operation that frequently uses interfaces, and the number of accesses to these interfaces is much greater than the number of modifications.
  • this type of IPC operation its service information and data corresponding to the service information can be added to the cache.
  • the cache can include two types of values.
  • One type represents the target method identifier of the IPC operation, that is, the service information.
  • the service information can be used to identify the service name and interface information called by the IPC operation; the other type corresponds to
  • the result of the service information is the data corresponding to the service information.
  • the data is the result returned by the server process.
  • the difficulty of calling the service can also be considered, and/or the number of service requests can also be considered.
  • the processor may determine whether to save the service in the memory based on the difficulty of calling the service. For example, the service of obtaining the phone number of "Zhang San” is relatively simple, while dialing the phone number of "Zhang San” The services involved are relatively complex. In this case, the service corresponding to obtaining the phone number of "Zhang San” can be saved in the memory.
  • the processor when the client process initiates a communication request to the service process, the processor records the number of communication requests within a certain time range; when the number of communication requests is greater than a threshold, the threshold can be an empirical value, for example, and the processor will The service information and data corresponding to the service information are stored in the memory.
  • the processor can detect the service waiting time and the number of service requests at the same time.
  • the processor can combine the service information and the number of service requests.
  • the data corresponding to the service information is stored in the memory.
  • the threshold for service waiting time and the threshold for the number of service requests By setting the threshold for service waiting time and the threshold for the number of service requests, services that cause the client process to wait too long and initiate communication requests multiple times are detected, and the service information corresponding to these services and the data corresponding to the service information can be stored in the memory. , which can further improve the operating speed and system performance of electronic devices and enhance user experience.
  • the processor can also comprehensively consider the duration of the IPC operation, the difficulty of calling the service, and the number of service requests. By comprehensively considering these factors, the processor can further find the target interfaces that need to be cached, so that these interfaces can be The information and the service information calling the interface are stored in the cache, which can further improve the operating speed and system performance of the electronic device and enhance the user experience.
  • the IPC time-consuming detection method provided by the embodiment of the present application, by writing a hook function to replace app_process during the system startup process, the hook operation of the IPC interface of all application processes can be realized without the upper-layer application program being aware of it, and thus You can obtain the execution time of each IPC operation and find the service of the server process that causes the client process IPC operation to wait for timeout, which facilitates subsequent location analysis.
  • the IPC time-consuming detection method provided by the embodiment of this application is not restricted by the Android version, is not restricted by root permissions, has no impact on business functions, and has no obvious impact on system performance.
  • Figure 9 shows a schematic flow chart of another inter-process communication method provided by an embodiment of the present application. As shown in Figure 9, the method 600 can be executed by a processor in the electronic device, and the method 900 specifically includes S901 to S907.
  • the binder driver receives the request message.
  • the binder driver When the binder driver receives the request message, the binder driver can first determine the service information in the request message. (That is, the above-mentioned service name and the interface information corresponding to the service) are stored in the cache.
  • the request message may be, for example, a request to obtain the phone number of "Zhang San".
  • S904 Determine whether there is corresponding record item information in the cache.
  • the processor When the client process sends a request message to the server process, the processor first determines whether the service information in the request message is in the cache, that is, whether there is corresponding record information in the cache. If the service information is in the cache, that is, there is corresponding record item information in the cache, the processor can execute S905; if the service information is not in the cache, that is, there is no corresponding record item information in the cache, the processor can execute S906 and S907.
  • the service information includes service name and interface information corresponding to the service.
  • the service name may be a telephone service
  • the interface information corresponding to the service may be understood as the interface information corresponding to the service for obtaining the phone number of "Zhang San”.
  • the record item information can be understood as the above-mentioned service information and data corresponding to the service information.
  • the service information can be understood as the service information of the server process provided by the client process during the service request process, that is, what kind of system service is obtained (for example, obtaining telephone service) and the specific data under the system service that needs to be obtained (for example, "Zhang three" phone number).
  • the server process determines that the information stored in the cache (that is, the data corresponding to the service information) has changed, the server process can update it through the interface provided by the binder driver and store the updated information in the cache. , so that it can be called next time.
  • an application in a mobile phone may often obtain the user's location information, but the user's location may not change for several hours or even a day.
  • the processor can also save it. in cache.
  • the server process discovers that the user's location has changed, it can update the specific content of the location through the location-related interface provided by the binder driver, so that the information saved in the cache is accurate and convenient for the user to call next time.
  • the processor determines whether the service information is in the cache according to the service information in the request message sent by the client process. If the service information is not in the cache, the processor sends the request message to the server process, and the server process determines whether the service information is in the cache according to the service information.
  • the information determines the data corresponding to the service information.
  • the data corresponding to the service information is, for example, the phone number of "Zhang San".
  • the processor determines whether the service information is in the cache according to the service information in the request message sent by the client process. If the service information is not in the cache, the processor sends the request message to the server process, and the server process determines whether the service information is in the cache according to the service information. The information determines the data corresponding to the service information. Please refer to Figure 5 for the specific content, which will not be described again here.
  • the processor needs to send the service information corresponding to the phone number of "Zhang San” to the server process, and then obtain the service information corresponding to the phone number of "Zhang San”.
  • Data related to Zhang San’s phone number For example, if the service information corresponding to the phone number of "Zhang San” is not in the cache, the processor needs to send the service information corresponding to the phone number of "Zhang San” to the server process, and then obtain the service information corresponding to the phone number of "Zhang San”. Data related to Zhang San’s phone number.
  • the processor can send the data to the client process, so that the processor can use the data corresponding to the service information to perform subsequent processing.
  • the data corresponding to the service information may be the phone number of "Zhang San", etc.
  • the corresponding service of the server process can be called first for processing.
  • the ⁇ service information, the data corresponding to the service information> can be used as the ⁇ key , value> pair, that is, the service information and the data corresponding to the service information are inserted into the cache in the form of key-value pairs.
  • the duration of the IPC operation and/or the difficulty of calling the service and/or the number of service requests may be considered.
  • the processor when the client process initiates a communication request to the server process, the processor records the first time point; when the server process responds to the communication request initiated by the client process, the processor records the second time point; the processor records the second time point according to the first time point.
  • the time point and the second time point determine the service waiting time; when the service waiting time is greater than the threshold, the processor saves the service information in the communication request and the data corresponding to the service information in the cache.
  • the processor when the client process initiates a communication request to the server process, the processor records the number of communication requests; when the number of communication requests is greater than the threshold, the processor saves the service information and the data corresponding to the service information in the cache. middle.
  • the processor can also detect the service waiting time and the number of service requests at the same time.
  • the processor can combine the service information with The data corresponding to the service information is stored in the cache.
  • the number of times the client process calls the service should be much greater than the number of times the server process modifies the service.
  • the specific content can be referred to Figure 8 and will not be repeated here.
  • the processor by judging whether the service information in the request message of the client process is in the cache, if the service information is in the cache, the processor can directly obtain the data corresponding to the service information in the cache, And send the data to the client process; if the service information is not in the cache, the processor can send the request message to the server process, obtain the data corresponding to the service information returned by the server process, and store the service information and the data corresponding to the service information. Save it in the cache, that is, cache the results returned by the server process, so that the next time the client process calls the service information, the processor can directly obtain the data corresponding to the service information from the cache and send the data to client process.
  • the methods provided by the embodiments of this application can reduce unnecessary service calls, avoid system freezes and other problems caused by IPC operations, effectively reduce the occupation of system resources, improve the operating speed and system performance of electronic devices, and enhance user experience.
  • the electronic device includes corresponding hardware structures and/or software modules that perform each function.
  • the algorithm steps of each example described in conjunction with the embodiments disclosed herein the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is performed by hardware or computer software driving the hardware depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each specific application, but such implementations should not be considered beyond the scope of this application.
  • Embodiments of the present application can divide the processor in the electronic device into functional modules according to the above method examples.
  • each functional module can be divided into corresponding functional modules, or two or more functions can be integrated into one processing module.
  • the above integrated modules can be implemented in the form of hardware or 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. In actual implementation, there may be other division methods.
  • FIG. 10 shows a schematic block diagram of the inter-process communication device provided by the embodiment of the present application.
  • the IPC device 1000 may include: a storage unit 1010, processing unit 1020 and transceiver unit 1030.
  • the storage unit 1010 is used to store service information and data corresponding to the service information.
  • the processing unit 1020 is configured to obtain a request message in which the client process initiates a communication request to the service process, determine that the service information is stored in the storage unit according to the service information in the request message, and obtain data corresponding to the service information from the storage unit.
  • the sending and receiving unit 1030 is used to send data corresponding to the service information to the client process.
  • the transceiver unit 1030 is also used to send the request message to the service process, and receive the data corresponding to the service information sent by the service process; the processing unit 1020 is also used to save the service information and the data corresponding to the service information. in the storage unit.
  • the processing unit 1020 is also configured to: record the first time point when the client process initiates a communication request to the service process; record the second time point when the service process responds to the communication request initiated by the client process; according to the first The time point and the second time point determine the service waiting time; when the service waiting time is greater than the threshold, the service information in the communication request and the data corresponding to the service information are saved in the storage unit 1010.
  • the processing unit 1020 is also configured to: when the client process initiates a communication request to the service process, record the number of communication requests; when the number of communication requests is greater than the threshold, save the service information and the data corresponding to the service information in the storage in the unit.
  • the processing unit 1020 is also configured to: when the service waiting time is greater than the threshold and the number of communication requests is greater than the threshold, save the service information and data corresponding to the service information in the storage unit.
  • the data corresponding to the service information is updated by the service process.
  • the service information includes a service name and interface information corresponding to the service.
  • the storage unit 1010 is a cache storage unit.
  • inter-process communication device provided by the embodiment of the present application is used to execute the above-mentioned inter-process communication method, and therefore can achieve the same effect as the above-mentioned processing method.
  • Figure 11 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the electronic device 1100 includes: one or more processors 1110; one or more memories 1120; the one or more memories 1120 store service information and data corresponding to the service information; the one or more memories 1120; The plurality of memories 1120 also stores one or more computer programs including instructions.
  • the instruction is executed by the one or more processors 1110, the electronic device 1100 is caused to execute each step of the inter-process communication method in the above embodiments.
  • the one or more processors 1110 may be the processor 110 shown in FIG. 1
  • the one or more memories 1120 may be the internal memory 120 shown in FIG. 1 and/or connected to an electronic device. external memory.
  • An embodiment of the present application provides a device.
  • the device includes a processor, and the processor is configured to execute the inter-process communication method in each of the above method embodiments.
  • An embodiment of the present application also provides a chip.
  • the chip includes a processor and a communication interface.
  • the communication interface is used to receive signals and transmit the signals to the processor.
  • the processor processes the signals so that in the above method embodiments Inter-process communication methods are executed.
  • Embodiments of the present application also provide a computer-readable storage medium.
  • Computer instructions are stored in the computer-readable storage medium.
  • the electronic device causes the electronic device to execute the inter-process steps in the above method embodiments. Communication methods.
  • Embodiments of the present application also provide a computer program product.
  • the computer program product When the computer program product is run on a computer, it causes the computer to execute the inter-process communication method in each of the above method embodiments.
  • the embodiment of the present application also provides a device.
  • This device may be a chip, a component or a module.
  • the device may include a connected processor and a memory.
  • the memory is used to store computer execution instructions.
  • the processing The processor can execute computer execution instructions stored in the memory, so that the chip executes the inter-process communication method in each of the above method embodiments.
  • the disclosed systems, devices and methods can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components may be combined or can be integrated into another system, or some features can be ignored, or not implemented.
  • the coupling or direct coupling or communication connection between each other shown or discussed may be through some interfaces, and the indirect coupling or communication connection of the devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or they may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application can be integrated into one processing unit, each unit can exist physically alone, or two or more units can be integrated into one unit.
  • the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium.
  • the technical solution of the present application is essentially or the part that contributes to the existing technology or the part of the technical solution can be embodied in the form of a software product.
  • the computer software product is stored in a storage medium, including Several instructions are used to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of this application.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本申请实施例提供了一种进程间通信方法和电子设备,该方法包括:处理器获取客户进程向服务进程发起通信请求的请求消息,并根据该请求消息中的服务信息确定该服务信息是否保存在存储器中,该存储器位于内核空间;若存储器中保存有该服务信息,则从存储器中获取与服务信息对应的数据,并将该服务信息对应的数据发送给客户进程。通过本申请实施例提供的方法或电子设备,客户进程无需访问位于用户空间中的服务进程,即可从位于内核空间的存储器中获取服务信息对应的数据,能够减少不必要的服务进程的调用,从而可以提高电子设备的运行速度和系统性能,增强用户体验。

Description

进程间通信方法和电子设备
本申请要求于2022年04月14日提交中国专利局、申请号为202210390253.9、申请名称为“进程间通信方法和电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及计算机应用领域,并且更具体地,涉及一种进程间通信方法和电子设备。
背景技术
在操作系统(例如:安卓系统、鸿蒙系统)中,客户进程与服务进程进行通信,一般可以采用进程间通信(inter-process communication,IPC)的方式,例如,客户进程可以通过binder机制进行信息传输,获取服务进程中的数据。
在利用binder机制进行通信过程中,当服务进程接收到信息并进行处理时,客户进程的请求会被挂起,直到服务进程返回处理结果为止。因此,当服务进程处理时间较长时,可能会出现卡顿、响应慢,甚至出现应用无响应(application not responding,ANR)等问题,从而影响了电子设备的系统性能,进而降低了用户体验。目前尚无系统优化方案解决这种问题。
发明内容
本申请实施例提供一种进程间通信方法和电子设备,减少不必要的服务进程的调用,从而可以提高电子设备的运行速度和系统性能,增强用户体验。
第一方面,提供了一种进程间通信方法,该方法包括:处理器获取客户进程向服务进程发起通信请求的请求消息;根据该请求消息中的服务信息确定服务信息保存在存储器中,且该存储器位于内核空间;处理器从存储器中获取与服务信息对应的数据;并将该服务信息对应的数据发送给客户进程。
在本申请实施例中,处理器可以根据请求消息中的服务信息,确定该服务信息保存在存储器中,从而可以直接从存储器中获取与该服务信息对应的数据,并将该数据发送给客户进程。由于该存储器位于内核空间中,因此客户进程无需访问位于用户空间中的服务进程,即可从位于内核空间的存储器中获取服务信息对应的数据,从而可以减少不必要的服务调用,避免IPC操作引起的系统卡顿等问题,能够有效降低系统资源的占用,提高电子设备的运行速度和系统性能,增强用户体验。
结合第一方面,在第一方面的某些实现方式中,在根据请求消息中的服务信息确定服务信息保存在存储器中之前,该方法还包括:处理器将请求消息发送给服务进程;接收服务进程发送的与该服务信息对应的数据,并将服务信息以及该服务信息对应的数据保存在存储器中。
在本申请实施例中,处理器可以将请求消息发送给服务进程,并获取服务进程返回的与该服务信息对应的数据,并将该服务信息以及该服务信息对应的数据保存在存储器中,即对服务进程返回的结果进行缓存,从而使得客户进程下次再调用该服务时,处理器可以直接从存储器中获取与该服务信息对应的数据,并将该数据发送给客户进程,进而可以减少不必要的服务调用,避免IPC操作引起的系统卡顿等问题,有效降低系统资源的占用,提高电子设备的运行速度和系统性能,增强用户体验。
结合第一方面,在第一方面的某些实现方式中,将服务信息以及该服务信息对应的数据保存在存储器中,包括:在客户进程向服务进程发起通信请求时,处理器记录第一时间点;在服务进程响应客户进程发起的通信请求时,处理器记录第二时间点;处理器根据第一时间点和第二时间点确定服务等待时间;当该服务等待时间大于阈值时,处理器将通信请求中的服务信息和服务信息对应的数据保存在存储器中。
在本申请实施例中,处理器可以检测IPC操作的耗时,通过设置服务等待时间的阈值,检测出导致客户进程等待时间过长的服务,并将该服务对应的服务信息以及服务信息对应的数据存储在存储器中,从而使得当客户进程再次调用该服务时,可以直接从存储器中获取该服务对应的数据,进而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
结合第一方面,在第一方面的某些实现方式中,将服务信息以及该服务信息对应的数据保存在存储器中,包括:在客户进程向服务进程发起通信请求时,处理器记录通信请求的次数;当通信请求的次数大于阈值时,处理器将该服务信息和该服务信息对应的数据保存在存储器中。
在本申请实施例中,处理器可以检测服务请求的次数,通过设置服务请求次数的阈值,检测出频繁调用的服务,并将该服务对应的服务信息以及服务信息对应的数据存储在存储器中,从而使得当客户进程再次调用该服务时,可以直接从存储器中获取该服务对应的数据,进而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
可选地,处理器还可以同时检测服务等待时间和服务请求的次数,当服务等待时间大于阈值且客户进程向服务进程发起通信请求的次数大于阈值时,处理器可以将该服务信息和该服务信息对应的数据保存在存储器中。
通过设置服务等待时间的阈值和服务请求次数阈值,检测出导致客户进程等待时间过长的服务并且多次发起通信请求的服务,可以将这些服务对应的服务信息以及服务信息对应的数据存储在存储器中,从而使得当客户进程再次调用这些服务时,可以直接从存储器中获取该服务对应的数据,进而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
可选地,当客户进程调用服务的次数远大于服务进程修改该服务的次数时,处理器也可以将这类服务保存在存储器中,从而使得当客户进程再次调用这些服务时,可以直接从存储器中获取这些服务对应的数据,进而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
结合第一方面,在第一方面的某些实现方式中,服务信息对应的数据是由服务进程进行更新的。
应理解,存储器中保存有服务信息以及服务信息对应的数据。其中,服务信息对应的 数据可以是由服务进程进行更新的,也就是说,服务信息对应的数据可以是动态实时变化的,当服务进程检测到服务信息对应的数据发生改变时,可以对服务信息对应的数据进行更新。
在本申请实施例中,存储器中存储的信息可以由服务进程进行实时更新,从而使得当用户调用相应的服务时,可以获得准确该服务对应的结果。
可选地,若处理器检测到存储器中某个服务信息对应的服务长时间没有调用,则处理器可以将该服务信息以及该服务信息对应的数据进行主动删除,从而可以节省存储器中的存储空间,以便于存储其他服务信息以及服务信息对应的数据。
可选地,若处理器检测到某个服务耗时较长和/或访问频率过高时,处理器也可以将该服务的服务信息以及服务信息对应的数据加入到存储器中,以便于当客户进程再次调用这些服务时,可以直接从存储器中获取这些服务对应的数据,从而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
结合第一方面,在第一方面的某些实现方式中,服务信息包括服务名称和服务对应的接口信息。
在本申请实施例中,处理器可以根据服务信息中的服务名称和服务对应的接口信息,能够准确的识别出客户进行的服务请求,从而可以判断该服务是否位于存储器中,能够避免直接向服务进程发送请求消息。
结合第一方面,在第一方面的某些实现方式中,该存储器为高速缓存存储器。
在本申请实施例中,通过将满足预设条件的服务信息以及服务信息对应的数据存储在高速缓存存储器cache中,使得再次调用该服务时,可以直接从cache中实现快速调用,避免了重复存取,减少了客户进程的等待时间,从而可以提高电子设备的运行速度和系统性能,增强用户体验。
第二方面,提供了一种进程间通信装置,该装置包括存储单元、处理单元和收发单元,存储单元用于,存储服务信息和该服务信息对应的数据;处理单元用于,获取客户进程向服务进程发起通信请求的请求消息,根据请求消息中的服务信息确定服务信息保存在存储单元中,从存储单元中获取与服务信息对应的数据;收发单元用于,将与服务信息对应的数据发送给客户进程。
结合第二方面,在第二方面的某些实现方式中,该收发单元还用于,将请求消息发送给服务进程,并接收服务进程发送的与服务信息对应的数据;处理单元还用于,将服务信息以及服务信息对应的数据保存在存储单元中。
结合第二方面,在第二方面的某些实现方式中,该处理单元还用于:在客户进程向服务进程发起通信请求时,记录第一时间点;在服务进程响应客户进程发起的通信请求时,记录第二时间点;根据第一时间点和第二时间点确定服务等待时间;当满足服务等待时间大于阈值时,将通信请求中的服务信息和服务信息对应的数据保存在存储单元中。
结合第二方面,在第二方面的某些实现方式中,该处理单元还用于:在客户进程向服务进程发起通信请求时,记录通信请求的次数;当通信请求的次数大于阈值时,将服务信息和服务信息对应的数据保存在存储单元中。
结合第二方面,在第二方面的某些实现方式中,该处理单元还用于:当服务等待时间大于阈值且通信请求的次数大于阈值时,将服务信息和该服务信息对应的数据保存在存储单元中。
结合第二方面,在第二方面的某些实现方式中,服务信息对应的数据是由服务进程进行更新的。
结合第二方面,在第二方面的某些实现方式中,服务信息包括服务名称和服务对应的接口信息。
结合第二方面,在第二方面的某些实现方式中,该存储单元为高速缓存存储单元。
第三方面,提供了一种装置,该装置包括处理器,该处理器用于执行如上述第一方面及其第一方面任一可能设计的技术方案。
第四方面,提供了一种电子设备,该电子设备包括:一个或多个处理器;一个或多个存储器,该一个或多个存储器存储有服务信息和该服务信息对应的数据;该一个或多个存储器存储有一个或多个计算机程序,该一个或多个计算机程序包括指令,当该指令被该一个或多个处理器执行时,使得该电子设备执行如上述第一方面及其第一方面任一可能设计的技术方案。
应理解,电子设备可以控制该一个或多个处理器执行如上述第一方面及其第一方面任一可能设计的技术方案。
第五方面,提供了一种芯片,该芯片与电子设备中的存储器耦合,用于调用存储器中存储的计算机程序并执行本申请实施例第一方面及其第一方面任一可能设计的技术方案;本申请实施例中“耦合”是指两个部件彼此直接或间接地结合。
第六方面,提供了一种计算机可读存储介质,该计算机可读存储介质包括计算机程序,当计算机程序在电子设备上运行时,使得该电子设备执行如上述第一方面及其第一方面任一可能设计的技术方案。
第七方面,提供了一种计算机程序产品,当所述计算机程序产品在电子设备上运行时,使得计算机执行如上述第一方面及其第一方面任一可能设计的技术方案。
其中,第二方面至第七方面的有益效果,可以参见第一方面的有益效果,不再重复赘述。
附图说明
图1是本申请实施例提供的一种电子设备的结构示意图。
图2是本申请实施例提供的一种存储层次的示意性框图。
图3是本申请实施例提供的一种电子设备的软件结构示意图。
图4是binder通信机制的原理示意图。
图5是binder通信机制的示意性流程图。
图6是本申请实施例提供的一种进程间通信方法的示意性流程图。
图7是本申请实施例提供的另一种进程间通信方法的示意性流程图。
图8是本申请实施例提供的一种进程间通信的耗时检测方法的示意性流程图。
图9是本申请实施例提供的另一种进程间通信方法的示意性流程图。
图10是本申请实施例提供的一种进程间通信装置的示意性框图。
图11是本申请实施例提供的一种电子设备的示意性结构图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地 描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
以下实施例中所使用的术语只是为了描述特定实施例的目的,而并非旨在作为对本申请的限制。如在本申请的说明书和所附权利要求书中所使用的那样,单数表达形式“一个”、“一种”和“该”旨在包括例如“一个或多个”这种表达形式,除非其上下文中明确地有相反指示。还应当理解,在本申请以下各实施例中,“至少一个”、“一个或多个”是指一个、两个或两个以上。“第一”、“第二”以及各种数字编号只是为了描述方便进行的区分,并不用来限制本申请实施例的范围。字符“/”一般表示前后关联对象是一种“或”的关系。下文各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。例如,本申请实施例中,“501”、“601”、“701”等字样仅为了描述方便作出的标识,并不是对执行步骤的次序进行限定。
在本说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。本申请中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其他实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。在本申请实施例中,“当……时”、“在……的情况下”、“若”以及“如果”等描述均指在某种客观情况下设备会做出相应的处理,并非是限定时间,且也不要求设备在实现时一定要有判断的动作,也不意味着存在其它限定。
以下介绍电子设备和用于使用这样的电子设备的实施例。在一些实施例中,电子设备可以是还包含其它功能诸如个人数字助理和/或音乐播放器功能的便携式电子设备,诸如手机、平板电脑、具备无线通讯功能的可穿戴电子设备(如智能手表)等。便携式电子设备的示例性实施例包括但不限于搭载鸿蒙(Harmony OS)或者其它操作系统的便携式电子设备。上述便携式电子设备也可以是其它便携式电子设备,诸如膝上型计算机(Laptop)等。还应当理解的是,在其他一些实施例中,上述电子设备也可以不是便携式电子设备,而是台式计算机、智能电视、智能音箱等。
图1示出了本申请实施例提供的一种电子设备的结构示意图。如图1所示,图1示出了电子设备100的结构示意图。电子设备100可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户身份识别(subscriber identification module,SIM)卡接口195等。其中,传感器模块180可以包括压力传感器180A,陀螺仪传感器180B,气压传感器180C,磁传感器180D,加速度传感器180E,距离传感器180F,接近光传感器180G,指纹传感器180H,温度传感器180J,触摸传感器180K,环境光传感器180L,骨传导传感器180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备100的具体限定。在本申请另一些实施例中,电子设备100可以包括比图示更多或更少的部件,或者组合某些部 件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
其中,处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,存储器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。其中,控制器可以是电子设备100的神经中枢和指挥中心。控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓存存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从该存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路间(inter-integrated circuit,I2C)接口,集成电路间音频(nter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,SIM卡接口,和/或USB接口等。其中,USB接口130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口130可以用于连接充电器为电子设备101充电,也可以用于电子设备101与外围设备之间传输数据。该USB接口130也可以用于连接耳机,通过耳机播放音频。
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。
内部存储器121可以用于存储一个或多个计算机程序,该一个或多个计算机程序包括指令。处理器110可以通过运行存储在内部存储器121的上述指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统;该存储程序区还可以存储一个或多个应用(比如图库、联系人等)等。存储数据区可存储电子设备101使用过程中所创建的数据(比如照片,联系人等)等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如一个或多个磁盘存储部件,闪存部件,通用闪存存储器(universal flash storage,UFS)、嵌入式多媒体卡(Embedded Multi Media Card,eMMC)等。在一些实施例中,处理器110可以通过运行存储在内部存储器121的指令,和/或存储在设置于处理器110中的存储器的指令,来使得电子设备101执行本申请实施例中所提供的方法,以及其他应用及数据处理。电子设备100可以通过音频模块170、扬声器170A、受话器170B、麦克风170C、耳机接口170D、以及应用处理器等实现音频功能。例如音乐播放、录音等。
图2示出了本申请实施例提供的一种存储层次的示意性框图。如图2所示,存储层次分为4层,由上之下分别为寄存器(register memory)、缓存存储器(cache memory)、 主存储器(main memory)、辅助存储器(auxiliary memory)。
其中,存储层次是存储系统层次结构的排列顺序,每一层于下一层相比都拥有较高的读写速度和较低延迟性,以及较小的容量。
寄存器是处理器用来存放数据的存储区域,用来暂时存放参与运算的数据和运算结果。寄存器可以设置在处理器内部。寄存器通常可以位于处理器内部。
缓存存储器是存在于主存储器和寄存器之间的存储器,缓存存储器的容量较小,但是读写速度比主存储器快。缓存存储器中可以存储部分主存储器中的数据,因此处理器在读取数据时会先访问缓存存储器,如果缓存存储器中未包括需要的数据时再访问主存储器,由于缓存存储器的读写速度快于主存储器,如果缓存存储器中包括处理器需要的数据时,则可以提高电子设备的运行速度。
主存储器又被称为主存、内存、内部存储器(即图1中的121),其作用是存放指令和数据。处理器需要读取数据时,可以先在缓存存储器中读取,当缓存存储器中未有该数据时,处理器可以在主存储器中查找该数据,当处理器在主存储器中找到该数据时,可以将找到的数据缓存到缓存存储器中以便下次可以直接在缓存存储器中读取该数据。主存储器的速度慢于缓存存储器,快于辅助存储器。
辅助存储器又被称为外部存储器(即图1中的120),是指电子设备中除主存储器、缓存存储器、寄存器以外的存储器,例如硬盘(hard disk)、光盘存储器。
需要说明的是,图2所示的存储层次仅为示例,本申请并不限定于此,例如,在本申请的另一些实施例中,主存储器与辅助存储器之间也可以设置有缓存。再例如,在本申请的另一些实施例中,缓存存储器可以分成多级,例如L1cache、L2cache、L3cache。
图3示出了本申请实施例的电子设备100的软件结构框图。
分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime)和系统库,以及内核层。应用程序层可以包括一系列应用程序包。
如图3所示,应用程序层可以包括图库、日历、地图、导航、通话,相机、设置、视频,音乐、短信等应用程序。应用程序框架层为应用程序层的应用程序提供应用编程接口(application programming interface,API)和编程框架。应用程序框架层可以包括一些预先定义的函数。如图2所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,电话管理器,资源管理器,通知管理器等。
窗口管理器用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。电话管理器用于提供电子设备100的通信功能。例如通话状态的管理(包括接通,挂断等)。资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。通知管理器使应用程序可以在状态 栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如,后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。再例如,在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。
Android runtime包括核心库和虚拟机。Android runtime负责安卓系统的调度和管理。核心库包含两部分:一部分是java语言需要调用的功能函数,另一部分是安卓的核心库。
应用程序层和应用程序框架层运行在虚拟机中。虚拟机将应用程序层和应用程序框架层的java文件执行为二进制文件。虚拟机用于执行对象生命周期的管理,堆栈管理,线程管理,安全和异常的管理,以及垃圾回收等功能。
系统库可以包括多个功能模块。例如:表面管理器(surface manager),媒体库(media libraries),三维图形处理库(例如:OpenGL ES),2D图形引擎(例如:SGL)等。表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。媒体库支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H.264,MP3,AAC,AMR,JPG,PNG等。三维图形处理库用于实现三维图形绘图,图像渲染,合成,和图层处理等。2D图形引擎是2D绘图的绘图引擎。此外,系统库还可以包括状态监测服务模块等,例如物理状态识别模块,用于对用户手势进行分析和识别;传感器服务模块,用于对硬件层各类传感器上传的传感器数据进行监测,确定电子设备100的物理状态。
内核层是硬件和软件之间的层。内核层可以包含显示驱动,摄像头驱动,音频驱动,传感器驱动和binder驱动等。
为了便于理解,本申请以下实施例将以具有图1至图3所示结构的电子设备为例,结合附图和应用场景,对本申请实施例提供的进程间通信方法进行具体阐述。
图4示出了binder通信机制的原理示意图。
在安卓(Android)、鸿蒙等操作系统中,用户态IPC是依赖binder实现的,binder是操作系统中非常重要的特性之一,其通信机制模型基于客户端/服务端(client/server,C/S)的通信模式实现。binder通信采用C/S模式,从组件视角来说,binder通信包含客户(client)端、服务(server)端、服务管理(service manager)以及binder驱动。
对于每个Android的进程,只能运行在自己进程所拥有的虚拟地址空间。举例而言,一个Android进程对应一个4GB的虚拟地址空间,其中3GB是用户空间,1GB是内核空间,内核空间的大小可以通过参数配置调整的。对于用户空间,不同进程之间彼此是不能共享的,而内核空间却是可共享的。client进程(即,使用服务的进程/客户进程)向server进程(即,提供服务的进程/服务进程)通信,可以利用进程间可共享的内核内存空间来完成底层通信工作的,client进程与server进程通信可以采用一种设备驱动程序中对设备的I/O通道进行管理的函数ioctl等与内核空间的binder驱动进行交互。
如图4所示,基于binder机制的通信过程主要可以概括为以下三个过程:注册服务、获取服务和使用服务。注册服务:server进程要先注册服务到service manager。获取服务:client进程使用某个服务前,要先从service manager中获取相应的服务。使用服务:client进程根据得到的服务信息建立与服务所在的server进程通信的通路,然后才可以直接与服务交互。可以理解的是,图4中的client进程、server进程、service manager之间交互都是 虚线表示,是由于它们彼此之间不是直接交互的,而都是通过与binder驱动进行交互的,从而实现IPC通信。client进程也可以被称为客户端,server进程也可以被称为服务端。
其中,binder驱动位于内核空间(即内核层中),client进程、server进程和service manager位于用户空间。binder驱动和service manager可以看作为操作系统的基础架构,而client进程和server进程是操作系统的应用层,用户只需自定义实现client进程和server进程,借助操作系统的基本平台架构便可以直接进行IPC通信。
图5示出了binder通信机制的示意性流程图。
从上述内容可知,client进程和server进程通过binder驱动实现交互。下面以请求获取“张三”的电话号码这个服务为例,详细说明client进程请求服务的具体过程,如图5所示,该过程具体可以包括S501至S505。
S501,server进程向服务管理注册服务。
其中,server进程是在C/S模式下提供服务的进程,即服务进程。
在该步骤中,由于server进程不能直接和服务管理进行交互,server进程通过binder驱动向服务管理注册服务,该服务管理中包含了很多服务,例如,该服务管理中包含获取电话号码的服务。
应理解,server进程首先向binder驱动注册获取电话号码的服务,然后binder驱动会向服务管理发送注册的获取电话号码的服务。
S502,client进程向服务管理发起获取服务的请求。
其中,client进程是在C/S模式下使用服务的进程,即客户进程。
在该步骤中,由于client进程不能直接和服务管理进行交互,client进程通过binder驱动向服务管理发起获取服务的请求,传递服务名称等信息。其中,该请求可以为获取电话号码的服务请求,该服务名称可以为获取电话服务。
示例性的,client进程首先向binder驱动发送要获取电话号码这个服务的请求,然后binder驱动将该请求发送给服务管理,服务管理可以知道client进程需要获取电话号码的相关服务信息。
S503,服务管理返回服务信息到client进程。
具体地,服务管理根据client进程发送的获取服务的请求中的服务名称,查找到对应的server的服务信息后,通过binder驱动将对应的server服务信息返回给client进程,并实现内存映射等操作为进程间通信IPC做准备。这里的服务信息可以理解为获取电话服务所对应的服务信息。
S504,client进程向server进程发送数据。
具体地,client进程接收到binder驱动返回的服务对应的服务信息后,即可将需要获取的数据打包,依靠binder驱动创建的内存映射,将数据发送给服务管理和/或发送给server进程,进行相应的处理。也就是说,client进程首先向binder驱动发送要获取的数据,然后binder驱动向服务管理和/或server进程发送需要获取的数据。
应理解,需要获取的数据为服务信息对应的数据,即用户想要获取的数据,该数据例如可以是“张三”的电话号码。
S505,server进程通过binder驱动向client进程发送返回结果。
具体地,server进程在收到数据后,会从线程池中取出线程,进行数据解包和目标方法调用,最终将处理结果原路返回给client进程。也就是说,server进程和/或服务管理会 根据client进程发送的数据获取相对应的结果,并将该结果发送给binder驱动,binder驱动再将该结果发送给client进程。应理解,这里的返回结果例如可以是“张三”的电话号码。
综上所述,通过S501至S505即可完成用户的服务请求(例如:获取“张三”的电话号码这个服务),通过S501至S503可以知道用户需要获取什么类型的服务(例如:获取电话的服务),通过S504和S505即可获取服务对应的具体数据(例如:“张三”的电话号码)。在S503中获取返回的服务信息以及S505中获取返回结果,client进程都需要通过binder驱动向服务管理或者server进程发送信息,服务管理或者server进程根据接收到的信息进行处理后再通过binder驱动返回相应的结果。
在binder这种通信机制下,当server进程在收到请求消息并进行处理时,client进程的请求线程会被挂起,直到server进程的处理结果返回。因此,当server进程处理时间较长时,可能会导致client进程出现卡顿、响应慢、甚至出现ANR等问题。针对这种问题,目前尚无系统优化方案。
因此,本申请提供了一种进程间通信IPC方法,通过在binder驱动中增加cache机制来缓存服务进程返回的结果,从而减少服务进程的服务执行次数和客户进程的等待时长,从而可以提高电子设备的运行速度,增强用户体验。
图6示出了本申请实施例提供的一种进程间通信方法的示意性流程图。如图6所示,该方法600可以由电子设备中的处理器执行,该方法600包括S601至S604,下面以获取“张三”的电话号码这个服务为例,详细说明客户进程获取服务的具体过程。
S601,处理器获取客户进程向服务进程发起通信请求的请求消息。
应理解。当用户需要获取某种服务时,需要向服务进程发送请求消息。该请求消息例如可以是S502中的客户进程向服务进程发送的获取服务请求,和/或,S504中的客户进程向服务进程发送需要获取的数据请求。
S602,处理器根据该请求消息中的服务信息确定该服务信息保存在存储器中。
应理解,处理器可以根据client进程发送的请求消息中的服务信息,来判断client进程需要哪些服务。例如,client进程向server进程发送的请求消息用于请求获取“张三”的电话号码,服务信息用于指示获取“张三”的电话号码,且该服务信息包括服务名称和服务对应的接口信息。该服务名称可以理解为获取电话服务对应的服务名称,服务对应的接口信息可以理解为获取“张三”的电话号码需要访问的接口信息。server进程根据服务信息确认client进程需要哪些信息,从而将client进程需要的信息发送给client进程。
还应理解,该存储器位于内核空间(即,内核层),该存储器例如可以是高速缓存存储器(cache)。该存储器中存储有服务信息和该服务信息对应的数据,该服务信息包括服务名称和服务对应的接口信息。当处理器根据请求消息中的服务信息确定该服务信息已经保存在存储器中时,处理器可以直接从该存储器中获取与服务信息对应的数据,并将该数据返回给客户进程。
示例性的,当用户想要获取“张三”的电话号码,且获取“张三”的电话号码对应的相关服务信息保存在存储器中时,客户进程可以首先从存储器中获取电话服务对应的数据,然后还可以从存储器中获取“张三”的电话号码。也就是说,该服务信息可以包括获取电话的服务信息和获取电话号码服务对应的接口信息,该服务信息对应的数据可以包括获取电话号码对应的相关数据;或者,该服务信息可以包括获取“张三”的电话号码对应的服务信息和获取“张三”的电话号码服务对应的接口信息,该服务信息对应的数据可以包括“张三”的 电话号码。
还应理解,在S602之前,该方法还可以执行如图7所示的方法,通过方法700可以将满足相应条件的服务保存在存储器中,以便于当客户进程再次调用该服务时,可以直接从存储器中获取服务信息以及服务信息对应的数据。
S603,处理器从该存储器中获取与服务信息对应的数据。
应理解,处理器根据client进程发送请求消息中的服务信息确定该服务信息保存在存储器(例如,cache)中,因而无需向server进程发送请求消息,可以直接从存储器(例如,cache)中获取与该服务信息对应的数据,从而可以减少大量的不必要的服务调用,缩短client进程IPC的等待时长。
示例性的,若获取“张三”的电话号码所对应的服务信息保存在cache中,则处理器可以直接从cache中获取“张三”的电话号码,而不需要将获取“张三”的电话号码所对应的服务信息发送给server进程,然后再获取“张三”的电话号码,从而可以减少不必要的server进程的调用。
需要说明的是,服务信息对应的数据可以是由服务进程进行更新的。也就是说,服务信息对应的数据可以是动态实时变化的,当server进程检测到服务信息对应的数据发生改变时,可以对服务信息对应的数据进行更新,从而使得当用户调用该服务时,可以获得准确该服务对应的结果。
可选地,若处理器检测到存储器中某个服务信息对应的服务长时间没有调用,则处理器可以将该服务信息以及该服务信息对应的数据进行主动删除,从而可以节省存储器中的存储空间,以便于存储其他服务信息以及服务信息对应的数据。
可选地,若处理器通过如图8中所述的方法,检测到某个服务耗时较长和/或访问频率过高时,处理器也可以将该服务的服务信息以及服务信息对应的数据加入到存储器中,以便于当client进程再次调用这些服务时,可以直接从存储器中获取这些服务对应的数据,从而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
S604,处理器将服务信息对应的数据发送给客户进程。
具体地,处理器可以根据服务信息,从存储器(例如,cache)中获取与该服务信息对应的数据,并将该数据发送给client进程,从而处理器可以利用该服务信息对应的数据进行接下来的处理。例如,该服务信息对应的数据可以是“张三”的电话号码等。
根据本申请实施例提供的IPC方法,处理器可以根据请求消息中的服务信息,确定该服务信息保存在存储器中,从而可以直接从存储器中获取与该服务信息对应的数据,并将该数据发送给客户进程。由于该存储器位于内核空间中,因此客户进程无需访问位于用户空间中的服务进程,即可从位于内核空间的存储器中获取服务信息对应的数据,从而可以减少不必要的服务调用,避免IPC操作引起的系统卡顿等问题,能够有效降低系统资源的占用,提高电子设备的运行速度和系统性能,增强用户体验。
图7示出了本申请实施例提供的另一种进程间通信方法的示意性流程图。如图7所示,该方法700可以由电子设备中的处理器执行,该方法700包括S701至S704,详细说明client进程获取服务的具体过程。
需要说明的是,方法700可以在方法600之前执行,即处理器可以通过执行S701至S704,获取需要保存在存储器中的服务,然后当客户进程调用该服务时,可以直接从存储器中直接获取需要的数据,从而无需再向服务进程发送请求消息以获取需要的数据。
S701,处理器获取客户进程向服务进程发起通信请求的请求消息。
该步骤可以参考S601,在此不再赘述。
S702,处理器将该请求消息发送给服务进程。
应理解,处理器例如可以根据图5中所述的方法流程,将该请求消息通过binder驱动发送给服务进程,以获取服务进程中与该请求消息中的服务信息对应的数据。
S703,处理器接收服务进程发送的与该服务信息对应的数据,并将该服务信息以及服务信息对应的数据保存在存储器中。
具体地,处理器将client进程发送的请求消息通过binder驱动发送给server进程后,server进程会从线程池中取出线程,进行数据解包和目标方法调用,确定该请求消息中的服务信息对应的数据。处理器接收server进程发送的与该服务信息对应的数据,并将该服务信息以及该服务信息对应的数据保存在存储器(例如,cache)中。
示例性的,通过server进程获取与“张三”的号码电话相关的数据后,可以将获取“张三”的电话号码所对应的服务信息以及“张三”的电话号码所对应的相关数据(例如:“张三”的电话号码)存储在cache中,以便于下次获取“张三”的电话号码时,可以从cache中直接获取“张三”的电话号码相关的数据,而不需要将获取“张三”的电话号码所对应的服务信息发送给server进程,然后再获取与“张三”的电话号码所对应的相关数据,从而可以减少不必要的server进程的调用。
可选地,该服务信息和服务信息对应的数据可以以键值对的方式缓存至cache中,并且具体存储时可以以服务信息作为key值,以服务信息对应的数据作为value值。因此,在查询cache中保存的数据时,可以根据请求消息中的服务信息获取cache中获取与服务信息对应的数据。
应理解,在判断哪些服务可以保存在存储器(例如,cache)中,可以考虑IPC操作时长和/或调用服务的难易程度和/或服务请求的次数等。
在一些实施例中,在client进程向server进程发起通信请求时,处理器记录第一时间点;在server进程响应client进程发起的通信请求时,处理器记录第二时间点;处理器根据第一时间点和第二时间点确定服务等待时间;当满足预设条件时,处理器将通信请求中的服务信息和服务信息对应的数据保存在存储器中。可选地,该预设条件可以是服务等待时间大于阈值,该阈值可以是经验值,例如,6ms、10ms等,本申请对此不作限定。
在一些实施例中,在client进程向server进程发起通信请求时,处理器记录通信请求的次数;当通信请求的次数大于阈值时,处理器可以将该通信请求中的服务信息和服务信息对应的数据保存在存储器中。
在一些实施例中,处理器还可以同时检测服务等待时间和服务请求的次数,当服务等待时间大于阈值且client进程向server进程发起通信请求的次数大于阈值时,处理器也可以将该通信请求中的服务信息和服务信息对应的数据保存在存储器中
一般而言,对于存储器中保存的服务,客户进程调用该服务的次数应远大于服务进程修改该服务的次数。下面结合图8中的内容进行具体阐述,在此不再赘述。
S704,处理器将服务信息对应的数据发送给客户进程。
具体地,处理器接收服务进程中返回的与服务信息对应的数据后,可以将该数据发送给client进程,从而处理器可以利用该服务信息对应的数据进行接下来的处理。例如,该服务信息对应的数据可以是“张三”的电话号码等。
根据本申请实施例提供的IPC方法,处理器可以将请求消息发送给服务进程,并获取服务进程返回的与该服务信息对应的数据,并将该服务信息以及该服务信息对应的数据保存在存储器中,即对服务进程返回的结果进行缓存,从而使得客户进程下次再调用该服务时,处理器可以直接从存储器中获取与该服务信息对应的数据,并将该数据发送给客户进程,进而可以减少不必要的服务调用,避免IPC操作引起的系统卡顿等问题,有效降低系统资源的占用,提高电子设备的运行速度和系统性能,增强用户体验。
图8示出了本申请实施例提供的一种进程间通信的耗时检测方法的示意性流程图。如图8所示,该方法800具体包括S801至S808,以下分别对这些步骤进行详细介绍。
S801,程序调用IPC接口请求服务。
应理解,不同的请求消息/程序,对应的IPC应用程序接口不同,例如,打开通讯录的请求和打开相机应用的请求需要访问不同的通信接口。
S802,进入自定义的钩子函数(hook函数)。
应理解,在本申请实施例中通过借助hook技术,编写自定义hook函数,在系统运行过程中,通过替换操作性系统(例如,安卓系统)的一个原生程序app_process(即应用进程的主入口点),实现对所有应用进程的IPC处理接口的hook操作。
其中,hook技术是一种用于改变API执行结果的技术,能够将系统的API函数执行重定向。通过hook函数能够记录IPC的开始时间和结束时间,从而可以确定IPC耗时。
S803,记录开始时间。
S804,调用系统函数进行IPC操作。
S805,接收到IPC结果后,记录结束时间。
通过S803至S805,利用hook函数分别在开始位置和结束位置记录记录开始时间和结束时间,确定每个IPC操作的时长(即,每个服务的操作时长)。
应理解,开始时间可以对应S502中客户进程向服务进程发起通信请求的时间,结束时间可以对应S503或S505中服务进程响应客户进程发起的通信请求的时间。也就是说,该时间检测可以是检测S502和S503的时间,即获取服务至返回服务信息对应的时间;也可以是检测S502至S505的时间,即获取服务至返回该服务对应的具体数据对应的时间。
S806,若结束时间和开始时间的差值大于设定的最大时长,则确定为发生IPC超时,打印异常日志。
通过结束时间和开始时间的差值得到当前IPC操作的等待时长,设置最大等待时长作为阈值,当该差值大于阈值(例如,5ms、10ms)时,则认为出现了等待超时的现象。对于造成等待超时的IPC操作,打印等待时长、堆栈等日志信息,用于下一步的排查和优化。
S807,根据异常日志,查看源码,判断IPC操作类型。
S808,若该IPC操作类型为查询类IPC操作,将IPC信息添加到cache中,设定为需要进行优化的操作。
应理解,该查询类IPC操作可以理解为频繁使用接口的操作,而且这些接口的访问次数远大于修改次数。对于这类IPC操作,可以将其服务信息以及该服务信息对应的数据添加到cache中。
其中,该cache中可以包括两类值,一类表示IPC操作的目标方法标识符,即服务信息,该服务信息可以用于标识该IPC操作调用的服务名称和接口信息;另一类则对应于该服务信息的结果,即该服务信息对应的数据,该数据为server进程返回的结果。
需要说明的是,在判断哪些服务需要保存在存储器中,除了可以考虑IPC操作时长外,还可以考虑调用服务的难易程度,和/或,还可以考虑服务请求的次数。
在一些实施例中,处理器可以根据调用的服务难以程度来确定是否将该服务保存在存储器中,例如,获取“张三”的电话号码的服务相对简单,而拨打“张三”的电话号码涉及的服务相对复杂,在这种情况下,可以将获取“张三”的电话号码对应的服务保存在存储器中。
在一些实施例中,在客户进程向服务进程发起通信请求时,处理器记录在一定时间范围内通信请求的次数;当通信请求的次数大于阈值时,该阈值例如可以是经验值,处理器将该服务信息和该服务信息对应的数据保存在存储器中。
通过设置服务请求次数的阈值,检测出频繁调用的服务,并将该服务对应的服务信息以及服务信息对应的数据存储在存储器中,从而使得当客户进程再次调用该服务时,可以直接从存储器中获取该服务对应的数据,进而可以减少不必要的服务调用,提高电子设备的运行速度和系统性能,增强用户体验。
在一些实施例中,处理器可以同时检测服务等待时间和服务请求的次数,当服务等待时间大于阈值且客户进程向服务进程发起通信请求的次数大于阈值时,处理器可以将该服务信息和该服务信息对应的数据保存在存储器中。
通过设置服务等待时间的阈值和服务请求次数阈值,检测出导致客户进程等待时间过长的服务并且多次发起通信请求的服务,可以将这些服务对应的服务信息以及服务信息对应的数据存储在存储器中,从而可以进一步提高电子设备的运行速度和系统性能,增强用户体验。
在一些实施例中,处理器还可以综合考虑IPC操作时长、调用服务的难易程度以及服务请求的次数,通过综合考虑这些因素,可以进一步找到需要进行cache缓存的目标接口,从而可以将这些接口信息以及调用该接口的服务信息存储到cache中,可以进一步提高电子设备的运行速度和系统性能,增强用户体验。
通过S801至S808,可以检测IPC耗时,识别出导致client进程等待时间过长的server进程,并将该服务信息以及获取的服务信息对应的数据存储在存储器(例如,cache)中,从而使得当client进程再次调用该服务时,可以直接从存储器(例如,cache)中获取该服务对应的数据,从而可以减少不必要的服务调用。
此外,通过本申请实施例提供的IPC耗时检测方法,通过在系统启动过程中通过编写hook函数替换app_process,在上层应用程序无感知的情况下,实现全部应用进程的IPC接口的hook操作,进而可以获取各个IPC操作的执行时间,找到导致client进程IPC操作等待超时的server进程的服务,便于后续定位分析。同时本申请实施例提供的IPC耗时检测方法,可以不受安卓版本限制、不受根权限的限制、不对业务功能产生影响、对系统性能也没有明显影响。
图9示出了本申请实施例提供的另一种进程间通信方法的示意性流程图。如图9所示,该方法600可以由电子设备中的处理器执行,该方法900具体包括S901至S907。
S901,程序调用IPC接口请求服务。
S902,binder驱动接收到请求消息。
应理解,client进程向server进程发起通信时,需要通过binder驱动进行信息交互,具体可以参考S501至S505,在此不再赘述。
当binder驱动接收到请求消息时,binder驱动首先可以判断该请求消息中的服务信息 (即上述的服务名称和服务对应的接口信息)是否保存在cache中,其中,该请求消息例如可以是请求获取“张三”的电话号码。
S903,根据client进程提供的服务信息进行判断。
S904,判断该cache中是否有对应的记录项信息。
当client进程向server进程发送请求消息时,处理器首先会判断该请求消息中的服务信息是否在cache中,即判断该cache中是否有对应的记录项信息。若该服务信息在cache中,即cache中有对应的记录项信息,则处理器可以执行S905;若该服务信息不在cache中,即cache中没有对应的记录项信息,则处理器可以执行S906和S907。
其中,该服务信息包括服务名称和服务对应的接口信息。示例性的,该服务名称可以为获取电话服务,该服务对应的接口信息可以理解为获取“张三”电话号码的服务对应的接口信息。该记录项信息可以理解为上述的服务信息以及服务信息对应的数据。该服务信息可以理解为client进程在请求服务过程中提供的server进程的服务信息,即获取什么样的系统服务(例如,获取电话服务)以及需要获取该系统服务下的具体数据(例如,“张三”的电话号码)。
需要说明的是,当server进程判断出cache中存储的信息(即,服务信息对应的数据)发生改变,则server进程可以通过binder驱动提供的接口进行更新,并将更新后的信息存储到cache中,以便于下次调用。
示例性的,手机中的应用程序可能会经常获取用户的定位信息,但用户的位置可能好几个小时甚至一天都不会发生改变,对于这类获取定位信息的服务,处理器也可以将其保存在cache中。当server进程发现用户定位发生改变时,可以通过binder驱动提供的与定位相关的接口对位置的具体内容进行更新,从而使得cache保存的信息都是准确无误的,便于用户下次调用。
S905,若cache中有对应的记录项信息,则将结果信息封装返回给client进程。
具体地,处理器根据client进程发送请求消息中的服务信息判断该服务信息是否在cache中,若该服务信息不在该cache中,则处理器将该请求消息发送给server进程,server进程根据该服务信息确定该服务信息对应的数据,该服务信息对应的数据例如“张三”的电话号码。
S906,若cache中没有对应的记录项信息,则根据正常流程调用server进程对应服务进行处理,并等待返回结果。
具体地,处理器根据client进程发送请求消息中的服务信息判断该服务信息是否在cache中,若该服务信息不在该cache中,则处理器将该请求消息发送给server进程,server进程根据该服务信息确定该服务信息对应的数据,具体内容可以参考图5,在此不再赘述。
示例性的,若获取“张三”的电话号码所对应的服务信息不在cache中,则处理器需要将获取“张三”的电话号码所对应的服务信息发送给server进程,然后再获取与“张三”的电话号码相关的数据。
S907,根据server进程返回的结果,将结果信息封装返回给client进程,并将处理结果插入到cache中。
具体地,处理器接收服务进程中返回的与服务信息对应的数据后,可以将该数据发送给client进程,从而处理器可以利用该服务信息对应的数据进行接下来的处理。例如,该服务信息对应的数据可以是“张三”的电话号码等。
示例性的,若cache中没有对应的记录项信息,则可以先调用server进程对应服务进行处理,在处理结束、返回结果的过程中,可以将<服务信息,服务信息对应的数据>作为<key,value>对,即将服务信息和服务信息对应的数据以键值对的方式插入到cache中。
应理解,在判断哪些服务可以保存在cache中,可以考虑IPC操作时长和/或调用服务的难易程度和/或服务请求的次数等。
在一些实施例中,在client进程向server进程发起通信请求时,处理器记录第一时间点;在server进程响应client进程发起的通信请求时,处理器记录第二时间点;处理器根据第一时间点和第二时间点确定服务等待时间;当服务等待时间大于阈值时,处理器将通信请求中的服务信息和服务信息对应的数据保存在cache中。
在一些实施例中,在client进程向server进程发起通信请求时,处理器记录通信请求的次数;当通信请求的次数大于阈值时,处理器将该服务信息和该服务信息对应的数据保存在cache中。
在一些实施例中,处理器还可以同时检测服务等待时间和服务请求的次数,当服务等待时间大于阈值且client进程向server进程发起通信请求的次数大于阈值时,处理器可以将该服务信息和该服务信息对应的数据保存在cache中。
一般而言,对于存储器中保存的服务,client进程调用该服务的次数应远大于server进程修改该服务的次数。具体内容可以参考图8,在此不再赘述。
根据本申请实施例提供的IPC方法,通过判断client进程的请求消息中的服务信息是否在cache中,如果该服务信息在cache中,则处理器可以直接获取cache中与该服务信息对应的数据,并将该数据发送给client进程;如果服务信息不在cache中,则处理器可以将该请求消息发送给server进程,获取server进程返回的服务信息对应的数据,将该服务信息以及服务信息对应的数据保存在cache中,即对server进程返回的结果进行缓存,从而使得client进程下次再调用该服务信息时,处理器可以直接从cache中获取与该服务信息对应的数据,并将该数据发送给client进程。通过本申请实施例提供的方法,均能够减少不必要的服务调用,避免IPC操作引起的系统卡顿等问题,有效降低系统资源的占用,提高电子设备的运行速度和系统性能,增强用户体验。
上述主要从电子设备的角度对本申请实施例提供的一种进程间通信方法进行了介绍。可以理解的是,电子设备为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的算法步骤,本申请能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
本申请实施例可以根据上述方法示例对电子设备中的处理器进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
在采用了对应各个功能的划分各个功能模块的情况下,图10示出了本申请实施例提供的进程间通信装置的示意性框图。如图10所示,该IPC装置1000可以包括:存储单元 1010、处理单元1020和收发单元1030。
存储单元1010用于,存储服务信息和该服务信息对应的数据。
处理单元1020用于,获取客户进程向服务进程发起通信请求的请求消息,根据请求消息中的服务信息确定服务信息保存在存储单元中,从存储单元中获取与服务信息对应的数据。
收发单元1030用于,将与服务信息对应的数据发送给客户进程。
可选地,该收发单元1030还用于,将请求消息发送给服务进程,并接收服务进程发送的与服务信息对应的数据;处理单元1020还用于,将服务信息以及服务信息对应的数据保存在存储单元中。
可选地,该处理单元1020还用于:在客户进程向服务进程发起通信请求时,记录第一时间点;在服务进程响应客户进程发起的通信请求时,记录第二时间点;根据第一时间点和第二时间点确定服务等待时间;当服务等待时间大于阈值时,将通信请求中的服务信息和服务信息对应的数据保存在存储单元1010中。
可选地,该处理单元1020还用于:在客户进程向服务进程发起通信请求时,记录通信请求的次数;当通信请求的次数大于阈值时,将服务信息和服务信息对应的数据保存在存储单元中。
可选地,该处理单元1020还用于:当服务等待时间大于阈值且通信请求的次数大于阈值时,将服务信息和该服务信息对应的数据保存在存储单元中。
可选地,该服务信息对应的数据是由服务进程进行更新的。
可选地,该服务信息包括服务名称和服务对应的接口信息。
可选地,该存储单元1010为高速缓存存储单元。
需要说明的是,上述方法实施例涉及的各步骤的所有相关内容均可以援引到对应功能模块的功能描述,在此不再赘述。本申请实施例提供的进程间通信装置,用于执行上述进程间通信方法,因此可以达到与上述处理方法相同的效果。
图11是本申请实施例提供的电子设备的示意性结构图。如图11所示,该电子设备1100包括:一个或多个处理器1110;一个或多个存储器1120;该一个或多个存储器1120存储有服务信息和所述服务信息对应的数据;该一个或多个存储器1120还存储有一个或多个计算机程序,该一个或多个计算机程序包括指令。当该指令被所述一个或多个处理器1110运行时,使得所述电子设备1100执行上述各实施例中进程间通信方法的各个步骤。
示例性地,上述一个或多个处理器1110具体可以为图1所示的处理器110,上述一个或多个存储器1120具体可以为图1所示的内部存储器120和/或与电子设备连接的外部存储器。
本申请实施例提供一种装置,该装置包括处理器,该处理器用于执行上述各方法实施例中的进程间通信方法。
本申请实施例还提供一种芯片,该芯片包括处理器和通信接口,该通信接口用于接收信号,并将该信号传输至处理器,该处理器处理信号,使得上述各方法实施例中的进程间通信方法被执行。
本申请实施例还提供一种计算机可读存储介质,该计算机可读存储介质中存储有计算机指令,当该计算机指令在电子设备上运行时,使得电子设备执行上述各方法实施例中的进程间通信方法。
本申请实施例还提供了一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述各方法实施例中的进程间通信方法。
另外,本申请实施例还提供一种装置,这个装置具体可以是芯片,组件或模块,该装置可包括相连的处理器和存储器;其中,存储器用于存储计算机执行指令,当装置运行时,处理器可执行存储器存储的计算机执行指令,以使芯片执行上述各方法实施例中的进程间通信方法。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (18)

  1. 一种进程间通信方法,其特征在于,包括:
    处理器获取客户进程向服务进程发起通信请求的请求消息;
    所述处理器根据所述请求消息中的服务信息确定所述服务信息保存在存储器中,所述存储器位于内核空间;
    所述处理器从所述存储器中获取与所述服务信息对应的数据;
    所述处理器将所述数据发送给所述客户进程。
  2. 根据权利要求1所述的方法,其特征在于,在所述处理器根据所述请求消息中的服务信息确定所述服务信息保存在存储器中之前,所述方法还包括:
    所述处理器将所述请求消息发送给所述服务进程;
    所述处理器接收所述服务进程发送的与所述服务信息对应的数据,并将所述服务信息以及所述服务信息对应的数据保存在所述存储器中。
  3. 根据权利要求2所述的方法,其特征在于,所述将所述服务信息以及所述服务信息对应的数据保存在所述存储器中,包括:
    在所述客户进程向所述服务进程发起通信请求时,所述处理器记录第一时间点;
    在所述服务进程响应所述客户进程发起的通信请求时,所述处理器记录第二时间点;
    所述处理器根据所述第一时间点和所述第二时间点确定服务等待时间;
    当所述服务等待时间大于阈值时,所述处理器将所述服务信息和所述服务信息对应的数据保存在所述存储器中。
  4. 根据权利要求2所述的方法,其特征在于,所述将所述服务信息以及所述服务信息对应的数据保存在所述存储器中,包括:
    在所述客户进程向所述服务进程发起通信请求时,所述处理器记录所述通信请求的次数;
    当所述通信请求的次数大于阈值时,所述处理器将所述服务信息和所述服务信息对应的数据保存在所述存储器中。
  5. 根据权利要求1至4中任一项所述的方法,其特征在于,所述服务信息对应的数据是由所述服务进程进行更新的。
  6. 根据权利要求1至5中任一项所述的方法,其特征在于,所述服务信息包括服务名称和服务对应的接口信息。
  7. 根据权利要求1至6中任一项所述的方法,其特征在于,所述存储器为高速缓存存储器。
  8. 一种电子设备,其特征在于,包括:
    一个或多个处理器;
    一个或多个存储器;
    所述一个或多个存储器存储有一个或多个计算机程序,所述一个或多个计算机程序包括指令,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    获取客户进程向服务进程发起通信请求的请求消息;
    根据所述请求消息中的服务信息确定所述服务信息保存在所述一个或多个存储器中, 所述一个或多个存储器位于内核空间;
    从所述一个或多个存储器中获取与所述服务信息对应的数据;
    将所述数据发送给所述客户进程。
  9. 根据权利要求8所述的电子设备,其特征在于,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    将所述请求消息发送给所述服务进程;
    接收所述服务进程发送的与所述服务信息对应的数据,并将所述服务信息以及所述服务信息对应的数据保存在所述一个或多个存储器中。
  10. 根据权利要求9所述的电子设备,其特征在于,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    在所述客户进程向所述服务进程发起通信请求时,记录第一时间点;
    在所述服务进程响应所述客户进程发起的通信请求时,记录第二时间点;
    根据所述第一时间点和所述第二时间点确定服务等待时间;
    当所述服务等待时间大于阈值时,将所述通信请求中的服务信息和所述服务信息对应的数据保存在所述一个或多个存储器中。
  11. 根据权利要求9所述的电子设备,其特征在于,当所述指令被所述一个或多个处理器执行时,使得所述电子设备执行以下步骤:
    在所述客户进程向所述服务进程发起通信请求时,记录所述通信请求的次数;
    当所述通信请求的次数大于阈值时,将所述服务信息和所述服务信息对应的数据保存在所述一个或多个存储器中。
  12. 根据权利要求8至11中任一项所述的电子设备,其特征在于,所述服务信息对应的数据是由所述服务进程进行更新的。
  13. 根据权利要求8至12中任一项所述的电子设备,其特征在于,所述服务信息包括服务名称和服务对应的接口信息。
  14. 根据权利要求8至13中任一项所述的电子设备,其特征在于,所述一个或多个存储器为高速缓存存储器。
  15. 一种装置,其特征在于,所述装置包括处理器,所述处理器用于执行如权利要求1至7中任一项所述的方法。
  16. 一种芯片,其特征在于,所述芯片包括处理器和通信接口,所述通信接口用于接收信号,并将所述信号传输至所述处理器,所述处理器处理所述信号,使得如权利要求1至7中任一项所述的方法被执行。
  17. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机指令,当所述计算机指令在计算机上运行时,使得如权利要求1至7中任一项所述的方法被执行。
  18. 一种计算机程序产品,其特征在于,当所述计算机程序产品在计算机上运行时,使得所述计算机执行如权利要求1至7中任一项所述的方法。
PCT/CN2023/087802 2022-04-14 2023-04-12 进程间通信方法和电子设备 WO2023198103A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210390253.9 2022-04-14
CN202210390253.9A CN116954936A (zh) 2022-04-14 2022-04-14 进程间通信方法和电子设备

Publications (1)

Publication Number Publication Date
WO2023198103A1 true WO2023198103A1 (zh) 2023-10-19

Family

ID=88328984

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/087802 WO2023198103A1 (zh) 2022-04-14 2023-04-12 进程间通信方法和电子设备

Country Status (2)

Country Link
CN (1) CN116954936A (zh)
WO (1) WO2023198103A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9584620B1 (en) * 2015-12-31 2017-02-28 International Business Machines Corporation Caching in storage clients
CN106547631A (zh) * 2016-09-26 2017-03-29 腾讯科技(深圳)有限公司 基于安卓平台的跨进程通信方法和装置
CN108696551A (zh) * 2017-04-06 2018-10-23 中兴通讯股份有限公司 系统进程间请求寻址的方法和装置
CN113495795A (zh) * 2020-04-03 2021-10-12 华为技术有限公司 一种进程间通信方法及相关设备
CN115061743A (zh) * 2022-06-08 2022-09-16 Oppo广东移动通信有限公司 接口调用方法及装置、计算机可读介质和电子设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9584620B1 (en) * 2015-12-31 2017-02-28 International Business Machines Corporation Caching in storage clients
CN106547631A (zh) * 2016-09-26 2017-03-29 腾讯科技(深圳)有限公司 基于安卓平台的跨进程通信方法和装置
CN108696551A (zh) * 2017-04-06 2018-10-23 中兴通讯股份有限公司 系统进程间请求寻址的方法和装置
CN113495795A (zh) * 2020-04-03 2021-10-12 华为技术有限公司 一种进程间通信方法及相关设备
CN115061743A (zh) * 2022-06-08 2022-09-16 Oppo广东移动通信有限公司 接口调用方法及装置、计算机可读介质和电子设备

Also Published As

Publication number Publication date
CN116954936A (zh) 2023-10-27

Similar Documents

Publication Publication Date Title
US8477143B2 (en) Buffers for display acceleration
EP2245589B1 (en) Multi-context graphics processing
JP5820023B2 (ja) モバイルコンピューティングデバイスを用いた複数のデータソースの検索
US20150128079A1 (en) Method for executing function in response to touch input and electronic device implementing the same
WO2018223558A1 (zh) 数据处理方法及电子设备
WO2021013019A1 (zh) 一种图片处理方法及装置
WO2023226455A1 (zh) 应用图标的显示方法、电子设备及可读存储介质
WO2021110133A1 (zh) 一种控件的操作方法及电子设备
WO2021135578A1 (zh) 页面处理方法、装置、存储介质及终端设备
WO2019128588A1 (zh) 进程处理方法和装置、电子设备、计算机可读存储介质
EP4328705A1 (en) Storage space arrangement method and electronic device
WO2018000300A1 (zh) 一种电子设备的数据操作方法及电子设备
WO2021185352A1 (zh) 一种版本升级方法及相关装置
WO2023051355A1 (zh) 权限检查的方法和电子设备
WO2021244459A1 (zh) 一种输入方法及电子设备
WO2019128542A1 (zh) 应用处理方法、电子设备、计算机可读存储介质
WO2023198103A1 (zh) 进程间通信方法和电子设备
WO2020147859A1 (zh) 分散式重锁降级
WO2019128545A1 (zh) 进程处理方法、电子设备、计算机可读存储介质
WO2023202444A1 (zh) 一种输入方法及装置
WO2024022119A1 (zh) 数据同步方法、电子设备及系统
WO2021114919A1 (zh) 内容获取方法、系统、用户终端及内容服务器
WO2023274125A1 (zh) 一种指令处理方法及其相关设备
EP4322144A1 (en) Display screen brightness adjustment method, electronic device and storage medium
WO2023284625A1 (zh) 应用的跨平台显示方法、可读介质和电子设备

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: 23787746

Country of ref document: EP

Kind code of ref document: A1