- VirtualBox wrapper:

- change names of CPU and network-limiting functions
        to express their units (always do this).
    - wrapper monitors status.suspend_network
        and suspends/resumes network accordingly
    - wrapper sets CPU and network bandwidth limits on startup
        (Rom: should this be done before run() rather than after?)
Note: App versions using this wrapper should always have
    <dont_throttle/> in their version.xml,
    to tell the client that the app throttles itself.


svn path=/trunk/boinc/; revision=24054
This commit is contained in:
David Anderson 2011-08-27 04:13:50 +00:00
parent 7147868a36
commit 1eed0db2ec
4 changed files with 66 additions and 10 deletions

View File

@ -5130,3 +5130,19 @@ David 26 Aug 2011
sched_version.cpp
sched_send.cpp
Makefile.am
David 26 Aug 2011
- VirtualBox wrapper:
- change names of CPU and network-limiting functions
to express their units (always do this).
- wrapper monitors status.suspend_network
and suspends/resumes network accordingly
- wrapper sets CPU and network bandwidth limits on startup
(Rom: should this be done before run() rather than after?)
Note: App versions using this wrapper should always have
<dont_throttle/> in their version.xml,
to tell the client that the app throttles itself.
samples/vboxwrapper/
vbox.cpp,h
vboxwrapper.cpp

View File

@ -54,6 +54,7 @@ VBOX_VM::VBOX_VM() {
memory_size_mb.clear();
image_filename.clear();
suspended = false;
network_suspended = false;
enable_network = false;
enable_shared_directory = false;
}
@ -495,11 +496,11 @@ int VBOX_VM::register_vm() {
return retval;
}
// Enable the network adapter if a network connection is required.
//
set_network_access(enable_network);
if (enable_network) {
set_network_access(true);
}
// Enable the shared folder if a shared folder is specified.
//
@ -783,6 +784,8 @@ int VBOX_VM::set_network_access(bool enabled) {
char buf[256];
int retval;
network_suspended = !enabled;
if (enabled) {
command = "modifyvm \"" + vm_name + "\" ";
command += "--cableconnected1 on ";
@ -820,14 +823,15 @@ int VBOX_VM::set_network_access(bool enabled) {
}
int VBOX_VM::set_cpu_throttle(int throttle_speed) {
int VBOX_VM::set_cpu_usage_fraction(double x) {
string command;
string output;
char buf[256];
int retval;
sprintf(buf, "%d", throttle_speed);
// the arg to modifyvm is percentage
//
sprintf(buf, "%d", (int)(x*100.));
command = "modifyvm \"" + vm_name + "\" ";
command += "--cpuexecutioncap ";
command += buf;
@ -849,14 +853,16 @@ int VBOX_VM::set_cpu_throttle(int throttle_speed) {
}
int VBOX_VM::set_network_throttle(int throttle_speed) {
int VBOX_VM::set_network_max_bytes_sec(double x) {
string command;
string output;
char buf[256];
int retval;
sprintf(buf, "%d", throttle_speed);
// the argument to modifyvm is in Kbps
//
sprintf(buf, "%d", (int)(x*8./1000.));
command = "modifyvm \"" + vm_name + "\" ";
command += "--nicspeed1 ";
command += buf;

View File

@ -36,7 +36,10 @@ struct VBOX_VM {
std::string vm_name;
// unique name for the VM
bool suspended;
bool network_suspended;
// whether network access is temporarily suspended
bool enable_network;
// whether to allow network access at all
bool enable_shared_directory;
void poll();
@ -54,8 +57,8 @@ struct VBOX_VM {
int deregister_vm();
int startvm();
int set_network_access(bool enabled);
int set_cpu_throttle(int throttle_speed);
int set_network_throttle(int throttle_speed);
int set_cpu_usage_fraction(double);
int set_network_max_bytes_sec(double);
static int initialize();
static int generate_vm_root_dir( std::string& dir );

View File

@ -184,6 +184,26 @@ int main(int argc, char** argv) {
boinc_finish(retval);
}
// set CPU and network throttling if needed
//
double x = aid.global_prefs.cpu_usage_limit;
if (x && x<100) {
vm.set_cpu_usage_fraction(x/100.);
}
// vbox doesn't distinguish up and down bandwidth; use the min of the prefs
//
x = aid.global_prefs.max_bytes_sec_up;
double y = aid.global_prefs.max_bytes_sec_down;
if (y) {
if (!x || y<x) {
x = y;
}
}
if (x) {
vm.set_network_max_bytes_sec(x);
}
while (1) {
vm.poll();
is_running = vm.is_running();
@ -222,6 +242,17 @@ int main(int argc, char** argv) {
}
}
}
if (vm.enable_network) {
if (boinc_status.network_suspended) {
if (!vm.network_suspended) {
vm.set_network_access(false);
}
} else {
if (vm.network_suspended) {
vm.set_network_access(true);
}
}
}
if (boinc_time_to_checkpoint()) {
boinc_checkpoint_completed();
checkpoint_cpu_time += current_cpu_time;