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-01 23:23:20 +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-01 23:23:20 +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-09-26 18:11:06 +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.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-09-26 18:11:06 +00:00
|
|
|
|
|
|
|
// SCHED_SHMEM is the structure of a chunk of memory shared between
|
|
|
|
// the feeder (which reads from the database)
|
|
|
|
// and instances of the scheduling server
|
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2002-05-30 07:14:21 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "error_numbers.h"
|
2002-05-30 07:14:21 +00:00
|
|
|
|
|
|
|
#include "sched_shmem.h"
|
2003-08-01 23:23:20 +00:00
|
|
|
#include "sched_util.h"
|
2005-01-27 18:44:32 +00:00
|
|
|
#include "sched_msgs.h"
|
2002-05-30 07:14:21 +00:00
|
|
|
|
2004-07-03 21:38:22 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2007-05-29 21:45:01 +00:00
|
|
|
void SCHED_SHMEM::init(int nwu_results) {
|
|
|
|
int size = sizeof(SCHED_SHMEM) + nwu_results*sizeof(WU_RESULT);
|
|
|
|
memset(this, 0, size);
|
|
|
|
ss_size = size;
|
2002-05-30 07:14:21 +00:00
|
|
|
platform_size = sizeof(PLATFORM);
|
|
|
|
app_size = sizeof(APP);
|
|
|
|
app_version_size = sizeof(APP_VERSION);
|
|
|
|
wu_result_size = sizeof(WU_RESULT);
|
|
|
|
max_platforms = MAX_PLATFORMS;
|
|
|
|
max_apps = MAX_APPS;
|
|
|
|
max_app_versions = MAX_APP_VERSIONS;
|
2007-05-29 21:45:01 +00:00
|
|
|
max_wu_results = nwu_results;
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 04:34:45 +00:00
|
|
|
static int error_return(const char* p) {
|
2005-05-01 04:35:22 +00:00
|
|
|
fprintf(stderr, "Error in structure: %s\n", p);
|
|
|
|
return ERR_SCHED_SHMEM;
|
|
|
|
}
|
|
|
|
|
2002-05-30 07:14:21 +00:00
|
|
|
int SCHED_SHMEM::verify() {
|
2007-05-29 21:45:01 +00:00
|
|
|
int size = sizeof(SCHED_SHMEM) + max_wu_results*sizeof(WU_RESULT);
|
|
|
|
if (ss_size != size) return error_return("shmem");
|
2005-05-01 04:35:22 +00:00
|
|
|
if (platform_size != sizeof(PLATFORM)) return error_return("platform");
|
|
|
|
if (app_size != sizeof(APP)) return error_return("app");
|
|
|
|
if (app_version_size != sizeof(APP_VERSION)) return error_return("app_version");
|
|
|
|
if (wu_result_size != sizeof(WU_RESULT)) return error_return("wu_result");
|
|
|
|
if (max_platforms != MAX_PLATFORMS) return error_return("max platform");
|
|
|
|
if (max_apps != MAX_APPS) return error_return("max apps");
|
|
|
|
if (max_app_versions != MAX_APP_VERSIONS) return error_return("max app version");
|
2002-05-30 07:14:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
static void overflow(const char* table, const char* param_name) {
|
2005-01-27 18:44:32 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2005-01-27 18:44:32 +00:00
|
|
|
"The SCHED_SHMEM structure is too small for the %s table.\n"
|
|
|
|
"Either increase the %s parameter in sched_shmem.h and recompile,\n"
|
|
|
|
"or prune old rows from the table.\n"
|
|
|
|
"Then restart the project.\n",
|
|
|
|
table, param_name
|
2002-05-30 07:14:21 +00:00
|
|
|
);
|
2005-01-27 18:44:32 +00:00
|
|
|
exit(1);
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SCHED_SHMEM::scan_tables() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_PLATFORM platform;
|
|
|
|
DB_APP app;
|
|
|
|
DB_APP_VERSION app_version;
|
2002-05-30 07:14:21 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
n = 0;
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!platform.enumerate()) {
|
2003-12-11 19:05:52 +00:00
|
|
|
if (platform.deprecated) continue;
|
2002-05-30 07:14:21 +00:00
|
|
|
platforms[n++] = platform;
|
2005-01-27 18:44:32 +00:00
|
|
|
if (n == MAX_PLATFORMS) {
|
|
|
|
overflow("platforms", "MAX_PLATFORMS");
|
|
|
|
}
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
nplatforms = n;
|
|
|
|
|
|
|
|
n = 0;
|
2006-07-11 21:49:20 +00:00
|
|
|
app_weights = 0;
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!app.enumerate()) {
|
2004-06-17 23:23:13 +00:00
|
|
|
if (app.deprecated) continue;
|
2002-05-30 07:14:21 +00:00
|
|
|
apps[n++] = app;
|
2005-01-27 18:44:32 +00:00
|
|
|
if (n == MAX_APPS) {
|
|
|
|
overflow("apps", "MAX_APPS");
|
|
|
|
}
|
2006-07-11 21:49:20 +00:00
|
|
|
app_weights += app.weight;
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
napps = n;
|
|
|
|
|
|
|
|
n = 0;
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!app_version.enumerate()) {
|
2003-12-24 21:49:35 +00:00
|
|
|
if (app_version.deprecated) continue;
|
2007-05-02 23:14:00 +00:00
|
|
|
if (!lookup_app(app_version.appid)) continue;
|
|
|
|
PLATFORM* pp= lookup_platform_id(app_version.platformid);
|
|
|
|
if (!pp) {
|
|
|
|
fprintf(stderr, "app version %d refers to nonexistent platform %d",
|
|
|
|
app_version.id, app_version.platformid
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2002-05-30 07:14:21 +00:00
|
|
|
app_versions[n++] = app_version;
|
2005-01-27 18:44:32 +00:00
|
|
|
if (n == MAX_APP_VERSIONS) {
|
|
|
|
overflow("app_versions", "MAX_APP_VERSIONS");
|
|
|
|
}
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
napp_versions = n;
|
2004-09-24 20:17:52 +00:00
|
|
|
|
2002-05-30 07:14:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLATFORM* SCHED_SHMEM::lookup_platform(char* name) {
|
2007-05-02 23:14:00 +00:00
|
|
|
for (int i=0; i<nplatforms; i++) {
|
2002-05-30 07:14:21 +00:00
|
|
|
if (!strcmp(platforms[i].name, name)) {
|
|
|
|
return &platforms[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-02 23:14:00 +00:00
|
|
|
PLATFORM* SCHED_SHMEM::lookup_platform_id(int id) {
|
|
|
|
for (int i=0; i<nplatforms; i++) {
|
|
|
|
if (platforms[i].id == id) return &platforms[i];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-05-30 07:14:21 +00:00
|
|
|
|
2007-05-02 23:14:00 +00:00
|
|
|
APP* SCHED_SHMEM::lookup_app(int id) {
|
|
|
|
for (int i=0; i<napps; i++) {
|
|
|
|
if (apps[i].id == id) return &apps[i];
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-24 20:17:52 +00:00
|
|
|
// find the latest app version for a given platform
|
2002-07-29 00:39:45 +00:00
|
|
|
//
|
2002-05-30 07:14:21 +00:00
|
|
|
APP_VERSION* SCHED_SHMEM::lookup_app_version(
|
2002-07-29 00:39:45 +00:00
|
|
|
int appid, int platformid, int min_version
|
2002-05-30 07:14:21 +00:00
|
|
|
) {
|
2002-07-29 00:39:45 +00:00
|
|
|
int i, best_version=-1;
|
|
|
|
APP_VERSION* avp, *best_avp = 0;
|
2002-05-30 07:14:21 +00:00
|
|
|
for (i=0; i<napp_versions; i++) {
|
|
|
|
avp = &app_versions[i];
|
2002-07-29 00:39:45 +00:00
|
|
|
if (avp->appid == appid && avp->platformid == platformid) {
|
|
|
|
if (avp->version_num >= min_version && avp->version_num > best_version) {
|
|
|
|
best_avp = avp;
|
|
|
|
best_version = avp->version_num;
|
|
|
|
}
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-01 23:23:20 +00:00
|
|
|
|
2002-07-29 00:39:45 +00:00
|
|
|
return best_avp;
|
2002-05-30 07:14:21 +00:00
|
|
|
}
|
2004-07-04 18:55:31 +00:00
|
|
|
|
2006-01-19 21:46:25 +00:00
|
|
|
// see if there's any work.
|
|
|
|
// If there is, reserve it for this process
|
|
|
|
// (if we don't do this, there's a race condition where lots
|
|
|
|
// of servers try to get a single work item)
|
|
|
|
//
|
2004-07-24 00:09:28 +00:00
|
|
|
bool SCHED_SHMEM::no_work(int pid) {
|
2004-07-04 18:55:31 +00:00
|
|
|
int i;
|
|
|
|
|
2004-07-24 00:09:28 +00:00
|
|
|
if (!ready) return true;
|
2004-07-04 18:55:31 +00:00
|
|
|
for (i=0; i<max_wu_results; i++) {
|
2004-07-24 00:09:28 +00:00
|
|
|
if (wu_results[i].state == WR_STATE_PRESENT) {
|
|
|
|
wu_results[i].state = pid;
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-04 18:55:31 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2004-07-24 00:09:28 +00:00
|
|
|
|
|
|
|
void SCHED_SHMEM::restore_work(int pid) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<max_wu_results; i++) {
|
|
|
|
if (wu_results[i].state == pid) {
|
|
|
|
wu_results[i].state = WR_STATE_PRESENT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2007-07-05 23:06:18 +00:00
|
|
|
void SCHED_SHMEM::show(FILE* f) {
|
|
|
|
fprintf(f,
|
|
|
|
"key:\n"
|
|
|
|
"ap: app ID\n"
|
|
|
|
"ic: infeasible count\n"
|
|
|
|
"wu: workunit ID\n"
|
|
|
|
"rs: result ID\n"
|
|
|
|
"hr: HR class\n"
|
|
|
|
"nr: need reliable\n"
|
|
|
|
);
|
|
|
|
fprintf(f, "ready: %d\n", ready);
|
|
|
|
fprintf(f, "max_wu_results: %d\n", max_wu_results);
|
|
|
|
for (int i=0; i<max_wu_results; i++) {
|
|
|
|
WU_RESULT& wu_result = wu_results[i];
|
|
|
|
switch(wu_result.state) {
|
|
|
|
case WR_STATE_PRESENT:
|
|
|
|
fprintf(f, "%4d: ap %d ic %d wu %d rs %d hr %d nr %d\n",
|
|
|
|
i, wu_result.workunit.appid, wu_result.infeasible_count,
|
|
|
|
wu_result.workunit.id, wu_result.resultid,
|
|
|
|
wu_result.workunit.hr_class, wu_result.need_reliable
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case WR_STATE_EMPTY:
|
|
|
|
fprintf(f, "%4d: ---\n", i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(f, "%d: PID %d: result %d\n", i, wu_result.state, wu_result.resultid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_e548c94703 = "$Id$";
|