1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2010 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
26
#include "error_numbers.h"
29
#include "sched_msgs.h"
33
struct RSC_JOB_LIMIT {
34
int base_limit; // 0 means no limit
35
int scaled_limit; // the actual limit
37
bool per_proc; // if true, scaled limit is limit*nprocs
39
int parse(XML_PARSER&, const char* end_tag);
41
inline void reset(int nprocs) {
44
scaled_limit = base_limit*nprocs;
46
scaled_limit = base_limit;
50
inline bool exceeded() {
51
return (scaled_limit && njobs >= scaled_limit);
54
inline void register_job() {
58
inline bool any_limit() {
59
return (base_limit != 0);
62
void print_log(const char*);
71
int parse(XML_PARSER&, const char* end_tag);
73
inline void reset(HOST& h, COPROCS& c) {
79
inline bool exceeded(bool is_gpu) {
80
if (total.exceeded()) return true;
82
if (gpu.exceeded()) return true;
84
if (cpu.exceeded()) return true;
89
inline void register_job(bool is_gpu) {
98
inline bool any_limit() {
99
return total.any_limit() || cpu.any_limit() || gpu.any_limit();
106
JOB_LIMIT project_limits; // project-wide limits
107
vector<JOB_LIMIT> app_limits; // per-app limits
109
int parse(XML_PARSER&, const char* end_tag);
112
// called at start of each request
114
inline void reset(HOST& h, COPROCS& c) {
115
project_limits.reset(h, c);
116
for (unsigned int i=0; i<app_limits.size(); i++) {
117
app_limits[i].reset(h, c);
121
inline JOB_LIMIT* lookup_app(char* name) {
122
for (unsigned int i=0; i<app_limits.size(); i++) {
123
JOB_LIMIT* jlp = &app_limits[i];
124
if (!strcmp(name, jlp->app_name)) {
131
inline bool exceeded(APP* app, bool is_gpu) {
132
if (project_limits.exceeded(is_gpu)) return true;
134
JOB_LIMIT* jlp = lookup_app(app->name);
136
if (jlp->exceeded(is_gpu)) return true;
142
inline void register_job(APP* app, bool is_gpu) {
143
project_limits.register_job(is_gpu);
145
JOB_LIMIT* jlp = lookup_app(app->name);
147
jlp->register_job(is_gpu);