162306a36Sopenharmony_ci/* SPDX-License-Identifier: MIT */ 262306a36Sopenharmony_ci/****************************************************************************** 362306a36Sopenharmony_ci * sched.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Scheduler state interactions 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef __XEN_PUBLIC_SCHED_H__ 1162306a36Sopenharmony_ci#define __XEN_PUBLIC_SCHED_H__ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <xen/interface/event_channel.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* 1662306a36Sopenharmony_ci * Guest Scheduler Operations 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * The SCHEDOP interface provides mechanisms for a guest to interact 1962306a36Sopenharmony_ci * with the scheduler, including yield, blocking and shutting itself 2062306a36Sopenharmony_ci * down. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci/* 2462306a36Sopenharmony_ci * The prototype for this hypercall is: 2562306a36Sopenharmony_ci * long HYPERVISOR_sched_op(enum sched_op cmd, void *arg, ...) 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci * @cmd == SCHEDOP_??? (scheduler operation). 2862306a36Sopenharmony_ci * @arg == Operation-specific extra argument(s), as described below. 2962306a36Sopenharmony_ci * ... == Additional Operation-specific extra arguments, described below. 3062306a36Sopenharmony_ci * 3162306a36Sopenharmony_ci * Versions of Xen prior to 3.0.2 provided only the following legacy version 3262306a36Sopenharmony_ci * of this hypercall, supporting only the commands yield, block and shutdown: 3362306a36Sopenharmony_ci * long sched_op(int cmd, unsigned long arg) 3462306a36Sopenharmony_ci * @cmd == SCHEDOP_??? (scheduler operation). 3562306a36Sopenharmony_ci * @arg == 0 (SCHEDOP_yield and SCHEDOP_block) 3662306a36Sopenharmony_ci * == SHUTDOWN_* code (SCHEDOP_shutdown) 3762306a36Sopenharmony_ci * 3862306a36Sopenharmony_ci * This legacy version is available to new guests as: 3962306a36Sopenharmony_ci * long HYPERVISOR_sched_op_compat(enum sched_op cmd, unsigned long arg) 4062306a36Sopenharmony_ci */ 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci/* 4362306a36Sopenharmony_ci * Voluntarily yield the CPU. 4462306a36Sopenharmony_ci * @arg == NULL. 4562306a36Sopenharmony_ci */ 4662306a36Sopenharmony_ci#define SCHEDOP_yield 0 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 4962306a36Sopenharmony_ci * Block execution of this VCPU until an event is received for processing. 5062306a36Sopenharmony_ci * If called with event upcalls masked, this operation will atomically 5162306a36Sopenharmony_ci * reenable event delivery and check for pending events before blocking the 5262306a36Sopenharmony_ci * VCPU. This avoids a "wakeup waiting" race. 5362306a36Sopenharmony_ci * @arg == NULL. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci#define SCHEDOP_block 1 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* 5862306a36Sopenharmony_ci * Halt execution of this domain (all VCPUs) and notify the system controller. 5962306a36Sopenharmony_ci * @arg == pointer to sched_shutdown structure. 6062306a36Sopenharmony_ci * 6162306a36Sopenharmony_ci * If the sched_shutdown_t reason is SHUTDOWN_suspend then 6262306a36Sopenharmony_ci * x86 PV guests must also set RDX (EDX for 32-bit guests) to the MFN 6362306a36Sopenharmony_ci * of the guest's start info page. RDX/EDX is the third hypercall 6462306a36Sopenharmony_ci * argument. 6562306a36Sopenharmony_ci * 6662306a36Sopenharmony_ci * In addition, which reason is SHUTDOWN_suspend this hypercall 6762306a36Sopenharmony_ci * returns 1 if suspend was cancelled or the domain was merely 6862306a36Sopenharmony_ci * checkpointed, and 0 if it is resuming in a new domain. 6962306a36Sopenharmony_ci */ 7062306a36Sopenharmony_ci#define SCHEDOP_shutdown 2 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* 7362306a36Sopenharmony_ci * Poll a set of event-channel ports. Return when one or more are pending. An 7462306a36Sopenharmony_ci * optional timeout may be specified. 7562306a36Sopenharmony_ci * @arg == pointer to sched_poll structure. 7662306a36Sopenharmony_ci */ 7762306a36Sopenharmony_ci#define SCHEDOP_poll 3 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/* 8062306a36Sopenharmony_ci * Declare a shutdown for another domain. The main use of this function is 8162306a36Sopenharmony_ci * in interpreting shutdown requests and reasons for fully-virtualized 8262306a36Sopenharmony_ci * domains. A para-virtualized domain may use SCHEDOP_shutdown directly. 8362306a36Sopenharmony_ci * @arg == pointer to sched_remote_shutdown structure. 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci#define SCHEDOP_remote_shutdown 4 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* 8862306a36Sopenharmony_ci * Latch a shutdown code, so that when the domain later shuts down it 8962306a36Sopenharmony_ci * reports this code to the control tools. 9062306a36Sopenharmony_ci * @arg == sched_shutdown, as for SCHEDOP_shutdown. 9162306a36Sopenharmony_ci */ 9262306a36Sopenharmony_ci#define SCHEDOP_shutdown_code 5 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* 9562306a36Sopenharmony_ci * Setup, poke and destroy a domain watchdog timer. 9662306a36Sopenharmony_ci * @arg == pointer to sched_watchdog structure. 9762306a36Sopenharmony_ci * With id == 0, setup a domain watchdog timer to cause domain shutdown 9862306a36Sopenharmony_ci * after timeout, returns watchdog id. 9962306a36Sopenharmony_ci * With id != 0 and timeout == 0, destroy domain watchdog timer. 10062306a36Sopenharmony_ci * With id != 0 and timeout != 0, poke watchdog timer and set new timeout. 10162306a36Sopenharmony_ci */ 10262306a36Sopenharmony_ci#define SCHEDOP_watchdog 6 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/* 10562306a36Sopenharmony_ci * Override the current vcpu affinity by pinning it to one physical cpu or 10662306a36Sopenharmony_ci * undo this override restoring the previous affinity. 10762306a36Sopenharmony_ci * @arg == pointer to sched_pin_override structure. 10862306a36Sopenharmony_ci * 10962306a36Sopenharmony_ci * A negative pcpu value will undo a previous pin override and restore the 11062306a36Sopenharmony_ci * previous cpu affinity. 11162306a36Sopenharmony_ci * This call is allowed for the hardware domain only and requires the cpu 11262306a36Sopenharmony_ci * to be part of the domain's cpupool. 11362306a36Sopenharmony_ci */ 11462306a36Sopenharmony_ci#define SCHEDOP_pin_override 7 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_cistruct sched_shutdown { 11762306a36Sopenharmony_ci unsigned int reason; /* SHUTDOWN_* => shutdown reason */ 11862306a36Sopenharmony_ci}; 11962306a36Sopenharmony_ciDEFINE_GUEST_HANDLE_STRUCT(sched_shutdown); 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cistruct sched_poll { 12262306a36Sopenharmony_ci GUEST_HANDLE(evtchn_port_t) ports; 12362306a36Sopenharmony_ci unsigned int nr_ports; 12462306a36Sopenharmony_ci uint64_t timeout; 12562306a36Sopenharmony_ci}; 12662306a36Sopenharmony_ciDEFINE_GUEST_HANDLE_STRUCT(sched_poll); 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_cistruct sched_remote_shutdown { 12962306a36Sopenharmony_ci domid_t domain_id; /* Remote domain ID */ 13062306a36Sopenharmony_ci unsigned int reason; /* SHUTDOWN_* => shutdown reason */ 13162306a36Sopenharmony_ci}; 13262306a36Sopenharmony_ciDEFINE_GUEST_HANDLE_STRUCT(sched_remote_shutdown); 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_cistruct sched_watchdog { 13562306a36Sopenharmony_ci uint32_t id; /* watchdog ID */ 13662306a36Sopenharmony_ci uint32_t timeout; /* timeout */ 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_ciDEFINE_GUEST_HANDLE_STRUCT(sched_watchdog); 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_cistruct sched_pin_override { 14162306a36Sopenharmony_ci int32_t pcpu; 14262306a36Sopenharmony_ci}; 14362306a36Sopenharmony_ciDEFINE_GUEST_HANDLE_STRUCT(sched_pin_override); 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci/* 14662306a36Sopenharmony_ci * Reason codes for SCHEDOP_shutdown. These may be interpreted by control 14762306a36Sopenharmony_ci * software to determine the appropriate action. For the most part, Xen does 14862306a36Sopenharmony_ci * not care about the shutdown code. 14962306a36Sopenharmony_ci */ 15062306a36Sopenharmony_ci#define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */ 15162306a36Sopenharmony_ci#define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */ 15262306a36Sopenharmony_ci#define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */ 15362306a36Sopenharmony_ci#define SHUTDOWN_crash 3 /* Tell controller we've crashed. */ 15462306a36Sopenharmony_ci#define SHUTDOWN_watchdog 4 /* Restart because watchdog time expired. */ 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/* 15762306a36Sopenharmony_ci * Domain asked to perform 'soft reset' for it. The expected behavior is to 15862306a36Sopenharmony_ci * reset internal Xen state for the domain returning it to the point where it 15962306a36Sopenharmony_ci * was created but leaving the domain's memory contents and vCPU contexts 16062306a36Sopenharmony_ci * intact. This will allow the domain to start over and set up all Xen specific 16162306a36Sopenharmony_ci * interfaces again. 16262306a36Sopenharmony_ci */ 16362306a36Sopenharmony_ci#define SHUTDOWN_soft_reset 5 16462306a36Sopenharmony_ci#define SHUTDOWN_MAX 5 /* Maximum valid shutdown reason. */ 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci#endif /* __XEN_PUBLIC_SCHED_H__ */ 167