~ubuntu-branches/ubuntu/lucid/boinc/lucid

« back to all changes in this revision

Viewing changes to sched/hr_info.C

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas, Frank S. Thomas
  • Date: 2008-05-31 08:02:47 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080531080247-4ce890lp2rc768cr
Tags: 6.2.7-1
[ Frank S. Thomas ]
* New upstream release.
  - BOINC Manager: Redraw disk usage charts immediately after connecting to
    a (different) client. (closes: 463823)
* debian/copyright:
  - Added the instructions from debian/README.Debian-source about how
    repackaged BOINC tarballs can be reproduced because DevRef now
    recommends to put this here instead of in the afore-mentioned file.
  - Updated for the new release.
* Removed the obsolete debian/README.Debian-source.
* For consistency upstream renamed the core client and the command tool
  ("boinc_client" to "boinc" and "boinc_cmd" to "boinccmd"). Done the same
  in all packages and created symlinks with the old names for the binaries
  and man pages. Also added an entry in debian/boinc-client.NEWS explaining
  this change.
* debian/rules: Do not list Makefile.ins in the clean target individually,
  just remove all that can be found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#ifdef HAVE_MALLOC_H
 
3
#include <malloc.h>
 
4
#endif
 
5
 
 
6
#include "error_numbers.h"
 
7
#include "sched_msgs.h"
 
8
 
 
9
#include "hr_info.h"
 
10
 
 
11
int HR_INFO::write_file() {
 
12
    int i, j;
 
13
 
 
14
    FILE* f = fopen(HR_INFO_FILENAME, "w");
 
15
    if (!f) return ERR_FOPEN;
 
16
    for (i=1; i<HR_NTYPES; i++) {
 
17
        fprintf(f, "--------- %s ----------\n", hr_names[i]);
 
18
        for (j=0; j<hr_nclasses[i]; j++) {
 
19
            fprintf(f, "%d %f\n", j, rac_per_class[i][j]);
 
20
        }
 
21
    }
 
22
    fclose(f);
 
23
    return 0;
 
24
}
 
25
 
 
26
int HR_INFO::read_file() {
 
27
    char buf[256];
 
28
    FILE* f = fopen(HR_INFO_FILENAME, "r");
 
29
    if (!f) return ERR_FOPEN;
 
30
    int i, j, jj;
 
31
    double x;
 
32
 
 
33
    for (i=1; i<HR_NTYPES; i++) {
 
34
        char* p = fgets(buf, sizeof(buf), f);
 
35
        if (!p) {
 
36
            fprintf(stderr, "missing delimeter line in HR info");
 
37
            exit(1);
 
38
        }
 
39
        for (j=0; j<hr_nclasses[i]; j++) {
 
40
            char* p = fgets(buf, sizeof(buf), f);
 
41
            if (!p) {
 
42
                fprintf(stderr, "missing data line in HR info");
 
43
                exit(1);
 
44
            }
 
45
            int n = sscanf(buf, "%d %lf", &jj, &x);
 
46
            if (n!=2 || j!=jj) {
 
47
                fprintf(stderr, "bad line %s in HR info: %d; %d != %d\n", buf, n, j, jj);
 
48
                exit(1);
 
49
            }
 
50
            rac_per_class[i][j] = x;
 
51
        }
 
52
    }
 
53
    fclose(f);
 
54
    return 0;
 
55
}
 
56
 
 
57
void HR_INFO::init() {
 
58
    int i;
 
59
    for (i=1; i<HR_NTYPES; i++) {
 
60
        rac_per_class[i] = (double*) calloc(hr_nclasses[i], sizeof(double));
 
61
        max_slots[i] = (int*) calloc(hr_nclasses[i], sizeof(int));
 
62
        cur_slots[i] = (int*) calloc(hr_nclasses[i], sizeof(int));
 
63
    }
 
64
}
 
65
 
 
66
void HR_INFO::scan_db() {
 
67
    DB_HOST host;
 
68
    int retval;
 
69
    int i;
 
70
 
 
71
    while (1) {
 
72
        retval = host.enumerate("where expavg_credit>1");
 
73
        if (retval) break;
 
74
        //printf("host %d: %s | %s | %s\n", host.id, host.os_name, host.p_vendor, host.p_model);
 
75
        for (i=1; i<HR_NTYPES; i++) {
 
76
            if (hr_unknown_platform_type(host, i)) {
 
77
                //printf("type %d: unknown\n", i);
 
78
                continue;
 
79
            }
 
80
            int hrc = hr_class(host, i);
 
81
            //printf("type %d: class %d\n", i, hrc);
 
82
            if (!hrc) continue;
 
83
            rac_per_class[i][hrc] += host.expavg_credit;
 
84
        }
 
85
    }
 
86
    if (retval != ERR_DB_NOT_FOUND) {
 
87
        fprintf(stderr, "host enum: %d", retval);
 
88
        exit(1);
 
89
    }
 
90
}
 
91
 
 
92
void HR_INFO::allocate(int total_slots) {
 
93
    int i, j;
 
94
 
 
95
    double weight_total = 0;
 
96
    for (i=1; i<HR_NTYPES; i++) {
 
97
        weight_total += type_weights[i];
 
98
    }
 
99
 
 
100
    // decide how many slots to allocate to each HR type
 
101
    //
 
102
    for (i=1; i<HR_NTYPES; i++) {
 
103
        slots_per_type[i] = (int)(total_slots*type_weights[i]/weight_total);
 
104
    }
 
105
 
 
106
    // within each type, decide how many slots to allocate to each class
 
107
    //
 
108
    for (i=1; i<HR_NTYPES; i++) {
 
109
        int nuncom = slots_per_type[i]/2;
 
110
        int ncom = slots_per_type[i] - nuncom;
 
111
        log_messages.printf(MSG_DEBUG,
 
112
            "type %d: %d total slots\n", i, slots_per_type[i]
 
113
        );
 
114
        log_messages.printf(MSG_DEBUG,
 
115
            "type %d uncommitted: allocating %d slots\n", i, nuncom
 
116
        );
 
117
 
 
118
        double total_rac = 0;
 
119
        for (j=1; j<hr_nclasses[i]; j++) {
 
120
            total_rac += rac_per_class[i][j];
 
121
        }
 
122
        max_slots[i][0] = nuncom;
 
123
        for (j=1; j<hr_nclasses[i]; j++) {
 
124
            int n = (int)(ncom*rac_per_class[i][j]/total_rac);
 
125
 
 
126
            // every HR class has a max of at least one,
 
127
            // so that new classes can get "on the board".
 
128
            // This means that the sum of the maxes can exceed the # of slots
 
129
            //
 
130
            if (n == 0) n = 1;
 
131
            max_slots[i][j] = n;
 
132
            if (n > 1) {
 
133
                log_messages.printf(MSG_DEBUG,
 
134
                    "type %d class %d: allocating %d slots\n", i, j, n
 
135
                );
 
136
            }
 
137
        }
 
138
        for (j=0; j<hr_nclasses[i]; j++) {
 
139
            cur_slots[i][j] = 0;
 
140
        }
 
141
    }
 
142
}
 
143
 
 
144
// Decide if job of the given HR type and class should be added to array,
 
145
// and if to update counts
 
146
//
 
147
bool HR_INFO::accept(int hrt, int hrc) {
 
148
    if (cur_slots[hrt][hrc] >= max_slots[hrt][hrc]) {
 
149
        log_messages.printf(MSG_DEBUG,
 
150
            "skipping job because HR class (%d, %d) full\n", hrt, hrc
 
151
        );
 
152
        return false;
 
153
    }
 
154
    cur_slots[hrt][hrc]++;
 
155
}
 
156
 
 
157
void HR_INFO::show(FILE* f) {
 
158
    for (int ht=1; ht<HR_NTYPES; ht++) {
 
159
        fprintf(f, "HR type %s: weight %f nslots %d\n",
 
160
            hr_names[ht], type_weights[ht], slots_per_type[ht]
 
161
        );
 
162
        for (int hc=0; hc<hr_nclasses[ht]; hc++) {
 
163
            if (hc && rac_per_class[ht][hc] == 0) continue;
 
164
            fprintf(f,
 
165
                "  class %d: rac %f max_slots %d cur_slots %d\n",
 
166
                hc, rac_per_class[ht][hc], max_slots[ht][hc], cur_slots[ht][hc]
 
167
            );
 
168
        }
 
169
    }
 
170
}