if (current_variable->address != NULL) {
new_var->address = current_variable->address;
} else if (current_variable->locations.size != 0) {
- new_var->address =
- (void *) mc_dwarf_resolve_locations(¤t_variable->locations,
+ s_mc_location_t location;
+ mc_dwarf_resolve_locations(&location, ¤t_variable->locations,
current_variable->object_info,
&(stack_frame->unw_cursor),
(void *) stack_frame->frame_base,
NULL, process_index);
+
+ switch(mc_get_location_type(&location)) {
+ case MC_LOCATION_TYPE_ADDRESS:
+ new_var->address = location.memory_location;
+ break;
+ case MC_LOCATION_TYPE_REGISTER:
+ default:
+ xbt_die("Cannot handle non-address variable");
+ }
+
} else {
xbt_die("No address");
}
/** \brief Resolve a location expression
* \deprecated Use mc_dwarf_resolve_expression
*/
-uintptr_t mc_dwarf_resolve_location(mc_expression_t expression,
- mc_object_info_t object_info,
- unw_cursor_t * c,
- void *frame_pointer_address,
- mc_snapshot_t snapshot, int process_index)
+void mc_dwarf_resolve_location(mc_location_t location,
+ mc_expression_t expression,
+ mc_object_info_t object_info,
+ unw_cursor_t * c,
+ void *frame_pointer_address,
+ mc_snapshot_t snapshot, int process_index)
{
s_mc_expression_state_t state;
memset(&state, 0, sizeof(s_mc_expression_state_t));
state.object_info = object_info;
state.process_index = process_index;
+ if (expression->size >= 1
+ && expression->ops[0].atom >=DW_OP_reg0 && expression->ops[0].atom <= DW_OP_reg31) {
+ int dwarf_register = expression->ops[0].atom - DW_OP_reg0;
+ xbt_assert(c, "Missing frame context for register operation DW_OP_reg%i",
+ dwarf_register);
+ location->memory_location = NULL;
+ location->cursor = c;
+ location->register_id = mc_dwarf_register_to_libunwind(dwarf_register);
+ return;
+ }
+
if (mc_dwarf_execute_expression(expression->size, expression->ops, &state))
xbt_die("Error evaluating DWARF expression");
if (state.stack_size == 0)
xbt_die("No value on the stack");
- else
- return state.stack[state.stack_size - 1];
+ else {
+ location->memory_location = (void*) state.stack[state.stack_size - 1];
+ location->cursor = NULL;
+ location->register_id = 0;
+ }
+}
+
+static mc_expression_t mc_find_expression(mc_location_list_t locations, unw_word_t ip) {
+ for (size_t i = 0; i != locations->size; ++i) {
+ mc_expression_t expression = locations->locations + i;
+ if ((expression->lowpc == NULL && expression->highpc == NULL)
+ || (ip && ip >= (unw_word_t) expression->lowpc
+ && ip < (unw_word_t) expression->highpc)) {
+ return expression;
+ }
+ }
+ return NULL;
}
-uintptr_t mc_dwarf_resolve_locations(mc_location_list_t locations,
+void mc_dwarf_resolve_locations(mc_location_t location,
+ mc_location_list_t locations,
mc_object_info_t object_info,
unw_cursor_t * c,
void *frame_pointer_address,
mc_snapshot_t snapshot, int process_index)
{
- unw_word_t ip;
+ unw_word_t ip = 0;
if (c) {
if (unw_get_reg(c, UNW_REG_IP, &ip))
xbt_die("Could not resolve IP");
}
- for (size_t i = 0; i != locations->size; ++i) {
- mc_expression_t expression = locations->locations + i;
- if ((expression->lowpc == NULL && expression->highpc == NULL)
- || (c && ip >= (unw_word_t) expression->lowpc
- && ip < (unw_word_t) expression->highpc)) {
- return mc_dwarf_resolve_location(expression, object_info, c,
- frame_pointer_address, snapshot, process_index);
- }
+ mc_expression_t expression = mc_find_expression(locations, ip);
+ if (expression) {
+ mc_dwarf_resolve_location(location,
+ expression, object_info, c,
+ frame_pointer_address, snapshot, process_index);
+ } else {
+ xbt_die("Could not resolve location");
}
- xbt_die("Could not resolve location");
}
/** \brief Find the frame base of a given frame
void *mc_find_frame_base(dw_frame_t frame, mc_object_info_t object_info,
unw_cursor_t * unw_cursor)
{
- return (void *) mc_dwarf_resolve_locations(&frame->frame_base, object_info,
- unw_cursor, NULL, NULL, -1);
+ s_mc_location_t location;
+ mc_dwarf_resolve_locations(&location,
+ &frame->frame_base, object_info,
+ unw_cursor, NULL, NULL, -1);
+ switch(mc_get_location_type(&location)) {
+ case MC_LOCATION_TYPE_ADDRESS:
+ return location.memory_location;
+
+ case MC_LOCATION_TYPE_REGISTER: {
+ // This is a special case.
+ // The register if not the location of the frame base
+ // (a frame base cannot be located in a register)
+ // Instead, DWARF defines this to mean that the register
+ // contains the address of the frame base.
+ unw_word_t word;
+ unw_get_reg(location.cursor, location.register_id, &word);
+ return (void*) word;
+ }
+
+ default:
+ xbt_die("Cannot handle non-address frame base");
+ return NULL; // Unreachable
+ }
}
void mc_dwarf_expression_clear(mc_expression_t expression)
mc_expression_t locations;
} s_mc_location_list_t, *mc_location_list_t;
-uintptr_t mc_dwarf_resolve_location(mc_expression_t expression, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_snapshot_t snapshot, int process_index);
-uintptr_t mc_dwarf_resolve_locations(mc_location_list_t locations, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_snapshot_t snapshot, int process_index);
+/** A location is either a location in memory of a register location
+ *
+ * Usage:
+ *
+ * * mc_dwarf_resolve_locations or mc_dwarf_resolve_location is used
+ * to find the location of a given location expression or location list;
+ *
+ * * mc_get_location_type MUST be used to find the location type;
+ *
+ * * for MC_LOCATION_TYPE_ADDRESS, memory_address is the resulting address
+ *
+ * * for MC_LOCATION_TYPE_REGISTER, unw_get_reg(l.cursor, l.register_id, value)
+ * and unw_get_reg(l.cursor, l.register_id, value) can be used to read/write
+ * the value.
+ * </ul>
+ */
+typedef struct s_mc_location {
+ void* memory_location;
+ unw_cursor_t* cursor;
+ int register_id;
+} s_mc_location_t, *mc_location_t;
+
+/** Type of a given location
+ *
+ * Use `mc_get_location_type(location)` to find the type.
+ * */
+typedef enum mc_location_type {
+ MC_LOCATION_TYPE_ADDRESS,
+ MC_LOCATION_TYPE_REGISTER
+} mc_location_type;
+
+/** Find the type of a location */
+static inline __attribute__ ((always_inline))
+enum mc_location_type mc_get_location_type(mc_location_t location) {
+ if (location->cursor) {
+ return MC_LOCATION_TYPE_REGISTER;
+ } else {
+ return MC_LOCATION_TYPE_ADDRESS;
+ }
+}
+
+void mc_dwarf_resolve_location(mc_location_t location, mc_expression_t expression, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_snapshot_t snapshot, int process_index);
+void mc_dwarf_resolve_locations(mc_location_t location, mc_location_list_t locations, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_snapshot_t snapshot, int process_index);
void mc_dwarf_expression_clear(mc_expression_t expression);
void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops);
container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
- val_t value = PJ_value_get ("start", type);
+ val_t value = PJ_value_get_or_new ("start", "0 0 1", type); //start is blue
new_pajePushState (MSG_get_clock(), vm_container, type, value);
}
container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
- val_t value = PJ_value_get ("suspend", type);
+ val_t value = PJ_value_get_or_new ("suspend", "1 0 0", type); //suspend is red
new_pajePushState (MSG_get_clock(), vm_container, type, value);
}
}
container_t vm_container = PJ_container_get (instr_vm_id(vm, str, len));
type_t type = PJ_type_get ("MSG_VM_STATE", vm_container->type);
- val_t value = PJ_value_get ("save", type);
+ val_t value = PJ_value_get_or_new ("save", "0 1 0", type); //save is green
new_pajePushState (MSG_get_clock(), vm_container, type, value);
}
}
double s_par_proc=0,s_seq_proc=0; /*Standard deviation of number of processes computed in par/seq during the current simulation*/
double avg_par_proc=0,sd_par_proc=0;
double avg_seq_proc=0,sd_seq_proc=0;
-double par_window=4294967296,seq_window=0; /*par_window is initially 1<<32*/
+double par_window=HUGE_VAL,seq_window=0; /*par_window is initially 1<<32*/
#endif
static unsigned long raw_process_index = 0; /* index of the next process to run in the
par_ratio = (par_proc_that_ran != 0) ? (par_time / (double)par_proc_that_ran) : 0;
seq_ratio = (seq_proc_that_ran != 0) ? (seq_time / (double)seq_proc_that_ran) : 0;
if(seq_ratio > par_ratio){
- if(nb_processes < avg_par_proc) {
+ if(nb_processes < avg_par_proc) {
threshold = (threshold>2) ? threshold - 1 : threshold ;
SIMIX_context_set_parallel_threshold(threshold);
}
}
}
- //XBT_CRITICAL("Thres: %d.", SIMIX_context_get_parallel_threshold());
-
if (nb_processes >= SIMIX_context_get_parallel_threshold()) {
simix_global->context_factory->suspend = smx_ctx_raw_suspend_parallel;
if(nb_processes < par_window){
par_time += xbt_os_timer_elapsed(round_time);
prev_avg_par_proc = avg_par_proc;
- delta = (nb_processes-avg_par_proc);
+ delta = nb_processes - avg_par_proc;
avg_par_proc = (par_sched_round==1) ? nb_processes : avg_par_proc + delta / (double) par_sched_round;
if(par_sched_round>=2){
- s_par_proc = sd_par_proc + (nb_processes - prev_avg_par_proc)*delta;
- sd_par_proc = sqrt(s_par_proc/(par_sched_round-1));
- par_window = avg_par_proc + sd_par_proc;
+ s_par_proc = s_par_proc + (nb_processes - prev_avg_par_proc) * delta;
+ sd_par_proc = sqrt(s_par_proc / (par_sched_round-1));
+ par_window = (int) (avg_par_proc + sd_par_proc);
}else{
sd_par_proc = 0;
}
avg_seq_proc = (seq_sched_round==1) ? nb_processes : avg_seq_proc + delta / (double) seq_sched_round;
if(seq_sched_round>=2){
- s_seq_proc = sd_seq_proc + (nb_processes - prev_avg_seq_proc)*delta;
- sd_seq_proc = sqrt(s_seq_proc/(seq_sched_round-1));
- seq_window = avg_seq_proc - sd_seq_proc;
+ s_seq_proc = s_seq_proc + (nb_processes - prev_avg_seq_proc)*delta;
+ sd_seq_proc = sqrt(s_seq_proc / (seq_sched_round-1));
+ seq_window = (int) (avg_seq_proc - sd_seq_proc);
} else {
sd_seq_proc = 0;
}
*/
static int allocated_junk = 0; /* keep track of many blocks of our little area was already given to someone */
#define JUNK_SIZE 8
-#define MAX_JUNK_AREAS (32 * 1024 / JUNK_SIZE)
+#define MAX_JUNK_AREAS (64 * 1024 / JUNK_SIZE)
static char junkareas[MAX_JUNK_AREAS][JUNK_SIZE];
/* This version use mmalloc if there is a current heap, or the legacy implem if not */
{
if (p==NULL)
return;
- if (p<=(void*)junkareas || p>(void*)(junkareas[MAX_JUNK_AREAS]) ) {
+ if (p<(void*)junkareas || p>=(void*)(junkareas[MAX_JUNK_AREAS]) ) {
+ // main use case
+
xbt_mheap_t mdp = __mmalloc_current_heap;
if (mdp) {
} else {
real_free(p);
}
- } else if(allocated_junk && p==junkareas[allocated_junk-1]) {
- allocated_junk--;
} else {
- // Leaked memory.
+ // We are in the junkarea.
+ // This area is used to allocate memory at initilization time.
+
+ if(allocated_junk && p==junkareas[allocated_junk-1]) {
+ // Last junkarea. We can reuse it.
+ allocated_junk--;
+ } else {
+ // We currently cannot reuse freed junkareas in the general case.
+ }
}
}
assert(var);
void* frame_base = mc_find_frame_base(subprogram, info, cursor);
- xbt_assert((void*)mc_dwarf_resolve_locations(&var->locations, info, cursor, frame_base, NULL, -1) == address,
+ s_mc_location_t location;
+
+ mc_dwarf_resolve_locations(&location,
+ &var->locations, info, cursor, frame_base, NULL, -1);
+
+ xbt_assert(mc_get_location_type(&location)==MC_LOCATION_TYPE_ADDRESS,
+ "Unexpected location type for variable %s of %s", variable, function);
+
+ xbt_assert(location.memory_location == address,
"Bad resolution of local variable %s of %s", variable, function);
}