WO2025256541A1 - 资源调度的方法、装置和系统 - Google Patents
资源调度的方法、装置和系统Info
- Publication number
- WO2025256541A1 WO2025256541A1 PCT/CN2025/100335 CN2025100335W WO2025256541A1 WO 2025256541 A1 WO2025256541 A1 WO 2025256541A1 CN 2025100335 W CN2025100335 W CN 2025100335W WO 2025256541 A1 WO2025256541 A1 WO 2025256541A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- thread
- application
- function
- stub
- computing resource
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
Definitions
- This application relates to the field of intelligent driving, specifically to methods, apparatus and systems for resource scheduling.
- the end-to-end latency of the data flow link of the autonomous driving system is a key indicator for measuring the response speed of autonomous driving.
- Low end-to-end latency e.g., less than 100ms
- the autonomous driving system needs to allocate corresponding computing resources to realize the business corresponding to different data flow links. How to reasonably schedule resources for application nodes of different data flow links in autonomous driving applications is an urgent problem to be solved at this stage.
- This application provides a method, apparatus, and system for resource scheduling, which can reasonably allocate computing resources to threads under application nodes corresponding to different key data streams in autonomous driving applications. This helps to reduce end-to-end latency and latency jitter of key data streams in autonomous driving systems, and further ensures the safety of vehicle owners and pedestrians outside the vehicle.
- a resource scheduling method comprising: running a first application, the first application including a first key data stream, the first key data stream being used to determine the output of the first application, the first key data stream being associated with N threads under M processes, the M processes including a first process, the first process being associated with a first thread, a first function and a first stub, the first thread being used to run the first function, M and N being positive integers; allocating a first computing resource to the first thread according to the first stub, the first computing resource being used by the first thread to run the first function.
- this method can be executed by the operating system.
- the operating system after the operating system reaches the first stub of the first application, it can not only identify the first function associated with the first stub as a critical function, but also allocate sufficient computing resources (i.e., first computing resources) to the first thread running the first function. This ensures that the first thread has sufficient computing resources to run the first function efficiently and quickly. Furthermore, when the first thread runs other functions, the operating system can reallocate computing resources to the first thread instead of continuously allocating the first computing resources. This allows the operating system to dynamically allocate computing resources to threads at the function level, helping to allocate more surplus resources to other threads running critical functions, thereby reducing the end-to-end latency of the first critical data stream. Especially when the first application is an autonomous driving application, it can effectively improve the user's driving experience and ensure the safety of passengers inside the vehicle, pedestrians outside the vehicle, and other vehicles.
- first computing resources i.e., first computing resources
- the capacity of the first computing resource is determined based on the first stub, and the first computing resource is allocated to the first thread based on the capacity of the first computing resource; or, the order of the first computing resources is determined based on the first stub, and the first computing resource is allocated to the first thread based on the order of the first computing resources; or, a first occupancy rate is determined based on the first stub, the first occupancy rate being used to represent the occupancy rate of the first computing resource among all computing resources, and the first computing resource is allocated to the first thread based on the first occupancy rate.
- all the aforementioned computing resources refer to the computing resources allocated within a first time frame.
- This first time frame refers to the time frame during which the execution times of other threads overlap with those of the first thread.
- all the aforementioned computing resources refer to the computing resources allocated to the first thread and other threads within this first time frame. Based on this, since the first occupancy rate is calculated using a fraction, the denominator of which can be used to represent the sum of the computing resources allocated to other threads within the first time frame and the aforementioned first computing resources, while the numerator of this fraction represents the first computing resources.
- the operating system can reclaim the first computing resources allocated to the first thread, or reduce the allocation of computing resources.
- the operating system can then reallocate or adjust the computing resources allocated to the first thread based on this method.
- the operating system can schedule computing resources based on priority, and priority can be used to represent the capacity, order, or weight of the first computing resource allocated to the first thread.
- the first stub indicates the capacity, order, or weight of the first computing resource allocated by the operating system to the first thread, so that the first thread can obtain sufficient computing resources when running the first function corresponding to the first stub, thereby enabling the operating system to achieve resource scheduling based on function granularity.
- the first stub is added to the first application during the execution of the first application; or, the first stub is added to the first application before the first application is executed.
- the first stub mentioned above can be a dynamic stub, a static stub, or it can be replaced with a custom application programming interface (API).
- API application programming interface
- pile points can be inserted into the first application through various pile insertion methods, thereby increasing the flexibility of pile insertion.
- the first application further includes a second key data stream used to determine the output of the first application.
- the second key data stream is associated with N threads under M processes.
- the M processes also include a second process, which is associated with a second thread, a second function, and a second stub.
- the second thread is used to run the second function.
- a first configuration file a first dependency relationship between the second thread and the first thread is determined.
- the first configuration file is used to indicate the dependency relationship between the aforementioned M processes and/or the aforementioned N threads.
- the second thread is allocated second computing resources.
- the second computing resources are used for the second thread to run the second function.
- the first dependency relationship is that the operation of the first thread depends on the second thread, the first computing resources are more than the second computing resources; or, if the first dependency relationship is that the operation of the second thread depends on the first thread, the first computing resources are less than the second computing resources.
- first and second key data streams are the same, and the second key data stream can also be understood as a mirror image of the first key data stream.
- the aforementioned first configuration file can be obtained through pre-experimentation.
- the first application is a program used to implement autonomous driving services, and this first application is installed on the autonomous driving system.
- the vehicle can be controlled to conduct test runs based on the first application.
- historical data of each thread running each function in the first application will be generated. This historical data may include station information, the timing of each thread's function execution, and the dependencies between threads during function execution.
- the aforementioned first configuration file can be determined and provided to the operating system for subsequent resource scheduling.
- an autonomous driving system is an application system, and application systems run in an environment provided by the operating system.
- the first process is also associated with a third stub.
- the third stub is adjacent to the first stub and is located before the first stub.
- a third computing resource is allocated to the first thread.
- the third computing resource is less than or equal to the first computing resource.
- the third computing resource is used to ensure that the first thread runs the first function.
- the aforementioned third stub can be set at the exit position of the third function, which is located before the first function in timing. If an exit stub is set at the exit of the third function, the third stub can be an exit stub associated with the third function. That is, after the third function is executed, the third stub is run directly, thereby allocating third computing resources to the first thread in advance.
- the first thread is bound to a first processor core and a second processor core, respectively.
- the first processor core and the second processor core are respectively configured to provide first computing resources for the first thread.
- the first resource utilization rate after the first processor core provides the first computing resources to the first thread is predicted. If the first resource utilization rate is less than or equal to a first threshold, the first computing resources are provided to the first thread through the first processor core. If the first resource utilization rate is greater than the first threshold, the second resource utilization rate after the second processor core provides the first computing resources to the first thread is predicted. If the second resource utilization rate is less than or equal to the first threshold, the first computing resources are provided to the first thread through the second processor core.
- the third resource utilization rate after the third processor core provides the first computing resources to the first thread is predicted, and the third processor core is not bound to the first thread; if the third resource utilization rate is less than or equal to the first threshold, the first computing resources are provided to the first thread through the third processor core.
- the first threshold mentioned above may be a threshold preset based on the operating system hardware performance.
- a first timer is started, and the duration of the first timer is set to be greater than or equal to the duration required to complete the first function; if the first timer times out and the first function has not completed its execution, the first computing resources allocated to the first thread are reduced.
- the first application further includes a fourth function, which obtains a preset first runtime period, the first runtime period being greater than or equal to the duration required to complete the fourth function; and within the first runtime period starting from the moment the fourth function is executed, allocates a fourth computing resource for the thread used to run the fourth function, the fourth computing resource being greater than or equal to the first computing resource.
- the first runtime segment mentioned above can be obtained through external input or preset before the system runs.
- a method for processing an application is provided. This method is used to process a first application, which is run by an operating system.
- the operating system allocates first computing resources by default to threads used to run functions in the first application.
- the method includes: adding N stubs to the first application, where N is a positive integer.
- the N stubs are associated with N key functions in the first application, and the key functions are associated with key data streams.
- the key data streams are used to determine the output of the first application, and the key functions are used to determine the output of the key data streams.
- the stubs are used to indicate the allocation of second computing resources to threads used to run the key functions, where the second computing resources are more than the first computing resources.
- the operating system mentioned above can be a Linux operating system or a Windows operating system, and this application embodiment does not limit it.
- the operating system can set priorities for the threads used to run the first application, and the priority of a thread determines how much computing resources the operating system allocates to that thread. Therefore, the operating system can schedule computing resources for threads by setting priorities.
- the system can dynamically adopt a privileged scheduling scheme for the thread running the critical function in real time when it reaches the stub, or allocate specified computing resources to the thread running the critical function. This ensures that the thread has sufficient computing resources to complete the execution of the critical function, enabling the operating system to dynamically allocate computing resources to threads at the function granularity, and ensuring that the critical process chain in the application can be completed as soon as possible, reducing the end-to-end latency of data transmission in the critical chain.
- a first warm-up stub is added between the first pre-function and the first stub, wherein the first pre-function runs before the first function and is adjacent to the first function, the first function is one of the N key functions, the first function is associated with the first stub, the first stub is one of the N stubs, and the first warm-up stub is used to indicate the allocation of a third computing resource for the thread running the first function, the third computing resource being less than or equal to the second computing resource.
- the operating system can run to the first preheating stub before running the first function, which is a key function. Based on the indication of the first preheating stub, the operating system can allocate corresponding computing resources in advance for the thread to run the first function, so as to ensure that the thread has computing resources to run the first function. This effectively avoids the computing resources used to run the first function being preempted by other key functions when the system runs the first function, thus ensuring the operation of the first function.
- a first application is run to obtain historical data, which is used to indicate the runtime sequence of multiple processes and/or multiple threads participating in running the first application; based on the historical data, a first configuration file is generated, which is used to indicate the runtime dependencies between the multiple processes and/or the multiple threads, and the first configuration file is also used to determine the aforementioned second computing resources.
- a resource scheduling apparatus comprising: a running unit for running a first application, the first application including a first key data stream used to determine the output of the first application, the first key data stream being associated with N threads under M processes, the M processes including a first process, the first process being associated with a first thread, a first function and a first stub, the first thread being used to run the first function, and M and N being positive integers; and a first operation unit for allocating a first computing resource to the first thread according to the first stub, the first computing resource being used by the first thread to run the first function.
- the aforementioned first operation unit is specifically used to: determine the capacity of the first computing resource based on the first stub, and allocate the first computing resource to the first thread based on the capacity of the first computing resource; or, determine the order of the first computing resources based on the first stub, and allocate the first computing resource to the first thread based on the order of the first computing resources; or, determine the first occupancy rate based on the first stub, the first occupancy rate being used to represent the occupancy rate of the first computing resource among all computing resources, and allocate the first computing resource to the first thread based on the first occupancy rate.
- the aforementioned first stub is added to the first application during the execution of the first application; or, the aforementioned first stub is added to the first application before the execution of the first application.
- the aforementioned first application further includes a second key data stream used to determine the output of the first application.
- This second key data stream is associated with N threads under M processes.
- the M processes also include a second process, which is associated with a second thread, a second function, and a second stub.
- the second thread is used to run the second function.
- the apparatus further includes a determining unit used to determine a first dependency relationship between the second thread and the first thread based on a first configuration file, the first configuration file indicating the dependency relationship between the M processes and/or the N threads.
- the first operating unit is further used to allocate second computing resources to the second thread based on the second stub and the first dependency relationship.
- the second computing resources are used for the second thread to run the second function.
- the first computing resources are more than the second computing resources; or, in the case where the first dependency relationship is that the operation of the second thread depends on the first thread, the first computing resources are less than the second computing resources.
- the first process is also associated with a third stub.
- the third stub is adjacent to the first stub and is located before the first stub.
- the first operation unit is also used to: allocate a third computing resource to the first thread according to the third stub, the third computing resource being less than or equal to the first computing resource, and the third computing resource being used to ensure that the first thread runs the first function.
- the first thread is bound to a first processor core and a second processor core, respectively.
- the first processor core and the second processor core are respectively configured to provide first computing resources to the first thread.
- the device further includes: a prediction unit, configured to predict a first resource utilization rate after the first processor core provides the first computing resources to the first thread; if the first resource utilization rate is greater than a first threshold, the prediction unit is further configured to predict a second resource utilization rate after the second processor core provides the first computing resources to the first thread; if the second resource utilization rate is less than or equal to the first threshold, the first operation unit is specifically configured to provide the first computing resources to the first thread through the second processor core; or, if the second resource utilization rate is greater than the first threshold, the prediction unit is further configured to predict a third resource utilization rate after the third processor core provides the first computing resources to the first thread, wherein the third processor core is not bound to the first thread; if the third resource utilization rate is less than or equal to the first threshold, the first operation
- the above-mentioned apparatus further includes: a second operation unit, configured to start a first timer at the beginning of the first thread running the first function, wherein the duration of the first timer is greater than or equal to the duration required to complete the first function; the first operation unit is further configured to reduce the first computing resources allocated to the first thread if the first timer times out and the first function has not completed its execution.
- the first application further includes a fourth function
- the device further includes: an acquisition unit, configured to acquire a preset first runtime period, the first runtime period being greater than or equal to the duration required to complete the fourth function; the first operation unit is further configured to allocate a fourth computing resource to the thread for running the fourth function within the first runtime period from the moment the fourth function is executed, the fourth computing resource being greater than or equal to the first computing resource.
- an apparatus for processing an application is provided.
- This apparatus is used to process a first application run by an operating system, and the operating system allocates first computing resources by default to threads running functions within the first application.
- the apparatus includes: an instrumentation unit for adding N stubs to the first application, where N is a positive integer; the N stubs are respectively associated with N key functions in the first application; the key functions are associated with key data streams; the key data streams determine the output of the first application; the key functions determine the output of the key data streams; and the stubs indicate the allocation of second computing resources to threads running the key functions, where the second computing resources are greater than the first computing resources.
- the instrumentation unit described above is further configured to add a first warm-up stub between the first pre-function and the first stub, wherein the execution order of the first pre-function precedes the first function and is adjacent to the first function, the first function is one of the N key functions, the first function is associated with the first stub, the first stub is one of the N stubs, and the first warm-up stub is used to indicate the allocation of a third computing resource for the thread used to run the first function, the third computing resource being less than or equal to the second computing resource.
- the above-mentioned apparatus further includes: a running unit for running a first application to obtain historical data, the historical data being used to indicate the runtime sequence of multiple processes and/or multiple threads participating in running the first application; and a processing unit for generating a first configuration file based on the historical data, the first configuration file being used to indicate the runtime dependencies between the multiple processes and/or the multiple threads, the first configuration file also being used to determine the second computing resource.
- an electronic device including a processor and a memory, wherein the processor is connected to a memory, wherein the memory is used to store program code, and the processor is used to call the program code to execute a method in any possible implementation of the method design of the first aspect above, or to execute a method in any possible implementation of the method design of the second aspect above.
- an autonomous driving system including a first operating system for executing methods in any possible implementation of the method design described in the first aspect above.
- the aforementioned first operating system is further used to: run a first application to obtain historical data, the historical data being used to indicate the runtime sequence of the M processes and/or N threads participating in running the first application; and generate a first configuration file based on the historical data, the first configuration file being used to indicate the runtime dependencies between the M processes and/or N threads.
- a vehicle in a seventh aspect, includes an autonomous driving system as described in any possible implementation of the system design in the sixth aspect above.
- a chip system which is applied to an electronic device.
- the chip system includes one or more interface circuits and one or more processors.
- the interface circuits and processors are interconnected via lines.
- the interface circuits are used to receive signals from the memory of the electronic device and send signals to the processor, the signals including computer instructions stored in the memory.
- the processor executes the computer instructions
- the electronic device executes the method in any possible implementation of the method design of the first aspect above, or executes the method in any possible implementation of the method design of the second aspect above.
- a computer-readable storage medium storing a computer program or instructions for implementing the method in any possible implementation of the method design of the first aspect, or implementing the method in any possible implementation of the method design of the second aspect.
- a computer program product wherein when the computer program code or instructions are executed on a computer, the computer performs the method in any possible implementation of the method design of the first aspect above, or performs the method in any possible implementation of the method design of the second aspect above.
- FIG. 1 is a functional schematic block diagram of a vehicle 100 provided in an embodiment of this application;
- Figure 2 is a schematic diagram of the architecture of an autonomous driving system 200 proposed in an embodiment of this application;
- FIG. 3 is a schematic diagram of the operation of the timing awareness layer and resource regulation layer proposed in the embodiments of this application;
- Figure 4 is a flowchart illustrating a resource scheduling method 400 proposed in an embodiment of this application.
- Figure 5 is a schematic diagram of another resource scheduling method 500 proposed in an embodiment of this application.
- Figure 6 is a schematic diagram illustrating the principle of another resource scheduling method 600 proposed in an embodiment of this application.
- Figure 7 is a schematic diagram of the principle of a processor core binding method 700 proposed in an embodiment of this application.
- Figure 8 is a schematic block diagram of a resource scheduling apparatus 800 provided in an embodiment of this application.
- Figure 9 is a schematic block diagram of an application processing device 900 provided in an embodiment of this application.
- references to "one embodiment” or “some embodiments” as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases “in one embodiment,” “in some embodiments,” “in other embodiments,” “in still other embodiments,” etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean “one or more, but not all, embodiments,” unless otherwise specifically emphasized.
- the terms “comprising,” “including,” “having,” and variations thereof mean “including but not limited to,” unless otherwise specifically emphasized.
- “at least one” refers to one or more, and “more than one” refers to two or more.
- “And/or” describes the relationship between related objects, indicating that three relationships can exist. For example, A and/or B can represent: A alone, A and B simultaneously, and B alone, where A and B can be singular or plural. The character “/” generally indicates that the preceding and following related objects are in an “or” relationship. “At least one of the following” or similar expressions refer to any combination of these items, including any combination of single or plural items.
- At least one of a, b, or c can represent: a, b, c, a-b, a-c, b-c, or a-b-c, where a, b, and c can be single or multiple.
- the technical solutions in this application embodiment can be applied to computing devices, such as servers, mainframes, personal computers, laptops, desktops, and other devices with computing capabilities.
- the technical solutions in this application embodiment can also be applied to computing devices that include heterogeneous chips or embedded chips.
- Autonomous driving intelligent operating system An operating system based on the portable operating system interface (POSIX) standard, suitable for the high-performance computing and high-bandwidth communication required for autonomous driving, providing functions such as vehicle environment perception, intelligent decision-making and path planning.
- POSIX portable operating system interface
- Application Nodes In the autonomous driving intelligent operating system, applications with specific autonomous driving functions (such as perception, fusion, and planning), encapsulated using communication middleware, are typically single-process, multi-threaded collections. Two or more nodes communicate by calling the communication middleware's APIs for sending and receiving messages, enabling the transfer of messages and services between processes or components.
- the communication middleware can be a robot operating system (ROS), or the communication module (CM) module in an automotive open system architecture (AUTOSAR CM), etc.
- ROS robot operating system
- CM communication module
- AUTOSAR CM automotive open system architecture
- Critical Links These are links of processes connected by application nodes that determine the output of a system or application.
- the link formed by processes that process sensor signals to generate controller signals determines the control content included in the controller signals.
- This link can be defined as a critical link, also known as a critical process link or a critical node link.
- the application nodes that constitute a critical link can be called critical nodes or critical processes. Threads within a critical process that participate in the critical link's operations can be called critical threads. Functions called by critical threads that participate in the critical link's operations, such as subscription, callback, and publish functions in the communication operations of an autonomous driving system, can be called critical functions.
- critical processes/nodes include both critical and non-critical threads, while non-critical processes/nodes only include non-critical threads; critical threads can call both critical and non-critical functions, while non-critical threads can only call non-critical functions.
- Message channel (topic): In the autonomous driving intelligent operating system, the communication channel specified between application nodes, which includes the sender's sending port, the receiver's receiving port, the channel name, message format, etc.
- End-to-end latency In autonomous driving systems and applications, broadly speaking, it refers to the latency from the moment a sensor receives a signal (such as an image) to the moment the chassis actuators execute a specific action (such as braking). Narrowly defined, it refers to the latency from when the mobile data center (MDC) receives a topic data packet from the sensor to when it sends the data packet to the chassis control topic.
- MDC mobile data center
- the latency of the data flow through the critical link can be understood as end-to-end latency.
- Statues are pieces of code inserted anywhere within an existing application to provide a specific way to observe or modify the application.
- the location where stub code is inserted is called a stub or message stub.
- the stub code is executed, causing the application to perform the specific operation specified in the stub code. Therefore, stubs can also be used to indicate the specific operation triggered within the stub code. For this reason, stub code can also be simply referred to as a stub.
- instrumentation The act of inserting stubs into an application is called instrumentation.
- instrumentation action can be further called dynamic instrumentation or static instrumentation.
- the application is a binary program
- binary instrumentation can be further called dynamic binary instrumentation or static binary instrumentation.
- Figure 1 is a functional schematic block diagram of a vehicle 100 provided in an embodiment of this application.
- Vehicle 100 may include a sensing system 120, a display device 130, and a computing platform 150.
- the sensing system 120 may include several sensors for sensing information about the environment surrounding vehicle 100.
- the sensing system 120 may include a positioning system, which may be a Global Positioning System (GPS), a BeiDou system or other positioning systems, an inertial measurement unit (IMU), lidar, millimeter-wave radar, ultrasonic radar, and one or more of camera devices.
- GPS Global Positioning System
- BeiDou system BeiDou system
- IMU inertial measurement unit
- lidar lidar
- millimeter-wave radar millimeter-wave radar
- ultrasonic radar ultrasonic radar
- Computing platform 150 may include processors 151 to 15n (n is a positive integer).
- a processor is a circuit with signal processing capabilities.
- the processor may be a circuit with instruction read and execute capabilities, such as a central processing unit (CPU), a microprocessor, a graphics processing unit (GPU) (which can be understood as a type of microprocessor), or a digital signal processor (DSP).
- the processor can implement certain functions through the logical relationship of hardware circuits. The logical relationship of the hardware circuits is fixed or reconfigurable.
- the processor is a hardware circuit implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD), such as a field-programmable gate array (FPGA).
- ASIC application-specific integrated circuit
- PLD programmable logic device
- FPGA field-programmable gate array
- the process of a processor loading a configuration document and configuring the hardware circuit can be understood as the process of a processor loading instructions to implement the functions of some or all of the aforementioned units.
- it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as a neural network processing unit (NPU), tensor processing unit (TPU), deep learning processing unit (DPU), etc.
- the computing platform 150 may also include a memory for storing instructions. Some or all of the processors 151 to 15n can call the instructions in the memory to implement the corresponding functions described in the embodiments of this application.
- the vehicles involved in this application can include road vehicles, water vehicles, air vehicles, industrial equipment, agricultural equipment, or entertainment equipment.
- vehicles can include driverless vehicles.
- vehicle is used broadly and can refer to various types of vehicles, such as transportation vehicles (e.g., commercial vehicles, passenger cars, motorcycles, flying cars, trains), industrial vehicles (e.g., forklifts, trailers, tractors), engineering vehicles (e.g., excavators, bulldozers, cranes), agricultural equipment (e.g., lawnmowers, harvesters), amusement equipment, and toy vehicles.
- transportation vehicles e.g., commercial vehicles, passenger cars, motorcycles, flying cars, trains
- industrial vehicles e.g., forklifts, trailers, tractors
- engineering vehicles e.g., excavators, bulldozers, cranes
- agricultural equipment e.g., lawnmowers, harvesters
- amusement equipment e.g., and toy vehicles.
- the end-to-end latency of the data flow link in an autonomous driving system is a key indicator for measuring the response speed of autonomous driving.
- Low end-to-end latency e.g., less than 100ms
- end-to-end latency is a key objective for optimizing autonomous driving systems and applications.
- the autonomous driving system needs to allocate corresponding computing resources to realize the business corresponding to different data flow links. Whether the computing resources are allocated reasonably also affects the end-to-end latency of the overall data transmission of the autonomous driving system.
- This solution estimates the runtime of the application on the embedded platform and then maps the application to hardware resources based on an automatic application mapping algorithm. During program execution, the system can allocate corresponding resources to each program according to the mapping relationship. Furthermore, by combining simulated annealing and the earliest deadline first (EDF) scheduling simulation algorithm, a static task scheduling table and a task core binding scheme are generated, enabling each central processing unit (CPU) core to run its program smoothly, thereby better meeting the real-time requirements of tasks.
- EDF earliest deadline first
- the above scheme only optimizes CPU resource scheduling and does not consider the scheduling optimization of other hardware resources, such as graphics processing units (GPUs).
- the above scheme is essentially a static scheduling scheme. Autonomous driving is too complex. Mapping different scenarios' services to resource configurations, allowing the scheduler to perceive the processes corresponding to these services, and making the most reasonable resource scheduling for these processes, usually leads to distortion of the above mapping due to the limitations of the number of scenario samples and the limitations of the scheduling algorithm, making it difficult to achieve the overall optimal system resource scheduling.
- embodiments of this application propose a method, apparatus and system for resource scheduling, aiming to solve the above-mentioned problems originating from the underlying system resource scheduling, and to provide a dynamic, fine-grained resource scheduling mechanism.
- Figure 2 is a schematic diagram of the architecture of an autonomous driving system 200 proposed in an embodiment of this application.
- the system 200 may include an application layer, a platform layer, and a hardware layer.
- the aforementioned application layer includes an autonomous driving node layer, which is used to collect signals from sensors such as lidar, cameras, and radar of autonomous vehicles, and to use autonomous driving algorithms to process the data, infer and calculate the current position, status, and external status of the autonomous vehicle, as well as vehicle control signals or commands.
- an autonomous driving node layer which is used to collect signals from sensors such as lidar, cameras, and radar of autonomous vehicles, and to use autonomous driving algorithms to process the data, infer and calculate the current position, status, and external status of the autonomous vehicle, as well as vehicle control signals or commands.
- the aforementioned autonomous driving node layer further includes perception nodes, fusion nodes, planning nodes, and control nodes.
- the system consists of several nodes: a perception node, a fusion node, and a planning node.
- the perception node executes processes related to sensor signals to acquire signals from LiDAR, cameras, radar, etc.
- the fusion node is used by the autonomous driving algorithm to fuse the data carried in the sensor signals and infer the current position, state, and external state of the autonomous vehicle.
- the planning node combines the data fusion results to plan the control strategy for the vehicle in the next time period.
- the control node controls the corresponding vehicle controllers, such as the steering wheel, brakes, and accelerator, according to the control strategy, thereby completing the automatic control of the vehicle.
- the aforementioned platform layer also known as the operating system (OS) layer, includes the timing perception layer, resource control layer, and OS subsystem related to autonomous driving applications.
- OS operating system
- the timing awareness layer is used to determine the runtime timing information of each application in the autonomous driving system through dynamic piling points, static piling points, or business API calls.
- This runtime timing information includes the running status of each thread in different applications, the running dependencies between thread data and processes and between threads, and the current computing resource usage of each thread and/or process.
- the resource control layer is used to uniformly call and allocate various computing resources in the autonomous driving OS.
- These computing resources also known as computing resources, include CPU computing resources, GPU computing resources, memory resources, bus bandwidth resources, network bandwidth resources, and input/output (IO) interface resources.
- the OS subsystem is used for the abstraction and management of autonomous driving hardware resources.
- the OS subsystem includes the OS scheduling subsystem, GPU driver, DDR driver, network driver, etc.
- the aforementioned system 200 also involves the following hardware modules: CPU, GPU, memory, network card, and storage.
- Storage refers to external storage, such as a hard disk.
- the CPU and GPU are used to provide computing resources for the autonomous driving system 200 and its applications; the memory is used to provide memory resources for the autonomous driving system 200 and its applications; the network card is used to provide network communication resources for the autonomous driving system 200 and its applications; and the storage is used to provide general storage resources for the autonomous driving system 200 and its applications.
- the autonomous driving application layer can obtain resources from the hardware platform, such as CPU, GPU, memory, network card, and storage, that enable the vehicle to drive autonomously, through the autonomous driving platform layer.
- the timing awareness layer can obtain runtime timing state information of each application within the autonomous driving application layer during its operation, and then pass this information to the resource control layer.
- the resource control layer can then dynamically allocate computing resources to application nodes in critical data flow links in real time to minimize end-to-end latency in data flow transmission for the autonomous driving system.
- FIG. 3 is a schematic diagram of the operation of the timing awareness layer and resource regulation layer proposed in the embodiments of this application.
- N stub codes can be added to the application before the autonomous driving system runs. These N stub codes are used to indicate to the corresponding functions that the autonomous driving system needs to allocate more resources to run.
- the system typically allocates computing resources to each thread based on its priority.
- the autonomous driving system initially runs the application, it allocates resources to each thread running the application based on a fair scheduling method.
- the introduction of stub code allows the autonomous driving system to adjust the scheduling scheme for the thread running the stub code's associated function to privileged scheduling. This means increasing the resource scheduling priority (hereinafter referred to as priority) of the thread running the function to a higher priority than under the fair scheduling method. Therefore, the higher the priority of the function, the more resources the autonomous driving system allocates to the thread containing that function.
- the fair scheduling method described above can be a completely fair scheduler (CFS), and the privileged scheduling can be a round-robin (RR) schedule or a real-time (RT) schedule.
- the minimum priority of the privileged scheduling must be greater than the maximum priority of the fair scheduling.
- the links shown in Figure 3 under the autonomous driving application layer are critical links (also known as critical data flows).
- this perception node is a critical node, and it includes three critical threads used to execute the subscription, callback, and publish services in the communication business of the autonomous driving system.
- the functions used to execute these three services each correspond to one stub.
- the subscription function is denoted as function 1, and the corresponding stub is denoted as stub 1;
- the callback function is denoted as function 2;
- the corresponding stub is denoted as stub 2;
- the publish function is denoted as function 3, and the corresponding stub is denoted as stub 3.
- stubs in addition to indicating the allocation of more resources for a specific function, may also carry some stub information.
- stub information 1 may include: a stub identifier (ID), the timing frame ID of stub 1 in the entire timeline of the application running in the system, the thread identifier (TID) of the thread to which stub 1 resides, the process identifier (PID) of the process to which stub 1 resides, and threads that have a dependency relationship with thread 1 used to run function 1, such as thread 2 used to run function 2, where the dependency relationship could be thread 2 depending on thread 1, etc.
- ID stub identifier
- TID thread identifier
- PID process identifier
- Stub information 2 and stub information 3 are similar.
- timing frame ID corresponds to the position of the timing frame in the entire application runtime sequence. For example, the smaller the timing frame ID, the earlier the timing frame appears in the entire application runtime sequence.
- the station information 1 carried by station 1 can be added to the timing perception queue of the timing perception layer; similarly, when the application runs to station 2 in the autonomous driving application layer, the station information 1 carried by station 2 can be added to the timing perception queue of the timing perception layer; when the application runs to station 3 in the autonomous driving application layer, the station information 3 carried by station 3 can be added to the timing perception queue of the timing perception layer.
- the timing frame ID included in the stub information is used to determine the runtime sequence of each stub, thereby determining the runtime sequence information of the function corresponding to each stub, and then inserting each stub information into the timing awareness queue in the corresponding order according to the runtime sequence information.
- peg information 1 is placed before peg information 2 and peg information 3 is placed after peg information 2.
- the physical form of the aforementioned time-aware queue can be a ring buffer.
- it can also be replaced with other data storage structures, and this application embodiment does not limit this.
- the aforementioned timing-aware queue can be stored in a shared memory space between user space and kernel space.
- the system 200 can also sense whether the autonomous driving scenario of the vehicle has changed through sensors. When the autonomous driving scenario of the vehicle changes, the system can also transmit the changed scenario information to the resource control layer as part of the basis for resource scheduling.
- the resource control layer sequentially reads stub information from the time-aware queue. By reading the order of each stub's information, the runtime timing information of the function corresponding to each stub can be determined. Then, based on the stub information, the topology information between the stubs is determined.
- the time-aware scheduler in the resource control layer can then determine a resource scheduling scheme based on the runtime timing information and topology information, or based on the runtime timing information, topology information, and the switched scenario information. For example, it can set the CPU scheduling priority for the function corresponding to each stub, and then configure the corresponding computing resources for the thread where each function is located.
- the above-mentioned stubs can also be replaced with corresponding custom APIs, the functionality of which can be defined to be the same as that of the above-mentioned stubs.
- these critical links may be independent of each other, interdependent, or even the operation of some critical links depends on the execution result of a thread or function of other critical links.
- the resource control layer can maintain a data flow timing table for each critical link based on the runtime sequence and topology of each process, thread, and function under each critical link. This table reflects the runtime sequence state of different critical links. Then, the timing-aware scheduler of the resource control layer can determine the overall resource scheduling scheme based on each data flow timing table, and subsequently allocate corresponding computing resources to the thread corresponding to each function.
- the system can allocate more computing resources to the thread running the critical function based on the aforementioned resource scheduling scheme. After the critical function finishes running, the system can actively withdraw the computing resources allocated to the thread and determine whether to continue to provide more computing resources to the thread based on whether the functions subsequently executed by the thread are associated with the stub.
- the stub information, function runtime sequence information, topology information between stubs, data flow timing linked lists, and resource scheduling schemes mentioned in the above embodiments can all be passed to the OS subsystem in the form of configuration files.
- the OS subsystem When the OS subsystem starts, it can read the above configuration files, thereby enabling the OS subsystem to automatically collect and perceive the runtime sequence information of autonomous driving applications during the operation of the autonomous driving system, and dynamically adjust the priority of each thread in the key thread group under the key link node in combination with the above configuration files.
- the resource scheduling mechanism of System 200 ensures that critical thread groups receive appropriate computing resources, thereby reducing the end-to-end latency of the autonomous driving system's data flow link. Furthermore, by allocating more computing resources to threads implementing critical functions through point markers, it is evident that the resource scheduling optimization in this process targets the function granularity, avoiding the problem of over-allocating resources to critical threads running non-critical functions, thus helping to achieve overall optimization of the system's resource scheduling strategy. In addition, because autonomous driving systems need to run different applications in different application scenarios, and different applications maintain a corresponding number of data flow timing tables, these real-time maintained data flow timing tables serve as the basis for determining the resource scheduling scheme.
- System 200 can achieve real-time dynamic adjustment of the resource scheduling scheme, meeting the needs of dynamically adjusting resource scheduling strategies in various scenarios of autonomous driving operations, without requiring a large amount of real-vehicle measurement data to determine the resource scheduling scheme, making implementation both simple and time-efficient.
- the reason why the above-mentioned system 200 can take corresponding resource scheduling strategies for some key thread groups of the application during the running of the application is that before the application of the autonomous driving system runs, stub code corresponding to the key functions under the key link is added in the application in advance, so as to instruct the system 200 to provide sufficient computing resources for the key functions corresponding to the stub code.
- embodiments of this application propose a method for processing applications, so that when the system runs the application, it can allocate computing resources to the corresponding key functions through stubs in the application.
- the first application is run by an operating system, which may be the operating system in system 200 in the aforementioned embodiment.
- the operating system allocates first computing resources by default for the thread used to run the functions in the first application.
- N stubs can be added to the first application.
- These N stubs are associated with N key functions in the first application, and the key functions are associated with key data streams.
- the key data streams are used to determine the output of the first application, and the key functions are used to determine the output of the key data streams.
- the stubs are used to indicate the allocation of second computing resources, which are more than the first computing resources, for the threads used to run the key functions.
- the operating system mentioned above can be a Linux operating system or a Windows operating system, and this application embodiment does not limit it.
- the operating system can set priorities for the threads used to run the first application, and the priority of a thread determines the amount of computing resources the operating system allocates to that thread. Therefore, the operating system can schedule computing resources for threads by setting priorities.
- the operating system when it initially runs the first application, it will default to a fair scheduling scheme. Under the fair scheduling scheme, the system also needs to set the priority of each thread used to run the functions of the first application to be within the first priority range. At the initial moment of resource scheduling by the operating system, the priority of each thread is the same default value. During the operation of the first application, the internal logical functional unit of the operating system can change the priority of each thread. However, under the fair scheduling scheme, the scheduling priority of each thread must be within the first priority range.
- the operating system can set the priority of the thread used to run the various functions in the first application to one of the intervals [100, 139], where [100, 139] can be understood as the aforementioned first priority interval. For instance, at the initial moment when the operating system runs the first application, the priority of the thread used to run the various functions in the first application can be set to 120 by default.
- the operating system After the operating system reaches the stub of the first application, it can allocate corresponding computing resources to the functions associated with that stub based on the content indicated by the stub.
- the stub may indicate that the priority of the thread running a certain function is adjusted to a second priority interval, where the lower bound of the second priority interval is higher than the upper bound of the first priority interval.
- the function associated with the stub is a critical function, and the operating system needs to use privileged scheduling for the thread running the critical function, that is, to raise the priority of the thread running the critical function to the second priority interval.
- RR scheduling can be used to set the priority of the thread to one of [0-99], so that the operating system can subsequently allocate more computing resources to the thread. Based on this, it can be seen that the operating system allocates less first computing resources to the thread corresponding to the default priority than the second computing resources allocated by the operating system based on the priority within the second priority interval.
- the aforementioned stub can directly indicate the allocation of a second computing resource for a thread running a certain function.
- This second computing resource can represent its capacity, its allocation order, or its weight among all the operating system's computing resources. Once the operating system reaches this stub, it can determine the meaning of the second computing resource and then allocate it to the corresponding thread.
- the aforementioned stubs can be dynamic stubs, static stubs, or can be replaced with custom APIs.
- the system can dynamically adopt a privileged scheduling scheme for the thread running the critical function in real time when it reaches the stub, or allocate specified computing resources to the thread running the critical function. This ensures that the thread has sufficient computing resources to complete the execution of the critical function, thereby ensuring that the critical process chain in the application can be completed as soon as possible and reducing the end-to-end latency of data transmission in the critical chain.
- preheating stubs can also be set before the stubs corresponding to the critical functions.
- the first application has N key functions, including a first function associated with a first stub.
- the first stub is one of the N stubs added in the first application.
- a first warm-up stub can be added between the first pre-function and the first stub.
- the first pre-function runs before the first function and is adjacent to the first function.
- the first function is one of the N key functions and is associated with the first stub.
- the first stub is one of the N stubs.
- the first warm-up stub is used to indicate the allocation of a third computing resource for the thread running the first function. This third computing resource is less than or equal to the second computing resource.
- the third computing resources allocated by the operating system to the thread for running the first function based on the first preheating stub may be more than the second computing resources mentioned above.
- the aforementioned first preheating point can also be used to indicate that the priority of the thread used to run the first function should be adjusted in advance to the second priority range.
- the first preheating stub may further indicate that the priority of the thread used to run the first function is adjusted to the lower bound of the second priority range, or it may be set to other priorities, such as the priority assigned to the thread by the operating system when the thread runs the first pre-function, wherein the first pre-function may be either a critical function or a non-critical function.
- the preheating point can be set at the exit position of the first pre-function, or if an exit point is set at the end of the first pre-function, the preheating point is the exit point of the first pre-function.
- the aforementioned first preheating point may not be added before the first function.
- the operating system can run to the first preheating stub before running the first function, which is a key function. Based on the indication of the first preheating stub, the operating system can allocate corresponding computing resources in advance for the thread to run the first function, so as to ensure that the thread has computing resources to run the first function. This effectively avoids the computing resources used to run the first function being preempted by other key functions when the system runs the first function, thus ensuring the operation of the first function.
- the operating system may pre-run the first application to obtain historical data, which is used to indicate the runtime sequence of multiple processes and/or multiple threads participating in running the first application; based on the historical data, a first configuration file is generated, which is used to indicate the runtime dependencies between the multiple processes and/or multiple threads, and the first configuration file is also used to determine the second computing resources.
- embodiments of this application propose a resource scheduling method, which can be executed when the first application obtained by running the above-described processing application method is executed.
- Figure 4 is a flowchart illustrating a resource scheduling method 400 proposed in an embodiment of this application.
- S410 Run a first application, which includes a first key data stream used to determine the output of the first application.
- the first key data stream is associated with N threads under M processes, wherein the M processes include a first process, which is associated with a first thread, a first function, and a first stub, and the first thread is used to run the first function, where M and N are positive integers.
- the data flow of an application refers to the transmission path and process of data within the application, encompassing the generation, transmission, storage, and processing of data.
- the aforementioned first key data flow refers to the data transmission path within the first application that determines the program's output. During transmission, the data in this first key data flow passes through multiple business processes, which determine the output of the application system corresponding to those processes.
- the first application may include multiple sub-applications, each used to implement one of the various services mentioned in the above embodiments, such as sensing services, fusion services, planning services, and control services.
- first computing resource refers to the computing resource allocated for the first thread
- first computing resource refers to the computing resource allocated by default by the operating system for the thread used to run functions.
- the first stub may be added to the first application during its execution, i.e., the insertion of the first stub is achieved using a dynamic binary instrumentation method; alternatively, the first stub may be pre-added to the first application before its execution, i.e., the insertion of the first stub is achieved using a static binary instrumentation method. Based on this method, stubs can be inserted into the first application using various instrumentation methods, thereby increasing the flexibility of instrumentation.
- S420 Based on the first stub, allocate the first computing resource to the first thread, which is used for the first thread to run the first function.
- the above-described S420 may further include the following steps:
- S421 Determine the capacity of the first computing resource based on the first stub, and allocate the first computing resource to the first thread based on the capacity of the first computing resource;
- S422 Determine the order of the first computing resources based on the first stub, and allocate the first computing resources to the first thread based on the order of the first computing resources;
- S423 Determine the first occupancy rate based on the first stake point.
- the first occupancy rate is used to represent the occupancy rate (or weight) of the first computing resource among all computing resources, and allocate the first computing resource to the first thread based on the first occupancy rate.
- all computing resources in S423 above refers to the computing resources allocated within a first time frame.
- This first time frame refers to the time frame during which the execution times of other threads overlap with those of the first thread.
- all computing resources refer to the computing resources allocated to the first thread and other threads within the first time frame. Based on this, since the first occupancy rate is calculated using a fraction, the denominator of which can be used to represent the sum of the computing resources allocated to other threads within the first time frame and the aforementioned first computing resources, while the numerator of this fraction represents the first computing resources.
- the aforementioned first process is associated with the first thread, the first function, and the first stub.
- This association is as follows: the first process includes at least one thread, the first thread belongs to that at least one thread, and the first thread is used to run at least one function.
- the first function belongs to that at least one function, and the first function is a key function in the first application. Therefore, based on the method proposed in this application embodiment, the first function is associated with the first stub so that when the operating system reaches the first stub, it can determine that the first computing resource is allocated to the first thread used to run the first function.
- the aforementioned first process can be a node in the application layer shown in Figure 2, such as a fusion node.
- the fusion node can include thread 1, thread 2, and thread 3. Thread 1 is used to run a callback function, and this callback function is associated with the first stub. Therefore, the callback function can be understood as the aforementioned first function, and thread 1 can be understood as the aforementioned first thread. When the operating system reaches the first stub, it can determine that the computing resource is allocated to thread 1.
- the first application also includes non-critical functions, which are not associated with the stubs mentioned in method 400.
- the operating system runs a non-critical function of the first application, it allocates default computing resources to the thread running the non-critical function. These default computing resources are less than the aforementioned first computing resources. After the first thread finishes running the first function using the first computing resources, when the first thread is used to run a non-critical function again, according to method 400, the operating system will not continue to allocate the first computing resources to the first thread, but will reduce them to the default computing resources.
- the operating system may reclaim the first computing resources allocated to the first thread or reduce the allocation of computing resources.
- the operating system may then reallocate or adjust the computing resources allocated to the first thread based on method 400.
- the operating system can schedule computing resources based on priority, and use priority to represent the capacity, order, or weight of the first computing resources allocated to the first thread.
- the operating system can assume that the priorities of each thread used to run the first application are all within a first priority interval. Based on this, the aforementioned first stub can be used to indicate that the priority of the first thread is adjusted to a second priority interval, the lower bound of which is higher than the upper bound of the first priority interval. This indicates that the operating system needs to allocate more computing resources to the first thread than the default allocation. Therefore, the operating system needs to schedule more computing resources for the first thread to ensure the efficient operation of the first function.
- the first priority interval can correspond to the scheduling priority interval under the CFS scheme, i.e., [100, 139]; correspondingly, the second priority interval can correspond to the scheduling priority interval under the RR or RT scheduling scheme, i.e., [0, 99].
- the specific priority interval values in this embodiment are based on the corresponding scheduling scheme. In other schemes based on fair scheduling or privileged scheduling, the specific value intervals corresponding to the first and second priority intervals can be adaptively adjusted.
- the first pile point mentioned above can be a dynamic pile point, a static pile point, or it can be replaced by a custom API.
- the pile points involved in subsequent embodiments are similar to the first pile point.
- the first function corresponding to the first stub mentioned above can be understood as a key function, that is, a function used to determine the output of the first application. Therefore, it is necessary to allocate more computing resources to the first thread used to run the first function through the first stub.
- the first critical data flow also involves some functions not associated with stubs, meaning these functions are non-critical.
- the first function run by the first thread is a critical function, it can be statically allocated first computing resources. But if the first thread, after completing the first function, is then used to run non-critical functions, the operating system will still allocate first computing resources to the first thread to run those non-critical functions. For the first thread currently running a non-critical function, the operating system does not need to allocate excessive first computing resources.
- This resource scheduling scheme may cause threads used for other critical functions to not receive enough computing resources, leading to an increase in end-to-end latency of the first critical data flow.
- the operating system after the operating system reaches the first stub of the first application, it can not only identify the first function associated with the first stub as a critical function, but also allocate sufficient computing resources (i.e., first computing resources) to the first thread running the first function. This ensures that the first thread has sufficient computing resources to run the first function efficiently and quickly. Furthermore, when the first thread runs other functions, the operating system can reallocate computing resources to the first thread instead of continuing to allocate the first computing resources. This allows the operating system to dynamically allocate computing resources to threads at the function level, helping to allocate more remaining resources to other threads running critical functions, thereby reducing the end-to-end latency of the first critical data stream. Especially when the first application is an autonomous driving application, it can effectively improve the user's driving experience and ensure the safety of passengers inside the vehicle, pedestrians outside the vehicle, and other vehicles.
- first computing resources i.e., first computing resources
- Figure 5 is a schematic diagram of another resource scheduling method 500 proposed in an embodiment of this application.
- Figure 5(a) it is a flowchart of a resource scheduling method 500 proposed in an embodiment of this application
- Figure 5(b) it is a schematic diagram of the principle of a resource scheduling method 500 proposed in an embodiment of this application.
- the aforementioned first application also includes a second key data stream used to determine the output of the first application.
- This second key data stream is associated with N threads under M processes.
- the M processes also include a second process, which is associated with a second thread, a second function, and a second stub.
- the second thread is used to run the second function.
- method 500 may include the following operations:
- S510 Based on the first configuration file, determine the first dependency relationship between the second thread and the first thread, whereby the first configuration file is used to indicate the dependency relationship between the above M processes and/or the above N threads.
- the above-described S510 can be executed when the operating system reaches the first stub and the second stub.
- "Reaching the first stub and the second stub” can be understood as simultaneously reaching both the first and second stubs, or reaching the second stub after reaching the first stub but before the first function has finished running. In other words, this scenario can be understood as the operating system needing to simultaneously schedule computational resources for two parallel threads used to run critical functions.
- the aforementioned first configuration file can be obtained through pre-experimentation.
- the first application is a program used to implement autonomous driving services, and this first application is installed on the autonomous driving system.
- the vehicle can be controlled to conduct test runs based on the first application.
- historical data of each thread running each function in the first application will be generated. This historical data may include station information, the timing of each thread running functions, and the dependencies between threads during the execution of functions.
- the aforementioned first configuration file can be determined and provided to the operating system for subsequent resource scheduling.
- an autonomous driving system is an application system, and application systems run in an environment provided by the operating system.
- S520 Based on the second stub and the first dependency, allocate a second computing resource to the second thread, which is used for the second thread to run the second function.
- the first computing resources are more than the second computing resources; or, when the first dependency relationship is that the operation of the second thread depends on the first thread, the first computing resources are less than the second computing resources, so as to ensure that the critical data streams that the operating system enters earlier can be output smoothly.
- the processes associated with the first and second key data streams are the same, or the second key data stream can be understood as a mirror image of the first key data stream.
- the aforementioned dependency relationship is essentially the runtime sequence relationship between the first and second threads. Taking the first thread's execution depending on the second thread as an example, this dependency relationship means that the first thread's execution order follows the second thread. At this time, the first thread associated with the first key data stream and the second thread associated with the second key data stream are running in parallel. The first thread associated with the first key data stream has already completed the execution of the first function, while the second key data stream has not yet entered the process of the first thread running the first function. Therefore, the first key data stream is the preceding frame data stream of the second key data stream.
- the operating system can allocate more resources to the threads associated with the first key data stream to ensure that the preceding frame data stream can be output smoothly. This avoids allocating sufficient computing resources to both data stream threads simultaneously, which would lead to excessive computing resource consumption, causing other threads to not receive enough computing resources, resulting in a situation where many functions cannot complete within a short period (e.g., 100ms to 300ms).
- the meaning of “second computing resource” mentioned in method 500 differs from the meaning of "second computing resource” mentioned in the corresponding embodiment of the method for processing the application.
- the second computing resource refers to the computing resources allocated for the second thread, while in the method for processing the application, the second computing resource refers to the computing resources allocated by the operating system based on stubs for the thread used to run critical functions.
- the first dependency relationship described above can be represented by the runtime order of the first thread and the second thread.
- the first dependency relationship can be represented by the distance between the first thread and the endpoint of the first key data flow and the distance between the second thread and the endpoint of the second key data flow. This distance can be understood as the number of hops between the thread and the termination node of the business process. After the thread finishes execution, the data flow will jump to the next thread until it jumps to the termination node. Alternatively, this distance can also be understood as the time required from running the thread to the output of the data flow associated with the thread. This time can be obtained by using historical data generated by the operating system running the first application.
- the above method 500 can be executed using graph theory algorithms. That is, after determining the dependencies between threads in the critical link, a scheduling priority is set for the function associated with the stub using graph theory algorithms. For example, the priority of the upper node in the directed graph is higher than the priority of the lower node, or the computing resources of the upper node in the directed graph are more than the computing resources of the lower node.
- Figure 6 is a schematic diagram illustrating the principle of another resource scheduling method 600 proposed in an embodiment of this application.
- the first process is also associated with a third stub.
- the third stub is adjacent to the first stub and is located before the first stub.
- the method 600 includes the following operation: allocating a third computing resource to the first thread according to the third stub.
- the third computing resource is less than or equal to the first computing resource.
- the third computing resource is used to ensure that the first thread runs the first function.
- the aforementioned third stub can be set at the exit position of the third function that is timed before the first function. If an exit stub is set at the exit of the third function, the third stub can be an exit stub associated with the third function. That is, after the third function is executed, the third stub is run directly, thereby allocating third computing resources to the first thread in advance.
- the third computing resource may be greater than the first computing resource.
- the aforementioned third stub can also be used to indicate that the priority of the first thread is set to the first priority, which corresponds to the third computing resource.
- the first priority can be the lower bound of the second priority interval.
- the first priority is the lower bound of the second priority interval, it at least allows for the pre-allocation of corresponding computing resources to the first thread, ensuring that these resources can guarantee the completion of the first function and preventing other critical threads from preempting the computing resources when the first function is executed, thus preventing the first function from running normally.
- the first priority can be any other priority value within the second priority interval, and this application embodiment does not limit this.
- the operating system when execution reaches the third stub, can allocate a third computing resource to the first thread (assuming the third computing resource is less than the first computing resource).
- the operating system can first determine whether the remaining computing resources meet a first condition, which is that the remaining computing resources are greater than or equal to the difference between the first and third computing resources. If the first condition is met, computing resources are allocated to the first thread so that the first thread can obtain the first computing resource; if the first condition is not met, computing resources are not allocated to the first thread.
- the operating system can control the binding relationship between processes or threads and CPU cores (also known as processor cores), a process called CPU core binding.
- CPU core binding technology critical threads are bound to more powerful CPU cores (also known as CPU big cores), thereby providing higher computing performance and faster response times for critical threads.
- Critical threads can fully utilize the computing power of CPU big cores, improving the running speed and responsiveness of applications.
- core binding technology allows for more precise control over which CPU cores a process or thread runs on, effectively reducing the possibility of multiple threads competing for computing resources on a single CPU core when the operating system allocates computing resources to multiple threads, making system management more flexible and convenient.
- the first thread mentioned in this embodiment can also be bound to a corresponding CPU core, so that computing resources are allocated to the first thread through the bound CPU core.
- Figure 7 is a flowchart illustrating a processor core-binding method 700 proposed in an embodiment of this application.
- method 700 includes the following steps:
- S710 Predicts the first resource utilization rate after the first processor core provides the first computing resources to the first thread.
- the first threshold mentioned above may be a threshold preset based on the hardware performance of the operating system used to run the first application.
- S720 Provides the first computing resources to the first thread through the first processor core.
- S730 Predicts the second resource utilization rate after the second processor core provides the first computing resources to the first thread.
- S740 Provides the first computing resources for the first thread through the second processor core.
- S750 Predicts the third resource utilization rate after the third processor core provides the first computing resources to the first thread, and the third processor core is not bound to the first thread.
- S760 Provides primary computing resources to the first thread through the third processor core.
- the first thread before executing S760, is unbound from the first processor core and the second processor core, and then bound to the third processor core.
- S770 Predicts the resource utilization of the fourth processor core after it provides the first computing resources to the first thread, where the fourth processor core is not bound to the first thread. This process repeats.
- the first thread when the first computing resources are provided to the first thread through the third processor core, the first thread is rebound to the first and second processor cores after the function of the first thread has finished running based on the first computing resources.
- this application proposes a timeout prevention mechanism to solve this problem.
- the timeout prevention mechanism includes the following steps:
- a first timer is started, and the duration of the first timer is set to be greater than or equal to the duration required to complete the execution of the first function; if the first timer times out and the first function has not completed execution, the first computing resources allocated to the first thread are reduced.
- the duration of the first timer set above may be twice the duration required to complete the execution of the first function.
- this application proposes a non-critical function protection mechanism to address this issue.
- this fourth function is not associated with the stubs proposed in this application, meaning it is a non-critical function.
- the non-critical function protection mechanism includes the following steps:
- the fourth function described above may be associated with a critical data stream of the first application or a non-critical data stream of the first application, and this application embodiment does not limit this.
- the fourth function is a non-critical function, it can be one of the more important functions in the first application used to implement relatively critical business logic.
- the fourth function does not need to run periodically within a short period, but it needs to trigger the corresponding important business logic at a specified time.
- the fourth function could be a function related to the vehicle chassis.
- the fourth function may not be directly related to the key data flows (perception, fusion, planning, or control) in autonomous driving, the chassis functions of the autonomous driving system are still relatively important. Therefore, ensuring the normal and timely operation of the fourth function is also quite important.
- the first runtime segment described above can be obtained through external input or can be preset before the system runs.
- the fourth computing resource since the fourth computing resource is more than the first computing resource, it can be known from the priority scheduling scheme that the priority of the first thread when running the fourth function is higher than the priority when running the first function.
- embodiments of this application also provide an apparatus for implementing any of the above methods, the apparatus including units (or means) for implementing any of the above methods.
- Figure 8 is a schematic block diagram of a resource scheduling device 800 provided in an embodiment of this application.
- the above-described device 800 is used to constitute an operating system.
- the device 800 includes:
- the execution unit 810 is used to run a first application, which includes a first key data stream used to determine the output of the first application.
- the first key data stream is associated with N threads under M processes.
- the M processes include a first process, which is associated with a first thread, a first function, and a first stub.
- the first thread is used to run the first function.
- M and N are positive integers.
- the first operation unit 820 is used to allocate a first computing resource to the first thread according to the first stub, and the first computing resource is used for the first thread to run a first function.
- the first operation unit 820 is specifically used to: determine the capacity of the first computing resource based on the first stub, and allocate the first computing resource to the first thread based on the capacity of the first computing resource; or, determine the order of the first computing resources based on the first stub, and allocate the first computing resource to the first thread based on the order of the first computing resources; or, determine a first occupancy rate based on the first stub, the first occupancy rate being used to represent the occupancy rate of the first computing resource among all computing resources, and allocate the first computing resource to the first thread based on the first occupancy rate.
- the first stub is added to the first application during the execution of the first application; or, the first stub is added to the first application before the first application is executed.
- the first application further includes a second key data stream used to determine the output of the first application.
- the second key data stream is associated with N threads under M processes.
- the M processes also include a second process associated with a second thread, a second function, and a second stub.
- the second thread is used to run the second function.
- the device 800 further includes:
- the determining unit 830 is used to determine the first dependency relationship between the second thread and the first thread based on the first configuration file, wherein the first configuration file is used to indicate the dependency relationship between the above M processes and/or the above N threads.
- the first operation unit 820 is further configured to allocate second computing resources to the second thread based on the second stub and the first dependency relationship.
- the second computing resources are used for the second thread to run the second function. If the first dependency relationship is that the operation of the first thread depends on the second thread, the first computing resources are more than the second computing resources. Alternatively, if the first dependency relationship is that the operation of the second thread depends on the first thread, the first computing resources are less than the second computing resources.
- the first process is also associated with a third stub.
- the third stub is adjacent to the first stub and is located before the first stub.
- the first operation unit 820 is further configured to: allocate a third computing resource to the first thread according to the third stub, the third computing resource being less than or equal to the first computing resource, and the third computing resource being used to ensure that the first thread runs the first function.
- the first thread is bound to a first processor core and a second processor core, respectively, and the first processor core and the second processor core are respectively configured to provide first computing resources for the first thread.
- the device 800 further includes:
- Prediction unit 840 is used to predict the first resource utilization rate after the first processor core provides the first computing resources to the first thread;
- the prediction unit 840 is also used to predict the second resource utilization rate after the second processor core provides the first computing resources to the first thread;
- the first operation unit 820 is specifically used to provide the first computing resource to the first thread through the second processor core; or,
- the prediction unit 840 is also used to predict the third resource utilization rate after the third processor core provides the first computing resources to the first thread, and the third processor core is not bound to the first thread;
- the first operation unit 820 is specifically used to provide the first computing resource to the first thread through the third processor core.
- the above-described device 800 further includes: a second operation unit 850, configured to start a first timer at the beginning of the first thread running the first function, wherein the duration of the first timer is greater than or equal to the duration required to complete the first function; the first operation unit 820 is further configured to reduce the first computing resources allocated to the first thread if the first timer times out and the first function has not completed its execution.
- a second operation unit 850 configured to start a first timer at the beginning of the first thread running the first function, wherein the duration of the first timer is greater than or equal to the duration required to complete the first function
- the first operation unit 820 is further configured to reduce the first computing resources allocated to the first thread if the first timer times out and the first function has not completed its execution.
- the first application program further includes a fourth function
- the device 800 further includes: an acquisition unit 860, configured to acquire a preset first runtime period, the first runtime period being greater than or equal to the duration required to complete the fourth function; the first operation unit 820 is further configured to allocate a fourth computing resource to the thread used to run the fourth function within the first runtime period from the moment the fourth function is run, the fourth computing resource being greater than or equal to the first computing resource.
- Figure 9 is a schematic block diagram of an application processing device 900 provided in an embodiment of this application.
- the device 900 is used to process a first application, which is run by an operating system, and the operating system allocates first computing resources by default for threads used to run functions in the first application.
- the device 900 includes:
- Instrumentation unit 910 is used to add N stubs in the first application, where N is a positive integer.
- the N stubs are associated with N key functions in the first application.
- the key functions are associated with key data streams.
- the key data streams are used to determine the output of the first application.
- the key functions are used to determine the output of the key data streams.
- the stubs are used to indicate the allocation of second computing resources for the thread used to run the key functions.
- the second computing resources are more than the first computing resources.
- the instrumentation unit 910 described above is further configured to add a first warm-up stub between the first pre-function and the first stub, wherein the execution order of the first pre-function precedes and is adjacent to the first function, the first function is one of the N key functions, the first function is associated with the first stub, the first stub is one of the N stubs, and the first warm-up stub is used to indicate the allocation of a third computing resource for the thread used to run the first function, the third computing resource being less than or equal to the second computing resource.
- the above-described device 900 further includes:
- the running unit 920 is used to run the first application to obtain historical data, which is used to indicate the runtime sequence of multiple processes and/or multiple threads involved in running the first application.
- the processing unit 930 is configured to generate a first configuration file based on the historical data.
- the first configuration file is used to indicate the operational dependencies between the plurality of processes and/or the plurality of threads.
- the first configuration file is also used to determine the second computing resource.
- This application also proposes a vehicle that includes the device 800 and/or device 900 proposed in any of the above embodiments, or an autonomous driving system for executing the resource scheduling method proposed in this application.
- the technical solution proposed in this application is not limited to being executed through the operating system corresponding to the autonomous driving system.
- the technical solution can also be extended to be executed by the operating system on which other application systems are installed, such as intelligent robot systems, smart home systems, etc.
- the disclosed systems, apparatuses, and methods can be implemented in other ways.
- the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods.
- multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
- the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
- the units described as separate components may or may not be physically separate.
- the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
- the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
- the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium.
- the technical solution of this application in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product.
- This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
本申请提供了资源调度的方法、装置和系统,涉及智能驾驶领域,该方法包括:运行第一应用程序,第一应用程序包括第一关键数据流,第一关键数据流用于决定第一应用程序的输出,第一关键数据流与M个进程下的N个线程相关联,M个进程包括第一进程,第一进程与第一线程、第一函数和第一桩点关联,第一线程用于运行第一函数,M和N为正整数;根据第一桩点,为第一线程分配第一计算资源,第一计算资源用于第一线程运行第一函数。基于该方法,能够合理地为自动驾驶应用中不同的关键数据流对应的应用节点下的线程分配计算资源,从而有助于降低自动驾驶系统关键数据流的端到端时延和时延抖动,进一步地,保障了车主和车外行人的安全。
Description
本申请要求于2024年6月13日提交中国专利局、申请号为202410765274.3、发明名称为“资源调度的方法、装置和系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及智能驾驶领域,具体涉及资源调度的方法、装置和系统。
在自动驾驶业务中,自动驾驶系统的数据流链路的端到端时延是衡量自动驾驶相应速度的关键指标,低端到端时延(例如小于100ms)能够大幅提高车辆和行人的安全系数,是自动驾驶系统和应用优化的关键目标。
在自动驾驶应用运行的过程中,自动驾驶系统为实现不同的数据流链路对应的业务,需要对应地分配相应的计算资源,而如何合理地为自动驾驶应用中不同的数据流链路应用节点调度资源,是现阶段亟待解决的问题。
本申请实施例提供了资源调度的方法、装置和系统,能够合理地为自动驾驶应用中不同的关键数据流对应的应用节点下的线程分配计算资源,从而有助于降低自动驾驶系统关键数据流的端到端时延和时延抖动,进一步地,保障了车主和车外行人的安全。
第一方面,提供了一种资源调度的方法,该方法包括:运行第一应用程序,第一应用程序包括第一关键数据流,第一关键数据流用于决定第一应用程序的输出,第一关键数据流与M个进程下的N个线程相关联,M个进程包括第一进程,第一进程与第一线程、第一函数和第一桩点关联,第一线程用于运行第一函数,M和N为正整数;根据第一桩点,为第一线程分配第一计算资源,第一计算资源用于第一线程运行第一函数。
示例地,该方法可以由操作系统执行。
基于上述技术方案,操作系统运行到第一应用程序的第一桩点后,不仅能够确定与第一桩点相关联的第一函数为关键函数,而且还会为用于运行第一函数的第一线程分配充足的计算资源,即第一计算资源,以使得第一线程能够有充足的计算资源高效快速地运行第一函数,而且在第一线程运行其他函数时,操作系统可以重新为第一线程分配计算资源,而不是继续为第一线程分配第一计算资源,实现操作系统能够动态地以函数粒度为线程分配计算资源,有助于将更多剩余的资源分配给其他运行关键函数的线程,从而有助于降低第一关键数据流的端到端时延。尤其是在第一应用程序为自动驾驶应用程序的情况下,能够有效提升用户的驾乘体验,并且保障车内乘客、车外行人以及其他车辆的安全性。
结合第一方面,在第一方面的某些实现方式中,根据第一桩点,确定第一计算资源的容量,并根据第一计算资源的容量,为第一线程分配第一计算资源;或者,根据第一桩点,确定第一计算资源的顺序,并根据第一计算资源的顺序,为第一线程分配第一计算资源;或者,根据第一桩点,确定第一占有率,第一占有率用于表示第一计算资源在所有计算资源中的占有率,并根据第一占有率,为第一线程分配第一计算资源。
应理解,上述所有计算资源指的是在第一时间范围内用于分配的计算资源,该第一时间范围指的是其他线程与第一线程之间的运行时间存在重叠部分的时间范围,进一步地,上述所有计算资源指的是在第一时间范围内,用于分配给第一线程和其他线程的计算资源。基于此,由于第一占有率是通过一个分数计算得到的,而该分数的分母可以用于表示在第一时间范围内,用于分配给其他线程的计算资源与上述第一计算资源之和,该分数的分子则是第一计算资源。
示例地,在第一线程将第一函数运行完毕后,操作系统可以将分配给第一线程的第一计算资源收回,或者减少计算资源的分配,待第一线程运行其他函数时,再基于该方法,为第一线程重新分配或者调整分配给第一线程的计算资源。
示例地,操作系统可以基于优先级进行计算资源的调度,并通过优先级来表示为第一线程分配的第一计算资源的容量、顺序或者权重。
基于上述技术方案,通过第一桩点指示操作系统为第一线程分配的第一计算资源的容量、顺序或者权重,以使得第一线程在运行第一桩点对应的第一函数时,能够得到充足的计算资源,从而使得操作系统能够实现基于函数粒度的资源调度。
结合第一方面,在第一方面的某些实现方式中,第一桩点是在运行第一应用程序的过程中添加至第一应用程序的;或者,第一桩点是在运行第一应用程序之前预先添加至第一应用程序的。
示例地,上述第一桩点可以是动态桩点,也可以是静态桩点,还可以替换为自定义的应用程序编程接口(application programming interface,API)。
基于上述技术方案,可以通过多种插桩的方式将桩点插入到第一应用程序,从而增加了插桩的灵活性。
结合第一方面,在第一方面的某些实现方式中,第一应用程序还包括第二关键数据流,第二关键数据流用于决定第一应用程序的输出,第二关键数据流与M个进程下的N个线程相关联,M个进程还包括第二进程,第二进程与第二线程、第二函数和第二桩点关联,第二线程用于运行第二函数,根据第一配置文件,确定第二线程与第一线程之间运行的第一依赖关系,该第一配置文件用于指示上述M个进程和/或上述N个线程之间运行的依赖关系;根据第二桩点和第一依赖关系,第二线程分配第二计算资源,第二计算资源用于第二线程运行第二函数,在第一依赖关系为第一线程的运行依赖于第二线程的情况下,第一计算资源多于第二计算资源,或者,在第一依赖关系为第二线程的运行依赖于第一线程的情况下,第一计算资源少于第二计算资源。
应理解,上述第一关键数据流和第二关键数据流所关联的进程是相同的,也可以理解为第二关键数据流为第一关键数据流的镜像。
示例地,上述第一配置文件可以通过预先实验的方式来获取,以自动驾驶应用场景为例,第一应用程序为用于实现自动驾驶业务的程序,该第一应用程序搭载于自动驾驶系统。在将第一应用程序部署在自动驾驶系统上后,可以控制车辆基于第一应用程序进行试跑,在该过程中会生成各个线程运行第一应用程序中各个函数的历史数据,该历史数据可以包括桩点信息、各个线程运行函数的时序、在线程运行函数过程中线程间的依赖关系等,并通过对历史数据的统计与分析,即可确定上述第一配置文件,以提供给操作系统用于后续的资源调度。应理解,自动驾驶系统是一种应用系统,而应用系统则是在操作系统提供的环境下运行的。
基于上述技术方案,通过判断并行线程之间的依赖关系,为被依赖的线程提供相对多的计算资源,尽可能降低被依赖的线程所在的关键数据流的端到端时延的同时,也能够有效避免同时为多个关键数据流对应的多个并行线程分配等量充足的计算资源,导致其他并行的线程因资源不充足,无法在短期内运行完毕的问题,进而减小了多个并行关键数据流的端到端时延的抖动。
结合第一方面,在第一方面的某些实现方式中,第一进程还与第三桩点相关联,在第一进程的运行时序中,第三桩点与第一桩点相邻,且位于第一桩点之前,根据第三桩点,为第一线程分配第三计算资源,第三计算资源小于或者等于第一计算资源,第三计算资源用于保障第一线程运行第一函数。
示例地,上述第三桩点可以设置于时序位于第一函数之前的第三函数的出口位置,在第三函数的出口设置有退出桩点的情况下,该第三桩点可以是与第三函数关联的退出桩点,即在执行完毕第三函数后,直接运行第三桩点,从而为第一线程提前分配第三计算资源。
基于上述技术方案,能够有效避免关键函数的计算资源提前被其他非关键线程抢占,导致关键函数无法尽快运行完毕的情况,有助于进一步降低关键数据流传输的端到端时延。
结合第一方面,在第一方面的某些实现方式中,第一线程分别与第一处理器核和第二处理器核绑定,第一处理器核和第二处理器核分别被配置用于为第一线程提供第一计算资源,预测第一处理器核为第一线程提供第一计算资源后的第一资源占用率;若第一资源占用率小于或者等于第一阈值,则通过第一处理器核为第一线程提供第一计算资源;若第一资源占用率大于第一阈值,则预测第二处理器核为第一线程提供第一计算资源后的第二资源占用率;若第二资源占用率小于或者等于第一阈值,则通过第二处理器核为第一线程提供第一计算资源。
结合第一方面,在第一方面的某些实现方式中,若上述第二资源占用率大于第一阈值,则预测第三处理器核为第一线程提供第一计算资源后的第三资源占用率,该第三处理器核未与第一线程绑定;若第三资源占用率小于或者等于第一阈值,则通过第三处理器核为第一线程提供第一计算资源。
示例地,上述第一阈值可以是根据操作系统硬件性能预设的阈值。
基于上述技术方案,能够避免多个线程抢占一个处理器核的计算资源的情况,有助于提升系统运行第一应用程序的效率,降低数据流在关键进程链路传输的端到端时延。
结合第一方面,在第一方面的某些实现方式中,在第一线程运行上述第一函数的起始时刻,开启第一定时器,第一定时器设置的时长大于或者等于运行完第一函数所需的时长;在第一定时器超时,且第一函数未完成运行的情况下,减少为第一线程分配的第一计算资源。
基于上述技术方案,能够有效避免因关键函数陷入死循环等异常状态,导致与该关键函数所在的线程绑定长时间抢占处理器资源的情况,从而使计算资源的分配更为合理。
结合第一方面,在第一方面的某些实现方式中,上述第一应用程序还包括第四函数,获取预设的第一运行时段,该第一运行时段大于或者等于运行完第四函数所需的时长;从运行到第四函数的时刻起的第一运行时段内,为用于运行第四函数的线程分配第四计算资源,该第四计算资源大于或者等于第一计算资源。
示例地,上述第一运行时段可以通过外部输入获得,也可以在系统运行前预设。
基于上述技术方案,能够避免用于运行非关键函数的计算资源长时间被关键函数所在的线程抢占,导致非关键函数失效的情况。从而保障了第一应用程序运行的功能完整性,尤其是在第一应用程序为自动驾驶应用程序的情况下,能够提升用户的驾乘体验。
第二方面,提供了一种处理应用程序的方法,该方法用于处理第一应用程序,第一应用程序由操作系统运行,操作系统默认为用于运行第一应用程序中的函数的线程分配第一计算资源,该方法包括:在第一应用程序中添加N个桩点,N为正整数,N个桩点分别与第一应用程序中的N个关键函数相关联,关键函数与关键数据流相关联,关键数据流用于决定第一应用程序的输出,关键函数用于决定关键数据流的输出,桩点用于指示为用于运行所述关键函数的线程分配第二计算资源,第二计算资源多于第一计算资源。
示例地,上述操作系统可以采用Linux操作系统,也可以采用Windows系统,本申请实施例对此不做限定。
示例地,操作系统可以为用于运行第一应用程序的线程设置优先级,而线程对应的优先级决定着操作系统为线程分配的计算资源的多少。所以操作系统可以通过为线程设置优先级的方式,来实现对线程的计算资源调度。
基于上述技术方案,通过在第一应用程序中添加与关键函数对应的桩点,以使得系统在运行到桩点时,能够实时动态地为用于运行该关键函数的线程采取特权调度方案,或者为用于运行该关键函数的线程分配指定的计算资源,从而使得线程能够有充足的计算资源来完成关键函数的运行,实现操作系统能够动态地以函数粒度为线程分配计算资源,并且保障应用程序中的关键进程链路能够尽快运行完毕,降低数据流在关键链路中传输的端到端时延。
结合第二方面,在第二方面的某些实现方式中,在第一前置函数与第一桩点之间添加第一预热桩点,其中,第一前置函数的运行时序在第一函数之前,且与所述第一函数相邻,第一函数为所述N个关键函数中的一个,第一函数与第一桩点相关联,第一桩点为所述N个桩点中的一个,第一预热桩点用于指示为用于运行第一函数的线程分配第三计算资源,该第三计算资源少于或者等于第二计算资源。
基于上述技术方案,由于预热桩点的引入,操作系统在第一前置函数执行完毕后,能够在运行到作为关键函数的第一函数之前,先运行到第一预热桩点,从而基于第一预热桩点的指示,提前为用于运行第一函数的线程分配相应的计算资源,以保障线程能够有计算资源用于运行第一函数,从而有效避免系统在运行到第一函数时,用于运行第一函数的计算资源被其他关键函数抢占,从而保障了第一函数的运行。
结合第二方面,在第二方面的某些实现方式中,运行第一应用程序,以获取历史数据,该历史数据用于指示参与运行第一应用程序的多个进程和/或多个线程的运行时序;根据历史数据,生成第一配置文件,该第一配置文件用于指示所述多个进程和/或所述多个线程之间运行的依赖关系,该第一配置文件还用于确定上述第二计算资源。
第三方面,提供了一种资源调度的装置,该装置包括:运行单元,用于运行第一应用程序,该第一应用程序包括第一关键数据流,该第一关键数据流用于决定第一应用程序的输出,该第一关键数据流与M个进程下的N个线程相关联,该M个进程包括第一进程,第一进程与第一线程、第一函数和第一桩点关联,该第一线程用于运行第一函数,M和N为正整数;第一操作单元,用于根据第一桩点,为第一线程分配第一计算资源,该第一计算资源用于第一线程运行第一函数。
结合第三方面,在第三方面的某些实现方式中,上述第一操作单元具体用于:根据第一桩点,确定第一计算资源的容量,并根据第一计算资源的容量,为第一线程分配第一计算资源;或者,根据第一桩点,确定第一计算资源的顺序,并根据第一计算资源的顺序,为第一线程分配第一计算资源;或者,根据第一桩点,确定第一占有率,第一占有率用于表示第一计算资源在所有计算资源中的占有率,并根据第一占有率,为第一线程分配第一计算资源。
结合第三方面,在第三方面的某些实现方式中,上述第一桩点是在运行第一应用程序的过程中添加至第一应用程序的;或者,上述第一桩点是在运行第一应用程序之前预先添加至第一应用程序的。
结合第三方面,在第三方面的某些实现方式中,上述第一应用程序还包括第二关键数据流,该第二关键数据流用于决定第一应用程序的输出,第二关键数据流与M个进程下的N个线程相关联,M个进程还包括第二进程,第二进程与第二线程、第二函数和第二桩点关联,第二线程用于运行第二函数,上述装置还包括:确定单元,用于根据第一配置文件,确定第二线程与第一线程之间运行的第一依赖关系,该第一配置文件用于指示上述M个进程和/或上述N个线程之间运行的依赖关系;上述第一操作单元还用于,根据第二桩点和第一依赖关系,为第二线程分配第二计算资源,第二计算资源用于第二线程运行第二函数,在第一依赖关系为第一线程的运行依赖于第二线程的情况下,第一计算资源多于第二计算资源,或者,在第一依赖关系为第二线程的运行依赖于第一线程的情况下,第一计算资源少于第二计算资源。
结合第三方面,在第三方面的某些实现方式中,上述第一进程还与第三桩点相关联,在第一进程的运行时序中,第三桩点与第一桩点相邻,且位于第一桩点之前,上述第一操作单元还用于:根据第三桩点,为第一线程分配第三计算资源,该第三计算资源小于或者等于第一计算资源,该第三计算资源用于保障第一线程运行第一函数。
结合第三方面,在第三方面的某些实现方式中,上述第一线程分别与第一处理器核和第二处理器核绑定,第一处理器核和第二处理器核分别被配置用于为第一线程提供第一计算资源,上述装置还包括:预测单元,用于预测第一处理器核为第一线程提供第一计算资源后的第一资源占用率;在第一资源占用率大于第一阈值的情况下,预测单元还用于,预测第二处理器核为第一线程提供第一计算资源后的第二资源占用率;在第二资源占用率小于或者等于第一阈值的情况下,上述第一操作单元具体用于,通过第二处理器核为第一线程提供第一计算资源;或者,在第二资源占用率大于第一阈值的情况下,预测单元还用于,预测第三处理器核为第一线程提供第一计算资源后的第三资源占用率,第三处理器核未与第一线程绑定;在第三资源占用率小于或者等于第一阈值的情况下,第一操作单元具体用于,通过第三处理器核为第一线程提供第一计算资源。
结合第三方面,在第三方面的某些实现方式中,上述装置还包括:第二操作单元,用于在上述第一线程运行上述第一函数的起始时刻,开启第一定时器,该第一定时器设置的时长大于或者等于运行完第一函数所需的时长;上述第一操作单元还用于,在第一定时器超时,且第一函数未完成运行的情况下,减少为第一线程分配的第一计算资源。
结合第三方面,在第三方面的某些实现方式中,上述第一应用程序还包括第四函数,上述装置还包括:获取单元,用于获取预设的第一运行时段,该第一运行时段大于或者等于运行完第四函数所需的时长;上述第一操作单元还用于,从运行到第四函数的时刻起的第一运行时段内,为用于运行第四函数的线程分配第四计算资源,该第四计算资源大于或者等于第一计算资源。
第四方面,提供了一种处理应用程序的装置,该装置用于处理第一应用程序,该第一应用程序由操作系统运行,且操作系统默认为用于运行第一应用程序中的函数的线程分配第一计算资源,该装置包括:插桩单元,用于在第一应用程序中添加N个桩点,N为正整数,N个桩点分别与第一应用程序中的N个关键函数相关联,关键函数与关键数据流相关联,关键数据流用于决定第一应用程序的输出,关键函数用于决定关键数据流的输出,桩点用于指示为用于运行关键函数的线程分配第二计算资源,第二计算资源多于第一计算资源。
结合第四方面,在第四方面的某些实现方式中,上述插桩单元还用于,在第一前置函数与第一桩点之间添加第一预热桩点,其中,第一前置函数的运行时序在第一函数之前,且与所述第一函数相邻,第一函数为所述N个关键函数中的一个,第一函数与第一桩点相关联,第一桩点为所述N个桩点中的一个,第一预热桩点用于指示为用于运行第一函数的线程分配第三计算资源,该第三计算资源少于或者等于第二计算资源。
结合第四方面,在第四方面的某些实现方式中,上述装置还包括:运行单元,用于运行第一应用程序,以获取历史数据,该历史数据用于指示参与运行第一应用程序的多个进程和/或多个线程的运行时序;处理单元,用于根据历史数据,生成第一配置文件,该第一配置文件用于指示所述多个进程和/或所述多个线程之间运行的依赖关系,该第一配置文件还用于确定上述第二计算资源。
第五方面,提供了一种电子设备,该装置包括处理器和处理器,其中,处理器和存储器相连,其中,存储器用于存储程序代码,处理器用于调用程序代码,以执行如上述第一方面的方法设计中任意一种可能的实现方式中的方法,或者执行如上述第二方面的方法设计中任意一种可能的实现方式中的方法。
第六方面,提供了一种自动驾驶系统,包括第一操作系统,该第一操作系统用于执行如上述第一方面的方法设计中任意一种可能的实现方式中的方法。
结合第六方面,在第六方面的某些实现方式中,上述第一操作系统还用于:运行第一应用程序,以获取历史数据,历史数据用于指示参与运行第一应用程序的M个进程和/或N个线程的运行时序;根据历史数据,生成第一配置文件,该第一配置文件用于指示M个进程和/或N个线程之间运行的依赖关系。
第七方面,提供了一种车辆,该车辆包括如上述第六方面的系统设计中任意一种可能的实现方式中的自动驾驶系统。
第八方面,提供了一种芯片系统,芯片系统应用于电子设备;芯片系统包括一个或多个接口电路,以及一个或多个处理器;接口电路和处理器通过线路互联;接口电路用于从电子设备的存储器接收信号,并向处理器发送信号,信号包括存储器中存储的计算机指令;当处理器执行计算机指令时,电子设备执行上述第一方面的方法设计中任意一种可能的实现方式中的方法,或者执行上述第二方面的方法设计中任意一种可能的实现方式中的方法。
第九方面,提供了一种计算机可读存储介质,存储有计算机程序或指令,该计算机程序或指令用于实现第一方面的方法设计中任意一种可能的实现方式中的方法,或者实现上述第二方面的方法设计中任意一种可能的实现方式中的方法。
第十方面,提供了一种计算机程序产品,该计算机程序代码或指令在计算机上执行时,使得计算机执行上述第一方面的方法设计中任意一种可能的实现方式中的方法,或者执行上述第二方面的方法设计中任意一种可能的实现方式中的方法。
图1是本申请实施例提供的一种车辆100的功能示意性框图;
图2是本申请实施例提出的一种自动驾驶系统200的架构示意图;
图3是本申请实施例提出的时序感知层和资源调控层的运行示意图;
图4是本申请实施例提出的一种资源调度的方法400的流程示意图;
图5是本申请实施例提出的又一种资源调度的方法500的示意图;
图6是本申请实施例提出的又一种资源调度的方法600的原理示意图;
图7是本申请实施例提出的一种处理器绑核的方法700的原理示意图;
图8是本申请实施例提供的一种资源调度的装置800的示意性框图;
图9是本申请实施例提供的一种处理应用程序的装置900的示意性框图。
下面将结合附图,对本申请实施例中的技术方案进行描述。
本申请实施例将围绕包括多个设备、组件、模块等的系统来呈现各个方面、实施例或特征。应当理解和明白的是,各个系统可以包括另外的设备、组件、模块等,并且/或者可以并不包括结合附图讨论的所有设备、组件、模块等。此外,还可以使用这些方案的组合。
另外,在本申请实施例中,“示例的”、“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更优选或更具优势。确切而言,使用示例的一词旨在以具体方式呈现概念。
本申请实施例描述的业务场景是为了更加清楚地说明本申请实施例的技术方案,并不构成对于本申请实施例提供的技术方案的限定,本领域普通技术人员可知,随着技术的演变和新业务场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。
在本说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。
本申请实施例中,“至少一个”是指一个或者多个,“多个”是指两个或两个以上。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:包括单独存在A,同时存在A和B,以及单独存在B的情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指的这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b,或c中的至少一项(个),可以表示:a,b,c,a-b,a-c,b-c,或a-b-c,其中a,b,c可以是单个,也可以是多个。
本申请实施例中的技术方案可以应用于计算设备,例如服务器、主机、个人电脑、笔记本电脑、台式机等具有计算能力的设备。本申请实施例中的技术方案可以应用于包括异构芯片或嵌入式芯片的计算设备。
为了便于理解,下面对本申请实施例涉及的相关术语及相关概念进行介绍。本申请实施例使用的术语仅用于对本申请的具体实施例进行解释,而非旨在限定本申请。
自动驾驶智能操作系统:基于可移植操作系统接口(portable operating system interface,POSIX)标准的操作系统,适用于自动驾驶所需要的高性能计算和高带宽通信的操作系统,提供车辆环境感知、智能决策和路径规划等功能。
应用节点:在自动驾驶智能操作系统中,使用通信中间件封装后的具有特定自动驾驶功能(如感知、融合和规划等)的应用,通常是单进程、多线程的集合。节点双方或多方通过调用通信中间件的消息发送、接收等API实现消息、服务调用在进程或组件之间的传递。其中,通信中间件可以是机器人操作系统(robot operating system,ROS)、汽车开放系统架构(automotive open system architecture,AUTOSAR CM)中的通信管理(communication module,CM)模块等。
关键链路:一些由决定系统或者应用程序输出的应用节点连接而成的进程链路,例如,自动驾驶系统中,将传感器信号进行相应的处理后形成控制器信号的进程所构成的链路,该链路决定着控制器信号所包括的控制内容,而该链路可以被定义为关键链路,或称关键进程链路,亦或称关键节点链路。构成关键链路的应用节点可以被称作关键节点或者关键进程,而关键进程中的参与到关键链路业务的一些线程,也可以被称作关键线程,而关键线程调用的参与到关键链路业务的一些函数,例如自动驾驶系统通信业务中的订阅、回调、发布等业务函数,可以被称作关键函数。
应理解,在应用程序包括的全部进程链路中,除关键链路以外的其他链路,均可以称为非关键链路;在关键进程/节点包括的全部线程中,除关键线程以外的其他线程,均可以称为非关键线程;在关键线程调用的全部函数中,除关键函数以外的其他函数,均可以称为非关键函数。其中,关键进程/节点包括关键线程和非关键线程,非关键进程/节点仅包括非关键线程;关键线程能够调用关键函数和非关键函数,非关键线程仅能够调用非关键函数。
消息通道(topic):自动驾驶智能操作系统中,应用节点之间指定的通信通道,其组成包括发送者的发送端口、接收者的接收端口、通道名称、消息格式等。
端到端时延:自动驾驶系统和应用中,广义的是指从最开始传感器收到信号(如图像)开始,到最后底盘执行器执行具体某一动作(如刹车)的时延;狭义上指的是移动数据中心(mobile data center,MDC)上收到传感器发送的topic数据包开始,到最后向底盘的控制topic发送数据包的时延。而数据流经过关键链路的时延可以理解为端到端时延。
桩点代码:在已有的应用程序中的任意位置插入的代码,该代码用于提供特定的方式来观察或者修改应用程序,桩点代码在应用程序中插入的位置称为桩点或者消息桩点,当应用程序运行到桩点时,就会触发桩点代码的执行,以使得应用程序执行桩点代码包括的特定操作,所以桩点也可以用于指示触发桩点代码中的特定操作。鉴于此,也可以将桩点代码简称为桩点。
而在应用程序中插入桩点的动作,可以称作插桩。目前有两种主流的桩点类型:动态桩点和静态桩点,对于插入的桩点类型不同,插桩的动作也可以进一步称为动态插桩或者静态插桩。若应用程序为二进制程序,那么插桩的动作可以称为二进制插桩,对于插入的桩点类型不同,二进制插桩的动作也可以进一步称为动态二进制插桩或者静态二进制插桩。
图1是本申请实施例提供的一种车辆100的功能示意性框图。
车辆100可以包括感知系统120、显示装置130和计算平台150,其中,感知系统120可以包括感测关于车辆100周边的环境的信息的若干种传感器。例如,感知系统120可以包括定位系统,定位系统可以是全球定位系统(global positioning system,GPS),也可以是北斗系统或者其他定位系统、惯性测量单元(inertial measurement unit,IMU)、激光雷达、毫米波雷达、超声雷达以及摄像装置中的一种或者多种。
车辆100的部分或所有功能可以由计算平台150控制。计算平台150可包括处理器151至15n(n为正整数),处理器是一种具有信号的处理能力的电路,在一种实现中,处理器可以是具有指令读取与运行能力的电路,例如中央处理单元(central processing unit,CPU)、微处理器、图形处理器(graphics processing unit,GPU)(可以理解为一种微处理器)、或数字信号处理器(digital signal processor,DSP)等;在另一种实现中,处理器可以通过硬件电路的逻辑关系实现一定功能,该硬件电路的逻辑关系是固定的或可以重构的,例如处理器为专用集成电路(application-specific integrated circuit,ASIC)或可编程逻辑器件(programmable logic device,PLD)实现的硬件电路,例如现场可编程门阵列(Field Programmable Gate Array,FPGA)。在可重构的硬件电路中,处理器加载配置文档,实现硬件电路配置的过程,可以理解为处理器加载指令,以实现以上部分或全部单元的功能的过程。此外,还可以是针对人工智能设计的硬件电路,其可以理解为一种ASIC,例如神经网络处理单元(neural network processing unit,NPU)、张量处理单元(tensor processing unit,TPU)、深度学习处理单元(deep learning processing unit,DPU)等。此外,计算平台150还可以包括存储器,存储器用于存储指令,处理器151至15n中的部分或全部处理器可以调用存储器中的指令,以实现本申请实施例所述的相应功能。
本申请涉及的车辆可以包括路上交通工具、水上交通工具、空中交通工具、工业设备、农业设备、或娱乐设备等。例如车辆可以包括无人驾驶车辆,该车辆为广义概念上的车辆,可以是交通工具(如商用车、乘用车、摩托车、飞行车、火车等),工业车辆(如:叉车、挂车、牵引车等),工程车辆(如挖掘机、推土车、吊车等),农用设备(如割草机、收割机等),游乐设备,玩具车辆等,本申请实施例对车辆的类型不作具体限定。为了方便描述,本申请实施例以自动驾驶车辆为例进行详细说明。
在自动驾驶业务中,自动驾驶系统的数据流链路的端到端时延是衡量自动驾驶相应速度的关键指标,低端到端时延(例如小于100ms)能够大幅提高车辆和行人的安全系数。所以,端到端时延是自动驾驶系统和应用优化的关键目标。
在自动驾驶应用运行的过程中,自动驾驶系统为实现不同的数据流链路对应的业务,需要对应地分配相应的计算资源,而计算资源分配得是否合理,也影响着自动驾驶系统整体数据传输的端到端时延。
传统车机系统通常基于AUTOSAR经典(classicplatform,CP)平台应用,该架构下的应用功能简单且运行时序比较确定,为了使系统与应用数据传输的端到端时延维持在较低水平,原始设备制造商(original equipment manufacture,OEM)主机厂通过为系统中各个关键链路下的应用节点设置不同的静态优先级配置,以保障所有关键链路的应用节点时序不被打断或影响,最后达到时延最低的目标。
但是,上述方案基本只是针对一些常见工况、普适环境,预先配置系统资源调度相关的参数,难无法针对自动驾驶车辆在行驶过程中遇到的不同场景进行自适应动态调整,方案的泛化性不足。
为了更好地满足任务的实时性要求,现阶段已提出了一种解决方案,该方案通过估算应用程序在嵌入式平台上的运行时间,然后基于应用程序自动映射算法,将程序映射到硬件资源之上,在运行程序的过程中,系统能够根据该映射关系,为各个程序分配相应的资源,并且结合模拟退火算法和最早截止时间优先(earliest deadline first,EDF)调度模拟算法,生成静态任务调度表和任务绑核方案,使得系统各个中央处理器(central processing unit,CPU)核能够流畅地运行各自的程序,从而更好地满足任务的实时性要求。
但是,上述方案只是针对CPU的资源调度方案进行优化,并没有考虑到其他硬件资源的调度优化,例如图形处理器(graphics processing unit,GPU)等资源的调度优化;并且,上述方案实质上还是一种静态调度的方案,而自动驾驶业务过于复杂,将不同场景的业务与资源配置进行映射,让调度器感知这些业务对应的进程,并对这些进程作出最合理的资源调度,通常会因为场景样本数量的局限性以及调度算法能力的局限性,导致上述映射发生失真,难以实现系统资源调度的整体最优。
基于上述说明可知,现阶段针对自动驾驶应用场景下的资源调度技术存在如下问题:
1、需要基于大量的实车测量数据作为理论支撑,完成建模、仿真和模型优化的操作,这对训练数据的精度和训练场景的泛化程度要求很高,并且从获取数据到输出调度模型需要耗费相当长的时间,执行难度与时间成本过高。
2、资源调度所面向的对象粒度过大,通常为进程或者线程粒度,但是在一些进程中,某些线程的重要性并不高,或者在一些线程中,某些函数的重要性并不高,但是,它们对应的进程或者线程被系统视为整个业务中的关键进程或者关键线程后,这些关联于关键进程的非关键线程,或者关联于关键线程的非关键函数,也会被分配过于充足的资源来运行,所以资源调度并非整体最优。
3、离线调度难以完全满足自动驾驶业务各种场景下动态调整资源调度策略的需求。
鉴于此,本申请实施例提出了一种资源调度的方法、装置和系统,旨在解决上述源自系统资源调度底层的问题,提供一种动态的、细粒度的资源调度机制。
图2是本申请实施例提出的一种自动驾驶系统200的架构示意图。
该系统200可以包括应用层、平台层和硬件层。
上述应用层包括自动驾驶节点层,该自动驾驶节点层用于从自动驾驶车辆传感器采集激光雷达、摄像机、雷达等信号,并使用自动驾驶算法进行数据处理,推理计算得到自动驾驶车辆的当前位置、状态和外界状态,以及车辆控制信号或指令。
上述自动驾驶节点层中进一步包括感知节点、融合节点、规划节点和控制节点。
其中,感知节点用于执行传感器信号相关的进程,以获取激光雷达、摄像机、雷达等信号;融合节点用于自动驾驶算法将传感器信号中携带的数据进行数据融合,推理计算得到自动驾驶车辆的当前位置、状态和外界状态;规划节点用于结合数据融合结果,规划车辆下一时间段内的控制策略;控制节点用于根据控制策略,控制相应的车辆控制器,例如方向盘、制动器、油门等,从而完成对车辆的自动控制。
上述平台层,也称操作系统(operating system,OS)层,包括关于自动驾驶应用的时序感知层、资源调控层和OS子系统。
其中,时序感知层用于通过动态桩点、静态桩点或者业务调用API等方式,确定自动驾驶系统各个应用的运行时序状态信息,该运行时序状态信息包括不同应用中各个线程的运行状态、线程数据和进程之间以及线程之间的运行依赖关系,以及各个线程和/或进程当前计算资源的占用量。
资源调控层用于进行自动驾驶OS中各种计算资源的统一调用与分配,其中计算资源也称用于计算的资源,包括CPU计算资源、GPU计算资源、内存资源、总线带宽资源、网络带宽资源和输入/输出接口(input/output,IO)资源等。
OS子系统用于进行自动驾驶硬件资源的抽象与管理,OS子系统包括OS调度子系统、GPU驱动、DDR驱动、网络驱动等。
在上述系统200中,还涉及到以下硬件模块:CPU、GPU、内存、网卡和存储器。其中,存储器指的是外存,例如磁盘等。
其中,CPU和GPU用于为自动驾驶系统200和系统内应用提供算力资源;内存用于为自动驾驶系统200和系统内应用提供内存资源;网卡用于为自动驾驶系统200和系统内应用提供网络通信资源;存储器用于为自动驾驶系统200和系统内应用提供通用存储资源。
在一些可能的实施例中,自动驾驶应用层可以通过自动驾驶平台层获取保障车辆能够自动驾驶的源自硬件平台上的CPU、GPU、内存、网卡和存储器等资源。而时序感知层可以从自动驾驶应用层运行过程中获取到该层各个应用的运行时序状态信息,然后将该信息传递到资源调控层,然后资源调控层可以实时动态地将计算资源分配给关键数据流链路的应用节点,以尽可能地降低自动驾驶系统的数据流传输的端到端时延。
为了方便理解,以下针对上述系统200中的时序感知层和资源调控层的运行机制进行详细说明。
图3是本申请实施例提出的时序感知层和资源调控层的运行示意图。
在一些可能的实施例中,在自动驾驶系统运行的应用程序之前,可以预先在应用程序中添加N个桩点代码,N为正整数,该N个桩点代码分别用于指示对应的函数需要自动驾驶系统给予更多的资源来运行。
在一些可能的实施例中,在自动驾驶系统的资源调度机制中,自动驾驶系统通常是基于各个线程对应的优先级来为各个线程分配计算资源的。而在自动驾驶系统初始运行应用程序时,是基于公平调度方法为用于运行应用程序的各个线程分配资源的,但是上述桩点代码的引入,使得自动驾驶系统能够将用于运行桩点代码关联函数的线程对应的调度方案调整为特权调度,即把用于运行该函数的线程对应的资源调度优先级(后续简称为优先级)提高,高于公平调度方法下的优先级,那么函数对应的优先级越高,自动驾驶系统为该函数所在线程分配的资源就越多。
在一些可能的实施例中,上述公平调度方法可以是完全公平调度(completely fair scheduler,CFS),上述特权调度可以是时间片轮转(round robin,RR)调度或者实时(real time,RT)调度。其中,特权调度的优先级最小值,要大于公平调度的优先级最大值。
参考图3所示,图3示出的自动驾驶应用层下的链路为关键链路(也称关键数据流),以关键链路的感知节点为例,该感知节点为关键节点,而该感知节点包括3个关键线程,用于执行自动驾驶系统中通信业务中订阅、回调、发布的业务。而用于执行这3个业务的函数分别对应于1个桩点,为了方便描述,以下将订阅函数记作函数1,对应的桩点记作桩点1,回调函数记作函数2,对应的桩点记作桩点2,发布函数记作函数3,对应的桩点记作桩点3。
在一些可能的实施例中,桩点除了用于指示为特定函数分配更多的资源,还可以携带一些桩点信息。以桩点信息1为例,桩点信息1可以包括:桩点标识符(identity document,ID)、桩点1位于系统运行应用程序的整个时序中的时序帧ID、桩点1所在线程的线程控制符(threadidentifier,TID)、桩点1所在进程的进程控制符(process identifier,PID)、以及与用于运行函数1的线程1存在依赖关系的线程,例如用于运行函数2的线程2,依赖关系可以为线程2依赖于线程1等。桩点信息2和桩点信息3同理。
应理解,时序帧ID的数值对应于时序帧在整个应用程序运行时序中的位置,例如时序帧ID越小,时序帧在整个应用程序运行时序中就越靠前。
在自动驾驶应用层将应用程序运行到桩点1时,可以将桩点1携带的桩点信息1添加至时序感知层的时序感知队列中;类似地,在自动驾驶应用层将应用程序运行到桩点2时,可以将桩点2带的桩点信息1添加至时序感知层的时序感知队列中;在自动驾驶应用层将应用程序运行到桩点3时,可以将桩点3携带的桩点信息3添加至时序感知层的时序感知队列中。
在一些可能的实施例中,在时序感知层将各个桩点信息添加到时序感知队列的过程中,会基于桩点信息包括的时序帧ID,来确定各个桩点信息所述桩点的运行时序,进而确定各个桩点对应函数的运行时序信息,并根据该运行时序信息再将各个桩点信息按照对应的顺序,安插在时序感知队列中。
示例地,桩点1在桩点2之前,桩点3在桩点2之后,那么在时序感知队列中,桩点信息1就安插在桩点信息2之前,桩点信息3就安插在桩点信息2之后。
在一些可能的实施例中,上述时序感知队列的实体形态可以是一种环形缓冲区(ring buffer),当然,也可以替换为其他数据存储结构,本申请实施例对此不做限定。
在一些可能的实施例中,上述时序感知队列可以存放在用户态和内核态共享的一片内存空间中。
在一些可能的实施例中,系统200还能够通过传感器感知车辆自动驾驶的场景是否发生切换,在车辆自动驾驶的场景发生切换时,还可以将切换后的场景信息传递到资源调控层中,作为资源调度的部分依据。
进一步地,资源调控层的从时序感知队列中依次读取桩点信息,而通过读取各个桩点信息的顺序,即可确定各个桩点对应函数的运行时序信息;然后根据各个桩点信息,确定各个桩点之间的拓扑信息;然后资源调控层中的时序感知调度器可以根据运行时序信息和拓扑信息,或者根据运行时序信息、拓扑信息和切换后的场景信息,确定资源调度方案,例如,为每个桩点对应的函数设置CPU调度优先级,进而为每个函数所在的线程配置相应的计算资源。
在一些可能的实施例中,上述桩点也可以替换为相应的自定义API,该API的功能可以定义为与上述桩点相同。
在一些可能的实施例中,考虑到自动驾驶应用程序中存在多条关键链路,这些关键链路或相互独立,或相互依赖,甚至是某些关键链路的运行依赖于其他关键链路的某个线程或函数的运行结果。为了实现自动驾驶系统为各个关键链路合理分配资源,资源调控层可以根据每条关键链路下各个进程、各个线程以及各个函数的运行时序和拓扑关系,为每条关键链路维护一个数据流时序表,以体现不同关键链路的运行时序状态,然后资源调控层的时序感知调度器可以根据各个数据流时序表,确定整体的资源调度方案,进而为每个函数对应的线程配置相应的计算资源。
应理解,在运行与桩点相关联的关键函数时,系统基于前述资源调度方案,可以为运行该关键函数的线程分配较多的计算资源,而当该关键函数运行完毕后,系统可以主动地将分配给该线程的计算资源撤出,根据该线程后续执行的函数是否与桩点关联,来判断是否继续为该线程提供较多的计算资源。
在一些可能的实施例中,上述实施例提到的桩点信息、函数的运行时序信息、桩点之间的拓扑信息以及数据流时序链表以及资源调度方案都可以配置文件的形式,传递到OS子系统。在OS子系统启动时,OS子系统可以读取到上述配置文件,从而实现在自动驾驶系统运行的过程中,OS子系统自动收集并感知自动驾驶应用运行时序信息,并且结合上述配置文件,动态地调整关键链路节点下关键线程组中各个线程的优先级。
基于上述技术方案,基于系统200的资源调度机制,保障了关键线程组能够得到合适的计算资源,从而降低自动驾驶系统数据流链路的端到端时延。而且通过桩点指示为用于实现关键函数的线程分配较多的计算资源,可见该过程的资源调度优化的对象是函数粒度,避免了关键线程在运行非关键函数时,也被过度分配较多资源的问题,有助于使系统资源调度策略达到整体最优。此外,因为自动驾驶系统在不同的应用场景下需要运行不同的应用程序,而不同的应用程序都会对应维护相应数量的数据流时序表,而这些实时维护的数据流时序表就是确定资源调度方案的依据,所以系统200能够实现资源调度方案的实时动态调整,满足自动驾驶业务各种场景下动态调整资源调度策略的需求,而且不需要大量的实车测量数据作为确定资源调度方案的依据,实现是难度和时间成本都很低。
基于前述实施例可知,上述系统200在运行应用程序的过程中,之所以能够对应用程序的一些关键线程组采取相应的资源调度策略,是在自动驾驶系统运行的应用程序之前,预先在应用程序中添加了与关键链路下的关键函数对应的桩点代码,以指示系统200为桩点代码对应的关键函数给予充足的计算资源。
鉴于此,本申请实施例提出了一种处理应用程序的方法,以使得系统在运行应用程序时,能够通过应用程序中的桩点指示,为对应的关键函数分配计算资源。
以第一应用程序为例,该第一应用程序由操作系统运行,该操作系统可以是前述实施例中的系统200中的操作系统,操作系统默认为用于运行第一应用程序中的函数的线程分配第一计算资源。
在一些可能的实施例中,可以在第一应用程序中添加N个桩点,N为正整数,该N个桩点分别与第一应用程序中的N个关键函数相关联,关键函数与关键数据流相关联,关键数据流用于决定第一应用程序的输出,关键函数用于决定关键数据流的输出,桩点用于指示为用于运行关键函数的线程分配第二计算资源,该第二计算资源多于第一计算资源。
示例地,上述操作系统可以采用Linux操作系统,也可以采用Windows系统,本申请实施例对此不做限定。
在一些可能的实施例中,操作系统可以为用于运行第一应用程序的线程设置优先级,而线程对应的优先级决定着操作系统为线程分配的计算资源的多少。所以操作系统可以通过为线程设置优先级的方式,来实现对线程的计算资源调度。
通常情况下,操作系统在运行第一应用程序的初始时刻,会默认采取公平调度方案,而在公平调度方案下,系统也需要为用于运行第一应用程序中各个函数的线程设定属于第一优先级区间的优先级,而在操作系统进行资源调度的初始时刻,各个线程对应的优先级都是相同的默认值,在操作系统运行第一应用程序的过程中,操作系统内部的逻辑功能单元可以更改各个线程对应的优先级,只不过在公平调度方案下,各个线程对应的调度优先级需要满足在第一优先级区间内。
示例地,在CFS方案下,在操作系统运行第一应用程序期间,操作系统可以将用于运行第一应用程序中的各个函数的线程对应的优先级设置为[100,139]区间中的一个,[100,139]可以理解为上述第一优先级区间。例如,在操作系统运行第一应用程序的初始时刻,可以将用于运行第一应用程序中的各个函数的线程对应的优先级默认设置为120。
应理解,优先级对应的数值越小,代表着优先级越高。
在操作系统运行到第一应用程序的桩点后,可以根据桩点指示的内容,来为与该桩点相关联的函数分配相应的计算资源。
在一些可能的实施例中,该桩点可以指示将用于运行某个函数的线程对应的优先级调整至第二优先级区间内,且该第二优先级区间的下界高于第一优先级区间的上界,这意味着,与该桩点关联的函数为关键函数,操作系统需要针对用于运行该关键函数的线程采取特权调度,即把用于运行该关键函数的线程对应的优先级提升至第二优先级区间内,例如采取RR调度,将该线程的优先级设置为[0-99]中的一个,以使得操作系统后续为该线程分配更多的计算资源。基于此可知,操作系统为对应于默认优先级的线程分配第一计算资源少于操作系统根据第二优先级区间内的优先级分配的第二计算资源。
或者,上述桩点也可以直接指示为用于运行某个函数的线程分配第二计算资源,该第二计算资源可以表示为第二计算资源的容量,也可以表示第二计算资源的分配顺序,还可以用于表示第二计算资源在操作系统的所有计算资源中占有的权重。操作系统运行到该桩点后,可以确定第二计算资源所表示的含义,进而为对应的线程分配第二计算资源。
当然,上述第二计算资源所表示的含义,也可以通过上述为线程设置优先级的方式来体现。
在一些可能的实施例中,上述桩点可以是动态桩点,也可以是静态桩点,还可以替换为自定义的API。
基于上述技术方案,通过在第一应用程序中添加与关键函数对应的桩点,以使得系统在运行到桩点时,能够实时动态地为用于运行该关键函数的线程采取特权调度方案,或者为用于运行该关键函数的线程分配指定的计算资源,从而使得线程能够有充足的计算资源来完成关键函数的运行,以保障应用程序中的关键进程链路能够尽快运行完毕,降低数据流在关键链路中传输的端到端时延。
在一些可能的实施例中,在向第一应用程序中添加桩点的过程中,还可以在关键函数对应的桩点之前,设置预热桩点。
例如,上述第一应用程序的N个关键函数中包括第一函数,该第一函数与第一桩点相关联,而第一桩点为在第一应用程序中添加的N个桩点中的一个,基于此,可以在第一前置函数与第一桩点之间添加第一预热桩点,其中,第一前置函数的运行时序在第一函数之前,且与所述第一函数相邻,第一函数为所述N个关键函数中的一个,第一函数与第一桩点相关联,第一桩点为所述N个桩点中的一个,第一预热桩点用于指示为用于运行第一函数的线程分配第三计算资源,该第三计算资源少于或者等于第二计算资源。
在一些可能的实施例中,在操作系统的计算资源充足的情况下,操作系统根据第一预热桩点为用于运行第一函数的线程分配的第三计算资源还可以多于上述第二计算资源。
在一些可能的实施例中,上述第一预热桩点也可以用于指示将用于运行第一函数的线程对应的优先级提前调整至第二优先级区间内。
在一些可能的实施例中,上述第一预热桩点可以进一步指示将用于运行第一函数的线程对应的优先级调整至第二优先级区间的下界,或者也可以设置为其他优先级,例如在线程运行第一前置函数时,操作系统为该线程分配的优先级,其中,第一前置函数既可以是关键函数,也可以是非关键函数。
在一些可能的实施例中,上述预热桩点可以设置于第一前置函数退出的位置,或者在第一前置函数的结尾处设置有退出桩点的情况下,上述预热桩点为第一前置函数的退出桩点。
在一些可能的实施例中,在第一函数为运行第一应用程序进入的第一个函数,那么第一函数之前可以不添加上述第一预热桩点。
基于上述技术方案,由于预热桩点的引入,操作系统在第一前置函数执行完毕后,能够在运行到作为关键函数的第一函数之前,先运行到第一预热桩点,从而基于第一预热桩点的指示,提前为用于运行第一函数的线程分配相应的计算资源,以保障线程能够有计算资源用于运行第一函数,从而有效避免系统在运行到第一函数时,用于运行第一函数的计算资源被其他关键函数抢占,从而保障了第一函数的运行。
在一些可能的实施例中,在第一应用程序投入到实际应用之前,操作系统可以预先运行上述第一应用程序,以获取历史数据,该历史数据用于指示参与运行第一应用程序的多个进程和/或多个线程的运行时序;根据历史数据,生成第一配置文件,该第一配置文件用于指示所述多个进程和/或所述多个线程之间运行的依赖关系,该第一配置文件还用于确定上述第二计算资源。
此外,本申请实施例提出了一种资源调度的方法,该方法可以是在运行上述处理应用程序的方法获得的第一应用程序时执行的方法。
图4是本申请实施例提出的一种资源调度的方法400的流程示意图。
S410:运行第一应用程序,该第一应用程序包括第一关键数据流,该第一关键数据流用于决定第一应用程序的输出,该第一关键数据流与M个进程下的N个线程相关联,其中,M个进程包括第一进程,该第一进程与第一线程、第一函数和第一桩点关联,该第一线程用于运行第一函数,其中,M和N为正整数。
应理解,应用程序的数据流是指数据在应用程序中的传输路径和过程,涵盖了数据的产生、传递、存储和处理的过程。而上述第一关键数据流则指的是在第一应用程序中能够决定程序输出的数据传输路径。该第一关键数据流中的数据在传输的过程中,会经过多个业务进程,该多个业务进程决定着多个业务进程对应的应用系统的输出。相应地,第一应用程序可以包括多个子应用程序,该多个子应用程序分别用于实现上述实施例提到的多个业务,例如,感知业务、融合业务、规划业务和控制业务等。
此外,方法400提到的“第一计算资源”所指代的含义,与前述处理应用程序的方法对应实施例提到的“第一计算资源”所指代的含义不同。在方法400中,第一计算资源指示的是为第一线程分配的计算资源,而在处理应用程序的方法中,第一计算资源指示的是操作系统默认为用于运行函数的线程分配的计算资源。
在一些可能的实施例中,上述第一桩点可以是在运行第一应用程序的过程中添加至第一应用程序的,即基于动态二进制插桩的方法实现第一桩点的插入;或者,第一桩点也可以是在运行第一应用程序之前预先添加至第一应用程序的,即基于静态二进制插桩的方法实现第一桩点的插入。基于该方法,可以通过多种插桩的方式将桩点插入到第一应用程序,从而增加了插桩的灵活性。
S420:根据第一桩点,为第一线程分配第一计算资源,该第一计算资源用于第一线程运行第一函数。
在一些可能的实施例中,上述S420还可以包括如下步骤:
S421:根据第一桩点,确定第一计算资源的容量,并根据第一计算资源的容量,为第一线程分配第一计算资源;
或者,S422:根据第一桩点,确定第一计算资源的顺序,并根据第一计算资源的顺序,为第一线程分配第一计算资源;
或者,S423:根据第一桩点,确定第一占有率,第一占有率用于表示第一计算资源在所有计算资源中的占有率(或者权重),并根据第一占有率,为第一线程分配第一计算资源。
应理解,上述S423中的“所有计算资源”指的是在第一时间范围内用于分配的计算资源,该第一时间范围指的是其他线程与第一线程之间的运行时间存在重叠部分的时间范围,进一步地,上述所有计算资源指的是在第一时间范围内,用于分配给第一线程和其他线程的计算资源。基于此,由于第一占有率是通过一个分数计算得到的,而该分数的分母可以用于表示在第一时间范围内,用于分配给其他线程的计算资源与上述第一计算资源之和,该分数的分子则是第一计算资源。
需要说明的是,上述第一进程与第一线程、第一函数和第一桩点关联,该关联关系如下:第一进程包括至少一个线程,上述第一线程属于该至少一个线程,而第一线程用于运行至少一个函数,上述第一函数属于该至少一个函数,上述第一函数为第一应用程序中的关键函数,所以基于本申请实施例提出的方法,为将第一函数与第一桩点关联,以使得操作系统运行到第一桩点时,即可确定为用于运行第一函数的第一线程所分配的第一计算资源。示例地,上述第一进程可以是图2所示的应用层中的一个节点,例如融合节点,而融合节点可以包括线程1、线程2和线程3,其中线程1用于运行回调函数,而该回调函数与第一桩点相关联,那么,该回调函数可以理解为上述第一函数,该线程1可以理解为上述第一线程,操作系统运行到第一桩点时,即可确定为线程1所分配的计算资源。
在一些可能的实施例中,第一应用程序中也包括非关键函数,且非关键函数并不与方法400中提到的桩点相关联。操作系统在运行到第一应用程序的非关键函数时,会为用于运行非关键函数的线程分配默认计算资源,该默认计算资源少于上述第一计算资源。而在第一线程基于第一计算资源运行完毕第一函数后,第一线程再用于运行非关键函数时,操作系统基于本方法400,操作系统并不会继续给第一线程分配第一计算资源,而是减少为默认计算资源。
在一些可能的实施例中,在第一线程将第一函数运行完毕后,操作系统可以将分配给第一线程的第一计算资源收回,或者减少计算资源的分配,待第一线程运行其他函数时,再基于方法400,为第一线程重新分配或者调整分配给第一线程的计算资源。
在一些可能的实施例中,操作系统可以基于优先级进行计算资源的调度,并通过优先级来表示为第一线程分配的第一计算资源的容量、顺序或者权重。操作系统在运行第一应用程序的初始时刻,可以默认用于运行第一应用程序的各个线程对应的优先级均在第一优先级区间内,基于此,上述第一桩点可以用于指示将第一线程的优先级调整至第二优先级区间,该第二优先级区间的下界高于第一优先级区间的上界。以此表示,操作系统需要为第一线程分配的第一计算资源,要多于默认为第一线程分配的计算资源。所以操作系统需要为第一线程调度更多的计算资源,以保障第一函数高效运行。
其中,第一优先级区间可以对应于CFS方案下的调度优先级区间,即[100,139];对应地,第二优先级区间可以对应于RR调度或者RT调度方案下的调度优先级区间,即[0,99]。需要说明的是,本实施例中具体优先级区间的数值时基于对应调度方案提出的,在其他基于公平调度或者基于特权调度的方案,上述第一优先级区间和上述第二优先级区间对应的具体数值区间可以进行适应性调整。
在一些可能的实施例中,上述第一桩点可以是动态桩点,也可以是静态桩点,还可以替换为自定义的API,后续实施例中涉及到的桩点与第一桩点同理。
应理解,上述第一桩点对应的第一函数可以理解为是关键函数,即用于决定第一应用程序输出的函数,所以需要通过第一桩点指示为用于运行该第一函数的第一线程分配更多的计算资源。
需要说明的是,通常情况下,第一关键数据流还会涉及一些未与桩点关联的函数,这意味着这些函数为非关键函数。但是基于现有技术的调度方案,因为第一线程运行的第一函数为关键函数,所以可以静态地为第一线程分配第一计算资源,但是如果第一线程在运行完毕第一函数后,还会用于运行非关键函数,那么即使第一线程在运行非关键函数时,操作系统还是会为第一线程分配第一计算资源,用于运行该非关键函数,而对于正在运行非关键函数的第一线程而言,操作系统并不需要为第一线程分配过多的第一计算资源,该资源调度方案可能会造成用于其他关键函数的线程得不到足够的计算资源,导致第一关键数据流的端到端时延增加。
但是,基于上述技术方案,操作系统运行到第一应用程序的第一桩点后,不仅能够确定与第一桩点相关联的第一函数为关键函数,而且还会为用于运行第一函数的第一线程分配充足的计算资源,即第一计算资源,以使得第一线程能够有充足的计算资源高效快速地运行第一函数,而且在第一线程运行其他函数时,操作系统可以重新为第一线程分配计算资源,而不是继续为第一线程分配第一计算资源,实现操作系统能够动态地以函数粒度为线程分配计算资源,有助于将更多剩余的资源分配给其他运行关键函数的线程,从而有助于降低第一关键数据流的端到端时延。尤其是在第一应用程序为自动驾驶应用程序的情况下,能够有效提升用户的驾乘体验,并且保障车内乘客、车外行人以及其他车辆的安全性。
图5是本申请实施例提出的又一种资源调度的方法500的示意图。其中,图5中的(a)为本申请实施例提出的一种资源调度的方法500的流程图,图5中的(b)为本申请实施例提出的一种资源调度的方法500的原理示意图。
参考图5所示,上述第一应用程序还包括第二关键数据流,该第二关键数据流用于决定第一应用程序的输出,该第二关键数据流与M个进程下的N个线程相关联,该M个进程还包括第二进程,该第二进程与第二线程、第二函数和第二桩点关联,该第二线程用于运行第二函数。基于此,方法500可以包括如下操作:
S510:根据第一配置文件,确定第二线程与第一线程之间运行的第一依赖关系,该第一配置文件用于指示上述M个进程和/或上述N个线程之间运行的依赖关系。
在一些可能的实施例中,上述S510可以在操作系统运行到第一桩点和第二桩点时执行,其中“运行到第一桩点和第二桩点”可以理解为,同时运行到了第一桩点和第二桩点,或者在运行到第一桩点后,且在第一函数运行完毕前,运行到了第二桩点。换言之,该场景可以理解为操作系统需要同时对两个并行的用于运行关键函数的线程进行计算资源的调度。
在一些可能的实施例中,上述第一配置文件可以通过预先实验的方式来获取,以自动驾驶应用场景为例,第一应用程序为用于实现自动驾驶业务的程序,该第一应用程序搭载于自动驾驶系统。在将第一应用程序部署在自动驾驶系统上后,可以控制车辆基于第一应用程序进行试跑,在该过程中会生成各个线程运行第一应用程序中各个函数的历史数据,该历史数据可以包括桩点信息、各个线程运行函数的时序、在线程运行函数过程中线程间的依赖关系等,并通过对历史数据的统计与分析,即可确定上述第一配置文件,以提供给操作系统用于后续的资源调度。应理解,自动驾驶系统是一种应用系统,而应用系统则是在操作系统提供的环境下运行的。
S520:根据第二桩点和第一依赖关系,为第二线程分配第二计算资源,该第二计算资源用于第二线程运行第二函数。
进一步地,在第一依赖关系为第一线程的运行依赖于第二线程的情况下,第一计算资源多于第二计算资源,或者,在第一依赖关系为第二线程的运行依赖于第一线程的情况下,第一计算资源少于第二计算资源,以此保障操作系统较早进入的关键数据流能够顺利输出。
应理解,上述第一关键数据流和第二关键数据流所关联的进程是相同的,也可以理解为第二关键数据流为第一关键数据流的镜像。而上述第一依赖关系实质上是第一线程与第二线程的运行时序关系,以第一线程的运行依赖于第二线程为例,该依赖关系就意味着第一线程的运行时序在第二线程之后,而此时与第一关键数据流相关联的第一线程和与第二关键数据流相关联的第二线程并行,与第一关键数据流相关联的第一线程已经完成的第一函数的运行,而第二关键数据流尚未进入到第一线程运行第一函数的流程,由此可见,第一关键数据流为第二关键数据流的前帧数据流,所以基于上述技术方案可知,在这两个关键数据流并行的情况下,操作系统可以为第一关键数据流相关的线程分配更多的资源,以保障前帧数据流能够顺利输出,以避免同时为两个数据流的线程均分配充足的计算资源,导致计算资源占用过多,导致其他线程得不到足够的计算资源,使大量函数在短期内(例如100ms至300ms)都无法运行完成的情况出现。
此外,方法500提到的“第二计算资源”所指代的含义,与前述处理应用程序的方法对应实施例提到的“第二计算资源”所指代的含义不同。在方法500中,第二计算资源指示的是为第二线程分配的计算资源,而在处理应用程序的方法中,第二计算资源指示的是操作系统根据桩点为用于运行关键函数的线程分配的计算资源。
在一些可能的实施例中,上述第一依赖关系可以通过第一线程和第二线程的运行时序来表示,或者,上述第一依赖关系可以通过第一线程与第一关键数据流的终点的距离和第二线程与第二关键数据流的终点的距离来表示,该距离可以理解为线程与业务流程的终止节点之间的跳数,当线程执行完毕后,数据流会跳转至下一个线程,直至跳转至终止节点,或者,该距离也可以理解为从运行该线程到该线程关联的数据流输出所需的时间,该时间可以通过操作系统运行第一应用程序生成的历史数据来获取。
在一些可能的实施例中,上述方法500可以采用图论算法来执行,即在确定关键链路的线程间的依赖关系后,通过图论算法,为与桩点关联的函数设置调度优先级,例如,位于有向图的上级节点对应的优先级高于下级节点对应的优先级,或者位于有向图的上级节点对应的计算资源多于下级节点对应的计算资源。
基于上述技术方案,通过判断并行线程之间的依赖关系,为被依赖的线程提供相对多的计算资源,尽可能降低被依赖的线程所在的关键数据流的端到端时延的同时,也能够有效避免同时为多个关键数据流对应的多个并行线程分配等量充足的计算资源,导致其他并行的线程因资源不充足,无法在短期内运行完毕的问题,进而减小了多个并行关键数据流的端到端时延的抖动。
图6是本申请实施例提出的又一种资源调度的方法600的原理示意图。
参考图6所示,上述第一进程还与第三桩点相关联,在第一进程的运行时序中,该第三桩点与上述第一桩点相邻,且位于上述第一桩点之前,上述方法600包括如下操作:根据第三桩点,为第一线程分配第三计算资源,该第三计算资源小于或者等于第一计算资源,该第三计算资源用于保障第一线程运行第一函数。
在一些可能的实施例中,上述第三桩点可以设置于时序位于第一函数之前的第三函数的出口位置,在第三函数的出口设置有退出桩点的情况下,该第三桩点可以是与第三函数关联的退出桩点,即在执行完毕第三函数后,直接运行第三桩点,从而为第一线程提前分配第三计算资源。
在一些可能的实施例中,在计算资源充足的情况下,上述第三计算资源还可以大于上述第一计算资源。
在一些可能的实施例中,在操作系统基于线程对应的优先级进行资源调度的情况下,上述第三桩点还可以用于指示将第一线程对应的优先级设置为第一优先级,该第一优先级与第三计算资源对应。
在一些可能的实施例中,上述第一优先级可以是上述第二优先级区间的下界。虽然第一优先级为第二优先级区间的下界,但是至少可以为第一线程提前分配相应的计算资源,以使得这些计算资源能够保障第一函数能够被运行完毕,避免在运行到第一函数时,计算资源被其他关键线程提前抢占,导致第一函数无法正常运行。当然,第一优先级可以是第二优先级区间内的其他优先级数值,本申请实施例对此不做限定。
在一些可能的实施例中,在运行到第三桩点时,操作系统可以为第一线程分配第三计算资源(假设第三计算资源少于第一计算资源),当运行到第一桩点时,操作系统可以先判断当前剩余计算资源是否满足第一条件,该第一条件为剩余计算资源大于或者等于第一计算资源与第三计算资源之差。若满足第一条件,则为第一线程补充分配计算资源,使第一线程能够分得第一计算资源;若不满足第一条件,则不为第一线程补充分配计算资源。
基于上述技术方案,能够有效避免关键函数的计算资源提前被其他非关键线程抢占,导致关键函数无法尽快运行完毕的情况,有助于进一步降低关键数据流传输的端到端时延。
通常情况下,操作系统可以控制进程或者线程与CPU核(也称处理器核)的绑定关系,该过程可以称作CPU绑核。基于CPU绑核技术,将关键线程绑定性能更强的CPU核(也称CPU大核),从而可以为关键线程提供更高的计算性能和更快的响应速度。关键线程可以充分利用CPU大核的计算能力,提升应用程序的运行速度和响应性能。而且通过绑核技术,可以更加精确地控制进程或线程在哪些CPU核上运行,有效降低了为操作系统为多个线程分配计算资源时,多个线程抢占一个CPU核的计算资源的情况发生,使得系统管理更加灵活和方便。基于此,本申请实施例中的提到的第一线程也可以与相应的CPU核绑定,以通过该绑定的CPU核为第一线程分配计算资源。
图7是本申请实施例提出的一种处理器绑核的方法700的流程示意图。
参考图7所示,上述第一线程分别与第一处理器核和第二处理器核绑定,其中,第一处理器核和第二处理器核分别被配置用于为第一线程提供第二计算资源。基于此,方法700包括如下步骤:
S710:预测第一处理器核为第一线程提供第一计算资源后的第一资源占用率。
在第一资源占用率小于或者等于第一阈值的情况下,转到S720,反之,转到730。
示例地,上述第一阈值可以是根据用于运行第一应用程序的操作系统的硬件性能预设的阈值。
S720:通过第一处理器核为第一线程提供第一计算资源。
S730:预测第二处理器核为第一线程提供第一计算资源后的第二资源占用率。
在第二资源占用率小于或者等于第一阈值的情况下,转到S740,反之,转到750。
S740:通过第二处理器核为第一线程提供第一计算资源。
S750:预测第三处理器核为第一线程提供第一计算资源后的第三资源占用率,该第三处理器核未与第一线程绑定。
在第三资源占用率小于或者等于第一阈值的情况下,转到S760,反之,转到770。
S760:通过第三处理器核为第一线程提供第一计算资源。
在一些可能的实施例中,在执行S760之前,将第一线程与第一处理器核以及第二处理器核解绑,然后于第三处理器核绑定。
S770:预测第四处理器核为第一线程提供第一计算资源后的第四资源占用率,该第四处理器核未与第一线程绑定。如此往复。
在一些可能的实施例中,在通过第三处理器核为第一线程提供第一计算资源的情况下,在第一线程的函数基于第一计算资源运行完毕后,将第一线程重新与上述第一处理器核与第二处理器核绑定。
基于上述技术方案,能够避免多个线程抢占一个处理器核的计算资源的情况,有助于提升系统运行第一应用程序的效率,降低数据流在关键进程链路传输的端到端时延。
在一些可能的实施例中,为了避免因关键函数陷入死循环等异常状态,导致被该关键函数占用的计算资源无法释放出来,甚至导致与该关键函数所在的线程绑定的处理器核不可用,本申请实施例提出了一种防超时机制,以解决该问题。以运行第一函数为例,该防超时机制包括如下步骤:
在第一线程运行上述第一函数的起始时刻,开启第一定时器,该第一定时器设置的时长大于或者等于运行完第一函数所需的时长;在第一定时器超时,且第一函数未完成运行的情况下,减少为第一线程分配的第一计算资源。
在一些可能的实施例中,上述第一定时器设置的时长可以是完成运行第一函数所需的时长的两倍。
应理解,上述方法也适用于其他关联桩点的函数。
基于上述技术方案,能够有效避免因关键函数陷入死循环等异常状态,导致与该关键函数所在的线程绑定长时间抢占处理器资源的情况,从而使计算资源的分配更为合理。
在一些可能的实施例中,考虑到一些相对重要的非关键函数可能因为关键函数的资源抢占,导致该非关键函数长时间无法获得计算资源去运行,从而导致该非关键函数失效。为了避免上述情况发生,本申请实施例提出了一种非关键函数保障机制,以解决该问题。以第一应用程序还包括的第四函数为例,该第四函数不与本申请提出的桩点相关联,意味着该第四函数为非关键函数,该非关键函数保障机制包括如下步骤:
获取预设的第一运行时段,该第一运行时段大于或者等于运行完第四函数所需的时长;从运行到第四函数的时刻起的第一运行时段内,为用于运行所述第四函数的线程分配第四计算资源,该第四计算资源大于或者等于第一计算资源。
在一些可能的实施例中,上述第四函数可以与第一应用程序的关键数据流相关联,也可以与第一应用程序中的非关键数据流相关联,本申请实施例对此不做限定。
需要说明的是,虽然第四函数是非关键函数,但是第四函数可以是第一应用程序中所有非关键函数中用于实现相对重要业务的函数,第四函数不需要在较短的周期内进行周期性的运行,但是需要在指定时刻通过第四函数触发相应的重要业务。以自动驾驶业务为例,第四函数可以是车辆底盘功能相关的函数,虽然第四函数可能不直接与自动驾驶业务中的关键数据流(感知、融合、规划或控制)相关联,但是自动驾驶系统的底盘功能也是相对重要的,所以保障第四函数的正常且及时地运行,也是比较重要的。
在一些可能的实施例中,上述第一运行时段可以通过外部输入获得,也可以在系统运行前预设。
在一些可能的实施例中,由于上述第四计算资源多于上述第一计算资源,那么基于优先级调度的方案可知,第一线程在运行第四函数时对应的优先级比运行第一函数时对应的优先级还高。
基于上述技术方案,能够避免用于运行非关键函数的计算资源长时间被关键函数所在的线程抢占,导致非关键函数失效的情况。从而保障了第一应用程序运行的功能完整性,尤其是在第一应用程序为自动驾驶应用程序的情况下,能够提升用户的驾乘体验。
此外,本申请实施例还提供用于实现以上任一种方法的装置,该装置包括用以实现以上任一种方法的单元(或手段)。
图8是本申请实施例提供的一种资源调度的装置800的示意性框图。
在一些可能的实施例中,上述装置800用于构成操作系统。
该装置800包括:
运行单元810,用于运行第一应用程序,该第一应用程序包括第一关键数据流,该第一关键数据流用于决定第一应用程序的输出,该第一关键数据流与M个进程下的N个线程相关联,该M个进程包括第一进程,第一进程与第一线程、第一函数和第一桩点关联,该第一线程用于运行第一函数,M和N为正整数;
第一操作单元820,用于根据第一桩点,为第一线程分配第一计算资源,该第一计算资源用于第一线程运行第一函数。
在一些可能的实施例中,上述第一操作单元820具体用于:根据第一桩点,确定第一计算资源的容量,并根据第一计算资源的容量,为第一线程分配第一计算资源;或者,根据第一桩点,确定第一计算资源的顺序,并根据第一计算资源的顺序,为第一线程分配第一计算资源;或者,根据第一桩点,确定第一占有率,第一占有率用于表示第一计算资源在所有计算资源中的占有率,并根据第一占有率,为第一线程分配第一计算资源。
在一些可能的实施例中,上述第一桩点是在运行第一应用程序的过程中添加至第一应用程序的;或者,上述第一桩点是在运行第一应用程序之前预先添加至第一应用程序的。
在一些可能的实施例中,上述第一应用程序还包括第二关键数据流,该第二关键数据流用于决定第一应用程序的输出,第二关键数据流与M个进程下的N个线程相关联,M个进程还包括第二进程,第二进程与第二线程、第二函数和第二桩点关联,第二线程用于运行第二函数,上述装置800还包括:
确定单元830,用于根据第一配置文件,确定第二线程与第一线程之间运行的第一依赖关系,该第一配置文件用于指示上述M个进程和/或上述N个线程之间运行的依赖关系;
上述第一操作单元820还用于,根据第二桩点和第一依赖关系,为第二线程分配第二计算资源,第二计算资源用于第二线程运行第二函数,在第一依赖关系为第一线程的运行依赖于第二线程的情况下,第一计算资源多于第二计算资源,或者,在第一依赖关系为第二线程的运行依赖于第一线程的情况下,第一计算资源少于第二计算资源。
在一些可能的实施例中,上述第一进程还与第三桩点相关联,在第一进程的运行时序中,第三桩点与第一桩点相邻,且位于第一桩点之前,上述第一操作单元820还用于:根据第三桩点,为第一线程分配第三计算资源,该第三计算资源小于或者等于第一计算资源,该第三计算资源用于保障第一线程运行第一函数。
在一些可能的实施例中,上述第一线程分别与第一处理器核和第二处理器核绑定,第一处理器核和第二处理器核分别被配置用于为第一线程提供第一计算资源,上述装置800还包括:
预测单元840,用于预测第一处理器核为第一线程提供第一计算资源后的第一资源占用率;
在第一资源占用率大于第一阈值的情况下,预测单元840还用于,预测第二处理器核为第一线程提供第一计算资源后的第二资源占用率;
在第二资源占用率小于或者等于第一阈值的情况下,上述第一操作单元820具体用于,通过第二处理器核为第一线程提供第一计算资源;或者,
在第二资源占用率大于第一阈值的情况下,预测单元840还用于,预测第三处理器核为第一线程提供第一计算资源后的第三资源占用率,第三处理器核未与第一线程绑定;
在第三资源占用率小于或者等于第一阈值的情况下,上述第一操作单元820具体用于,通过第三处理器核为第一线程提供第一计算资源。
在一些可能的实施例中,上述装置800还包括:第二操作单元850,用于在第一线程运行上述第一函数的起始时刻,开启第一定时器,该第一定时器设置的时长大于或者等于运行完第一函数所需的时长;上述第一操作单元820还用于,在第一定时器超时,且第一函数未完成运行的情况下,减少为第一线程分配的第一计算资源。
在一些可能的实施例中,上述第一应用程序还包括第四函数,上述装置800还包括:获取单元860,用于获取预设的第一运行时段,该第一运行时段大于或者等于运行完第四函数所需的时长;上述第一操作单元820还用于,从运行到第四函数的时刻起的第一运行时段内,为用于运行所述第四函数的线程分配第四计算资源,该第四计算资源大于或者等于第一计算资源。
图9是本申请实施例提供的一种处理应用程序的装置900的示意性框图。
该装置900用于处理第一应用程序,该第一应用程序由操作系统运行,且操作系统默认为用于运行第一应用程序中的函数的线程分配第一计算资源,该装置900包括:
插桩单元910,用于在第一应用程序中添加N个桩点,N为正整数,N个桩点分别与第一应用程序中的N个关键函数相关联,关键函数与关键数据流相关联,关键数据流用于决定第一应用程序的输出,关键函数用于决定关键数据流的输出,桩点用于指示为用于运行关键函数的线程分配第二计算资源,第二计算资源多于第一计算资源。
在一些可能的实施例中,上述插桩单元910还用于,在第一前置函数与第一桩点之间添加第一预热桩点,其中,第一前置函数的运行时序在第一函数之前,且与所述第一函数相邻,第一函数为所述N个关键函数中的一个,第一函数与第一桩点相关联,第一桩点为所述N个桩点中的一个,第一预热桩点用于指示为用于运行第一函数的线程分配第三计算资源,该第三计算资源少于或者等于第二计算资源。
在一些可能的实施例中,上述装置900还包括:
运行单元920,用于运行所述第一应用程序,以获取历史数据,所述历史数据用于指示参与运行所述第一应用程序的多个进程和/或多个线程的运行时序;
处理单元930,用于根据所述历史数据,生成第一配置文件,所述第一配置文件用于指示所述多个进程和/或所述多个线程之间运行的依赖关系,所述第一配置文件还用于确定所述第二计算资源。
本申请实施例还提出了一种车辆,该车辆包括上述任一实施例提出的装置800和/或装置900,或者用于执行本申请实施例提出的资源调度方法的自动驾驶系统。
在一些可能的实施例中,本申请提出的技术方案并不局限于通过自动驾驶系统对应的操作系统来执行,该技术方案还可以扩展应用至其他应用系统搭载至的操作系统来执行,例如智能机器人系统、智能家居系统等。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。
Claims (29)
- 一种资源调度的方法,其特征在于,所述方法包括:运行第一应用程序,所述第一应用程序包括第一关键数据流,所述第一关键数据流用于决定所述第一应用程序的输出,所述第一关键数据流与M个进程下的N个线程相关联,所述M个进程包括第一进程,所述第一进程与第一线程、第一函数和第一桩点关联,所述第一线程用于运行所述第一函数,所述M和所述N为正整数;根据所述第一桩点,为所述第一线程分配第一计算资源,所述第一计算资源用于所述第一线程运行所述第一函数。
- 根据权利要求1所述的方法,其特征在于,所述根据所述第一桩点,确定为所述第一线程分配所述第一计算资源包括:根据所述第一桩点,确定所述第一计算资源的容量,并根据所述第一计算资源的容量,为所述第一线程分配所述第一计算资源;或者,根据所述第一桩点,确定所述第一计算资源的顺序,并根据所述第一计算资源的顺序,为所述第一线程分配所述第一计算资源;或者,根据所述第一桩点,确定第一占有率,所述第一占有率用于表示所述第一计算资源在所有计算资源中的占有率,并根据所述第一占有率,为所述第一线程分配所述第一计算资源。
- 根据权利要求1或2所述的方法,其特征在于,所述第一桩点是在运行所述第一应用程序的过程中添加至所述第一应用程序的;或者,所述第一桩点是在运行所述第一应用程序之前添加至所述第一应用程序的。
- 根据权利要求1至3中任一项所述的方法,其特征在于,所述第一应用程序还包括第二关键数据流,所述第二关键数据流用于决定所述第一应用程序的输出,所述第二关键数据流与所述M个进程下的所述N个线程相关联,所述M个进程还包括第二进程,所述第二进程与第二线程、第二函数和第二桩点关联,所述第二线程用于运行所述第二函数,所述方法还包括:根据第一配置文件,确定所述第二线程与所述第一线程之间运行的第一依赖关系,所述第一配置文件用于指示所述M个进程和/或所述N个线程之间运行的依赖关系;根据所述第二桩点和所述第一依赖关系,为所述第二线程分配第二计算资源,所述第二计算资源用于所述第二线程运行所述第二函数,在所述第一依赖关系为所述第一线程的运行依赖于所述第二线程的情况下,所述第一计算资源多于所述第二计算资源,或者,在所述第一依赖关系为所述第二线程的运行依赖于所述第一线程的情况下,所述第一计算资源少于所述第二计算资源。
- 根据权利要求1至4中任一项所述的方法,其特征在于,所述第一进程还与第三桩点相关联,在所述第一进程的运行时序中,所述第三桩点与所述第一桩点相邻,且位于所述第一桩点之前,所述方法还包括:根据所述第三桩点,为所述第一线程分配第三计算资源,所述第三计算资源小于或者等于所述第一计算资源,所述第三计算资源用于保障所述第一线程运行所述第一函数。
- 根据权利要求1至5中任一项所述的方法,其特征在于,所述第一线程分别与第一处理器核和第二处理器核绑定,所述第一处理器核和所述第二处理器核分别被配置用于为所述第一线程提供所述第一计算资源,所述方法还包括:预测所述第一处理器核为所述第一线程提供所述第一计算资源后的第一资源占用率;在所述第一资源占用率大于第一阈值的情况下,预测第二处理器核为所述第一线程提供所述第一计算资源后的第二资源占用率;在所述第二资源占用率小于或者等于第一阈值的情况下,所述为所述第一线程分配第一计算资源包括:通过所述第二处理器核为所述第一线程提供所述第一计算资源;或者,在所述第二资源占用率大于所述第一阈值的情况下,预测第三处理器核为所述第一线程提供所述第一计算资源后的第三资源占用率,所述第三处理器核未与所述第一线程绑定;在所述第三资源占用率小于或者等于第一阈值的情况下,所述为所述第一线程分配第一计算资源包括:通过所述第三处理器核为所述第一线程提供所述第一计算资源。
- 根据权利要求1至6中任一项所述的方法,其特征在于,所述方法还包括:在所述第一线程运行所述第一函数的起始时刻,开启第一定时器,所述第一定时器设置的时长大于或者等于运行完所述第一函数所需的时长;在所述第一定时器超时,且所述第一函数未完成运行的情况下,减少为所述第一线程分配的所述第一计算资源。
- 根据权利要求1至7中任一项所述的方法,其特征在于,所述第一应用程序还包括第四函数,所述方法还包括:获取预设的第一运行时段,所述第一运行时段大于或者等于运行完所述第四函数所需的时长;从运行到所述第四函数的时刻起的所述第一运行时段内,为用于运行所述第四函数的线程分配第四计算资源,所述第四计算资源大于或者等于所述第一计算资源。
- 一种处理应用程序的方法,其特征在于,用于处理第一应用程序,所述第一应用程序由操作系统运行,所述操作系统默认为用于运行所述第一应用程序中的函数的线程分配第一计算资源,所述方法包括:在所述第一应用程序中添加N个桩点,所述N为正整数,所述N个桩点分别与所述第一应用程序中的N个关键函数相关联,所述关键函数与关键数据流相关联,所述关键数据流用于决定所述第一应用程序的输出,所述关键函数用于决定所述关键数据流的输出,所述桩点用于指示为用于运行所述关键函数的线程分配第二计算资源,所述第二计算资源多于所述第一计算资源。
- 根据权利要求9所述的方法,其特征在于,所述方法还包括:在第一前置函数与第一桩点之间添加第一预热桩点,所述第一前置函数的运行时序在第一函数之前,且与所述第一函数相邻,所述第一函数为所述N个关键函数中的一个,所述第一函数与第一桩点相关联,所述第一桩点为所述N个桩点中的一个,所述第一预热桩点用于指示为用于运行所述第一函数的线程分配第三计算资源,所述第三计算资源少于或者等于所述第二计算资源。
- 根据权利要求9或10所述的方法,其特征在于,所述方法还包括:运行所述第一应用程序,以获取历史数据,所述历史数据用于指示参与运行所述第一应用程序的多个进程和/或多个线程的运行时序;根据所述历史数据,生成第一配置文件,所述第一配置文件用于指示所述多个进程和/或所述多个线程之间运行的依赖关系,所述第一配置文件还用于确定所述第二计算资源。
- 一种资源调度的装置,其特征在于,所述装置包括:运行单元,用于运行第一应用程序,所述第一应用程序包括第一关键数据流,所述第一关键数据流用于决定所述第一应用程序的输出,所述第一关键数据流与M个进程下的N个线程相关联,所述M个进程包括第一进程,所述第一进程与第一线程、第一函数和第一桩点关联,所述第一线程用于运行所述第一函数,所述M和所述N为正整数;第一操作单元,用于根据所述第一桩点,为所述第一线程分配第一计算资源,所述第一计算资源用于所述第一线程运行所述第一函数。
- 根据权利要求12所述的装置,其特征在于,所述第一操作单元具体用于:根据所述第一桩点,确定所述第一计算资源的容量,并根据所述第一计算资源的容量,为所述第一线程分配所述第一计算资源;或者,根据所述第一桩点,确定所述第一计算资源的顺序,并根据所述第一计算资源的顺序,为所述第一线程分配所述第一计算资源;或者,根据所述第一桩点,确定第一占有率,所述第一占有率用于表示所述第一计算资源在所有计算资源中的占有率,并根据所述第一占有率,为所述第一线程分配所述第一计算资源。
- 根据权利要求12或13所述的装置,其特征在于,所述第一桩点是在运行所述第一应用程序的过程中添加至所述第一应用程序的;或者,所述第一桩点是在运行所述第一应用程序之前添加至所述第一应用程序的。
- 根据权利要求12至14中任一项所述的装置,其特征在于,所述第一应用程序还包括第二关键数据流,所述第二关键数据流用于决定所述第一应用程序的输出,所述第二关键数据流与所述M个进程下的所述N个线程相关联,所述M个进程还包括第二进程,所述第二进程与第二线程、第二函数和第二桩点关联,所述第二线程用于运行所述第二函数,所述装置还包括:确定单元,用于根据第一配置文件,确定所述第二线程与所述第一线程之间运行的第一依赖关系,所述第一配置文件用于指示所述M个进程和/或所述N个线程之间运行的依赖关系;所述第一操作单元还用于,根据所述第二桩点和所述第一依赖关系,为所述第二线程分配第二计算资源,所述第二计算资源用于所述第二线程运行所述第二函数,在所述第一依赖关系为所述第一线程的运行依赖于所述第二线程的情况下,所述第一计算资源多于所述第二计算资源,或者,在所述第一依赖关系为所述第二线程的运行依赖于所述第一线程的情况下,所述第一计算资源少于所述第二计算资源。
- 根据权利要求12至15中任一项所述的装置,其特征在于,所述第一进程还与第三桩点相关联,在所述第一进程的运行时序中,所述第三桩点与所述第一桩点相邻,且位于所述第一桩点之前,所述第一操作单元还用于:根据所述第三桩点,为所述第一线程分配第三计算资源,所述第三计算资源小于或者等于所述第一计算资源,所述第三计算资源用于保障所述第一线程运行所述第一函数。
- 根据权利要求12至16中任一项所述的装置,其特征在于,所述第一线程分别与第一处理器核和第二处理器核绑定,所述第一处理器核和所述第二处理器核分别被配置用于为所述第一线程提供所述第一计算资源,所述装置还包括:预测单元,用于预测所述第一处理器核为所述第一线程提供所述第一计算资源后的第一资源占用率;在所述第一资源占用率大于第一阈值的情况下,所述预测单元还用于,预测第二处理器核为所述第一线程提供所述第一计算资源后的第二资源占用率;在所述第二资源占用率小于或者等于第一阈值的情况下,所述第一操作单元具体用于,通过所述第二处理器核为所述第一线程提供所述第一计算资源;或者,在所述第二资源占用率大于所述第一阈值的情况下,所述预测单元还用于,预测第三处理器核为所述第一线程提供所述第一计算资源后的第三资源占用率,所述第三处理器核未与所述第一线程绑定;在所述第三资源占用率小于或者等于第一阈值的情况下,所述第一操作单元具体用于,通过所述第三处理器核为所述第一线程提供所述第一计算资源。
- 根据权利要求12至17中任一项所述的装置,其特征在于,所述装置还包括:第二操作单元,用于在所述第一线程运行所述第一函数的起始时刻,开启第一定时器,所述第一定时器设置的时长大于或者等于运行完所述第一函数所需的时长;所述第一操作单元还用于,在所述第一定时器超时,且所述第一函数未完成运行的情况下,减少为所述第一线程分配的所述第一计算资源。
- 根据权利要求12至18中任一项所述的装置,其特征在于,所述第一应用程序还包括第四函数,所述装置还包括:获取单元,用于获取预设的第一运行时段,所述第一运行时段大于或者等于运行完所述第四函数所需的时长;所述第一操作单元还用于,从运行到所述第四函数的时刻起的所述第一运行时段内,为用于运行所述第四函数的线程分配第四计算资源,所述第四计算资源大于或者等于所述第一计算资源。
- 一种处理应用程序的装置,其特征在于,用于处理第一应用程序,所述第一应用程序由操作系统运行,所述操作系统默认为用于运行所述第一应用程序中的函数的线程分配第一计算资源,所述装置包括:插桩单元,用于在所述第一应用程序中添加N个桩点,所述N为正整数,所述N个桩点分别与所述第一应用程序中的N个关键函数相关联,所述关键函数与关键数据流相关联,所述关键数据流用于决定所述第一应用程序的输出,所述关键函数用于决定所述关键数据流的输出,所述桩点用于指示为用于运行所述关键函数的线程分配第二计算资源,所述第二计算资源多于所述第一计算资源。
- 根据权利要求20所述的装置,其特征在于,所述插桩单元还用于:在第一前置函数与第一桩点之间添加第一预热桩点,所述第一前置函数的运行时序在第一函数之前,且与所述第一函数相邻,所述第一函数为所述N个关键函数中的一个,所述第一函数与第一桩点相关联,所述第一桩点为所述N个桩点中的一个,所述第一预热桩点用于指示为用于运行所述第一函数的线程分配第三计算资源,所述第三计算资源少于或者等于所述第二计算资源。
- 根据权利要求20或21所述的装置,其特征在于,所述装置还包括:运行单元,用于运行所述第一应用程序,以获取历史数据,所述历史数据用于指示参与运行所述第一应用程序的多个进程和/或多个线程的运行时序;处理单元,用于根据所述历史数据,生成第一配置文件,所述第一配置文件用于指示所述多个进程和/或所述多个线程之间运行的依赖关系,所述第一配置文件还用于确定所述第二计算资源。
- 一种电子设备,其特征在于,包括处理器和存储器,其中,所述处理器和存储器相连,其中,所述存储器用于存储程序代码,所述处理器用于调用所述程序代码,以执行如权利要求1至8中任一项所述的方法,或者执行如权利要求9至11中任一项所述的方法。
- 一种自动驾驶系统,其特征在于,包括第一操作系统,所述第一操作系统用于执行如权利要求1至8中任一项所述的方法。
- 根据权利要求24所述的自动驾驶系统,其特征在于,在所述第一操作系统用于执行如权利要求1至8中任一项所述的方法之前,所述第一操作系统还用于:运行所述第一应用程序,以获取历史数据,所述历史数据用于指示参与运行所述第一应用程序的所述M个进程和/或所述N个线程的运行时序;根据所述历史数据,生成第一配置文件,所述第一配置文件用于指示所述M个进程和/或所述N个线程之间运行的依赖关系。
- 一种车辆,其特征在于,包括如权利要求24或25所述的自动驾驶系统。
- 一种芯片系统,其特征在于,所述芯片系统应用于电子设备;所述芯片系统包括一个或多个接口电路,以及一个或多个处理器;所述接口电路和所述处理器通过线路互联;所述接口电路用于从所述电子设备的存储器接收信号,并向所述处理器发送所述信号,所述信号包括所述存储器中存储的计算机指令;当所述处理器执行所述计算机指令时,所述电子设备执行如权利要求1至8中任一项所述的方法,或者如权利要求9至11中任一项所述的方法。
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行以实现如权利要求1至8中任一项所述的方法,或者实现如权利要求9至11任一项所述的方法。
- 一种计算机程序产品,其特征在于,包含指令,当所述指令被处理器运行时,使得所述权利要求1至8中任一项所述的方法被执行,或者使得所述权利要求9至11中任一项所述的方法被执行。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410765274.3 | 2024-06-13 | ||
| CN202410765274.3A CN121116512A (zh) | 2024-06-13 | 2024-06-13 | 资源调度的方法、装置和系统 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2025256541A1 true WO2025256541A1 (zh) | 2025-12-18 |
Family
ID=97951766
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2025/100335 Pending WO2025256541A1 (zh) | 2024-06-13 | 2025-06-11 | 资源调度的方法、装置和系统 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN121116512A (zh) |
| WO (1) | WO2025256541A1 (zh) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN121572341B (zh) * | 2026-01-29 | 2026-04-03 | 瀚博半导体(上海)股份有限公司 | 控制机器人系统的方法、装置、设备、存储介质和程序产品 |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110055838A1 (en) * | 2009-08-28 | 2011-03-03 | Moyes William A | Optimized thread scheduling via hardware performance monitoring |
| WO2022151970A1 (zh) * | 2021-01-14 | 2022-07-21 | 华为技术有限公司 | 一种数据传输方法、系统以及计算节点 |
| CN116483734A (zh) * | 2023-06-16 | 2023-07-25 | 荣耀终端有限公司 | 一种基于编译器的插桩方法、系统及相关电子设备 |
| CN117519918A (zh) * | 2022-07-30 | 2024-02-06 | 华为技术有限公司 | 任务管理方法及相关设备 |
| CN117891617A (zh) * | 2024-03-15 | 2024-04-16 | 荣耀终端有限公司 | 资源调度方法、设备、可读存储介质及芯片系统 |
| WO2024087840A1 (zh) * | 2022-10-26 | 2024-05-02 | 荣耀终端有限公司 | 资源管控方法、装置、芯片、电子设备及介质 |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117149394A (zh) * | 2023-09-28 | 2023-12-01 | 联想(北京)有限公司 | 一种进程调度方法及装置 |
-
2024
- 2024-06-13 CN CN202410765274.3A patent/CN121116512A/zh active Pending
-
2025
- 2025-06-11 WO PCT/CN2025/100335 patent/WO2025256541A1/zh active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110055838A1 (en) * | 2009-08-28 | 2011-03-03 | Moyes William A | Optimized thread scheduling via hardware performance monitoring |
| WO2022151970A1 (zh) * | 2021-01-14 | 2022-07-21 | 华为技术有限公司 | 一种数据传输方法、系统以及计算节点 |
| CN117519918A (zh) * | 2022-07-30 | 2024-02-06 | 华为技术有限公司 | 任务管理方法及相关设备 |
| WO2024087840A1 (zh) * | 2022-10-26 | 2024-05-02 | 荣耀终端有限公司 | 资源管控方法、装置、芯片、电子设备及介质 |
| CN116483734A (zh) * | 2023-06-16 | 2023-07-25 | 荣耀终端有限公司 | 一种基于编译器的插桩方法、系统及相关电子设备 |
| CN117891617A (zh) * | 2024-03-15 | 2024-04-16 | 荣耀终端有限公司 | 资源调度方法、设备、可读存储介质及芯片系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN121116512A (zh) | 2025-12-12 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US20060101465A1 (en) | Distributed control system | |
| JP2023519405A (ja) | ハードウェアアクセラレータをスケジューリングするための方法およびタスクスケジューラ | |
| JP2008506187A (ja) | 複数のカーネルの並列実行のための方法およびシステム | |
| JP7658861B2 (ja) | 電子システム及び電子制御装置 | |
| WO2025256541A1 (zh) | 资源调度的方法、装置和系统 | |
| CN112673349A (zh) | 基于QoS即服务的数据确定性可传递通信技术 | |
| CN113010301A (zh) | 用户定义的测定的优先级队列 | |
| CN114721834B (zh) | 资源分配处理方法、装置、设备、车辆和介质 | |
| WO2025065425A1 (zh) | 一种任务调度方法及装置 | |
| US20240054002A1 (en) | Vehicle-mounted computer, computer execution method, and computer program | |
| EP4647909A1 (en) | State management method and apparatus, and intelligent driving device | |
| US11972184B2 (en) | Method and system for designing a robotic system architecture with optimized system latency | |
| CN115048206A (zh) | 资源调度方法及服务器 | |
| JP2026036650A (ja) | リソーススケジューリング方法及び装置、並びにチップシステム、電子機器及び乗り物 | |
| Han et al. | Holistic Heterogeneous Scheduling for Autonomous Applications using Fine-grained, Multi-XPU Abstraction | |
| Easwaran et al. | Real-Time Scheduling for Computing Architectures | |
| JP2022507939A (ja) | 調整されたコンポーネントインターフェース制御フレームワーク | |
| US20240303103A1 (en) | Vehicle-mounted computer, computer execution method, and computer program | |
| CN117271110A (zh) | 用于执行机动车用户功能的计算机系统和方法 | |
| CN118679469A (zh) | 资源仲裁的方法和仲裁节点 | |
| EP4357920A1 (en) | Task scheduling method and apparatus | |
| CN115810276A (zh) | 一种实现交通信号控制的系统及子系统 | |
| JP7747202B2 (ja) | リソース割当方法および装置、ならびにコンピュータプログラム | |
| CN121387813B (zh) | 一种异构计算低延迟通信方法及系统 | |
| WO2022141297A1 (zh) | 事件处理方法和装置 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 25821251 Country of ref document: EP Kind code of ref document: A1 |