示例#1
0
double PoissonGLM::fun(double *w)
{
	double f = 0;
	double *y = prob->get_Y();
	int N = prob->get_N() * prob->get_ntrials();

	Prior *prior = this->prior;
	int n_dim = prob->get_ndim();

	prob->Xv(w, z);
	calc_rate(z, N);

	if (canonical)
		for(int i=0;i<N;i++)
			f += rate[i] - y[i] * z[i];
	else
		for(int i=0;i<N;i++)
			f += rate[i] - y[i] * log(rate[i]);

	if (prior != NULL) {
		f += prior->fun(w, n_dim);
	}

//	std::cout << "f: " << f << std::endl;

	return(f);
}
示例#2
0
文件: mix.cpp 项目: rsrsps/gzdoom
static bool check_release(double RateMul, double sec)
{
	double rate = calc_rate(960 * RateMul, sec);

	// Is release rate very fast? If so, don't do the release, but do
	// the voice off ramp instead.
	return (rate < 960/20);
}
示例#3
0
文件: mf.cpp 项目: lming08/libmf
float calc_rmse(Model const &model, Matrix const &M)
{
    double loss = 0;
    for(auto r = M.R.begin(); r != M.R.end(); r++)
    {
//add qinyuqing code 
        float const e = r->rate - calc_rate(model, *r);
        loss += e*e;
    }
    return sqrt(loss/M.nr_ratings);
}
示例#4
0
文件: retr.c 项目: kmekler/symblog
/* Return a printed representation of the download rate, as
   appropriate for the speed.  If PAD is non-zero, strings will be
   padded to the width of 7 characters (xxxx.xx).  */
char *
retr_rate (long bytes, long msecs, int pad)
{
  static char res[20];
  static char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" };
  int units = 0;

  double dlrate = calc_rate (bytes, msecs, &units);
  sprintf (res, pad ? "%7.2f %s" : "%.2f %s", dlrate, rate_names[units]);

  return res;
}
示例#5
0
const char *
retr_rate (wgint bytes, double secs)
{
  static char res[20];
  static const char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" };
  int units;

  double dlrate = calc_rate (bytes, secs, &units);
  /* Use more digits for smaller numbers (regardless of unit used),
     e.g. "1022", "247", "12.5", "2.38".  */
  sprintf (res, "%.*f %s",
           dlrate >= 99.95 ? 0 : dlrate >= 9.995 ? 1 : 2,
           dlrate, rate_names[units]);

  return res;
}
示例#6
0
void predict(Model *model, char *test_path, char *dst_path) {

    Matrix *Te = new Matrix(test_path); FILE *f = fopen(dst_path, "w"); double rmse = 0;

    printf("Predicting..."); fflush(stdout); Clock clock; clock.tic();

    for(int rx=0; rx<Te->nr_rs; rx++) {
        float rate = calc_rate(model,&Te->M[rx]); 
        float e = Te->M[rx].rate - rate;
        fprintf(f,"%f\n",rate);  rmse += e*e;
    }
    printf("done. %.2lf\n",clock.toc()); fflush(stdout);

    printf("RMSE: %.4lf\n",sqrt(rmse/Te->nr_rs));

    delete Te;
}
示例#7
0
void can_stat_update(unsigned long data)
{
	unsigned long j = jiffies; /* snapshot */

	/* restart counting in timer context on user request */
	if (user_reset)
		can_init_stats();

	/* restart counting on jiffies overflow */
	if (j < can_stats.jiffies_init)
		can_init_stats();

	/* prevent overflow in calc_rate() */
	if (can_stats.rx_frames > (ULONG_MAX / HZ))
		can_init_stats();

	/* prevent overflow in calc_rate() */
	if (can_stats.tx_frames > (ULONG_MAX / HZ))
		can_init_stats();

	/* matches overflow - very improbable */
	if (can_stats.matches > (ULONG_MAX / 100))
		can_init_stats();

	/* calc total values */
	if (can_stats.rx_frames)
		can_stats.total_rx_match_ratio = (can_stats.matches * 100) /
			can_stats.rx_frames;

	can_stats.total_tx_rate = calc_rate(can_stats.jiffies_init, j,
					    can_stats.tx_frames);
	can_stats.total_rx_rate = calc_rate(can_stats.jiffies_init, j,
					    can_stats.rx_frames);

	/* calc current values */
	if (can_stats.rx_frames_delta)
		can_stats.current_rx_match_ratio =
			(can_stats.matches_delta * 100) /
			can_stats.rx_frames_delta;

	can_stats.current_tx_rate = calc_rate(0, HZ, can_stats.tx_frames_delta);
	can_stats.current_rx_rate = calc_rate(0, HZ, can_stats.rx_frames_delta);

	/* check / update maximum values */
	if (can_stats.max_tx_rate < can_stats.current_tx_rate)
		can_stats.max_tx_rate = can_stats.current_tx_rate;

	if (can_stats.max_rx_rate < can_stats.current_rx_rate)
		can_stats.max_rx_rate = can_stats.current_rx_rate;

	if (can_stats.max_rx_match_ratio < can_stats.current_rx_match_ratio)
		can_stats.max_rx_match_ratio = can_stats.current_rx_match_ratio;

	/* clear values for 'current rate' calculation */
	can_stats.tx_frames_delta = 0;
	can_stats.rx_frames_delta = 0;
	can_stats.matches_delta   = 0;

	/* restart timer (one second) */
	mod_timer(&can_stattimer, round_jiffies(jiffies + HZ));
}
示例#8
0
文件: eta.c 项目: martin21/fio
/*
 * Print status of the jobs we know about. This includes rate estimates,
 * ETA, thread state, etc.
 */
void print_thread_status(void)
{
	unsigned long elapsed = (mtime_since_genesis() + 999) / 1000;
	int i, nr_ramp, nr_running, nr_pending, t_rate, m_rate;
	int t_iops, m_iops, files_open;
	struct thread_data *td;
	char eta_str[128];
	double perc = 0.0;
	unsigned long long io_bytes[2], io_iops[2];
	unsigned long rate_time, disp_time, bw_avg_time, *eta_secs, eta_sec;
	struct timeval now;

	static unsigned long long rate_io_bytes[2];
	static unsigned long long disp_io_bytes[2];
	static unsigned long long disp_io_iops[2];
	static struct timeval rate_prev_time, disp_prev_time;
	static unsigned int rate[2], iops[2];
	static int linelen_last;
	static int eta_good;
	int i2p = 0;

	if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
		return;

	if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
		return;

	if (!rate_io_bytes[0] && !rate_io_bytes[1])
		fill_start_time(&rate_prev_time);
	if (!disp_io_bytes[0] && !disp_io_bytes[1])
		fill_start_time(&disp_prev_time);

	eta_secs = malloc(thread_number * sizeof(unsigned long));
	memset(eta_secs, 0, thread_number * sizeof(unsigned long));

	io_bytes[0] = io_bytes[1] = 0;
	io_iops[0] = io_iops[1] = 0;
	nr_pending = nr_running = t_rate = m_rate = t_iops = m_iops = 0;
	nr_ramp = 0;
	bw_avg_time = ULONG_MAX;
	files_open = 0;
	for_each_td(td, i) {
		if (td->o.bw_avg_time < bw_avg_time)
			bw_avg_time = td->o.bw_avg_time;
		if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
		    || td->runstate == TD_FSYNCING
		    || td->runstate == TD_PRE_READING) {
			nr_running++;
			t_rate += td->o.rate[0] + td->o.rate[1];
			m_rate += td->o.ratemin[0] + td->o.ratemin[1];
			t_iops += td->o.rate_iops[0] + td->o.rate_iops[1];
			m_iops += td->o.rate_iops_min[0] + td->o.rate_iops_min[1];
			files_open += td->nr_open_files;
		} else if (td->runstate == TD_RAMP) {
			nr_running++;
			nr_ramp++;
		} else if (td->runstate < TD_RUNNING)
			nr_pending++;

		if (elapsed >= 3)
			eta_secs[i] = thread_eta(td);
		else
			eta_secs[i] = INT_MAX;

		check_str_update(td);

		if (td->runstate > TD_RAMP) {
			io_bytes[0] += td->io_bytes[0];
			io_bytes[1] += td->io_bytes[1];
			io_iops[0] += td->io_blocks[0];
			io_iops[1] += td->io_blocks[1];
		}
	}

	if (exitall_on_terminate)
		eta_sec = INT_MAX;
	else
		eta_sec = 0;

	for_each_td(td, i) {
		if (!i2p && is_power_of_2(td->o.kb_base))
			i2p = 1;
		if (exitall_on_terminate) {
			if (eta_secs[i] < eta_sec)
				eta_sec = eta_secs[i];
		} else {
			if (eta_secs[i] > eta_sec)
				eta_sec = eta_secs[i];
		}
	}

	free(eta_secs);

	if (eta_sec != INT_MAX && elapsed) {
		perc = (double) elapsed / (double) (elapsed + eta_sec);
		eta_to_str(eta_str, eta_sec);
	}

	fio_gettime(&now, NULL);
	rate_time = mtime_since(&rate_prev_time, &now);

	if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
		calc_rate(rate_time, io_bytes, rate_io_bytes, rate);
		memcpy(&rate_prev_time, &now, sizeof(now));
		add_agg_sample(rate[DDIR_READ], DDIR_READ, 0);
		add_agg_sample(rate[DDIR_WRITE], DDIR_WRITE, 0);
	}

	disp_time = mtime_since(&disp_prev_time, &now);
	if (disp_time < 1000)
		return;

	calc_rate(disp_time, io_bytes, disp_io_bytes, rate);
	calc_iops(disp_time, io_iops, disp_io_iops, iops);

	memcpy(&disp_prev_time, &now, sizeof(now));

	if (!nr_running && !nr_pending)
		return;

	printf("Jobs: %d (f=%d)", nr_running, files_open);
	if (m_rate || t_rate) {
		char *tr, *mr;

		mr = num2str(m_rate, 4, 0, i2p);
		tr = num2str(t_rate, 4, 0, i2p);
		printf(", CR=%s/%s KB/s", tr, mr);
		free(tr);
		free(mr);
	} else if (m_iops || t_iops)
		printf(", CR=%d/%d IOPS", t_iops, m_iops);
	if (eta_sec != INT_MAX && nr_running) {
		char perc_str[32];
		char *iops_str[2];
		char *rate_str[2];
		int l;

		if ((!eta_sec && !eta_good) || nr_ramp == nr_running)
			strcpy(perc_str, "-.-% done");
		else {
			eta_good = 1;
			perc *= 100.0;
			sprintf(perc_str, "%3.1f%% done", perc);
		}

		rate_str[0] = num2str(rate[0], 5, 10, i2p);
		rate_str[1] = num2str(rate[1], 5, 10, i2p);

		iops_str[0] = num2str(iops[0], 4, 1, 0);
		iops_str[1] = num2str(iops[1], 4, 1, 0);

		l = printf(": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
				 run_str, perc_str, rate_str[0], rate_str[1], 
				 iops_str[0], iops_str[1], eta_str);
		if (l >= 0 && l < linelen_last)
			printf("%*s", linelen_last - l, "");
		linelen_last = l;

		free(rate_str[0]);
		free(rate_str[1]);
		free(iops_str[0]);
		free(iops_str[1]);
	}
	printf("\r");
	fflush(stdout);
}
示例#9
0
static int rtcp_xr_voip_metrics_init(uint8_t *buf, RtpSession *session) {
	JBParameters jbparams;
	uint32_t expected_packets;
	uint32_t lost_packets;
	rtcp_xr_voip_metrics_report_block_t *block = (rtcp_xr_voip_metrics_report_block_t *)buf;
	float rtt = rtp_session_get_round_trip_propagation(session);
	uint16_t int_rtt = (rtt >= 0) ? (rtt * 1000) : 0;
	float qi = -1;
	float lq_qi = -1;

	rtp_session_get_jitter_buffer_params(session, &jbparams);
	if (session->rtcp.xr_media_callbacks.average_qi != NULL) {
		qi = session->rtcp.xr_media_callbacks.average_qi(session->rtcp.xr_media_callbacks.userdata);
	}
	if (session->rtcp.xr_media_callbacks.average_lq_qi != NULL) {
		lq_qi = session->rtcp.xr_media_callbacks.average_lq_qi(session->rtcp.xr_media_callbacks.userdata);
	}

	block->bh.bt = RTCP_XR_VOIP_METRICS;
	block->bh.flags = 0; // Reserved bits
	block->bh.length = htons(8);
	block->ssrc = htonl(rtp_session_get_recv_ssrc(session));
	block->gmin = RTCP_XR_GMIN;

	// Fill RX config
	block->rx_config = 0;
	if (jbparams.adaptive) {
		block->rx_config |= RTCP_XR_VOIP_METRICS_CONFIG_JBA_ADA;
	} else {
		block->rx_config |= RTCP_XR_VOIP_METRICS_CONFIG_JBA_NON;
	}
	if (session->rtcp.xr_media_callbacks.plc != NULL) {
		switch (session->rtcp.xr_media_callbacks.plc(session->rtcp.xr_media_callbacks.userdata)) {
			default:
			case OrtpRtcpXrNoPlc:
				block->rx_config |= RTCP_XR_VOIP_METRICS_CONFIG_PLC_UNS;
				break;
			case OrtpRtcpXrSilencePlc:
				block->rx_config |= RTCP_XR_VOIP_METRICS_CONFIG_PLC_DIS;
				break;
			case OrtpRtcpXrEnhancedPlc:
				block->rx_config |= RTCP_XR_VOIP_METRICS_CONFIG_PLC_ENH;
				break;
		}
	} else {
		block->rx_config |= RTCP_XR_VOIP_METRICS_CONFIG_PLC_UNS;
	}

	// Fill JB fields
	block->jb_nominal = htons((uint16_t)jbparams.nom_size);
	if (jbparams.adaptive) {
		block->jb_maximum = htons((session->rtp.jittctl.adapt_jitt_comp_ts * 1000) / session->rtp.jittctl.clock_rate);
	} else {
		block->jb_maximum = block->jb_nominal;
	}
	block->jb_abs_max = htons(65535);

	if (session->rtcp_xr_stats.rcv_count > 0) {
		expected_packets = session->rtcp_xr_stats.last_rcv_seq - session->rtcp_xr_stats.first_rcv_seq + 1;
		lost_packets = expected_packets - session->rtcp_xr_stats.rcv_count;
		block->loss_rate = calc_rate((double)lost_packets, (double)expected_packets);
		block->discard_rate = calc_rate((double)session->rtcp_xr_stats.discarded_count, (double)expected_packets);
		// TODO: fill burst_density, gap_density, burst_duration, gap_duration
		block->burst_density = 0;
		block->gap_density = 0;
		block->burst_duration = htons(0);
		block->gap_duration = htons(0);
		block->round_trip_delay = htons(int_rtt);
		// TODO: fill end_system_delay
		block->end_system_delay = htons(0);
		if (session->rtcp.xr_media_callbacks.signal_level != NULL) {
			block->signal_level = session->rtcp.xr_media_callbacks.signal_level(session->rtcp.xr_media_callbacks.userdata);
		} else {
			block->signal_level = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		}
		if (session->rtcp.xr_media_callbacks.noise_level != NULL) {
			block->noise_level = session->rtcp.xr_media_callbacks.noise_level(session->rtcp.xr_media_callbacks.userdata);
		} else {
			block->noise_level = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		}
		block->rerl = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		if (qi < 0) {
			block->r_factor = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		} else {
			block->r_factor = (uint8_t)(qi * 20);
		}
		block->ext_r_factor = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		if (lq_qi < 0) {
			block->mos_lq = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		} else {
			block->mos_lq = (uint8_t)(lq_qi * 10);
			if (block->mos_lq < 10) block->mos_lq = 10;
		}
		if (qi < 0) {
			block->mos_cq = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		} else {
			block->mos_cq = (uint8_t)(qi * 10);
			if (block->mos_cq < 10) block->mos_cq = 10;
		}
	} else {
		block->loss_rate = 0;
		block->discard_rate = 0;
		block->burst_density = 0;
		block->gap_density = 0;
		block->burst_duration = htons(0);
		block->gap_duration = htons(0);
		block->round_trip_delay = htons(0);
		block->end_system_delay = htons(0);
		block->signal_level = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		block->noise_level = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		block->rerl = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		block->r_factor = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		block->ext_r_factor = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		block->mos_lq = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
		block->mos_cq = ORTP_RTCP_XR_UNAVAILABLE_PARAMETER;
	}
	return sizeof(rtcp_xr_voip_metrics_report_block_t);
}
示例#10
0
文件: qdisc_rio.c 项目: MarginC/kame
void
rio_stat_loop(int fd, const char *ifname, int count, int interval)
{
	struct rio_stats rio_stats;
	struct timeval cur_time, last_time;
	u_int64_t last_bytes[3];
	double sec;
	int cnt = count;
	sigset_t		omask;
	
	bzero(&rio_stats, sizeof(rio_stats));
	strlcpy(rio_stats.iface.rio_ifname, ifname,
		sizeof(rio_stats.iface.rio_ifname));

	gettimeofday(&last_time, NULL);
	last_time.tv_sec -= interval;

	while (count == 0 || cnt-- > 0) {
	
		if (ioctl(fd, RIO_GETSTATS, &rio_stats) < 0)
			err(1, "ioctl RIO_GETSTATS");

		gettimeofday(&cur_time, NULL);
		sec = calc_interval(&cur_time, &last_time);

		printf("weight:%d q_limit:%d\n",
		       rio_stats.weight, rio_stats.q_limit);

		printf("\t\t\tLOW DP\t\tMEDIUM DP\t\tHIGH DP\n");

		printf("thresh (prob):\t\t[%d,%d](1/%d)\t[%d,%d](1/%d)\t\t[%d,%d](1/%d)\n",
		       rio_stats.q_params[0].th_min,
		       rio_stats.q_params[0].th_max,
		       rio_stats.q_params[0].inv_pmax,
		       rio_stats.q_params[1].th_min,
		       rio_stats.q_params[1].th_max,
		       rio_stats.q_params[1].inv_pmax,
		       rio_stats.q_params[2].th_min,
		       rio_stats.q_params[2].th_max,
		       rio_stats.q_params[2].inv_pmax);
		printf("qlen (avg):\t\t%d (%.2f)\t%d (%.2f)\t\t%d (%.2f)\n",
		       rio_stats.q_len[0],
		       ((double)rio_stats.q_stats[0].q_avg)/(double)avg_scale,
		       rio_stats.q_len[1],
		       ((double)rio_stats.q_stats[1].q_avg)/(double)avg_scale,
		       rio_stats.q_len[2],
		       ((double)rio_stats.q_stats[2].q_avg)/(double)avg_scale);
		printf("xmit (drop) pkts:\t%llu (%llu)\t\t%llu (%llu)\t\t\t%llu (%llu)\n",
		       (ull)rio_stats.q_stats[0].xmit_cnt.packets,
		       (ull)rio_stats.q_stats[0].drop_cnt.packets,
		       (ull)rio_stats.q_stats[1].xmit_cnt.packets,
		       (ull)rio_stats.q_stats[1].drop_cnt.packets,
		       (ull)rio_stats.q_stats[2].xmit_cnt.packets,
		       (ull)rio_stats.q_stats[2].drop_cnt.packets);
		printf("(forced:early):\t\t(%u:%u)\t\t(%u:%u)\t\t\t(%u:%u)\n",
		       rio_stats.q_stats[0].drop_forced,
		       rio_stats.q_stats[0].drop_unforced,
		       rio_stats.q_stats[1].drop_forced,
		       rio_stats.q_stats[1].drop_unforced,
		       rio_stats.q_stats[2].drop_forced,
		       rio_stats.q_stats[2].drop_unforced);
		if (rio_stats.q_stats[0].marked_packets != 0
		    || rio_stats.q_stats[1].marked_packets != 0
		    || rio_stats.q_stats[2].marked_packets != 0)
			printf("marked:\t\t\t%u\t\t%u\t\t\t%u\n",
			       rio_stats.q_stats[0].marked_packets,
			       rio_stats.q_stats[1].marked_packets,
			       rio_stats.q_stats[2].marked_packets);
		printf("throughput:\t\t%sbps\t%sbps\t\t%sbps\n\n",
		       rate2str(calc_rate(rio_stats.q_stats[0].xmit_cnt.bytes,
					  last_bytes[0], sec)),
		       rate2str(calc_rate(rio_stats.q_stats[1].xmit_cnt.bytes,
					  last_bytes[1], sec)),
		       rate2str(calc_rate(rio_stats.q_stats[2].xmit_cnt.bytes,
					  last_bytes[2], sec)));

		last_bytes[0] = rio_stats.q_stats[0].xmit_cnt.bytes;
		last_bytes[1] = rio_stats.q_stats[1].xmit_cnt.bytes;
		last_bytes[2] = rio_stats.q_stats[2].xmit_cnt.bytes;
		last_time = cur_time;

		/* wait for alarm signal */
		if (sigprocmask(SIG_BLOCK, NULL, &omask) == 0)
			sigsuspend(&omask);
	}
}
示例#11
0
void can_stat_update(unsigned long data)
{
	unsigned long j = jiffies; 

	
	if (user_reset)
		can_init_stats();

	
	if (j < can_stats.jiffies_init)
		can_init_stats();

	
	if (can_stats.rx_frames > (ULONG_MAX / HZ))
		can_init_stats();

	
	if (can_stats.tx_frames > (ULONG_MAX / HZ))
		can_init_stats();

	
	if (can_stats.matches > (ULONG_MAX / 100))
		can_init_stats();

	
	if (can_stats.rx_frames)
		can_stats.total_rx_match_ratio = (can_stats.matches * 100) /
			can_stats.rx_frames;

	can_stats.total_tx_rate = calc_rate(can_stats.jiffies_init, j,
					    can_stats.tx_frames);
	can_stats.total_rx_rate = calc_rate(can_stats.jiffies_init, j,
					    can_stats.rx_frames);

	
	if (can_stats.rx_frames_delta)
		can_stats.current_rx_match_ratio =
			(can_stats.matches_delta * 100) /
			can_stats.rx_frames_delta;

	can_stats.current_tx_rate = calc_rate(0, HZ, can_stats.tx_frames_delta);
	can_stats.current_rx_rate = calc_rate(0, HZ, can_stats.rx_frames_delta);

	
	if (can_stats.max_tx_rate < can_stats.current_tx_rate)
		can_stats.max_tx_rate = can_stats.current_tx_rate;

	if (can_stats.max_rx_rate < can_stats.current_rx_rate)
		can_stats.max_rx_rate = can_stats.current_rx_rate;

	if (can_stats.max_rx_match_ratio < can_stats.current_rx_match_ratio)
		can_stats.max_rx_match_ratio = can_stats.current_rx_match_ratio;

	
	can_stats.tx_frames_delta = 0;
	can_stats.rx_frames_delta = 0;
	can_stats.matches_delta   = 0;

	
	mod_timer(&can_stattimer, round_jiffies(jiffies + HZ));
}
示例#12
0
文件: mix.cpp 项目: rsrsps/gzdoom
/* Returns 1 if envelope runs out */
bool SF2Envelope::Update(Voice *v)
{
	double sec;
	double newvolume = 0;

	switch (stage)
	{
	case SF2_DELAY:
		if (v->sample_count >= timecent_to_sec(DelayTime) * SampleRate)
		{
			stage = SF2_ATTACK;
			return Update(v);
		}
		return 0;

	case SF2_ATTACK:
		sec = timecent_to_sec(AttackTime);
		if (sec <= 0)
		{ // instantaneous attack
			newvolume = 1;
		}
		else
		{
			newvolume = volume + calc_rate(RateMul, sec);
		}
		if (newvolume >= 1)
		{
			volume = 0;
			HoldStart = v->sample_count;
			if (HoldTime <= -32768)
			{ // hold time is 0, so skip right to decay
				stage = SF2_DECAY;
			}
			else
			{
				stage = SF2_HOLD;
			}
			return Update(v);
		}
		break;

	case SF2_HOLD:
		if (v->sample_count - HoldStart >= timecent_to_sec(HoldTime) * SampleRate)
		{
			stage = SF2_DECAY;
			return Update(v);
		}
		return 0;

	case SF2_DECAY:
		sec = timecent_to_sec(DecayTime);
		if (sec <= 0)
		{ // instantaneous decay
			newvolume = SustainLevel;
		}
		else
		{
			newvolume = volume + calc_rate(RateMul_cB, sec);
		}
		if (newvolume >= SustainLevel)
		{
			newvolume = SustainLevel;
			stage = SF2_SUSTAIN;
			bUpdating = false;
			if (!(v->status & VOICE_RELEASING))
			{
				v->status |= VOICE_SUSTAINING;
			}
		}
		break;

	case SF2_SUSTAIN:
		// Stay here until released.
		return 0;

	case SF2_RELEASE:
		sec = timecent_to_sec(ReleaseTime);
		if (sec <= 0)
		{ // instantaneous release
			newvolume = 1000;
		}
		else
		{
			newvolume = volume + calc_rate(RateMul_cB, sec);
		}
		if (newvolume >= 960)
		{
			stage = SF2_FINISHED;
			shutoff_voice(v);
			bUpdating = false;
			return 1;
		}
		break;

	case SF2_FINISHED:
		return 1;
	}
	volume = (float)newvolume;
	return 0;
}
示例#13
0
文件: eta.c 项目: mavissong/fio
/*
 * Print status of the jobs we know about. This includes rate estimates,
 * ETA, thread state, etc.
 */
int calc_thread_status(struct jobs_eta *je, int force)
{
	struct thread_data *td;
	int i;
	unsigned long rate_time, disp_time, bw_avg_time, *eta_secs;
	unsigned long long io_bytes[DDIR_RWDIR_CNT];
	unsigned long long io_iops[DDIR_RWDIR_CNT];
	struct timeval now;

	static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT];
	static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT];
	static unsigned long long disp_io_iops[DDIR_RWDIR_CNT];
	static struct timeval rate_prev_time, disp_prev_time;

	if (!force) {
		if (output_format != FIO_OUTPUT_NORMAL)
			return 0;
		if (temp_stall_ts || eta_print == FIO_ETA_NEVER)
			return 0;

		if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
			return 0;
	}

	if (!ddir_rw_sum(rate_io_bytes))
		fill_start_time(&rate_prev_time);
	if (!ddir_rw_sum(disp_io_bytes))
		fill_start_time(&disp_prev_time);

	eta_secs = malloc(thread_number * sizeof(unsigned long));
	memset(eta_secs, 0, thread_number * sizeof(unsigned long));

	je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;

	io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0;
	io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0;
	bw_avg_time = ULONG_MAX;
	for_each_td(td, i) {
		if (is_power_of_2(td->o.kb_base))
			je->is_pow2 = 1;
		if (td->o.bw_avg_time < bw_avg_time)
			bw_avg_time = td->o.bw_avg_time;
		if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
		    || td->runstate == TD_FSYNCING
		    || td->runstate == TD_PRE_READING) {
			je->nr_running++;
			if (td_read(td)) {
				je->t_rate += td->o.rate[DDIR_READ];
				je->t_iops += td->o.rate_iops[DDIR_READ];
				je->m_rate += td->o.ratemin[DDIR_READ];
				je->m_iops += td->o.rate_iops_min[DDIR_READ];
			}
			if (td_write(td)) {
				je->t_rate += td->o.rate[DDIR_WRITE];
				je->t_iops += td->o.rate_iops[DDIR_WRITE];
				je->m_rate += td->o.ratemin[DDIR_WRITE];
				je->m_iops += td->o.rate_iops_min[DDIR_WRITE];
			}
			if (td_trim(td)) {
				je->t_rate += td->o.rate[DDIR_TRIM];
				je->t_iops += td->o.rate_iops[DDIR_TRIM];
				je->m_rate += td->o.ratemin[DDIR_TRIM];
				je->m_iops += td->o.rate_iops_min[DDIR_TRIM];
			}

			je->files_open += td->nr_open_files;
		} else if (td->runstate == TD_RAMP) {
			je->nr_running++;
			je->nr_ramp++;
		} else if (td->runstate == TD_SETTING_UP)
			je->nr_running++;
		else if (td->runstate < TD_RUNNING)
			je->nr_pending++;

		if (je->elapsed_sec >= 3)
			eta_secs[i] = thread_eta(td);
		else
			eta_secs[i] = INT_MAX;

		check_str_update(td);

		if (td->runstate > TD_RAMP) {
			int ddir;
			for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
				io_bytes[ddir] += td->io_bytes[ddir];
				io_iops[ddir] += td->io_blocks[ddir];
			}
		}
	}

	if (exitall_on_terminate)
		je->eta_sec = INT_MAX;
	else
		je->eta_sec = 0;

	for_each_td(td, i) {
		if (exitall_on_terminate) {
			if (eta_secs[i] < je->eta_sec)
				je->eta_sec = eta_secs[i];
		} else {
			if (eta_secs[i] > je->eta_sec)
				je->eta_sec = eta_secs[i];
		}
	}

	free(eta_secs);

	fio_gettime(&now, NULL);
	rate_time = mtime_since(&rate_prev_time, &now);

	if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
		calc_rate(rate_time, io_bytes, rate_io_bytes, je->rate);
		memcpy(&rate_prev_time, &now, sizeof(now));
		add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0);
		add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0);
		add_agg_sample(je->rate[DDIR_TRIM], DDIR_TRIM, 0);
	}

	disp_time = mtime_since(&disp_prev_time, &now);

	/*
	 * Allow a little slack, the target is to print it every 1000 msecs
	 */
	if (!force && disp_time < 900)
		return 0;

	calc_rate(disp_time, io_bytes, disp_io_bytes, je->rate);
	calc_iops(disp_time, io_iops, disp_io_iops, je->iops);

	memcpy(&disp_prev_time, &now, sizeof(now));

	if (!force && !je->nr_running && !je->nr_pending)
		return 0;

	je->nr_threads = thread_number;
	memcpy(je->run_str, run_str, thread_number * sizeof(char));

	return 1;
}
示例#14
0
文件: proc.c 项目: AlexShiLucky/linux
void can_stat_update(struct timer_list *t)
{
	struct net *net = from_timer(net, t, can.can_stattimer);
	struct s_stats *can_stats = net->can.can_stats;
	unsigned long j = jiffies; /* snapshot */

	/* restart counting in timer context on user request */
	if (user_reset)
		can_init_stats(net);

	/* restart counting on jiffies overflow */
	if (j < can_stats->jiffies_init)
		can_init_stats(net);

	/* prevent overflow in calc_rate() */
	if (can_stats->rx_frames > (ULONG_MAX / HZ))
		can_init_stats(net);

	/* prevent overflow in calc_rate() */
	if (can_stats->tx_frames > (ULONG_MAX / HZ))
		can_init_stats(net);

	/* matches overflow - very improbable */
	if (can_stats->matches > (ULONG_MAX / 100))
		can_init_stats(net);

	/* calc total values */
	if (can_stats->rx_frames)
		can_stats->total_rx_match_ratio = (can_stats->matches * 100) /
			can_stats->rx_frames;

	can_stats->total_tx_rate = calc_rate(can_stats->jiffies_init, j,
					    can_stats->tx_frames);
	can_stats->total_rx_rate = calc_rate(can_stats->jiffies_init, j,
					    can_stats->rx_frames);

	/* calc current values */
	if (can_stats->rx_frames_delta)
		can_stats->current_rx_match_ratio =
			(can_stats->matches_delta * 100) /
			can_stats->rx_frames_delta;

	can_stats->current_tx_rate = calc_rate(0, HZ, can_stats->tx_frames_delta);
	can_stats->current_rx_rate = calc_rate(0, HZ, can_stats->rx_frames_delta);

	/* check / update maximum values */
	if (can_stats->max_tx_rate < can_stats->current_tx_rate)
		can_stats->max_tx_rate = can_stats->current_tx_rate;

	if (can_stats->max_rx_rate < can_stats->current_rx_rate)
		can_stats->max_rx_rate = can_stats->current_rx_rate;

	if (can_stats->max_rx_match_ratio < can_stats->current_rx_match_ratio)
		can_stats->max_rx_match_ratio = can_stats->current_rx_match_ratio;

	/* clear values for 'current rate' calculation */
	can_stats->tx_frames_delta = 0;
	can_stats->rx_frames_delta = 0;
	can_stats->matches_delta   = 0;

	/* restart timer (one second) */
	mod_timer(&net->can.can_stattimer, round_jiffies(jiffies + HZ));
}