codes-workload.c 10.4 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

7
#include <assert.h>
8 9 10 11 12

#include "ross.h"
#include "codes/codes-workload.h"
#include "codes-workload-method.h"

13
/* list of available methods.  These are statically compiled for now, but we
14 15
 * could make generators optional via autoconf tests etc. if needed
 */
16
extern struct codes_workload_method test_workload_method;
17
extern struct codes_workload_method iolang_workload_method;
18 19 20
#ifdef USE_DUMPI
extern struct codes_workload_method dumpi_trace_workload_method;
#endif
21
#ifdef USE_DARSHAN
22
extern struct codes_workload_method darshan_io_workload_method;
23
#endif
24 25 26
#ifdef USE_RECORDER
extern struct codes_workload_method recorder_io_workload_method;
#endif
27

28
static struct codes_workload_method *method_array[] =
29 30
{
    &test_workload_method,
31
    &iolang_workload_method,
32 33 34
#ifdef USE_DUMPI
    &dumpi_trace_workload_method,
#endif
35 36
#ifdef USE_DARSHAN
    &darshan_io_workload_method,
37 38 39
#endif
#ifdef USE_RECORDER
    &recorder_io_workload_method,
40 41
#endif
    NULL};
42

Philip Carns's avatar
Philip Carns committed
43 44 45 46 47
/* This shim layer is responsible for queueing up reversed operations and
 * re-issuing them so that the underlying workload generator method doesn't
 * have to worry about reverse events.
 *
 * NOTE: we could make this faster with a smarter data structure.  For now
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
 * we just have a linked list of rank_queue structs, one per rank that has
 * opened the workload.  We then have a linked list off of each of those
 * to hold a lifo queue of operations that have been reversed for that rank.
 */

/* holds an operation that has been reversed */
struct rc_op
{
    struct codes_workload_op op;
    struct rc_op* next;
};

/* tracks lifo queue of reversed operations for a given rank */
struct rank_queue
{
63
    int app;
64 65 66 67 68 69 70
    int rank;
    struct rc_op *lifo;
    struct rank_queue *next;
};

static struct rank_queue *ranks = NULL;

71 72 73 74 75
int codes_workload_load(
        const char* type,
        const char* params,
        int app_id,
        int rank)
76
{
77 78
    int i;
    int ret;
79
    struct rank_queue *tmp;
80 81 82 83 84

    for(i=0; method_array[i] != NULL; i++)
    {
        if(strcmp(method_array[i]->method_name, type) == 0)
        {
85
            /* load appropriate workload generator */
86
            ret = method_array[i]->codes_workload_load(params, app_id, rank);
87 88 89 90
            if(ret < 0)
            {
                return(-1);
            }
91 92 93 94 95

            /* are we tracking information for this rank yet? */
            tmp = ranks;
            while(tmp)
            {
96
                if(tmp->rank == rank && tmp->app == app_id)
97 98 99 100 101
                    break;
                tmp = tmp->next;
            }
            if(tmp == NULL)
            {
102
                tmp = (struct rank_queue*)malloc(sizeof(*tmp));
103
                assert(tmp);
104
                tmp->app  = app_id;
105 106 107 108 109 110
                tmp->rank = rank;
                tmp->lifo = NULL;
                tmp->next = ranks;
                ranks = tmp;
            }

111 112 113 114 115
            return(i);
        }
    }

    fprintf(stderr, "Error: failed to find workload generator %s\n", type);
116 117 118
    return(-1);
}

119 120 121 122 123
void codes_workload_get_next(
        int wkld_id,
        int app_id,
        int rank,
        struct codes_workload_op *op)
124
{
125 126 127 128 129 130 131 132 133
    struct rank_queue *tmp;
    struct rc_op *tmp_op;

    /* first look to see if we have a reversed operation that we can
     * re-issue
     */
    tmp = ranks;
    while(tmp)
    {
134
        if(tmp->rank == rank && tmp->app == app_id)
135 136 137 138 139 140 141
            break;
        tmp = tmp->next;
    }
    assert(tmp);
    if(tmp->lifo)
    {
        tmp_op = tmp->lifo;
142
        tmp->lifo = tmp_op->next;
143 144 145 146 147 148 149

        *op = tmp_op->op;
        free(tmp_op);
        return;
    }

    /* ask generator for the next operation */
150
    method_array[wkld_id]->codes_workload_get_next(app_id, rank, op);
151

152 153 154
    return;
}

155 156 157 158 159
void codes_workload_get_next_rc(
        int wkld_id,
        int app_id,
        int rank,
        const struct codes_workload_op *op)
160
{
161 162 163 164 165 166
    struct rank_queue *tmp;
    struct rc_op *tmp_op;

    tmp = ranks;
    while(tmp)
    {
167
        if(tmp->rank == rank && tmp->app == app_id)
168 169 170 171 172
            break;
        tmp = tmp->next;
    }
    assert(tmp);

173
    tmp_op = (struct rc_op*)malloc(sizeof(*tmp_op));
174 175 176 177
    assert(tmp_op);
    tmp_op->op = *op;
    tmp_op->next = tmp->lifo;
    tmp->lifo = tmp_op;
178

179 180 181
    return;
}

182 183 184 185
int codes_workload_get_rank_cnt(
        const char* type,
        const char* params,
        int app_id)
186
{
187 188 189 190 191 192 193
    int i;
    int rank_cnt;

    for(i=0; method_array[i] != NULL; i++)
    {
        if(strcmp(method_array[i]->method_name, type) == 0)
        {
194 195
            rank_cnt =
                method_array[i]->codes_workload_get_rank_cnt(params, app_id);
196 197 198 199 200 201 202
            assert(rank_cnt > 0);
            return(rank_cnt);
        }
    }

    fprintf(stderr, "Error: failed to find workload generator %s\n", type);
    return(-1);
203 204
}

205 206 207 208 209 210
void codes_workload_print_op(
        FILE *f,
        struct codes_workload_op *op,
        int app_id,
        int rank)
{
211 212
    switch(op->op_type){
        case CODES_WK_END:
213
            fprintf(f, "op: app:%d rank:%d type:end\n", app_id, rank);
214 215
            break;
        case CODES_WK_DELAY:
216
            fprintf(f, "op: app:%d rank:%d type:delay seconds:%lf\n",
217
                    app_id, rank, op->u.delay.seconds);
218 219
            break;
        case CODES_WK_BARRIER:
220
            fprintf(f, "op: app:%d rank:%d type:barrier count:%d root:%d\n",
221
                    app_id, rank, op->u.barrier.count, op->u.barrier.root);
222 223
            break;
        case CODES_WK_OPEN:
224
            fprintf(f, "op: app:%d rank:%d type:open file_id:%lu flag:%d\n",
225
                    app_id, rank, op->u.open.file_id, op->u.open.create_flag);
226 227
            break;
        case CODES_WK_CLOSE:
228
            fprintf(f, "op: app:%d rank:%d type:close file_id:%lu\n",
229
                    app_id, rank, op->u.close.file_id);
230 231
            break;
        case CODES_WK_WRITE:
232
            fprintf(f, "op: app:%d rank:%d type:write "
233
                       "file_id:%lu off:%lu size:%lu\n",
234
                    app_id, rank, op->u.write.file_id, op->u.write.offset,
235 236 237
                    op->u.write.size);
            break;
        case CODES_WK_READ:
238
            fprintf(f, "op: app:%d rank:%d type:read "
239
                       "file_id:%lu off:%lu size:%lu\n",
240
                    app_id, rank, op->u.read.file_id, op->u.read.offset,
241 242
                    op->u.read.size);
            break;
243
        case CODES_WK_SEND:
244
            fprintf(f, "op: app:%d rank:%d type:send "
245
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
246
                    app_id, rank,
247 248 249 250 251
                    op->u.send.source_rank, op->u.send.dest_rank,
                    op->u.send.num_bytes, op->u.send.data_type,
                    op->u.send.count, op->u.send.tag);
            break;
        case CODES_WK_RECV:
252
            fprintf(f, "op: app:%d rank:%d type:recv "
253
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
254
                    app_id, rank,
255 256 257 258 259
                    op->u.recv.source_rank, op->u.recv.dest_rank,
                    op->u.recv.num_bytes, op->u.recv.data_type,
                    op->u.recv.count, op->u.recv.tag);
            break;
        case CODES_WK_ISEND:
260
            fprintf(f, "op: app:%d rank:%d type:isend "
261
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
262
                    app_id, rank,
263 264 265 266 267
                    op->u.send.source_rank, op->u.send.dest_rank,
                    op->u.send.num_bytes, op->u.send.data_type,
                    op->u.send.count, op->u.send.tag);
            break;
        case CODES_WK_IRECV:
268
            fprintf(f, "op: app:%d rank:%d type:irecv "
269
                    "src:%d dst:%d bytes:%d type:%d count:%d tag:%d\n",
270
                    app_id, rank,
271 272 273 274 275
                    op->u.recv.source_rank, op->u.recv.dest_rank,
                    op->u.recv.num_bytes, op->u.recv.data_type,
                    op->u.recv.count, op->u.recv.tag);
            break;
        case CODES_WK_BCAST:
276
            fprintf(f, "op: app:%d rank:%d type:bcast "
277
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
278 279
            break;
        case CODES_WK_ALLGATHER:
280
            fprintf(f, "op: app:%d rank:%d type:allgather "
281
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
282 283
            break;
        case CODES_WK_ALLGATHERV:
284
            fprintf(f, "op: app:%d rank:%d type:allgatherv "
285
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
286 287
            break;
        case CODES_WK_ALLTOALL:
288
            fprintf(f, "op: app:%d rank:%d type:alltoall "
289
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
290 291
            break;
        case CODES_WK_ALLTOALLV:
292
            fprintf(f, "op: app:%d rank:%d type:alltoallv "
293
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
294 295
            break;
        case CODES_WK_REDUCE:
296
            fprintf(f, "op: app:%d rank:%d type:reduce "
297
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
298 299
            break;
        case CODES_WK_ALLREDUCE:
300
            fprintf(f, "op: app:%d rank:%d type:allreduce "
301
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
302 303
            break;
        case CODES_WK_COL:
304 305 306 307 308
            fprintf(f, "op: app:%d rank:%d type:collective "
                    "bytes:%d\n", app_id, rank, op->u.collective.num_bytes);
            break;
        case CODES_WK_WAITALL:
            fprintf(f, "op: app:%d rank:%d type:waitall "
309
                    "num reqs: :%d\n", app_id, rank, op->u.waits.count);
310 311 312
            break;
        case CODES_WK_WAIT:
            fprintf(f, "op: app:%d rank:%d type:wait "
313
                    "num reqs: :%d\n", app_id, rank, op->u.wait.req_id);
314 315 316
            break;
        case CODES_WK_WAITSOME:
            fprintf(f, "op: app:%d rank:%d type:waitsome "
317
                    "num reqs: :%d\n", app_id, rank, op->u.waits.count);
318 319 320
            break;
        case CODES_WK_WAITANY:
            fprintf(f, "op: app:%d rank:%d type:waitany "
321
                    "num reqs: :%d\n", app_id, rank, op->u.waits.count);
322
            break;
Jonathan Jenkins's avatar
Jonathan Jenkins committed
323 324
        case CODES_WK_IGNORE:
            break;
325
        default:
Jonathan Jenkins's avatar
Jonathan Jenkins committed
326 327 328
            fprintf(stderr,
                    "%s:%d: codes_workload_print_op: unrecognized workload type "
                    "(op code %d)\n", __FILE__, __LINE__, op->op_type);
329 330 331
    }
}

332 333 334 335
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
336
 *  indent-tabs-mode: nil
337 338 339 340
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */