~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to sched/sched_limit.h

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of BOINC.
 
2
// http://boinc.berkeley.edu
 
3
// Copyright (C) 2010 University of California
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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/>.
 
17
 
 
18
#ifndef _SCHED_LIMIT_
 
19
#define _SCHED_LIMIT_
 
20
 
 
21
#include <vector>
 
22
 
 
23
#include "boinc_db.h"
 
24
 
 
25
#include "hostinfo.h"
 
26
#include "error_numbers.h"
 
27
#include "parse.h"
 
28
 
 
29
#include "sched_msgs.h"
 
30
 
 
31
using std::vector;
 
32
 
 
33
struct RSC_JOB_LIMIT {
 
34
    int base_limit;     // 0 means no limit
 
35
    int scaled_limit;   // the actual limit
 
36
    int njobs;
 
37
    bool per_proc;      // if true, scaled limit is limit*nprocs
 
38
 
 
39
    int parse(XML_PARSER&, const char* end_tag);
 
40
 
 
41
    inline void reset(int nprocs) {
 
42
        njobs = 0;
 
43
        if (per_proc) {
 
44
            scaled_limit = base_limit*nprocs;
 
45
        } else {
 
46
            scaled_limit = base_limit;
 
47
        }
 
48
    }
 
49
 
 
50
    inline bool exceeded() {
 
51
        return (scaled_limit && njobs >= scaled_limit);
 
52
    }
 
53
 
 
54
    inline void register_job() {
 
55
        njobs++;
 
56
    }
 
57
 
 
58
    inline bool any_limit() {
 
59
        return (base_limit != 0);
 
60
    }
 
61
 
 
62
    void print_log(const char*);
 
63
};
 
64
 
 
65
struct JOB_LIMIT {
 
66
    char app_name[256];
 
67
    RSC_JOB_LIMIT total;
 
68
    RSC_JOB_LIMIT cpu;
 
69
    RSC_JOB_LIMIT gpu;
 
70
 
 
71
    int parse(XML_PARSER&, const char* end_tag);
 
72
 
 
73
    inline void reset(HOST& h, COPROCS& c) {
 
74
        total.reset(1);
 
75
        cpu.reset(h.p_ncpus);
 
76
        gpu.reset(c.ndevs());
 
77
    }
 
78
 
 
79
    inline bool exceeded(bool is_gpu) {
 
80
        if (total.exceeded()) return true;
 
81
        if (is_gpu) {
 
82
            if (gpu.exceeded()) return true;
 
83
        } else {
 
84
            if (cpu.exceeded()) return true;
 
85
        }
 
86
        return false;
 
87
    }
 
88
 
 
89
    inline void register_job(bool is_gpu) {
 
90
        total.register_job();
 
91
        if (is_gpu) {
 
92
            gpu.register_job();
 
93
        } else {
 
94
            cpu.register_job();
 
95
        }
 
96
    }
 
97
 
 
98
    inline bool any_limit() {
 
99
        return total.any_limit() || cpu.any_limit() || gpu.any_limit();
 
100
    }
 
101
 
 
102
    void print_log();
 
103
};
 
104
 
 
105
struct JOB_LIMITS {
 
106
    JOB_LIMIT project_limits;      // project-wide limits
 
107
    vector<JOB_LIMIT> app_limits;  // per-app limits
 
108
 
 
109
    int parse(XML_PARSER&, const char* end_tag);
 
110
    void print_log();
 
111
 
 
112
    // called at start of each request
 
113
    //
 
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);
 
118
        }
 
119
    }
 
120
 
 
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)) {
 
125
                return jlp;
 
126
            }
 
127
        }
 
128
        return NULL;
 
129
    }
 
130
 
 
131
    inline bool exceeded(APP* app, bool is_gpu) {
 
132
        if (project_limits.exceeded(is_gpu)) return true;
 
133
        if (app) {
 
134
            JOB_LIMIT* jlp = lookup_app(app->name);
 
135
            if (jlp) {
 
136
                if (jlp->exceeded(is_gpu)) return true;
 
137
            }
 
138
        }
 
139
        return false;
 
140
    }
 
141
 
 
142
    inline void register_job(APP* app, bool is_gpu) {
 
143
        project_limits.register_job(is_gpu);
 
144
        if (app) {
 
145
            JOB_LIMIT* jlp = lookup_app(app->name);
 
146
            if (jlp) {
 
147
                jlp->register_job(is_gpu);
 
148
            }
 
149
        }
 
150
    }
 
151
};
 
152
 
 
153
#endif