codes-workload.c 4.04 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 14 15 16
/* list of available methods.  These are statically compiled for now, but we
 * could make generators optional via autoconf tests etc. if needed 
 */ 
extern struct codes_workload_method test_workload_method;
17
extern struct codes_workload_method bgp_io_workload_method;
18
#ifdef USE_DARSHAN
19
extern struct codes_workload_method darshan_io_workload_method;
20
#endif
21
static struct codes_workload_method *method_array[] = 
22 23 24 25 26 27 28
{
    &test_workload_method,
    &bgp_io_workload_method,
#ifdef USE_DARSHAN
    &darshan_io_workload_method,
#endif
    NULL};
29

Philip Carns's avatar
Philip Carns committed
30 31 32 33 34
/* 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 * 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
{
    int rank;
    struct rc_op *lifo;
    struct rank_queue *next;
};

static struct rank_queue *ranks = NULL;

57 58
int codes_workload_load(const char* type, const char* params, int rank)
{
59 60
    int i;
    int ret;
61
    struct rank_queue *tmp;
62 63 64 65 66

    for(i=0; method_array[i] != NULL; i++)
    {
        if(strcmp(method_array[i]->method_name, type) == 0)
        {
67
            /* load appropriate workload generator */
68 69 70 71 72
            ret = method_array[i]->codes_workload_load(params, rank);
            if(ret < 0)
            {
                return(-1);
            }
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

            /* are we tracking information for this rank yet? */
            tmp = ranks;
            while(tmp)
            {
                if(tmp->rank == rank)
                    break;
                tmp = tmp->next;
            }
            if(tmp == NULL)
            {
                tmp = malloc(sizeof(*tmp));
                assert(tmp);
                tmp->rank = rank;
                tmp->lifo = NULL;
                tmp->next = ranks;
                ranks = tmp;
            }

92 93 94 95 96
            return(i);
        }
    }

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

100
void codes_workload_get_next(int wkld_id, int rank, struct codes_workload_op *op)
101
{
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    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)
    {
        if(tmp->rank == rank)
            break;
        tmp = tmp->next;
    }
    assert(tmp);
    if(tmp->lifo)
    {
        tmp_op = tmp->lifo;
        tmp->lifo = tmp_op->next; 

        *op = tmp_op->op;
        free(tmp_op);
123
        //printf("codes_workload_get_next re-issuing reversed operation.\n");
124 125 126 127
        return;
    }

    /* ask generator for the next operation */
128
    //printf("codes_workload_get_next issuing new operation.\n");
129 130
    method_array[wkld_id]->codes_workload_get_next(rank, op);

131 132 133
    return;
}

134
void codes_workload_get_next_rc(int wkld_id, int rank, const struct codes_workload_op *op)
135
{
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    struct rank_queue *tmp;
    struct rc_op *tmp_op;

    tmp = ranks;
    while(tmp)
    {
        if(tmp->rank == rank)
            break;
        tmp = tmp->next;
    }
    assert(tmp);

    tmp_op = malloc(sizeof(*tmp_op));
    assert(tmp_op);
    tmp_op->op = *op;
    tmp_op->next = tmp->lifo;
    tmp->lifo = tmp_op;
153

154 155 156
    return;
}

157 158 159 160 161
void* codes_workload_get_info(int wkld_id, int rank)
{
    return method_array[wkld_id]->codes_workload_get_info(rank);
}

162 163 164 165 166 167 168 169
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */