A message processing method and device, and a storage medium
Patent Information
- Application Number
- CN202211447079.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-18
- Publication Date
- 2026-09-08
- Estimated Expiration
- 2042-11-18
AI Technical Summary
[0004]本申请提供一种消息处理方法、装置及存储介质,用以解决现有消息处理方法在处理高并发计算时能力有限,导致自动驾驶系统处理数据的时延较大的问题
[0006] The first thread includes multiple coroutines, each bound to a state machine. Thus, running the first thread is equivalent to running multiple coroutines, and more tasks can be accomplished by adding coroutines. Because coroutines run on top of threads, switching between coroutines only requires context saving, without system-level creation and destruction. Therefore, adding coroutines does not incur additional system resource overhead.
Smart Images

Figure CN115904750B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of autonomous driving technology, and in particular to a message processing method, apparatus and storage medium. Background Technology
[0002] The autonomous driving system of a vehicle is a distributed real-time system based on multiple chips and processes, incorporating many complex state machine-based algorithms. With the increasing development of autonomous driving assistance functions, such as adaptive cruise control (ACC), automatic emergency braking (AEB), and automated parking assist (APA), simultaneously activating these functions puts the autonomous driving system in a state of high-concurrency computing, processing a large number of perception signals and algorithms, consuming significant system resources.
[0003] Existing message processing methods have limited capabilities when dealing with high-concurrency computing. The increasing number of autonomous driving assistance functions leads to greater latency in data processing by autonomous driving systems, affecting their performance. Summary of the Invention
[0004] This application provides a message processing method, apparatus, and storage medium to solve the problem that existing message processing methods have limited capabilities when handling high-concurrency computing, resulting in large latency in data processing for autonomous driving systems.
[0005] Firstly, this application provides a message processing method. Taking an electronic device with processing capabilities as an example, the method specifically includes: the electronic device responding to a first input event in a message queue, switching from a currently running first coroutine to a second coroutine according to a topological sort. The first and second coroutines belong to a first thread, which includes at least two coroutines, each coroutine corresponding to a state machine, and the topological sort indicates the execution order of the state machines. Then, the electronic device runs the first state machine corresponding to the second coroutine to process the first input event. The first state machine includes multiple states, each state corresponding to a task.
[0006] The first thread includes multiple coroutines, each bound to a state machine. Thus, running the first thread is equivalent to running multiple coroutines, and more tasks can be accomplished by adding coroutines. Because coroutines run on top of threads, switching between coroutines only requires context saving, without system-level creation and destruction. Therefore, adding coroutines does not incur additional system resource overhead.
[0007] Optionally, before switching from the currently running first coroutine to the second coroutine according to the topology sort in response to the first input event in the message queue, the method further includes: the electronic device reading the configuration information of each state machine from the system configuration file and generating the topology sort of each state machine according to the configuration information.
[0008] This application sets the execution order of multiple coroutines, thus fixing the execution order of each state machine. The multiple state machines run according to the set execution order of the coroutines. Compared to the traditional polling method for determining the execution order of multiple state machines, idle state machines do not consume system resources, reducing system resource overhead. Therefore, compared to the traditional method of binding one thread to one state machine, this application can process more tasks in parallel, improving the efficiency of multi-task parallel processing.
[0009] Optionally, in response to a first input event in the message queue, the electronic device switches from the currently running first coroutine to the second coroutine according to topology order. Specifically, this includes: the electronic device determining a first state machine corresponding to the first input event based on a first configuration relationship, whereby the first configuration relationship indicates the correspondence between multiple events and multiple state machines. Then, the electronic device determines a second coroutine corresponding to the first state machine based on a second configuration relationship, whereby the second configuration relationship indicates the correspondence between multiple state machines and multiple coroutines. Afterward, the electronic device switches from the first coroutine to the second coroutine according to topology order.
[0010] Optionally, the first input event includes the storage address of the first input data. The first state machine corresponding to the second coroutine processes the first input event, including: the electronic device receiving the storage address of the first input data and retrieving the first input data from shared memory based on that storage address. The shared memory is used to store input data that triggers the operation of each state machine. Then, the electronic device runs the first state machine corresponding to the second coroutine to process the first input data. If it is determined that the processing result of the first input data meets a preset condition, the state of the first input data is switched.
[0011] Storing the first input data in shared memory and transferring it via shared memory eliminates the need for copying input data, thus reducing system load.
[0012] Optionally, the storage address is a pointer variable corresponding to the storage area that stores the first input data.
[0013] Optionally, before switching from the currently running first coroutine to the second coroutine according to the topology order in response to the first input event in the message queue, the method further includes: the electronic device receiving first input data sent by the data bus and determining whether the first input data is normal. If the first input data is normal, the electronic device then determines whether the first input data has changed. If the first input data has changed, the electronic device stores the first input data in shared memory and sends the identifier of the first input data to the message queue. Optionally, the method further includes: if the first input data is abnormal, outputting indication information and sending a prompt message to the message queue, the indication information being used to prompt the first state machine to terminate processing the first input event.
[0014] Secondly, this application provides a message processing apparatus. The apparatus includes a switching module and a processing module. The switching module, in response to a first input event in a message queue, switches from a currently running first coroutine to a second coroutine according to a topological order. The first and second coroutines belong to a first thread, which includes at least two coroutines, each corresponding to a state machine. The topological order indicates the execution order of the state machines. The processing module runs the first state machine corresponding to the second coroutine to process the first input event. The first state machine includes multiple states, each state corresponding to a task.
[0015] Optionally, the switching module is also used to: read the configuration information of each state machine from the system configuration file, and generate the topology sorting of each state machine based on the configuration information.
[0016] Optionally, the switching module is specifically configured to: determine a first state machine corresponding to the first input event based on a first configuration relationship, wherein the first configuration relationship indicates the correspondence between multiple events and multiple state machines; then, determine a second coroutine corresponding to the first state machine based on a second configuration relationship, wherein the second configuration relationship indicates the correspondence between multiple state machines and multiple coroutines; and finally, switch from the first coroutine to the second coroutine according to topological sorting.
[0017] Optionally, the processing module is specifically used to: receive the storage address of the first input data, and retrieve the first input data from the shared memory according to the storage address. The shared memory is used to store the input data that triggers the operation of each state machine. Then, the first state machine corresponding to the second coroutine is run to process the first input data. If it is determined that the processing result of the first input data meets the preset conditions, the state of the first input data is switched.
[0018] Optionally, the storage address is a pointer variable corresponding to the storage area that stores the first input data.
[0019] Optionally, the switching module is also configured to: receive first input data sent by the data bus, and determine whether the first input data is normal. If the first input data is normal, then determine whether the first input data has changed. If the first input data has changed, store the first input data in shared memory, and send the identifier of the first input data to the message queue.
[0020] Optionally, the switching module is also used to: if the first input data is abnormal, output indication information and send the prompt information to the message queue, the indication information being used to prompt the first state machine to terminate the processing of the first input event.
[0021] Thirdly, embodiments of this application provide an electronic device including a processor and a memory communicatively connected to the processor. The memory stores computer-executable instructions, which are executed by the processor to enable the processor to perform the method described in any one of the first aspects above.
[0022] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, cause the processor to perform the method described in any one of the first aspects.
[0023] Fifthly, embodiments of this application provide a computer program product, which includes a computer program stored in a computer-readable storage medium. A processor can read the computer program from the computer-readable storage medium, and when the processor executes the computer program, it can implement the method described in any one of the first aspects above. Attached Figure Description
[0024] Figure 1 This is a schematic diagram illustrating an application scenario of the automatic lane-changing function provided in the embodiments of this application;
[0025] Figure 2 A schematic diagram of the state machine polling mechanism provided in the embodiments of this application;
[0026] Figure 3 A flowchart illustrating the message queue processing method provided in this application embodiment;
[0027] Figure 4 A schematic diagram of the architecture of multiple coroutines in a thread provided in an embodiment of this application;
[0028] Figure 5 This is a schematic diagram of the architecture of an autonomous driving system provided in an embodiment of this application;
[0029] Figure 6 This is a schematic diagram of the structure of the message processing apparatus provided in the embodiments of this application;
[0030] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0031] To better understand the solutions provided by the embodiments of the present invention, some technical concepts involved in the embodiments of the present invention will be introduced first.
[0032] 1) A thread, contained within a process, is the smallest unit of computational scheduling by the operating system. A process can contain multiple threads, and a thread can be understood as a single, sequential flow of control within a process. The creation and destruction of threads are handled by the operating system through the allocation of system resources. Furthermore, the operating system can control the switching between multiple threads.
[0033] 2) Coroutines run on top of threads, and multiple coroutines can run on a single thread through time-sharing multiplexing. Therefore, increasing the number of coroutines does not affect the thread's execution time. Switching between multiple coroutines does not require the system to allocate system resources for coroutine creation and destruction, thus avoiding additional system resource overhead. Furthermore, by flexibly setting the execution parameters of multiple coroutines running on a single thread, such as the number of coroutines, their execution order, and execution time, the actual requirements of the task can be met. For example, automatic parking involves multiple tasks, each implemented through multiple coroutines, and the execution parameters of these coroutines can be set according to the actual needs of automatic parking.
[0034] 3) A state machine is an abstraction of the operating rules of a real-world system. It is a mathematical model that can be used to design algorithms. A state machine receives a series of inputs and, through internal processing, transitions its system state and generates a certain output. A state machine system can be described by a directed graph, where the vertices of the directed graph are the states of the state machine system, and the edges of the directed graph are the inputs required for the state machine system to transition from one state to another, and the generated outputs.
[0035] A "state" is a position in a state machine system where the system is stable and awaits input for a state transition. A state transition occurs when the state the system is waiting for is satisfied or the awaited event has occurred, triggering a series of actions.
[0036] A state machine system contains a set of states, of which one and only one is the initial state, also referred to as the starting state. The state machine system also contains a set of input symbols and a transition function to move from the current state to the next state. When the system starts, it is in the initial state. When the system receives a specific set of inputs, it will transition to the next state.
[0037] 4) A message queue is a container for storing messages. It acts as an intermediary between the message sender and receiver. When a message sent by the sender cannot reach the receiver immediately, it is stored in the message queue until it is determined that the message can be sent to the receiver. Similarly, for the message receiver, if the message queue does not contain the message the receiver needs, the receiver can remain silent. Because message queues do not need to wait for message transmission, they can reduce latency during data transmission.
[0038] 5) Shared memory is a mechanism for inter-process communication. All processes using the same shared memory can access the addresses within that shared memory. Any process writing data to a segment of shared memory will be visible to other processes that have access to that segment. Using shared memory can reduce memory consumption during large-scale data processing and lower system load.
[0039] Understandably, autonomous driving systems integrate a range of driver assistance functions, including adaptive cruise control, lane keeping assist, and automatic lane changing. When these functions are activated while the vehicle is in motion, the autonomous driving system may execute multiple tasks in parallel. Furthermore, a task may have multiple operating states (hereinafter referred to as states), and the implementation of this task involves switching between these states. These state transitions can be implemented using a state machine system. It should be understood that a state machine receives a series of inputs, processes them internally, causes state transitions, and generates specific outputs. When multiple tasks are executed in parallel, multiple state machines operate concurrently, resulting in a high load on the autonomous driving system.
[0040] by Figure 1 Taking the scenario shown as an example, when the vehicle is traveling in the middle lane of the road, adaptive cruise control, automatic lane change, and lane keeping assist are activated. Taking automatic lane change as an example, selectable states include: lane keeping, left lane change, right lane change, acceleration, and deceleration. When the vehicle detects that a right lane change is required ahead based on the preset driving path, it continuously acquires vehicle operating status information and traffic information such as road conditions, pedestrians, and other vehicles in the driving environment through vehicle sensors to determine that it is currently in lane keeping mode. Then, when the vehicle reaches the preset lane change location according to the driving path, the operating status information changes, and the autonomous driving system sends the data of the changed operating status to the state machine. The state machine processes the changed data, switches the state of the data, and instructs the autonomous driving system to run the corresponding algorithm to control the vehicle to perform the right lane change operation.
[0041] The above scenario uses the automatic lane-changing function of an autonomous driving system as an example. It's understandable that autonomous driving systems need to implement many more functions, such as automatic parking. Each function can be viewed as a task, and a function may include multiple sub-tasks. Therefore, autonomous driving systems need to execute multiple tasks in parallel, using state machines to switch between the various working states involved in each task. Currently, autonomous driving systems use a single time slice with high-cycle polling of each state machine to achieve parallel execution of multiple tasks. This means that even idle state machines consume system resources for computation, resulting in significant data processing latency and impacting the execution efficiency of the autonomous driving system.
[0042] Please see Figure 2 This illustrates how the state machine in a traditional autonomous driving system is executed. Figure 2 Taking an autonomous driving system as an example, it includes an APA state machine adapted to the APA function, an AEB state machine adapted to the AEB function, and other state machines. Figure 2 Taking time slices T0-T6 as an example, the autonomous driving system follows a polling sequence from T0 to T6. In each polling time slice, the system detects an input event, starting with the APA state machine and polling sequentially through the AEB state machine and other state machines to determine which state machine was triggered by the input event. Since the autonomous driving system needs to poll each state machine, each state machine needs to operate normally. This means that even idle state machines consume system resources, affecting data processing efficiency.
[0043] To address this, this application provides a message processing method. In this method, state machines are bound to coroutines, and more tasks can be implemented by adding coroutines. Since coroutines run on top of threads, switching between coroutines only requires context saving and does not require system-level creation and destruction; therefore, adding coroutines does not incur additional system resource overhead. Thus, compared to the traditional method of binding one thread to one state machine, this application embodiment can process more tasks in parallel, improving the efficiency of multi-task parallel processing. Furthermore, this application embodiment can also set the execution order of multiple coroutines, making the execution order of each state machine fixed, and multiple state machines run according to the set execution order of the multiple coroutines. Compared to the traditional polling method for determining the execution order of multiple state machines, idle state machines do not consume system resources, reducing system resource overhead.
[0044] Please see Figure 3This diagram illustrates a flowchart of the message processing method provided in an embodiment of this application. This method can be executed by an electronic device with processing capabilities, such as a system-on-chip (SoC) in an autonomous driving system. Of course, the type of electronic device in this embodiment is not limited to an SoC in an autonomous driving system; it can also be other electronic devices in an autonomous driving system. In the following description, the method is described as being executed by an electronic device. In the following description, a first coroutine is used as an example. This first coroutine is bound to a first state machine to implement a first task. This first state machine involves multiple states. When a state changes, the first state machine runs, switching states; when a state does not change, the state of the first state machine remains unchanged. Whether a state change occurs can be determined based on the data to be processed. For ease of description, the data to be processed will be referred to as the first input data in the following description.
[0045] S301. The electronic device receives the first input data sent by the data bus and sends the identifier of the first input data to the message queue.
[0046] The first input data can be data representing vehicle status information. For example, the first input data can be data indicating the vehicle's lane or data representing the vehicle's speed. The first input data can be acquired through vehicle body sensors and sent to electronic devices via a data bus. Of course, the first input data can also be sent to electronic devices through other means besides the data bus, which will not be detailed here. The first input data is sent to electronic devices via the data bus, and correspondingly, the electronic devices receive the first input data sent by the data bus.
[0047] The electronic device receives the first input data sent by the data bus and determines whether the first input data is normal. Normal first input data means that there were no format errors or data loss during transmission. If the first input data is normal, the electronic device continues to determine whether the first input data has changed. A change in the first input data means whether the currently received first input data has changed compared to previously received input data. If it has changed, it indicates that the state corresponding to the first input data has changed. The electronic device determines the operation of the first state machine based on whether the first input data has changed. If the first input data has not changed, it can be assumed that the state corresponding to the first input data has not changed, and the first state machine maintains its state. If the first input data has changed, it can be assumed that the state corresponding to the first input data has changed, and the first state machine performs a state transition.
[0048] This application involves multiple tasks and requires processing a large amount of data. To minimize latency and prevent data loss, this application employs a message queue mechanism. The data to be processed is stored as messages in the queue. For example, an electronic device can add an identifier to the first input data that has changed and send this identifier as a message to the message queue. A change in the first input data is an event that triggers the state machine. Since this application uses a message queue, the electronic device adding an identifier to the first input data can be understood as an input event (e.g., called the first input event) for the first state machine. Thus, the execution of the first state machine is triggered based on the identifier of the first input data in the message queue. When the identifier of the first input data does not exist in the message queue, the first state machine can be in a silent state to reduce system load. When the identifier of the first input data exists in the message queue, the first state machine starts running based on the identifier of the first input data, which can reduce the latency of input data transmission. In addition, the FIFO depth of the message queue can be freely configured to prevent input data loss when there is a large amount of input data in the system.
[0049] When the electronic device sends the identifier of the first input data to the message queue, it also stores the first input data in shared memory. Based on the characteristics of shared memory, subsequent electronic devices only need to retrieve the first input data from shared memory according to the identifier in the message queue, omitting the first input data copying process and reducing system resource overhead. Understandably, if the electronic device determines that the first input data is abnormal during the above process, it sends an indication message to the message queue to prompt the first state machine to terminate processing the first input event. The first state machine retrieves this indication message from the message queue, considers the first input data abnormal, and will not read the first input data from shared memory, thus not processing the first input data.
[0050] S302. The electronic device responds to a first input event in the message queue and switches from the currently running first coroutine to a second coroutine according to the topology order. The first coroutine and the second coroutine belong to the first thread. The first thread includes at least two coroutines. Each coroutine in the at least two coroutines corresponds to a state machine. The topology order indicates the execution order of each state machine.
[0051] The first coroutine is the currently running coroutine, and the first input event triggers the execution of the second coroutine. When the electronic device detects the presence of the first input event in the message queue, it switches from the first coroutine to the second coroutine to handle the first input event. The first and second coroutines belong to the same thread (e.g., referred to as the first thread). Each coroutine is bound to a state machine. Figure 4The diagram illustrates the binding of coroutines to state machines. Taking thread 1 as the first thread, thread 1 is associated with coroutines 1 through 4. Coroutine 1 is bound to state machine 1, coroutine 2 to state machine 2, coroutine 3 to state machine 3, and coroutine 4 to state machine 4. For multiple coroutines, the correspondence between multiple coroutines and multiple state machines can be pre-configured and stored, for example, a second configuration relationship. Since coroutines run on top of threads, switching between coroutines only requires context saving, without system-level creation and destruction, making the electronic device's processing efficiency for first input events higher.
[0052] An input event triggers a state machine; each state machine has its own corresponding input event. Multiple events can be pre-configured to correspond to multiple state machines, for example, a first configuration relationship. Thus, when an electronic device responds to a first input event and switches from a first coroutine to a second coroutine, the first state machine corresponding to the first input event can be determined based on the first configuration relationship, and then the second coroutine corresponding to the first state machine can be determined based on the second configuration relationship.
[0053] This application involves multiple tasks, which means multiple state machines. If the state machines are polled, even idle state machines consume system resources. Therefore, this application can set the execution order of multiple state machines (or coroutines), making the execution order of each state machine fixed, and the multiple state machines run according to the set execution order. This avoids the situation where one coroutine takes too long to execute, causing other coroutines to wait. Compared to the traditional polling method for determining the execution order of multiple state machines, idle state machines do not consume system resources, reducing system resource overhead and latency.
[0054] Before responding to the first input event in the message queue, the electronic device reads configuration information for each state machine from the system configuration file. This configuration information includes information for configuring the execution order of the state machines, allowing the electronic device to generate a topological ordering of the state machines based on their configuration information. For example, see [link to relevant documentation]. Figure 4 This illustrates the topological ordering of multiple coroutines in thread 2. For example... Figure 4 As shown, coroutines 6 and 7 run after coroutine 5, and coroutine 8 runs after either coroutine 6 or coroutine 7. Afterward, the electronic device switches from the currently running first coroutine to the second coroutine according to this topology order.
[0055] S303. The electronic device runs the first state machine corresponding to the second coroutine to process the first input event. The first state machine includes multiple states, and each state corresponds to a task.
[0056] In this embodiment, the electronic device responds to a first input event, acquires first input data, and then runs a first state machine corresponding to a second coroutine to process the first input data. Specifically, the electronic device can acquire the first input data from shared memory based on the identifier of the first input data included in the first input event. For example, the identifier of the first input data can be the storage address of the first input data. Optionally, the storage address of the first input data can be a pointer variable corresponding to the storage area storing the first input data. After the first state machine processes the first input data, if the processing result of the first input data meets a preset condition, the state of the first input data is switched. If the processing result of the first input data meets the preset condition, the state of the first input data is maintained.
[0057] Based on the same inventive concept, embodiments of this application also provide an architecture for an autonomous driving system. For example... Figure 5 As shown, the architecture includes a System-on-a-Chip (SOC) and a Microcontroller Unit (MCU). The SOC can be used to execute the message processing provided in the embodiments of this application. The SOC is functionally divided in a similar manner. The functionally divided SOC includes a message queue processing module 501, a state machine module 502, and an algorithm module 503. The MCU includes a bus data transceiver module 504 for receiving data sent by vehicle body sensors. In the divided SOC, the message queue processing module 501 receives first input data sent by the MCU's bus data transceiver module and sends the identifier of the first input data to the message queue. The state machine module 502 responds to the first input event in the message queue, switches from the currently running first coroutine to a second coroutine according to the topology order, and processes the first input event by running the first state corresponding to the second coroutine. The algorithm module 503 receives the processing result from the state machine module 502 and runs the algorithm.
[0058] Please see Figure 6 Based on the same inventive concept, this application also provides a message processing device 600. The device includes a switching module 601 and a processing module 602. The switching module 601, in response to a first input event in the message queue, switches from a currently running first coroutine to a second coroutine according to topological ordering. The first and second coroutines belong to a first thread, which includes at least two coroutines. Each coroutine corresponds to a state machine, and the topological ordering indicates the execution order of the state machines. The processing module 602 runs the first state machine corresponding to the second coroutine to process the first input event. The first state machine includes multiple states, each state corresponding to a task.
[0059] Optionally, the switching module 601 is also used to: read the configuration information of each state machine from the system configuration file, and generate the topology sorting of each state machine according to the configuration information.
[0060] Optionally, the switching module 601 is specifically configured to: determine a first state machine corresponding to the first input event based on a first configuration relationship, wherein the first configuration relationship indicates the correspondence between multiple events and multiple state machines; then, determine a second coroutine corresponding to the first state machine based on a second configuration relationship, wherein the second configuration relationship indicates the correspondence between multiple state machines and multiple coroutines; and finally, switch from the first coroutine to the second coroutine according to topological sorting.
[0061] Optionally, the processing module 602 is specifically used to: receive the storage address of the first input data, and retrieve the first input data from the shared memory according to the storage address, wherein the shared memory is used to store the input data that triggers the operation of each state machine. Then, the first state machine corresponding to the second coroutine is run to process the first input data, and if it is determined that the processing result of the first input data meets the preset conditions, the state of the first input data is switched.
[0062] Optionally, the storage address is a pointer variable corresponding to the storage area that stores the first input data.
[0063] Optionally, the switching module 601 is further configured to: receive first input data sent by the data bus, and determine whether the first input data is normal. If the first input data is normal, then determine whether the first input data has changed. If the first input data has changed, store the first input data in shared memory, and send the identifier of the first input data to the message queue.
[0064] Optionally, the switching module 601 is further configured to: if the first input data is abnormal, output indication information and send the prompt information to the message queue, wherein the indication information is used to prompt the first state machine to terminate the processing of the first input event.
[0065] Based on the same inventive concept, embodiments of this application provide an electronic device including at least one processor 701 and a memory 702 communicatively connected to the at least one processor. The memory stores instructions executable by the at least one processor to enable the at least one processor to perform the methods described in any of the above embodiments.
[0066] In this embodiment, the specific connection medium between the processor 701 and the memory 702 is not limited. Figure 7 Taking the connection between processor 701 and memory 702 via bus 700 as an example, bus 700 in... Figure 7The connections between other components are indicated by thick lines and are for illustrative purposes only, not as limiting information. The 700 bus can be divided into address bus, data bus, control bus, etc., for ease of representation. Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0067] The computing device in this application embodiment may also include a communication interface 703, such as a network port, through which the computing device can receive or send data.
[0068] The processor 701 serves as the control center of the computing device. It connects to various parts of the device via various interfaces and lines, executing instructions stored in the memory 702 and accessing data stored in the memory 702 to perform various functions and process data, thereby providing overall monitoring of the computing device. Optionally, the processor 701 may include one or more processing units. The processor 701 may integrate an application processor and a modem processor. The application processor primarily handles the operating system and applications, while the modem processor primarily handles wireless communication. It is understood that the modem processor may not be integrated into the processor 701. In some embodiments, the processor 701 and the memory 702 may be implemented on the same chip; in other embodiments, they may be implemented on separate chips.
[0069] Optionally, the processor 701 may be a general-purpose processor, such as a central processing unit, an application-specific integrated circuit (ASIC), one or more integrated circuits for controlling program execution, hardware circuits developed using a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the message processing method disclosed in the embodiments of this application can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.
[0070] By designing and programming the processor 701, the code corresponding to the message processing method described in the foregoing embodiments can be embedded into the chip, so that the chip can execute the steps of the aforementioned message processing method when running. How to design and program the processor 701 is a well-known technique to those skilled in the art, and will not be described in detail here.
[0071] Optionally, in this embodiment, the memory 702 stores instructions executable by at least one processor 701. The at least one processor 701 can execute the steps included in the aforementioned message processing method by executing the instructions stored in the memory 702. The memory 702, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The memory 702 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic memory, magnetic disk, optical disk, etc. The memory 702 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. The memory 702 in this embodiment can also be a circuit or any other device capable of performing storage functions, used to store program instructions and / or data. The number of memories 702 can be one or more. The memory 702 is used in... Figure 7 It is shown together, but it should be noted that the memory 702 is not a mandatory functional module, therefore in Figure 7 It is shown in dashed lines.
[0072] Based on the same inventive concept, embodiments of this application provide a computer storage medium storing computer program instructions for executing the methods in any of the above embodiments. In specific implementations, the computer-readable storage medium includes various storage media capable of storing program code, such as a Universal Serial Bus flash drive (USB), a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0073] In some possible implementations, various aspects of the message processing method provided in this application may also be implemented as a program product comprising program code that, when the program product is run on a computing device, causes the computing device to perform the steps of the message processing method according to the various exemplary embodiments of this application described above.
[0074] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0075] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0076] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0077] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0078] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: Universal Serial Bus flash disks, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0079] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A message processing method, characterized in that, include: In response to a first input event in the message queue, the system switches from the currently running first coroutine to the second coroutine according to the topology order. The first coroutine and the second coroutine belong to the first thread, which includes at least two coroutines. Each of the at least two coroutines corresponds to a state machine, and the topology order indicates the execution order of the state machines. The first state machine corresponding to the second coroutine is run to process the first input event. The first state machine includes multiple states, and each state corresponds to a task. The process of switching from the currently running first coroutine to the second coroutine in response to the first input event in the message queue, based on topology order, includes: Based on the first configuration relationship, a first state machine corresponding to the first input event is determined, wherein the first configuration relationship is used to indicate the correspondence between multiple events and multiple state machines; Based on the second configuration relationship, the second coroutine corresponding to the first state machine is determined. The second configuration relationship is used to indicate the correspondence between multiple state machines and multiple coroutines. Switch from the first coroutine to the second coroutine according to the topology sorting; Before switching from the currently running first coroutine to the second coroutine according to topology order in response to the first input event in the message queue, the method further includes: Receive the first input data sent by the data bus and determine whether the first input data is normal; If the first input data is normal, determine whether the first input data has changed; If the first input data changes, the first input data is stored in shared memory, and the identifier of the first input data is sent to the message queue.
2. The method as described in claim 1, characterized in that, Before switching from the currently running first coroutine to the second coroutine according to topology order in response to the first input event in the message queue, the method further includes: Read the configuration information of each state machine from the system configuration file; The topological order of each state machine is generated based on the configuration information.
3. The method as described in claim 2, characterized in that, The first input event includes the storage address of the first input data. The first state machine corresponding to the second coroutine processes the first input event, including: The storage address of the first input data is received, and the first input data is obtained from the shared memory according to the storage address. The shared memory is used to store the input data that triggers the operation of each state machine. The first state machine corresponding to the second coroutine is run to process the first input data; If it is determined that the processing result of the first input data meets the preset conditions, the state of the first input data is switched.
4. The method as described in claim 3, characterized in that, The storage address is a pointer variable corresponding to the storage area where the first input data is stored.
5. The method as described in claim 3, characterized in that, The method further includes: If the first input data is abnormal, an indication message is output, which is used to prompt the first state machine to terminate the processing of the first input event.
6. A message processing device, characterized in that, include: A switching module is used to switch from a currently running first coroutine to a second coroutine according to a topological sorting in response to a first input event in a message queue. The first coroutine and the second coroutine belong to a first thread, which includes at least two coroutines. Each coroutine in the at least two coroutines corresponds to a state machine, and the topological sorting indicates the execution order of each state machine. The processing module is used to run the first state machine corresponding to the second coroutine to process the first input event, wherein the first state machine includes multiple states, and one state corresponds to one task; The process of switching from the currently running first coroutine to the second coroutine in response to the first input event in the message queue, based on topology order, includes: Based on the first configuration relationship, a first state machine corresponding to the first input event is determined, wherein the first configuration relationship is used to indicate the correspondence between multiple events and multiple state machines; Based on the second configuration relationship, the second coroutine corresponding to the first state machine is determined. The second configuration relationship is used to indicate the correspondence between multiple state machines and multiple coroutines. Switch from the first coroutine to the second coroutine according to the topology sorting; The message processing device is further configured to: receive first input data sent by the data bus in response to a first input event in the message queue and before switching from the currently running first coroutine to the second coroutine according to the topology sorting; determine whether the first input data is normal; if the first input data is normal, determine whether the first input data has changed; if the first input data has changed, store the first input data in shared memory and send the identifier of the first input data to the message queue.
7. The apparatus as claimed in claim 6, characterized in that, The switching module is also used for: Read the configuration information of each state machine from the system configuration file; The topological order of each state machine is generated based on the configuration information.
8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-5.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Cloud edge collaborative video analysis system and method based on server-free function calculation
CN113992941A
Robot control method, control cabinet and system
CN114310879A