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
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
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"
|
|
|
|
|
2005-08-01 22:44:40 +00:00
|
|
|
HOST_INFO::HOST_INFO() {
|
|
|
|
clear_host_info();
|
|
|
|
}
|
|
|
|
|
2004-03-31 19:43:15 +00:00
|
|
|
void HOST_INFO::clear_host_info() {
|
2005-10-04 21:44:58 +00:00
|
|
|
timezone = 0;
|
2004-03-31 19:43:15 +00:00
|
|
|
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_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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2005-10-10 03:21:52 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
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"
|
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-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;
|
|
|
|
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"
|
|
|
|
" <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-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-10-15 05:08:59 +00:00
|
|
|
void HOST_INFO::make_random_string(char* salt, char* out) {
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
sprintf(buf, "%f%s%s%f%s", dtime(), domain_name, ip_addr, d_free, salt);
|
|
|
|
md5_block((const unsigned char*) buf, (int)strlen(buf), out);
|
|
|
|
}
|
|
|
|
|
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() {
|
2005-10-15 05:08:59 +00:00
|
|
|
make_random_string("", host_cpid);
|
2005-01-20 18:50:49 +00:00
|
|
|
}
|
|
|
|
|
2005-10-15 05:08:59 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_edf7e5c147 = "$Id$";
|