loggp.c 19.2 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (C) 2013 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#include <string.h>
#include <assert.h>
#include <ross.h>

#include "codes/lp-io.h"
#include "codes/jenkins-hash.h"
#include "codes/model-net-method.h"
#include "codes/model-net.h"
15
#include "codes/model-net-lp.h"
Philip Carns's avatar
Philip Carns committed
16 17
#include "codes/codes_mapping.h"
#include "codes/codes.h"
18
#include "codes/net/loggp.h"
Philip Carns's avatar
Philip Carns committed
19 20 21 22

#define CATEGORY_NAME_MAX 16
#define CATEGORY_MAX 12

23 24 25
#define LP_CONFIG_NM (model_net_lp_config_names[LOGGP])
#define LP_METHOD_NM (model_net_method_names[LOGGP])

Philip Carns's avatar
Philip Carns committed
26 27 28 29 30 31 32 33 34 35 36 37
/*Define loggp data types and structs*/
typedef struct loggp_state loggp_state;


struct loggp_state
{
    /* next idle times for network card, both inbound and outbound */
    tw_stime net_send_next_idle;
    tw_stime net_recv_next_idle;
    struct mn_stats loggp_stats_array[CATEGORY_MAX];
};

38 39 40
/* loggp parameters for a given msg size, as reported by netgauge */
struct param_table_entry
{
41
    uint64_t size;
42 43 44 45 46 47 48 49 50 51 52 53 54 55
    int n;
    double PRTT_10s;
    double PRTT_n0s;
    double PRTT_nPRTT_10ss;
    double L;
    double o_s;
    double o_r;
    double g;
    double G;
    double lsqu_gG;
};
struct param_table_entry param_table[100];
static int param_table_size = 0;

Philip Carns's avatar
Philip Carns committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69
static int loggp_magic = 0;

/* returns a pointer to the lptype struct to use for loggp LPs */
static const tw_lptype* loggp_get_lp_type(void);

/* retrieve the size of the portion of the event struct that is consumed by
 * the loggp module.  The caller should add this value to the size of
 * its own event structure to get the maximum total size of a message.
 */
static int loggp_get_msg_sz(void);

/* Returns the loggp magic number */
static int loggp_get_magic();

70 71 72 73 74 75
/* collective network calls */
static void loggp_collective();

/* collective network calls-- rc */
static void loggp_collective_rc();

Philip Carns's avatar
Philip Carns committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/* allocate a new event that will pass through loggp to arriave at its
 * destination:
 *
 * - category: category name to associate with this communication
 * - final_dest_gid: the LP that the message should be delivered to.
 * - event_size_bytes: size of event msg that will be delivered to
 * final_dest_gid.
 * - local_event_size_byte: size of event message that will delivered to
 *   local LP upon local send comletion (set to 0 if not used)
 * - net_msg_size_bytes: size of simulated network message in bytes.
 * - sender: LP calling this function.
 */
/* Modelnet interface events */
/* sets up the loggp parameters through modelnet interface */
static void loggp_setup(const void* net_params);

/* Issues a loggp packet event call */
93
static tw_stime loggp_packet_event(
Philip Carns's avatar
Philip Carns committed
94 95
     char* category, 
     tw_lpid final_dest_lp, 
96
     uint64_t packet_size, 
97 98
     int is_pull,
     uint64_t pull_size, /* only used when is_pull==1 */
99
     tw_stime offset,
Philip Carns's avatar
Philip Carns committed
100 101 102 103
     int remote_event_size, 
     const void* remote_event, 
     int self_event_size,
     const void* self_event,
104
     tw_lpid src_lp,
Philip Carns's avatar
Philip Carns committed
105 106 107 108 109 110 111 112
     tw_lp *sender,
     int is_last_pckt);
static void loggp_packet_event_rc(tw_lp *sender);

static void loggp_packet_event_rc(tw_lp *sender);

static void loggp_report_stats();

113 114
static tw_lpid loggp_find_local_device(tw_lp *sender);

115
static struct param_table_entry* find_params(uint64_t msg_size);
116

Philip Carns's avatar
Philip Carns committed
117 118 119 120 121 122 123 124 125
/* data structure for model-net statistics */
struct model_net_method loggp_method =
{
    .mn_setup = loggp_setup,
    .model_net_method_packet_event = loggp_packet_event,
    .model_net_method_packet_event_rc = loggp_packet_event_rc,
    .mn_get_lp_type = loggp_get_lp_type,
    .mn_get_msg_sz = loggp_get_msg_sz,
    .mn_report_stats = loggp_report_stats,
126
    .model_net_method_find_local_device = loggp_find_local_device,
127 128
    .mn_collective_call = loggp_collective,
    .mn_collective_call_rc = loggp_collective_rc
Philip Carns's avatar
Philip Carns committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
};

static void loggp_init(
    loggp_state * ns,
    tw_lp * lp);
static void loggp_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp);
static void loggp_rev_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp);
static void loggp_finalize(
    loggp_state * ns,
    tw_lp * lp);

tw_lptype loggp_lp = {
     (init_f) loggp_init,
     (event_f) loggp_event,
     (revent_f) loggp_rev_event,
     (final_f) loggp_finalize,
     (map_f) codes_mapping,
     sizeof(loggp_state),
};

static void handle_msg_ready_rev_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp);
static void handle_msg_ready_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp);
static void handle_msg_start_rev_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp);
static void handle_msg_start_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp);

/* returns pointer to LP information for loggp module */
static const tw_lptype* loggp_get_lp_type()
{
    return(&loggp_lp);
}

/* returns number of bytes that the loggp module will consume in event
 * messages
 */
static int loggp_get_msg_sz(void)
{
    return(sizeof(loggp_message));
}

/* report network statistics */
static void loggp_report_stats()
{
   /* TODO: Do we have some loggp statistics to report like we have for torus and dragonfly? */
   return;
}
198 199 200 201 202 203 204 205 206 207 208 209 210 211

/* collective network calls */
static void loggp_collective()
{
/* collectives not supported */
    return;
}

static void loggp_collective_rc()
{
/* collectives not supported */
   return;
}

Philip Carns's avatar
Philip Carns committed
212 213 214 215 216 217 218 219 220 221 222
static void loggp_init(
    loggp_state * ns,
    tw_lp * lp)
{
    uint32_t h1 = 0, h2 = 0;
    memset(ns, 0, sizeof(*ns));

    /* all devices are idle to begin with */
    ns->net_send_next_idle = tw_now(lp);
    ns->net_recv_next_idle = tw_now(lp);

223
    bj_hashlittle2(LP_METHOD_NM, strlen(LP_METHOD_NM), &h1, &h2);
Philip Carns's avatar
Philip Carns committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    loggp_magic = h1+h2;
    /* printf("\n loggp_magic %d ", loggp_magic); */

    return;
}

static void loggp_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp)
{
    assert(m->magic == loggp_magic);

    switch (m->event_type)
    {
240
        case LG_MSG_START:
Philip Carns's avatar
Philip Carns committed
241 242
            handle_msg_start_event(ns, b, m, lp);
            break;
243
        case LG_MSG_READY:
Philip Carns's avatar
Philip Carns committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
            handle_msg_ready_event(ns, b, m, lp);
            break;
        default:
            assert(0);
            break;
    }
}

static void loggp_rev_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp)
{
    assert(m->magic == loggp_magic);

    switch (m->event_type)
    {
262
        case LG_MSG_START:
Philip Carns's avatar
Philip Carns committed
263 264
            handle_msg_start_rev_event(ns, b, m, lp);
            break;
265
        case LG_MSG_READY:
Philip Carns's avatar
Philip Carns committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
            handle_msg_ready_rev_event(ns, b, m, lp);
            break;
        default:
            assert(0);
            break;
    }

    return;
}

static void loggp_finalize(
    loggp_state * ns,
    tw_lp * lp)
{
    model_net_print_stats(lp->gid, &ns->loggp_stats_array[0]);
    return;
}

int loggp_get_magic()
{
  return loggp_magic;
}

/* reverse computation for msg ready event */
static void handle_msg_ready_rev_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp)
{
    struct mn_stats* stat;

    ns->net_recv_next_idle = m->net_recv_next_idle_saved;
    
    stat = model_net_find_stats(m->category, ns->loggp_stats_array);
    stat->recv_count--;
    stat->recv_bytes -= m->net_msg_size_bytes;
303
    stat->recv_time -= m->recv_time_saved;
Philip Carns's avatar
Philip Carns committed
304

305
    if (m->event_size_bytes && m->is_pull){
306
        int net_id = model_net_get_id(LP_METHOD_NM);
307 308 309
        model_net_event_rc(net_id, lp, m->pull_size);
    }

Philip Carns's avatar
Philip Carns committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    return;
}

/* handler for msg ready event.  This indicates that a message is available
 * to recv, but we haven't checked to see if the recv queue is available yet
 */
static void handle_msg_ready_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp)
{
    tw_stime recv_queue_time = 0;
    tw_event *e_new;
    loggp_message *m_new;
    struct mn_stats* stat;
326 327 328 329 330
    double recv_time;
    struct param_table_entry *param;

    param = find_params(m->net_msg_size_bytes);

331 332 333
    recv_time = ((double)(m->net_msg_size_bytes-1)*param->G);
    /* scale to nanoseconds */
    recv_time *= 1000.0;
334
    m->recv_time_saved = recv_time;
Philip Carns's avatar
Philip Carns committed
335 336 337 338 339 340

    //printf("handle_msg_ready_event(), lp %llu.\n", (unsigned long long)lp->gid);
    /* add statistics */
    stat = model_net_find_stats(m->category, ns->loggp_stats_array);
    stat->recv_count++;
    stat->recv_bytes += m->net_msg_size_bytes;
341
    stat->recv_time += recv_time;
Philip Carns's avatar
Philip Carns committed
342 343 344 345 346 347 348

    /* are we available to recv the msg? */
    /* were we available when the transmission was started? */
    if(ns->net_recv_next_idle > tw_now(lp))
        recv_queue_time += ns->net_recv_next_idle - tw_now(lp);

    /* calculate transfer time based on msg size and bandwidth */
349
    recv_queue_time += recv_time;
Philip Carns's avatar
Philip Carns committed
350

351
    /* bump up input queue idle time accordingly, include gap (g) parameter */
Philip Carns's avatar
Philip Carns committed
352
    m->net_recv_next_idle_saved = ns->net_recv_next_idle;
Philip Carns's avatar
Philip Carns committed
353
    ns->net_recv_next_idle = recv_queue_time + tw_now(lp) + param->g*1000.0;
Philip Carns's avatar
Philip Carns committed
354 355 356 357 358 359 360

    /* copy only the part of the message used by higher level */
    if(m->event_size_bytes)
    {
      /* schedule event to final destination for when the recv is complete */
//      printf("\n Remote message to LP %d ", m->final_dest_gid); 

361
        void *tmp_ptr = model_net_method_get_edata(LOGGP, m);
362 363
        //char* tmp_ptr = (char*)m;
        //tmp_ptr += loggp_get_msg_sz();
364 365
        if (m->is_pull){
            /* call the model-net event */
366
            int net_id = model_net_get_id(LP_METHOD_NM);
367 368 369 370 371 372 373 374 375 376
            model_net_event(net_id, m->category, m->src_gid, m->pull_size,
                    recv_queue_time, m->event_size_bytes, tmp_ptr, 0, NULL,
                    lp);
        }
        else{
            e_new = tw_event_new(m->final_dest_gid, recv_queue_time, lp);
            m_new = tw_event_data(e_new);
            memcpy(m_new, tmp_ptr, m->event_size_bytes);
            tw_event_send(e_new);
        }
Philip Carns's avatar
Philip Carns committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
    }

    return;
}

/* reverse computation for msg start event */
static void handle_msg_start_rev_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp)
{
    ns->net_send_next_idle = m->net_send_next_idle_saved;

    if(m->local_event_size_bytes > 0)
    {
        codes_local_latency_reverse(lp);
    }

    mn_stats* stat;
    stat = model_net_find_stats(m->category, ns->loggp_stats_array);
    stat->send_count--;
    stat->send_bytes -= m->net_msg_size_bytes;
400
    stat->send_time -= m->xmit_time_saved;
Philip Carns's avatar
Philip Carns committed
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421

    return;
}

/* handler for msg start event; this indicates that the caller is trying to
 * transmit a message through this NIC
 */
static void handle_msg_start_event(
    loggp_state * ns,
    tw_bf * b,
    loggp_message * m,
    tw_lp * lp)
{
    tw_event *e_new;
    loggp_message *m_new;
    tw_stime send_queue_time = 0;
    mn_stats* stat;
    int mapping_grp_id, mapping_type_id, mapping_rep_id, mapping_offset;
    tw_lpid dest_id;
    char lp_type_name[MAX_NAME_LENGTH], lp_group_name[MAX_NAME_LENGTH];
    int total_event_size;
422 423 424 425
    double xmit_time;
    struct param_table_entry *param;

    param = find_params(m->net_msg_size_bytes);
Philip Carns's avatar
Philip Carns committed
426

427 428
    total_event_size = model_net_get_msg_sz(LOGGP) + m->event_size_bytes +
        m->local_event_size_bytes;
Philip Carns's avatar
Philip Carns committed
429

430 431 432 433 434
    /* NOTE: we do not use the o_s or o_r parameters here; as indicated in
     * the netgauge paper those are typically overlapping with L (and the
     * msg xfer as well) and therefore are more important for overlapping
     * computation rather than simulating communication time.
     */
435 436 437
    xmit_time = param->L + ((double)(m->net_msg_size_bytes-1)*param->G);
    /* scale to nanoseconds */
    xmit_time *= 1000.0;
438 439
    m->xmit_time_saved = xmit_time;

Philip Carns's avatar
Philip Carns committed
440 441 442 443 444
    //printf("handle_msg_start_event(), lp %llu.\n", (unsigned long long)lp->gid);
    /* add statistics */
    stat = model_net_find_stats(m->category, ns->loggp_stats_array);
    stat->send_count++;
    stat->send_bytes += m->net_msg_size_bytes;
445
    stat->send_time += xmit_time;
Philip Carns's avatar
Philip Carns committed
446 447 448 449
    if(stat->max_event_size < total_event_size)
        stat->max_event_size = total_event_size;

    /* calculate send time stamp */
450
    send_queue_time = (param->L)*1000.0; 
Philip Carns's avatar
Philip Carns committed
451 452 453 454 455
    /* bump up time if the NIC send queue isn't idle right now */
    if(ns->net_send_next_idle > tw_now(lp))
        send_queue_time += ns->net_send_next_idle - tw_now(lp);

    /* move the next idle time ahead to after this transmission is
456 457
     * _complete_ from the sender's perspective, include gap paramater (g)
     * at this point. 
Philip Carns's avatar
Philip Carns committed
458 459
     */ 
    m->net_send_next_idle_saved = ns->net_send_next_idle;
460 461
    if(ns->net_send_next_idle < tw_now(lp))
        ns->net_send_next_idle = tw_now(lp);
Philip Carns's avatar
Philip Carns committed
462
    ns->net_send_next_idle += xmit_time + param->g*1000.0;
Philip Carns's avatar
Philip Carns committed
463 464 465

    /* create new event to send msg to receiving NIC */
    codes_mapping_get_lp_info(m->final_dest_gid, lp_group_name, &mapping_grp_id, &mapping_type_id, lp_type_name, &mapping_rep_id, &mapping_offset);
466
    codes_mapping_get_lp_id(lp_group_name, LP_CONFIG_NM, mapping_rep_id , mapping_offset, &dest_id); 
Philip Carns's avatar
Philip Carns committed
467

468
    void *m_data;
Philip Carns's avatar
Philip Carns committed
469
//    printf("\n msg start sending to %d ", dest_id);
470 471 472 473
    //e_new = tw_event_new(dest_id, send_queue_time, lp);
    //m_new = tw_event_data(e_new);
    e_new = model_net_method_event_new(dest_id, send_queue_time, lp, LOGGP,
            (void**)&m_new, &m_data);
Philip Carns's avatar
Philip Carns committed
474 475 476 477

    /* copy entire previous message over, including payload from user of
     * this module
     */
478 479 480 481 482 483 484
    memcpy(m_new, m, sizeof(loggp_message));
    if (m->event_size_bytes){
        memcpy(m_data, model_net_method_get_edata(LOGGP, m),
                m->event_size_bytes);
    }

    m_new->event_type = LG_MSG_READY;
Philip Carns's avatar
Philip Carns committed
485 486 487 488 489 490 491 492
    
    tw_event_send(e_new);

    /* if there is a local event to handle, then create an event for it as
     * well
     */
    if(m->local_event_size_bytes > 0)
    {
493
        //char* local_event;
Philip Carns's avatar
Philip Carns committed
494

495
        e_new = tw_event_new(m->src_gid, send_queue_time+codes_local_latency(lp), lp);
Philip Carns's avatar
Philip Carns committed
496 497
        m_new = tw_event_data(e_new);

498
        void * m_loc = (char*) model_net_method_get_edata(LOGGP, m) +
499 500 501
            m->event_size_bytes;
         //local_event = (char*)m;
         //local_event += loggp_get_msg_sz() + m->event_size_bytes;         	 
Philip Carns's avatar
Philip Carns committed
502
        /* copy just the local event data over */
503
        memcpy(m_new, m_loc, m->local_event_size_bytes);
Philip Carns's avatar
Philip Carns committed
504 505 506 507 508 509 510 511 512
        tw_event_send(e_new);
    }
    return;
}

/* Model-net function calls */

/*This method will serve as an intermediate layer between loggp and modelnet. 
 * It takes the packets from modelnet layer and calls underlying loggp methods*/
513
static tw_stime loggp_packet_event(
Philip Carns's avatar
Philip Carns committed
514 515
		char* category,
		tw_lpid final_dest_lp,
516
		uint64_t packet_size,
517 518
                int is_pull,
                uint64_t pull_size, /* only used when is_pull==1 */
519
                tw_stime offset,
Philip Carns's avatar
Philip Carns committed
520 521 522 523
		int remote_event_size,
		const void* remote_event,
		int self_event_size,
		const void* self_event,
524
                tw_lpid src_lp,
Philip Carns's avatar
Philip Carns committed
525 526 527 528 529 530 531
		tw_lp *sender,
		int is_last_pckt)
{
     tw_event * e_new;
     tw_stime xfer_to_nic_time;
     loggp_message * msg;
     char* tmp_ptr;
532
#if 0
Philip Carns's avatar
Philip Carns committed
533 534 535 536
     char lp_type_name[MAX_NAME_LENGTH], lp_group_name[MAX_NAME_LENGTH];

     int mapping_grp_id, mapping_rep_id, mapping_type_id, mapping_offset;
     codes_mapping_get_lp_info(sender->gid, lp_group_name, &mapping_grp_id, &mapping_type_id, lp_type_name, &mapping_rep_id, &mapping_offset);
537 538
     codes_mapping_get_lp_id(lp_group_name, LP_CONFIG_NM, mapping_rep_id, mapping_offset, &dest_id);
#endif
Philip Carns's avatar
Philip Carns committed
539 540

     xfer_to_nic_time = codes_local_latency(sender);
541 542 543 544
     e_new = model_net_method_event_new(sender->gid, xfer_to_nic_time+offset,
             sender, LOGGP, (void**)&msg, (void**)&tmp_ptr);
     //e_new = tw_event_new(dest_id, xfer_to_nic_time+offset, sender);
     //msg = tw_event_data(e_new);
Philip Carns's avatar
Philip Carns committed
545 546
     strcpy(msg->category, category);
     msg->final_dest_gid = final_dest_lp;
547
     msg->src_gid = src_lp;
Philip Carns's avatar
Philip Carns committed
548 549 550 551
     msg->magic = loggp_get_magic();
     msg->net_msg_size_bytes = packet_size;
     msg->event_size_bytes = 0;
     msg->local_event_size_bytes = 0;
552
     msg->event_type = LG_MSG_START;
553 554
     msg->is_pull = is_pull;
     msg->pull_size = pull_size;
Philip Carns's avatar
Philip Carns committed
555

556 557
     //tmp_ptr = (char*)msg;
     //tmp_ptr += loggp_get_msg_sz();
Philip Carns's avatar
Philip Carns committed
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
      
    //printf("\n Sending to LP %d msg magic %d ", (int)dest_id, loggp_get_magic()); 
     /*Fill in loggp information*/     
     if(is_last_pckt) /* Its the last packet so pass in remote event information*/
      {
       if(remote_event_size)
	 {
           msg->event_size_bytes = remote_event_size;
           memcpy(tmp_ptr, remote_event, remote_event_size);
           tmp_ptr += remote_event_size;
	 }
       if(self_event_size)
       {
	   msg->local_event_size_bytes = self_event_size;
	   memcpy(tmp_ptr, self_event, self_event_size);
	   tmp_ptr += self_event_size;
       }
      // printf("\n Last packet size: %d ", loggp_get_msg_sz() + remote_event_size + self_event_size);
      }
     tw_event_send(e_new);
578
     return xfer_to_nic_time;
Philip Carns's avatar
Philip Carns committed
579 580 581 582
}

static void loggp_setup(const void* net_params)
{
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
    loggp_param* loggp_params = (loggp_param*)net_params;
    FILE *conf;
    int ret;
    char buffer[512];
    int line_nr = 0;

    /* TODO: update this to read on one proc and then broadcast */

    printf("Loggp configured to use parameters from file %s\n", loggp_params->net_config_file);

    conf = fopen(loggp_params->net_config_file, "r");
    if(!conf)
    {
        perror("fopen");
        assert(0);
    }

    while(fgets(buffer, 512, conf))
    {
        line_nr++;
        if(buffer[0] == '#')
            continue;
605
        ret = sscanf(buffer, "%llu %d %lf %lf %lf %lf %lf %lf %lf %lf %lf", 
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
            &param_table[param_table_size].size,
            &param_table[param_table_size].n,
            &param_table[param_table_size].PRTT_10s,
            &param_table[param_table_size].PRTT_n0s,
            &param_table[param_table_size].PRTT_nPRTT_10ss,
            &param_table[param_table_size].L,
            &param_table[param_table_size].o_s,
            &param_table[param_table_size].o_r,
            &param_table[param_table_size].g,
            &param_table[param_table_size].G,
            &param_table[param_table_size].lsqu_gG);
        if(ret != 11)
        {
            fprintf(stderr, "Error: malformed line %d in %s\n", line_nr, 
                loggp_params->net_config_file);
            assert(0);
        }
        param_table_size++;
    }

    printf("Parsed %d loggp table entries.\n", param_table_size);
Philip Carns's avatar
Philip Carns committed
627

628
    fclose(conf);
Philip Carns's avatar
Philip Carns committed
629 630 631 632 633 634 635 636 637 638
 
    return;
}

static void loggp_packet_event_rc(tw_lp *sender)
{
    codes_local_latency_reverse(sender);
    return;
}

639 640
/* find the parameters corresponding to the message size we are transmitting
 */
641
static struct param_table_entry* find_params(uint64_t msg_size)
642 643 644 645 646 647 648 649 650
{
    int i;

    /* pick parameters based on the next smallest size in the table, but
     * default to beginning or end of table if we are out of range
     */

    for(i=0; i<param_table_size; i++)
    {
651
        if(param_table[i].size > msg_size)
652 653 654 655
        {
            break;
        }
    }
656 657
    if(i>=param_table_size)
        i = param_table_size-1;
658 659 660 661

    return(&param_table[i]);
}

662 663 664 665 666 667 668
static tw_lpid loggp_find_local_device(tw_lp *sender)
{
     char lp_type_name[MAX_NAME_LENGTH], lp_group_name[MAX_NAME_LENGTH];
     int mapping_grp_id, mapping_rep_id, mapping_type_id, mapping_offset;
     tw_lpid dest_id;

     codes_mapping_get_lp_info(sender->gid, lp_group_name, &mapping_grp_id, &mapping_type_id, lp_type_name, &mapping_rep_id, &mapping_offset);
669
     codes_mapping_get_lp_id(lp_group_name, LP_CONFIG_NM, mapping_rep_id, mapping_offset, &dest_id);
670 671 672 673 674

    return(dest_id);
}


Philip Carns's avatar
Philip Carns committed
675 676 677 678 679 680 681 682
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ft=c ts=8 sts=4 sw=4 expandtab
 */