model-net-sched.h 6.87 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright (C) 2014 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

Jonathan Jenkins's avatar
Jonathan Jenkins committed
7
/* A scheduler interface for use by model-net models. */
8 9 10 11

#ifndef MODEL_NET_SCHED_H
#define MODEL_NET_SCHED_H

Jonathan Jenkins's avatar
Jonathan Jenkins committed
12 13 14 15
#ifdef __cplusplus
extern "C" {
#endif

16 17
#include <ross.h>
#include "model-net.h"
18 19 20 21 22

// forward decl of mn_sched_params since we currently have a circular include
// (method needs sched def, sched needs method def)
typedef struct mn_sched_params_s mn_sched_params;

23 24
#include "model-net-method.h"

25 26 27 28 29 30 31
/// types of schedulers
/// format: enum type, config string, function pointer names
/// fcfs-full eschews packetization
#define SCHEDULER_TYPES \
    X(MN_SCHED_FCFS,      "fcfs",        &fcfs_tab) \
    X(MN_SCHED_FCFS_FULL, "fcfs-full",   &fcfs_tab) \
    X(MN_SCHED_RR,        "round-robin", &rr_tab) \
32
    X(MN_SCHED_PRIO,      "priority",    &prio_tab) \
33 34 35 36 37 38 39 40
    X(MAX_SCHEDS,         NULL,          NULL)

#define X(a,b,c) a,
enum sched_type {
    SCHEDULER_TYPES
};
#undef X

41 42 43 44 45
/// scheduler decls

typedef struct model_net_sched_s model_net_sched;
typedef struct model_net_sched_rc_s model_net_sched_rc;

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
// priority scheduler configurtion parameters
typedef struct mn_prio_params_s {
    int num_prios; // number of priorities
    // sub-scheduler to use. can be any but prio
    enum sched_type sub_stype;
} mn_prio_params;

// TODO: other scheduler config params

// initialization parameter set
typedef struct model_net_sched_cfg_params_s {
    enum sched_type type;
    union {
        mn_prio_params prio;
    } u;
} model_net_sched_cfg_params;

typedef struct mn_sched_cfg_params {
    mn_prio_params prio;
} mn_sched_cfg_params;

/// message-specific parameters
enum sched_msg_param_type {
    MN_SCHED_PARAM_PRIO, // currently, only the priority scheduler has params
    MAX_SCHED_MSG_PARAM_TYPES
};

// scheduler-specific parameter definitions must go here
74
struct mn_sched_params_s {
75
    int prio; // MN_SCHED_PARAM_PRIO (currently the only one)
76
} ;
77

78 79 80
/// interface to be implemented by schedulers
/// see corresponding general functions
typedef struct model_net_sched_interface {
81 82 83 84 85
    // initialize the scheduler
    // params - scheduler specific params (currently only prio q uses)
    void (*init)(
            const struct model_net_method     * method, 
            const model_net_sched_cfg_params  * params,
86
            int                                 is_recv_queue,
87 88
            void                             ** sched);
    // finalize the scheduler
89
    void (*destroy)(void * sched);
90 91 92 93
    // add a new request to the scheduler
    // sched_params - per-message parameters distinct to each scheduler:
    //                prio (currently the only user): int priority
    //              - NULL arguments should be treated as "use default value" 
94
    void (*add)(
95 96 97 98 99 100 101 102 103
            const model_net_request * req,
            const mn_sched_params   * sched_params,
            int                       remote_event_size,
            void                    * remote_event,
            int                       local_event_size,
            void                    * local_event,
            void                    * sched,
            model_net_sched_rc      * rc,
            tw_lp                   * lp);
104
    // reverse the previous request addition
105
    void (*add_rc)(void *sched, const model_net_sched_rc *rc, tw_lp *lp);
106
    // schedule the next packet for processing by the model
107
    int  (*next)(
108 109
            tw_stime              * poffset,
            void                  * sched,
110
            // NOTE: copy here when deleting remote/local events for rc
111 112 113
            void                  * rc_event_save,
            model_net_sched_rc    * rc,
            tw_lp                 * lp);
114 115
    // reverse schedule the previous packet
    void (*next_rc)(
116 117 118 119
            void                     * sched,
            const void               * rc_event_save,
            const model_net_sched_rc * rc,
            tw_lp                    * lp);
120 121 122 123 124 125
} model_net_sched_interface;

/// overall scheduler struct - type puns the actual data structure

struct model_net_sched_s {
    enum sched_type type;
126 127
    // data for the underlying scheduler implementation (see
    // model-net-sched-impl*)
128
    void * dat;
129
    const model_net_sched_interface * impl;
130 131
};

132 133
/// scheduler-specific structures go here

134 135 136 137 138 139 140
/// reverse computation structure - this is expected to be held by upper-level
/// model-net LPs and passed to the scheduler functions to allow proper rc
/// NOTE: since modelnet LPs will be stashing this in their event structs, 
/// need to provide full definition in header
struct model_net_sched_rc_s {
    // NOTE: sched implementations may need different types, but for now they
    // are equivalent 
141
    model_net_request req; // request gets deleted...
142
    mn_sched_params sched_params; // along with msg params
143
    int rtn; // return code from a sched_next 
144
    int prio; // prio when doing priority queue events
145 146
};

147 148 149
// initialize the scheduler
// - params is created by the configuration routine and can be different from
//   type to type. Currently only priority scheduler uses it
150
void model_net_sched_init(
151
        const model_net_sched_cfg_params * params,
152
        int is_recv_queue,
153 154 155 156 157 158 159 160 161 162 163 164 165 166
        struct model_net_method *method,
        model_net_sched *sched);

/// schedules the next chunk, storing any info needed for rc in sched_rc
/// packet issue time is placed in poffset to be able to separate packet calls
/// between multiple scheduler events
/// returns: 
/// * 0 on success,
/// * 1 on success and the corresponding request is finished. In this case,
///   out_req is set to the underlying request
/// * -1 when there is nothing to be scheduled
int model_net_sched_next(
        tw_stime *poffset,
        model_net_sched *sched,
167
        void *rc_event_save,
168 169 170 171 172
        model_net_sched_rc *sched_rc,
        tw_lp *lp);

void model_net_sched_next_rc(
        model_net_sched *sched,
173 174
        const void *rc_event_save,
        const model_net_sched_rc *sched_rc,
175 176 177 178
        tw_lp *lp);

/// enter a new request into the scheduler, storing any info needed for rc in
/// sched_rc
179 180
/// sched_msg_params is scheduler-specific parameters (currently only used by
/// prio scheduler)
181
void model_net_sched_add(
182
        const model_net_request *req,
183
        const mn_sched_params * sched_params,
184 185 186 187 188 189 190 191 192 193
        int remote_event_size,
        void * remote_event,
        int local_event_size,
        void * local_event,
        model_net_sched *sched,
        model_net_sched_rc *sched_rc,
        tw_lp *lp);

void model_net_sched_add_rc(
        model_net_sched *sched,
194
        const model_net_sched_rc *sched_rc,
195 196
        tw_lp *lp);

197 198 199
// set default parameters for messages that don't specify any
void model_net_sched_set_default_params(mn_sched_params *sched_params);

200 201
extern char * sched_names[];

Jonathan Jenkins's avatar
Jonathan Jenkins committed
202 203 204 205
#ifdef __cplusplus
}
#endif

206 207 208 209 210 211 212 213 214 215
#endif /* end of include guard: MODEL_NET_SCHED_H */

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */