2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-09-26 18:11:06 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-01 23:23:20 +00:00
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-01 23:23:20 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-01 23:23:20 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-09-26 18:11:06 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cassert>
|
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"
|
2002-05-30 07:14:21 +00:00
|
|
|
|
2004-07-03 21:38:22 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2002-05-30 07:14:21 +00:00
|
|
|
void SCHED_SHMEM::init() {
|
|
|
|
memset(this, 0, sizeof(SCHED_SHMEM));
|
|
|
|
ss_size = sizeof(SCHED_SHMEM);
|
|
|
|
platform_size = sizeof(PLATFORM);
|
|
|
|
app_size = sizeof(APP);
|
|
|
|
app_version_size = sizeof(APP_VERSION);
|
2004-09-24 20:17:52 +00:00
|
|
|
core_version_size = sizeof(CORE_VERSION);
|
2002-05-30 07:14:21 +00:00
|
|
|
wu_result_size = sizeof(WU_RESULT);
|
|
|
|
max_platforms = MAX_PLATFORMS;
|
|
|
|
max_apps = MAX_APPS;
|
|
|
|
max_app_versions = MAX_APP_VERSIONS;
|
2004-09-24 20:17:52 +00:00
|
|
|
max_core_versions = MAX_CORE_VERSIONS;
|
2002-05-30 07:14:21 +00:00
|
|
|
max_wu_results = MAX_WU_RESULTS;
|
|
|
|
nwu_results = MAX_WU_RESULTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SCHED_SHMEM::verify() {
|
2003-10-21 04:06:55 +00:00
|
|
|
if (ss_size != sizeof(SCHED_SHMEM)) return ERR_SCHED_SHMEM;
|
|
|
|
if (platform_size != sizeof(PLATFORM)) return ERR_SCHED_SHMEM;
|
|
|
|
if (app_size != sizeof(APP)) return ERR_SCHED_SHMEM;
|
|
|
|
if (app_version_size != sizeof(APP_VERSION)) return ERR_SCHED_SHMEM;
|
2004-09-24 20:17:52 +00:00
|
|
|
if (core_version_size != sizeof(CORE_VERSION)) return ERR_SCHED_SHMEM;
|
2003-10-21 04:06:55 +00:00
|
|
|
if (wu_result_size != sizeof(WU_RESULT)) return ERR_SCHED_SHMEM;
|
|
|
|
if (max_platforms != MAX_PLATFORMS) return ERR_SCHED_SHMEM;
|
|
|
|
if (max_apps != MAX_APPS) return ERR_SCHED_SHMEM;
|
|
|
|
if (max_app_versions != MAX_APP_VERSIONS) return ERR_SCHED_SHMEM;
|
2004-09-24 20:17:52 +00:00
|
|
|
if (max_core_versions != MAX_CORE_VERSIONS) return ERR_SCHED_SHMEM;
|
2003-10-21 04:06:55 +00:00
|
|
|
if (max_wu_results != MAX_WU_RESULTS) return ERR_SCHED_SHMEM;
|
2002-05-30 07:14:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void overflow(char* table) {
|
2002-07-11 01:09:53 +00:00
|
|
|
assert(table!=NULL);
|
2002-05-30 07:14:21 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"The SCHED_SHMEM structure is too small for table %s.\n"
|
|
|
|
"Increase the size and restart feeder and fcgi.\n",
|
|
|
|
table
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-06-17 23:23:13 +00:00
|
|
|
bool SCHED_SHMEM::have_app(int appid) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<napps; i++) {
|
|
|
|
if (apps[i].id == appid) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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;
|
2004-09-24 20:17:52 +00:00
|
|
|
DB_CORE_VERSION core_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;
|
|
|
|
if (n == MAX_PLATFORMS) overflow("platforms");
|
|
|
|
}
|
|
|
|
nplatforms = n;
|
|
|
|
|
|
|
|
n = 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;
|
|
|
|
if (n == MAX_APPS) overflow("apps");
|
|
|
|
}
|
|
|
|
napps = n;
|
|
|
|
|
|
|
|
n = 0;
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!app_version.enumerate()) {
|
2004-07-13 10:36:18 +00:00
|
|
|
if (app_version.version_num/100 != BOINC_MAJOR_VERSION) continue;
|
2003-12-24 21:49:35 +00:00
|
|
|
if (app_version.deprecated) continue;
|
2004-06-17 23:23:13 +00:00
|
|
|
if (!have_app(app_version.appid)) continue;
|
2002-05-30 07:14:21 +00:00
|
|
|
app_versions[n++] = app_version;
|
|
|
|
if (n == MAX_APP_VERSIONS) overflow("app_versions");
|
|
|
|
}
|
|
|
|
napp_versions = n;
|
2004-09-24 20:17:52 +00:00
|
|
|
|
|
|
|
n = 0;
|
|
|
|
while (!core_version.enumerate()) {
|
|
|
|
if (core_version.version_num/100 != BOINC_MAJOR_VERSION) continue;
|
|
|
|
if (core_version.deprecated) continue;
|
|
|
|
core_versions[n++] = core_version;
|
|
|
|
if (n == MAX_CORE_VERSIONS) overflow("core_versions");
|
|
|
|
}
|
|
|
|
ncore_versions = n;
|
2002-05-30 07:14:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLATFORM* SCHED_SHMEM::lookup_platform(char* name) {
|
|
|
|
int i;
|
2002-07-11 01:09:53 +00:00
|
|
|
assert(name!=NULL);
|
2002-05-30 07:14:21 +00:00
|
|
|
for (i=0; i<nplatforms; i++) {
|
|
|
|
if (!strcmp(platforms[i].name, name)) {
|
|
|
|
return &platforms[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
APP* SCHED_SHMEM::lookup_app(int id) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<napps; i++) {
|
|
|
|
if (apps[i].id == id) {
|
|
|
|
return &apps[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
assert(min_version>=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
|
|
|
|
2004-09-24 20:17:52 +00:00
|
|
|
// find the latest core version for a given platform
|
|
|
|
//
|
|
|
|
CORE_VERSION* SCHED_SHMEM::lookup_core_version(int platformid) {
|
|
|
|
CORE_VERSION* cvp, *best=0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<ncore_versions; i++) {
|
|
|
|
cvp = &core_versions[i];
|
|
|
|
if (!best || cvp->version_num > best->version_num) {
|
|
|
|
best = cvp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|