// suspend all currently running tasks // called only from CLIENT_STATE::suspend_tasks(), // e.g. because on batteries, time of day, benchmarking, CPU throttle, etc. // void ACTIVE_TASK_SET::suspend_all(int reason) { for (unsigned int i=0; i<active_tasks.size(); i++) { ACTIVE_TASK* atp = active_tasks[i]; if (atp->task_state() != PROCESS_EXECUTING) continue; switch (reason) { case SUSPEND_REASON_CPU_THROTTLE: // if we're doing CPU throttling, don't bother suspending apps // that don't use a full CPU // if (atp->result->dont_throttle()) continue; if (atp->app_version->avg_ncpus < 1) continue; atp->preempt(REMOVE_NEVER); break; case SUSPEND_REASON_BENCHMARKS: atp->preempt(REMOVE_NEVER); break; case SUSPEND_REASON_CPU_USAGE: // If we're suspending because of non-BOINC CPU load, // don't remove from memory. // Some systems do a security check when apps are launched, // which uses a lot of CPU. // Avoid going into a preemption loop. // if (atp->result->non_cpu_intensive()) break; atp->preempt(REMOVE_NEVER); break; default: atp->preempt(REMOVE_MAYBE_USER); } } }
// suspend all currently running tasks // called only from CLIENT_STATE::suspend_tasks(), // e.g. because on batteries, time of day, benchmarking, CPU throttle, etc. // void ACTIVE_TASK_SET::suspend_all(int reason) { for (unsigned int i=0; i<active_tasks.size(); i++) { ACTIVE_TASK* atp = active_tasks[i]; if (atp->task_state() != PROCESS_EXECUTING) continue; switch (reason) { case SUSPEND_REASON_CPU_THROTTLE: // if we're doing CPU throttling, don't bother suspending apps // that don't use a full CPU // if (atp->result->project->non_cpu_intensive) continue; if (atp->app_version->avg_ncpus < 1) continue; atp->preempt(REMOVE_NEVER); break; case SUSPEND_REASON_BENCHMARKS: atp->preempt(REMOVE_NEVER); break; case SUSPEND_REASON_CPU_USAGE: if (atp->result->project->non_cpu_intensive) break; // fall through default: atp->preempt(REMOVE_MAYBE_USER); } } }
// The following runs "test_app" and sends it various messages. // Used for testing the runtime system. // void run_test_app() { WORKUNIT wu; PROJECT project; APP app; APP_VERSION av; ACTIVE_TASK at; ACTIVE_TASK_SET ats; RESULT result; int retval; char buf[256]; getcwd(buf, sizeof(buf)); // so we can see where we're running gstate.run_test_app = true; wu.project = &project; wu.app = &app; wu.command_line = string("--critical_section"); strcpy(app.name, "test app"); av.init(); av.avg_ncpus = 1; strcpy(result.name, "test result"); result.avp = &av; result.wup = &wu; result.project = &project; result.app = &app; at.result = &result; at.wup = &wu; at.app_version = &av; at.max_elapsed_time = 1e6; at.max_disk_usage = 1e14; at.max_mem_usage = 1e14; strcpy(at.slot_dir, "."); #if 1 // test file copy // ASYNC_COPY* ac = new ASYNC_COPY; FILE_INFO fi; retval = ac->init(&at, &fi, "big_file", "./big_file_copy"); if (retval) { exit(1); } while (1) { do_async_file_ops(); if (at.async_copy == NULL) { break; } } fprintf(stderr, "done\n"); exit(0); #endif ats.active_tasks.push_back(&at); unlink("boinc_finish_called"); unlink("boinc_lockfile"); unlink("boinc_temporary_exit"); unlink("stderr.txt"); retval = at.start(true); if (retval) { fprintf(stderr, "start() failed: %s\n", boincerror(retval)); } while (1) { gstate.now = dtime(); at.preempt(REMOVE_NEVER); ats.poll(); boinc_sleep(.1); at.unsuspend(); ats.poll(); boinc_sleep(.2); //at.request_reread_prefs(); } }
// suspend all currently running tasks // e.g. because on batteries, time of day, benchmarking, CPU throttle, etc. // void ACTIVE_TASK_SET::suspend_all(int reason) { for (unsigned int i=0; i<active_tasks.size(); i++) { ACTIVE_TASK* atp = active_tasks[i]; // don't suspend if process doesn't exist, // or if quit/abort is pending. // If process is currently suspended, proceed; // the new suspension may require it to be removed from memory. // E.g. a GPU job may currently be suspended due to CPU throttling, // and therefore left in memory, // but this suspension (say, a user request) // might require it to be removed from memory. // switch (atp->task_state()) { case PROCESS_EXECUTING: case PROCESS_SUSPENDED: break; default: continue; } // handle CPU throttling separately // if (reason == SUSPEND_REASON_CPU_THROTTLE) { if (atp->result->dont_throttle()) continue; atp->preempt(REMOVE_NEVER, reason); continue; } #ifdef ANDROID // On Android, remove apps from memory if on batteries // no matter what the reason for suspension. // The message polling in the BOINC runtime system // imposes an overhead which drains the battery // if (gstate.host_info.host_is_running_on_batteries()) { atp->preempt(REMOVE_ALWAYS); continue; } #endif switch (reason) { case SUSPEND_REASON_BENCHMARKS: atp->preempt(REMOVE_NEVER); break; case SUSPEND_REASON_CPU_USAGE: // If we're suspending because of non-BOINC CPU load, // don't remove from memory. // Some systems do a security check when apps are launched, // which uses a lot of CPU. // Avoid going into a preemption loop. // if (atp->result->non_cpu_intensive()) break; atp->preempt(REMOVE_NEVER); break; case SUSPEND_REASON_BATTERY_OVERHEATED: case SUSPEND_REASON_BATTERY_CHARGING: // these conditions can oscillate, so leave apps in mem // atp->preempt(REMOVE_NEVER); break; default: atp->preempt(REMOVE_MAYBE_USER); break; } } }