6
#include "error_numbers.h"
7
#include "sched_msgs.h"
11
int HR_INFO::write_file() {
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]);
26
int HR_INFO::read_file() {
28
FILE* f = fopen(HR_INFO_FILENAME, "r");
29
if (!f) return ERR_FOPEN;
33
for (i=1; i<HR_NTYPES; i++) {
34
char* p = fgets(buf, sizeof(buf), f);
36
fprintf(stderr, "missing delimeter line in HR info");
39
for (j=0; j<hr_nclasses[i]; j++) {
40
char* p = fgets(buf, sizeof(buf), f);
42
fprintf(stderr, "missing data line in HR info");
45
int n = sscanf(buf, "%d %lf", &jj, &x);
47
fprintf(stderr, "bad line %s in HR info: %d; %d != %d\n", buf, n, j, jj);
50
rac_per_class[i][j] = x;
57
void HR_INFO::init() {
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));
66
void HR_INFO::scan_db() {
72
retval = host.enumerate("where expavg_credit>1");
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);
80
int hrc = hr_class(host, i);
81
//printf("type %d: class %d\n", i, hrc);
83
rac_per_class[i][hrc] += host.expavg_credit;
86
if (retval != ERR_DB_NOT_FOUND) {
87
fprintf(stderr, "host enum: %d", retval);
92
void HR_INFO::allocate(int total_slots) {
95
double weight_total = 0;
96
for (i=1; i<HR_NTYPES; i++) {
97
weight_total += type_weights[i];
100
// decide how many slots to allocate to each HR type
102
for (i=1; i<HR_NTYPES; i++) {
103
slots_per_type[i] = (int)(total_slots*type_weights[i]/weight_total);
106
// within each type, decide how many slots to allocate to each class
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]
114
log_messages.printf(MSG_DEBUG,
115
"type %d uncommitted: allocating %d slots\n", i, nuncom
118
double total_rac = 0;
119
for (j=1; j<hr_nclasses[i]; j++) {
120
total_rac += rac_per_class[i][j];
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);
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
133
log_messages.printf(MSG_DEBUG,
134
"type %d class %d: allocating %d slots\n", i, j, n
138
for (j=0; j<hr_nclasses[i]; j++) {
144
// Decide if job of the given HR type and class should be added to array,
145
// and if to update counts
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
154
cur_slots[hrt][hrc]++;
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]
162
for (int hc=0; hc<hr_nclasses[ht]; hc++) {
163
if (hc && rac_per_class[ht][hc] == 0) continue;
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]