Skip to content

Commit bcdedc9

Browse files
committed
drivers: xen: add SCHEDOP hypercall wrapper
Add SCHEDOP_poll wrapper used by Xen backends to wait on event channels efficiently. - sched - sched_poll: HYPERVISOR_sched_op(SCHEDOP_poll) Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 7184d29 commit bcdedc9

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

drivers/xen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ zephyr_sources(hvm.c)
55
zephyr_sources(events.c)
66
zephyr_sources_ifdef(CONFIG_XEN_GRANT_TABLE gnttab.c)
77
zephyr_sources(memory.c)
8+
zephyr_sources_ifdef(CONFIG_XEN_SCHED sched.c)
89

910
add_subdirectory_ifdef(CONFIG_XEN_DOM0 dom0)

drivers/xen/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ config NR_GRANT_FRAMES
2929
grant table driver in runtime. This value should be <= max_grant_frames
3030
configured for domain in Xen hypervisor.
3131

32+
config XEN_SCHED
33+
bool "Xen scheduler helpers"
34+
default y
35+
help
36+
Enable Xen scheduler helper functions
37+
3238
endmenu
3339

3440
endif # XEN

drivers/xen/sched.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2025 TOKITA Hiroshi
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/arch/arm64/hypercall.h>
8+
#include <zephyr/xen/sched.h>
9+
10+
int xen_sched_poll(evtchn_port_t *ports, unsigned int nr_ports, uint64_t timeout)
11+
{
12+
struct sched_poll poll = {
13+
.ports.p = ports,
14+
.nr_ports = 1,
15+
.timeout = timeout,
16+
};
17+
18+
return HYPERVISOR_sched_op(SCHEDOP_poll, &poll);
19+
}

include/zephyr/xen/sched.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2025 TOKITA Hiroshi
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_XEN_SCHED_H_
8+
#define ZEPHYR_XEN_SCHED_H_
9+
10+
#include <zephyr/xen/public/sched.h>
11+
12+
/**
13+
* @brief Poll one or more Xen event channels for activity.
14+
*
15+
* Issues the SCHEDOP_poll hypercall to wait for events on the specified ports.
16+
*
17+
* @param ports Array of event channel ports to poll.
18+
* @param nr_ports Number of ports in the array.
19+
* @param timeout Timeout in microseconds to wait for an event.
20+
* @return 0 if an event occurred, -EAGAIN on timeout, or negative errno on error.
21+
*/
22+
int xen_sched_poll(evtchn_port_t *ports, unsigned int nr_ports, uint64_t timeout);
23+
24+
#endif /* ZEPHYR_XEN_SCHED_H_ */

0 commit comments

Comments
 (0)