Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Enhancements to VNET and to halting:
[palacios.git] / palacios / src / palacios / vmm_halt.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Peter Dinda <pdinda@northwestern.edu>
11  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
12  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Peter Dinda <pdinda@northwestern.edu>
16  *
17  * This is free software.  You are permitted to use,
18  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19  */
20
21 #include <palacios/vmm_halt.h>
22 #include <palacios/vmm_intr.h>
23 #include <palacios/vmm_lowlevel.h> 
24
25 #ifndef V3_CONFIG_DEBUG_HALT
26 #undef PrintDebug
27 #define PrintDebug(fmt, args...)
28 #endif
29
30
31 #define NO_PROGRESS_CYCLE_LIMIT  4000000ULL   // 4 million cycles, about 1ms on a 4 GHz machine
32
33 #define YIELD_TIME_USEC    1000
34
35
36 //
37 // This should trigger a #GP if cpl != 0, otherwise, yield to host
38 //
39
40 int v3_handle_halt(struct guest_info * info) 
41 {
42     
43     if (info->cpl != 0) { 
44         v3_raise_exception(info, GPF_EXCEPTION);
45     } else {
46         uint64_t total_cycles;
47         
48
49         PrintDebug("CPU Yield\n");
50
51         total_cycles = 0;
52
53         while (!v3_intr_pending(info) && (info->vm_info->run_state == VM_RUNNING)) {
54             uint64_t t, cycles;
55             /* Yield, allowing time to pass while yielded */
56             t = v3_get_host_time(&info->time_state);
57
58             // adaptively select the best yield option
59             if (total_cycles > NO_PROGRESS_CYCLE_LIMIT) { 
60                 // Slow yield - will take at least YIELD_TIME_USEC to come back
61                 v3_yield(info,YIELD_TIME_USEC);
62             } else {
63                 // Fast yield - may come back immediately
64                 v3_yield(info,-1);
65             }
66
67             cycles = v3_get_host_time(&info->time_state) - t;
68
69             if ((total_cycles + cycles) > total_cycles) { 
70                 total_cycles += cycles;
71             }
72
73             v3_advance_time(info, &cycles);
74
75             v3_update_timers(info);
76             
77             /* At this point, we either have some combination of 
78                interrupts, including perhaps a timer interrupt, or 
79                no interrupt.
80             */
81             if (!v3_intr_pending(info)) {
82                 /* if no interrupt, then we do halt */
83                 /* asm("hlt"); */
84             }
85
86         }
87
88         /* V3_Print("palacios: done with halt\n"); */
89         
90         info->rip += 1;
91     }
92
93     return 0;
94 }