2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-08-08 23:41:36 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-08-08 23:41:36 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-10-28 19:04:13 +00:00
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2002-10-28 19:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-06 00:42:18 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "parse.h"
|
2005-01-20 18:50:49 +00:00
|
|
|
#include "md5_file.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "error_numbers.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-07-03 05:01:29 +00:00
|
|
|
#include "hostinfo.h"
|
|
|
|
|
2002-10-28 19:31:34 +00:00
|
|
|
// Reset the host info struct to default values
|
|
|
|
//
|
2004-03-31 19:43:15 +00:00
|
|
|
void HOST_INFO::clear_host_info() {
|
|
|
|
timezone = 0; // seconds added to local time to get UTC
|
|
|
|
strcpy(domain_name, "");
|
|
|
|
strcpy(serialnum, "");
|
|
|
|
strcpy(ip_addr, "");
|
2005-01-20 18:50:49 +00:00
|
|
|
strcpy(host_cpid, "");
|
2002-10-28 19:31:34 +00:00
|
|
|
|
2004-03-31 19:43:15 +00:00
|
|
|
p_ncpus = 0;
|
|
|
|
strcpy(p_vendor, "");
|
|
|
|
strcpy(p_model, "");
|
|
|
|
p_fpops = 0;
|
|
|
|
p_iops = 0;
|
|
|
|
p_membw = 0;
|
|
|
|
p_fpop_err = 0;
|
|
|
|
p_iop_err = 0;
|
|
|
|
p_membw_err = 0;
|
|
|
|
p_calculated = 0;
|
2003-08-08 23:41:36 +00:00
|
|
|
|
2004-03-31 19:43:15 +00:00
|
|
|
strcpy(os_name, "");
|
|
|
|
strcpy(os_version, "");
|
2002-10-28 19:31:34 +00:00
|
|
|
|
2004-03-31 19:43:15 +00:00
|
|
|
m_nbytes = 0;
|
|
|
|
m_cache = 0;
|
|
|
|
m_swap = 0;
|
2002-10-28 19:31:34 +00:00
|
|
|
|
2004-03-31 19:43:15 +00:00
|
|
|
d_total = 0;
|
|
|
|
d_free = 0;
|
2002-10-28 19:31:34 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Parse the host information, usually from the client state XML file
|
|
|
|
//
|
2004-06-12 04:45:36 +00:00
|
|
|
int HOST_INFO::parse(MIOFILE& in) {
|
2002-04-30 22:22:54 +00:00
|
|
|
char buf[256];
|
2002-08-15 22:03:41 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(this, 0, sizeof(HOST_INFO));
|
2004-06-12 04:45:36 +00:00
|
|
|
while (in.fgets(buf, 256)) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (match_tag(buf, "</host_info>")) return 0;
|
|
|
|
else if (parse_int(buf, "<timezone>", timezone)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<domain_name>", domain_name, sizeof(domain_name))) continue;
|
|
|
|
else if (parse_str(buf, "<ip_addr>", ip_addr, sizeof(ip_addr))) continue;
|
2005-01-20 18:50:49 +00:00
|
|
|
else if (parse_str(buf, "<host_cpid>", host_cpid, sizeof(host_cpid))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<p_ncpus>", p_ncpus)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<p_vendor>", p_vendor, sizeof(p_vendor))) continue;
|
|
|
|
else if (parse_str(buf, "<p_model>", p_model, sizeof(p_model))) continue;
|
2003-10-19 19:03:49 +00:00
|
|
|
else if (parse_double(buf, "<p_fpops>", p_fpops)) {
|
|
|
|
// fix foolishness that could result in negative value here
|
|
|
|
//
|
|
|
|
if (p_fpops < 0) p_fpops = -p_fpops;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_double(buf, "<p_iops>", p_iops)) {
|
|
|
|
if (p_iops < 0) p_iops = -p_iops;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_double(buf, "<p_membw>", p_membw)) {
|
|
|
|
if (p_membw < 0) p_membw = -p_membw;
|
|
|
|
continue;
|
|
|
|
}
|
2003-07-01 23:16:53 +00:00
|
|
|
else if (parse_int(buf, "<p_fpop_err>", p_fpop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_iop_err>", p_iop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_membw_err>", p_membw_err)) continue;
|
2002-11-19 22:57:05 +00:00
|
|
|
else if (parse_double(buf, "<p_calculated>", p_calculated)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<os_name>", os_name, sizeof(os_name))) continue;
|
|
|
|
else if (parse_str(buf, "<os_version>", os_version, sizeof(os_version))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_double(buf, "<m_nbytes>", m_nbytes)) continue;
|
|
|
|
else if (parse_double(buf, "<m_cache>", m_cache)) continue;
|
|
|
|
else if (parse_double(buf, "<m_swap>", m_swap)) continue;
|
|
|
|
else if (parse_double(buf, "<d_total>", d_total)) continue;
|
|
|
|
else if (parse_double(buf, "<d_free>", d_free)) continue;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Write the host information, usually to the client state XML file
|
|
|
|
//
|
2004-06-12 04:45:36 +00:00
|
|
|
int HOST_INFO::write(MIOFILE& out) {
|
|
|
|
out.printf(
|
2002-04-30 22:22:54 +00:00
|
|
|
"<host_info>\n"
|
|
|
|
" <timezone>%d</timezone>\n"
|
|
|
|
" <domain_name>%s</domain_name>\n"
|
|
|
|
" <ip_addr>%s</ip_addr>\n"
|
2005-01-20 18:50:49 +00:00
|
|
|
" <host_cpid>%s</host_cpid>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <p_ncpus>%d</p_ncpus>\n"
|
|
|
|
" <p_vendor>%s</p_vendor>\n"
|
|
|
|
" <p_model>%s</p_model>\n"
|
|
|
|
" <p_fpops>%f</p_fpops>\n"
|
|
|
|
" <p_iops>%f</p_iops>\n"
|
|
|
|
" <p_membw>%f</p_membw>\n"
|
2003-07-01 23:16:53 +00:00
|
|
|
" <p_fpop_err>%d</p_fpop_err>\n"
|
|
|
|
" <p_iop_err>%d</p_iop_err>\n"
|
|
|
|
" <p_membw_err>%d</p_membw_err>\n"
|
2002-11-19 22:57:05 +00:00
|
|
|
" <p_calculated>%f</p_calculated>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <os_name>%s</os_name>\n"
|
|
|
|
" <os_version>%s</os_version>\n"
|
|
|
|
" <m_nbytes>%f</m_nbytes>\n"
|
|
|
|
" <m_cache>%f</m_cache>\n"
|
|
|
|
" <m_swap>%f</m_swap>\n"
|
|
|
|
" <d_total>%f</d_total>\n"
|
|
|
|
" <d_free>%f</d_free>\n"
|
|
|
|
"</host_info>\n",
|
|
|
|
timezone,
|
|
|
|
domain_name,
|
|
|
|
ip_addr,
|
2005-01-20 18:50:49 +00:00
|
|
|
host_cpid,
|
2002-04-30 22:22:54 +00:00
|
|
|
p_ncpus,
|
|
|
|
p_vendor,
|
|
|
|
p_model,
|
|
|
|
p_fpops,
|
|
|
|
p_iops,
|
|
|
|
p_membw,
|
2003-07-01 23:16:53 +00:00
|
|
|
p_fpop_err,
|
|
|
|
p_iop_err,
|
|
|
|
p_membw_err,
|
2003-08-08 23:41:36 +00:00
|
|
|
p_calculated,
|
2002-04-30 22:22:54 +00:00
|
|
|
os_name,
|
|
|
|
os_version,
|
|
|
|
m_nbytes,
|
|
|
|
m_cache,
|
|
|
|
m_swap,
|
|
|
|
d_total,
|
|
|
|
d_free
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-28 19:04:13 +00:00
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
// CPU benchmarks are run in a separate process,
|
|
|
|
// which communicates its result via a file.
|
|
|
|
// The following functions read and write this file.
|
2002-12-09 23:51:55 +00:00
|
|
|
//
|
2003-04-01 03:28:37 +00:00
|
|
|
int HOST_INFO::parse_cpu_benchmarks(FILE* in) {
|
2002-12-09 23:51:55 +00:00
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
fgets(buf, 256, in);
|
|
|
|
while (fgets(buf, 256, in)) {
|
2003-04-01 03:28:37 +00:00
|
|
|
if (match_tag(buf, "<cpu_benchmarks>"));
|
|
|
|
else if (match_tag(buf, "</cpu_benchmarks>")) return 0;
|
2002-12-09 23:51:55 +00:00
|
|
|
else if (parse_double(buf, "<p_fpops>", p_fpops)) continue;
|
|
|
|
else if (parse_double(buf, "<p_iops>", p_iops)) continue;
|
|
|
|
else if (parse_double(buf, "<p_membw>", p_membw)) continue;
|
2003-07-01 23:16:53 +00:00
|
|
|
else if (parse_int(buf, "<p_fpop_err>", p_fpop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_iop_err>", p_iop_err)) continue;
|
|
|
|
else if (parse_int(buf, "<p_membw_err>", p_membw_err)) continue;
|
2002-12-09 23:51:55 +00:00
|
|
|
else if (parse_double(buf, "<p_calculated>", p_calculated)) continue;
|
|
|
|
else if (parse_double(buf, "<m_cache>", m_cache)) continue;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-01 03:28:37 +00:00
|
|
|
int HOST_INFO::write_cpu_benchmarks(FILE* out) {
|
2002-12-09 23:51:55 +00:00
|
|
|
fprintf(out,
|
2003-04-01 03:28:37 +00:00
|
|
|
"<cpu_benchmarks>\n"
|
2002-12-09 23:51:55 +00:00
|
|
|
" <p_fpops>%f</p_fpops>\n"
|
|
|
|
" <p_iops>%f</p_iops>\n"
|
|
|
|
" <p_membw>%f</p_membw>\n"
|
2003-07-01 23:16:53 +00:00
|
|
|
" <p_fpop_err>%d</p_fpop_err>\n"
|
|
|
|
" <p_iop_err>%d</p_iop_err>\n"
|
|
|
|
" <p_membw_err>%d</p_membw_err>\n"
|
2002-12-09 23:51:55 +00:00
|
|
|
" <p_calculated>%f</p_calculated>\n"
|
|
|
|
" <m_cache>%f</m_cache>\n"
|
2003-04-01 03:28:37 +00:00
|
|
|
"</cpu_benchmarks>\n",
|
2002-12-09 23:51:55 +00:00
|
|
|
p_fpops,
|
|
|
|
p_iops,
|
|
|
|
p_membw,
|
2003-07-01 23:16:53 +00:00
|
|
|
p_fpop_err,
|
|
|
|
p_iop_err,
|
|
|
|
p_membw_err,
|
2003-08-08 23:41:36 +00:00
|
|
|
p_calculated,
|
2002-12-09 23:51:55 +00:00
|
|
|
m_cache
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-20 18:50:49 +00:00
|
|
|
// make a host cross-project ID.
|
|
|
|
// Should be unique across hosts with very high probability
|
|
|
|
//
|
|
|
|
void HOST_INFO::generate_host_cpid() {
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
sprintf(buf, "%f%s%s%f", dtime(), domain_name, ip_addr, d_free);
|
|
|
|
md5_block((const unsigned char*) buf, strlen(buf), host_cpid);
|
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_edf7e5c147 = "$Id$";
|