37 #define MAX_DESTINATIONS 128 
   40 #define MAX_ROUTE_ID 10000 
   57 #ifdef LOG_ROUTING_CHANGES 
   60     int offset = sprintf(output,
"\n---------- ROUTE TYPE: %d ----------\n", table->
type_id);
 
   63         offset += sprintf(output+offset, 
"- %4d: %3d\n", destination->
id, (
int)table->
keys[i]);
 
   65     log(LOG_ROUTING_CHANGES, 
"%s", output);
 
   68 #define print_routing_table(t) 
   82     return pthread_rwlock_rdlock(&table->
rwlock);
 
   91     return pthread_rwlock_wrlock(&table->
rwlock);
 
  100     return pthread_rwlock_unlock(&table->
rwlock);
 
  117         if (table->
keys[i] > value)
 
  148         log_error(
"MSU %d does not exist in route %d", msu_id, table->
id);
 
  160     log(LOG_ROUTING_CHANGES, 
"Removed destination %d from table %d (type %d)",
 
  190     table->
keys[i] = key;
 
  196     log(LOG_ROUTING_CHANGES, 
"Added destination %d to table %d (type: %d)",
 
  214         log_error(
"MSU %d does not exist in route %d", msu_id, table->
id);
 
  231     for (i = table->
n_endpoints-1; i > 0 && new_key < table->keys[i-1]; i--) {
 
  235     table->
keys[i] = new_key;
 
  238     log(LOG_ROUTING_CHANGES, 
"Changed key of msu %d in table %d from %d to %d",
 
  239                msu_id, table->
id, orig_key, new_key);
 
  253         log_error(
"Error allocating routing table");
 
  256     table->
id = route_id;
 
  258     pthread_rwlock_init(&table->
rwlock, NULL);
 
  272     return all_routes[route_id];
 
  283         log_error(
"Route with id %d already exists on runtime", route_id);
 
  288         log_error(
"Error initializing routing table %d", route_id);
 
  291     all_routes[route_id] = table;
 
  292     log(LOG_ROUTING_CHANGES, 
"Initialized route %d (type %d)", route_id, type_id);
 
  297 #define MAX_MSU_Q_SIZE INT_MAX 
  312         if (length < shortest_queue) {
 
  314             shortest_queue = length;
 
  316         } 
else if (length == shortest_queue) {
 
  317             endpoints[n_shortest] = &table->
endpoints[i];
 
  322     if (n_shortest == 0) {
 
  327     *endpoint = *endpoints[key % (int)n_shortest];
 
  361     int found_endpoints = 0;
 
  365             if (n_endpoints <= found_endpoints) {
 
  366                 log_error(
"Not enough endpoints passed in to hold results");
 
  370             endpoints[found_endpoints] = table->
endpoints[i];
 
  375     return found_endpoints;
 
  389         log_error(
"Could not find index for key %d", key);
 
  394     log(LOG_ROUTING_DECISIONS, 
"Endpoint for key %u is %d", key, endpoint->
id);
 
  400     for (
int i=0; i<set->
n_routes; i++) {
 
  405     log_error(
"No route available of type %d", type_id);
 
  410     log(LOG_ROUTING_CHANGES, 
"Adding endpoint %d to route %d", endpoint.
id, route_id);
 
  413         log_error(
"Route %d does not exist", route_id);
 
  422         log_error(
"Route %d does not exist", route_id);
 
  427         log_error(
"Error removing msu %d from route %d", msu_id, route_id);
 
  430     log(LOG_ROUTING_CHANGES, 
"Removed destination %d from route %d", msu_id, route_id);
 
  437         log_error(
"Route %d does not exist", route_id);
 
  442         log_error(
"Error altering routing for msu %d on route %d", msu_id, route_id);
 
  445     log(LOG_ROUTING_CHANGES, 
"Altered key %d for msu %d in route %d",
 
  446                new_key, msu_id, route_id);
 
  453         log_error(
"Route %d does not exist", route_id);
 
  457     if (set->
routes == NULL) {
 
  468         if (set->
routes[i]->
id == route_id) {
 
  473         log_error(
"route %d does not exist in set", route_id);
 
  484     endpoint->
id = msu_id;
 
  487         log_error(
"Cannot get local runtime ID");
 
  490     if (runtime_id == local_id) {
 
  494             log_error(
"Cannot find local MSU with id %d for initializing endpoint",
 
int init_msu_endpoint(int msu_id, int runtime_id, struct msu_endpoint *endpoint)
Initializes an endpoint structure to point to the relevant msu. 
int add_route_endpoint(int route_id, struct msu_endpoint endpoint, uint32_t key)
Adds an endpoint to the route with the given ID. 
int init_route(int route_id, int type_id)
Initializes a new route with the given route_id and type_id. 
int get_endpoint_by_id(struct routing_table *table, int msu_id, struct msu_endpoint *endpoint)
Gets endpoint with the given MSU ID in the provided route. 
The publicly accessible copy of the routing table. 
int id
A unque identifier for the endpoint (msu ID) 
unsigned int runtime_id
The ID for the runtime on which the endpoint resides. 
Macro for declaring functions or variables as unused to avoid compiler warnings. 
static int rm_routing_table_entry(struct routing_table *table, int msu_id)
Removes a destination from the routing table. 
The core of the routing system, the routing table lists a route's destinations. 
int n_endpoints
The number of destinations this route contains. 
pthread_rwlock_t rwlock
Protects access to the destinations so they cannot be changed while they are being read...
static int alter_routing_table_entry(struct routing_table *table, int msu_id, uint32_t new_key)
Modifies the key associated with an existing destination in a routing table. 
static struct routing_table * get_routing_table(int route_id)
Gets the routing table associated with the route_id. 
uint32_t keys[128]
The keys associated with each of the destinations. 
int add_routing_table_entry(struct routing_table *table, struct msu_endpoint *dest, uint32_t key)
Adds a (copy of the) destination to a routing table. 
struct routing_table ** routes
int get_route_endpoint(struct routing_table *table, uint32_t key, struct msu_endpoint *endpoint)
Gets the endpoint associated with the given key in the provided route. 
Logging of status messages to the terminal. 
#define MAX_ROUTE_ID
The maximum ID that may be assigned to a route. 
static struct routing_table * all_routes[10000]
All of the created routes in this runtime. 
int rm_route_from_set(struct route_set *set, int route_id)
Removes a route from a set of routes. 
Interactions with global dfg from individual runtime. 
static int unlock(struct routing_table *table)
Simple wrapper to unlock a locked routing table. 
struct msg_queue * queue
if msu_endpoint::locality == MSU_IS_LOCAL, the queue for the msu endpoint 
int get_endpoints_by_runtime_id(struct routing_table *table, int runtime_id, struct msu_endpoint *endpoints, int n_endpoints)
Gets all of the endpoints in the provided routing table with the right runtime id. 
#define MAX_DESTINATIONS
The maximum number of destinations a route can have. 
int type_id
The type-id associated with the destinations in this table. 
#define log_error(fmt,...)
Declares the structures and functions applicable to MSUs on the local machine. 
static int write_lock(struct routing_table *table)
Simple wrapper to lock a routing table for writing. 
struct local_msu * get_local_msu(unsigned int id)
Gets the local MSU with the given ID, or NULL if N/A. 
The structure that represents an MSU located on the local machine. 
int add_route_to_set(struct route_set *set, int route_id)
Adds a route to a set of routes. 
Functions for routing MSU messages between MSUs. 
enum msu_locality locality
Whether the endpoint is on the local machine or remote. 
int get_n_endpoints(struct routing_table *table)
struct routing_table * init_routing_table(int route_id, int type_id)
Initializes and returns a new routing table. 
struct msg_queue queue
Input queue to MSU. 
int remove_route_endpoint(int route_id, int msu_id)
Removes destination from route with given ID. 
#define print_routing_table(t)
struct msu_endpoint endpoints[128]
The destinations themselves. 
int modify_route_endpoint(int route_id, int msu_id, uint32_t new_key)
Modifies key associated with MSU in route. 
uint32_t num_msgs
Number of messages currently in the queue. 
struct routing_table * get_type_from_route_set(struct route_set *set, int type_id)
Gets the route from the provided array of routes which has the correct type ID. 
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
unsigned int route_id
The ID for the route used to get to the endpoint. 
int get_endpoint_by_index(struct routing_table *table, int index, struct msu_endpoint *endpoint)
Gets endpoint witih given index in route set. 
static int find_id_index(struct routing_table *table, int msu_id)
Finds the index of the entry in the routing table with the destination that has the provided msu id...
static int runtime_id(int runtime_fd)
#define log(level, fmt,...)
Log at a custom level. 
static int read_lock(struct routing_table *table)
Simple wrapper to lock a routing table for reading. 
static int find_value_index(struct routing_table *table, uint32_t value)
Searches through the entries in the routing table, returning the index of the first key which surpass...
An endpoint to which an msu_msg can be delivered. 
int get_shortest_queue_endpoint(struct routing_table *table, uint32_t key, struct msu_endpoint *endpoint)
Gets the local endpoint from a route with the shortest queue length.