From e258300578758f7c0e5a9f994201b27d40133a4b Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Mon, 3 Feb 2003 22:46:09 +0000 Subject: [PATCH] time tests check time out svn path=/trunk/boinc/; revision=855 --- client/client_state.C | 42 ++++++++++++++++++++++++++++++++++++++---- client/client_state.h | 1 + client/speed_stats.h | 2 ++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/client/client_state.C b/client/client_state.C index ec71e3eb0a..29e00ae140 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -47,7 +47,7 @@ #include "speed_stats.h" #include "client_state.h" -#define SECONDS_PER_MONTH (SECONDS_PER_DAY*30) +#define SECONDS_PER_MONTH (SECONDS_PER_DAY*30) CLIENT_STATE gstate; @@ -133,6 +133,7 @@ int CLIENT_STATE::init() { get_host_info(host_info); // this is platform dependent if (gstate.should_run_time_tests()) { + time_tests_start = time(NULL); show_message("Running time tests", "low"); #ifdef _WIN32 time_tests_handle = CreateThread( @@ -238,6 +239,7 @@ int CLIENT_STATE::time_tests() { if(!finfo) return ERR_FOPEN; host_info.write_time_tests(finfo); fclose(finfo); + return 0; } @@ -249,17 +251,49 @@ int CLIENT_STATE::check_time_tests() { #ifdef _WIN32 DWORD exit_code = 0; GetExitCodeThread(time_tests_handle, &exit_code); - if(exit_code == STILL_ACTIVE) return TIME_TESTS_RUNNING; + if(exit_code == STILL_ACTIVE) { + if(time(NULL) > time_tests_start + MAX_TIME_TESTS_SECONDS) { + show_message("Time tests timed out, using default values", "low"); + TerminateThread(time_tests_handle, 0); + CloseHandle(time_tests_handle); + host_info.p_fpops = 1e9; + host_info.p_iops = 1e9; + host_info.p_membw = 4e9; + host_info.m_cache = 1e6; + time_tests_id = 0; + return TIME_TESTS_ERROR; + } + return TIME_TESTS_RUNNING; + } CloseHandle(time_tests_handle); #else int retval, exit_code = 0; retval = waitpid(time_tests_id, &exit_code, WNOHANG); - if(retval == 0) return TIME_TESTS_RUNNING; + if(retval == 0) { + if(time(NULL) > time_tests_start + MAX_TIME_TESTS_SECONDS) { + show_message("Time tests timed out, using default values", "low"); + kill(pid, SIGKILL); + host_info.p_fpops = 1e9; + host_info.p_iops = 1e9; + host_info.p_membw = 4e9; + host_info.m_cache = 1e6; + time_tests_id = 0; + return TIME_TESTS_ERROR; + } + return TIME_TESTS_RUNNING; + } #endif time_tests_id = 0; show_message("Time tests complete", "low"); finfo = fopen(TIME_TESTS_FILE_NAME, "r"); - if(!finfo) return TIME_TESTS_COMPLETE; + if(!finfo) { + show_message("Error in time tests file, using default values", "low"); + host_info.p_fpops = 1e9; + host_info.p_iops = 1e9; + host_info.p_membw = 4e9; + host_info.m_cache = 1e6; + return TIME_TESTS_ERROR; + } host_info.parse_time_tests(finfo); fclose(finfo); file_delete(TIME_TESTS_FILE_NAME); diff --git a/client/client_state.h b/client/client_state.h index cdb8763c7c..5d2a8051ae 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -75,6 +75,7 @@ public: #else PROCESS_ID time_tests_id; #endif + unsigned int time_tests_start; int check_time_tests(); int project_disk_usage(PROJECT*, double&); int current_disk_usage(double&); diff --git a/client/speed_stats.h b/client/speed_stats.h index 5b2776aa93..1470f62b07 100644 --- a/client/speed_stats.h +++ b/client/speed_stats.h @@ -20,9 +20,11 @@ #define SAMPLE 10 /* to get a larger time sample */ #define SECS_PER_RUN 0.2 +#define MAX_TIME_TESTS_SECONDS 60 #define TIME_TESTS_RUNNING 0 #define TIME_TESTS_COMPLETE 1 #define TIME_TESTS_NOT_RUNNING 2 +#define TIME_TESTS_ERROR 3 int check_cache_size( int mem_size ); clock_t double_flop_test( int iterations, int print_debug );