Commit 219a5405 authored by David Anderson's avatar David Anderson

client: get rid of the use of memset() to initialize structs to zero.

Instead: declare a static const instance (whose data members are zero)
and copy that.
This avoid the error-prone need to assign each member,
and it works even if there are virtual function tables.
parent e7a545e7
......@@ -226,8 +226,14 @@ struct DAILY_STATS {
double host_expavg_credit;
double day;
void clear();
DAILY_STATS() {clear();}
DAILY_STATS(int){}
void clear() {
static const DAILY_STATS x(0);
*this = x;
}
DAILY_STATS() {
clear();
}
int parse(FILE*);
};
bool operator < (const DAILY_STATS&, const DAILY_STATS&);
......@@ -273,7 +279,14 @@ struct APP {
bool ignore;
#endif
APP() {memset(this, 0, sizeof(APP));}
APP(int){}
void clear() {
static const APP x(0);
*this = x;
}
APP(){
clear();
}
int parse(XML_PARSER&);
int write(MIOFILE&);
};
......
......@@ -358,10 +358,6 @@ int CLIENT_STATE::parse_account_files() {
return 0;
}
void DAILY_STATS::clear() {
memset(this, 0, sizeof(DAILY_STATS));
}
int DAILY_STATS::parse(FILE* in) {
MIOFILE mf;
XML_PARSER xp(&mf);
......
......@@ -175,7 +175,6 @@ int cpu_benchmarks(BENCHMARK_DESC* bdp) {
double vax_mips, int_loops=0, int_time=0, fp_time;
bdp->error_str[0] = '\0';
host_info.clear_host_info();
#if defined(ANDROID) && defined(__arm__)
// check for FP accelerator: VFP, Neon, or none;
......
......@@ -502,7 +502,7 @@ int COPROCS::read_coproc_info_file(vector<string> &warnings) {
} else {
my_nvidia_gpu.device_num = (int)nvidia_gpus.size();
my_nvidia_gpu.pci_info = my_nvidia_gpu.pci_infos[0];
memset(&my_nvidia_gpu.pci_infos[0], 0, sizeof(struct PCI_INFO));
my_nvidia_gpu.pci_infos[0].clear();
nvidia_gpus.push_back(my_nvidia_gpu);
}
continue;
......@@ -519,10 +519,10 @@ int COPROCS::read_coproc_info_file(vector<string> &warnings) {
}
if (xp.match_tag("ati_opencl")) {
memset(&ati_opencl, 0, sizeof(ati_opencl));
ati_opencl.clear();
retval = ati_opencl.parse(xp, "/ati_opencl");
if (retval) {
memset(&ati_opencl, 0, sizeof(ati_opencl));
ati_opencl.clear();
} else {
ati_opencl.is_used = COPROC_IGNORED;
ati_opencls.push_back(ati_opencl);
......@@ -531,10 +531,10 @@ int COPROCS::read_coproc_info_file(vector<string> &warnings) {
}
if (xp.match_tag("nvidia_opencl")) {
memset(&nvidia_opencl, 0, sizeof(nvidia_opencl));
nvidia_opencl.clear();
retval = nvidia_opencl.parse(xp, "/nvidia_opencl");
if (retval) {
memset(&nvidia_opencl, 0, sizeof(nvidia_opencl));
nvidia_opencl.clear();
} else {
nvidia_opencl.is_used = COPROC_IGNORED;
nvidia_opencls.push_back(nvidia_opencl);
......@@ -543,10 +543,10 @@ int COPROCS::read_coproc_info_file(vector<string> &warnings) {
}
if (xp.match_tag("intel_gpu_opencl")) {
memset(&intel_gpu_opencl, 0, sizeof(intel_gpu_opencl));
intel_gpu_opencl.clear();
retval = intel_gpu_opencl.parse(xp, "/intel_gpu_opencl");
if (retval) {
memset(&intel_gpu_opencl, 0, sizeof(intel_gpu_opencl));
intel_gpu_opencl.clear();
} else {
intel_gpu_opencl.is_used = COPROC_IGNORED;
intel_gpu_opencls.push_back(intel_gpu_opencl);
......@@ -555,10 +555,10 @@ int COPROCS::read_coproc_info_file(vector<string> &warnings) {
}
if (xp.match_tag("other_opencl")) {
memset(&other_opencl, 0, sizeof(other_opencl));
other_opencl.clear();
retval = other_opencl.parse(xp, "/other_opencl");
if (retval) {
memset(&other_opencl, 0, sizeof(other_opencl));
other_opencl.clear();
} else {
other_opencl.is_used = COPROC_USED;
other_opencls.push_back(other_opencl);
......@@ -567,10 +567,10 @@ int COPROCS::read_coproc_info_file(vector<string> &warnings) {
}
if (xp.match_tag("opencl_cpu_prop")) {
memset(&cpu_opencl, 0, sizeof(cpu_opencl));
cpu_opencl.clear();
retval = cpu_opencl.parse(xp);
if (retval) {
memset(&cpu_opencl, 0, sizeof(cpu_opencl));
cpu_opencl.clear();
} else {
cpu_opencl.opencl_prop.is_used = COPROC_IGNORED;
cpu_opencls.push_back(cpu_opencl);
......
......@@ -392,7 +392,7 @@ void* cudalib = NULL;
warnings.push_back(buf);
for (j=0; j<cuda_ndevs; j++) {
memset(&cc.prop, 0, sizeof(cc.prop));
cc.prop.clear();
CUdevice device;
retval = (*p_cuDeviceGet)(&device, j);
if (retval) {
......
......@@ -51,11 +51,6 @@
DAILY_XFER_HISTORY daily_xfer_history;
NET_STATUS net_status;
NET_STATS::NET_STATS() {
memset(&up, 0, sizeof(up));
memset(&down, 0, sizeof(down));
}
// called after file xfer to update rates
//
void NET_INFO::update(double nbytes, double dt) {
......@@ -102,7 +97,7 @@ int NET_STATS::write(MIOFILE& out) {
}
int NET_STATS::parse(XML_PARSER& xp) {
memset(this, 0, sizeof(NET_STATS));
clear();
while (!xp.get_tag()) {
if (xp.match_tag("/net_stats")) return 0;
if (xp.parse_double("bwup", up.max_rate)) continue;
......
......@@ -48,7 +48,6 @@ struct NET_INFO {
// when avg_rate was last updated
void update(double nbytes, double dt);
// updates the above vars
};
class NET_STATS {
......@@ -56,7 +55,14 @@ public:
NET_INFO up;
NET_INFO down;
NET_STATS();
NET_STATS(int){}
void clear() {
static const NET_STATS x(0);
*this = x;
}
NET_STATS() {
clear();
}
int write(MIOFILE&);
int parse(XML_PARSER&);
......
......@@ -761,10 +761,6 @@ void SIM_RESULTS::divide(int n) {
monotony /= n;
}
void SIM_RESULTS::clear() {
memset(this, 0, sizeof(*this));
}
void PROJECT::print_results(FILE* f, SIM_RESULTS& sr) {
double t = project_results.flops_used;
double gt = sr.flops_used;
......
......@@ -34,12 +34,19 @@ struct SIM_RESULTS {
double idle_frac;
int nrpcs;
SIM_RESULTS(int){}
void clear() {
static const SIM_RESULTS x(0);
*this = x;
}
SIM_RESULTS() {
clear();
}
void compute_figures_of_merit();
void print(FILE* f, bool human_readable=false);
void parse(FILE* f);
void add(SIM_RESULTS& r);
void divide(int);
void clear();
};
struct PROJECT_RESULTS {
......
......@@ -325,8 +325,13 @@ struct PROJECT_WORK_FETCH {
// If we're uploading but a resource is idle, make a work request.
// If this succeeds, clear the flag.
PROJECT_WORK_FETCH(int) {}
void clear() {
static const PROJECT_WORK_FETCH x(0);
*this = x;
}
PROJECT_WORK_FETCH() {
memset(this, 0, sizeof(*this));
clear();
}
void reset(PROJECT*);
void rr_init(PROJECT*);
......
......@@ -269,7 +269,7 @@ void APP_INIT_DATA::clear() {
host_total_credit = 0;
host_expavg_credit = 0;
resource_share_fraction = 0;
host_info.clear_host_info();
host_info.clear();
proxy_info.clear();
global_prefs.defaults();
starting_elapsed_time = 0;
......
......@@ -39,12 +39,10 @@
using std::string;
LOG_FLAGS::LOG_FLAGS() {
init();
}
void LOG_FLAGS::init() {
memset(this, 0, sizeof(LOG_FLAGS));
static const LOG_FLAGS x;
*this = x;
// on by default (others are off by default)
//
task = true;
......@@ -55,6 +53,7 @@ void LOG_FLAGS::init() {
// Parse log flag preferences
//
int LOG_FLAGS::parse(XML_PARSER& xp) {
init();
while (!xp.get_tag()) {
if (!xp.is_tag) {
continue;
......@@ -729,7 +728,8 @@ int APP_CONFIG::parse_gpu_versions(
int APP_CONFIG::parse(XML_PARSER& xp, MSG_VEC& mv, LOG_FLAGS& log_flags) {
char buf[1024];
memset(this, 0, sizeof(APP_CONFIG));
static const APP_CONFIG init;
*this = init;
while (!xp.get_tag()) {
if (xp.match_tag("/app")) return 0;
......@@ -768,7 +768,8 @@ int APP_VERSION_CONFIG::parse(
XML_PARSER& xp, MSG_VEC& mv, LOG_FLAGS& log_flags
) {
char buf[1024];
memset(this, 0, sizeof(APP_VERSION_CONFIG));
static const APP_VERSION_CONFIG init;
*this = init;
while (!xp.get_tag()) {
if (!xp.is_tag) {
......
......@@ -121,7 +121,7 @@ struct LOG_FLAGS {
bool work_fetch_debug;
// work fetch policy
LOG_FLAGS();
LOG_FLAGS(){}
void init();
int parse(XML_PARSER&);
void show();
......@@ -224,6 +224,7 @@ struct APP_CONFIG {
bool fraction_done_exact;
bool report_results_immediately;
APP_CONFIG(){}
int parse(XML_PARSER&, MSG_VEC&, LOG_FLAGS&);
int parse_gpu_versions(XML_PARSER&, MSG_VEC&, LOG_FLAGS&);
};
......@@ -235,6 +236,7 @@ struct APP_VERSION_CONFIG {
double avg_ncpus;
double ngpus;
APP_VERSION_CONFIG(){}
int parse(XML_PARSER&, MSG_VEC&, LOG_FLAGS&);
};
......
......@@ -408,7 +408,8 @@ void COPROC_NVIDIA::write_xml(MIOFILE& f, bool scheduler_rpc) {
#endif
void COPROC_NVIDIA::clear() {
COPROC::clear();
static const COPROC_NVIDIA x;
*this = x;
safe_strcpy(type, proc_type_name_xml(PROC_TYPE_NVIDIA_GPU));
estimated_delay = -1; // mark as absent
cuda_version = 0;
......@@ -608,39 +609,40 @@ void COPROC_NVIDIA::set_peak_flops() {
void COPROC_NVIDIA::fake(
int driver_version, double ram, double avail_ram, int n
) {
safe_strcpy(type, proc_type_name_xml(PROC_TYPE_NVIDIA_GPU));
count = n;
for (int i=0; i<count; i++) {
device_nums[i] = i;
}
available_ram = avail_ram;
display_driver_version = driver_version;
cuda_version = 5000;
have_cuda = true;
safe_strcpy(prop.name, "Fake NVIDIA GPU");
memset(&prop, 0, sizeof(prop));
prop.totalGlobalMem = ram;
prop.sharedMemPerBlock = 100;
prop.regsPerBlock = 8;
prop.warpSize = 10;
prop.memPitch = 10;
prop.maxThreadsPerBlock = 20;
prop.maxThreadsDim[0] = 2;
prop.maxThreadsDim[1] = 2;
prop.maxThreadsDim[2] = 2;
prop.maxGridSize[0] = 10;
prop.maxGridSize[1] = 10;
prop.maxGridSize[2] = 10;
prop.totalConstMem = 10;
prop.major = 1;
prop.minor = 2;
prop.clockRate = 1250000;
prop.textureAlignment = 1000;
prop.multiProcessorCount = 14;
have_opencl = true;
safe_strcpy(opencl_prop.opencl_device_version, "OpenCL 3.17");
opencl_prop.opencl_device_version_int = 317;
set_peak_flops();
static const COPROC_NVIDIA x;
*this = x;
safe_strcpy(type, proc_type_name_xml(PROC_TYPE_NVIDIA_GPU));
count = n;
for (int i=0; i<count; i++) {
device_nums[i] = i;
}
available_ram = avail_ram;
display_driver_version = driver_version;
cuda_version = 5000;
have_cuda = true;
safe_strcpy(prop.name, "Fake NVIDIA GPU");
prop.totalGlobalMem = ram;
prop.sharedMemPerBlock = 100;
prop.regsPerBlock = 8;
prop.warpSize = 10;
prop.memPitch = 10;
prop.maxThreadsPerBlock = 20;
prop.maxThreadsDim[0] = 2;
prop.maxThreadsDim[1] = 2;
prop.maxThreadsDim[2] = 2;
prop.maxGridSize[0] = 10;
prop.maxGridSize[1] = 10;
prop.maxGridSize[2] = 10;
prop.totalConstMem = 10;
prop.major = 1;
prop.minor = 2;
prop.clockRate = 1250000;
prop.textureAlignment = 1000;
prop.multiProcessorCount = 14;
have_opencl = true;
safe_strcpy(opencl_prop.opencl_device_version, "OpenCL 3.17");
opencl_prop.opencl_device_version_int = 317;
set_peak_flops();
}
////////////////// ATI STARTS HERE /////////////////
......@@ -715,15 +717,14 @@ void COPROC_ATI::write_xml(MIOFILE& f, bool scheduler_rpc) {
#endif
void COPROC_ATI::clear() {
COPROC::clear();
static const COPROC_ATI x;
*this = x;
safe_strcpy(type, proc_type_name_xml(PROC_TYPE_AMD_GPU));
estimated_delay = -1;
safe_strcpy(name, "");
safe_strcpy(version, "");
atirt_detected = false;
amdrt_detected = false;
memset(&attribs, 0, sizeof(attribs));
memset(&info, 0, sizeof(info));
version_num = 0;
is_used = COPROC_USED;
}
......@@ -872,14 +873,13 @@ void COPROC_ATI::set_peak_flops() {
}
void COPROC_ATI::fake(double ram, double avail_ram, int n) {
clear();
safe_strcpy(type, proc_type_name_xml(PROC_TYPE_AMD_GPU));
safe_strcpy(version, "1.4.3");
safe_strcpy(name, "foobar");
count = n;
available_ram = avail_ram;
have_cal = true;
memset(&attribs, 0, sizeof(attribs));
memset(&info, 0, sizeof(info));
attribs.localRAM = (int)(ram/MEGA);
attribs.numberOfSIMD = 32;
attribs.wavefrontSize = 32;
......@@ -924,7 +924,8 @@ void COPROC_INTEL::write_xml(MIOFILE& f, bool scheduler_rpc) {
#endif
void COPROC_INTEL::clear() {
COPROC::clear();
static const COPROC_INTEL x;
*this = x;
safe_strcpy(type, proc_type_name_xml(PROC_TYPE_INTEL_GPU));
estimated_delay = -1;
safe_strcpy(name, "");
......
......@@ -136,7 +136,15 @@ struct PCI_INFO {
int device_id;
int domain_id;
PCI_INFO(): present(false), bus_id(0), device_id(0),domain_id(0) {}
void clear() {
present = false;
bus_id = 0;
device_id = 0;
domain_id = 0;
}
PCI_INFO() {
clear();
}
void write(MIOFILE&);
int parse(XML_PARSER&);
};
......@@ -196,49 +204,27 @@ struct COPROC {
OPENCL_DEVICE_PROP opencl_prop;
COPROC(int){}
inline void clear() {
static const COPROC x(0);
*this = x;
}
COPROC(){
clear();
}
#ifndef _USING_FCGI_
void write_xml(MIOFILE&, bool scheduler_rpc=false);
void write_request(MIOFILE&);
#endif
int parse(XML_PARSER&);
inline void clear() {
// can't just memcpy() - trashes vtable
type[0] = 0;
count = 0;
non_gpu = false;
peak_flops = 0;
used = 0;
have_cuda = false;
have_cal = false;
have_opencl = false;
specified_in_config = false;
req_secs = 0;
req_instances = 0;
opencl_device_count = 0;
estimated_delay = 0;
available_ram = 0;
for (int i=0; i<MAX_COPROC_INSTANCES; i++) {
device_nums[i] = 0;
instance_has_opencl[i] = false;
opencl_device_ids[i] = 0;
opencl_device_indexes[i] = 0;
running_graphics_app[i] = true;
}
device_num = 0;
memset(&opencl_prop, 0, sizeof(opencl_prop));
memset(&pci_info, 0, sizeof(pci_info));
last_print_time = 0;
}
inline void clear_usage() {
for (int i=0; i<count; i++) {
usage[i] = 0;
pending_usage[i] = 0;
}
}
COPROC() {
clear();
}
int device_num_index(int n) {
for (int i=0; i<count; i++) {
if (device_nums[i] == n) return i;
......@@ -296,6 +282,15 @@ struct CUDA_DEVICE_PROP {
double textureAlignment;
int deviceOverlap;
int multiProcessorCount;
CUDA_DEVICE_PROP(int){}
void clear() {
static const CUDA_DEVICE_PROP x(0);
*this = x;
}
CUDA_DEVICE_PROP() {
clear();
}
};
typedef int CUdevice;
......@@ -309,9 +304,7 @@ struct COPROC_NVIDIA : public COPROC {
#ifndef _USING_FCGI_
void write_xml(MIOFILE&, bool scheduler_rpc);
#endif
COPROC_NVIDIA(): COPROC() {
clear();
}
COPROC_NVIDIA(): COPROC() {}
void get(std::vector<std::string>& warnings);
void correlate(
bool use_all,
......@@ -346,9 +339,7 @@ struct COPROC_ATI : public COPROC {
#ifndef _USING_FCGI_
void write_xml(MIOFILE&, bool scheduler_rpc);
#endif
COPROC_ATI(): COPROC() {
clear();
}
COPROC_ATI(): COPROC() {}
void get(std::vector<std::string>& warnings);
void correlate(
bool use_all,
......@@ -370,9 +361,7 @@ struct COPROC_INTEL : public COPROC {
#ifndef _USING_FCGI_
void write_xml(MIOFILE&, bool scheduler_rpc);
#endif
COPROC_INTEL(): COPROC() {
clear();
}
COPROC_INTEL(): COPROC() {}
void get(std::vector<std::string>& warnings);
void correlate(
bool use_all,
......
......@@ -660,6 +660,7 @@ struct OLD_RESULT {
double completed_time;
double create_time;
OLD_RESULT(){}
int parse(XML_PARSER&);
void print();
};
......
......@@ -83,7 +83,8 @@ using std::vector;
using std::sort;
int OLD_RESULT::parse(XML_PARSER& xp) {
memset(this, 0, sizeof(OLD_RESULT));
static const OLD_RESULT x;
*this = x;
while (!xp.get_tag()) {
if (xp.match_tag("/old_result")) return 0;
if (xp.parse_str("project_url", project_url, sizeof(project_url))) continue;
......@@ -99,7 +100,8 @@ int OLD_RESULT::parse(XML_PARSER& xp) {
}
int TIME_STATS::parse(XML_PARSER& xp) {
memset(this, 0, sizeof(TIME_STATS));
static const TIME_STATS x;
*this = x;
while (!xp.get_tag()) {
if (xp.match_tag("/time_stats")) return 0;
if (xp.parse_double("now", now)) continue;
......@@ -588,7 +590,8 @@ int APP_VERSION::parse(XML_PARSER& xp) {
}
void APP_VERSION::clear() {
memset(this, 0, sizeof(*this));
static const APP_VERSION x;
*this = x;
}
WORKUNIT::WORKUNIT() {
......@@ -1049,7 +1052,7 @@ void CC_STATE::clear() {
results.clear();
platforms.clear();
executing_as_daemon = false;
host_info.clear_host_info();
host_info.clear();
have_nvidia = false;
have_ati = false;
}
......@@ -1480,7 +1483,8 @@ int RPC_CLIENT::exchange_versions(string client_name, VERSION_INFO& server) {
retval = rpc.do_rpc(buf);
if (!retval) {
memset(&server, 0, sizeof(server));
static const VERSION_INFO x;
server = x;
while (rpc.fin.fgets(buf, 256)) {
if (match_tag(buf, "</server_version>")) break;
else if (parse_int(buf, "<major>", server.major)) continue;
......
......@@ -39,50 +39,8 @@
#include "hostinfo.h"
HOST_INFO::HOST_INFO() {
clear_host_info();
}
void HOST_INFO::clear_host_info() {
timezone = 0;
safe_strcpy(domain_name, "");
safe_strcpy(serialnum, "");
safe_strcpy(ip_addr, "");
safe_strcpy(host_cpid, "");
p_ncpus = 0;
safe_strcpy(p_vendor, "");
safe_strcpy(p_model, "");
safe_strcpy(p_features, "");
p_fpops = 0;
p_iops = 0;
p_membw = 0;
p_calculated = 0;
p_vm_extensions_disabled = false;
m_nbytes = 0;
m_cache = 0;
m_swap = 0;
d_total = 0;
d_free = 0;
safe_strcpy(os_name, "");
safe_strcpy(os_version, "");
wsl_available = false;
#ifdef _WIN64
wsls.clear();
#endif
safe_strcpy(product_name, "");
safe_strcpy(mac_address, "");
safe_strcpy(virtualbox_version, "");
num_opencl_cpu_platforms = 0;
}
int HOST_INFO::parse(XML_PARSER& xp, bool static_items_only) {
clear();
while (!xp.get_tag()) {
if (xp.match_tag("/host_info")) return 0;
if (xp.parse_double("p_fpops", p_fpops)) {
......
......@@ -95,7 +95,12 @@ public:
int num_opencl_cpu_platforms;
OPENCL_CPU_PROP opencl_cpu_prop[MAX_OPENCL_CPU_PLATFORMS];
HOST_INFO();
HOST_INFO(int){}
HOST_INFO(){}
void clear() {
static const HOST_INFO x(0);
*this = x;
}
int parse(XML_PARSER&, bool static_items_only = false);
int write(MIOFILE&, bool include_net_info, bool include_coprocs);
int parse_cpu_benchmarks(FILE*);
......@@ -117,7 +122,6 @@ public:
int get_host_battery_state();
int get_local_network_info();
int get_virtualbox_version();
void clear_host_info();
void make_random_string(const char* salt, char* out);
void generate_host_cpid();
static bool parse_linux_os_info(FILE* file, const LINUX_OS_INFO_PARSER parser,
......
......@@ -85,8 +85,10 @@ struct OPENCL_DEVICE_PROP {
#endif
int parse(XML_PARSER&, const char* end_tag);
void description(char* buf, int buflen, const char* type);
OPENCL_DEVICE_PROP(){}
void clear() {
memset(this, 0, sizeof(*this));
static const OPENCL_DEVICE_PROP x;
*this = x;
}
};
......
......@@ -38,14 +38,6 @@
#include "prefs.h"
GLOBAL_PREFS_MASK::GLOBAL_PREFS_MASK() {
clear();
}
void GLOBAL_PREFS_MASK::clear() {
memset(this, 0, sizeof(GLOBAL_PREFS_MASK));
}
void GLOBAL_PREFS_MASK::set_all() {
battery_charge_min_pct = true;
battery_max_temperature = true;
......@@ -267,7 +259,6 @@ void GLOBAL_PREFS::defaults() {
// mod_time, host_specific here
// since they are outside of <venue> elements,
// and this is called when find the right venue.
// Also, don't memset to 0
}
// values for fields with an enabling checkbox in the GUI.
......
......@@ -71,8 +71,14 @@ struct GLOBAL_PREFS_MASK {
bool work_buf_additional_days;
bool work_buf_min_days;
GLOBAL_PREFS_MASK();
void clear();
GLOBAL_PREFS_MASK(int){}
void clear() {
static const GLOBAL_PREFS_MASK x(0);
*this = x;
}