2012-11-28 20:26:49 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2012 University of California
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// BOINC 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "filesys.h"
|
|
|
|
|
|
|
|
#include "client_msgs.h"
|
|
|
|
#include "client_state.h"
|
|
|
|
#include "client_types.h"
|
|
|
|
#include "project.h"
|
|
|
|
#include "result.h"
|
|
|
|
|
|
|
|
#include "app_config.h"
|
|
|
|
|
|
|
|
bool have_max_concurrent = false;
|
|
|
|
|
2012-12-12 19:45:49 +00:00
|
|
|
int APP_CONFIG::parse(XML_PARSER& xp, PROJECT* p) {
|
2012-11-28 20:26:49 +00:00
|
|
|
memset(this, 0, sizeof(APP_CONFIG));
|
|
|
|
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/app")) return 0;
|
|
|
|
if (xp.parse_str("name", name, 256)) continue;
|
|
|
|
if (xp.parse_int("max_concurrent", max_concurrent)) {
|
|
|
|
if (max_concurrent) have_max_concurrent = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xp.match_tag("gpu_versions")) {
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/gpu_versions")) break;
|
|
|
|
if (xp.parse_double("gpu_usage", gpu_gpu_usage)) continue;
|
|
|
|
if (xp.parse_double("cpu_usage", gpu_cpu_usage)) continue;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2012-12-12 19:45:49 +00:00
|
|
|
if (log_flags.unparsed_xml) {
|
|
|
|
msg_printf(p, MSG_INFO,
|
|
|
|
"Unparsed line in app_info.xml: %s",
|
|
|
|
xp.parsed_tag
|
|
|
|
);
|
|
|
|
}
|
|
|
|
xp.skip_unexpected(log_flags.unparsed_xml, "APP_CONFIG::parse");
|
2012-11-28 20:26:49 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2012-12-12 19:45:49 +00:00
|
|
|
int APP_CONFIGS::parse(XML_PARSER& xp, PROJECT* p) {
|
2012-11-28 20:26:49 +00:00
|
|
|
app_configs.clear();
|
|
|
|
if (!xp.parse_start("app_config")) return ERR_XML_PARSE;
|
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/app_config")) return 0;
|
|
|
|
if (xp.match_tag("app")) {
|
|
|
|
APP_CONFIG ac;
|
2012-12-12 19:45:49 +00:00
|
|
|
int retval = ac.parse(xp, p);
|
2012-11-28 20:26:49 +00:00
|
|
|
if (!retval) {
|
|
|
|
app_configs.push_back(ac);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2012-12-12 19:45:49 +00:00
|
|
|
if (log_flags.unparsed_xml) {
|
|
|
|
msg_printf(p, MSG_INFO,
|
|
|
|
"Unparsed line in app_info.xml: %s",
|
|
|
|
xp.parsed_tag
|
|
|
|
);
|
|
|
|
}
|
|
|
|
xp.skip_unexpected(log_flags.unparsed_xml, "APP_CONFIGS::parse");
|
2012-11-28 20:26:49 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2012-12-12 19:45:49 +00:00
|
|
|
int APP_CONFIGS::parse_file(FILE* f, PROJECT* p) {
|
2012-11-28 20:26:49 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
mf.init_file(f);
|
2012-12-12 19:45:49 +00:00
|
|
|
int retval = parse(xp, p);
|
2012-11-28 20:26:49 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-05-19 17:02:00 +00:00
|
|
|
void APP_CONFIGS::config_app_versions(PROJECT* p, bool show_warnings) {
|
2012-11-28 20:26:49 +00:00
|
|
|
for (unsigned int i=0; i<app_configs.size(); i++) {
|
|
|
|
APP_CONFIG& ac = app_configs[i];
|
|
|
|
APP* app = gstate.lookup_app(p, ac.name);
|
|
|
|
if (!app) {
|
2013-05-19 17:02:00 +00:00
|
|
|
if (show_warnings) {
|
|
|
|
msg_printf(p, MSG_USER_ALERT,
|
|
|
|
"Your app_config.xml file refers to an unknown application '%s'. Known applications: %s",
|
|
|
|
ac.name, app_list_string(p).c_str()
|
|
|
|
);
|
|
|
|
}
|
2012-11-28 20:26:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
app->max_concurrent = ac.max_concurrent;
|
|
|
|
if (!ac.gpu_gpu_usage || !ac.gpu_cpu_usage) continue;
|
|
|
|
for (unsigned int j=0; j<gstate.app_versions.size(); j++) {
|
|
|
|
APP_VERSION* avp = gstate.app_versions[j];
|
|
|
|
if (avp->app != app) continue;
|
|
|
|
if (!avp->gpu_usage.rsc_type) continue;
|
|
|
|
avp->gpu_usage.usage = ac.gpu_gpu_usage;
|
|
|
|
avp->avg_ncpus = ac.gpu_cpu_usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void max_concurrent_init() {
|
|
|
|
for (unsigned int i=0; i<gstate.apps.size(); i++) {
|
|
|
|
gstate.apps[i]->n_concurrent = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 19:48:14 +00:00
|
|
|
// undo the effects of an app_config.xml that no longer exists
|
|
|
|
// NOTE: all we can do here is to clear APP::max_concurrent;
|
|
|
|
// we can't restore device usage info because we don't have it.
|
|
|
|
// It will be restored on next scheduler RPC.
|
|
|
|
//
|
|
|
|
static void clear_app_config(PROJECT* p) {
|
|
|
|
for (unsigned int i=0; i<gstate.apps.size(); i++) {
|
|
|
|
APP* app = gstate.apps[i];
|
|
|
|
if (app->project != p) continue;
|
|
|
|
app->max_concurrent = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 20:26:49 +00:00
|
|
|
void check_app_config() {
|
2013-04-18 20:57:33 +00:00
|
|
|
char path[MAXPATHLEN];
|
2012-11-28 20:26:49 +00:00
|
|
|
FILE* f;
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<gstate.projects.size(); i++) {
|
|
|
|
PROJECT* p = gstate.projects[i];
|
2013-04-18 20:57:33 +00:00
|
|
|
sprintf(path, "%s/%s", p->project_dir(), APP_CONFIG_FILE_NAME);
|
2012-11-28 20:26:49 +00:00
|
|
|
f = boinc_fopen(path, "r");
|
2013-06-17 19:48:14 +00:00
|
|
|
if (!f) {
|
|
|
|
clear_app_config(p);
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 20:26:49 +00:00
|
|
|
msg_printf(p, MSG_INFO,
|
|
|
|
"Found %s", APP_CONFIG_FILE_NAME
|
|
|
|
);
|
2012-12-12 19:45:49 +00:00
|
|
|
int retval = p->app_configs.parse_file(f, p);
|
2012-11-28 20:26:49 +00:00
|
|
|
if (!retval) {
|
2013-05-19 17:02:00 +00:00
|
|
|
p->app_configs.config_app_versions(p, true);
|
2012-11-28 20:26:49 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|