1181624Skmacy/******************************************************************************
2181624Skmacy * sched.h
3288917Sroyger *
4181624Skmacy * Scheduler state interactions
5288917Sroyger *
6181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy
7181624Skmacy * of this software and associated documentation files (the "Software"), to
8181624Skmacy * deal in the Software without restriction, including without limitation the
9181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is
11181624Skmacy * furnished to do so, subject to the following conditions:
12181624Skmacy *
13181624Skmacy * The above copyright notice and this permission notice shall be included in
14181624Skmacy * all copies or substantial portions of the Software.
15181624Skmacy *
16181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22181624Skmacy * DEALINGS IN THE SOFTWARE.
23181624Skmacy *
24181624Skmacy * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
25181624Skmacy */
26181624Skmacy
27181624Skmacy#ifndef __XEN_PUBLIC_SCHED_H__
28181624Skmacy#define __XEN_PUBLIC_SCHED_H__
29181624Skmacy
30181624Skmacy#include "event_channel.h"
31181624Skmacy
32181624Skmacy/*
33288917Sroyger * `incontents 150 sched Guest Scheduler Operations
34288917Sroyger *
35288917Sroyger * The SCHEDOP interface provides mechanisms for a guest to interact
36288917Sroyger * with the scheduler, including yield, blocking and shutting itself
37288917Sroyger * down.
38288917Sroyger */
39288917Sroyger
40288917Sroyger/*
41181624Skmacy * The prototype for this hypercall is:
42288917Sroyger * ` long HYPERVISOR_sched_op(enum sched_op cmd, void *arg, ...)
43288917Sroyger *
44181624Skmacy * @cmd == SCHEDOP_??? (scheduler operation).
45181624Skmacy * @arg == Operation-specific extra argument(s), as described below.
46288917Sroyger * ...  == Additional Operation-specific extra arguments, described below.
47288917Sroyger *
48181624Skmacy * Versions of Xen prior to 3.0.2 provided only the following legacy version
49181624Skmacy * of this hypercall, supporting only the commands yield, block and shutdown:
50181624Skmacy *  long sched_op(int cmd, unsigned long arg)
51181624Skmacy * @cmd == SCHEDOP_??? (scheduler operation).
52181624Skmacy * @arg == 0               (SCHEDOP_yield and SCHEDOP_block)
53181624Skmacy *      == SHUTDOWN_* code (SCHEDOP_shutdown)
54288917Sroyger *
55288917Sroyger * This legacy version is available to new guests as:
56288917Sroyger * ` long HYPERVISOR_sched_op_compat(enum sched_op cmd, unsigned long arg)
57181624Skmacy */
58181624Skmacy
59288917Sroyger/* ` enum sched_op { // SCHEDOP_* => struct sched_* */
60181624Skmacy/*
61181624Skmacy * Voluntarily yield the CPU.
62181624Skmacy * @arg == NULL.
63181624Skmacy */
64181624Skmacy#define SCHEDOP_yield       0
65181624Skmacy
66181624Skmacy/*
67181624Skmacy * Block execution of this VCPU until an event is received for processing.
68181624Skmacy * If called with event upcalls masked, this operation will atomically
69181624Skmacy * reenable event delivery and check for pending events before blocking the
70181624Skmacy * VCPU. This avoids a "wakeup waiting" race.
71181624Skmacy * @arg == NULL.
72181624Skmacy */
73181624Skmacy#define SCHEDOP_block       1
74181624Skmacy
75181624Skmacy/*
76181624Skmacy * Halt execution of this domain (all VCPUs) and notify the system controller.
77288917Sroyger * @arg == pointer to sched_shutdown_t structure.
78288917Sroyger *
79288917Sroyger * If the sched_shutdown_t reason is SHUTDOWN_suspend then
80288917Sroyger * x86 PV guests must also set RDX (EDX for 32-bit guests) to the MFN
81288917Sroyger * of the guest's start info page.  RDX/EDX is the third hypercall
82288917Sroyger * argument.
83288917Sroyger *
84288917Sroyger * In addition, which reason is SHUTDOWN_suspend this hypercall
85288917Sroyger * returns 1 if suspend was cancelled or the domain was merely
86288917Sroyger * checkpointed, and 0 if it is resuming in a new domain.
87181624Skmacy */
88181624Skmacy#define SCHEDOP_shutdown    2
89181624Skmacy
90181624Skmacy/*
91181624Skmacy * Poll a set of event-channel ports. Return when one or more are pending. An
92181624Skmacy * optional timeout may be specified.
93288917Sroyger * @arg == pointer to sched_poll_t structure.
94181624Skmacy */
95181624Skmacy#define SCHEDOP_poll        3
96181624Skmacy
97181624Skmacy/*
98181624Skmacy * Declare a shutdown for another domain. The main use of this function is
99181624Skmacy * in interpreting shutdown requests and reasons for fully-virtualized
100181624Skmacy * domains.  A para-virtualized domain may use SCHEDOP_shutdown directly.
101288917Sroyger * @arg == pointer to sched_remote_shutdown_t structure.
102181624Skmacy */
103181624Skmacy#define SCHEDOP_remote_shutdown        4
104181624Skmacy
105181624Skmacy/*
106251767Sgibbs * Latch a shutdown code, so that when the domain later shuts down it
107251767Sgibbs * reports this code to the control tools.
108288917Sroyger * @arg == sched_shutdown_t, as for SCHEDOP_shutdown.
109251767Sgibbs */
110251767Sgibbs#define SCHEDOP_shutdown_code 5
111251767Sgibbs
112251767Sgibbs/*
113251767Sgibbs * Setup, poke and destroy a domain watchdog timer.
114288917Sroyger * @arg == pointer to sched_watchdog_t structure.
115251767Sgibbs * With id == 0, setup a domain watchdog timer to cause domain shutdown
116251767Sgibbs *               after timeout, returns watchdog id.
117251767Sgibbs * With id != 0 and timeout == 0, destroy domain watchdog timer.
118251767Sgibbs * With id != 0 and timeout != 0, poke watchdog timer and set new timeout.
119251767Sgibbs */
120251767Sgibbs#define SCHEDOP_watchdog    6
121288917Sroyger/* ` } */
122288917Sroyger
123288917Sroygerstruct sched_shutdown {
124288917Sroyger    unsigned int reason; /* SHUTDOWN_* => enum sched_shutdown_reason */
125288917Sroyger};
126288917Sroygertypedef struct sched_shutdown sched_shutdown_t;
127288917SroygerDEFINE_XEN_GUEST_HANDLE(sched_shutdown_t);
128288917Sroyger
129288917Sroygerstruct sched_poll {
130288917Sroyger    XEN_GUEST_HANDLE(evtchn_port_t) ports;
131288917Sroyger    unsigned int nr_ports;
132288917Sroyger    uint64_t timeout;
133288917Sroyger};
134288917Sroygertypedef struct sched_poll sched_poll_t;
135288917SroygerDEFINE_XEN_GUEST_HANDLE(sched_poll_t);
136288917Sroyger
137288917Sroygerstruct sched_remote_shutdown {
138288917Sroyger    domid_t domain_id;         /* Remote domain ID */
139288917Sroyger    unsigned int reason;       /* SHUTDOWN_* => enum sched_shutdown_reason */
140288917Sroyger};
141288917Sroygertypedef struct sched_remote_shutdown sched_remote_shutdown_t;
142288917SroygerDEFINE_XEN_GUEST_HANDLE(sched_remote_shutdown_t);
143288917Sroyger
144251767Sgibbsstruct sched_watchdog {
145251767Sgibbs    uint32_t id;                /* watchdog ID */
146251767Sgibbs    uint32_t timeout;           /* timeout */
147251767Sgibbs};
148251767Sgibbstypedef struct sched_watchdog sched_watchdog_t;
149251767SgibbsDEFINE_XEN_GUEST_HANDLE(sched_watchdog_t);
150251767Sgibbs
151251767Sgibbs/*
152181624Skmacy * Reason codes for SCHEDOP_shutdown. These may be interpreted by control
153181624Skmacy * software to determine the appropriate action. For the most part, Xen does
154181624Skmacy * not care about the shutdown code.
155181624Skmacy */
156288917Sroyger/* ` enum sched_shutdown_reason { */
157181624Skmacy#define SHUTDOWN_poweroff   0  /* Domain exited normally. Clean up and kill. */
158181624Skmacy#define SHUTDOWN_reboot     1  /* Clean up, kill, and then restart.          */
159181624Skmacy#define SHUTDOWN_suspend    2  /* Clean up, save suspend info, kill.         */
160181624Skmacy#define SHUTDOWN_crash      3  /* Tell controller we've crashed.             */
161251767Sgibbs#define SHUTDOWN_watchdog   4  /* Restart because watchdog time expired.     */
162288917Sroyger#define SHUTDOWN_MAX        4  /* Maximum valid shutdown reason.             */
163288917Sroyger/* ` } */
164181624Skmacy
165181624Skmacy#endif /* __XEN_PUBLIC_SCHED_H__ */
166181624Skmacy
167181624Skmacy/*
168181624Skmacy * Local variables:
169181624Skmacy * mode: C
170288917Sroyger * c-file-style: "BSD"
171181624Skmacy * c-basic-offset: 4
172181624Skmacy * tab-width: 4
173181624Skmacy * indent-tabs-mode: nil
174181624Skmacy * End:
175181624Skmacy */
176