Beispiel #1
0
void timer_spin_sleep_bios(int ms) {
	
	uint32 before, cur, cnt = 782 * ms;
	before = timer_count(TMU0);
	
	do {
		cur = before - timer_count(TMU0);
	} while(cur < cnt);
}
Beispiel #2
0
static void timer_diag_coalescing(TimerSlack slack, const zx_time_t* deadline,
                                  const zx_duration_t* expected_adj, size_t count) {
    printf("testing coalsecing mode %u\n", slack.mode());

    fbl::atomic<size_t> timer_count(0);

    timer_t* timer = (timer_t*)malloc(sizeof(timer_t) * count);

    printf("       orig         new       adjustment\n");
    for (size_t ix = 0; ix != count; ++ix) {
        timer_init(&timer[ix]);
        const Deadline dl(deadline[ix], slack);
        timer_set(&timer[ix], dl, timer_diag_cb2, &timer_count);
        printf("[%zu] %" PRIi64 "  -> %" PRIi64 ", %" PRIi64 "\n",
               ix, dl.when(), timer[ix].scheduled_time, timer[ix].slack);

        if (timer[ix].slack != expected_adj[ix]) {
            printf("\n!! unexpected adjustment! expected %" PRIi64 "\n", expected_adj[ix]);
        }
    }

    // Wait for the timers to fire.
    while (timer_count.load() != count) {
        thread_sleep(current_time() + ZX_MSEC(5));
    }

    free(timer);
}
Beispiel #3
0
/**
 * Streaming callback to format our output
 */
static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) {
    #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1;
    struct timeval *tv = data;
    switch (type) {
        case KEY_VAL:
            STREAM("kv.%s|%f|%lld\n", name, *(double*)value);
            break;

        case COUNTER:
            STREAM("counts.%s|%f|%lld\n", name, counter_sum(value));
            break;

        case TIMER:
            STREAM("timers.%s.sum|%f|%lld\n", name, timer_sum(value));
            STREAM("timers.%s.mean|%f|%lld\n", name, timer_mean(value));
            STREAM("timers.%s.lower|%f|%lld\n", name, timer_min(value));
            STREAM("timers.%s.upper|%f|%lld\n", name, timer_max(value));
            STREAM("timers.%s.count|%lld|%lld\n", name, timer_count(value));
            STREAM("timers.%s.stdev|%f|%lld\n", name, timer_stddev(value));
            STREAM("timers.%s.median|%f|%lld\n", name, timer_query(value, 0.5));
            STREAM("timers.%s.p95|%f|%lld\n", name, timer_query(value, 0.95));
            STREAM("timers.%s.p99|%f|%lld\n", name, timer_query(value, 0.99));
            break;

        default:
            syslog(LOG_ERR, "Unknown metric type: %d", type);
            break;
    }
    return 0;
}
Beispiel #4
0
static int stream_formatter_bin(FILE *pipe, void *data, metric_type type, char *name, void *value) {
    #define STREAM_BIN(...) if (stream_bin_writer(pipe, ((struct timeval *)data)->tv_sec, __VA_ARGS__, name)) return 1;
    #define STREAM_UINT(val) if (!fwrite(&val, sizeof(unsigned int), 1, pipe)) return 1;
    timer_hist *t;
    int i;
    switch (type) {
        case KEY_VAL:
            STREAM_BIN(BIN_TYPE_KV, BIN_OUT_NO_TYPE, *(double*)value);
            break;

        case GAUGE:
            STREAM_BIN(BIN_TYPE_GAUGE, BIN_OUT_NO_TYPE, ((gauge_t*)value)->value);
            break;

        case COUNTER:
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM, counter_sum(value));
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM_SQ, counter_squared_sum(value));
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MEAN, counter_mean(value));
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_COUNT, counter_count(value));
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_STDDEV, counter_stddev(value));
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MIN, counter_min(value));
            STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MAX, counter_max(value));
            break;

        case SET:
            STREAM_BIN(BIN_TYPE_SET, BIN_OUT_SUM, set_size(value));
            break;

        case TIMER:
            t = (timer_hist*)value;
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM, timer_sum(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM_SQ, timer_squared_sum(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MEAN, timer_mean(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_COUNT, timer_count(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_STDDEV, timer_stddev(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MIN, timer_min(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MAX, timer_max(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | 50, timer_query(&t->tm, 0.5));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | 95, timer_query(&t->tm, 0.95));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | 99, timer_query(&t->tm, 0.99));

            // Binary streaming for histograms
            if (t->conf) {
                STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_FLOOR, t->conf->min_val);
                STREAM_UINT(t->counts[0]);
                for (i=0; i < t->conf->num_bins-2; i++) {
                    STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_BIN, t->conf->min_val+(t->conf->bin_width*i));
                    STREAM_UINT(t->counts[i+1]);
                }
                STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_CEIL, t->conf->max_val);
                STREAM_UINT(t->counts[i+1]);
            }
            break;

        default:
            syslog(LOG_ERR, "Unknown metric type: %d", type);
            break;
    }
    return 0;
}
Beispiel #5
0
static void timer_event_set_mode(enum clock_event_mode mode, struct clock_event_device *evt)
{
	struct timer_info *info = tm_event_info();
	int ch = info->channel;
	unsigned long cnt = info->tcount;
	pr_debug("%s (ch:%d, mode:0x%x, cnt:%ld)\n", __func__, ch, mode, cnt);

	switch(mode) {
	case CLOCK_EVT_MODE_UNUSED:		// 0x0
	case CLOCK_EVT_MODE_ONESHOT:	// 0x3
		break;
	case CLOCK_EVT_MODE_SHUTDOWN:	// 0x1
		timer_stop(ch, 0);
		break;
	case CLOCK_EVT_MODE_RESUME:		// 0x4
		timer_event_resume(info);
	case CLOCK_EVT_MODE_PERIODIC:	// 0x2
		timer_stop (ch, 0);
		timer_count(ch, cnt);
		timer_start(ch, 1);
		break;
	default:
		break;
	}
}
Beispiel #6
0
static int __init timer_source_init(int ch)
{
	struct clocksource *cs = &tm_source_clk;
	struct timer_info *info = tm_source_info();

	info->channel = ch;
	info->irqno = -1;
	timer_clock_select(info, TIMER_CLOCK_SOURCE_HZ);

	/*
	 * register timer source
	 */
	clocksource_register_hz(cs, info->rate);

	pr_debug("timer.%d: source shift =%u  \n", ch, cs->shift);
	pr_debug("timer.%d: source mult  =%u  \n", ch, cs->mult);

	/*
	 * source timer run
	 */
	info->tcount = -1UL;
	timer_reset(ch);
	timer_stop (ch, 0);
	timer_clock(ch, info->tmmux, info->prescale);
	timer_count(ch, info->tcount + 1);
	timer_start(ch, 0);

	__timer_sys_mux_val = info->tmmux;
	__timer_sys_scl_val = info->prescale;
	__timer_sys_clk_clr = readl(TIMER_SYS_CLKGEN + CLKGEN_CLR);
	printk("timer.%d: source, %9lu(HZ:%d), mult:%u\n", ch, info->rate, HZ, cs->mult);
 	return 0;
}
Beispiel #7
0
static VALUE strstat_timer_count(VALUE self) {
  timer *i_timer;

  i_timer = (timer*) strstat_get_struct(self);

  return LONG2NUM(timer_count(i_timer));
}
Beispiel #8
0
void release_opencl()
{
  DTIMER_START(T_RELEASE);

  clReleaseMemObject(pgq);
  clReleaseMemObject(pgsx);
  clReleaseMemObject(pgsy);

  clReleaseKernel(kernel);
  clReleaseProgram(program);
  clReleaseCommandQueue(cmd_queue);
  clReleaseContext(context);

  DTIMER_STOP(T_RELEASE);

#ifdef TIMER_DETAIL
  if (timers_enabled) {
    int i;
    double tt;
    double t_opencl = 0.0, t_buffer = 0.0, t_kernel = 0.0;
    unsigned cnt;

    for (i = T_OPENCL_API; i < T_END; i++)
      t_opencl += timer_read(i);

    for (i = T_BUFFER_CREATE; i <= T_BUFFER_WRITE; i++)
      t_buffer += timer_read(i);

    for (i = T_KERNEL_EMBAR; i <= T_KERNEL_EMBAR; i++)
      t_kernel += timer_read(i);

    printf("\nOpenCL timers -\n");
    printf("Kernel    : %9.3f (%.2f%%)\n", 
        t_kernel, t_kernel/t_opencl * 100.0);

    cnt = timer_count(T_KERNEL_EMBAR);
    tt = timer_read(T_KERNEL_EMBAR);
    printf("- embar   : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    printf("Buffer    : %9.3lf (%.2f%%)\n",
        t_buffer, t_buffer/t_opencl * 100.0);
    printf("- creation: %9.3lf\n", timer_read(T_BUFFER_CREATE));
    printf("- read    : %9.3lf\n", timer_read(T_BUFFER_READ));
    printf("- write   : %9.3lf\n", timer_read(T_BUFFER_WRITE));

    tt = timer_read(T_OPENCL_API);
    printf("API       : %9.3lf (%.2f%%)\n", tt, tt/t_opencl * 100.0);

    tt = timer_read(T_BUILD);
    printf("BUILD     : %9.3lf (%.2f%%)\n", tt, tt/t_opencl * 100.0);

    tt = timer_read(T_RELEASE);
    printf("RELEASE   : %9.3lf (%.2f%%)\n", tt, tt/t_opencl * 100.0);

    printf("Total     : %9.3lf\n", t_opencl);
  }
#endif
}
Beispiel #9
0
/*
 * Get system time - return ticks since OS boot.
 */
int
sys_time(u_long *ticks)
{
    u_long t;

    t = timer_count();
    return umem_copyout(&t, ticks, sizeof(t));
}
Beispiel #10
0
static void print_kernel_time(double t_kernel, int i)
{
  char *name = kernel_names[i - T_BUFFER_WRITE - 1];
  unsigned cnt = timer_count(i);
  if (cnt == 0) return;
  double tt = timer_read(i);
  printf("- %-11s: %9.3lf (%u, %.3f, %.2f%%)\n",
      name, tt, cnt, tt/cnt, tt/t_kernel * 100.0);
}
Beispiel #11
0
/**
 * Streaming callback to format our output
 */
static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) {
    #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1;
    struct timeval *tv = data;
    timer_hist *t;
    int i;
    switch (type) {
        case KEY_VAL:
            STREAM("%s|%f|%lld\n", name, *(double*)value);
            break;

        case GAUGE:
            STREAM("%s|%f|%lld\n", name, ((gauge_t*)value)->value);
            break;

        case COUNTER:
            STREAM("%s|%f|%lld\n", name, counter_sum(value));
            break;

        case SET:
            STREAM("%s|%lld|%lld\n", name, set_size(value));
            break;

        case TIMER:
            t = (timer_hist*)value;
            STREAM("timers.%s.sum|%f|%lld\n", name, timer_sum(&t->tm));
            STREAM("timers.%s.sum_sq|%f|%lld\n", name, timer_squared_sum(&t->tm));
            STREAM("timers.%s.mean|%f|%lld\n", name, timer_mean(&t->tm));
            STREAM("timers.%s.lower|%f|%lld\n", name, timer_min(&t->tm));
            STREAM("timers.%s.upper|%f|%lld\n", name, timer_max(&t->tm));
            STREAM("timers.%s.count|%lld|%lld\n", name, timer_count(&t->tm));
            STREAM("timers.%s.stdev|%f|%lld\n", name, timer_stddev(&t->tm));
            STREAM("timers.%s.median|%f|%lld\n", name, timer_query(&t->tm, 0.5));
            STREAM("timers.%s.upper_90|%f|%lld\n", name, timer_query(&t->tm, 0.9));
            STREAM("timers.%s.upper_95|%f|%lld\n", name, timer_query(&t->tm, 0.95));
            STREAM("timers.%s.upper_99|%f|%lld\n", name, timer_query(&t->tm, 0.99));

            // Stream the histogram values
            if (t->conf) {
                STREAM("%s.histogram.bin_<%0.2f|%u|%lld\n", name, t->conf->min_val, t->counts[0]);
                for (i=0; i < t->conf->num_bins-2; i++) {
                    STREAM("%s.histogram.bin_%0.2f|%u|%lld\n", name, t->conf->min_val+(t->conf->bin_width*i), t->counts[i+1]);
                }
                STREAM("%s.histogram.bin_>%0.2f|%u|%lld\n", name, t->conf->max_val, t->counts[i+1]);
            }
            break;

        default:
            syslog(LOG_ERR, "Unknown metric type: %d", type);
            break;
    }
    return 0;
}
Beispiel #12
0
static void timer_source_resume(struct clocksource *cs)
{
	struct timer_info *info = tm_source_info();
	int ch = info->channel;
	ulong flags;

	local_irq_save(flags);

	if (info->in_tclk) {
		clk_set_rate(info->clk, info->rate);
		clk_enable(info->clk);
	}

	timer_reset(ch);
	timer_stop (ch, 0);
	timer_clock(ch, info->tmmux, info->prescale);
	timer_count(ch, info->rcount + 1);	/* restore count */
	timer_start(ch, 0);
	timer_count(ch, info->tcount + 1);	/* next count */

	local_irq_restore(flags);
}
Beispiel #13
0
static int timer_event_set_next(unsigned long delta, struct clock_event_device *evt)
{
	struct timer_info *info = tm_event_info();
	int ch = info->channel;
	ulong flags;

	pr_debug("%s (ch:%d,delta:%ld)\n", __func__, ch, delta);
	raw_local_irq_save(flags);

	timer_stop (ch, 0);
	timer_count(ch, delta);
	timer_start(ch, 1);

	raw_local_irq_restore(flags);
	return 0;
}
Beispiel #14
0
inline void mc68901_device::timer_input(int index, int value)
{
	int bit = GPIO_TIMER[index];
	int aer = BIT(m_aer, bit);
	int cr = index ? m_tbcr : m_tacr;

	switch (cr & 0x0f)
	{
	case TCR_TIMER_EVENT:
		if (((m_ti[index] ^ aer) == 1) && ((value ^ aer) == 0))
		{
			timer_count(index);
		}

		m_ti[index] = value;
		break;

	case TCR_TIMER_PULSE_4:
	case TCR_TIMER_PULSE_10:
	case TCR_TIMER_PULSE_16:
	case TCR_TIMER_PULSE_50:
	case TCR_TIMER_PULSE_64:
	case TCR_TIMER_PULSE_100:
	case TCR_TIMER_PULSE_200:
		m_timer[index]->enable((value == aer));

		if (((m_ti[index] ^ aer) == 0) && ((value ^ aer) == 1))
		{
			if (m_ier & INT_MASK_GPIO[bit])
			{
				take_interrupt(INT_MASK_GPIO[bit]);
			}
		}

		m_ti[index] = value;
		break;
	}
}
Beispiel #15
0
void z80sti_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	timer_count(id);
}
Beispiel #16
0
int main()
{
	float gyro[3], accel[3], mag[3];
	float vel[3] = { 0, 0, 0 };
	/* Normaly we get/set UAVObjects but this one only needs to be set.
	We will never expect to get this from another module*/
	AttitudeActualData attitude_actual;
	AHRSSettingsData ahrs_settings;

	/* Brings up System using CMSIS functions, enables the LEDs. */
	PIOS_SYS_Init();

	/* Delay system */
	PIOS_DELAY_Init();

	/* Communication system */
	PIOS_COM_Init();

	/* ADC system */
	AHRS_ADC_Config( adc_oversampling );

	/* Setup the Accelerometer FS (Full-Scale) GPIO */
	PIOS_GPIO_Enable( 0 );
	SET_ACCEL_2G;
#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
	/* Magnetic sensor system */
	PIOS_I2C_Init();
	PIOS_HMC5843_Init();

	// Get 3 ID bytes
	strcpy(( char * )mag_data.id, "ZZZ" );
	PIOS_HMC5843_ReadID( mag_data.id );
#endif

	/* SPI link to master */
//	PIOS_SPI_Init();
	AhrsInitComms();
	AHRSCalibrationConnectCallback( calibration_callback );
	GPSPositionConnectCallback( gps_callback );

	ahrs_state = AHRS_IDLE;

	while( !AhrsLinkReady() ) {
		AhrsPoll();
		while( ahrs_state != AHRS_DATA_READY ) ;
		ahrs_state = AHRS_PROCESSING;
		downsample_data();
		ahrs_state = AHRS_IDLE;
		if(( total_conversion_blocks % 50 ) == 0 )
			PIOS_LED_Toggle( LED1 );
	}


	AHRSSettingsGet(&ahrs_settings);


	/* Use simple averaging filter for now */
	for( int i = 0; i < adc_oversampling; i++ )
		fir_coeffs[i] = 1;
	fir_coeffs[adc_oversampling] = adc_oversampling;

	if( ahrs_settings.Algorithm ==  AHRSSETTINGS_ALGORITHM_INSGPS) {
		// compute a data point and initialize INS
		downsample_data();
		converge_insgps();
	}


#ifdef DUMP_RAW
	int previous_conversion;
	while( 1 ) {
		AhrsPoll();
		int result;
		uint8_t framing[16] = {
			0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
			15
		};
		while( ahrs_state != AHRS_DATA_READY ) ;
		ahrs_state = AHRS_PROCESSING;

		if( total_conversion_blocks != previous_conversion + 1 )
			PIOS_LED_On( LED1 );	// not keeping up
		else
			PIOS_LED_Off( LED1 );
		previous_conversion = total_conversion_blocks;

		downsample_data();
		ahrs_state = AHRS_IDLE;;

		// Dump raw buffer
		result = PIOS_COM_SendBuffer( PIOS_COM_AUX, &framing[0], 16 );	// framing header
		result += PIOS_COM_SendBuffer( PIOS_COM_AUX, ( uint8_t * ) & total_conversion_blocks, sizeof( total_conversion_blocks ) );	// dump block number
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX,
								 ( uint8_t * ) & valid_data_buffer[0],
								 ADC_OVERSAMPLE *
								 ADC_CONTINUOUS_CHANNELS *
								 sizeof( valid_data_buffer[0] ) );
		if( result == 0 )
			PIOS_LED_Off( LED1 );
		else {
			PIOS_LED_On( LED1 );
		}
	}
#endif

	timer_start();

	/******************* Main EKF loop ****************************/
	while( 1 ) {
		AhrsPoll();
		AHRSCalibrationData calibration;
		AHRSCalibrationGet( &calibration );
		BaroAltitudeData baro_altitude;
		BaroAltitudeGet( &baro_altitude );
		GPSPositionData gps_position;
		GPSPositionGet( &gps_position );
		AHRSSettingsGet(&ahrs_settings);

		// Alive signal
		if(( total_conversion_blocks % 100 ) == 0 )
			PIOS_LED_Toggle( LED1 );

#if defined(PIOS_INCLUDE_HMC5843) && defined(PIOS_INCLUDE_I2C)
		// Get magnetic readings
		if( PIOS_HMC5843_NewDataAvailable() ) {
			PIOS_HMC5843_ReadMag( mag_data.raw.axis );
			mag_data.updated = 1;
		}
		attitude_raw.magnetometers[0] = mag_data.raw.axis[0];
		attitude_raw.magnetometers[2] = mag_data.raw.axis[1];
		attitude_raw.magnetometers[2] = mag_data.raw.axis[2];

#endif
		// Delay for valid data

		counter_val = timer_count();
		running_counts = counter_val - last_counter_idle_end;
		last_counter_idle_start = counter_val;

		while( ahrs_state != AHRS_DATA_READY ) ;

		counter_val = timer_count();
		idle_counts = counter_val - last_counter_idle_start;
		last_counter_idle_end = counter_val;

		ahrs_state = AHRS_PROCESSING;

		downsample_data();

		/***************** SEND BACK SOME RAW DATA ************************/
		// Hacky - grab one sample from buffer to populate this.  Need to send back
		// all raw data if it's happening
		accel_data.raw.x = valid_data_buffer[0];
		accel_data.raw.y = valid_data_buffer[2];
		accel_data.raw.z = valid_data_buffer[4];

		gyro_data.raw.x = valid_data_buffer[1];
		gyro_data.raw.y = valid_data_buffer[3];
		gyro_data.raw.z = valid_data_buffer[5];

		gyro_data.temp.xy = valid_data_buffer[6];
		gyro_data.temp.z = valid_data_buffer[7];

		if( ahrs_settings.Algorithm ==  AHRSSETTINGS_ALGORITHM_INSGPS) {
			/******************** INS ALGORITHM **************************/

			// format data for INS algo
			gyro[0] = gyro_data.filtered.x;
			gyro[1] = gyro_data.filtered.y;
			gyro[2] = gyro_data.filtered.z;
			accel[0] = accel_data.filtered.x,
					   accel[1] = accel_data.filtered.y,
								  accel[2] = accel_data.filtered.z,
											 // Note: The magnetometer driver returns registers X,Y,Z from the chip which are
											 // (left, backward, up).  Remapping to (forward, right, down).
											 mag[0] = -( mag_data.raw.axis[1] - calibration.mag_bias[1] );
			mag[1] = -( mag_data.raw.axis[0] - calibration.mag_bias[0] );
			mag[2] = -( mag_data.raw.axis[2] - calibration.mag_bias[2] );

			INSStatePrediction( gyro, accel,
								1 / ( float )EKF_RATE );
			INSCovariancePrediction( 1 / ( float )EKF_RATE );

			if( gps_updated && gps_position.Status == GPSPOSITION_STATUS_FIX3D ) {
				// Compute velocity from Heading and groundspeed
				vel[0] =
					gps_position.Groundspeed *
					cos( gps_position.Heading * M_PI / 180 );
				vel[1] =
					gps_position.Groundspeed *
					sin( gps_position.Heading * M_PI / 180 );

				// Completely unprincipled way to make the position variance
				// increase as data quality decreases but keep it bounded
				// Variance becomes 40 m^2 and 40 (m/s)^2 when no gps
				INSSetPosVelVar( 0.004 );

				HomeLocationData home;
				HomeLocationGet( &home );
				float ned[3];
				double lla[3] = {( double ) gps_position.Latitude / 1e7, ( double ) gps_position.Longitude / 1e7, ( double )( gps_position.GeoidSeparation + gps_position.Altitude )};
				// convert from cm back to meters
				double ecef[3] = {( double )( home.ECEF[0] / 100 ), ( double )( home.ECEF[1] / 100 ), ( double )( home.ECEF[2] / 100 )};
				LLA2Base( lla, ecef, ( float( * )[3] ) home.RNE, ned );

				if( gps_updated ) { //FIXME: Is this correct?
					//TOOD: add check for altitude updates
					FullCorrection( mag, ned,
									vel,
									baro_altitude.Altitude );
					gps_updated = false;
				} else {
					GpsBaroCorrection( ned,
									   vel,
									   baro_altitude.Altitude );
				}

				gps_updated = false;
				mag_data.updated = 0;
			} else if( gps_position.Status == GPSPOSITION_STATUS_FIX3D
					   && mag_data.updated == 1 ) {
				MagCorrection( mag );	// only trust mags if outdoors
				mag_data.updated = 0;
			} else {
				// Indoors, update with zero position and velocity and high covariance
				INSSetPosVelVar( 0.1 );
				vel[0] = 0;
				vel[1] = 0;
				vel[2] = 0;

				VelBaroCorrection( vel,
								   baro_altitude.Altitude );
//                MagVelBaroCorrection(mag,vel,altitude_data.altitude);  // only trust mags if outdoors
			}

			attitude_actual.q1 = Nav.q[0];
			attitude_actual.q2 = Nav.q[1];
			attitude_actual.q3 = Nav.q[2];
			attitude_actual.q4 = Nav.q[3];
		} else if( ahrs_settings.Algorithm ==  AHRSSETTINGS_ALGORITHM_SIMPLE ) {
			float q[4];
			float rpy[3];
			/***************** SIMPLE ATTITUDE FROM NORTH AND ACCEL ************/
			/* Very simple computation of the heading and attitude from accel. */
			rpy[2] =
				atan2(( mag_data.raw.axis[0] ),
					  ( -1 * mag_data.raw.axis[1] ) ) * 180 /
				M_PI;
			rpy[1] =
				atan2( accel_data.filtered.x,
					   accel_data.filtered.z ) * 180 / M_PI;
			rpy[0] =
				atan2( accel_data.filtered.y,
					   accel_data.filtered.z ) * 180 / M_PI;

			RPY2Quaternion( rpy, q );
			attitude_actual.q1 = q[0];
			attitude_actual.q2 = q[1];
			attitude_actual.q3 = q[2];
			attitude_actual.q4 = q[3];
		}

		ahrs_state = AHRS_IDLE;

#ifdef DUMP_FRIENDLY
		PIOS_COM_SendFormattedStringNonBlocking( PIOS_COM_AUX, "b: %d\r\n",
				total_conversion_blocks );
		PIOS_COM_SendFormattedStringNonBlocking( PIOS_COM_AUX, "a: %d %d %d\r\n",
				( int16_t )( accel_data.filtered.x * 1000 ),
				( int16_t )( accel_data.filtered.y * 1000 ),
				( int16_t )( accel_data.filtered.z * 1000 ) );
		PIOS_COM_SendFormattedStringNonBlocking( PIOS_COM_AUX, "g: %d %d %d\r\n",
				( int16_t )( gyro_data.filtered.x * 1000 ),
				( int16_t )( gyro_data.filtered.y * 1000 ),
				( int16_t )( gyro_data.filtered.z * 1000 ) );
		PIOS_COM_SendFormattedStringNonBlocking( PIOS_COM_AUX, "m: %d %d %d\r\n",
				mag_data.raw.axis[0],
				mag_data.raw.axis[1],
				mag_data.raw.axis[2] );
		PIOS_COM_SendFormattedStringNonBlocking( PIOS_COM_AUX,
				"q: %d %d %d %d\r\n",
				( int16_t )( Nav.q[0] * 1000 ),
				( int16_t )( Nav.q[1] * 1000 ),
				( int16_t )( Nav.q[2] * 1000 ),
				( int16_t )( Nav.q[3] * 1000 ) );
#endif
#ifdef DUMP_EKF
		uint8_t framing[16] = {
			15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
			0
		};
		extern float F[NUMX][NUMX], G[NUMX][NUMW], H[NUMV][NUMX];	// linearized system matrices
		extern float P[NUMX][NUMX], X[NUMX];	// covariance matrix and state vector
		extern float Q[NUMW], R[NUMV];	// input noise and measurement noise variances
		extern float K[NUMX][NUMV];	// feedback gain matrix

		// Dump raw buffer
		int8_t result;
		result = PIOS_COM_SendBuffer( PIOS_COM_AUX, &framing[0], 16 );	// framing header
		result += PIOS_COM_SendBuffer( PIOS_COM_AUX, ( uint8_t * ) & total_conversion_blocks, sizeof( total_conversion_blocks ) );	// dump block number
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX,
								 ( uint8_t * ) & mag_data,
								 sizeof( mag_data ) );
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX,
								 ( uint8_t * ) & gps_data,
								 sizeof( gps_data ) );
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX,
								 ( uint8_t * ) & accel_data,
								 sizeof( accel_data ) );
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX,
								 ( uint8_t * ) & gyro_data,
								 sizeof( gyro_data ) );
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX, ( uint8_t * ) & Q,
								 sizeof( float ) * NUMX * NUMX );
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX, ( uint8_t * ) & K,
								 sizeof( float ) * NUMX * NUMV );
		result +=
			PIOS_COM_SendBuffer( PIOS_COM_AUX, ( uint8_t * ) & X,
								 sizeof( float ) * NUMX * NUMX );

		if( result == 0 )
			PIOS_LED_Off( LED1 );
		else {
			PIOS_LED_On( LED1 );
		}
#endif
		AttitudeActualSet( &attitude_actual );

		/*FIXME: This is dangerous. There is no locking for UAVObjects
		so it could stomp all over the airspeed/climb rate etc.
		This used to be done in the OP module which was bad.
		Having ~4ms latency for the round trip makes it worse here.
		*/
		PositionActualData pos;
		PositionActualGet( &pos );
		for( int ct = 0; ct < 3; ct++ ) {
			pos.NED[ct] = Nav.Pos[ct];
			pos.Vel[ct] = Nav.Vel[ct];
		}
		PositionActualSet( &pos );

		static bool was_calibration = false;
		AhrsStatusData status;
		AhrsStatusGet( &status );
		if( was_calibration != status.CalibrationSet ) {
			was_calibration = status.CalibrationSet;
			if( status.CalibrationSet ) {
				calibrate_sensors();
				AhrsStatusGet( &status );
				status.CalibrationSet = true;
			}
		}
		status.CPULoad = (( float )running_counts /
						  ( float )( idle_counts + running_counts ) ) * 100;

		status.IdleTimePerCyle = idle_counts / ( TIMER_RATE / 10000 );
		status.RunningTimePerCyle = running_counts / ( TIMER_RATE / 10000 );
		status.DroppedUpdates = ekf_too_slow;
		AhrsStatusSet( &status );

	}

	return 0;
}
Beispiel #17
0
/**
 * Streaming callback to format our output
 */
static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) {
    #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1;
    struct timeval *tv = data;
    timer_hist *t;
    int i;
    char *prefix = GLOBAL_CONFIG->prefixes_final[type];
    extended_counters_config* counters_config = &(GLOBAL_CONFIG->ext_counters_config);

    switch (type) {
        case KEY_VAL:
            STREAM("%s%s|%f|%lld\n", prefix, name, *(double*)value);
            break;

        case GAUGE:
            STREAM("%s%s|%f|%lld\n", prefix, name, ((gauge_t*)value)->value);
            break;

        case COUNTER:
            if (GLOBAL_CONFIG->extended_counters) {
                if (counters_config->count) {
                    STREAM("%s%s.count|%lld|%lld\n", prefix, name, counter_count(value));
                }
                if (counters_config->mean) {
                    STREAM("%s%s.mean|%f|%lld\n", prefix, name, counter_mean(value));    
                }
                if (counters_config->stdev) {
                    STREAM("%s%s.stdev|%f|%lld\n", prefix, name, counter_stddev(value));
                }
                if (counters_config->sum) {
                    STREAM("%s%s.sum|%f|%lld\n", prefix, name, counter_sum(value));
                }
                if (counters_config->sum_sq) {
                    STREAM("%s%s.sum_sq|%f|%lld\n", prefix, name, counter_squared_sum(value));
                }
                if (counters_config->lower) {
                    STREAM("%s%s.lower|%f|%lld\n", prefix, name, counter_min(value));
                }
                if (counters_config->upper) {
                    STREAM("%s%s.upper|%f|%lld\n", prefix, name, counter_max(value));
                }
                if (counters_config->rate) {
                    STREAM("%s%s.rate|%f|%lld\n", prefix, name, counter_sum(value) / GLOBAL_CONFIG->flush_interval);
                }
            } else {
                STREAM("%s%s|%f|%lld\n", prefix, name, counter_sum(value));
            }
            break;

        case SET:
            STREAM("%s%s|%lld|%lld\n", prefix, name, set_size(value));
            break;

        case TIMER:
            t = (timer_hist*)value;
            STREAM("%s%s.sum|%f|%lld\n", prefix, name, timer_sum(&t->tm));
            STREAM("%s%s.sum_sq|%f|%lld\n", prefix, name, timer_squared_sum(&t->tm));
            STREAM("%s%s.mean|%f|%lld\n", prefix, name, timer_mean(&t->tm));
            STREAM("%s%s.lower|%f|%lld\n", prefix, name, timer_min(&t->tm));
            STREAM("%s%s.upper|%f|%lld\n", prefix, name, timer_max(&t->tm));
            STREAM("%s%s.count|%lld|%lld\n", prefix, name, timer_count(&t->tm));
            STREAM("%s%s.stdev|%f|%lld\n", prefix, name, timer_stddev(&t->tm));
            for (i=0; i < GLOBAL_CONFIG->num_quantiles; i++) {
                if (GLOBAL_CONFIG->quantiles[i] == 0.5) {
                    STREAM("%s%s.median|%f|%lld\n", prefix, name, timer_query(&t->tm, 0.5));
                }
                STREAM("%s%s.p%0.0f|%f|%lld\n", prefix, name,
                    GLOBAL_CONFIG->quantiles[i] * 100,
                    timer_query(&t->tm, GLOBAL_CONFIG->quantiles[i]));
            }
            STREAM("%s%s.rate|%f|%lld\n", prefix, name, timer_sum(&t->tm) / GLOBAL_CONFIG->flush_interval);
            STREAM("%s%s.sample_rate|%f|%lld\n", prefix, name, (double)timer_count(&t->tm) / GLOBAL_CONFIG->flush_interval);

            // Stream the histogram values
            if (t->conf) {
                STREAM("%s%s.histogram.bin_<%0.2f|%u|%lld\n", prefix, name, t->conf->min_val, t->counts[0]);
                for (i=0; i < t->conf->num_bins-2; i++) {
                    STREAM("%s%s.histogram.bin_%0.2f|%u|%lld\n", prefix, name, t->conf->min_val+(t->conf->bin_width*i), t->counts[i+1]);
                }
                STREAM("%s%s.histogram.bin_>%0.2f|%u|%lld\n", prefix, name, t->conf->max_val, t->counts[i+1]);
            }
            break;

        default:
            syslog(LOG_ERR, "Unknown metric type: %d", type);
            break;
    }
    return 0;
}
Beispiel #18
0
void mc68901_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	if(id >= TIMER_A && id <= TIMER_D)
		timer_count(id);
}
Beispiel #19
0
static void release_opencl()
{
  DTIMER_START(T_RELEASE);

  clReleaseMemObject(m_key_array);
  clReleaseMemObject(m_key_buff1);
  clReleaseMemObject(m_key_buff2);
  clReleaseMemObject(m_index_array);
  clReleaseMemObject(m_rank_array);
  clReleaseMemObject(m_partial_vals);
  clReleaseMemObject(m_passed_verification);
  if (device_type == CL_DEVICE_TYPE_GPU) {
    clReleaseMemObject(m_key_scan);
    clReleaseMemObject(m_sum);
  } else {
    clReleaseMemObject(m_bucket_ptrs);
    clReleaseMemObject(m_bucket_size);
  }

  clReleaseKernel(k_rank0);
  clReleaseKernel(k_rank1);
  clReleaseKernel(k_rank2);
  if (device_type == CL_DEVICE_TYPE_GPU) {
    clReleaseKernel(k_rank3_0);
    clReleaseKernel(k_rank3_1);
    clReleaseKernel(k_rank3_2);
  } else {
    clReleaseKernel(k_rank3);
  }
  clReleaseKernel(k_rank4);

  clReleaseProgram(program);
  clReleaseCommandQueue(cmd_queue);
  clReleaseContext(context);

  DTIMER_STOP(T_RELEASE);

#ifdef TIMER_DETAIL
  if (timer_on) {
    int i;
    double tt;
    double t_opencl = 0.0, t_buffer = 0.0, t_kernel = 0.0;
    unsigned cnt;

    for (i = T_OPENCL_API; i < T_END; i++)
      t_opencl += timer_read(i);

    for (i = T_BUFFER_CREATE; i <= T_BUFFER_WRITE; i++)
      t_buffer += timer_read(i);

    for (i = T_KERNEL_CREATE_SEQ; i <= T_KERNEL_FV2; i++)
      t_kernel += timer_read(i);

    printf("\nOpenCL timers -\n");
    printf("Kernel      : %9.3f (%.2f%%)\n", 
        t_kernel, t_kernel/t_opencl * 100.0);

    cnt = timer_count(T_KERNEL_CREATE_SEQ);
    tt = timer_read(T_KERNEL_CREATE_SEQ);
    printf("- create_seq: %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_RANK0);
    tt = timer_read(T_KERNEL_RANK0);
    printf("- rank0     : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_RANK1);
    tt = timer_read(T_KERNEL_RANK1);
    printf("- rank1     : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_RANK2);
    tt = timer_read(T_KERNEL_RANK2);
    printf("- rank2     : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_RANK3);
    tt = timer_read(T_KERNEL_RANK3);
    printf("- rank3     : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_RANK4);
    tt = timer_read(T_KERNEL_RANK4);
    printf("- rank4     : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_FV0);
    tt = timer_read(T_KERNEL_FV0);
    printf("- fv0       : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_FV1);
    tt = timer_read(T_KERNEL_FV1);
    printf("- fv1       : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    cnt = timer_count(T_KERNEL_FV2);
    tt = timer_read(T_KERNEL_FV2);
    printf("- fv2       : %9.3lf (%u, %.3f, %.2f%%)\n",
        tt, cnt, tt/cnt, tt/t_kernel * 100.0);

    printf("Buffer      : %9.3lf (%.2f%%)\n",
        t_buffer, t_buffer/t_opencl * 100.0);
    printf("- creation  : %9.3lf\n", timer_read(T_BUFFER_CREATE));
    printf("- read      : %9.3lf\n", timer_read(T_BUFFER_READ));
    printf("- write     : %9.3lf\n", timer_read(T_BUFFER_WRITE));

    tt = timer_read(T_OPENCL_API);
    printf("API         : %9.3lf (%.2f%%)\n", tt, tt/t_opencl * 100.0);

    tt = timer_read(T_BUILD);
    printf("BUILD       : %9.3lf (%.2f%%)\n", tt, tt/t_opencl * 100.0);

    tt = timer_read(T_RELEASE);
    printf("RELEASE     : %9.3lf (%.2f%%)\n", tt, tt/t_opencl * 100.0);

    printf("Total       : %9.3lf\n", t_opencl);
  }
#endif
}
Beispiel #20
0
static int stream_formatter_bin(FILE *pipe, void *data, metric_type type, char *name, void *value) {
    #define STREAM_BIN(...) if (stream_bin_writer(pipe, ((struct timeval *)data)->tv_sec, __VA_ARGS__, name)) return 1;
    #define STREAM_UINT(val) if (!fwrite(&val, sizeof(unsigned int), 1, pipe)) return 1;
    timer_hist *t;
    int i;

    included_metrics_config* counters_config = &(GLOBAL_CONFIG->ext_counters_config);

    switch (type) {
        case KEY_VAL:
            STREAM_BIN(BIN_TYPE_KV, BIN_OUT_NO_TYPE, *(double*)value);
            break;

        case GAUGE:
            STREAM_BIN(BIN_TYPE_GAUGE, BIN_OUT_NO_TYPE, ((gauge_t*)value)->value);
            break;

        case COUNTER:
            if (counters_config->sum) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM, counter_sum(value));
            }
            if (counters_config->sum_sq) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM_SQ, counter_squared_sum(value));
            }
            if (counters_config->mean) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MEAN, counter_mean(value));
            }
            if (counters_config->count) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_COUNT, counter_count(value));
            }
            if (counters_config->stdev) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_STDDEV, counter_stddev(value));
            }
            if (counters_config->lower) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MIN, counter_min(value));
            }
            if (counters_config->upper) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MAX, counter_max(value));
            }
            if (counters_config->rate) {
                STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_RATE, counter_sum(value) / GLOBAL_CONFIG->flush_interval);
            }
            break;

        case SET:
            STREAM_BIN(BIN_TYPE_SET, BIN_OUT_SUM, set_size(value));
            break;

        case TIMER:
            t = (timer_hist*)value;
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM, timer_sum(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM_SQ, timer_squared_sum(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MEAN, timer_mean(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_COUNT, timer_count(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_STDDEV, timer_stddev(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MIN, timer_min(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MAX, timer_max(&t->tm));
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_RATE, timer_sum(&t->tm) / GLOBAL_CONFIG->flush_interval);
            STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SAMPLE_RATE, (double)timer_count(&t->tm) / GLOBAL_CONFIG->flush_interval);
            for (i=0; i < GLOBAL_CONFIG->num_quantiles; i++) {
                STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT |
                    (int)(GLOBAL_CONFIG->quantiles[i] * 100),
                    timer_query(&t->tm, GLOBAL_CONFIG->quantiles[i]));
            }

            // Binary streaming for histograms
            if (t->conf) {
                STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_FLOOR, t->conf->min_val);
                STREAM_UINT(t->counts[0]);
                for (i=0; i < t->conf->num_bins-2; i++) {
                    STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_BIN, t->conf->min_val+(t->conf->bin_width*i));
                    STREAM_UINT(t->counts[i+1]);
                }
                STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_CEIL, t->conf->max_val);
                STREAM_UINT(t->counts[i+1]);
            }
            break;

        default:
            syslog(LOG_ERR, "Unknown metric type: %d", type);
            break;
    }
    return 0;
}
Beispiel #21
0
/*********************************************************************************************************************
** Function name:           mtimer_gettick
** Descriptions:            读取毫秒定时器的当前嘀嗒数
** Input parameters:        
** Output parameters:       
** Returned value:          当前嘀嗒数
**--------------------------------------------------------------------------------------------------------------------
** Created by:              Feng Liang
** Created Date:            2012-2-10  0:18:50
** Test recorde:            
**--------------------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Test recorde: 
*********************************************************************************************************************/
INT32U mtimer_gettick(void)
{
    return timer_count(&mtimer_features);
}
Beispiel #22
0
/*
 * Each PE sends the contents of its local buckets to the PE that owns that bucket.
 */
static KEY_TYPE * exchange_keys(int const * const send_offsets,
                                       int const * const local_bucket_sizes,
                                       KEY_TYPE const * const my_local_bucketed_keys)
{
  timer_start(&timers[TIMER_ATA_KEYS]);

  const int my_rank = shmem_my_pe();
  unsigned int total_keys_sent = 0;

  // Keys destined for local key buffer can be written with memcpy
  const long long int write_offset_into_self = shmem_longlong_fadd(
          &receive_offset, (long long int)local_bucket_sizes[my_rank], my_rank);
  assert((unsigned long long)write_offset_into_self +
          (unsigned long long)local_bucket_sizes[my_rank] <= KEY_BUFFER_SIZE);
  memcpy(&my_bucket_keys[write_offset_into_self], 
         &my_local_bucketed_keys[send_offsets[my_rank]], 
         local_bucket_sizes[my_rank]*sizeof(KEY_TYPE));


  for(uint64_t i = 0; i < NUM_PES; ++i){

#ifdef PERMUTE
    const int target_pe = permute_array[i];
#elif INCAST
    const int target_pe = i;
#else
    const int target_pe = (my_rank + i) % NUM_PES;
#endif

    // Local keys already written with memcpy
    if(target_pe == my_rank){ continue; }

    const int read_offset_from_self = send_offsets[target_pe];
    const int my_send_size = local_bucket_sizes[target_pe];

    const long long int write_offset_into_target = shmem_longlong_fadd(
            &receive_offset, (long long int)my_send_size, target_pe);

#ifdef DEBUG
    printf("Rank: %d Target: %d Offset into target: %lld Offset into myself: %d Send Size: %d\n",
        my_rank, target_pe, write_offset_into_target, read_offset_from_self, my_send_size);
#endif

    // fprintf(stderr, "PUTTING %llu\n", my_send_size);
    assert((unsigned long long)write_offset_into_target +
            (unsigned long long)my_send_size <= KEY_BUFFER_SIZE);
    assert((unsigned long long)read_offset_from_self +
            (unsigned long long)my_send_size <= NUM_KEYS_PER_PE);
    shmem_int_put(&(my_bucket_keys[write_offset_into_target]), 
                  &(my_local_bucketed_keys[read_offset_from_self]), 
                  my_send_size, 
                  target_pe);

    total_keys_sent += my_send_size;
  }

#ifdef BARRIER_ATA
  SHMEM_BARRIER_AT_EXCHANGE;
#endif

  timer_stop(&timers[TIMER_ATA_KEYS]);
  timer_count(&timers[TIMER_ATA_KEYS], total_keys_sent);

#ifdef DEBUG
  wait_my_turn();
  char msg[1024];
  sprintf(msg,"Rank %d: Bucket Size %lld | Total Keys Sent: %u | Keys after exchange:", 
                        my_rank, receive_offset, total_keys_sent);
  for(long long int i = 0; i < receive_offset; ++i){
    if(i < PRINT_MAX)
    sprintf(msg + strlen(msg),"%d ", my_bucket_keys[i]);
  }
  sprintf(msg + strlen(msg),"\n");
  printf("%s",msg);
  fflush(stdout);
  my_turn_complete();
#endif

  return my_bucket_keys;
}
Beispiel #23
0
/**
 * Streaming callback to format our output
 */
static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) {
    #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1;
    struct config_time* ct = data;
    struct timeval *tv = ct->tv;
    timer_hist *t;
    int i;
    char *prefix = ct->global_config->prefixes_final[type];
    switch (type) {
        case KEY_VAL:
            STREAM("%s%s|%f|%lld\n", prefix, name, *(double*)value);
            break;

        case GAUGE:
            STREAM("%s%s|%f|%lld\n", prefix, name, ((gauge_t*)value)->value);
            break;

        case COUNTER:
            if (ct->global_config->extended_counters) {
                STREAM("%s%s.count|%" PRIu64 "|%lld\n", prefix, name, counter_count(value));
                STREAM("%s%s.mean|%f|%lld\n", prefix, name, counter_mean(value));
                STREAM("%s%s.stdev|%f|%lld\n", prefix, name, counter_stddev(value));
                STREAM("%s%s.sum|%f|%lld\n", prefix, name, counter_sum(value));
                STREAM("%s%s.sum_sq|%f|%lld\n", prefix, name, counter_squared_sum(value));
                STREAM("%s%s.lower|%f|%lld\n", prefix, name, counter_min(value));
                STREAM("%s%s.upper|%f|%lld\n", prefix, name, counter_max(value));
                STREAM("%s%s.rate|%f|%lld\n", prefix, name, counter_sum(value) / ct->global_config->flush_interval);
            } else {
                STREAM("%s%s|%f|%lld\n", prefix, name, counter_sum(value));
            }
            break;

        case SET:
            STREAM("%s%s|%" PRIu64 "|%lld\n", prefix, name, set_size(value));
            break;

        case TIMER:
            t = (timer_hist*)value;
            STREAM("%s%s.sum|%f|%lld\n", prefix, name, timer_sum(&t->tm));
            STREAM("%s%s.sum_sq|%f|%lld\n", prefix, name, timer_squared_sum(&t->tm));
            STREAM("%s%s.mean|%f|%lld\n", prefix, name, timer_mean(&t->tm));
            STREAM("%s%s.lower|%f|%lld\n", prefix, name, timer_min(&t->tm));
            STREAM("%s%s.upper|%f|%lld\n", prefix, name, timer_max(&t->tm));
            STREAM("%s%s.count|%" PRIu64 "|%lld\n", prefix, name, timer_count(&t->tm));
            STREAM("%s%s.stdev|%f|%lld\n", prefix, name, timer_stddev(&t->tm));
            for (i=0; i < ct->global_config->num_quantiles; i++) {
                int percentile;
                double quantile = ct->global_config->quantiles[i];
                if (quantile == 0.5) {
                    STREAM("%s%s.median|%f|%lld\n", prefix, name, timer_query(&t->tm, 0.5));
                }
                if (to_percentile(quantile, &percentile)) {
                    syslog(LOG_ERR, "Invalid quantile: %lf", quantile);
                    break;
                }
                STREAM("%s%s.p%d|%f|%lld\n", prefix, name, percentile,
                    timer_query(&t->tm, quantile));
            }
            STREAM("%s%s.rate|%f|%lld\n", prefix, name, timer_sum(&t->tm) / ct->global_config->flush_interval);
            STREAM("%s%s.sample_rate|%f|%lld\n", prefix, name, (double)timer_count(&t->tm) / ct->global_config->flush_interval);

            // Stream the histogram values
            if (t->conf) {
                STREAM("%s%s.histogram.bin_<%0.2f|%u|%lld\n", prefix, name, t->conf->min_val, t->counts[0]);
                for (i=0; i < t->conf->num_bins-2; i++) {
                    STREAM("%s%s.histogram.bin_%0.2f|%u|%lld\n", prefix, name, t->conf->min_val+(t->conf->bin_width*i), t->counts[i+1]);
                }
                STREAM("%s%s.histogram.bin_>%0.2f|%u|%lld\n", prefix, name, t->conf->max_val, t->counts[i+1]);
            }
            break;

        default:
            syslog(LOG_ERR, "Unknown metric type: %d", type);
            break;
    }
    return 0;
}