ROSS
st-model-data.c
Go to the documentation of this file.
1 #include <ross.h>
2 
4 static int model_type_warned = 0;
5 
6 
7 // if model uses tw_lp_setup_types() to set lp->type, it will also call
8 // this function to set up the functions types for model-level data collection
9 // because this can make use of the already defined type mapping
11 {
12  if (g_st_model_types)
13  lp->model_types = &g_st_model_types[g_tw_lp_typemap(lp->gid)];
15  {
16  fprintf(stderr, "WARNING: node: %ld: %s:%i: ", g_tw_mynode, __FILE__, __LINE__);
17  fprintf(stderr, "The g_st_model_types has not been defined! No model level data will be collected\n");
19  }
20 
21 }
22 
23 // if model uses tw_lp_settypes(), model will also need to call
24 // this function to set up function types for model-level data collection
26 {
27  if (model_types)
28  {
29  tw_lp *lp = g_tw_lp[i];
31  }
33  {
34  fprintf(stderr, "WARNING: node: %ld: %s:%i: ", g_tw_mynode, __FILE__, __LINE__);
35  fprintf(stderr, "The struct st_model_types has not been defined for at least 1 LP type! No model level data will be collected for LP types without a valid st_model_types struct defined.\n");
37  }
38 }
39 
40 /*
41  * This function allows for ROSS to collect model level data, when not using Analysis LPs.
42  * Call this function when collecting simulation level data (GVT-based and/or real time-based).
43  * Loop through all LPs on this PE and collect stats
44  */
45 void st_collect_model_data(tw_pe *pe, double current_rt, int stats_type)
46 {
47  tw_clock start_cycle_time = tw_clock_read();
48  int index;
49  tw_lpid lpid = 0;
50  int total_sz = 0;
51  tw_lp *clp;
52  sample_metadata sample_md;
53  model_metadata model_md;
54  sample_md.flag = MODEL_TYPE;
55  sample_md.sample_sz = sizeof(model_md);
56  sample_md.real_time = current_rt;
57  model_md.peid = (unsigned int) g_tw_mynode;
58  model_md.gvt = (float) TW_STIME_DBL(pe->GVT);
59  model_md.stats_type = stats_type;
60 
61  for (lpid = 0; lpid < g_tw_nlp; lpid++)
62  {
63  index = 0;
64  clp = g_tw_lp[lpid];
65  if (!clp->model_types || !clp->model_types->model_stat_fn)
66  {
67  // may not want to collect model stats on every LP type, so if not defined, just continue
68  continue;
69  }
70 
71  sample_md.ts = tw_now(clp);
72  model_md.kpid = (unsigned int) clp->kp->id;
73  model_md.lpid = (unsigned int) clp->gid;
74  model_md.model_sz = (unsigned int) clp->model_types->mstat_sz;
75  total_sz = sizeof(sample_md) + sizeof(model_md) + model_md.model_sz;
76  char buffer[total_sz];
77  memcpy(&buffer[0], &sample_md, sizeof(sample_md));
78  index += sizeof(sample_md);
79  memcpy(&buffer[index], &model_md, sizeof(model_md));
80  index += sizeof(model_md);
81 
82  if (model_md.model_sz > 0)
83  {
84  (*clp->model_types->model_stat_fn)(clp->cur_state, clp, &buffer[index]);
85 
87  st_buffer_push(MODEL_COL, &buffer[0], total_sz);
89  fwrite(buffer, total_sz, 1, seq_model);
90  }
91  }
92  pe->stats.s_stat_comp += tw_clock_read() - start_cycle_time;
93 }
tw_synch g_tw_synchronization_protocol
Definition: ross-global.c:18
model_stat_f model_stat_fn
function pointer to collect model level data for RT and GVT-based instrumentation ...
st_model_types * g_st_model_types
Definition: st-model-data.c:3
static int model_type_warned
Definition: st-model-data.c:4
tw_lp ** g_tw_lp
Definition: ross-global.c:26
tw_statistics stats
per PE counters
Definition: ross-types.h:415
void st_model_setup_types(tw_lp *lp)
Definition: st-model-data.c:10
FILE * seq_model
void st_buffer_push(int type, char *data, int size)
size_t mstat_sz
size of data collected from model at sampling points
static tw_clock tw_clock_read(void)
Definition: aarch64.h:6
void st_collect_model_data(tw_pe *pe, double current_rt, int stats_type)
Definition: st-model-data.c:45
Holds the entire PE state.
Definition: ross-types.h:375
tw_lpid g_tw_nlp
Definition: ross-global.c:23
tw_clock s_stat_comp
Definition: ross-types.h:151
uint64_t tw_lpid
Definition: ross.h:160
tw_kp * kp
kp – Kernel process that we belong to (must match pe).
Definition: ross-types.h:313
tw_lpid gid
global LP id
Definition: ross-types.h:306
static tw_stime tw_now(tw_lp const *lp)
tw_peid g_tw_mynode
Definition: ross-global.c:88
void st_model_settype(tw_lpid i, st_model_types *model_types)
Definition: st-model-data.c:25
tw_peid g_tw_masternode
Definition: ross-global.c:89
unsigned int model_sz
tw_typemap_f g_tw_lp_typemap
Definition: ross-global.c:102
struct st_model_types * model_types
Definition: ross-types.h:322
tw_stime GVT
Global Virtual Time.
Definition: ross-types.h:403
tw_pe * pe
Definition: avl_tree.c:11
uint64_t tw_clock
Definition: aarch64.h:4
tw_kpid id
ID number, otherwise its not available to the app.
Definition: ross-types.h:341
void * cur_state
Current application LP data.
Definition: ross-types.h:315
int g_st_disable_out
st_model_types model_types[]
Definition: phold.c:142
#define TW_STIME_DBL(x)
Definition: ross.h:153
LP State Structure.
Definition: ross-types.h:304