#include <palacios/vmm_types.h>
+#include <palacios/vmm_time.h>
struct v3_yield_strategy {
enum {
uint64_t threshold_usec; // the point at which we transiton from untimed to timed yield
uint64_t time_usec; // the amount of time for a timed yield call
-#define V3_DEFAULT_YIELD_STRATEGY V3_YIELD_STRATEGY_GREEDY
+#define V3_DEFAULT_YIELD_STRATEGY V3_YIELD_STRATEGY_FRIENDLY
#define V3_DEFAULT_YIELD_THRESHOLD_USEC 100
-#define V3_DEFAULT_YIELD_TIME_USEC 1000
+#define V3_DEFAULT_YIELD_TIME_USEC 10000
};
uint64_t v3_cycle_diff_in_usec(struct guest_info *core, uint64_t earlier_cycles, uint64_t later_cycles);
+// The following three macros are intended to make it easy to
+// use strategy-driven yield. Call the first one when you are out of work
+// then call the second when each time that you want to yield because you are
+// out of work, and then call the third one when you have work to do again
+//
+// This assumes the thread is locked to a core and may behave strangely if
+// this is not the case.
+
+#define V3_NO_WORK(core) { \
+ uint64_t _v3_strat_local_first=0, _v3_strat_local_cur=0; \
+ _v3_strat_local_first=v3_get_host_time(core ? &(core->time_state) : 0);
+
+
+#define V3_STILL_NO_WORK(core) \
+ _v3_strat_local_cur=v3_get_host_time(core ? &(core->time_state) : 0); \
+ v3_strategy_driven_yield(core,v3_cycle_diff_in_usec(core,_v3_strat_local_first,_v3_strat_local_cur));
+
+#define V3_HAVE_WORK_AGAIN(core) }
#endif