Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/sched/vcpu.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef _SCHED_VCPU_H_
0019 #define _SCHED_VCPU_H_
0020 
0021 #include "kernel.h"
0022 #include "arch/i386-percpu.h"
0023 #include "util/cassert.h"
0024 
0025 #define VCPU_ALIGNMENT (LOCK_ALIGNMENT<<3)
0026 
0027 typedef enum {
0028   MAIN_VCPU = 0, IO_VCPU
0029 } vcpu_type;
0030 
0031 typedef enum {
0032   IOVCPU_CLASS_ALL = 0,
0033   IOVCPU_CLASS_ATA = (1<<0),
0034   IOVCPU_CLASS_NET = (1<<1),
0035   IOVCPU_CLASS_USB = (1<<2),
0036   IOVCPU_CLASS_DISK = (1<<3),
0037   IOVCPU_CLASS_CDROM = (1<<4),
0038 } iovcpu_class;
0039 
0040 typedef struct _replenishment {
0041   u64 t, b;
0042   struct _replenishment *next;
0043 } replenishment;
0044 
0045 #define MAX_REPL 32
0046 typedef struct {
0047   replenishment array[MAX_REPL];
0048   replenishment *head;
0049   u32 size;
0050 } repl_queue;
0051 void repl_queue_pop (repl_queue *Q);
0052 void repl_queue_add (repl_queue *Q, u64 b, u64 t);
0053 
0054 struct _vcpu;
0055 typedef struct {
0056   void (*update_replenishments) (struct _vcpu *, u64 tcur);
0057   u64  (*next_event) (struct _vcpu *);
0058   void (*end_timeslice) (struct _vcpu *, u64 delta);
0059   void (*unblock) (struct _vcpu *);
0060 } vcpu_hooks;
0061 
0062 /* Virtual CPU */
0063 typedef struct _vcpu
0064 {
0065   union {
0066     struct {
0067       spinlock lock;
0068       vcpu_type type;
0069       vcpu_hooks *hooks;
0070       struct _vcpu *next;       /* next vcpu in a queue */
0071       bool runnable, running;
0072       u16 cpu;                  /* cpu affinity for vcpu */
0073       u16 tr;                   /* task register */
0074       u16 runqueue;             /* per-VCPU runqueue */
0075       u32 quantum;              /* internal VCPU scheduling quantum */
0076       u64 next_schedule;        /* when to trigger internal schedule */
0077       u64 prev_tsc;             /* when started running */
0078       u64 virtual_tsc;          /* virtual timestamp counter */
0079 
0080       u64 C, T, b, usage;       /* common scheduling parameters */
0081 
0082       /* type-specific parameters */
0083       union {
0084         /* MAIN_VCPU */
0085         struct {
0086           u64 a;                /* activation time */
0087           repl_queue Q;
0088         } main;
0089         /* IO_VCPU */
0090         struct {
0091           u64 e;                /* eligibility time */
0092           replenishment r;      /* replenishment */
0093           u32 Unum, Uden;       /* utilization fraction */
0094           bool budgeted;
0095           iovcpu_class class;
0096         } io;
0097       };
0098 
0099       /* statistics tracking */
0100       u64 timestamps_counted;
0101       u64 prev_pmc[2];
0102       u64 pmc_total[2];
0103       u64 local_miss_count;     /* incl. pre-fetches */
0104       u64 global_miss_count;    /* 0x09, 0x03 UNC_L3_MISS.ANY (Neh.) */
0105       u64 sched_overflow;
0106       u64 sched_overhead;
0107       u64 prev_usage;
0108       u64 prev_delta;
0109       u32 prev_count;
0110 
0111       /* Cache accounting */
0112       u64 acnt_tsc;
0113       u64 cache_occupancy;
0114       u64 mpki;
0115       u64 prev_local_miss;
0116       u64 prev_global_miss;
0117       u64 prev_inst_ret;
0118     };
0119     u8 raw[VCPU_ALIGNMENT];     /* pad to VCPU_ALIGNMENT */
0120   };
0121 } vcpu;
0122 CASSERT (sizeof (vcpu) == VCPU_ALIGNMENT, vcpu);
0123 
0124 extern u64 vcpu_current_vtsc (void);
0125 
0126 extern void iovcpu_job_wakeup (task_id job, u64 T);
0127 extern void iovcpu_job_wakeup_for_me (task_id job);
0128 extern void iovcpu_job_completion (void);
0129 
0130 extern uint lowest_priority_vcpu (void);
0131 extern uint select_iovcpu (iovcpu_class);
0132 extern void set_iovcpu (task_id, iovcpu_class);
0133 
0134 extern DEF_PER_CPU (vcpu*, vcpu_current);
0135 
0136 #endif
0137 
0138 /*
0139  * Local Variables:
0140  * indent-tabs-mode: nil
0141  * mode: C
0142  * c-file-style: "gnu"
0143  * c-basic-offset: 2
0144  * End:
0145  */
0146 
0147 /* vi: set et sw=2 sts=2: */