Context delay switching method and system based on embedded operating system

By constructing a dependency graph and dynamically adjusting the task switching order, the problem of insufficient adaptability to changes in task dependencies in traditional embedded operating systems is solved, achieving efficient and stable task switching in embedded systems and improving real-time response capabilities and resource utilization.

CN121387520APending Publication Date: 2026-01-23BEIJING INST OF COMP TECH & APPL
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511361169.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-23
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

Traditional embedded operating system context switching methods are insufficient when dealing with complex dependencies between tasks and real-time requirements. Static scheduling cannot adapt to changes in runtime task dependencies, resulting in poor flexibility and low system stability. Simple priority scheduling may cause critical tasks to fail to complete and thus fail to execute in a timely manner, affecting system performance.

Method used

Build a dependency graph to collect dependencies between tasks in real time and analyze execution status. Quantify the degree of association between tasks through a dependency strength formula, dynamically adjust the task switching order, filter non-conflicting tasks and sort them by priority to ensure that critical tasks are executed in the order of dependencies and avoid execution blockage or data errors caused by incomplete preceding tasks.

Benefits of technology

It improves the real-time response capability and operational stability of embedded systems, optimizes resource utilization, reduces resource contention and deadlock, and improves task switching efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121387520A_ABST
    Figure CN121387520A_ABST
Patent Text Reader

Abstract

The invention relates to a context delay switching method and system based on an embedded operating system, and belongs to the technical field of embedded operating systems. According to the method, a dependency graph is constructed, a dependency state is analyzed, judgment and adjustment are carried out, conflict-free tasks are screened, sorting is carried out, and switching is executed; according to the method, the limitation that traditional static scheduling cannot adapt to task dependency relationship changes during operation is solved by constructing the dependency relationship graph and collecting and analyzing the dependency strength and the execution state between the tasks in real time, and in a complex embedded scene, the correlation degree between the tasks is quantified through a dependency strength formula, and the real-time state analysis is combined, so that the real-time state analysis is realized. The task switching sequence can be dynamically adjusted, it is ensured that key tasks are executed according to the dependency sequence, execution blocking or data errors caused by the fact that front tasks are not completed are avoided, switching of the tasks which do not meet dependency can be flexibly suspended, conflict-free tasks are executed, and therefore the real-time response capacity and the operation stability are improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of embedded operating systems, and particularly relates to a context delay switching method and system based on an embedded operating system. BACKGROUND

[0002] In the current rapid development of embedded system technology, as the core software layer, the operating system bears the key responsibilities of managing hardware resources, scheduling task execution, and ensuring stable system operation. With the rise of the Internet of Things, intelligent manufacturing, autonomous driving, and other fields, the application scenarios of embedded devices are becoming increasingly complex, and higher requirements are placed on the task processing capabilities of operating systems, especially in applications that require high real-time performance and high reliability, such as industrial automation control, medical device monitoring, aerospace navigation, etc. The system often needs to run multiple interdependent tasks simultaneously. These tasks not only have execution order constraints, but also may involve data interaction and resource sharing.

[0003] However, in traditional technology, the methods for context switching of embedded operating systems mostly rely on static scheduling or simple priority scheduling mechanisms, which have significant shortcomings in handling complex dependency relationships between tasks and real-time requirements. Static scheduling usually determines the task execution order at the system design stage, making it difficult to adapt to changes in runtime task dependency relationships, resulting in poor flexibility. Although simple priority scheduling takes into account the urgency of tasks, it ignores the dependency strength between tasks, which may lead to critical tasks not being executed in time due to the incomplete execution of preceding tasks, affecting the overall system performance. In addition, during context switching, there is often a lack of comprehensive analysis of task conflicts and dependency relationships, which can easily lead to resource competition problems, reducing system stability and reliability. Especially in dynamic environments, it is difficult to meet the needs of modern embedded systems for efficient, real-time, and reliable task scheduling.

[0004] Therefore, it is necessary to develop a context delay switching method and system based on an embedded operating system. SUMMARY

[0005] (I) Technical problem to be solved

[0006] The technical problem to be solved by the present application is how to provide a context delay switching method and system based on an embedded operating system to solve the problem that traditional static scheduling cannot adapt to changes in runtime task dependency relationships.

[0007] (II) Technical solution

[0008] To solve the above technical problems, the present application provides a context delay switching method based on an embedded operating system, which comprises:

[0009] Dependency graph construction: collect the dependency relationship between tasks when a new task is created, convert the task into a node with attributes, calculate the dependency strength between tasks, and according to the dependency strength, represent the dependency relationship with a directed edge and mark the strength, and construct a dynamically updated dependency relationship graph;

[0010] Dependency state analysis: when the context switching requirement is triggered, the dependency relationship graph is called, the target task to be switched is determined and its node is located, all pre-dependent tasks are collected by reverse traversal of the directed edges pointing to the node, the execution status of each pre-task is queried, the dependency tightness of the target task and the pre-task is obtained by combining the dependency strength, the influence degree of the target task execution when the pre-dependent task is not completed is judged, and whether the target task has an unfinished pre-dependent task is analyzed;

[0011] Judgment and adjustment: according to the analysis result and the dependency strength, if all pre-dependent tasks have been completed, the context switching is directly executed, the context information of the current task is saved, the context information of the target task is loaded and the scheduling table is updated, if there is an unfinished pre-dependent task, the task switching order is adjusted after evaluation combined with the dependency strength, the switching operation of the target task is suspended and the target task is marked;

[0012] Conflict-free task screening: after the task switching order adjustment, the range of switchable candidate tasks is determined, the conflict coefficient of each candidate task is calculated, and the screening threshold is calculated, the tasks with conflict coefficient not exceeding the threshold are screened and marked;

[0013] Sorting and executing switching: calculate the priority of the conflict-free task, sort the tasks from high to low according to the priority, preferentially execute the context switching of the task with high priority, calculate the actual switching delay during switching, start the execution of the new task after the switching is completed, and continue to monitor and update the related information.

[0014] The application also provides a context delay switching system based on an embedded operating system, which comprises:

[0015] Dependency graph construction module: collect the dependency relationship between tasks when a new task is created, convert the task into a node with attributes, calculate the dependency strength between tasks, and according to the dependency strength, represent the dependency relationship with a directed edge and mark the strength, and construct a dynamically updated dependency relationship graph;

[0016] Dependency state analysis module: when the context switching requirement is triggered, the dependency relationship graph is called, the target task to be switched is determined and its node is located, all pre-dependent tasks are collected by reverse traversal of the directed edges pointing to the node, the execution status of each pre-task is queried, the dependency tightness of the target task and the pre-task is obtained by combining the dependency strength, and whether the target task has an unfinished pre-dependent task is analyzed;

[0017] Judgment adjustment module: according to the analysis result and the dependence intensity, it is judged that the preposition dependence task has been completed, the context switching is directly executed, the current task context information is saved, the target task context information is loaded and the scheduling table is updated, if there is an unfinished preposition dependence task, after evaluation combined with the dependence intensity, the task switching sequence is adjusted, the switching operation of the target task is suspended and the target task is marked;

[0018] Conflict-free task screening module: after the task switching sequence adjustment, the range of switchable candidate tasks is determined, the conflict coefficient of each candidate task is calculated, and the screening threshold is calculated, the tasks with conflict coefficient not exceeding the threshold are screened and marked;

[0019] Sorting and executing switching module: the priority of the conflict-free task is calculated, the tasks are sorted in descending order of priority, the context switching of the tasks with high priority is preferentially executed, the actual switching delay is calculated during switching, the new task starts to execute after the switching is completed, and the related information is continuously monitored and updated.

[0020] (Three) beneficial effects

[0021] The application provides a context delay switching method and system based on an embedded operating system, which has the following beneficial effects compared with the prior art:

[0022] Firstly, the application solves the limitation that the traditional static scheduling cannot adapt to the change of runtime task dependence relationship by constructing a dependence relationship graph, collecting and analyzing the dependence intensity and execution state between tasks in real time, in a complex embedded scene, the correlation degree between tasks is quantified by a dependence intensity formula, and real-time state analysis is combined, the task switching sequence can be dynamically adjusted, the key task can be executed in the dependence order, the execution blockage or data error caused by the incomplete preposition task can be avoided, and the switching of the task with unsatisfied dependence can be flexibly suspended, and the conflict-free task is executed, so that the real-time response capability and running stability are improved.

[0023] Secondly, the application realizes accurate screening and priority sorting of candidate tasks by a conflict coefficient calculation formula and a conflict-free task screening threshold formula, overcomes the problem that the traditional priority scheduling easily causes resource competition and deadlock, excludes the tasks in running, completed or hardware exclusive tasks by traversing the task list, calculates the conflict coefficient of the remaining tasks combined with the dependence relationship graph, screens the candidate tasks without dependence conflict with the current task, and comprehensively evaluates the real-time requirement, dependence intensity and conflict coefficient of the task, preferentially executes the high-priority task, reduces invalid switching and resource waiting time, optimizes the resource utilization rate, and improves the overall switching efficiency. DETAILED DESCRIPTION

[0024] Figure 1The flow chart of the context delay switching method based on the embedded operating system of the present application;

[0025] Figure 2 The framework chart of the context delay switching system based on the embedded operating system of the present application. DETAILED DESCRIPTION

[0026] In order to make the objects, contents and advantages of the present application clearer, the specific embodiments of the present application are described in further detail below in combination with the drawings and examples.

[0027] The present application aims to make up for the deficiencies of the prior art, and provides a context delay switching method and system based on an embedded operating system.

[0028] The present application discloses a context delay switching method and system based on an embedded operating system, and relates to the technical field of embedded operating systems.

[0029] The present application provides the following technical solutions to solve the above technical problems: on the one hand, a context delay switching method based on an embedded operating system, the specific steps of which are:

[0030] Building a dependency graph: collecting the dependency relationship between tasks when a new task is created, converting the tasks into nodes with attributes, calculating the dependency strength between tasks, and according to the dependency strength, representing the dependency relationship with directed edges and marking the strength to build a dynamically updated dependency relationship graph;

[0031] Analysis of dependent state: when triggering the context switching requirement, call the dependency graph to determine the target task to be switched and locate its node, traverse the directed edges pointing to the node in reverse and collect all the pre-depending tasks, query the execution status of each pre-task, combine the dependency strength to obtain the dependency tightness of the target task and the pre-task, assist in judging the influence degree of the target task execution when the pre-task is not completed, and analyze whether the target task has an unfinished pre-depending task;

[0032] Judgment and adjustment: according to the analysis result and the dependency strength, it is judged that the pre-depending tasks have been completed, the context switching is directly performed, the context information of the current task is saved, the context information of the target task is loaded and the scheduling table is updated, if there is an unfinished pre-depending task, the task switching order is adjusted after evaluation combined with the dependency strength, the switching operation of the target task is suspended and the target task is marked;

[0033] Screening conflict-free tasks: after adjusting the task switching order, determine the range of candidate tasks that can be switched, calculate the conflict coefficient of each candidate task, and calculate the screening threshold, screen tasks with conflict coefficients not exceeding the threshold and mark them;

[0034] Sorting and executing switching: calculate the priority of conflict-free tasks, sort them from high to low according to the priority, and execute the context switching of tasks with high priority first, calculate the actual switching delay during switching, start the execution of the new task after switching is completed, and continue to monitor and update the relevant information.

[0035] Further, in the construction of the dependency graph, when a new task is created, the dependency relationship between tasks is collected, the dependency relationship between the new task and other existing tasks and tasks created at the same time is input through an interface, and each task is converted into an attribute node containing a unique identifier, type and expected execution time. At the same time, the dependency strength between tasks is calculated through the task dependency strength formula, and the dependency relationship between tasks is represented by directed edges according to the calculated dependency strength, and the corresponding dependency strength value is marked on the directed edges. By continuously adding new task nodes and updating dependency relationships, a dynamically updated dependency relationship graph is constructed.

[0036] Further, in the construction of the dependency graph, the dependency strength between tasks is calculated through the task dependency strength formula, and the task dependency strength formula is:

[0037]

[0038] Wherein, D i,j is the dependency strength of task j to task i, with a value range of [0, 1], T i→j is the time consumption of the output result of task i transmitted to task j, T j is the total execution time of task j, and Ddata the amount of data transmitted from task i to task j, D total the total amount of data required for task j, S i,j a dependency type coefficient, determined according to the dependency type when the task is created, hard dependency S i,j = 1, soft dependency S i,j = 0.5, no dependency S i,j = 0, hard dependency means that task j must wait for the result of task i before execution, soft dependency means that task j can be partially executed without the result of task i, and no dependency means that the two are unrelated, and a, b, g are weight coefficients, and a + b + g = 1.

[0039] Further, in the screening of conflict-free tasks, after adjusting the task switching sequence, the range of candidate tasks that can be switched is first determined by traversing the task list. Specifically, tasks that are currently occupying processor resources for execution are excluded from all tasks because they are in a running state and cannot be immediately switched. Tasks marked as "completed" are excluded because such tasks do not need to be switched. Tasks marked as "execution failed" and cannot be recovered are excluded because such tasks do not have the conditions for switching execution. Tasks that are temporarily unable to be scheduled due to exclusive hardware resources are excluded, and the remaining tasks constitute the range of candidate tasks that can be switched. According to the dependency relationship graph and the dependency strength, the conflict coefficient C k of each candidate task is calculated by the task conflict coefficient calculation formula. th At the same time, the screening threshold C k is calculated by the conflict-free task screening threshold formula. th Tasks with C k < C m∈M are screened out, i.e., tasks that have no dependency conflict with the current execution task and other unfinished tasks, and are marked.

[0040] Further, in the screening of conflict-free tasks, the conflict coefficient C of each candidate task is calculated by the task conflict coefficient calculation formula.

[0041] k = ∑ m∈M D m,k · θ m + ∑ n∈N D k,n · θ n ,

[0042] where C k is the conflict coefficient of task k and unfinished tasks, with a value range of [0, +∞), M is the set of unfinished tasks that task k depends on, N is the set of unfinished tasks that depend on task k, θ m and θ n are the urgency of task m and task n, with a value range of [0, 1], D m,kDependency strength of task k to task m, D k,n Dependency strength of task n to task k.

[0043] Further, the screening of conflict-free tasks, the screening threshold is calculated by the conflict-free task screening threshold formula, and the conflict-free task screening threshold formula is: Wherein, C th Conflict coefficient screening threshold, the value range is [0, 0.5], The historical average conflict coefficient is μ, the current load coefficient is μ, and the value range is [0, 1]. The sensitivity parameter is λ.

[0044] Further, in the sorting and switching execution, the priority of the screened conflict-free task is calculated by using the task switching priority calculation formula, and the task with high priority is selected to execute context switching. When switching, the actual switching delay is calculated by using the context switching delay correction formula, after switching, the new task starts to execute, and the task state and the change of the dependency relationship are monitored, and the related atlas and information are updated.

[0045] Further, in the sorting and switching execution, the priority is calculated by using the task switching priority calculation formula, and the task switching priority calculation formula is:

[0046]

[0047] Wherein, P k The switching priority of task k is ∈, and the minimum value is avoided to be 0. U k The real-time requirement value of task k is U max The maximum real-time requirement value of the task is U The average dependency strength of task k is calculated by using the calculation formula: S is the total number of dependent tasks, D i,k The dependency strength of task k to task i is ω1, ω2, and ω3 are weight coefficients, and ω1+ω2+ω3=1. C k The conflict coefficient of task k is C.

[0048] Further, in the sorting and switching execution, the actual switching delay is calculated by using the context switching delay correction formula, and the context switching delay correction formula is:

[0049]

[0050] Wherein, ΔT k The actual switching delay of task k is T baseis the time consuming of basic context switch, δ is the conflict influence weight coefficient, which is set according to the task characteristics, is the average priority of all tasks, C k is the conflict coefficient of task k.

[0051] In another aspect, a context delay switching system based on an embedded operating system, the system comprising:

[0052] A dependency graph construction module: when a new task is created, the inter-task dependency relationship is collected, the task is converted into a node with attributes, the dependency strength between tasks is calculated, and the dependency relationship is represented by a directed edge and marked with strength according to the dependency strength, and a dynamically updated dependency relationship graph is constructed;

[0053] An analysis dependency state module: when the context switching requirement is triggered, the dependency relationship graph is called to determine the target task to be switched and locate its node, the directed edges pointing to the node are traversed in reverse and all pre-dependence tasks are collected, the execution state of each pre-task is queried, the dependency tightness of the target task and the pre-task is obtained in combination with the dependency strength, and whether the target task has an unfinished pre-dependence task is analyzed;

[0054] A judgment and adjustment module: according to the analysis result and the dependency strength, if all pre-dependence tasks have been completed, the context switching is directly performed, the context information of the current task is saved, the context information of the target task is loaded and the scheduling table is updated, if there is an unfinished pre-dependence task, after evaluation in combination with the dependency strength, the adjustment of the task switching order is performed, the switching operation on the target task is suspended, and the target task is marked;

[0055] A conflict-free task screening module: after the adjustment of the task switching order, the range of switchable candidate tasks is determined, the conflict coefficient of each candidate task is calculated, and a screening threshold is calculated, tasks with a conflict coefficient not exceeding the threshold are screened and marked;

[0056] A sorting and execution switching module: the priority of the conflict-free task is calculated, the tasks are sorted in descending order of priority, the context switching of the tasks with high priority is preferentially performed, the actual switching delay is calculated during switching, the new task starts to execute after the switching is completed, and the related information is continuously monitored and updated.

[0057] Embodiment one:

[0058] Building dependency graph: in the context of delay switching of navigation and multimedia tasks in intelligent vehicle embedded system, after the vehicle starts, a new task "real-time navigation path planning" is created, and the dependency relationship between this task and other tasks is collected: this task must depend on the result of the "GPS positioning signal analysis" task to generate an accurate path (hard dependency), and can refer to part of the data of the "real-time traffic information broadcast" task to optimize the route (soft dependency), and has no dependency association with entertainment tasks such as "vehicle music playing" and "Bluetooth phone call", and each task is converted into a node containing attributes, for example, the "real-time navigation path planning" node contains unique identification, task type "driving assistance type", expected execution time, etc., the "GPS positioning signal analysis" node is marked as a "location service type" task, and the "real-time traffic information broadcast" node is marked as a "data push type" task, then the strength of each dependency relationship is calculated by a task dependency strength formula, and the task dependency strength formula is: wherein, D i,j is the dependency strength of task j to task i, the value range is [0, 1], T i→j is the time consumption of the output result of task i transmitted to task j, T j is the total execution time of task j, D data is the data volume transmitted by task i to task j, D total is the total data volume required by task j, S i,j is the dependency type coefficient, which is determined according to the dependency type when the task is created, hard dependency S i,j =1, soft dependency S i,j =0.5, no dependency S i,j =0, hard dependency means that task j must wait for the result of task i to execute, soft dependency means that task j can partially execute without the result of task i, and no dependency means that the two are unrelated, α, β, γ are weight coefficients, and α+β+γ=1 For example, combining the time consumption proportion, data volume proportion and hard dependency type coefficient of the result transmitted from "GPS positioning signal analysis" to "real-time navigation path planning", the dependency strength of the two is obtained, combining the transmission time consumption proportion, data volume proportion and soft dependency type coefficient of "real-time traffic information broadcast" and "real-time navigation path planning", the corresponding dependency strength is calculated, according to the calculated dependency strength, the related task nodes are connected by directed edges, and the calculated dependency strength value is marked on the edge, at the same time, as new tasks (such as "voice control navigation") are added during vehicle driving, a dynamically updated dependency relationship graph is constructed.

[0059] Analysis of dependent state: when the user triggers the context switching requirement of the "real-time navigation path planning" task by voice instruction in driving, the dependence graph is called to accurately locate the node corresponding to "real-time navigation path planning", and through the reverse traversal of the directed edge pointing to the node, it is determined that the pre-dependent tasks are "GPS positioning signal analysis" and "real-time traffic information broadcast", and the execution status of the two tasks is queried in real time: at this time, "GPS positioning signal analysis" is not completed because the vehicle enters the tunnel and the signal is temporarily interrupted, and "real-time traffic information broadcast" has been completed and the current road congestion has been pushed. Combined with the dependence strength of the two, it can be seen that "GPS positioning signal analysis" as a hard dependence, its incomplete will lead to "real-time navigation path planning" unable to generate effective path, significant impact, while "real-time traffic information broadcast" incomplete will only reduce the path optimization accuracy, less impact, finally analysis that "real-time navigation path planning" exists incomplete key pre-dependent task.

[0060] Judgment and adjustment: according to the analysis result, it is judged that the key pre-dependent task "GPS positioning signal analysis" of "real-time navigation path planning" is not completed, and the dependence strength is high, if forced switching will lead to navigation path error, affect driving safety, therefore, suspend the switching operation of "real-time navigation path planning", and mark it as "waiting for GPS signal recovery", and then perform switching operation after GPS signal recovery, at the same time, keep the "vehicle music playing" task being executed to avoid interrupting user's entertainment experience, and update the system scheduling table to record the suspension state and reason of "real-time navigation path planning".

[0061] Screening conflict-free tasks: after adjusting the task switching order, determine the range of candidate tasks that can be switched: first, exclude the "vehicle music playing" task that is currently occupying the processor resources (in running state cannot be switched immediately), exclude the "Bluetooth device connection initialization" task that has been completed (no need to switch again), exclude the "vehicle external environment camera start" task that fails to execute due to hardware failure and cannot be recovered (no switching condition), exclude the "reverse image display" task that cannot be scheduled temporarily due to occupying the vehicle display screen (hardware resource exclusive), the remaining tasks constitute the candidate range, including "vehicle range estimation", "vehicle temperature regulation" and the like, and according to the dependence relationship graph and dependence strength, the conflict coefficient of each candidate task is calculated through the task conflict coefficient calculation formula, the task conflict coefficient calculation formula is: k =∑ m∈M D m,k ·θ m +∑ n∈N D k,n ·θ n , wherein C kis the conflict coefficient of task k and unfinished tasks, the value range is [0, +∞), M is the set of all unfinished tasks dependent on task k, N is the set of unfinished tasks on which task k depends, θ m is the urgency of task m, the value range is [0, 1], D n is the urgency of task n, the value range is [0, 1], D m,k is the dependency strength of task m to task k, D k,n is the dependency strength of task k to task n, at the same time, the filtering threshold is calculated by the conflict-free task filtering threshold formula, and the conflict-free task filtering threshold formula is: Wherein, C th is the conflict coefficient filtering threshold, the value range is [0, 0.5], is the historical average conflict coefficient, μ is the current load coefficient, the value range is [0, 1], λ is the sensitivity parameter, and the task with C k <C th , that is, the task without dependency conflict with "vehicle music playing" and other unfinished tasks, such as "vehicle temperature regulation" task, is marked, as shown in Figure 1 .

[0062] Sorting and executing switching: for the conflict-free tasks such as "vehicle temperature regulation" selected, the priority is calculated by the task switching priority calculation formula, and the task switching priority calculation formula is: Wherein, P k is the switching priority of task k, ∈ is the minimum value to avoid the denominator being 0, U k is the real-time requirement value of task k, the value range is [1, 10], U max is the maximum real-time requirement value of the task, is the average dependency strength of task k, which is calculated, and the calculation formula is: s is the total number of dependent tasks, D i,k is the dependency strength of task k to task i, ω1, ω2, ω3 are weight coefficients, and ω1+ω2+ω3=1, C k is the conflict coefficient of task k, the priority comprehensively considers the conflict coefficient (the smaller the conflict, the higher the priority), the real-time requirement (the user adjusts the temperature many times recently, and the real-time requirement is high), and the average dependency strength (the dependency to other tasks is less, and the priority is improved), and after sorting in descending order of priority, the "vehicle temperature regulation" task is ranked first due to high real-time requirement and small conflict, and the context switching of the "vehicle temperature regulation" task is preferentially executed, and the actual switching delay is calculated by the context switching delay correction formula during the switching process, and the context switching delay correction formula is: Wherein, ΔT k is the actual switching delay of task k, Tbase is the base context switch overhead, δ is the conflict impact weight coefficient, which is set according to the task characteristics, is the average priority of all tasks in the system, C k is the conflict coefficient of task k, the delay is based on the base context switch overhead, and is modified by combining the task conflict coefficient, the system average priority, and the conflict impact weight coefficient, so as to more accurately control the time cost in the context switching process and provide an accurate time reference for task scheduling. After the switching is completed, the "in-vehicle temperature regulation" task starts to execute, adjusts the air conditioner operating state according to the user's preset temperature, and continuously monitors the state changes of the "GPS positioning signal analysis" task and the update of the dependency graph, so as to prepare for the switching of the subsequent "real-time navigation path planning" task.

[0063] In summary, in the intelligent vehicle embedded system, by constructing a dynamic dependency graph, the dependency relationships between navigation, entertainment and other tasks are clearly sorted out. When the navigation task switching demand is triggered, the completion status of the pre-dependent task can be analyzed, and whether it is suitable to switch can be judged according to the dependency strength, so as to avoid navigation errors caused by incomplete key dependencies. By screening non-conflict tasks and executing switching according to priority, the timely response of tasks such as in-vehicle temperature regulation is ensured, and the efficiency and stability of task switching are realized, and the operation reliability and user experience of the vehicle-mounted system are improved.

[0064] Example Two:

[0065] Constructing dependency graph: In the context delay switching scenario of production line automation control tasks in industrial embedded systems, when the production line of the intelligent factory is started, a new task "precision part assembly control" is created, and the dependency relationships between this task and other production tasks are collected: this task must wait for the "part size visual detection" task to complete (hard dependency), otherwise the assembly precision cannot be ensured, and it can also refer to part of the data of the "conveyor belt running speed monitoring" task to adjust the assembly rhythm (soft dependency), and has no dependency with auxiliary tasks such as "workshop environment temperature and humidity monitoring" and "equipment energy consumption statistics". Each task is converted into a node containing attributes, the "precision part assembly control" node is marked as a "core control class" task, containing a unique identifier and an expected execution time, the "part size visual detection" node is marked as a "quality detection class" task, and the "conveyor belt running speed monitoring" node is marked as a "device monitoring class" task. Then, the strength of each dependency relationship is calculated by the task dependency strength formula, which is: For example, the time-consuming proportion, data volume proportion, and hard dependency type coefficient of the detection result transmitted from "part size visual detection" to "precision part assembly control" are combined to obtain the dependency strength of the two, and the dependency strength of "conveyor running speed monitoring" and "precision part assembly control" is calculated in the same way. According to the calculated dependency strength, the corresponding nodes are connected by directed edges marked with strength to construct a dynamic dependency graph. When tasks such as "part grabbing robot control" are added later, the dependency relationship in the graph is updated in a timely manner, as shown in Figure 2 .

[0066] Analysis of dependency state: When the production line enters the part assembly stage, the context switching requirement of the "precision part assembly control" task is triggered, and the dependency relationship graph is immediately called to locate the task node. By traversing the directed edges pointing to the node in reverse, it is determined that the pre-dependent tasks of the node are "part size visual detection" and "conveyor running speed monitoring". The execution status of the two tasks is queried: "part size visual detection" has not been completed due to temporary failure of the detection camera, and "conveyor running speed monitoring" has normally output the current speed data. According to the analysis of the dependency strength, it is known that "part size visual detection" is a hard dependency, and its incomplete execution will lead to the inability to judge whether the parts are qualified during assembly, which may cause product scrap. The incomplete execution of "conveyor running speed monitoring" will only slightly slow down the assembly rhythm, so the existence of the key pre-dependent task of "precision part assembly control" is determined.

[0067] Judgment and adjustment: Based on the analysis result, it is determined that the key pre-dependent task of "precision part assembly control" is "part size visual detection", and the dependency strength between the two is high. If the switching is forced, it will cause production quality problems. Therefore, the switching operation of "precision part assembly control" is suspended, and it is marked as "waiting for visual detection to recover". After the visual detection is restored, the switching operation is performed again. At the same time, the "conveyor speed control" task that is currently being executed is kept running to ensure the normal operation of other links of the production line. The scheduling table is updated to record the suspended state of "precision part assembly control".

[0068] Screening conflict-free tasks: After adjusting the switching order, the range of candidate tasks that can be switched is determined: excluding the currently running "conveyor speed control" task, excluding the completed "raw material warehouse scanning" task, excluding the "part weight detection" task that fails to execute due to sensor damage, and excluding the "remote device diagnosis" task that occupies a dedicated communication interface (hard resource exclusive). The remaining candidate tasks include "assembly tool wear monitoring", "production line yield statistics", etc. The conflict coefficient of each candidate task is calculated by the task conflict coefficient calculation formula, which takes into account the dependency strength of the task and the incomplete task, as well as the urgency of the incomplete task. The task conflict coefficient calculation formula is: k C m∈M =∑ m,k D ·θm +∑ n∈N D k,n ·θ n , and the threshold value is calculated by a non-conflict task screening threshold formula, which is determined in combination with the historical average conflict coefficient, the current production line load and the sensitivity parameter, and the non-conflict task screening threshold formula is: tasks with C k <C th , such as the "assembly tool wear monitoring" task (without dependency conflict with other tasks), are screened out and marked.

[0069] The switching is sequenced and executed: for the screened non-conflict tasks such as the "assembly tool wear monitoring" task, the priority is calculated by a task switching priority calculation formula, which comprehensively considers the task conflict coefficient (the priority is high if the conflict is small), the real-time requirement (the tool wear may affect the assembly accuracy, so the real-time requirement is high), and the average dependency strength (less dependency on other tasks), and the task switching priority calculation formula is: and sequenced according to the priority, the "assembly tool wear monitoring" task is ranked first due to the high real-time requirement, and the context switching of the task is preferentially executed, and the actual switching delay is calculated by a context switching delay correction formula based on the basic switching time consumption, in combination with the task conflict coefficient, the system average priority and the conflict influence weight coefficient correction, so as to more accurately control the time cost in the context switching process and provide an accurate time reference for task scheduling, and the context switching delay correction formula is: After the switching is completed, the "assembly tool wear monitoring" task starts to be executed, and the fault repair state of the "part size visual detection" task and the update of the dependency graph are continuously monitored to prepare for the switching of the subsequent "precision part assembly control" task.

[0070] In summary, in the production line control of an industrial embedded system, the association of tasks such as precision assembly and visual detection is clarified by constructing a task dependency graph, when the assembly task needs to be switched, the execution state of the pre-position detection task can be effectively analyzed, the inappropriate switching operation is suspended based on the dependency strength, the production quality is guaranteed, the non-conflict tasks are screened and executed according to the priority, and the timely operation of key auxiliary tasks such as tool wear monitoring is ensured, the task switching sequence is dynamically adjusted throughout the process, the dependency information is continuously updated, the rationality and efficiency of the production line task scheduling are significantly improved, and the production failure risk caused by task conflict is reduced.

[0071] Compared with the prior art, the context delay switching method and system based on an embedded operating system have the following beneficial effects:

[0072] One, the application solves the limitation that the traditional static scheduling cannot adapt to the change of runtime task dependency relationship by constructing dependency graph, collecting and analyzing the dependency strength and execution state between tasks in real time, in complex embedded scenarios, the correlation degree between tasks is quantified by the dependency strength formula, combined with real-time state analysis, the task switching order can be dynamically adjusted, the key task can be executed according to the dependency order, the execution block or data error caused by the incomplete completion of the preceding task can be avoided, and the switching of the task with unsatisfied dependency can be flexibly paused, and the conflict-free task is executed, so that the real-time response capability and running stability are improved.

[0073] Two, the application realizes accurate screening and priority sorting of candidate tasks through the conflict coefficient calculation formula and the conflict-free task screening threshold formula, overcomes the problem that the traditional priority scheduling is easy to cause resource competition and deadlock, excludes the tasks in running, completed or hardware exclusive tasks by traversing the task list, calculates the conflict coefficient of the remaining tasks combined with the dependency graph, screens the candidate tasks without dependency conflict with the current task, and comprehensively evaluates the real-time requirement, dependency strength and conflict coefficient of the task, preferentially executes the high-priority task, reduces invalid switching and resource waiting time, so as to optimize the resource utilization rate and improve the overall switching efficiency.

[0074] The above is only the preferred embodiment of the application, it should be pointed out that for ordinary skilled person in the art, without departing from the technical principles of the application, a number of improvements and modifications can be made, these improvements and modifications should also be regarded as the protection scope of the application.

Claims

1. A method for context delay switching based on an embedded operating system, characterized in that, The method comprises: Building a dependency graph: collecting the dependency relationship between tasks when a new task is created, converting the tasks into attribute-containing nodes, calculating the dependency strength between tasks, and according to the dependency strength, representing the dependency relationship with a directed edge and marking the strength, and building a dynamically updated dependency relationship graph; Analyzing the dependency state: when the context switching requirement is triggered, the dependency relationship graph is called to determine the target task to be switched and locate its node, the directed edges pointing to the node are traversed in reverse and all pre-dependent tasks are collected, the execution status of each pre-task is queried, the dependency tightness of the target task and the pre-task is obtained by combining the dependency strength, the influence degree of the target task execution when the pre-task is not completed is judged, and whether the target task has an unfinished pre-dependent task is analyzed; Judgment and adjustment: according to the analysis result and the dependency strength, if all pre-dependent tasks have been completed, the context switching is directly executed, the context information of the current task is saved, the context information of the target task is loaded and the scheduling table is updated, if there are unfinished pre-dependent tasks, the task switching order is adjusted after evaluation according to the dependency strength, the switching operation on the target task is suspended and the target task is marked; Screening conflict-free tasks: after adjusting the task switching order, the range of switchable candidate tasks is determined, the conflict coefficient of each candidate task is calculated, and a screening threshold is calculated, and tasks with a conflict coefficient not exceeding the threshold are screened and marked; Sorting and executing switching: the priority of the conflict-free tasks is calculated, the tasks are sorted in descending order of priority, the context switching of the tasks with high priority is preferentially executed, the actual switching delay is calculated during switching, the new task starts to execute after switching is completed, and related information is continuously monitored and updated.

2. The method of claim 1, wherein the context delay switch of the embedded-based operating system is characterized by, In the step of building a dependency graph, the dependency relationship between tasks is collected when a new task is created, the dependency relationship between the new task and other existing tasks and tasks created at the same time is input through an interface, and each task is converted into an attribute node containing a unique identifier, a type and an expected execution duration. At the same time, the dependency strength between tasks is calculated through a task dependency strength formula, the dependency relationship between tasks is represented by a directed edge according to the calculated dependency strength, and the corresponding dependency strength value is marked on the directed edge. By continuously adding new task nodes and updating the dependency relationship, a dynamically updated dependency relationship graph is constructed.

3. The method of claim 2, wherein the context delay switch of the embedded-based operating system is characterized by, In the step of building a dependency graph, the dependency strength between tasks is calculated through a task dependency strength formula, and the task dependency strength formula is: wherein, D i,j is the dependency strength of task j on task i, taking value in the range [0, 1], T i→j is the time cost of transmitting the output result of task i to task j, T j is the total execution time of task j, D data is the data volume transmitted from task i to task j, D total is the total data volume required by task j, S i,j is the dependency type coefficient, determined according to the dependency type when the task is created, S i,j = 1 for hard dependency, S i,j = 0.5 for soft dependency, and S i,j = 0 for no dependency, the hard dependency means that task j must wait for the result of task i before execution, the soft dependency means that task j can partially execute without the result of task i, and the no dependency means that the two tasks are irrelevant, and a, b, g are weight coefficients and a + b + g = 1.

4. The method of claim 3, wherein the context delay switch of the embedded-based operating system is characterized by, In the conflict-free task screening, after adjusting the task switching sequence, the range of switchable candidate tasks is first determined by traversing the task list: exclude the tasks currently occupying processor resources for execution, as they are in a running state and cannot be immediately switched; exclude tasks marked as "completed", which do not need to be switched; exclude tasks marked as "execution failed" and cannot be recovered, which do not have the conditions for switching execution; exclude tasks that cannot be scheduled temporarily due to hardware resource monopoly, then the remaining tasks constitute the range of switchable candidate tasks, and according to the dependency graph and dependency strength, the conflict coefficient C of each candidate task is calculated by the task conflict coefficient calculation formula k At the same time, the conflict-free task screening threshold value C is calculated by the conflict-free task screening threshold value formula th Tasks with C k <C th , that is, tasks that have no dependency conflict with the current execution task and other unfinished tasks, are screened out and marked.

5. The method of claim 4, wherein the context delay switch of the embedded-based operating system is characterized by, In the step of screening conflict-free tasks, the conflict coefficient of each candidate task is calculated through a task conflict coefficient calculation formula, and the task conflict coefficient calculation formula is: wherein C k is the conflict coefficient of task k with unfinished tasks, taking the value range [0, +∞), M is the set of unfinished tasks on which task k depends, N is the set of unfinished tasks that depend on task k, θ m , θ n is the urgency of task m, task n, taking the value range [0, 1], D m,k is the dependency strength of task k to task m, D k,n is the dependency strength of task n to task k.

6. The method of claim 5, wherein the context delay switch of the embedded-based operating system is characterized by, In the step of screening conflict-free tasks, the screening threshold is calculated through a conflict-free task screening threshold formula, and the conflict-free task screening threshold formula is: where C th is the conflict coefficient filtering threshold, taking the value range [0, 0.5], is the historical average conflict coefficient, μ is the current load coefficient, taking the value range [0, 1], and λ is the sensitivity parameter.

7. The method of claim 5, wherein the context delay switch of the embedded-based operating system is characterized by, In the sorting and performing switching, the priority of the screened conflict-free task is calculated by using a task switching priority calculation formula, the tasks are sorted in descending order of priority, and the context switching of the task with high priority is preferentially selected; when switching, the actual switching delay is calculated by using a context switching delay correction formula, after the switching is completed, the new task starts to execute, and the task state and the change of the dependency relationship are continuously monitored, and the related graph and information are updated.

8. The method of claim 7, wherein the context delay switch of the embedded-based operating system is characterized by, In the sorting and performing switching, the priority is calculated by using a task switching priority calculation formula, wherein the task switching priority calculation formula is: where P k is the switching priority of task k, ∈ is a minimum value to avoid denominator 0, U k is the real-time requirement value of task k, and the value range is [1, 10], U max is the maximum real-time requirement value of the task, is the average dependence intensity of task k, which is calculated by the following formula: s is the total number of dependencies, D i,k is the dependency strength of task k on task i, ω1, ω2, ω3 are weight coefficients, and ω1+ω2+ω3=1, C k is the conflict coefficient of task k.

9. The method of claim 8, wherein the context delay switch is performed by the embedded operating system. In the sorting and performing switching, the actual switching delay is calculated by using a context switching delay correction formula, wherein the context switching delay correction formula is: where ΔT k is the actual switching latency of task k, T base is the base switching latency, δ is the conflict impact weight coefficient, which is set according to the task characteristics, is the average priority of all tasks, C k is the conflict coefficient of task k.

10. A context delay switching system based on an embedded operating system, characterized in that, The system comprises: A dependency graph construction module: when a new task is created, the dependency relationship between tasks is collected, the tasks are converted into nodes with attributes, the dependency strength between tasks is calculated, the dependency relationship is represented by a directed edge and marked with strength according to the dependency strength, and a dynamically updated dependency relationship graph is constructed; An analysis dependency state module: when the context switching demand is triggered, the dependency relationship graph is called, the target task to be switched is determined and the node thereof is located, the directed edge pointing to the node is traversed in reverse and all pre-dependent tasks are collected, the execution state of each pre-dependent task is queried, the dependency tightness between the target task and the pre-dependent task is obtained in combination with the dependency strength, and whether the target task has an uncompleted pre-dependent task is analyzed; A judgment and adjustment module: according to the analysis result and the dependency strength, it is judged that if all the pre-dependent tasks have been completed, the context switching is directly performed, the context information of the current task is saved, the context information of the target task is loaded and the scheduling table is updated, if there is an uncompleted pre-dependent task, after evaluation in combination with the dependency strength, the adjustment of the task switching order is performed, the switching operation on the target task is suspended, and the target task is marked; A conflict-free task screening module: after the adjustment of the task switching order, the range of the switchable candidate tasks is determined, the conflict coefficient of each candidate task is calculated, and a screening threshold is calculated, the task with a conflict coefficient not exceeding the threshold is screened and marked; A sorting and performing switching module: the priority of the conflict-free task is calculated, the tasks are sorted in descending order of priority, the context switching of the task with high priority is preferentially performed, the actual switching delay is calculated when switching, after the switching is completed, the new task starts to execute, and the related information is continuously monitored and updated.

Citation Information

Cited By

  • Vehicle-mounted information delivery decision-making system and method based on machine learning

    CN121882939A