A sched_ext scheduling mechanism method based on a sunway platform

By adapting the kernel and implementing the interface of the sched_ext scheduling framework on the Shenwei platform, the cross-architecture applicability of sched_ext on the Shenwei platform was solved, enabling the loading and replacement of dynamic scheduling strategies, thereby improving the system's resource utilization and task execution efficiency.

CN121957679BActive Publication Date: 2026-07-07CLP KESHENTAI INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CLP KESHENTAI INFORMATION TECH CO LTD
Filing Date
2026-04-01
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

The existing sched_ext scheduling framework is not yet mature in its implementation on the Shenwei platform. It lacks cross-architecture universality and robustness, and cannot meet the scheduling needs of cloud computing service providers with diverse hardware stacks and accelerators in specific fields.

Method used

By analyzing the architecture and operating principles of the sched_ext programmable scheduling framework and combining it with the scheduling mechanism characteristics of the Shenwei platform, kernel adaptation and interface implementation are carried out, including scheduling class integration, eBPF Trampoline mechanism design, and kfunc call support, so as to realize the loading and replacement of dynamic scheduling strategies and ensure seamless deployment and functional support on the Shenwei platform.

Benefits of technology

It provides the ability to dynamically and programmably extend scheduling policies on the Shenwei platform, improving resource utilization and task execution efficiency. It also supports updating scheduling logic without restarting the system or recompiling the kernel, ensuring security and low performance overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121957679B_ABST
    Figure CN121957679B_ABST
Patent Text Reader

Abstract

The application discloses a sched_ext scheduling mechanism method based on a Shenwei platform, which comprises the following steps: analyzing the architecture and operation principle of a sched_ext programmable scheduling framework to clarify the core mechanism of dynamic loading and replacement of scheduling strategies; analyzing the technical features of the existing scheduling mechanism of the Shenwei platform, combining the advantages of the sched_ext in strategy flexibility and expansibility, and determining the feasibility of the fusion of the two; carrying out kernel adaptation and interface implementation of the sched_ext on the Shenwei platform, completing the deployment and function support of the programmable scheduling framework on the target architecture; and evaluating the performance of the scheduling mechanism under typical load and extreme scenarios through systematic testing and multi-level function verification. The application provides programmable capability of a user-mode scheduler which can be customized, and improves the resource utilization rate and task execution efficiency of the Shenwei platform in complex computing scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of kernel scheduling mechanism technology, and in particular to a sched_ext scheduling mechanism method based on the Shenwei platform. Background Technology

[0002] The scheduler is the core of the operating system's allocation and management of computing resources, and its design directly determines the system's overall throughput, response latency, and energy efficiency. With the increasing diversification and scenario-based nature of computing workloads, from virtual machines and container instances in cloud computing centers to real-time data processing services on edge computing nodes, and then to large-scale scientific computing applications in the field of high-performance computing and large-scale model applications in the field of artificial intelligence, different workloads have put forward significantly different and even contradictory requirements for processor scheduling strategies.

[0003] sched_ext offers several advantages. First, in terms of security, it exposes only the policy to the user, fundamentally ensuring system stability. Furthermore, EBPF's security check mechanism allows users to write schedulers for production environments. Second, regarding programmability and agility, developers can use familiar high-level programming languages ​​like C or Rust, combined with a mature user-space development and debugging toolchain, to quickly prototype, test, and iterate various scheduling algorithms. Policy updates do not require kernel recompilation or system restarts, enabling runtime hot updates of scheduling policies, significantly accelerating the R&D and deployment cycle of scheduling optimizations. Finally, in terms of architectural neutrality and ecosystem potential, its design concept integrates the advantages of EBPF, which is independent of specific CPU instruction set architectures, enabling "write once, deploy everywhere," facilitating the migration of scheduling algorithms to specific processors. This has extremely high practical value for cloud service providers with diverse hardware stacks, scenarios requiring customized scheduling logic for accelerators in specific domains, and the embedded and IoT fields.

[0004] Despite the promising future of the sched_ext framework, its existing complete implementations, optimized use cases, and developer ecosystem are almost entirely built and evolved around the x86 architecture. For the Shenwei platform, sched_ext development is still in its early stages. Designing, enabling, and deeply applying the sched_ext framework on the Shenwei platform not only verifies the framework's cross-architecture universality and robustness but also provides crucial scheduler programmability capabilities for the Shenwei architecture's Linux operating system. Summary of the Invention

[0005] The purpose of this invention is to provide a sched_ext scheduling mechanism method based on the Shenwei platform to solve the problems in the background art.

[0006] To address the aforementioned technical problems, this invention provides a sched_ext scheduling mechanism method based on the Shenwei platform, comprising the following steps:

[0007] This paper analyzes the architecture and operating principle of the sched_ext programmable scheduling framework to clarify the core mechanism of its dynamic loading and replacement of scheduling strategies.

[0008] This study analyzes the technical characteristics of the existing scheduling mechanism of the Shenwei platform and combines the advantages of the sched_ext programmable scheduling framework in terms of policy flexibility and scalability to determine the feasibility of integrating the two.

[0009] Based on the above analysis, we carried out kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform to complete the deployment and functional support of the programmable scheduling framework on the target architecture.

[0010] Through systematic testing and multi-level functional verification, the performance of the scheduling mechanism under typical loads and extreme scenarios was evaluated to ensure its stability, performance improvement effect, and platform applicability; among other things...

[0011] The kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform includes: code porting and adaptation of the scheduling mechanism of the sched_ext programmable scheduling framework, specifically including: scheduling class integration and framework code round-robin, design of the eBPF Trampoline mechanism under the Shenwei architecture, and kfunc call support;

[0012] The aforementioned scheduling class integration and framework code round includes: fully integrating the sched_ext scheduling class in the high-version kernel into the target kernel's scheduling system;

[0013] The design of the eBPF Trampoline mechanism under the Shenwei architecture includes: two-stage assembly strategy, call generator implementation, stack frame design and context management, Shenwei architecture chain execution design, reuse and storage of other registers, instruction hot replacement and bpf_arch_text_poke support;

[0014] The kfunc call support includes: kernel build registration and JIT compilation support.

[0015] In one implementation, the architecture of the sched_ext programmable scheduling framework includes: the sched_ext framework is implemented as a kernel module and runs as an independent scheduling class in the Linux kernel. Its scheduling policy is dynamically loaded, replaced, and unloaded through an eBPF scheduling policy program written in user space.

[0016] The sched_ext programmable scheduling framework operates based on an event-driven callback mechanism, allowing user-mode eBPF scheduling policy programs to respond to task wake-up, scheduling preemption, and load balancing kernel scheduling events, and make corresponding scheduling decisions.

[0017] The core mechanism of the sched_ext programmable scheduling framework includes the following metrics:

[0018] Programmability of scheduling policies: Supports dynamic updates to scheduling logic without restarting the system or recompiling the kernel;

[0019] Security and Isolation: Relying on the eBPF verifier ensures the safe execution of the loader and prevents kernel state corruption;

[0020] Low performance overhead: Minimizes the additional overhead introduced by scheduling policy extensions through Just-in-Time compilation and efficient kernel-user space interaction mechanisms;

[0021] The scheduling mechanism of the Shenwei platform is the native scheduling framework of the Linux 6.6 kernel, which is built based on the deadline scheduling class.

[0022] The sched_ext programmable scheduling framework provides the kernel with the ability to extend dynamic and programmable scheduling policies without recompiling or restarting.

[0023] The feasibility of merging the two stems from the design of sched_ext programmable scheduling as a kernel module, which mainly includes scheduling class implementation, key data structures and interface definitions, as well as supporting header files and auxiliary code. By merging the framework code into the target kernel environment, and by systematically comparing, analyzing and adapting the version differences of kernel internal interfaces and data structures, it is ensured that the ported sched_ext scheduling class can seamlessly access and respond to kernel scheduling event streams.

[0024] In one implementation, the kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform further includes:

[0025] The scheduling mechanism of the sched_ext programmable scheduling framework is functionally verified and registered. After code adaptation is completed, the sched_ext programmable scheduling framework is successfully registered with the kernel as an independent scheduling class, so that it can be normally managed and called by the scheduler core.

[0026] The performance and security of the sched_ext programmable scheduling framework scheduling mechanism are verified. The integrated framework is tested to verify whether it can correctly execute the user-space injected eBPF scheduling policy while maintaining the original scheduling fairness and stability, without introducing security vulnerabilities or significant performance loss.

[0027] In the integration of the scheduling class with the framework code, sched_ext was first introduced as a stable feature in Linux version 6.12. The highest stable kernel version supported by the Shenwei platform is 6.6. Therefore, the core module code of the sched_ext scheduling class is extracted from the higher version kernel.

[0028] The framework code round includes the implementation body of the scheduling class, key data structures and interface definitions, as well as corresponding header files and auxiliary code. When merging the code round into the 6.6 kernel environment, the differences in internal interfaces and data structures between different kernel versions are addressed by comparing and analyzing the code, testing and verifying it, and making adaptation modifications to ensure that the ported sched_ext_class can correctly respond to and access the scheduling event stream of the 6.6 kernel.

[0029] In the design of the eBPF Trampoline mechanism under the Shenwei architecture, the two-stage assembly strategy includes a space calculation and feasibility verification stage and an actual instruction generation stage. In the space calculation and feasibility verification stage, the total number of instructions and memory space required are calculated by simulating the instruction generation process, and the sufficiency of the target buffer space is verified.

[0030] In the actual instruction generation stage, based on the calculation results of the first stage, the 32-bit binary code of each SW64 architecture instruction is deterministically written into the executable buffer; the two stages follow the same generation logic to ensure that the size of the final generated machine code is strictly consistent with the pre-calculated result, avoid buffer overflow and prevent code injection.

[0031] In one implementation, the call generator includes: short jump optimization and long call backup path;

[0032] The short jump optimization is as follows: calculate the signed offset between the target address and the current generation position; if the offset is within the encoding range of the SW64 architecture short jump instruction, generate a short jump instruction; wherein, the generated short jump instruction needs to be encoded and shifted, and the value of the shift is = offset / 4 - 1;

[0033] The long call backup path is as follows: if the target address exceeds the short jump range, a standard call instruction sequence is generated. This sequence first loads the target address into a temporary register through an auxiliary function, and then indirectly jumps to the target address through the register. This mechanism ensures that the target function at any location in the kernel space can be called correctly.

[0034] In one implementation, the stack frame design and context management mechanism is used to support the correct execution of trampoline code in two different context scenarios: calls from the entry point of the traced function and direct calls.

[0035] The stack frame design and context management mechanism defines a unified stack memory layout. It uses a set of offsets precisely calculated at compile time or runtime to locate various data areas within the stack frame, including the total stack space size, BPF trampoline context offset, parameter storage area offset, call point address storage offset, and callee storage register offset. Based on this layout, dedicated subroutines save call parameters from specified general-purpose registers to the stack parameter area, or restore them from the stack to the corresponding registers, enabling parameter and return value transfer between the kernel and the eBPF scheduling policy program. This design allows the same trampoline code to transparently handle both call scenarios and accurately restore the call context after execution, ensuring correct control flow return.

[0036] In one implementation, the Shenwei architecture's chained execution design, designed for scenarios supporting multiple BPF_TRAMP_MODIFY_RETURN type programs attached to a single hook point, implements dynamic execution flow control based on return values ​​through dedicated sub-functions. This includes: generating initialization code to zero out the storage units used for passing return values ​​in the chained execution; for each fmod_ret program in the chain, sequentially generating a complete code sequence that calls the program, reserving an instruction position afterward as a conditional branch placeholder, and recording this placeholder position; after completing the generation of all program call code, filling the aforementioned placeholder position with conditional branch instructions based on the recorded position information; wherein...

[0037] The conditional branch instruction is based on the return value of the current fmod_ret program. If it is non-zero, it jumps to the target address that skips all subsequent fmod_ret programs, thus achieving short-circuit control of chained execution based on the return value of the preceding program.

[0038] In one implementation, the reuse and storage of the other registers are achieved in the following way: to support the use of specific callee-saved registers by the trampoline code during execution, a dedicated area is allocated on the stack for temporarily storing and restoring the values ​​of these registers, ensuring that the operation of the trampoline does not affect the normal register context of the subsequent eBPF scheduling policy program; this mechanism achieves secure maintenance and transmission of the internal state of the trampoline without monopolizing hardware registers or interfering with the register usage conventions of the eBPF scheduling policy program, thereby improving the efficiency and flexibility of code execution.

[0039] In one implementation, the instruction hot-swapping and bpf_arch_text_poke support enable secure dynamic modification of the executing trampoline code through the following process:

[0040] Based on the replacement type and the provided old and new target addresses, generate the corresponding old instruction sequence and new instruction sequence;

[0041] Perform a security check on the current instruction content at the target memory address to confirm that it completely matches the generated old instruction sequence;

[0042] After verification, the new instruction sequence is written to the target memory address in an atomic operation, and the instruction cache is refreshed synchronously to ensure the thread safety and instruction consistency of the code patch.

[0043] In one implementation, the kfunc call is supported by registering the underlying functions required by the sched_ext module into the kernel's BPF type format information and kfunc metadata during kernel build, so that the eBPF verifier and loader can recognize and allow the eBPF scheduler to reference these functions; during the just-in-time compilation phase of the eBPF scheduler, when a call to a registered kfunc is detected, the platform's JIT compiler translates the call into a direct call to the actual kernel function address.

[0044] In one implementation, the systematic testing and multi-level functional verification include: basic functional testing, comprehensive test case testing, and in-depth functional verification; wherein,

[0045] The basic functional tests use the test_progs test program that comes with the kernel source code tree to run hundreds of test cases related to fentry, fexit, and dummy. These tests are used to evaluate the correctness of the operation and interface stability of the core scheduling mechanism of the sched_ext programmable scheduling framework. All relevant test cases are required to pass.

[0046] The comprehensive test cases include: writing and loading a custom eBPF scheduling policy program to verify the integrity and reliability of the dynamic loading, replacement and unloading process of the sched_ext programmable scheduling framework on the Shenwei platform; designing typical and boundary scenarios such as multi-task contention, CPU hot-plugging, and real-time task scheduling to verify that the behavior of the integrated scheduling system under various loads meets expectations and that it works normally in coordination with other kernel subsystems of the platform.

[0047] The deep functional verification includes:

[0048] Performance benchmark tests were conducted using the perf and cyclictest tools to compare and analyze key indicators of system scheduling latency, throughput, and context switching overhead before and after enabling the sched_ext customized strategy under typical loads, quantifying the performance improvement effect.

[0049] Stability and stress testing involves running the system under prolonged high load and extreme stress scenarios to monitor for scheduler-related crashes, deadlocks, or performance degradation, and to verify the production environment availability of the mechanism.

[0050] Security and isolation verification ensures that all user-space injected eBPF scheduling policy programs are checked by the kernel verifier and that their execution does not compromise kernel data integrity or lead to privilege escalation.

[0051] This invention provides a sched_ext scheduling mechanism method based on the Shenwei platform. It analyzes the architecture and operating principles of the sched_ext programmable scheduling framework to clarify its core mechanism for dynamically loading and replacing scheduling strategies. It analyzes the technical characteristics of existing scheduling mechanisms on the Shenwei platform and, combined with the advantages of the sched_ext programmable scheduling framework in terms of strategy flexibility and scalability, determines the feasibility of their integration. Based on the above analysis, it conducts kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform to complete the deployment and functional support of the programmable scheduling framework on the target architecture. Through systematic testing and multi-level functional verification, the performance of the scheduling mechanism under typical loads and extreme scenarios is evaluated to ensure its stability, performance improvement effect, and platform applicability. This invention, based on the sched_ext scheduling mechanism of the Shenwei platform, can provide customizable user-space scheduler programmability, improving the resource utilization and task execution efficiency of the Shenwei platform in complex computing scenarios. Attached Figure Description

[0052] Figure 1 This is a flowchart of a sched_ext scheduling mechanism method based on the Shenwei platform provided by the present invention.

[0053] Figure 2This is a flowchart illustrating the porting process of the sched_ext scheduling mechanism method based on the Shenwei platform provided by this invention.

[0054] Figure 3 This is a system architecture diagram of a sched_ext scheduling mechanism method based on the Shenwei platform provided by the present invention.

[0055] Figure 4 This is a stack frame memory layout diagram of a sched_ext scheduling mechanism method based on the Shenwei platform provided by the present invention. Detailed Implementation

[0056] The following detailed description, in conjunction with the accompanying drawings and specific embodiments, provides a further detailed explanation of the sched_ext scheduling mechanism method based on the Shenwei platform proposed in this invention. The advantages and features of this invention will become clearer from the following description. It should be noted that the accompanying drawings are all in a very simplified form and use non-precise proportions, and are only used to facilitate and clarify the illustration of the embodiments of this invention.

[0057] like Figure 1 As shown, this invention provides a sched_ext scheduling mechanism method based on the Shenwei platform, the process of which is as follows: Figure 1 As shown, it includes the following steps:

[0058] Step S10: Analyze the architecture and operating principle of the sched_ext programmable scheduling framework to clarify the core mechanism of its dynamic loading and replacement of scheduling strategies.

[0059] Specifically, the architecture of the sched_ext programmable scheduling framework includes: the sched_ext framework is implemented as a kernel module and runs as an independent scheduling class in the Linux kernel. Its scheduling policy can be dynamically loaded, replaced, and unloaded through user-space eBPF scheduling policy programs.

[0060] The sched_ext programmable scheduling framework operates based on an event-driven callback mechanism, allowing user-space eBPF scheduling policy programs to respond to kernel scheduling events such as task wake-up, scheduling preemption, and load balancing, and make corresponding scheduling decisions.

[0061] The core mechanism of the sched_ext programmable scheduling framework includes the following metrics:

[0062] Programmability of scheduling policies: Supports dynamic updates to scheduling logic without restarting the system or recompiling the kernel;

[0063] Security and Isolation: Relying on the eBPF verifier ensures the safe execution of the loader and prevents kernel state corruption;

[0064] Low performance overhead: Minimizes the additional overhead introduced by scheduling policy extensions through Just-in-Time compilation and efficient kernel-user space interaction mechanisms.

[0065] Step S20: Analyze the technical characteristics of the existing scheduling mechanism of the Shenwei platform, and combine the advantages of the sched_ext programmable scheduling framework in terms of policy flexibility and scalability to determine the feasibility of integrating the two.

[0066] Specifically, the scheduling mechanism of the Shenwei platform is the native scheduling framework of the Linux 6.6 kernel, which is built on the deadline-based scheduling (EEVDF) class.

[0067] The advantage of the sched_ext programmable scheduling framework lies in its ability to provide the kernel with dynamic, programmable scheduling policy extension capabilities without recompiling or restarting, thereby overcoming the limitations of traditional kernel schedulers with fixed policies and long optimization iteration cycles.

[0068] The feasibility of merging the two stems from the design of the sched_ext programmable scheduling framework as a kernel module, which mainly includes the implementation of the scheduling class, the definition of key data structures and interfaces, and the accompanying header files and auxiliary code. By merging the framework code into the target kernel environment and conducting systematic comparison, analysis, and adaptation modifications to address version differences in kernel internal interfaces and data structures, it was ensured that the ported sched_ext programmable scheduling framework scheduling class could seamlessly access and respond to the kernel scheduling event stream.

[0069] Step S30: Based on the above analysis, carry out kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform to complete the deployment and functional support of the sched_ext programmable scheduling framework on the target architecture.

[0070] Specifically, the kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform will be carried out, including:

[0071] The scheduling mechanism of the sched_ext programmable scheduling framework was ported and adapted.

[0072] The scheduling mechanism of the sched_ext programmable scheduling framework was functionally verified and registered. After code adaptation was completed, the sched_ext programmable scheduling framework was successfully registered with the kernel as an independent scheduling class, enabling it to be normally managed and called by the scheduler core.

[0073] The performance and security of the sched_ext programmable scheduling framework scheduling mechanism are verified through testing. The integrated framework is verified to correctly execute the user-space injected eBPF scheduling policy program while maintaining the original scheduling fairness and stability, without introducing security vulnerabilities or significant performance loss.

[0074] Step S40: Through systematic testing and multi-level functional verification, evaluate the performance of the sched_ext programmable scheduling framework scheduling mechanism under typical loads and extreme scenarios to ensure its stability, performance improvement effect and platform applicability.

[0075] Specifically, systematic testing and multi-level functional verification include: basic functional testing, comprehensive test case testing, and in-depth functional verification;

[0076] Among them, the basic functional test uses the test_progs test program that comes with the kernel source code tree to run hundreds of test cases related to fentry, fexit, dummy, etc., to evaluate the correctness of the operation of the core scheduling mechanism of the sched_ext programmable scheduling framework and the stability of the interface. All relevant test cases are required to pass.

[0077] Comprehensive test cases include: writing and loading custom eBPF scheduling policy programs to verify the integrity and reliability of the dynamic loading, replacement and unloading process of the sched_ext programmable scheduling framework on the Shenwei platform; designing typical and boundary scenarios such as multi-task contention, CPU hot-plugging, and real-time task scheduling to verify that the behavior of the integrated scheduling system under various loads meets expectations and that it works normally in coordination with other kernel subsystems of the platform.

[0078] In-depth functional verification includes: Performance benchmarking: Using tools such as perf and cyclictest, comparing and analyzing key indicators such as system scheduling latency, throughput, and context switching overhead before and after enabling the customized strategy of the sched_ext programmable scheduling framework under typical loads to quantify the performance improvement effect; Stability and stress testing: Running under long-term high load and extreme stress scenarios to monitor whether the system has scheduler-related crashes, deadlocks, or performance degradation, verifying the production environment availability of this mechanism; Security and isolation verification: Ensuring that all user-space injected eBPF scheduling policy programs are checked by the kernel verifier and that their execution does not damage kernel data integrity or lead to privilege escalation.

[0079] like Figure 2As shown, this invention provides a porting process for the sched_ext scheduling mechanism method based on the Shenwei platform. Through a systematic kernel code porting and adaptation method, the deployment and functional support of the sched_ext programmable scheduling framework on the Shenwei architecture are completed, including scheduling class integration and framework code rounds, design of the eBPF Trampoline mechanism under the Shenwei architecture, and kfunc call support.

[0080] Specifically, the integration of the scheduling class and framework code includes: fully integrating the sched_ext programmable scheduling framework scheduling class from the high-version kernel into the target kernel's scheduling system; since the sched_ext programmable scheduling framework was first introduced as a stable feature in Linux version 6.12, and the highest stable kernel version supported by the Shenwei platform is 6.6, it is necessary to extract the core module code of the sched_ext programmable scheduling framework scheduling class from the high-version kernel; the framework code includes the implementation body of the scheduling class, key data structures and interface definitions, as well as corresponding header files and auxiliary code; when integrating the framework code into the 6.6 kernel environment, for the differences in internal interfaces and data structures between different kernel versions, the code is compared and analyzed, tested and verified, and modified for compatibility, so that the ported sched_ext_class can correctly respond to and access the scheduling event stream of the 6.6 kernel.

[0081] The design of the eBPF Trampoline mechanism under the Shenwei architecture includes: a two-stage assembly strategy, call generator implementation, stack frame design and context management, Shenwei architecture chained execution design, reuse and storage of other registers, instruction hot replacement, and bpf_arch_text_poke support. The two-stage assembly strategy includes a space calculation and feasibility verification stage and an actual instruction generation stage. In the space calculation and feasibility verification stage, the total number of instructions and memory space required are calculated by simulating the instruction generation process, and the sufficiency of the target buffer space is verified. In the actual instruction generation stage, based on the calculation results of the first stage, the 32-bit binary code of each SW64 architecture instruction is deterministically written into the executable buffer. The two stages follow the same generation logic to ensure that the size of the final generated machine code is strictly consistent with the pre-calculated result, thereby avoiding buffer overflow and preventing code injection.

[0082] The design of the eBPF Trampoline mechanism under the Shenwei architecture includes a call generator implementation comprising: short jump optimization and long call fallback path. Short jump optimization involves calculating the signed offset between the target address and the current generation position. If this offset falls within the encoding range of short jump instructions in the SW64 architecture, a short jump instruction is generated. The generated short jump instruction requires encoding offset, with the offset value equal to offset / 4 - 1. The long call fallback path involves generating a standard call instruction sequence if the target address exceeds the short jump range. This sequence first loads the target address into a temporary register via an auxiliary function, and then indirectly jumps to the target address through the register. This mechanism ensures that target functions at any location in kernel space can be correctly called.

[0083] The design of the eBPF Trampoline mechanism under the Shenwei architecture, including stack frame design and context management, supports the correct execution of trampoline code in two different context scenarios: calls from the entry point of the traced function and direct calls. The stack frame design and context management mechanism define a unified stack memory layout, using a set of offsets precisely calculated at compile time or runtime to locate various data areas within the stack frame, including the total stack space size, BPF trampoline context offset, parameter storage area offset, call point address storage offset, and callee storage register offset. Based on this layout, dedicated subroutines save call parameters from specified general-purpose registers to the parameter area on the stack, or restore them from the stack to the corresponding registers, thereby enabling parameter and return value transfer between the kernel and the eBPF scheduling policy program. This design allows the same trampoline code to transparently handle the two calling scenarios and accurately restore the call context after execution, ensuring correct return of control flow.

[0084] The design of the eBPF Trampoline mechanism under the Shenwei architecture, specifically the chained execution design of the Shenwei architecture, is designed for scenarios that support attaching multiple BPF_TRAMP_MODIFY_RETURN type programs to a single hook point. It implements dynamic execution flow control based on return values ​​through dedicated sub-functions, including: generating initialization code and zeroing the storage unit used to pass return values ​​during chained execution; generating a complete code sequence that calls each fmod_ret program in the chain, reserving an instruction position after it as a conditional branch placeholder, and recording this placeholder position; after generating the calling code for all programs, filling the aforementioned placeholder position with conditional branch instructions based on the recorded position information; the conditional branch instructions are judged based on the return value of the current fmod_ret program, and if it is non-zero, jump to the target address that skips all subsequent fmod_ret programs, thereby achieving short-circuit control of chained execution based on the return value of the preceding program.

[0085] The design of the eBPF Trampoline mechanism under the Shenwei architecture achieves the reuse and storage of other registers in the following way: To support the trampoline code's use of specific callee-saved registers during execution, a dedicated area is allocated on the stack for temporarily saving and restoring the values ​​of these registers, thereby ensuring that the trampoline's operation does not affect the normal register context of the subsequent eBPF scheduling policy program. This mechanism achieves the safe maintenance and transfer of the trampoline's internal state without monopolizing hardware registers or interfering with the eBPF scheduling policy program's register usage conventions, thus improving the efficiency and flexibility of code execution.

[0086] The design of the eBPF Trampoline mechanism under the Shenwei architecture, which supports instruction hot replacement and bpf_arch_text_poke, achieves safe dynamic modification of the currently executing trampoline code through the following process: Based on the replacement type and the provided old and new target addresses, the corresponding old instruction sequence and new instruction sequence are generated; the current instruction content at the target memory address is verified for safety to confirm that it completely matches the generated old instruction sequence; after the verification is passed, the new instruction sequence is written to the target memory address in an atomic operation, and the instruction cache is refreshed simultaneously to ensure the thread safety and instruction consistency of the code patching.

[0087] kfunc calls are supported in the following way: During kernel build, the underlying functions required by the sched_ext module are registered in the kernel's BPF type format information and kfunc metadata, so that the eBPF verifier and loader can recognize and allow the eBPF scheduler to reference these functions; during the just-in-time compilation phase of the eBPF scheduler, when a call to a registered kfunc is detected, the platform's JIT compiler translates the call into a direct call to the actual kernel function address.

[0088] like Figure 3 As shown, the overall system architecture of the sched_ext scheduling mechanism method based on the Shenwei platform provided by this invention specifically includes:

[0089] The system adopts a layered architecture, which includes the Shenwei hardware platform layer, Linux kernel layer, eBPF interaction layer and user space layer from bottom to top, and realizes programmable scheduling through vertical data flow.

[0090] The Shenwei platform hardware layer serves as the underlying support for the system, providing CPU, memory, and I / O hardware resources based on the SW64 architecture.

[0091] The Linux kernel layer runs on top of the hardware, and its core is the scheduler core. The scheduler core manages multiple scheduling classes in parallel, including the fair scheduling class, the real-time scheduling class, and the newly added sched_ext programmable scheduling class. The sched_ext programmable scheduling class contains a programmable scheduling policy engine, which is responsible for executing the dynamic scheduling logic injected by user space.

[0092] The eBPF interaction layer serves as a bridge connecting user space and the kernel's sched_ext programmable scheduling class. Specifically, it is the eBPF Trampoline module implemented on the SW64 architecture. This module is responsible for trampoline code generation, register context management, and unified stack frame layout, ensuring secure and efficient interaction between the user-space eBPF scheduling policy program and the kernel.

[0093] The user space layer includes the eBPF scheduling policy program and control management tools; through the control management tools, users dynamically load the compiled eBPF scheduling policy program into the kernel's sched_ext programmable scheduling class via the eBPF Trampoline.

[0094] The data flow between each level includes: a policy loading flow initiated by the control and management tools and loaded into the kernel via the eBPF Trampoline; an event callback flow triggered by kernel scheduling events and called back to the user-space eBPF scheduling policy via the eBPF Trampoline; and a scheduling decision flow generated by the eBPF scheduling policy and returned to the scheduler kernel via the eBPFTrampoline.

[0095] like Figure 4 As shown, the stack frame memory layout of the sched_ext scheduling mechanism method based on the Shenwei platform provided by this invention specifically includes:

[0096] This layout is a stack memory structure designed for eBPF Trampoline to support two different context scenarios: calls from the entry point of the traced function and direct calls.

[0097] Stack frames are addressed based on the current frame pointer (FP) using a series of offsets that are precisely calculated at compile time or runtime. The regions above the frame pointer, FP + 0 and FP + 8, are used to store the parent function's frame pointer and return address in scenarios where the call originates from the entry point of the traced function.

[0098] The core of the stack frame is located in the FP-8 and FP-16 regions below the frame pointer. This region is designed as a reuse area. In the scenario of calling from the entry point of the traced function, it is used to store the return address and frame pointer of the traced function; in the scenario of direct calling, it is used to store the return address and frame pointer of the direct caller.

[0099] The stack frame further contains multiple functional data areas, all located and managed using predefined offsets, including:

[0100] The return value storage area, located in FP – retval_off, is used to temporarily store the return values ​​of calls of type BPF_TRAMP_F_CALL_ORIG or BPF_TRAMP_F_RET_FENTRY_RET.

[0101] The function parameter area, starting from FP – args_off, is used to store the parameters passed to the traced function or BPF program;

[0102] The execution context area, starting from FP – run_ctx_off, is used to store the bpf_tramp_run_ctx structure and maintain the internal state of the trampoline operation;

[0103] The register save area, starting from FP - sreg_off, is used to protect the registers saved by the callee and ensure that the context is correctly restored.

[0104] The layout also includes padding areas for memory alignment and stack-up parameter areas for handling overflow parameters, starting from FP-stk_arg_off.

[0105] Through a unified stack frame layout and offset addressing mechanism, the same trampoline code can seamlessly adapt to two calling scenarios, ensuring the correctness and reliability of parameter passing, return value processing, and register context management between the kernel and eBPF programs.

[0106] The above description is merely a description of preferred embodiments of the present invention and is not intended to limit the scope of the present invention in any way. Any changes or modifications made by those skilled in the art based on the above disclosure shall fall within the protection scope of the claims.

Claims

1. A scheduling mechanism method based on the Shenwei platform, characterized in that, Includes the following steps: This paper analyzes the architecture and operating principle of the sched_ext programmable scheduling framework to clarify the core mechanism of its dynamic loading and replacement of scheduling strategies. The technical characteristics of the existing scheduling mechanism of the Shenwei platform are analyzed, and the advantages of the sched_ext programmable scheduling framework in terms of policy flexibility and scalability are combined to determine the feasibility of integrating the two. Based on the above analysis, we carried out kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform to complete the deployment and functional support of the programmable scheduling framework on the target architecture. Through systematic testing and multi-level functional verification, the performance of the scheduling mechanism under typical loads and extreme scenarios was evaluated to ensure its stability, performance improvement effect, and platform applicability; among other things... The kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform includes: code porting and adaptation of the scheduling mechanism of the sched_ext programmable scheduling framework, specifically including: scheduling class integration and framework code round-robin, design of the eBPF Trampoline mechanism under the Shenwei architecture, and kfunc call support; The aforementioned scheduling class integration and framework code round includes: fully integrating the sched_ext scheduling class in the high-version kernel into the target kernel's scheduling system; The design of the eBPF Trampoline mechanism under the Shenwei architecture includes: two-stage assembly strategy, call generator implementation, stack frame design and context management, Shenwei architecture chain execution design, reuse and storage of other registers, instruction hot replacement and bpf_arch_text_poke support; The kfunc call support includes: kernel build registration and JIT compilation support; The architecture of the sched_ext programmable scheduling framework includes: the sched_ext framework is implemented as a kernel module and runs as an independent scheduling class in the Linux kernel. Its scheduling policy is dynamically loaded, replaced and unloaded through the eBPF scheduling policy program written in user space. The sched_ext programmable scheduling framework operates based on an event-driven callback mechanism, allowing user-mode eBPF scheduling policy programs to respond to task wake-up, scheduling preemption, and load balancing kernel scheduling events, and make corresponding scheduling decisions. The core mechanism of the sched_ext programmable scheduling framework includes the following metrics: Programmability of scheduling policies: Supports dynamic updates to scheduling logic without restarting the system or recompiling the kernel; Security and Isolation: Relying on the eBPF verifier ensures the safe execution of the loader and prevents kernel state corruption; Low performance overhead: Minimizes the additional overhead introduced by scheduling policy extensions through Just-in-Time compilation and efficient kernel-user space interaction mechanisms; The scheduling mechanism of the Shenwei platform is the native scheduling framework of the Linux 6.6 kernel, which is built based on the deadline scheduling class. The sched_ext programmable scheduling framework provides the kernel with the ability to extend dynamic and programmable scheduling policies without recompiling or restarting. The feasibility of merging the two stems from the design of sched_ext programmable scheduling as a kernel module, which mainly includes scheduling class implementation, key data structures and interface definitions, as well as supporting header files and auxiliary code. By merging the framework code into the target kernel environment, and by systematically comparing, analyzing and adapting the version differences of kernel internal interfaces and data structures, it is ensured that the ported sched_ext scheduling class can seamlessly access and respond to kernel scheduling event streams.

2. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 1, characterized in that, The kernel adaptation and interface implementation of the sched_ext programmable scheduling framework on the Shenwei platform also includes: The scheduling mechanism of the sched_ext programmable scheduling framework is functionally verified and registered. After code adaptation is completed, the sched_ext programmable scheduling framework is successfully registered with the kernel as an independent scheduling class, so that it can be normally managed and called by the scheduler core. The performance and security of the sched_ext programmable scheduling framework scheduling mechanism are verified. The integrated framework is tested to verify whether it can correctly execute the user-space injected eBPF scheduling policy while maintaining the original scheduling fairness and stability, without introducing security vulnerabilities or significant performance loss. In the integration of the scheduling class and framework code, sched_ext was first introduced as a stable feature in Linux version 6.

12. The highest stable kernel version supported by the Shenwei platform is 6.

6. Therefore, the core module code of the sched_ext scheduling class is extracted from the higher version kernel. The framework code round includes the implementation body of the scheduling class, key data structures and interface definitions, as well as corresponding header files and auxiliary code. When merging the code round into the 6.6 kernel environment, the differences in internal interfaces and data structures between different kernel versions are addressed by comparing and analyzing the code, testing and verifying it, and making adaptation modifications to ensure that the ported sched_ext_class can correctly respond to and access the scheduling event stream of the 6.6 kernel. In the design of the eBPF Trampoline mechanism under the Shenwei architecture, the two-stage assembly strategy includes a space calculation and feasibility verification stage and an actual instruction generation stage. In the space calculation and feasibility verification stage, the total number of instructions and memory space required are calculated by simulating the instruction generation process, and the sufficiency of the target buffer space is verified. In the actual instruction generation stage, based on the calculation results of the first stage, the 32-bit binary code of each SW64 architecture instruction is deterministically written into the executable buffer; the two stages follow the same generation logic to ensure that the size of the final generated machine code is strictly consistent with the pre-calculated result, avoid buffer overflow and prevent code injection.

3. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 2, characterized in that, The call generator implementation includes: short jump optimization and long call backup path; The short jump optimization is as follows: calculate the signed offset between the target address and the current generation position; if the offset is within the encoding range of the SW64 architecture short jump instruction, generate a short jump instruction; wherein, the generated short jump instruction needs to be encoded and shifted, and the value of the shift is = offset / 4 - 1; The long call backup path is as follows: if the target address exceeds the short jump range, a standard call instruction sequence is generated. This sequence first loads the target address into a temporary register through an auxiliary function, and then indirectly jumps to the target address through the register. This mechanism ensures that the target function at any location in the kernel space can be called correctly.

4. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 2, characterized in that, The stack frame design and context management mechanism are used to support the correct execution of trampoline code in two different context scenarios: calls from the entry point of the traced function and direct calls. The stack frame design and context management mechanism defines a unified stack memory layout, which uses a set of offsets that are precisely calculated at compile time or runtime to locate each data area in the stack frame, including the total stack space size, BPF trampoline context offset, parameter storage area offset, call point address storage offset, and callee storage register offset. Based on this layout, dedicated subroutines save call parameters from specified general-purpose registers to the parameter area on the stack, or restore them from the stack to the corresponding registers, enabling parameter and return value transfer between the kernel and the eBPF scheduling policy program. This allows the same trampoline code to transparently handle the two call scenarios mentioned above, and accurately restore the call context after execution, ensuring that the control flow returns correctly.

5. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 2, characterized in that, The Shenwei architecture's chained execution design is designed for scenarios supporting multiple BPF_TRAMP_MODIFY_RETURN type programs attached to a single hook point. It implements dynamic execution flow control based on return values ​​through dedicated sub-functions, including: generating initialization code and zeroing the storage unit used for passing return values ​​in the chained execution; for each fmod_ret program in the chain, sequentially generating the complete code sequence that calls the program, reserving an instruction position after it as a conditional branch placeholder, and recording this placeholder position; after completing the generation of all program call code, filling the aforementioned placeholder position with conditional branch instructions based on the recorded position information; wherein... The conditional branch instruction is based on the return value of the current fmod_ret program. If it is non-zero, it jumps to the target address that skips all subsequent fmod_ret programs, thus achieving short-circuit control of chained execution based on the return value of the preceding program.

6. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 2, characterized in that, The reuse and storage of the other registers are achieved in the following way: In order to support the use of specific callee saved registers during the execution of trampoline code, a special area is allocated on the stack for temporarily storing and restoring the values ​​of these registers, ensuring that the operation of trampoline does not affect the normal register context of subsequent eBPF scheduling policy programs.

7. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 2, characterized in that, The hot-swap instruction and bpf_arch_text_poke support enable safe and dynamic modification of the executing trampoline code through the following process: Based on the replacement type and the provided old and new target addresses, generate the corresponding old instruction sequence and new instruction sequence; Perform a security check on the current instruction content at the target memory address to confirm that it completely matches the generated old instruction sequence; After verification, the new instruction sequence is written to the target memory address in an atomic operation, and the instruction cache is refreshed synchronously to ensure the thread safety and instruction consistency of the code patch.

8. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 2, characterized in that, The kfunc call support is implemented in the following way: during kernel build, the underlying functions required by the sched_ext module are registered in the kernel's BPF type format information and kfunc metadata, so that the eBPF verifier and loader can recognize and allow the eBPF scheduler to reference these functions; during the just-in-time compilation phase of the eBPF scheduler, when a call to a registered kfunc is detected, the platform's JIT compiler converts the call into a direct call to the actual kernel function address.

9. The sched_ext scheduling mechanism method based on the Shenwei platform as described in claim 1, characterized in that, The systematic testing and multi-level functional verification include: basic functional testing, comprehensive test case testing, and in-depth functional verification; among which... The basic functional tests use the test_progs test program that comes with the kernel source code tree to run hundreds of test cases related to fentry, fexit, and dummy. These tests are used to evaluate the correctness of the operation and interface stability of the core scheduling mechanism of the sched_ext programmable scheduling framework. All relevant test cases are required to pass. The comprehensive test cases include: writing and loading a custom eBPF scheduling policy program to verify the integrity and reliability of the dynamic loading, replacement and unloading process of the sched_ext programmable scheduling framework on the Shenwei platform; designing typical and boundary scenarios such as multi-task contention, CPU hot-plugging, and real-time task scheduling to verify that the behavior of the integrated scheduling system under various loads meets expectations and that it works normally in coordination with other kernel subsystems of the platform. The deep functional verification includes: Performance benchmark tests were conducted using the perf and cyclictest tools to compare and analyze key indicators of system scheduling latency, throughput, and context switching overhead before and after enabling the sched_ext customized strategy under typical loads, quantifying the performance improvement effect. Stability and stress testing involves running the system under prolonged high load and extreme stress scenarios to monitor for scheduler-related crashes, deadlocks, or performance degradation, and to verify the production environment availability of the mechanism. Security and isolation verification ensures that all user-space injected eBPF scheduling policy programs are checked by the kernel verifier and that their execution does not compromise kernel data integrity or lead to privilege escalation.