A real-time scheduling method and system based on a Wayland protocol
By introducing the priority keyword and the whr_scheduler protocol into the Wayland protocol, scheduling strategies are dynamically allocated to clients, and high and low priority queues are built. This solves the problem that clients cannot automatically request priority adjustments, achieves efficient and automated event response control, and improves user experience and system performance.
Patent Information
- Application Number
- CN202511255305.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-04
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-09-04
AI Technical Summary
In the existing Wayland protocol, clients cannot communicate with the server to request or trigger priority policy adjustments, which may cause delays for clients with high real-time response requirements due to event processing queuing, affecting user experience. Furthermore, the existing solution relies on manual operation, which is cumbersome, inefficient, and lacks automation and scalability.
The Wayland protocol introduces the priority keyword to mark the weight of client events and dynamically assigns scheduling policies to clients through the whr_scheduler protocol, constructing high and low priority queues, and prioritizing the processing of events in the high priority queue. Clients can actively request resource priority through the protocol without manual intervention from the user.
It implements automated priority control for client events, improves system deployment efficiency and compatibility, avoids delays in important events, ensures timely response to high-priority events, and is suitable for various Wayland server architectures.
Smart Images

Figure CN120743484B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of graphics display based on the Wayland protocol, and more specifically to a real-time scheduling method and system based on the Wayland protocol. Background Technology
[0002] Wayland is a modern graphics display protocol widely used in the graphical user interface architecture of Linux systems. Traditionally, the Wayland server coordinates the display content on the client side and handles events from clients through mechanisms such as epoll. However, in current implementations, communication between Wayland clients and servers, event handling, and their scheduling priorities within the operating system all employ default general strategies, failing to prioritize critical clients.
[0003] In graphics applications requiring high real-time responsiveness, client response delays due to default scheduling policies or event processing queuing can negatively impact user experience. Existing solutions cannot flexibly and dynamically control client priority at the kernel scheduling layer using the standard Wayland protocol, nor can they differentiate event processing priorities. To address this issue, existing technologies have made the following improvements:
[0004] 1. For example Figure 2 As shown, the administrator can manually change the scheduling policy of a specified process to SCHED_RR (real-time scheduling policy) by using the chrt command or by writing a script.
[0005] 2. In the Wayland architecture, the server primarily listens for socket events from all clients via the epoll mechanism. When multiple clients simultaneously generate input or output events, the server processes these events according to their epoll readiness order, lacking a concept of event-level priority. All events are treated as having equal priority, and the processing order mainly depends on the order and speed of kernel-level readiness notifications.
[0006] The above improvements have the following drawbacks:
[0007] 1. It heavily relies on manual user operation and cannot automatically determine the importance and set priorities based on client type at runtime. For large-scale system deployments or frequently changing client scenarios, this method is cumbersome, inefficient, and struggles to guarantee consistency and security.
[0008] 2. Lack of a linkage mechanism with the Wayland protocol. Clients cannot request or indicate the need to improve scheduling policies through standard protocol mechanisms, and can only rely on external human identification and operation, which reduces the system's automation and scalability.
[0009] 3. Even if a client process uses the SCHED_RR scheduling strategy, its events will still be processed equally in epoll along with those of other clients with normal priority. The Wayland server does not adjust the event processing order based on a process's scheduling strategy. Therefore, when multiple clients are handling concurrent events, critical clients may still experience response delays due to queuing, limiting the performance advantages brought by the scheduling strategy.
[0010] 4. The epoll mechanism only provides a binary "ready" condition and fails to introduce an event priority field, preventing the server from flexibly scheduling events based on client importance. It cannot implement a "preemptive event response" mechanism, creating a significant bottleneck for improving user experience.
[0011] In summary, in existing technical solutions, setting scheduling policies relies entirely on manual execution by the user or scripts, and is unrelated to the Wayland protocol itself. Clients cannot request or trigger priority policy adjustments through protocol-based communication with the server, nor can they automatically control their processing order within the graphics display system. Summary of the Invention
[0012] To address the aforementioned shortcomings in the prior art, this invention provides a real-time scheduling method and system based on the Wayland protocol, which solves the problem that clients cannot request or trigger priority policy adjustments through protocol communication with the server, nor can they automatically control their processing order in the graphics display system.
[0013] To achieve the above-mentioned objectives, the technical solution adopted by this invention is as follows:
[0014] A real-time scheduling method based on the Wayland protocol is provided, which includes the following steps:
[0015] Add the `priority` keyword to all client-side event structures on the server side; the `priority` keyword is used to mark the weight of client-side events.
[0016] Construct the wlr_scheduler protocol; the wlr_scheduler protocol is used to mark scheduling priorities;
[0017] Different scheduling strategies are assigned to the client based on the whr_scheduler protocol binding status.
[0018] When processing epoll events on the server side, client events are placed into high-priority queues or low-priority queues according to different scheduling strategies, and client events in the same queue are sorted according to the priority keyword.
[0019] Client events are scheduled in a manner that prioritizes processing client events in high-priority queues and processes client events in low-priority queues later.
[0020] Furthermore, the specific method for adding the `priority` keyword to all client-side event structures in the server-side is as follows:
[0021] The priority keyword was added to the existing client-side event resource structure wl_event_source in Wayland.
[0022] Furthermore, specific methods for assigning different scheduling strategies to the client based on the whr_scheduler protocol binding include:
[0023] Determine whether the current client is bound to the whr_scheduler protocol. If so, set the event scheduling policy of the client to a real-time scheduling policy and set the priority keyword in the event structure of the client to the specified value in the real-time scheduling policy. Otherwise, set the event scheduling policy of the client to a normal scheduling policy and set the priority keyword in the event structure of the client to the specified value in the normal scheduling policy.
[0024] Furthermore, the client sends a wl_scheduler_requesets() request to bind to the wlr_scheduler protocol, and binds to the wlr_scheduler protocol through wl_registry to complete the wlr_scheduler protocol binding. This allows the client to proactively request resource priorities in a "declarative" manner without requiring manual intervention or modification of system parameters by the user.
[0025] Furthermore, the whr_scheduler protocol is deployed on the server side. The server side responds to the client's whr_scheduler protocol binding request and uses the set_self_rr_scheduling() call to set the client's event scheduling policy for binding the whr_scheduler protocol to a real-time scheduling policy and to set the priority keyword in the client's event structure to the specified value in the real-time scheduling policy.
[0026] Furthermore, specific methods for placing client-side events into high-priority or low-priority queues according to different scheduling strategies, and sorting client-side events within the same queue according to the priority keyword, include:
[0027] After the main loop on the server side has received all client events, the client events using the real-time scheduling strategy are placed into the high-priority queue in descending order of their client event weights, while the client events using the normal scheduling strategy are placed into the low-priority queue in descending order of their client event weights.
[0028] Furthermore, when different client-side events in the same queue have the same client-side event weight, they are sorted according to the order in which the events are triggered.
[0029] A system providing a real-time scheduling method based on the Wayland protocol includes:
[0030] The protocol construction module is used to build the wlr_scheduler protocol; the wlr_scheduler protocol is used to mark scheduling priorities.
[0031] The protocol registration module is used to handle client-side binding requests to the whr_scheduler protocol;
[0032] The priority allocation module adds the priority keyword to all client-side event structures in the server-side; the priority keyword is used to mark the weight of client-side events.
[0033] The scheduling control module is used to allocate different scheduling strategies to the client based on the wlr_scheduler protocol binding status;
[0034] The sorting module is used to place client events into high-priority or low-priority queues according to different scheduling strategies, and sort client events in the same queue according to the priority keyword.
[0035] The resource scheduling module is used to schedule client events by prioritizing those in high-priority queues and then processing those in low-priority queues.
[0036] A computer device is provided, comprising a memory and a processor, the memory storing a computer program, which, when executed by the processor, causes the processor to perform steps of a real-time scheduling method based on the Wayland protocol.
[0037] A computer-readable storage medium is provided that stores a computer program, which, when executed by a processor, causes the processor to perform steps of a real-time scheduling method based on the Wayland protocol.
[0038] The beneficial effects of this invention are as follows:
[0039] 1. Clients only need to register the whr_scheduler protocol to request the activation of real-time scheduling, without needing to modify system configuration files or execute complex commands, thus improving deployment efficiency and ease of use;
[0040] 2. By centrally controlling the scheduling and event processing order through the server, the rational allocation of system resources can be ensured;
[0041] 3. After introducing the priority keyword weighting mechanism, it supports multi-level priority control, rather than the rough "whether to register the agreement" dichotomy;
[0042] 4. By using the dual-queue model, critical client events can be isolated from non-critical events, effectively avoiding performance bottlenecks caused by the server processing all events equally.
[0043] 5. It can ensure that events from high-priority clients always enter the high-priority queue first, no longer competing fairly with ordinary events, thereby avoiding the situation where "important tasks are blocked by low-priority tasks".
[0044] 6. Clients that have not registered the whr_scheduler protocol will still use the original scheduling and event handling process to ensure compatibility with older clients and systems;
[0045] 7. This invention requires minimal modifications and has clear logic, making it suitable for various Wayland-based server architectures, including wlroots, Weston, and KWin, and facilitating portability and integration. Attached Figure Description
[0046] Figure 1 This is a flowchart illustrating the method.
[0047] Figure 2 A diagram illustrating the manual setting of scheduling strategies in existing technologies;
[0048] Figure 3 This is a schematic diagram of the real-time scheduling strategy based on the Wayland protocol on the server side in an example embodiment.
[0049] Figure 4 This is a flowchart of the client's scheduling process in the embodiment. Detailed Implementation
[0050] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.
[0051] Example 1:
[0052] like Figure 1 As shown, the real-time scheduling method based on the Wayland protocol includes the following steps:
[0053] S1. Add the priority keyword to all client-side event structures in the server-side; the priority keyword is used to mark the weight of client-side events.
[0054] S2. Construct the wlr_scheduler protocol; the wlr_scheduler protocol is used to mark scheduling priorities;
[0055] S3. Assign different scheduling strategies to the client based on the whr_scheduler protocol binding status;
[0056] S4. When processing epoll events on the server side, client events are placed into high-priority queues or low-priority queues according to different scheduling strategies, and client events in the same queue are sorted according to the priority keyword.
[0057] S5. Schedule client events by prioritizing those in the high-priority queue and then processing those in the low-priority queue.
[0058] In this embodiment, the client event registration function wl_event_loop_add_fd() provided by the Waylandy source code is overridden, and a new event registration function wl_event_loop_add_fd_with_priority() is added to add the keyword priority, allowing the client to declare its priority requirements during the connection or registration phase.
[0059] Specifically, the method for adding the priority keyword to all client-side event structures in the server-side is as follows:
[0060] The priority keyword was added to the existing client-side event resource structure wl_event_source in Wayland.
[0061] The above operations extend the client event data structure in Wayland's internal event loop by introducing a priority attribute field and rewriting the event registration interface to allow specifying priorities during event registration, thereby achieving event-level scheduling control.
[0062] In this embodiment, as Figure 3 As shown, the specific methods for assigning different scheduling strategies to the client based on the wlr_scheduler protocol binding include:
[0063] Determine whether the current client is bound to the whr_scheduler protocol. If so, set the client's event scheduling policy to a real-time scheduling policy and set the priority keyword in the client's event structure to the specified value (e.g., 1 or other values) in the real-time scheduling policy. Otherwise, set the client's event scheduling policy to a normal scheduling policy (e.g., SCHED_OTHER) and set the priority keyword in the client's event structure to the specified value (e.g., 0 or other values) in the normal scheduling policy.
[0064] In this embodiment, the client sends a wl_scheduler_requesets() request to bind the wlr_scheduler protocol, and binds the wlr_scheduler protocol through wl_registry to complete the wlr_scheduler protocol binding. This method allows the client to actively request resource priority in a "declarative" manner without requiring manual intervention or modification of system parameters by the user.
[0065] In this embodiment, the whr_scheduler protocol is deployed on the server side. The server side responds to the client's whr_scheduler protocol binding request by extracting the PID of the process to which the client that requests to bind the whr_scheduler protocol belongs, and sets the event scheduling policy of the client to a real-time scheduling policy (SCHED_RR) by calling set_self_rr_scheduling(), and sets the priority keyword in the event structure of the client to the specified value in the real-time scheduling policy.
[0066] In this embodiment, as Figure 4 As shown, the specific methods for placing client-side events into high-priority or low-priority queues according to different scheduling strategies, and sorting client-side events within the same queue according to the priority keyword, include:
[0067] After the main loop on the server side has received all client events, the client events using the real-time scheduling strategy are placed into the high-priority queue in descending order of their client event weights, while the client events using the normal scheduling strategy are placed into the low-priority queue in descending order of their client event weights.
[0068] The above operations are implemented in the Wayland source code using two queue processing mechanisms: a high-priority queue containing all client events registered with the whr_scheduler protocol, and a normal-priority queue containing client events not registered with the protocol. Events are processed sequentially according to their readiness order. When a large number of events are generated by the client, the events captured by epoll_wait() in the event processing flow are categorized according to whether the client has registered with the whr_scheduler protocol. Events from clients that have registered with the protocol are placed in the high-priority queue, and the remaining events are placed in the normal-priority queue. During event scheduling, events in the high-priority queue are processed first, followed by events in the normal-priority queue. Within each queue, events are ordered in descending order of their priority value, with higher-value events responding first.
[0069] In its implementation, the Wayland source code's two-queue processing mechanism relies on the existence of a `priority` keyword in the client event data structure to identify event priority. During system initialization, a high-priority queue and a regular-priority queue are created, and queue scheduling parameters are set (starvation protection, a maximum number of high-priority events processed per round). The original `epoll_wait()` callback-invoking approach is modified to: 1. Enqueue events when they are ready; 2. Unified scheduling of queue events. First, all acquired events are enqueued separately. In a `while` loop, events in the queues are scheduled according to a FIFO strategy, prioritizing consumption from the high-priority queue. Additionally, if a regular queue remains non-empty for an extended period, a starvation protection mechanism is triggered, forcibly switching to regular queue events to ensure overall system fairness and responsiveness. When different client-side events in the same queue have the same client-side event weight, they are sorted according to their triggering order.
[0070] Example 2:
[0071] This embodiment is a further extension of Embodiment 1. In this embodiment, a system providing a real-time scheduling method based on the Wayland protocol includes:
[0072] The protocol construction module is used to build the wlr_scheduler protocol; the wlr_scheduler protocol is used to mark scheduling priorities.
[0073] The protocol registration module is used to handle client-side binding requests to the whr_scheduler protocol;
[0074] The priority allocation module adds the priority keyword to all client-side event structures in the server-side; the priority keyword is used to mark the weight of client-side events.
[0075] The scheduling control module is used to allocate different scheduling strategies to the client based on the whr_scheduler protocol binding status;
[0076] The sorting module is used to place client events into high-priority or low-priority queues according to different scheduling strategies, and sort client events in the same queue according to the priority keyword.
[0077] The resource scheduling module is used to schedule client events by prioritizing those in high-priority queues and then processing those in low-priority queues.
[0078] A computer device is provided, comprising a memory and a processor, the memory storing a computer program, which, when executed by the processor, causes the processor to perform steps of a real-time scheduling method based on the Wayland protocol.
[0079] A computer-readable storage medium is provided that stores a computer program, which, when executed by a processor, causes the processor to perform steps of a real-time scheduling method based on the Wayland protocol.
[0080] In summary, this invention, based on the client-side registration of the whr_scheduler protocol, dynamically sets real-time or normal scheduling policies for the current process. Furthermore, because the whr_scheduler protocol configures the priority keyword (weight), events can be responded to promptly based on their weights during internal event handling on the server side. This design ensures that responses to critical client events are not blocked by other ordinary clients, effectively solving the problem of delayed critical events caused by the "first-come, first-served" principle in the traditional epoll model.
Claims
1. A real-time scheduling method based on the Wayland protocol, characterized in that, Includes the following steps: Add the `priority` keyword to all client-side event structures on the server side; the `priority` keyword is used to mark the weight of client-side events. Construct the wlr_scheduler protocol; the wlr_scheduler protocol is used to mark scheduling priorities; Different scheduling strategies are assigned to the client based on the whr_scheduler protocol binding status. When processing epoll events on the server side, client events are placed into high-priority queues or low-priority queues according to different scheduling strategies, and client events in the same queue are sorted according to the priority keyword. Client events are scheduled in a manner that prioritizes processing client events in high-priority queues and processes client events in low-priority queues later. Specific methods for assigning different scheduling strategies to the client based on the whr_scheduler protocol binding include: Determine whether the current client is bound to the whr_scheduler protocol. If so, set the client's event scheduling policy to a real-time scheduling policy and set the priority keyword in the client's event structure to the specified value in the real-time scheduling policy. Otherwise, set the client's event scheduling policy to a normal scheduling policy and set the priority keyword in the client's event structure to the specified value in the normal scheduling policy.
2. The real-time scheduling method based on the Wayland protocol according to claim 1, characterized in that, The specific method to add the priority keyword to all client-side event structures on the server side is as follows: The priority keyword was added to the existing client-side event resource structure wl_event_source in Wayland.
3. The real-time scheduling method based on the Wayland protocol according to claim 1, characterized in that, The client sends a wl_scheduler_requesets() request to bind to the wlr_scheduler protocol, and then binds to the wlr_scheduler protocol through wl_registry. This completes the wlr_scheduler protocol binding, allowing the client to proactively request resource priorities in a "declarative" manner without requiring manual intervention or modification of system parameters by the user.
4. The real-time scheduling method based on the Wayland protocol according to claim 3, characterized in that, The wlr_scheduler protocol is deployed on the server side. The server side responds to the client side's wlr_scheduler protocol binding request and uses the set_self_rr_scheduling() call to set the client side's event scheduling policy to a real-time scheduling policy and set the priority keyword in the client side's event structure to the specified value in the real-time scheduling policy.
5. The real-time scheduling method based on the Wayland protocol according to claim 1, characterized in that, The specific methods for placing client events into high-priority or low-priority queues according to different scheduling strategies, and sorting client events within the same queue according to the priority keyword, include: After the main loop on the server side has received all client events, the client events using the real-time scheduling strategy are placed into the high-priority queue in descending order of their client event weights, while the client events using the normal scheduling strategy are placed into the low-priority queue in descending order of their client event weights.
6. The real-time scheduling method based on the Wayland protocol according to claim 1, characterized in that, When different client-side events in the same queue have the same client-side event weight, they are sorted according to the order in which the events were triggered.
7. A system based on the real-time scheduling method according to any one of claims 1 to 6 based on the Wayland protocol, characterized in that, include: The protocol construction module is used to build the wlr_scheduler protocol; the wlr_scheduler protocol is used to mark scheduling priorities. The protocol registration module is used to handle client-side binding requests to the whr_scheduler protocol; The priority allocation module adds the priority keyword to all client-side event structures in the server-side; the priority keyword is used to mark the weight of client-side events. The scheduling control module is used to allocate different scheduling strategies to the client based on the whr_scheduler protocol binding status; The sorting module is used to place client events into high-priority or low-priority queues according to different scheduling strategies, and sort client events in the same queue according to the priority keyword. The resource scheduling module is used to schedule client events by prioritizing those in high-priority queues and then processing those in low-priority queues.
8. A computer device, characterized in that, It includes a memory and a processor. The memory stores a computer program, and when the computer program is executed by the processor, it causes the processor to perform the steps of the real-time scheduling method based on the Wayland protocol as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The system stores a computer program, which, when executed by a processor, causes the processor to perform the steps of the real-time scheduling method based on the Wayland protocol as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data processing method, system and equipment based on Internet of Things terminal and medium
CN117608822A
System supporting qt4 to adapt to wayland and wayland interaction method
CN119248268A