1*3a9fd824SRoger Pau Monné /****************************************************************************** 2*3a9fd824SRoger Pau Monné * sched.h 3*3a9fd824SRoger Pau Monné * 4*3a9fd824SRoger Pau Monné * Scheduler state interactions 5*3a9fd824SRoger Pau Monné * 6*3a9fd824SRoger Pau Monné * Permission is hereby granted, free of charge, to any person obtaining a copy 7*3a9fd824SRoger Pau Monné * of this software and associated documentation files (the "Software"), to 8*3a9fd824SRoger Pau Monné * deal in the Software without restriction, including without limitation the 9*3a9fd824SRoger Pau Monné * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10*3a9fd824SRoger Pau Monné * sell copies of the Software, and to permit persons to whom the Software is 11*3a9fd824SRoger Pau Monné * furnished to do so, subject to the following conditions: 12*3a9fd824SRoger Pau Monné * 13*3a9fd824SRoger Pau Monné * The above copyright notice and this permission notice shall be included in 14*3a9fd824SRoger Pau Monné * all copies or substantial portions of the Software. 15*3a9fd824SRoger Pau Monné * 16*3a9fd824SRoger Pau Monné * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*3a9fd824SRoger Pau Monné * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*3a9fd824SRoger Pau Monné * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19*3a9fd824SRoger Pau Monné * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*3a9fd824SRoger Pau Monné * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21*3a9fd824SRoger Pau Monné * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22*3a9fd824SRoger Pau Monné * DEALINGS IN THE SOFTWARE. 23*3a9fd824SRoger Pau Monné * 24*3a9fd824SRoger Pau Monné * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 25*3a9fd824SRoger Pau Monné */ 26*3a9fd824SRoger Pau Monné 27*3a9fd824SRoger Pau Monné #ifndef __XEN_PUBLIC_SCHED_H__ 28*3a9fd824SRoger Pau Monné #define __XEN_PUBLIC_SCHED_H__ 29*3a9fd824SRoger Pau Monné 30*3a9fd824SRoger Pau Monné #include "event_channel.h" 31*3a9fd824SRoger Pau Monné 32*3a9fd824SRoger Pau Monné /* 33*3a9fd824SRoger Pau Monné * `incontents 150 sched Guest Scheduler Operations 34*3a9fd824SRoger Pau Monné * 35*3a9fd824SRoger Pau Monné * The SCHEDOP interface provides mechanisms for a guest to interact 36*3a9fd824SRoger Pau Monné * with the scheduler, including yield, blocking and shutting itself 37*3a9fd824SRoger Pau Monné * down. 38*3a9fd824SRoger Pau Monné */ 39*3a9fd824SRoger Pau Monné 40*3a9fd824SRoger Pau Monné /* 41*3a9fd824SRoger Pau Monné * The prototype for this hypercall is: 42*3a9fd824SRoger Pau Monné * ` long HYPERVISOR_sched_op(enum sched_op cmd, void *arg, ...) 43*3a9fd824SRoger Pau Monné * 44*3a9fd824SRoger Pau Monné * @cmd == SCHEDOP_??? (scheduler operation). 45*3a9fd824SRoger Pau Monné * @arg == Operation-specific extra argument(s), as described below. 46*3a9fd824SRoger Pau Monné * ... == Additional Operation-specific extra arguments, described below. 47*3a9fd824SRoger Pau Monné * 48*3a9fd824SRoger Pau Monné * Versions of Xen prior to 3.0.2 provided only the following legacy version 49*3a9fd824SRoger Pau Monné * of this hypercall, supporting only the commands yield, block and shutdown: 50*3a9fd824SRoger Pau Monné * long sched_op(int cmd, unsigned long arg) 51*3a9fd824SRoger Pau Monné * @cmd == SCHEDOP_??? (scheduler operation). 52*3a9fd824SRoger Pau Monné * @arg == 0 (SCHEDOP_yield and SCHEDOP_block) 53*3a9fd824SRoger Pau Monné * == SHUTDOWN_* code (SCHEDOP_shutdown) 54*3a9fd824SRoger Pau Monné * 55*3a9fd824SRoger Pau Monné * This legacy version is available to new guests as: 56*3a9fd824SRoger Pau Monné * ` long HYPERVISOR_sched_op_compat(enum sched_op cmd, unsigned long arg) 57*3a9fd824SRoger Pau Monné */ 58*3a9fd824SRoger Pau Monné 59*3a9fd824SRoger Pau Monné /* ` enum sched_op { // SCHEDOP_* => struct sched_* */ 60*3a9fd824SRoger Pau Monné /* 61*3a9fd824SRoger Pau Monné * Voluntarily yield the CPU. 62*3a9fd824SRoger Pau Monné * @arg == NULL. 63*3a9fd824SRoger Pau Monné */ 64*3a9fd824SRoger Pau Monné #define SCHEDOP_yield 0 65*3a9fd824SRoger Pau Monné 66*3a9fd824SRoger Pau Monné /* 67*3a9fd824SRoger Pau Monné * Block execution of this VCPU until an event is received for processing. 68*3a9fd824SRoger Pau Monné * If called with event upcalls masked, this operation will atomically 69*3a9fd824SRoger Pau Monné * reenable event delivery and check for pending events before blocking the 70*3a9fd824SRoger Pau Monné * VCPU. This avoids a "wakeup waiting" race. 71*3a9fd824SRoger Pau Monné * @arg == NULL. 72*3a9fd824SRoger Pau Monné */ 73*3a9fd824SRoger Pau Monné #define SCHEDOP_block 1 74*3a9fd824SRoger Pau Monné 75*3a9fd824SRoger Pau Monné /* 76*3a9fd824SRoger Pau Monné * Halt execution of this domain (all VCPUs) and notify the system controller. 77*3a9fd824SRoger Pau Monné * @arg == pointer to sched_shutdown_t structure. 78*3a9fd824SRoger Pau Monné * 79*3a9fd824SRoger Pau Monné * If the sched_shutdown_t reason is SHUTDOWN_suspend then 80*3a9fd824SRoger Pau Monné * x86 PV guests must also set RDX (EDX for 32-bit guests) to the MFN 81*3a9fd824SRoger Pau Monné * of the guest's start info page. RDX/EDX is the third hypercall 82*3a9fd824SRoger Pau Monné * argument. 83*3a9fd824SRoger Pau Monné * 84*3a9fd824SRoger Pau Monné * In addition, which reason is SHUTDOWN_suspend this hypercall 85*3a9fd824SRoger Pau Monné * returns 1 if suspend was cancelled or the domain was merely 86*3a9fd824SRoger Pau Monné * checkpointed, and 0 if it is resuming in a new domain. 87*3a9fd824SRoger Pau Monné */ 88*3a9fd824SRoger Pau Monné #define SCHEDOP_shutdown 2 89*3a9fd824SRoger Pau Monné 90*3a9fd824SRoger Pau Monné /* 91*3a9fd824SRoger Pau Monné * Poll a set of event-channel ports. Return when one or more are pending. An 92*3a9fd824SRoger Pau Monné * optional timeout may be specified. 93*3a9fd824SRoger Pau Monné * @arg == pointer to sched_poll_t structure. 94*3a9fd824SRoger Pau Monné */ 95*3a9fd824SRoger Pau Monné #define SCHEDOP_poll 3 96*3a9fd824SRoger Pau Monné 97*3a9fd824SRoger Pau Monné /* 98*3a9fd824SRoger Pau Monné * Declare a shutdown for another domain. The main use of this function is 99*3a9fd824SRoger Pau Monné * in interpreting shutdown requests and reasons for fully-virtualized 100*3a9fd824SRoger Pau Monné * domains. A para-virtualized domain may use SCHEDOP_shutdown directly. 101*3a9fd824SRoger Pau Monné * @arg == pointer to sched_remote_shutdown_t structure. 102*3a9fd824SRoger Pau Monné */ 103*3a9fd824SRoger Pau Monné #define SCHEDOP_remote_shutdown 4 104*3a9fd824SRoger Pau Monné 105*3a9fd824SRoger Pau Monné /* 106*3a9fd824SRoger Pau Monné * Latch a shutdown code, so that when the domain later shuts down it 107*3a9fd824SRoger Pau Monné * reports this code to the control tools. 108*3a9fd824SRoger Pau Monné * @arg == sched_shutdown_t, as for SCHEDOP_shutdown. 109*3a9fd824SRoger Pau Monné */ 110*3a9fd824SRoger Pau Monné #define SCHEDOP_shutdown_code 5 111*3a9fd824SRoger Pau Monné 112*3a9fd824SRoger Pau Monné /* 113*3a9fd824SRoger Pau Monné * Setup, poke and destroy a domain watchdog timer. 114*3a9fd824SRoger Pau Monné * @arg == pointer to sched_watchdog_t structure. 115*3a9fd824SRoger Pau Monné * With id == 0, setup a domain watchdog timer to cause domain shutdown 116*3a9fd824SRoger Pau Monné * after timeout, returns watchdog id. 117*3a9fd824SRoger Pau Monné * With id != 0 and timeout == 0, destroy domain watchdog timer. 118*3a9fd824SRoger Pau Monné * With id != 0 and timeout != 0, poke watchdog timer and set new timeout. 119*3a9fd824SRoger Pau Monné */ 120*3a9fd824SRoger Pau Monné #define SCHEDOP_watchdog 6 121*3a9fd824SRoger Pau Monné 122*3a9fd824SRoger Pau Monné /* 123*3a9fd824SRoger Pau Monné * Override the current vcpu affinity by pinning it to one physical cpu or 124*3a9fd824SRoger Pau Monné * undo this override restoring the previous affinity. 125*3a9fd824SRoger Pau Monné * @arg == pointer to sched_pin_override_t structure. 126*3a9fd824SRoger Pau Monné * 127*3a9fd824SRoger Pau Monné * A negative pcpu value will undo a previous pin override and restore the 128*3a9fd824SRoger Pau Monné * previous cpu affinity. 129*3a9fd824SRoger Pau Monné * This call is allowed for the hardware domain only and requires the cpu 130*3a9fd824SRoger Pau Monné * to be part of the domain's cpupool. 131*3a9fd824SRoger Pau Monné */ 132*3a9fd824SRoger Pau Monné #define SCHEDOP_pin_override 7 133*3a9fd824SRoger Pau Monné /* ` } */ 134*3a9fd824SRoger Pau Monné 135*3a9fd824SRoger Pau Monné struct sched_shutdown { 136*3a9fd824SRoger Pau Monné unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */ 137*3a9fd824SRoger Pau Monné }; 138*3a9fd824SRoger Pau Monné typedef struct sched_shutdown sched_shutdown_t; 139*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(sched_shutdown_t); 140*3a9fd824SRoger Pau Monné 141*3a9fd824SRoger Pau Monné struct sched_poll { 142*3a9fd824SRoger Pau Monné XEN_GUEST_HANDLE(evtchn_port_t) ports; 143*3a9fd824SRoger Pau Monné unsigned int nr_ports; 144*3a9fd824SRoger Pau Monné uint64_t timeout; 145*3a9fd824SRoger Pau Monné }; 146*3a9fd824SRoger Pau Monné typedef struct sched_poll sched_poll_t; 147*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(sched_poll_t); 148*3a9fd824SRoger Pau Monné 149*3a9fd824SRoger Pau Monné struct sched_remote_shutdown { 150*3a9fd824SRoger Pau Monné domid_t domain_id; /* Remote domain ID */ 151*3a9fd824SRoger Pau Monné unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */ 152*3a9fd824SRoger Pau Monné }; 153*3a9fd824SRoger Pau Monné typedef struct sched_remote_shutdown sched_remote_shutdown_t; 154*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(sched_remote_shutdown_t); 155*3a9fd824SRoger Pau Monné 156*3a9fd824SRoger Pau Monné struct sched_watchdog { 157*3a9fd824SRoger Pau Monné uint32_t id; /* watchdog ID */ 158*3a9fd824SRoger Pau Monné uint32_t timeout; /* timeout */ 159*3a9fd824SRoger Pau Monné }; 160*3a9fd824SRoger Pau Monné typedef struct sched_watchdog sched_watchdog_t; 161*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(sched_watchdog_t); 162*3a9fd824SRoger Pau Monné 163*3a9fd824SRoger Pau Monné struct sched_pin_override { 164*3a9fd824SRoger Pau Monné int32_t pcpu; 165*3a9fd824SRoger Pau Monné }; 166*3a9fd824SRoger Pau Monné typedef struct sched_pin_override sched_pin_override_t; 167*3a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(sched_pin_override_t); 168*3a9fd824SRoger Pau Monné 169*3a9fd824SRoger Pau Monné /* 170*3a9fd824SRoger Pau Monné * Reason codes for SCHEDOP_shutdown. These may be interpreted by control 171*3a9fd824SRoger Pau Monné * software to determine the appropriate action. For the most part, Xen does 172*3a9fd824SRoger Pau Monné * not care about the shutdown code. 173*3a9fd824SRoger Pau Monné */ 174*3a9fd824SRoger Pau Monné /* ` enum sched_shutdown_reason { */ 175*3a9fd824SRoger Pau Monné #define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */ 176*3a9fd824SRoger Pau Monné #define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */ 177*3a9fd824SRoger Pau Monné #define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */ 178*3a9fd824SRoger Pau Monné #define SHUTDOWN_crash 3 /* Tell controller we've crashed. */ 179*3a9fd824SRoger Pau Monné #define SHUTDOWN_watchdog 4 /* Restart because watchdog time expired. */ 180*3a9fd824SRoger Pau Monné 181*3a9fd824SRoger Pau Monné /* 182*3a9fd824SRoger Pau Monné * Domain asked to perform 'soft reset' for it. The expected behavior is to 183*3a9fd824SRoger Pau Monné * reset internal Xen state for the domain returning it to the point where it 184*3a9fd824SRoger Pau Monné * was created but leaving the domain's memory contents and vCPU contexts 185*3a9fd824SRoger Pau Monné * intact. This will allow the domain to start over and set up all Xen specific 186*3a9fd824SRoger Pau Monné * interfaces again. 187*3a9fd824SRoger Pau Monné */ 188*3a9fd824SRoger Pau Monné #define SHUTDOWN_soft_reset 5 189*3a9fd824SRoger Pau Monné #define SHUTDOWN_MAX 5 /* Maximum valid shutdown reason. */ 190*3a9fd824SRoger Pau Monné /* ` } */ 191*3a9fd824SRoger Pau Monné 192*3a9fd824SRoger Pau Monné #endif /* __XEN_PUBLIC_SCHED_H__ */ 193*3a9fd824SRoger Pau Monné 194*3a9fd824SRoger Pau Monné /* 195*3a9fd824SRoger Pau Monné * Local variables: 196*3a9fd824SRoger Pau Monné * mode: C 197*3a9fd824SRoger Pau Monné * c-file-style: "BSD" 198*3a9fd824SRoger Pau Monné * c-basic-offset: 4 199*3a9fd824SRoger Pau Monné * tab-width: 4 200*3a9fd824SRoger Pau Monné * indent-tabs-mode: nil 201*3a9fd824SRoger Pau Monné * End: 202*3a9fd824SRoger Pau Monné */ 203