Esempio n. 1
0
int main(int argc, char *argv[]) {
  struct adafs_touch_state ts[2] = { ADAFS_TOUCH_STATE_INIT(LEN_BITS), ADAFS_TOUCH_STATE_INIT(LEN_BITS) };
  enum state s;
  double log_int;
  double timeout;

  if (argc != 4) {
    fprintf(stderr, "Usage: %s EventLog MultiThreshold IntervalThreshold\n",
        argv[0]);
    return -1;
  }
  
  freopen(argv[1], "r", stdin);
  THR_M = atof(argv[2]);
  THR_INT = atof(argv[3]);

  s = ST_CON;
  timeout = THR_INT;
  while (scanf("%lf", &log_int) == 1) {
    while (log_int > timeout) {
      log_int -= timeout;
      trace_event(EV_TIMER, log_int + timeout, s);
      timeout = transfer(ts, &s, EV_TIMER, log_int + timeout);
      trace_state(s, timeout);
    }
    trace_event(EV_USER, log_int, s);
    timeout = transfer(ts, &s, EV_USER, log_int);
    trace_state(s, timeout);
  }
  printf("%s:\t%d\t%d\t%f\t%f\n", argv[1],
      num_conflicts, num_pred, total_len, total_len/num_pred);
  return 0;
}
Esempio n. 2
0
void reference_solve_return_set(Reference *ref, Nonterminal *nt, int *result)
{
	Symbol *sb = ref->symbol;

	if(ref->status == REF_SOLVED) {
		//Ref already solved
		return;
	}

	BMapEntryAction *entry = bmap_action_get(&ref->state->actions, sb->id);
	Action *cont = entry? &entry->action: NULL;

	//There could be many references here:
	// * When the calling NT's end state matches the continuation, there
	//   could be many references to that terminal, we need the whole 
	//   follow set.
	// * When the continuation has its own references to other NT's.
	//   In this case those refs have to be solved to get the followset.

	// TODO: All references must be solved! missing continuation return refs
	if(cont && cont->state->status != STATE_CLEAR) {
		trace_state(
			"skip return ref to",
			cont->state,
			""
		);
		*result = REF_RESULT_PENDING;
		return;
	}

	//Solve reference
	trace_state(
		"append return ref to",
		cont->state,
		""
	);

	BMapCursorAction cursor;

	BMapAction action_set;
	bmap_action_init(&action_set);

	bmap_cursor_action_init(&cursor, &cont->state->actions);
	while(bmap_cursor_action_next(&cursor)) {
		BMapEntryAction *e = bmap_cursor_action_current(&cursor);
		_clone_rs_action(ref, &action_set, nt, e->key, &e->action);
	}
	bmap_cursor_action_dispose(&cursor);

	_merge_action_set(nt->end, &action_set);
	bmap_action_dispose(&action_set);

	ref->status = REF_SOLVED;
}
Esempio n. 3
0
void reference_solve_first_set(Reference *ref, int *result)
{
	if(ref->status == REF_SOLVED) {
		//ref already solved
		return;
	}

	if(ref->to_state->status != STATE_CLEAR) {
		trace_state(
			"skip first set from",
			ref->to_state,
			""
		);
		*result = REF_RESULT_PENDING;
		return;
	}

	//solve reference
	trace_state(
		"append first set from",
		ref->to_state,
		""
	);

	if(ref->type == REF_TYPE_COPY) {
		*result |= _clone_deep(ref);
	} else {
		// Add all cloned actions into a clone set, then merge the clone set
		// into the ref state. It's important to do this in two passes in 
		// order to avoid having collisions produced by the very actions we
		// are cloning.
		BMapAction action_set;
		bmap_action_init(&action_set);

		BMapCursorAction cursor;
		BMapEntryAction *entry;

		bmap_cursor_action_init(&cursor, &(ref->to_state->actions));
		while(bmap_cursor_action_next(&cursor)) {
			entry = bmap_cursor_action_current(&cursor);
			*result |= _clone_fs_action(&action_set, ref, entry->key, &entry->action);
		}
		bmap_cursor_action_dispose(&cursor);

		if(!(*result & REF_RESULT_PENDING)) {
			_merge_action_set(ref->state, &action_set);
			ref->status = REF_SOLVED;
		}

		bmap_action_dispose(&action_set);
	}
}
void ConcurrentMarkSweepThread::icms_wait() {
  assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
  if (_should_stop && icms_is_enabled()) {
    MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
    trace_state("pause_icms");
    _collector->stats().stop_cms_timer();
    while(!_should_run && icms_is_enabled()) {
      iCMS_lock->wait(Mutex::_no_safepoint_check_flag);
    }
    _collector->stats().start_cms_timer();
    _should_stop = false;
    trace_state("pause_icms end");
  }
}
// Incremental CMS
void ConcurrentMarkSweepThread::start_icms() {
  assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
  MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
  trace_state("start_icms");
  _should_run = true;
  iCMS_lock->notify_all();
}
void ConcurrentMarkSweepThread::stop_icms() {
  assert(UseConcMarkSweepGC && CMSIncrementalMode, "just checking");
  MutexLockerEx x(iCMS_lock, Mutex::_no_safepoint_check_flag);
  if (!_should_stop) {
    trace_state("stop_icms");
    _should_stop = true;
    _should_run = false;
    asynchronous_yield_request();
    iCMS_lock->notify_all();
  }
}
Esempio n. 7
0
static accelerometer_i quantize_accelerometer(accelerometer_d value, unsigned mask)
{
	return (accelerometer_i) {
		.x = quantize(value.x, mask),
		.y = quantize(value.y, mask),
		.z = quantize(value.z, mask),
		.q = quantize(value.q, mask),
	};
}

static vec3_i quantize_vec(vec3 value, unsigned mask)
{
	return (vec3_i) {
		.x = quantize(value.x, mask),
		.y = quantize(value.y, mask),
		.z = quantize(value.z, mask),
	};
}

static accelerometer_d add_accelerometer_noise(accelerometer_d value)
{
	return (accelerometer_d) {
		.x = value.x + gaussian(accelerometer_sd.x),
		.y = value.y + gaussian(accelerometer_sd.y),
		.z = value.z + gaussian(accelerometer_sd.z),
		.q = value.q + gaussian(accelerometer_sd.q),
	};
}

static vec3 vec_noise(vec3 value, vec3 sd)
{
	return (vec3) {
		.x = value.x + gaussian(sd.x),
		.y = value.y + gaussian(sd.y),
		.z = value.z + gaussian(sd.z),
	};
}

static void update_simulator(void)
{
	trace_state("sim", &rocket_state, ", %4.1f kg, %c%c%c\n",
	       mass,
	       engine_burning        ? 'B' : '-',
	       drogue_chute_deployed ? 'D' : '-',
	       main_chute_deployed   ? 'M' : '-');

	accelerometer_sensor(quantize_accelerometer(add_accelerometer_noise(accelerometer_measurement(&rocket_state)), 0xfff));
	if(t % 2000 == 0)
		gyroscope_sensor(quantize_vec(vec_noise(gyroscope_measurement(&rocket_state), gyroscope_sd), 0xfff));
	if(t % 100000 == 0)
		pressure_sensor(quantize(pressure_measurement(&rocket_state) + gaussian(pressure_sd), 0xfff));
	if(t % 100000 == 25000)
		magnetometer_sensor(quantize_vec(vec_noise(magnetometer_measurement(&rocket_state), magnetometer_sd), 0xfff));
	if(t % 100000 == 50000)
		gps_sensor(vec_noise(rocket_state.pos, gps_pos_sd),
		           vec_noise(rocket_state.vel, gps_vel_sd));

	if(!engine_ignited && t >= LAUNCH_TIME && last_reported_state() == STATE_ARMED)
	{
		trace_printf("Sending launch signal\n");
		launch();
	}
	if(engine_burning
	   && t - engine_ignition_time >= ENGINE_BURN_TIME)
	{
		trace_printf("Engine burn-out.\n");
		engine_burning = false;
	}
	if(last_reported_state() == STATE_PREFLIGHT)
	{
		trace_printf("Sending arm signal\n");
		arm();
	}
	if(engine_burning)
		mass -= FUEL_MASS * DELTA_T_SECONDS / (ENGINE_BURN_TIME / 1e6);

	geodetic pos = ECEF_to_geodetic(rocket_state.pos);
	if(pos.altitude <= initial_geodetic.altitude)
	{
		if(pos.altitude < initial_geodetic.altitude)
		{
			pos.altitude = initial_geodetic.altitude;
			rocket_state.pos = geodetic_to_ECEF(pos);
		}
		mat3 rot = make_LTP_rotation(pos);
		ground_clip(&rocket_state.vel, rot);
	}
}

static void init_rocket_state(struct rocket_state *rocket_state)
{
	/* TODO: accept an initial orientation for leaving the tower */
	mass = ROCKET_EMPTY_MASS + FUEL_MASS;
	rocket_state->pos = geodetic_to_ECEF(initial_geodetic);
	rocket_state->rotpos = make_LTP_rotation(initial_geodetic);
	rocket_state->acc = expected_acceleration(0, rocket_state);
}

int main(int argc, const char *const argv[])
{
	parse_trace_args(argc, argv);
	initial_geodetic = (geodetic) {
		.latitude = M_PI_2,
		.longitude = 0,
		.altitude = 0,
	};

	init_atmosphere(LAYER0_BASE_TEMPERATURE, LAYER0_BASE_PRESSURE);
	init_rocket_state(&rocket_state);
	init(initial_geodetic, rocket_state.rotpos);

	while(last_reported_state() != STATE_RECOVERY)
	{
		update_rocket_state_sim(&rocket_state, DELTA_T_SECONDS, expected_acceleration, (double)t);
		t += DELTA_T;
		update_simulator();
		tick(DELTA_T_SECONDS);
	}
	return 0;
}