The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
process.c
Go to the documentation of this file.
1 
32 #include <limits.h>
33 
34 #include <core/core.h>
35 #include <core/init.h>
36 #include <scheduler/process.h>
37 #include <scheduler/scheduler.h>
38 
39 // TODO: see issue #121 to see how to make this ugly hack disappear
40 __thread unsigned int __lp_counter = 0;
41 __thread unsigned int __lp_bound_counter = 0;
42 
44 struct lp_struct **lps_blocks = NULL;
45 
49 __thread struct lp_struct **lps_bound_blocks = NULL;
50 
51 void initialize_binding_blocks(void)
52 {
53  lps_bound_blocks =
54  (struct lp_struct **)rsalloc(n_prc * sizeof(struct lp_struct *));
55  bzero(lps_bound_blocks, sizeof(struct lp_struct *) * n_prc);
56 }
57 
58 void initialize_lps(void)
59 {
60  unsigned int i, j;
61  unsigned int lid = 0;
62  struct lp_struct *lp;
63  unsigned int local = 0;
64  GID_t gid;
65 
66  // First of all, determine what LPs should be locally hosted.
67  // Only for them, we are creating struct lp_structs here.
69 
70  // We now know how many LPs should be locally hosted. Prepare
71  // the place for their control blocks.
72  lps_blocks =
73  (struct lp_struct **)rsalloc(n_prc * sizeof(struct lp_struct *));
74 
75  // We now iterate over all LP Gids. Everytime that we find an LP
76  // which should be locally hosted, we create the local lp_struct
77  // process control block.
78  for (i = 0; i < n_prc_tot; i++) {
79  set_gid(gid, i);
80  if (find_kernel_by_gid(gid) != kid)
81  continue;
82 
83  // Initialize the control block for the current lp
84  lp = (struct lp_struct *)rsalloc(sizeof(struct lp_struct));
85  bzero(lp, sizeof(struct lp_struct));
86  lps_blocks[local++] = lp;
87 
88  if (local > n_prc) {
89  printf("reached local %d\n", local);
90  fflush(stdout);
91  abort();
92  }
93  // Initialize memory map
94  initialize_memory_map(lp);
95 
96  // Allocate memory for the outgoing buffer
99  rsalloc(sizeof(msg_t *) * INIT_OUTGOING_MSG);
100 
101  // Initialize bottom halves msg channel
102  lp->bottom_halves = init_channel();
103 
104  // We sequentially assign lids, and use the current gid
105  lp->lid.to_int = lid++;
106  lp->gid = gid;
107 
108  // Which version of OnGVT and ProcessEvent should we use?
110  lp->OnGVT = &OnGVT_light;
111  lp->ProcessEvent = &ProcessEvent_light;
112  } // TODO: add here an else for ISS
113 
114  // Allocate LP stack
115  lp->stack = get_ult_stack(LP_STACK_SIZE);
116 
117  // Set the initial checkpointing period for this LP.
118  // If the checkpointing period is fixed, this will not change during the
119  // execution. Otherwise, new calls to this function will (locally) update
120  // this.
122 
123  // Initially, every LP is ready
124  lp->state = LP_STATE_READY;
125 
126  // There is no current state layout at the beginning
127  lp->current_base_pointer = NULL;
128 
129  // Initialize the queues
130  lp->queue_in = new_list(msg_t);
131  lp->queue_out = new_list(msg_hdr_t);
132  lp->queue_states = new_list(state_t);
133  lp->rendezvous_queue = new_list(msg_t);
134 
135  // No event has been processed so far
136  lp->bound = NULL;
137 
138  // We have no information about messages still to be delivered to this LP
139  lp->outgoing_buffer.min_in_transit = rsalloc(sizeof(simtime_t) * n_cores);
140  for (j = 0; j < n_cores; j++) {
142  }
143 
144 #ifdef HAVE_CROSS_STATE
145  // No read/write dependencies open so far for the LP. The current lp is always opened
146  lp->ECS_index = 0;
147  lp->ECS_synch_table[0] = LidToGid(lp); // LidToGid for distributed ECS
148 #endif
149 
150  // Create User-Level Thread
151  context_create(&lp->context, LP_main_loop, NULL, lp->stack,
152  LP_STACK_SIZE);
153  }
154 }
155 
156 // This works only for locally-hosted LPs!
157 struct lp_struct *find_lp_by_gid(GID_t gid)
158 {
159  foreach_lp(lp) {
160  if (lp->gid.to_int == gid.to_int)
161  return lp;
162  }
163  return NULL;
164 }
void context_create(exec_context_t *creat, void(*fn)(void *), void *args, void *stack, size_t stack_size)
msg_t * bound
Pointer to the last correctly processed event.
Definition: process.h:106
Initialization routines.
Structure for LP&#39;s state.
Definition: state.h:49
struct lp_struct ** lps_blocks
Maintain LPs&#39; simulation and execution states.
Definition: process.c:44
Core ROOT-Sim functionalities.
unsigned int n_cores
Total number of cores required for simulation.
Definition: core.c:61
unsigned int max_size
Total space in outgoing_msgs.
int ckpt_period
Number of events to execute before taking a snapshot in PSS (ignored otherwise)
Definition: init.h:66
msg_channel * bottom_halves
Bottom halves.
Definition: process.h:115
void * stack
Process&#39; stack.
Definition: process.h:73
unsigned int to_int
The LID numerical value.
Definition: core.h:145
unsigned int to_int
The GID numerical value.
Definition: core.h:133
The ROOT-Sim scheduler main module header.
#define INIT_OUTGOING_MSG
unsigned int find_kernel_by_gid(GID_t gid)
Definition: core.c:164
#define INFTY
Infinite timestamp: this is the highest timestamp in a simulation run.
Definition: ROOT-Sim.h:58
void LP_main_loop(void *args)
Definition: scheduler.c:140
double simtime_t
This defines the type with whom timestamps are represented.
Definition: ROOT-Sim.h:55
simulation_configuration rootsim_config
This global variable holds the configuration for the current simulation.
Definition: core.c:70
Message Type definition.
Definition: core.h:164
bool(* OnGVT)(unsigned int me, void *snapshot)
Definition: process.h:130
#define new_list(type)
Definition: list.h:59
__thread struct lp_struct ** lps_bound_blocks
Definition: process.c:49
void * get_ult_stack(size_t size)
Definition: ult.c:65
LP control blocks.
Definition of a GID.
Definition: core.h:132
outgoing_t outgoing_buffer
Buffer used by KLTs for buffering outgoing messages during the execution of an event.
Definition: process.h:124
GID_t gid
Global ID of the LP.
Definition: process.h:82
short unsigned int state
Current execution state of the LP.
Definition: process.h:88
unsigned int n_prc
Number of logical processes hosted by the current kernel instance.
Definition: core.c:67
LP_context_t context
LP execution state.
Definition: process.h:67
void(* ProcessEvent)(unsigned int me, simtime_t now, int event_type, void *event_content, unsigned int size, void *state)
Definition: process.h:136
LID_t lid
Local ID of the LP.
Definition: process.h:79
Message envelope definition. This is used to handle the output queue and stores information needed to...
Definition: core.h:194
msg_t ** outgoing_msgs
Resizable array of message pointers.
simtime_t * min_in_transit
Smallest timestamp of events kept here.
int snapshot
Type of snapshot (e.g., full, incremental, autonomic, ...)
Definition: init.h:67
void set_checkpoint_period(struct lp_struct *lp, int period)
Definition: state.c:349
unsigned int n_prc_tot
Total number of logical processes running in the simulation.
Definition: core.c:64
void * current_base_pointer
The current state base pointer (updated by SetState())
Definition: process.h:100
unsigned int kid
Identifier of the local kernel.
Definition: core.c:55
void distribute_lps_on_kernels(void)
Definition: core.c:258