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