Thread signal processing method, device and equipment of embedded system, and storage medium
By freezing the logical context of the target thread in the embedded system and generating a new logical context to handle soft interrupt signals, the problem of low reliability caused by the soft interrupt signal handling logic not being executed in the target thread in the embedded real-time operating system is solved, and higher security and reliability are achieved.
Patent Information
- Application Number
- CN202510225791.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-02-27
AI Technical Summary
In existing embedded real-time operating systems, the signal processing logic for soft interrupt signals is not executed in the target thread, resulting in low operational reliability and security risks and resource access permission issues.
By receiving a soft interrupt signal, the target thread is identified and its state is detected. When the target thread is currently executing user logic, its logical context is frozen. The soft interrupt signal is attached to the list of signals to be processed, a new logical context is generated, and the target thread is unfrozen so that signal processing logic can be executed in the target thread.
It improves the security of thread signal handling mechanisms, avoids the problem of the execution privilege of soft interrupt signal handling logic being higher than that of the target thread, and enhances the operational reliability of embedded real-time operating systems.
Smart Images

Figure CN120216120B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of signal processing, and in particular, to a thread signal processing method and device for an embedded system, an embedded system equipment and a storage medium. BACKGROUND
[0002] An embedded real-time operating system is a software system specially designed for processing specific time-constrained tasks, ensuring that tasks are completed within a specified time to meet strict real-time requirements. Embedded real-time operating systems have been widely used in military, industry, medical, communication and financial fields.
[0003] The existing embedded real-time operating system usually uses threads to process signals. In general cases, a thread focuses on executing its own code logic, but in some cases, the thread needs to be notified that an asynchronous event has occurred. The way to notify the thread that an asynchronous event has occurred is to send a soft interrupt signal. After a certain event occurs, a soft interrupt signal needs to be sent to the target thread, and the target thread needs to stop executing the current code and execute the signal processing logic of the received soft interrupt signal. The existing signal processing mechanism usually directly executes the signal processing logic of the soft interrupt signal in the thread scheduler, or opens a new thread to execute the signal processing logic of the soft interrupt signal, so that the signal processing logic of the soft interrupt signal is not executed in the target thread, which may cause the execution privilege of the signal processing logic of the soft interrupt signal to be higher than the privilege of the target thread, so that the signal processing logic of the soft interrupt signal can access and modify more system resources, or may perform some unsafe operations, increasing the security risk, thus resulting in low running reliability of the embedded real-time operating system. SUMMARY
[0004] Embodiments of the present application provide a thread signal processing method and device for an embedded system, an embedded system equipment and a storage medium, which can solve the technical problem of low running reliability of the embedded real-time operating system caused by the signal processing logic of the soft interrupt signal not being executed in the target thread, improve the security of the thread signal processing mechanism, and thus improve the running reliability of the embedded real-time operating system.
[0005] In a first aspect, embodiments of the present application provide a thread signal processing method for an embedded system, comprising:
[0006] receiving a soft interrupt signal and determining a target thread according to the soft interrupt signal;
[0007] detecting the current state of the target thread;
[0008] when the current state of the target thread is a state of executing user logic, freezing the target thread to save the initial logical context of the target thread;
[0009] mount the soft interrupt signal to a pending signal list of the target thread, and generate a new logical context according to the soft interrupt signal and the initial logical context;
[0010] unfreeze the target thread, and execute a signal handling logic of the target thread according to the new logical context and the pending signal list to complete a task corresponding to the soft interrupt signal.
[0011] In an embodiment, the mounting the soft interrupt signal to the pending signal list of the target thread, and the generating the new logical context according to the soft interrupt signal and the initial logical context, comprise:
[0012] mounting the soft interrupt signal to a pending signal list of the target thread;
[0013] determining a target privilege level of the target thread according to the initial logical context;
[0014] generating the new logical context according to the target privilege level and the soft interrupt signal.
[0015] In an embodiment, after detecting the current state of the target thread, the method further comprises:
[0016] freezing the target thread to save an initial logical context of the target thread when the current state of the target thread is a state of executing a signal handling logic;
[0017] mounting the soft interrupt signal to a pending signal list of the target thread;
[0018] unfreezing the target thread to resume the signal handling logic being executed by the target thread;
[0019] executing a subsequent signal handling logic of the target thread according to the initial logical context and the pending signal list to complete a task corresponding to the soft interrupt signal.
[0020] In an embodiment, the freezing the target thread when the current state of the target thread is the state of executing the signal handling logic, comprises:
[0021] freezing the target thread to save an initial logical context of the target thread and setting an initial stack pointer when the current state of the target thread is the state of executing the signal handling logic;
[0022] unfreezing the target thread to resume the signal handling logic being executed by the target thread, comprises:
[0023] unfreezing the target thread to resume the signal handling logic being executed by the target thread according to the initial stack pointer.
[0024] In an embodiment, the unfreezing the target thread to resume the signal handling logic being executed by the target thread, comprises:
[0025] When the signal processing logic being executed is API exit processing logic, unfreeze the target thread and resume the API exit processing logic being executed by the target thread;
[0026] Based on the initial logical context and the linked list of signals to be processed, the target thread executes its subsequent signal processing logic, including:
[0027] After the API exit processing logic is completed, the target thread's subsequent signal processing logic is executed according to the initial logic context and the pending signal list to complete the task corresponding to the soft interrupt signal.
[0028] In one embodiment, after detecting the current state of the target thread, the process includes:
[0029] When the target thread is currently executing a system API, freeze the target thread to preserve its initial logical context.
[0030] The soft interrupt signal is attached to the pending signal list of the target thread;
[0031] If the target thread is blocked, interrupt the blocking of the target thread;
[0032] Unfreeze the target thread and resume the system APIs that the target thread is currently executing;
[0033] When the system API exits, the target thread executes the subsequent signal processing logic based on the initial logical context and the list of signals to be processed, in order to complete the task corresponding to the soft interrupt signal.
[0034] In one embodiment, interrupting the blocking of the target thread when it is blocked includes:
[0035] Detect the current state of the target thread; if the current state is a waiting state, determine that the target thread is blocked.
[0036] Interrupt the blocking of the target thread and change the current state of the target thread to the running state.
[0037] In a second aspect, embodiments of this application provide a thread signal processing apparatus for an embedded system, comprising:
[0038] The signal receiving module is used to receive software interrupt signals and determine the target thread based on the software interrupt signals.
[0039] The state detection module is used to detect the current state of the target thread;
[0040] The first freeze module is used to freeze the target thread when the current state of the target thread is executing user logic, so as to save the initial logical context of the target thread.
[0041] The first processing module is configured to mount the soft interrupt signal to a pending signal linked list of the target thread, and generate a new logical context according to the soft interrupt signal and the initial logical context;
[0042] The first unfreezing module is configured to unfreeze the target thread, and execute a signal processing logic of the target thread according to the new logical context and the pending signal linked list, so as to complete a task corresponding to the soft interrupt signal.
[0043] In a third aspect, an embodiment of the present application provides a thread signal processing device of an embedded system, comprising:
[0044] a memory and one or more processors;
[0045] the memory is configured to store one or more programs;
[0046] When the one or more programs are executed by the one or more processors, the one or more processors implement the thread signal processing method of the embedded system as in the first aspect.
[0047] In a fourth aspect, an embodiment of the present application provides a storage medium storing computer executable instructions, which when executed by a computer processor, are used to execute the thread signal processing method of the embedded system as in the first aspect.
[0048] The embodiment of the present application determines the target thread according to the received soft interrupt signal when processing the thread signal, detects the current state of the target thread, freezes the target thread when the current state of the target thread is the state of executing user logic, saves the initial logical context of the target thread, mounts the soft interrupt signal to the pending signal linked list of the target thread, generates a new logical context according to the soft interrupt signal and the initial logical context, unfreezes the target thread, and executes the signal processing logic of the target thread according to the new logical context and the pending signal linked list, so as to complete the task corresponding to the soft interrupt signal. By using the above technical means, the signal processing logic of the soft interrupt signal can be executed in the target thread, so that the technical problem that the running reliability of the embedded real-time operating system is low due to the fact that the signal processing logic of the soft interrupt signal is not executed in the target thread can be avoided. In the embodiment, the target thread is frozen and the initial logical context is saved when the current state of the target thread is the state of executing user logic, the soft interrupt signal is mounted to the pending signal linked list of the target thread, and the new logical context is generated according to the soft interrupt signal and the initial logical context, so that the signal processing logic of the target thread can be executed according to the new logical context and the pending signal linked list after the target thread is unfreezed, the signal processing logic corresponding to the soft interrupt signal is inserted in the target thread, the signal processing logic of the soft interrupt signal can be completed in the target thread, the privilege of the execution of the signal processing logic of the soft interrupt signal is lower than the privilege of the target thread, the safety of the thread signal processing mechanism is improved, and the running reliability of the embedded real-time operating system is further improved.
[0049] The beneficial effects of the thread signal processing apparatus of the embedded system, the thread signal processing device of the embedded system and the storage medium provided above can refer to the beneficial effects of the thread signal processing method of the embedded system. BRIEF DESCRIPTION OF DRAWINGS
[0050] Figure 1 is a flowchart of a thread signal processing method of an embedded system provided by the embodiment of the present application;
[0051] Figure 2 is a flowchart of another thread signal processing method of an embedded system provided by the embodiment of the present application;
[0052] Figure 3 is a flowchart of still another thread signal processing method of an embedded system provided by the embodiment of the present application;
[0053] Figure 4 is a structural schematic diagram of a thread signal processing apparatus of an embedded system provided by the embodiment of the present application;
[0054] Figure 5 is a structural schematic diagram of a thread signal processing device of an embedded system provided by the embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purposes, technical solutions and advantages of the present application clearer, the following further describes specific embodiments of the present application with reference to the accompanying drawings. It can be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application. In addition, it should be noted that, for the convenience of description, only parts related to the present application are shown in the drawings, but not all. Before discussing the example embodiments in more detail, it should be mentioned that some example embodiments are described as processes or methods depicted as flowcharts. Although the flowcharts describe the operations (or steps) as sequential processes, many of the operations can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The processes can be terminated when the operations are completed, but can also have additional steps not included in the drawings. The processes can correspond to methods, functions, procedures, subroutines, etc.
[0056] The existing embedded real-time operating system usually uses threads for signal processing. In general cases, a thread focuses on executing its own code logic, but in some cases, the thread needs to be notified that an asynchronous event has occurred. The way to notify the thread that an asynchronous event has occurred is to send a soft interrupt signal. After an event occurs, a soft interrupt signal needs to be sent to the target thread, and the target thread needs to stop executing the current code and execute the signal processing logic of the received soft interrupt signal instead. The existing signal processing mechanism usually directly executes the signal processing logic of the soft interrupt signal in the thread scheduler, or newly opens a thread to execute the signal processing logic of the soft interrupt signal, so that the signal processing logic of the soft interrupt signal is not executed in the target thread, which may cause the execution privilege of the signal processing logic of the soft interrupt signal to be higher than that of the target thread, so that the signal processing logic of the soft interrupt signal can access and modify more system resources, or may perform some unsafe operations, increasing the security risk, thus resulting in low running reliability of the embedded real-time operating system. In addition, newly opening a thread to execute the signal processing logic of the soft interrupt signal, so that the signal processing logic of the soft interrupt signal is not executed in the target thread, may cause the execution privilege of the signal processing logic of the soft interrupt signal to be lower than that of the target thread, based on the reduced privilege, which may cause the signal processing logic of the soft interrupt signal to be unable to access the resources held by the target thread due to insufficient permissions, for example, if the target thread holds access permissions to a certain protected memory region or file descriptor, and the thread corresponding to the signal processing logic of the soft interrupt signal does not have sufficient permissions to access these resources, then the signal processing logic of the soft interrupt signal cannot be executed correctly, thereby affecting the normal operation of the embedded real-time operating system, also making the running reliability of the embedded real-time operating system low.
[0057] For example, taking the RT-Thread real-time operating system as an example, the signal logic thereof is mainly executed in the rt_schedule function (core scheduling function), and the rt_schedule function is usually run in the kernel mode of the operating system and has privileged access, which is crucial for underlying operations such as task scheduling, resource allocation, and context switching. Since the rt_schedule function can be called in a terminal handler, for example, when a timer interrupt occurs, the rt_schedule function can also be executed in an interrupt context. Among them, the interrupt context is a special execution environment in which only a limited amount of stack space and resources are available. Since the rt_schedule function runs in a privileged level and in an interrupt context, its signal processing logic is also executed in a privileged level. For non-privileged threads, the signal processing logic can be executed in a privileged level, which can execute in a manner that exceeds the privilege level of the target thread, which can cause system crashes or deadlocks, thus making the reliability of the thread signal processing mechanism relatively low; and if the signal processing logic is executed in an interrupt context, it will not be able to execute code that needs to be run in a non-interrupt context. In fact, most program requirements run in a non-interrupt context, further reducing the reliability of the thread signal processing mechanism.
[0058] Based on this, the thread signal processing method, device, equipment and storage medium of the embedded system provided by the embodiments of the present application are provided to solve the problem of low reliability of the thread signal processing mechanism of the existing embedded system. The thread signal processing method, device, equipment and storage medium provided by the present application are intended to determine the target thread according to the received soft interrupt signal and detect the current state of the target thread when processing the thread signal. When the current state of the target thread is the state of executing user logic, the target thread is frozen, the initial logical context of the target thread is saved, the soft interrupt signal is mounted to the pending signal linked list of the target thread, and a new logical context is generated according to the soft interrupt signal and the initial logical context. The target thread is unfrozen, and the signal processing logic of the target thread is executed according to the new logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal. By using the above technical means, the signal processing logic of the soft interrupt signal can be executed in the target thread, which can avoid the technical problem of low running reliability of the embedded real-time operating system caused by the signal processing logic of the soft interrupt signal not being executed in the target thread. In the present embodiment, when the current state of the target thread is the state of executing user logic, the target thread is frozen and the initial logical context is saved, the soft interrupt signal is mounted to the pending signal linked list of the target thread, and a new logical context is generated according to the soft interrupt signal and the initial logical context. After the target thread is unfrozen, the signal processing logic of the target thread can be executed according to the new logical context and the pending signal linked list, the signal processing logic corresponding to the soft interrupt signal is inserted in the target thread, the signal processing logic of the soft interrupt signal can be completed in the target thread, the execution privilege of the signal processing logic of the soft interrupt signal is lower than the privilege of the target thread, thereby improving the security of the thread signal processing mechanism and further improving the running reliability of the embedded real-time operating system.
[0059] Figure 1 A flowchart of the thread signal processing method of the embedded system provided by the embodiments of the present application is given. The thread signal processing method of the embedded system provided in the present embodiment can be executed by a thread signal processing device of the embedded system. The thread signal processing device of the embedded system can be realized by software and / or hardware. The thread signal processing device of the embedded system can be composed of two or more physical entities, or can be composed of one physical entity. Generally, the thread signal processing device of the embedded system can be a computer device.
[0060] The following describes the computer device as an example of the main body for executing the thread signal processing method of the embedded system. Referring to Figure 1 The thread signal processing method of the embedded system is used for an embedded real-time operating system. The thread signal processing method of the embedded system specifically includes:
[0061] S101. Receive a soft interrupt signal, and determine a target thread according to the soft interrupt signal.
[0062] An asynchronous event occurs to a thread, and a soft interrupt signal is sent to notify the thread of the asynchronous event. Upon receiving the soft interrupt signal, a target thread is determined according to the soft interrupt signal. The soft interrupt signal contains identification information corresponding to the target thread, and the target thread can be determined according to the identification information in the soft interrupt signal. The soft interrupt signal can be sent by another thread or by the kernel.
[0063] S102. Detect the current state of the target thread.
[0064] After determining the target thread, the current state of the target thread is detected. The current state can be a state of executing user logic, a state of executing signal processing logic, or a state of executing a system API. Therefore, the current state of the target thread needs to be determined to perform different processing logics according to different states, thereby improving the reliability of the target thread in executing the task of the soft interrupt signal. For example, a function provided by an embedded real-time operating system can be used to query the state of the target thread. Alternatively, a flag bit can be set in the thread code to indicate whether the thread is executing signal processing logic or a system API. When the thread starts processing the signal processing logic or the system API, the flag bit is set, and when the processing is completed, the flag bit is cleared. Therefore, whether the target thread is currently in the state of executing user logic, the state of executing signal processing logic, or the state of executing a system API can be determined by detecting whether the target thread has the flag bit. For example, if the flag bit is not detected, it means that the target thread is not executing signal processing logic and is not executing a system API. Therefore, the target thread is currently in the state of executing user logic. Alternatively, a corresponding debugging tool or performance analysis tool can be used to monitor the activity of the target thread. These tools can provide information about the execution time, waiting time, and CPU usage of the target thread, and the current state of the target thread can be determined according to these information.
[0065] The system API refers to a series of programming interfaces provided by an (embedded real-time) operating system to application programs, which are used to realize the interaction between the application programs and the operating system. The process of the target thread executing the system API is the process of the target thread interacting with the operating system, and the system API is the programming interface that realizes this interaction. Through the system API, the target thread can perform various system-level operations to achieve more complex functions and higher performance.
[0066] S103. When the current state of the target thread is the state of executing user logic, freeze the target thread to save the initial logical context of the target thread.
[0067] The state of executing user logic can be understood as the target thread is not executing signal handling logic nor executing system APIs. A flag can be set in the thread code to indicate whether the thread is executing signal handling logic or system APIs, and the flag is set when the thread starts to handle signal handling logic or system APIs and is cleared when the handling is finished, so that the current state of the target thread can be determined by detecting whether the flag exists in the target thread, i.e., whether the target thread is in the state of executing user logic, the state of executing signal handling logic or the state of executing system APIs. For example, if the flag is not detected, it means that the target thread is not executing signal handling logic nor executing system APIs, so the target thread is in the state of executing user logic. When the current state of the target thread is in the state of executing user logic, the target thread is frozen to save the initial logical context of the target thread. For example, when it is determined that the target thread is in the state of executing user logic, the thread lock of the target thread is acquired. Before freezing the target thread, the appropriate thread lock is acquired to ensure the safety of the target thread, which can be a task lock, a scheduler lock or other types of locks (e.g., spinlock). The target thread is suspended, i.e., frozen, using the (non-system) API provided by the embedded real-time operating system, so that the target thread stops executing but the resources (e.g., stack) occupied by the target thread are not immediately released. When the target thread is suspended, the initial logical context of the target thread is saved.
[0068] In S104, the soft interrupt signal is mounted to the pending signal linked list of the target thread, and a new logical context is generated according to the soft interrupt signal and the initial logical context.
[0069] The embedded real-time operating system sends the soft interrupt signal to the target thread, and the target thread mounts the received soft interrupt signal to the pending signal linked list of the target thread. The target thread registers a signal handling function for the soft interrupt signal, and the signal handling function is called when the soft interrupt signal arrives. When the target thread receives the soft interrupt signal, the signal handling function is triggered, and in the signal handling function, the information carried by the soft interrupt signal can be read, and a new logical context is generated according to the information and the initial logical context of the target thread.
[0070] For example, when a target thread registers a signal handling function for a soft interrupt signal, the function parameters can be determined first, including a signal type, a function pointer, and a pointing pointer. The signal type indicates the type of signal for which the signal handling function is registered. The function pointer is used to point to the new signal handling function, which will be called when a signal of the specified type (e.g., a soft interrupt signal) occurs. The pointing pointer represents a pointer to the function pointer, which is used to store the address of the old signal handling function. If the signal handling function is executed successfully, it will contain the address of the previously registered handling function for the signal. The function body of the signal handling function is constructed according to the aforementioned function parameters. The process of constructing the function body includes: obtaining the current task pointer, which can be obtained by calling the rtk_task_self() function to obtain the pointer of the current task, and storing it in the p_cur_task variable. Acquire the task lock and lock the task lock. Get the old signal handling function of the specified signal type from the signal storage structure of the current task and store it in the old_sig_fn variable. Register the new signal handling function and store the address of the new signal handling function in the signal storage structure of the specified signal type. Use the rtk_spinlock_give() function to release the previously acquired task lock and restore the previously saved interrupt state. The function returns AW_OK, indicating that the signal handling function has been successfully registered. The above registration of the signal handling function can be understood as saving the corresponding function to a specific location.
[0071] Exemplarily, when the soft interrupt signal is mounted into the pending signal list of the target thread, a static function rtk_task_signal_pend can be defined, which can only be called inside the file where it is defined. The function parameters of the static function include a pointer to the pointer of the task receiving the signal, the pending signal to be suspended, the first parameter of the signal, the second parameter of the signal, the count pointer and the completion status pointer. The pointer to the pointer is used to point to the pointer of the task receiving the signal. The pending signal indicates the signal to be suspended. The first parameter of the signal is used to transmit the signal-related data. The second parameter of the signal is used to transmit additional data. The count pointer is a pointer to the API call reference count, which is used to return the reference count of the call. The completion status pointer is a pointer to the signal execution completion status, which is used to return whether the signal has been executed. The function body of the static function is constructed according to the foregoing function parameters. The function body of the static function includes: obtaining the signal pending node, i.e. the node suspended when the target thread is frozen. The spin lock of the task is obtained, and the interrupt state is saved to prevent concurrent access when the task state is modified. The value of the signal pending node is set, and the signal, the parameter and the pointer to the second parameter of the signal are set to p_sig_pend_node. The structure of the pending signal list is initialized, and the node is added to the tail of the signal pending list of the task. The API reference count of the call is returned, the state of whether the signal has been executed is returned, the signal execution completion status of the task is reset to 0, which represents that there is a new signal to be processed, the API call reference count and the signal execution completion status are updated. The signal occurrence flag of the task is set, so that the task becomes the ready state. The spin lock of the task is released, and the previously saved interrupt state is restored, which realizes unlocking. The function execution is successful, and AW_OK is returned. Through the defined static function, a signal is suspended into the signal pending list of the specified task, and the related state information is updated, so that when the target thread receives the soft interrupt signal, the soft interrupt signal can be suspended into the pending signal list of the target thread.
[0072] In an embodiment, when a thread is created, the embedded real-time operating system allocates an initial logical context for the thread and sets an appropriate privilege level according to the type and purpose of the thread. The privilege level of each thread can be different, and the privilege level information of the thread is contained in the logical context, so when a new logical context is created, a new logical context needs to be generated according to the target privilege level of the target thread. When generating a new logical context, the target privilege level of the target thread can be determined according to the initial logical context. The target privilege level can be a privileged level or a non-privileged level. A new logical context is generated according to the target privilege level and the soft interrupt signal. For example, when the target privilege level (i.e., the privilege level information of the target thread) is a privileged level, the corresponding privilege level information in the generated new logical context is also a privileged level; when the target privilege level (i.e., the privilege level information of the target thread) is a non-privileged level, the corresponding privilege level information in the generated new logical context is also a non-privileged level. Therefore, the execution privilege of the signal processing logic of the soft interrupt signal will not be higher than the privilege of the target thread, thereby improving the security of the thread processing mechanism of the soft interrupt signal, and further improving the running reliability of the embedded real-time operating system.
[0073] For example, on an ARM cortex-m processor, the target privilege level of the target thread can be detected by the cortex_m_init_exc_return_get function to determine whether the target privilege level (i.e., the privilege level information of the target thread) is a privileged level or a non-privileged level. It should be noted that the privileged level and the non-privileged level are preset levels, and they can also be divided into multiple levels according to actual needs, and the corresponding levels are defined as privileged levels, for example, a three-level division is set, which are first level, second level and third level, the first level can be defined as a privileged level, and the second level and the third level are non-privileged levels. Therefore, the levels of the privileged level and the non-privileged level can be set according to actual conditions. The base context (i.e., the initial logical context) of the Cortex-M task is initialized by the rtk_cortex_m_base_context_init function. This function accepts a series of parameters, including the stack pointer, the stack limit, the task entry point, the parameters, the exit function and the options, and fills a cortex_m_base_context structure. The rtk_arch_task_stack_init function is used to implement the function of the external calling interface, which is used to initialize the stack of the task. It accepts the entry point of the task, the parameters, the stack pointer (the base stack pointer), the exit function, the options, and the low and high addresses of the stack as parameters. Inside the function, it calls the rtk_cortex_m_base_context_init function to actually initialize the logical context and passes in the necessary parameters. Finally, the function returns the current stack address of the task, which is the stack pointer position after the initialization of the logical context, and can be used for task scheduling.
[0074] Therefore, when the target thread corresponds to a target privilege level that is a non-privileged level, a flag is specified in the newly created logical context, and the thread scheduling automatically sets the running signal processing function to be in the non-privileged level, so as to implement the target privilege level (which is the non-privileged level at this time) to execute the signal processing function.
[0075] S105, thawing the target thread, and executing the signal processing logic of the target thread according to the new logical context and the pending signal list to complete the task corresponding to the soft interrupt signal.
[0076] After the new logical context is generated, the target thread is thawed, and the signal processing logic of the target thread is executed according to the new logical context and the pending signal list to complete the task corresponding to the soft interrupt signal. After the target thread is thawed and ready to execute, the embedded real-time operating system detects the pending signal list of the target thread, which contains all the pending signals of the target thread. The corresponding signal processing logic is executed in sequence according to the order of the pending signals in the pending signal list. When executing the signal processing logic, each signal in the pending signal list can be executed in sequence by __rtk_task_excute_sig_func. First, the embedded real-time operating system identifies the type of the signal, which can be a synchronous signal (such as an IPC signal sent by another thread) or an asynchronous signal (such as a soft interrupt signal). According to the signal type and the signal processing settings of the target thread, such as the signal processing function or signal processing program set by the signal(), sigaction(), etc. functions, the embedded real-time operating system calls the corresponding signal processing function to process the signal. Since the soft interrupt signal is mounted to the pending signal list of the target thread, the soft interrupt signal will be identified and the corresponding signal processing logic will be executed. Therefore, the task corresponding to the soft interrupt signal can be completed, i.e. the task corresponding to the soft interrupt signal can be completed in the target thread.
[0077] For example, when executing the signal processing function according to the new logical context, the logical context is executed by calling the entry function (such as the __rtk_task_do_signal_context function), the signal processing function is executed by calling __rtk_task_excute_sig_func inside the function, and the signal processing context is exited by rtk_arch_task_try_sig_exit
[0078] In an embodiment, in the case of executing the signal processing function in a new logical context, after execution is completed, the original logical context of the target thread, i.e., the initial logical context, is returned. The original context of the thread can be returned by using the rtk_arch_task_try_sig_exit function. The mechanism for safely exiting the execution of the signal processing function logic is implemented by the function, which avoids race conditions by disabling interrupts, checks whether the execution of the signal processing function logic should be exited, and if so, performs an exit operation and finally restores interrupt processing to ensure the stability and predictability of the system. In this process, only the stack pointer (SP) needs to be changed to the stack pointer of the original context, and the execution can be switched to the new thread.
[0079] In the above, in the thread signal processing, the target thread is determined according to the received soft interrupt signal, and the current state of the target thread is detected. When the current state of the target thread is a state of executing user logic, the target thread is frozen, the initial logical context of the target thread is saved, the soft interrupt signal is mounted to the pending signal linked list of the target thread, a new logical context is generated according to the soft interrupt signal and the initial logical context, the target thread is unfrozen, and the signal processing logic of the target thread is executed according to the new logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal. By using the above technical means, the signal processing logic of the soft interrupt signal can be executed in the target thread, which can avoid the technical problem that the running reliability of the embedded real-time operating system is low due to the signal processing logic of the soft interrupt signal not being executed in the target thread. In the embodiment, when the current state of the target thread is a state of executing user logic, the target thread is frozen and the initial logical context is saved, the soft interrupt signal is mounted to the pending signal linked list of the target thread, and a new logical context is generated according to the soft interrupt signal and the initial logical context, so that after the target thread is unfrozen, the signal processing logic of the target thread can be executed according to the new logical context and the pending signal linked list, the signal processing logic corresponding to the soft interrupt signal is inserted in the target thread, the signal processing logic of the soft interrupt signal can be completed in the target thread, the execution privilege of the signal processing logic of the soft interrupt signal is the same as the privilege of the target thread, the security risk caused by the increase of the execution privilege of the signal processing logic of the soft interrupt signal is avoided, the security of the thread signal processing mechanism is improved, and the running reliability of the embedded real-time operating system is further improved. In addition, by inserting the signal processing logic corresponding to the soft interrupt signal in the target thread, the signal processing logic of the soft interrupt signal can be completed in the target thread, the problem of reduced privilege caused by processing the soft interrupt signal in a new thread is avoided, the execution privilege of the signal processing logic of the soft interrupt signal is the same as the privilege of the target thread, so that the soft interrupt signal can be executed correctly, and the running reliability of the embedded real-time operating system is further improved.
[0080] On the basis of the above-mentioned embodiments, Figure 2 is a flowchart of another thread signal processing method of an embedded system provided by the embodiments of the present application, which refers to Figure 2 The thread signal processing method of the embedded system specifically comprises:
[0081] S201, receiving a soft interrupt signal, and determining a target thread according to the soft interrupt signal.
[0082] S202, detecting a current state of the target thread.
[0083] S203, freezing the target thread to save an initial logical context of the target thread when the current state of the target thread is a state of executing signal processing logic.
[0084] The state of executing signal processing logic can be understood as a state of calling a corresponding signal processing function and executing the signal processing function. At this time, if the signal processing logic of executing the soft interrupt signal is directly inserted, the executing signal processing logic (or signal processing function) can be affected or damaged, and the subsequent recovery of the execution of the original signal of the target thread can need to re-execute the signal processing logic (or signal processing function) affected before, which can reduce the overall execution efficiency of the target thread. Therefore, the signal processing logic of the soft interrupt signal can be executed after the originally executing signal processing logic is executed completely, so as to improve the execution reliability of the target thread and improve the execution efficiency.
[0085] When the current state of the target thread is the state of executing signal processing logic, the target thread is frozen, the initial logical context of the target thread is saved, and an initial stack pointer is set. The initial stack pointer is used to indicate the execution of the previously executing signal processing logic after the target thread is unfrozen. By setting the initial stack pointer, the effective management and concurrent execution of threads in a multi-threaded environment can be realized, while ensuring the consistency of data and the safety of memory, which provides a basis for efficient and reliable operation of an embedded real-time operating system.
[0086] S204, mounting the soft interrupt signal to a pending signal linked list of the target thread.
[0087] In the embodiments, the specific implementation process of mounting the soft interrupt signal to the pending signal linked list of the target thread is the same as the corresponding implementation steps in S104, which will not be repeated here.
[0088] S205, unfreezing the target thread to recover the signal processing logic being executed by the target thread.
[0089] thaw the target thread, restore the initial logical context corresponding to the target thread, and resume the signal processing logic being executed by the target thread according to the initial stack pointer, i.e., continue the signal processing logic being executed before the full freeze, until the signal processing logic is executed completely.
[0090] S206, execute the subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list, so as to complete the task corresponding to the soft interrupt signal.
[0091] Based on the fact that the soft interrupt signal is mounted in the pending signal linked list of the target thread, after the signal processing logic being executed before the full freeze is executed completely, the subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list can be executed, i.e., the signal processing logic corresponding to the soft interrupt signal mounted in the pending signal linked list can be executed, so that the task corresponding to the soft interrupt signal can be completed.
[0092] In an embodiment, the signal processing logic being executed can be API exit processing logic. The API exit processing logic usually involves access and management of system resources or specific functions, and these operations are often critical and time-sensitive. When the API exit processing logic is being executed, important system resources can be being operated or data consistency can be being maintained. Therefore, if the API exit processing logic is interrupted by other signals at this critical moment, i.e., the signal processing logic corresponding to the soft interrupt signal is started to be executed at this moment, it can cause inconsistency of resource state or data damage. Therefore, after the target thread is thawed, the API exit processing logic needs to be restored, and after the API exit processing logic is processed completely, the subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list is executed, i.e., the signal processing logic corresponding to the soft interrupt signal is executed, so as to complete the task corresponding to the soft interrupt signal. Through the above method, the data integrity and consistency can be ensured after the API exit processing logic is processed completely, so as to improve the reliability of thread signal processing. In addition, based on the fact that the API exit processing logic can occupy some system resources, such as memory and file handle, if the signal processing logic of the soft interrupt signal attempts to access these resources, resource conflict or deadlock can be caused. Therefore, by ensuring that the API exit processing logic is completed first, the potential conflict and deadlock problem can be avoided, and the reliability of thread signal processing is further improved.
[0093] In the above, when the current state of the target thread is the state of executing the signal processing logic, the target thread is frozen and the initial logical context of the target thread is saved, and the soft interrupt signal is mounted to the pending signal linked list of the target thread. At this time, if a new logical context is established as in the state of executing the user logic, it will cause waste of thread stack resources. Therefore, the target thread can be unfrozen, and after the target thread executes the signal processing logic being executed before freezing, a pending signal is popped from the pending signal linked list, and the corresponding signal processing function is executed to complete the task corresponding to the soft interrupt signal. By using the above technical means, the signal processing logic of the soft interrupt signal can be executed in the target thread, so that the technical problem that the running reliability of the embedded real-time operating system is low due to the signal processing logic of the soft interrupt signal not being executed in the target thread can be avoided. In the embodiment, when the current state of the target thread is the state of executing the signal processing logic, the target thread is frozen and the initial logical context is saved. By setting the initial stack pointer, the signal processing logic interrupted before can be restored according to the initial stack pointer after the target thread is unfrozen, so that the signal processing logic being executed before is completed first, and then the signal processing logic corresponding to the soft interrupt signal is processed. In this way, the execution efficiency of thread signal processing is improved, and the reliability of thread signal processing is improved. In addition, the signal processing logic corresponding to the soft interrupt signal is inserted into the target thread in the embodiment, so that the signal processing logic of the soft interrupt signal can be completed in the target thread. The execution privilege of the signal processing logic of the soft interrupt signal is the same as the privilege of the target thread, so that the security risk caused by the increase of the execution privilege of the signal processing logic of the soft interrupt signal is avoided, thereby improving the security of the thread signal processing mechanism, and further improving the running reliability of the embedded real-time operating system. In addition, by inserting the signal processing logic corresponding to the soft interrupt signal into the target thread, the problem of privilege reduction caused by processing the soft interrupt signal in a new thread can be avoided. The execution privilege of the signal processing logic of the soft interrupt signal is the same as the privilege of the target thread, so that the soft interrupt signal can be executed correctly, and the running reliability of the embedded real-time operating system is further improved.
[0094] On the basis of the above embodiment, Figure 3 is a flowchart of another thread signal processing method of an embedded system provided by the embodiment of the application, referring to Figure 3 The thread signal processing method of the embedded system specifically comprises:
[0095] S301, a soft interrupt signal is received, and a target thread is determined according to the soft interrupt signal.
[0096] S302, detecting the current state of the target thread.
[0097] S303, freezing the target thread to save the initial logical context of the target thread when the current state of the target thread is the state of executing the system API.
[0098] The system API refers to a series of programming interfaces provided by the (embedded real-time) operating system to the application program, which is used to realize the interaction between the application program and the operating system. The process of the target thread executing the system API is the process of the target thread interacting with the operating system, and the system API is the programming interface for realizing such interaction. Through the system API, the target thread can perform various system-level operations, thereby realizing more complex functions and higher performance.
[0099] When it is determined that the current state of the target thread is the state of executing the system API, the target thread is frozen to save the initial logical context of the target thread. The steps of freezing the target thread are the same as those of S103 described above, and will not be repeated here.
[0100] S304, mounting the soft interrupt signal to the pending signal linked list of the target thread.
[0101] In this embodiment, the specific implementation process of mounting the soft interrupt signal to the pending signal linked list of the target thread is the same as the corresponding implementation steps in S104 described above, and will not be repeated here.
[0102] S305, interrupting the blocking of the target thread when the target thread exists blocking.
[0103] When executing the system API, it may be in a situation of time delay or waiting for a semaphore, which is called blocking. For example, when executing the system API, it may need to wait for 10 minutes to trigger the next execution. If the corresponding signal processing logic is executed after waiting for the blocking to be completed, time will be wasted, and the efficiency of thread signal execution will be low. Therefore, when the target thread exists blocking, the blocking can be interrupted to improve the speed and efficiency of thread signal processing.
[0104] For example, the current state of the target thread is detected, and when the current state of the target thread is the waiting state, it is determined that the target thread exists blocking, and at this time the blocking of the target thread can be interrupted, and the current state of the target thread is changed to the execution state.
[0105] S306, unfreezing the target thread to restore the system API being executed by the target thread.
[0106] When the target thread has a block, the block of the target thread is broken, and then the target thread is unfreezed. When there is no block, the soft interrupt signal is hung to the pending signal list of the target thread, and then the target thread is unfreezed. After the target thread is unfreezed, the system API being executed by the target thread is restored. For example, when there is a block, based on the fact that the block has been broken, the state of the target thread is changed to an execution state, so that after the target thread is unfreezed, the signal processing logic corresponding to the system API can be executed without waiting for a time delay, thereby improving the overall work efficiency of signal thread processing.
[0107] S307, when the system API exits, the subsequent signal processing logic of the target thread is executed according to the initial logical context and the pending signal list, so as to complete the task corresponding to the soft interrupt signal.
[0108] After the system API is executed, that is, when the system API exits, the subsequent signal processing logic of the target thread is executed according to the initial logical context and the pending signal list, so as to complete the task corresponding to the soft interrupt signal. The above-mentioned task corresponding to the soft interrupt signal is executed after the completion of the API exit processing logic, which can ensure the integrity and consistency of data, thereby improving the reliability of thread signal processing. In addition, based on the fact that the API exit processing logic may occupy some system resources, such as memory and file handle, if the signal processing logic of the soft interrupt signal attempts to access these resources, resource conflicts or deadlocks may be caused, so by ensuring that the API exit processing logic is completed first, the potential conflicts and deadlock problems can be avoided, thereby further improving the reliability of thread signal processing.
[0109] For example, when the system API exits, the rtk_api_exit function can be executed, and when the function detects that there is a signal to be processed, the signal processing function is executed by executing the __rtk_task_excute_sig_func function, as in the execution of the signal processing function in the context.
[0110] In the above, when the current state of the target thread is a state of executing a system API, the target thread is frozen, the initial logical context of the target thread is saved, the soft interrupt signal is mounted to the pending signal linked list of the target thread, if the target thread exists blocking, the blocking of the target thread is interrupted, then the target thread is unfrozen, the system API being executed by the target thread is restored, when the system API exits, the subsequent signal processing logic of the target thread is executed according to the initial logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal. By using the above technical means, the signal processing logic of the soft interrupt signal can be executed in the target thread, so that the technical problem that the running reliability of the embedded real-time operating system is low due to the signal processing logic of the soft interrupt signal not being executed in the target thread can be avoided. In the embodiment, when the current state of the target thread is a state of executing a system API, the target thread is frozen to save the initial logical context of the target thread, the soft interrupt signal is mounted to the pending signal linked list of the target thread, the target thread is unfrozen, the system API being executed by the target thread is restored, then the signal processing logic corresponding to the soft interrupt signal is executed according to the pending signal linked list, so that the signal processing logic corresponding to the soft interrupt signal is inserted in the target thread, the signal processing logic of the soft interrupt signal can be completed in the target thread, the execution privilege of the signal processing logic of the soft interrupt signal is the same as the privilege of the target thread, the security risk caused by the increase of the execution privilege of the signal processing logic of the soft interrupt signal is avoided, so that the security of the thread signal processing mechanism is improved, and the running reliability of the embedded real-time operating system is further improved. In addition, by inserting the signal processing logic corresponding to the soft interrupt signal in the target thread, the signal processing logic of the soft interrupt signal can be completed in the target thread, the problem of privilege reduction caused by processing the soft interrupt signal in a new thread is avoided, the execution privilege of the signal processing logic of the soft interrupt signal is the same as the privilege of the target thread, so that the soft interrupt signal can be executed correctly, and the running reliability of the embedded real-time operating system is further improved. In addition, when there is blocking, the blocking is interrupted, and the state of the target thread is changed to an execution state, so that after the target thread is unfrozen, the signal processing logic corresponding to the system API can be executed without delay, so that the overall work efficiency of the signal thread processing is improved.
[0111] In the above, no matter whether the target thread is executing a system API or not, the corresponding signal processing logic can be executed immediately at a faster speed. For example, when the current state of the target thread is executing a system API, the signal processing logic can be executed quickly by interrupting the blocking; when the target thread is not executing a system API, the initial logical context is saved, and the soft interrupt signal is mounted to the pending signal linked list, so that after the target thread is unfrozen, the corresponding signal processing logic can be immediately performed based on the initial logical context and the pending signal linked list.
[0112] The signal processing logic is executed in the target thread instead of being executed by other threads, so as to reduce the resource occupation in the system, and improve the overall work efficiency of the thread signal processing.
[0113] The rtk_arch_task_stack_init function is used to establish a new logical context, and the option parameter in the function is used to determine whether the new logical context runs in a privileged mode, so that when the target thread is a privileged thread, the subsequent signal processing logic can be executed in a privileged environment, or when the target thread is a non-privileged thread, the subsequent signal processing logic can be executed in a non-privileged environment, so as to avoid executing the signal processing logic in a manner that exceeds the privilege level of the target thread, and improve the reliability of the thread signal processing mechanism.
[0114] On the basis of the above embodiment, Figure 4 A structure diagram of a thread signal processing device of an embedded system provided by the embodiment is provided. Figure 4 The thread signal processing device of the embedded system provided by the embodiment specifically comprises a signal receiving module 21, a state detecting module 22, a first freezing module 23, a first processing module 24, and a first unfreezing module 25.
[0115] The signal receiving module 21 is configured to receive a soft interrupt signal, and determine a target thread according to the soft interrupt signal.
[0116] The state detecting module 22 is configured to detect a current state of the target thread.
[0117] The first freezing module 23 is configured to freeze the target thread to save an initial logical context of the target thread when the current state of the target thread is a state of executing user logic.
[0118] The first processing module 24 is configured to mount the soft interrupt signal to a pending signal linked list of the target thread, and generate a new logical context according to the soft interrupt signal and the initial logical context.
[0119] The first unfreezing module 25 is configured to unfreeze the target thread, and execute signal processing logic of the target thread according to the new logical context and the pending signal linked list, so as to complete a task corresponding to the soft interrupt signal.
[0120] In an embodiment, the first processing module 24 comprises a first signal mounting sub-module, a privilege level determining sub-module, and a new context generating sub-module.
[0121] The first signal mounting submodule is configured to mount the soft interrupt signal to a pending signal linked list of the target thread.
[0122] The privilege level determining submodule is configured to determine a target privilege level of the target thread according to the initial logical context.
[0123] The new context generating submodule is configured to generate a new logical context according to the target privilege level and the soft interrupt signal.
[0124] In an embodiment, the thread signal processing apparatus of the embedded system further comprises a second freezing module, a second processing module, a second unfreezing module and a third processing module.
[0125] The second freezing module is configured to freeze the target thread to save an initial logical context of the target thread when a current state of the target thread is a state of executing a signal processing logic.
[0126] The second processing module is configured to mount the soft interrupt signal to a pending signal linked list of the target thread.
[0127] The second unfreezing module is configured to unfreeze the target thread to restore the signal processing logic being executed by the target thread.
[0128] The third processing module is configured to execute subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list to complete a task corresponding to the soft interrupt signal.
[0129] On the basis of the foregoing embodiment, the second freezing module is further configured to freeze the target thread to save the initial logical context and set an initial stack pointer of the target thread when the current state of the target thread is the state of executing the signal processing logic.
[0130] On the basis of the foregoing embodiment, the second unfreezing module is further configured to unfreeze the target thread to restore the signal processing logic being executed by the target thread according to the initial stack pointer.
[0131] On the basis of the foregoing embodiment, the second unfreezing module is further configured to unfreeze the target thread to restore API exit processing logic being executed by the target thread when the signal processing logic being executed is the API exit processing logic.
[0132] On the basis of the foregoing embodiment, the third processing module is further configured to execute subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal after the API exit processing logic is processed.
[0133] In an embodiment, the thread signal processing apparatus of the embedded system further comprises a third freezing module, a fourth processing module, a blocking interruption module, a third unfreezing module and a fifth processing module.
[0134] a third freezing module, configured to freeze the target thread to save an initial logical context of the target thread when a current state of the target thread is a state of executing the system API;
[0135] a fourth processing module, configured to mount the soft interrupt signal to a pending signal linked list of the target thread;
[0136] a blocking breaking module, configured to break the blocking of the target thread when the target thread exists the blocking;
[0137] a third unfreezing module, configured to unfreeze the target thread to restore the system API being executed by the target thread;
[0138] a fifth processing module, configured to execute subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list when the system API exits, so as to complete a task corresponding to the soft interrupt signal.
[0139] In an embodiment, the blocking breaking module comprises a blocking judging submodule and a blocking breaking submodule.
[0140] The blocking judging submodule is configured to detect the current state of the target thread, and determine that the target thread exists the blocking when the current state is a waiting state.
[0141] The blocking breaking submodule is configured to break the blocking of the target thread, and change the current state of the target thread to an execution state.
[0142] The thread signal processing apparatus of the embedded system provided by the embodiments of the present application can be used to execute the thread signal processing method of the embedded system provided by the above embodiments, and has the corresponding functions and beneficial effects.
[0143] The embodiments of the present application provide a thread signal processing device of an embedded system, referring to Figure 5 The thread signal processing device of the embedded system comprises a processor 31, a memory 32, a communication module 33, an input device 34 and an output device 35. The number of processors in the thread signal processing device of the embedded system can be one or more, and the number of memories in the thread signal processing device of the embedded system can be one or more. The processor, the memory, the communication module, the input device and the output device of the thread signal processing device of the embedded system can be connected through a bus or other means.
[0144] The memory 32, as a computer readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the thread signal processing method of the embedded system according to any embodiment of the present application (for example, the signal receiving module, the state detecting module, the first freezing module, the first processing module and the first unfreezing module in the thread signal processing device of the embedded system). The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and application programs required by at least one function; and the data storage area can store data created according to the use of the device and the like. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device or other non-volatile solid-state storage device. In some examples, the memory can further include a memory remotely arranged with respect to the processor, which can be connected to the device through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.
[0145] The communication module 33 is used for data transmission.
[0146] The processor 31 executes various function applications and data processing of the device by running the software programs, instructions and modules stored in the memory, that is, implements the above-mentioned thread signal processing method of the embedded system.
[0147] The input device 34 can be used to receive input digital or character information, and generate key signal input related to user settings and function control of the device. The output device 35 can include a display device such as a display screen.
[0148] The above-mentioned thread signal processing device of the embedded system can be used to execute the thread signal processing method of the embedded system provided by the above-mentioned embodiments, and has corresponding functions and advantages.
[0149] The embodiment of the present application further provides a storage medium storing computer executable instructions, which, when executed by a computer processor, are used to execute a thread signal processing method of an embedded system, the thread signal processing method of the embedded system comprising: receiving a soft interrupt signal, determining a target thread according to the soft interrupt signal; detecting a current state of the target thread; when the current state of the target thread is a state of executing user logic, freezing the target thread to save an initial logical context of the target thread; mounting the soft interrupt signal to a pending signal linked list of the target thread, and generating a new logical context according to the soft interrupt signal and the initial logical context; unfreezing the target thread, and executing signal processing logic of the target thread according to the new logical context and the pending signal linked list, to complete a task corresponding to the soft interrupt signal.
[0150] Storage medium - any type of memory device or storage device. The term "storage medium" is intended to include an installation medium, e.g., a CD-ROM, floppy disks, or tape apparatus; computer system memory or random access memory such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; or a non-volatile memory such as a magnetic medium (e.g., a hard drive or optical storage); registers or other similar types of memory elements, etc. The memory medium can also include other types of storage medium or combinations thereof. In addition, the memory medium can reside in a first computer system's internal storage or external storage that is connected to the first computer system. The first computer system can provide program instructions to a second computer system for execution via a network like the Internet from the first computer system. A second computer system can then provide program instructions to a first computer system for execution. The term "memory medium" can also include two or more memory mediums that reside in different locations, e.g., in different computer systems that are connected over a network. The memory medium can store program instructions that implement one or more embodiments of the methods described herein (e.g., embodied in a computer program product).
[0151] Of course, the storage medium storing computer executable instructions provided by the embodiments of the present application is not limited to the thread signal processing method of the embedded system as described above, but can also perform the related operations in the thread signal processing method of the embedded system provided by any of the embodiments of the present application.
[0152] The thread signal processing apparatus of the embedded system, the storage medium and the thread signal processing device of the embedded system provided in the above embodiments can perform the thread signal processing method of the embedded system provided by any of the embodiments of the present application, and the technical details not described in detail in the above embodiments can be referred to the thread signal processing method of the embedded system provided by any of the embodiments of the present application.
[0153] The above are only the preferred embodiments of the present application and the technical principles applied. The present application is not limited to the specific embodiments described herein, and various obvious changes, re-adjustments and replacements made by those skilled in the art will not deviate from the protection scope of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments, and can include more other equivalent embodiments without deviating from the concept of the present application, and the scope of the present application is determined by the scope of the claims.
Claims
1. A method of thread signal processing for an embedded system, characterized by, The method comprises the following steps: receiving a soft interrupt signal, determining a target thread according to the soft interrupt signal; detecting the current state of the target thread; freezing the target thread to save the initial logical context of the target thread when the current state of the target thread is a state of executing user logic, wherein the state of executing user logic is a state that the target thread does not execute signal processing logic and system API; mounting the soft interrupt signal to the pending signal linked list of the target thread, and generating a new logical context according to the soft interrupt signal and the initial logical context, wherein the mounting the soft interrupt signal to the pending signal linked list of the target thread comprises the following steps: determining the target privilege level of the target thread according to the initial logical context, and generating the new logical context according to the target privilege level and the soft interrupt signal; unfreezing the target thread, and executing the signal processing logic of the target thread according to the new logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal.
2. The method of claim 1, wherein, After the step of detecting the current state of the target thread, the method comprises the following steps: freezing the target thread to save the initial logical context of the target thread when the current state of the target thread is a state of executing signal processing logic, wherein the state of executing signal processing logic is a state that the corresponding signal processing function is called and is in the state of executing the signal processing function; mounting the soft interrupt signal to the pending signal linked list of the target thread; unfreezing the target thread to restore the signal processing logic being executed by the target thread; executing the subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal.
3. The method of claim 2, wherein, The step of freezing the target thread when the current state of the target thread is the state of executing signal processing logic comprises the following steps: freezing the target thread to save the initial logical context of the target thread and setting an initial stack pointer when the current state of the target thread is the state of executing signal processing logic. The step of unfreezing the target thread to restore the signal processing logic being executed by the target thread comprises the following steps: unfreezing the target thread to restore the signal processing logic being executed by the target thread according to the initial stack pointer.
4. The method of claim 2, wherein, The step of unfreezing the target thread to restore the signal processing logic being executed by the target thread comprises the following steps: unfreezing the target thread to restore the API exit processing logic being executed by the target thread when the signal processing logic being executed is API exit processing logic, wherein the API exit processing logic is processing logic for accessing and managing system resources or specific functions when the execution of the system API ends. The step of executing the subsequent signal processing logic of the target thread according to the initial logical context and the pending signal linked list comprises the following steps: After the API exit processing logic processing is completed, signal processing logic subsequent to the target thread is executed according to the initial logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal.
5. The method of claim 1, wherein, After the current state of the target thread is detected, the method comprises the following steps: When the current state of the target thread is a state of executing a system API, the target thread is frozen to save an initial logical context of the target thread, wherein the state of executing a system API is a state of the target thread interacting with an operating system, and the system API is a programming interface for implementing the interaction; The soft interrupt signal is mounted to the pending signal linked list of the target thread; When the target thread exists in blocking, the blocking of the target thread is interrupted; The target thread is unfrozen to restore the system API being executed by the target thread; When the system API exits, signal processing logic subsequent to the target thread is executed according to the initial logical context and the pending signal linked list to complete the task corresponding to the soft interrupt signal.
6. The method of claim 5, wherein, When the target thread exists in blocking, the blocking of the target thread is interrupted, and the method comprises the following steps: The current state of the target thread is detected, and when the current state is a waiting state, it is determined that the target thread exists in blocking; The blocking of the target thread is interrupted, and the current state of the target thread is changed to an execution state.
7. A thread signal processing apparatus for an embedded system, characterized by comprising: The method comprises the following steps: A signal receiving module is configured to receive a soft interrupt signal and determine a target thread according to the soft interrupt signal; A state detecting module is configured to detect a current state of the target thread; A first freezing module is configured to freeze the target thread to save an initial logical context of the target thread when the current state of the target thread is a state of executing user logic, wherein the state of executing user logic is a state in which the target thread does not execute signal processing logic and a system API; A first processing module is configured to mount the soft interrupt signal to a pending signal linked list of the target thread and generate a new logical context according to the soft interrupt signal and the initial logical context, and the first processing module is specifically configured to mount the soft interrupt signal to the pending signal linked list of the target thread, determine a target privilege level of the target thread according to the initial logical context, and generate the new logical context according to the target privilege level and the soft interrupt signal; A first unfreezing module is configured to unfreeze the target thread and execute signal processing logic of the target thread according to the new logical context and the pending signal linked list to complete a task corresponding to the soft interrupt signal.
8. A thread signal handling device for an embedded system, characterized in that The method comprises the following steps: A memory and one or more processors; The memory is configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-6.
9. A storage medium storing computer-executable instructions, wherein: The computer executable instructions, when executed by a processor, are used to execute the method according to any one of claims 1-6.
Citation Information
Patent Citations
Interrupt processing method and device, equipment, storage medium and vehicle
CN117992186A
Signal dispatching for C language interrupt handling
US5644772A