Android binder inter-process communication mechanism 2, androidbinder
1. Service Components
The template class BnInterface is used to describe the Binder local object, which corresponds to the Binder object in the Binder driver.
The implementation principle is as follows:
When a Binder proxy object sends an inter-process communication request to the Binder local object through the Binder driver, the Binder calls the transact function of the local object to process the request.
For each Binder thread, it has an IPCThreadState object internally, and calls its transact function to interact with the Binder driver.
2. Clent Components
The template class BpInterface description is called the Binder proxy object, which corresponds to the Binder reference object in the Binder driver.
The implementation principle is as follows:
Do not translate the following English sentences. It is necessary for homework. It is very urgent.
Prepare your binder 2 for your scientific notebook.
Binder is a mechanism for inter-process communication. It is used in Android systems.
Science note book is an open source data set for online scientific research projects.
A short sentence contains too much information, so it is difficult to understand.
Inter-process communication
Four different technologies used for inter-process communication (IPC:
1. message transmission (pipelines, FIFO, posix, and system v message queues)
2. synchronization (mutex lock, condition variable, read/write lock, file and record lock, Posix and System V signal light)
3. Shared Memory zone (anonymous shared memory zone, Posix shared memory zone, and System V shared memory zone)
4. process call (Solaris gate, Sun RPC)
Message queues and process calls are often used independently, that is, they generally provide their own synchronization mechanisms. on the contrary, the shared memory area usually needs some synchronization form provided by the application to work normally. which IPC should be used to solve a specific problem? There is no simple determination. We should gradually familiarize ourselves with the mechanisms provided by various IPC forms, and then compare their features according to the requirements of specific applications.
The following four prerequisites must be taken into account:
1. the Internet is not connected. IPC is applicable to processes or threads on a single host. if applications may be distributed across multiple hosts, you should consider using sockets instead of IPC to simplify the future transfer to networked applications.
2. Portability.
3. Performance: run the test program in a specific development environment to compare the performance differences of several IPC types.
4. Real-time scheduling. If this feature is required and the posix real-time scheduling option is also supported by the system used, use the Posix message transmission and synchronization functions.
Main differences between various IPC types:
1. pipeline and FIFO are byte streams without message boundaries. posix messages and System V messages have record boundaries maintained from the sender to the receiver (eg: TCP is a byte stream without record boundaries, UDP provides messages with record boundaries ).
2. when a message is placed in an empty queue, the Posix Message Queue can send a signal to a process or start a new thread. system V does not provide similar notification forms.
3. pipelines and FIFO data bytes are FIFO. posix messages and System V messages have the priority assigned by the sender. when reading messages from a Posix message queue, messages with the highest priority are first returned. when reading messages from a System V message queue, the reader can require messages of any priority.
4. among the many message passing technologies-pipelines, FIFO, Posix message queues, and System V message queues, functions that can be called from a signal processing program only include read and write (applicable to pipelines and FIFO ).
When comparing different forms of message transmission, we are interested in two measurement scales:
1. bandwidth: the speed at which data is transferred through the IPC channel. to measure this value, we send large amounts of data (Millions of bytes) from one process to another ). we also measure this value for I/O operations of different sizes (such as write and read operations of pipelines and FIFO, we look forward to discovering the law that the bandwidth will increase with the increase of the data volume for each I/O operation.
2. latency: the time it takes for a small IPC message to return from a process to a process. we measure the time (round-trip time) from a process to a process with only one byte message)
In the real world, bandwidth tells us how long it takes to send large pieces of data through an IPC channel. However, IPC is also used to transmit small control information, the time required by the system to process these small messages is provided by delay. both numbers are important.