Skip to content

Commit

Permalink
examples: match packets from traces to ECs
Browse files Browse the repository at this point in the history
This commit introduces the following changes:
 1) Support for reading externally generated packet traces in
    generic driver.
 2) Matching packets from traces to execution contexts based on
    packet address.
 3) Synthetic benchmark that associate with each EC a handlers
    with user-defined complexity (computations/DMA).
  • Loading branch information
Mikhail Khalilov authored and miharulidze committed Oct 17, 2022
1 parent 947ba5d commit 7001a19
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 133 deletions.
16 changes: 9 additions & 7 deletions examples/aggregate/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,16 +17,18 @@

int main(int argc, char**argv)
{
const char *handlers_file="build/aggregate_global";
const char *hh=NULL;
const char *ph="aggregate_global_ph";
const char *th="aggregate_global_th";
const char *handlers_file = "build/aggregate_global";
const char *hh = NULL;
const char *ph = "aggregate_global_ph";
const char *th = "aggregate_global_th";
int ectx_num;

gdriver_init(argc, argv);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 42);
gdriver_init(argc, argv, NULL, &ectx_num);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 0, NULL, 0);

gdriver_run();

gdriver_fini();

return 0;
}
14 changes: 7 additions & 7 deletions examples/aggregate_and_reduce/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,20 +18,20 @@
int main(int argc, char**argv)
{
const char *handlers_file = "build/aggregate_and_reduce";

const char *hh_aggregate = NULL;
const char *ph_aggregate = "aggregate_global_ph";
const char *th_aggregate = "aggregate_global_th";

const char *hh_reduce = NULL;
const char *ph_reduce = "reduce_l1_ph";
const char *th_reduce = "reduce_l1_th";

gdriver_init(argc, argv);
int ectx_num;

gdriver_init(argc, argv, NULL, &ectx_num);

gdriver_add_ectx(handlers_file, hh_aggregate, ph_aggregate, th_aggregate,
NULL, NULL, 42);
gdriver_add_ectx(handlers_file, hh_reduce, ph_reduce, th_reduce, NULL, NULL, 42);
NULL, NULL, 0, NULL, 0);
gdriver_add_ectx(handlers_file, hh_reduce, ph_reduce, th_reduce,
NULL, NULL, 0, NULL, 0);

gdriver_run();

Expand Down
14 changes: 8 additions & 6 deletions examples/copy_from_host/driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@

int main(int argc, char**argv)
{
const char *handlers_file="build/copy_from_host";
const char *hh=NULL;
const char *ph="copy_from_host_ph";
const char *th=NULL;
const char *handlers_file = "build/copy_from_host";
const char *hh = NULL;
const char *ph = "copy_from_host_ph";
const char *th = NULL;
int num_ectx;

gdriver_init(argc, argv);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 42);
gdriver_init(argc, argv, NULL, &num_ectx);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 0, NULL, 0);

gdriver_run();

gdriver_fini();

return 0;
}
16 changes: 9 additions & 7 deletions examples/copy_to_host/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,16 +17,18 @@

int main(int argc, char**argv)
{
const char *handlers_file="build/copy_to_host";
const char *hh=NULL;
const char *ph="copy_to_host_ph";
const char *th=NULL;
const char *handlers_file = "build/copy_to_host";
const char *hh = NULL;
const char *ph = "copy_to_host_ph";
const char *th = NULL;
int ectx_num;

gdriver_init(argc, argv);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 42);
gdriver_init(argc, argv, NULL, &ectx_num);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 0, NULL, 0);

gdriver_run();

gdriver_fini();

return 0;
}
7 changes: 4 additions & 3 deletions examples/empty/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,9 +28,10 @@ int main(int argc, char**argv)
const char *hh="empty_hh";
const char *ph="empty_ph";
const char *th="empty_th";
int ectx_num;

gdriver_init(argc, argv);
gdriver_add_ectx(handlers_file, hh, ph, th, fill_packet, NULL, 42);
gdriver_init(argc, argv, NULL, &ectx_num);
gdriver_add_ectx(handlers_file, hh, ph, th, fill_packet, NULL, 0, NULL, 0);

gdriver_run();

Expand Down
8 changes: 5 additions & 3 deletions examples/filtering/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,20 +59,22 @@ int main(int argc, char **argv)
const char *hh = NULL;
const char *ph = "filtering_ph";
const char *th = NULL;
int ectx_num;

srand(SEED);

uint32_t *vec = (uint32_t *)malloc(sizeof(uint32_t) * (TOT_WORDS));
fill_htable(vec, TOT_WORDS);

gdriver_init(argc, argv);
gdriver_init(argc, argv, NULL, &ectx_num);
gdriver_add_ectx(handlers_file, hh, ph, th, fill_packet,
(void *)vec, sizeof(uint32_t) * (TOT_WORDS));
(void *)vec, sizeof(uint32_t) * (TOT_WORDS), NULL, 0);

gdriver_run();

gdriver_fini();

free(vec);

return 0;
}
66 changes: 36 additions & 30 deletions examples/generic_driver/gdriver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,12 +106,29 @@ static void gdriver_dump_ectx_info(const gdriver_ectx_t *gectx)
printf("[GDRIVER] matching context=%s\n", gectx->matching_ctx ? gectx->matching_ctx : "NULL");
}

static void gdriver_fill_pkt(int ectx_idx, uint32_t msg_idx, uint32_t pkt_idx,
uint8_t *pkt_buf, uint32_t pkt_size, uint32_t *l1_pkt_size)
{
pkt_hdr_t *hdr;

if (sim_state.ectxs[ectx_idx].pkt_fill_cb != NULL) {
pkt_size = sim_state.ectxs[ectx_idx].pkt_fill_cb(
msg_idx, pkt_idx, pkt_buf, sim_state.tgen.packet_size, l1_pkt_size);
} else {
// generate IP+UDP headers
hdr = (pkt_hdr_t*)pkt_buf;
hdr->ip_hdr.ihl = 5;
hdr->ip_hdr.length = pkt_size;
*l1_pkt_size = pkt_size;
// TODO: set other fields
}
}

static void gdriver_generate_packets()
{
uint32_t global_msg_counter = 0, global_packet_counter = 0;
uint8_t *pkt_buf;
uint32_t pkt_size, l1_pkt_size, delay;
pkt_hdr_t *hdr;
uint32_t pkt_size, l1_pkt_size, delay;
int is_last;

printf("[GDRIVER]: Using default packet generator\n");
Expand All @@ -123,30 +140,16 @@ static void gdriver_generate_packets()
for (uint32_t msg_idx = 0; msg_idx < sim_state.tgen.num_messages; msg_idx++) {
for (uint32_t pkt_idx = 0; pkt_idx < sim_state.tgen.num_packets; pkt_idx++) {
pkt_size = sim_state.tgen.packet_size;
l1_pkt_size = pkt_size;
if (sim_state.ectxs[ectx_idx].pkt_fill_cb != NULL) {
pkt_size = sim_state.ectxs[ectx_idx].pkt_fill_cb(
global_msg_counter + msg_idx, global_packet_counter + pkt_idx,
pkt_buf, sim_state.tgen.packet_size, &l1_pkt_size);
} else {
// generate IP+UDP headers
hdr = (pkt_hdr_t*)pkt_buf;
hdr->ip_hdr.ihl = 5;
hdr->ip_hdr.length = pkt_size;
// TODO: set other fields
}

gdriver_fill_pkt(ectx_idx, global_msg_counter + msg_idx, global_packet_counter + pkt_idx,
pkt_buf, pkt_size, &l1_pkt_size);
is_last = (pkt_idx + 1 == sim_state.tgen.num_packets);
delay = (is_last) ? sim_state.tgen.message_delay :
sim_state.tgen.packet_delay;
delay = (is_last) ? sim_state.tgen.message_delay : sim_state.tgen.packet_delay;

printf("[GDRIVER]: ectx_id=%u msg_idx=%u, pkt_idx=%u %s\n",
ectx_idx, ectx_idx + msg_idx, pkt_idx, is_last ? "<-----LAST" : "");
pspinsim_packet_add(
&(sim_state.ectxs[ectx_idx].ectx), global_msg_counter + msg_idx,
pspinsim_packet_add(&(sim_state.ectxs[ectx_idx].ectx), global_msg_counter + msg_idx,
pkt_buf, pkt_size, l1_pkt_size, is_last, delay, 0);

sim_state.tgen.packets_sent++;
sim_state.tgen.packets_sent++;
global_packet_counter++;
}
global_msg_counter++;
Expand Down Expand Up @@ -199,12 +202,13 @@ static void gdriver_parse_trace()
break;
}
}

assert(matched);

l1_pkt_size = pkt_size;
pspinsim_packet_add(&(sim_state.ectxs[ectx_id].ectx), msgid, pkt_buf, pkt_size, l1_pkt_size, is_last, wait_cycles, 0);
wait_cycles = 0;
gdriver_fill_pkt(ectx_id, msgid, 0, pkt_buf, pkt_size, &l1_pkt_size);
pspinsim_packet_add(&(sim_state.ectxs[ectx_id].ectx), msgid,
pkt_buf, pkt_size, l1_pkt_size, is_last, wait_cycles, 0);

wait_cycles = 0;
}
sim_state.ttrace.packets_parsed++;
}
Expand Down Expand Up @@ -260,7 +264,7 @@ static int gdriver_init_ectx(gdriver_ectx_t *gectx, uint32_t gectx_id,
* For now assume that each execution context had its own region of host/L1/L2
* memories.
*
* See macro on top for clarity.
* See EC_MEM_BASE_ADDR macro definition for clarity.
*/

gectx->ectx.handler_mem_addr = EC_MEM_BASE_ADDR(gectx_id,
Expand Down Expand Up @@ -308,7 +312,8 @@ int gdriver_add_ectx(const char *hfile, const char *hh, const char *ph, const ch
if (matching_ctx_size > GDRIVER_MATCHING_CTX_MAXSIZE)
return GDRIVER_ERR;

if (gdriver_init_ectx(&(sim_state.ectxs[sim_state.num_ectxs]), sim_state.num_ectxs,
if (gdriver_init_ectx(
&(sim_state.ectxs[sim_state.num_ectxs]), sim_state.num_ectxs,
hfile, hh, ph, th,
fill_pkt_cb, l2_img, l2_img_size,
matching_ctx, matching_ctx_size)) {
Expand All @@ -322,10 +327,11 @@ int gdriver_add_ectx(const char *hfile, const char *hh, const char *ph, const ch

int gdriver_run()
{
if (sim_state.is_trace)
if (sim_state.is_trace) {
gdriver_parse_trace();
else
} else {
gdriver_generate_packets();
}

if (pspinsim_run() == SPIN_SUCCESS) {
return GDRIVER_OK;
Expand Down
2 changes: 1 addition & 1 deletion examples/generic_driver/gdriver.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
16 changes: 9 additions & 7 deletions examples/histogram/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,18 +38,20 @@ uint32_t fill_packet(uint32_t msg_idx, uint32_t pkt_idx, uint8_t *pkt_buff, uint

int main(int argc, char**argv)
{
const char *handlers_file="build/histogram_l1";
const char *hh=NULL;
const char *ph="histogram_l1_ph";
const char *th="histogram_l1_th";
const char *handlers_file = "build/histogram_l1";
const char *hh = NULL;
const char *ph = "histogram_l1_ph";
const char *th = "histogram_l1_th";
int ectx_num;

srand(SEED);

gdriver_init(argc, argv);
gdriver_add_ectx(handlers_file, hh, ph, th, fill_packet, NULL, 42);
gdriver_init(argc, argv, NULL, &ectx_num);
gdriver_add_ectx(handlers_file, hh, ph, th, fill_packet, NULL, 0, NULL, 0);

gdriver_run();

gdriver_fini();

return 0;
}
17 changes: 9 additions & 8 deletions examples/host_direct/driver/driver.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 ETH Zurich
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,19 +15,20 @@
#include <stdint.h>
#include "gdriver.h"


int main(int argc, char**argv)
{
const char *handlers_file="build/hostdirect";
const char *hh=NULL;
const char *ph="hostdirect_ph";
const char *th=NULL;
const char *handlers_file = "build/hostdirect";
const char *hh = NULL;
const char *ph = "hostdirect_ph";
const char *th = NULL;
int ectx_num;

gdriver_init(argc, argv);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 42);
gdriver_init(argc, argv, NULL, &ectx_num);
gdriver_add_ectx(handlers_file, hh, ph, th, NULL, NULL, 0, NULL, 0);

gdriver_run();

gdriver_fini();

return 0;
}
Loading

0 comments on commit 7001a19

Please sign in to comment.