1*8ac98aedSDavid Woodhouse /* SPDX-License-Identifier: MIT */ 250c88402SJoao Martins /****************************************************************************** 350c88402SJoao Martins * sched.h 450c88402SJoao Martins * 550c88402SJoao Martins * Scheduler state interactions 650c88402SJoao Martins * 750c88402SJoao Martins * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 850c88402SJoao Martins */ 950c88402SJoao Martins 1050c88402SJoao Martins #ifndef __XEN_PUBLIC_SCHED_H__ 1150c88402SJoao Martins #define __XEN_PUBLIC_SCHED_H__ 1250c88402SJoao Martins 1350c88402SJoao Martins #include "event_channel.h" 1450c88402SJoao Martins 1550c88402SJoao Martins /* 1650c88402SJoao Martins * `incontents 150 sched Guest Scheduler Operations 1750c88402SJoao Martins * 1850c88402SJoao Martins * The SCHEDOP interface provides mechanisms for a guest to interact 1950c88402SJoao Martins * with the scheduler, including yield, blocking and shutting itself 2050c88402SJoao Martins * down. 2150c88402SJoao Martins */ 2250c88402SJoao Martins 2350c88402SJoao Martins /* 2450c88402SJoao Martins * The prototype for this hypercall is: 2550c88402SJoao Martins * ` long HYPERVISOR_sched_op(enum sched_op cmd, void *arg, ...) 2650c88402SJoao Martins * 2750c88402SJoao Martins * @cmd == SCHEDOP_??? (scheduler operation). 2850c88402SJoao Martins * @arg == Operation-specific extra argument(s), as described below. 2950c88402SJoao Martins * ... == Additional Operation-specific extra arguments, described below. 3050c88402SJoao Martins * 3150c88402SJoao Martins * Versions of Xen prior to 3.0.2 provided only the following legacy version 3250c88402SJoao Martins * of this hypercall, supporting only the commands yield, block and shutdown: 3350c88402SJoao Martins * long sched_op(int cmd, unsigned long arg) 3450c88402SJoao Martins * @cmd == SCHEDOP_??? (scheduler operation). 3550c88402SJoao Martins * @arg == 0 (SCHEDOP_yield and SCHEDOP_block) 3650c88402SJoao Martins * == SHUTDOWN_* code (SCHEDOP_shutdown) 3750c88402SJoao Martins * 3850c88402SJoao Martins * This legacy version is available to new guests as: 3950c88402SJoao Martins * ` long HYPERVISOR_sched_op_compat(enum sched_op cmd, unsigned long arg) 4050c88402SJoao Martins */ 4150c88402SJoao Martins 4250c88402SJoao Martins /* ` enum sched_op { // SCHEDOP_* => struct sched_* */ 4350c88402SJoao Martins /* 4450c88402SJoao Martins * Voluntarily yield the CPU. 4550c88402SJoao Martins * @arg == NULL. 4650c88402SJoao Martins */ 4750c88402SJoao Martins #define SCHEDOP_yield 0 4850c88402SJoao Martins 4950c88402SJoao Martins /* 5050c88402SJoao Martins * Block execution of this VCPU until an event is received for processing. 5150c88402SJoao Martins * If called with event upcalls masked, this operation will atomically 5250c88402SJoao Martins * reenable event delivery and check for pending events before blocking the 5350c88402SJoao Martins * VCPU. This avoids a "wakeup waiting" race. 5450c88402SJoao Martins * @arg == NULL. 5550c88402SJoao Martins */ 5650c88402SJoao Martins #define SCHEDOP_block 1 5750c88402SJoao Martins 5850c88402SJoao Martins /* 5950c88402SJoao Martins * Halt execution of this domain (all VCPUs) and notify the system controller. 6050c88402SJoao Martins * @arg == pointer to sched_shutdown_t structure. 6150c88402SJoao Martins * 6250c88402SJoao Martins * If the sched_shutdown_t reason is SHUTDOWN_suspend then 6350c88402SJoao Martins * x86 PV guests must also set RDX (EDX for 32-bit guests) to the MFN 6450c88402SJoao Martins * of the guest's start info page. RDX/EDX is the third hypercall 6550c88402SJoao Martins * argument. 6650c88402SJoao Martins * 6750c88402SJoao Martins * In addition, which reason is SHUTDOWN_suspend this hypercall 6850c88402SJoao Martins * returns 1 if suspend was cancelled or the domain was merely 6950c88402SJoao Martins * checkpointed, and 0 if it is resuming in a new domain. 7050c88402SJoao Martins */ 7150c88402SJoao Martins #define SCHEDOP_shutdown 2 7250c88402SJoao Martins 7350c88402SJoao Martins /* 7450c88402SJoao Martins * Poll a set of event-channel ports. Return when one or more are pending. An 7550c88402SJoao Martins * optional timeout may be specified. 7650c88402SJoao Martins * @arg == pointer to sched_poll_t structure. 7750c88402SJoao Martins */ 7850c88402SJoao Martins #define SCHEDOP_poll 3 7950c88402SJoao Martins 8050c88402SJoao Martins /* 8150c88402SJoao Martins * Declare a shutdown for another domain. The main use of this function is 8250c88402SJoao Martins * in interpreting shutdown requests and reasons for fully-virtualized 8350c88402SJoao Martins * domains. A para-virtualized domain may use SCHEDOP_shutdown directly. 8450c88402SJoao Martins * @arg == pointer to sched_remote_shutdown_t structure. 8550c88402SJoao Martins */ 8650c88402SJoao Martins #define SCHEDOP_remote_shutdown 4 8750c88402SJoao Martins 8850c88402SJoao Martins /* 8950c88402SJoao Martins * Latch a shutdown code, so that when the domain later shuts down it 9050c88402SJoao Martins * reports this code to the control tools. 9150c88402SJoao Martins * @arg == sched_shutdown_t, as for SCHEDOP_shutdown. 9250c88402SJoao Martins */ 9350c88402SJoao Martins #define SCHEDOP_shutdown_code 5 9450c88402SJoao Martins 9550c88402SJoao Martins /* 9650c88402SJoao Martins * Setup, poke and destroy a domain watchdog timer. 9750c88402SJoao Martins * @arg == pointer to sched_watchdog_t structure. 9850c88402SJoao Martins * With id == 0, setup a domain watchdog timer to cause domain shutdown 9950c88402SJoao Martins * after timeout, returns watchdog id. 10050c88402SJoao Martins * With id != 0 and timeout == 0, destroy domain watchdog timer. 10150c88402SJoao Martins * With id != 0 and timeout != 0, poke watchdog timer and set new timeout. 10250c88402SJoao Martins */ 10350c88402SJoao Martins #define SCHEDOP_watchdog 6 10450c88402SJoao Martins 10550c88402SJoao Martins /* 10650c88402SJoao Martins * Override the current vcpu affinity by pinning it to one physical cpu or 10750c88402SJoao Martins * undo this override restoring the previous affinity. 10850c88402SJoao Martins * @arg == pointer to sched_pin_override_t structure. 10950c88402SJoao Martins * 11050c88402SJoao Martins * A negative pcpu value will undo a previous pin override and restore the 11150c88402SJoao Martins * previous cpu affinity. 11250c88402SJoao Martins * This call is allowed for the hardware domain only and requires the cpu 11350c88402SJoao Martins * to be part of the domain's cpupool. 11450c88402SJoao Martins */ 11550c88402SJoao Martins #define SCHEDOP_pin_override 7 11650c88402SJoao Martins /* ` } */ 11750c88402SJoao Martins 11850c88402SJoao Martins struct sched_shutdown { 11950c88402SJoao Martins unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */ 12050c88402SJoao Martins }; 12150c88402SJoao Martins typedef struct sched_shutdown sched_shutdown_t; 12250c88402SJoao Martins DEFINE_XEN_GUEST_HANDLE(sched_shutdown_t); 12350c88402SJoao Martins 12450c88402SJoao Martins struct sched_poll { 12550c88402SJoao Martins XEN_GUEST_HANDLE(evtchn_port_t) ports; 12650c88402SJoao Martins unsigned int nr_ports; 12750c88402SJoao Martins uint64_t timeout; 12850c88402SJoao Martins }; 12950c88402SJoao Martins typedef struct sched_poll sched_poll_t; 13050c88402SJoao Martins DEFINE_XEN_GUEST_HANDLE(sched_poll_t); 13150c88402SJoao Martins 13250c88402SJoao Martins struct sched_remote_shutdown { 13350c88402SJoao Martins domid_t domain_id; /* Remote domain ID */ 13450c88402SJoao Martins unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */ 13550c88402SJoao Martins }; 13650c88402SJoao Martins typedef struct sched_remote_shutdown sched_remote_shutdown_t; 13750c88402SJoao Martins DEFINE_XEN_GUEST_HANDLE(sched_remote_shutdown_t); 13850c88402SJoao Martins 13950c88402SJoao Martins struct sched_watchdog { 14050c88402SJoao Martins uint32_t id; /* watchdog ID */ 14150c88402SJoao Martins uint32_t timeout; /* timeout */ 14250c88402SJoao Martins }; 14350c88402SJoao Martins typedef struct sched_watchdog sched_watchdog_t; 14450c88402SJoao Martins DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t); 14550c88402SJoao Martins 14650c88402SJoao Martins struct sched_pin_override { 14750c88402SJoao Martins int32_t pcpu; 14850c88402SJoao Martins }; 14950c88402SJoao Martins typedef struct sched_pin_override sched_pin_override_t; 15050c88402SJoao Martins DEFINE_XEN_GUEST_HANDLE(sched_pin_override_t); 15150c88402SJoao Martins 15250c88402SJoao Martins /* 15350c88402SJoao Martins * Reason codes for SCHEDOP_shutdown. These may be interpreted by control 15450c88402SJoao Martins * software to determine the appropriate action. For the most part, Xen does 15550c88402SJoao Martins * not care about the shutdown code. 15650c88402SJoao Martins */ 15750c88402SJoao Martins /* ` enum sched_shutdown_reason { */ 15850c88402SJoao Martins #define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */ 15950c88402SJoao Martins #define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */ 16050c88402SJoao Martins #define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */ 16150c88402SJoao Martins #define SHUTDOWN_crash 3 /* Tell controller we've crashed. */ 16250c88402SJoao Martins #define SHUTDOWN_watchdog 4 /* Restart because watchdog time expired. */ 16350c88402SJoao Martins 16450c88402SJoao Martins /* 16550c88402SJoao Martins * Domain asked to perform 'soft reset' for it. The expected behavior is to 16650c88402SJoao Martins * reset internal Xen state for the domain returning it to the point where it 16750c88402SJoao Martins * was created but leaving the domain's memory contents and vCPU contexts 16850c88402SJoao Martins * intact. This will allow the domain to start over and set up all Xen specific 16950c88402SJoao Martins * interfaces again. 17050c88402SJoao Martins */ 17150c88402SJoao Martins #define SHUTDOWN_soft_reset 5 17250c88402SJoao Martins #define SHUTDOWN_MAX 5 /* Maximum valid shutdown reason. */ 17350c88402SJoao Martins /* ` } */ 17450c88402SJoao Martins 17550c88402SJoao Martins #endif /* __XEN_PUBLIC_SCHED_H__ */ 17650c88402SJoao Martins 17750c88402SJoao Martins /* 17850c88402SJoao Martins * Local variables: 17950c88402SJoao Martins * mode: C 18050c88402SJoao Martins * c-file-style: "BSD" 18150c88402SJoao Martins * c-basic-offset: 4 18250c88402SJoao Martins * tab-width: 4 18350c88402SJoao Martins * indent-tabs-mode: nil 18450c88402SJoao Martins * End: 18550c88402SJoao Martins */ 186