2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-08-08 23:41:36 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2003-08-08 23:41:36 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
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
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
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, "");
|
2007-03-19 20:03:06 +00:00
|
|
|
strcpy(p_features, "");
|
2004-03-31 19:43:15 +00:00
|
|
|
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
|
|
|
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;
|
2006-05-16 20:43:11 +00:00
|
|
|
|
|
|
|
strcpy(os_name, "");
|
|
|
|
strcpy(os_version, "");
|
2002-10-28 19:31:34 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 01:09:28 +00:00
|
|
|
int HOST_INFO::parse(MIOFILE& in, bool benchmarks_only) {
|
2007-03-15 19:08:22 +00:00
|
|
|
char buf[1024];
|
2002-08-15 22:03:41 +00:00
|
|
|
|
2007-03-15 19:08:22 +00:00
|
|
|
while (in.fgets(buf, sizeof(buf))) {
|
2002-04-30 22:22:54 +00:00
|
|
|
if (match_tag(buf, "</host_info>")) return 0;
|
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;
|
2009-12-09 01:09:28 +00:00
|
|
|
|
|
|
|
if (benchmarks_only) continue;
|
|
|
|
|
|
|
|
if (parse_int(buf, "<timezone>", timezone)) continue;
|
|
|
|
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;
|
|
|
|
else if (parse_str(buf, "<host_cpid>", host_cpid, sizeof(host_cpid))) continue;
|
|
|
|
else if (parse_int(buf, "<p_ncpus>", p_ncpus)) continue;
|
|
|
|
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;
|
|
|
|
else if (parse_str(buf, "<p_features>", p_features, sizeof(p_features))) 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;
|
2006-05-16 20:43:11 +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;
|
2009-12-07 06:13:17 +00:00
|
|
|
else if (match_tag(buf, "<coprocs>")) {
|
|
|
|
coprocs.parse(in);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2005-10-10 03:21:52 +00:00
|
|
|
return ERR_XML_PARSE;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2006-01-09 07:14:58 +00:00
|
|
|
// Write the host information, to the client state XML file
|
|
|
|
// or in a scheduler request message
|
2002-07-15 23:21:20 +00:00
|
|
|
//
|
2009-12-07 06:13:17 +00:00
|
|
|
int HOST_INFO::write(
|
|
|
|
MIOFILE& out, bool suppress_net_info, bool include_coprocs
|
|
|
|
) {
|
2009-08-25 21:35:21 +00:00
|
|
|
char pv[265], pm[256], pf[256], osn[256], osv[256];
|
2004-06-12 04:45:36 +00:00
|
|
|
out.printf(
|
2002-04-30 22:22:54 +00:00
|
|
|
"<host_info>\n"
|
2007-03-13 19:33:27 +00:00
|
|
|
" <timezone>%d</timezone>\n",
|
|
|
|
timezone
|
|
|
|
);
|
|
|
|
if (!suppress_net_info) {
|
|
|
|
out.printf(
|
|
|
|
" <domain_name>%s</domain_name>\n"
|
|
|
|
" <ip_addr>%s</ip_addr>\n",
|
|
|
|
domain_name,
|
|
|
|
ip_addr
|
|
|
|
);
|
|
|
|
}
|
2009-08-25 21:32:39 +00:00
|
|
|
xml_escape(p_vendor, pv, sizeof(pv));
|
|
|
|
xml_escape(p_model, pm, sizeof(pm));
|
|
|
|
xml_escape(p_features, pf, sizeof(pf));
|
|
|
|
xml_escape(os_name, osn, sizeof(osn));
|
|
|
|
xml_escape(os_version, osv, sizeof(osv));
|
2007-03-13 19:33:27 +00:00
|
|
|
out.printf(
|
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"
|
2007-03-19 20:03:06 +00:00
|
|
|
" <p_features>%s</p_features>\n"
|
2002-04-30 22:22:54 +00:00
|
|
|
" <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
|
|
|
" <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"
|
2006-05-16 20:43:11 +00:00
|
|
|
" <os_name>%s</os_name>\n"
|
2009-12-07 06:13:17 +00:00
|
|
|
" <os_version>%s</os_version>\n",
|
2005-01-20 18:50:49 +00:00
|
|
|
host_cpid,
|
2002-04-30 22:22:54 +00:00
|
|
|
p_ncpus,
|
2009-08-25 21:32:39 +00:00
|
|
|
pv,
|
|
|
|
pm,
|
|
|
|
pf,
|
2002-04-30 22:22:54 +00:00
|
|
|
p_fpops,
|
|
|
|
p_iops,
|
|
|
|
p_membw,
|
2003-08-08 23:41:36 +00:00
|
|
|
p_calculated,
|
2002-04-30 22:22:54 +00:00
|
|
|
m_nbytes,
|
|
|
|
m_cache,
|
|
|
|
m_swap,
|
|
|
|
d_total,
|
2006-05-16 20:43:11 +00:00
|
|
|
d_free,
|
2009-08-25 21:32:39 +00:00
|
|
|
osn,
|
|
|
|
osv
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2009-12-07 06:13:17 +00:00
|
|
|
if (include_coprocs) {
|
|
|
|
coprocs.write_xml(out);
|
|
|
|
}
|
|
|
|
out.printf(
|
|
|
|
"</host_info>\n"
|
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
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];
|
|
|
|
|
2007-03-19 20:03:06 +00:00
|
|
|
char* p = fgets(buf, 256, in);
|
2007-03-20 00:07:16 +00:00
|
|
|
if (!p) return 0; // Fixes compiler warning
|
2002-12-09 23:51:55 +00:00
|
|
|
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
|
|
|
|