当前位置: 首页>>代码示例>>C++>>正文


C++ rte_rdtsc函数代码示例

本文整理汇总了C++中rte_rdtsc函数的典型用法代码示例。如果您正苦于以下问题:C++ rte_rdtsc函数的具体用法?C++ rte_rdtsc怎么用?C++ rte_rdtsc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rte_rdtsc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: get_machclk_freq

/**
 * get the clk frequency in Hz
 */
static uint64_t get_machclk_freq(void)
{
	uint64_t start = 0;
	uint64_t end = 0;
	uint64_t diff = 0;
	uint64_t clk_freq_hz = 0;
	struct timespec tv_start = {0, 0}, tv_end = {0, 0};
	struct timespec req = {0, 0};

	req.tv_sec = 1;
	req.tv_nsec = 0;

	clock_gettime(CLOCK_REALTIME, &tv_start);
	start = rte_rdtsc();

	if (nanosleep(&req, NULL) != 0) {
		perror("get_machclk_freq()");
		exit(EXIT_FAILURE);
	}

	clock_gettime(CLOCK_REALTIME, &tv_end);
	end = rte_rdtsc();

	diff = (uint64_t)(tv_end.tv_sec - tv_start.tv_sec) * USEC_PER_SEC
		+ ((tv_end.tv_nsec - tv_start.tv_nsec + TEST_NSEC_MARGIN) /
		   USEC_PER_MSEC); /**< diff is in micro secs */

	if (diff == 0)
		return 0;

	clk_freq_hz = ((end - start) * USEC_PER_SEC / diff);
	return clk_freq_hz;
}
开发者ID:0day-ci,项目名称:dpdk,代码行数:36,代码来源:test_red.c

示例2: pktgen_interact

void
pktgen_interact(struct cmdline *cl)
{
	char c;
	struct pollfd fds;
	uint64_t curr_tsc;
	uint64_t next_poll;
	uint64_t reload;

	fds.fd      = cl->s_in;
	fds.events  = POLLIN;
	fds.revents = 0;

	c = -1;
	reload = (pktgen.hz / 1000);
	next_poll = rte_rdtsc() + reload;

	for (;; ) {
		rte_timer_manage();
		curr_tsc = rte_rdtsc();
		if (unlikely(curr_tsc >= next_poll)  ) {
			next_poll = curr_tsc + reload;
			if (poll(&fds, 1, 0) ) {
				if ( (fds.revents & (POLLERR | POLLNVAL | POLLHUP)) )
					break;
				if ( (fds.revents & POLLIN) ) {
					if (read(cl->s_in, &c, 1) < 0)
						break;
					if (cmdline_in(cl, &c, 1) < 0)
						break;
				}
			}
		}
	}
}
开发者ID:megahall,项目名称:pktgen-dpdk,代码行数:35,代码来源:pktgen-main.c

示例3: timed_deletes

static int
timed_deletes(struct efd_perf_params *params)
{
	unsigned int i, a;
	const uint64_t start_tsc = rte_rdtsc();
	int32_t ret;

	for (i = 0; i < KEYS_TO_ADD; i++) {
		ret = rte_efd_delete(params->efd_table, test_socket_id, keys[i],
				NULL);

		if (ret != 0) {
			printf("Error %d in rte_efd_delete - key=0x", ret);
			for (a = 0; a < params->key_size; a++)
				printf("%02x", keys[i][a]);
			printf("\n");

			return -1;
		}
	}

	const uint64_t end_tsc = rte_rdtsc();
	const uint64_t time_taken = end_tsc - start_tsc;

	cycles[params->cycle][DELETE] = time_taken / KEYS_TO_ADD;

	return 0;
}
开发者ID:Leon555,项目名称:dpdk,代码行数:28,代码来源:test_efd_perf.c

示例4: timed_lookups

static int
timed_lookups(struct efd_perf_params *params)
{
	unsigned int i, j, a;
	const uint64_t start_tsc = rte_rdtsc();
	efd_value_t ret_data;

	for (i = 0; i < NUM_LOOKUPS / KEYS_TO_ADD; i++) {
		for (j = 0; j < KEYS_TO_ADD; j++) {
			ret_data = rte_efd_lookup(params->efd_table,
					test_socket_id, keys[j]);
			if (ret_data != data[j]) {
				printf("Value mismatch using rte_efd_lookup: "
						"key #%d (0x", i);
				for (a = 0; a < params->key_size; a++)
					printf("%02x", keys[i][a]);
				printf(")\n");
				printf("  Expected %d, got %d\n", data[i],
						ret_data);

				return -1;
			}

		}
	}

	const uint64_t end_tsc = rte_rdtsc();
	const uint64_t time_taken = end_tsc - start_tsc;

	cycles[params->cycle][LOOKUP] = time_taken / NUM_LOOKUPS;

	return 0;
}
开发者ID:Leon555,项目名称:dpdk,代码行数:33,代码来源:test_efd_perf.c

示例5: sched_module_tb_init

/*
functional description:
token-bucket initialization module
author:jzheng
date:2014-06-02
*/
int sched_module_tb_init(dbg_local struct rte_mbuf*pktbuf,struct sched_stat_str *lpstat)
{
	if(lpstat->iDiscard==TRUE)
		return -1;
	#if 0
	if(lpstat->iFlowIdx==-1)
		return -1;
	#endif
	if(gFlow[lpstat->iFlowIdx].b_tb_initialized==TRUE)
		return 1;
	gFlow[lpstat->iFlowIdx].tb_uptream.eMeterMode=COLOR_BLIND;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiCBS=DEF_COMMIT_BURST_SIZE;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiCIR=DEF_COMMIT_INFO_RATE;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiPBS=DEF_PEEK_BURST_SIZE;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiPIR=DEF_PEEK_INFO_RATE;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiCToken=gFlow[lpstat->iFlowIdx].tb_uptream.uiCBS;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiPToken=gFlow[lpstat->iFlowIdx].tb_uptream.uiPBS;
	gFlow[lpstat->iFlowIdx].tb_uptream.uiCntLast=rte_rdtsc();
	
	gFlow[lpstat->iFlowIdx].tb_downstream.eMeterMode=COLOR_BLIND;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiCBS=DEF_COMMIT_BURST_SIZE;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiCIR=DEF_COMMIT_INFO_RATE;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiPBS=DEF_PEEK_BURST_SIZE;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiPIR=DEF_PEEK_INFO_RATE;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiCToken=gFlow[lpstat->iFlowIdx].tb_downstream.uiCBS;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiPToken=gFlow[lpstat->iFlowIdx].tb_downstream.uiPBS;
	gFlow[lpstat->iFlowIdx].tb_downstream.uiCntLast=rte_rdtsc();

	gFlow[lpstat->iFlowIdx].b_tb_initialized=TRUE;
	return 0;
}
开发者ID:chillancezen,项目名称:l3_switch,代码行数:37,代码来源:l3switch_sched.c

示例6: time_cache_line_switch

/* test case to time the number of cycles to round-trip a cache line between
 * two cores and back again.
 */
static void
time_cache_line_switch(void)
{
	/* allocate a full cache line for data, we use only first byte of it */
	uint64_t data[RTE_CACHE_LINE_SIZE*3 / sizeof(uint64_t)];

	unsigned i, slaveid = rte_get_next_lcore(rte_lcore_id(), 0, 0);
	volatile uint64_t *pdata = &data[0];
	*pdata = 1;
	rte_eal_remote_launch((lcore_function_t *)flip_bit, &data[0], slaveid);
	while (*pdata)
		rte_pause();

	const uint64_t start_time = rte_rdtsc();
	for (i = 0; i < (1 << ITER_POWER); i++) {
		while (*pdata)
			rte_pause();
		*pdata = 1;
	}
	const uint64_t end_time = rte_rdtsc();

	while (*pdata)
		rte_pause();
	*pdata = 2;
	rte_eal_wait_lcore(slaveid);
	printf("==== Cache line switch test ===\n");
	printf("Time for %u iterations = %"PRIu64" ticks\n", (1<<ITER_POWER),
			end_time-start_time);
	printf("Ticks per iteration = %"PRIu64"\n\n",
			(end_time-start_time) >> ITER_POWER);
}
开发者ID:Lanyaaki,项目名称:ipaugenblick,代码行数:34,代码来源:test_distributor_perf.c

示例7: timed_deletes

static int
timed_deletes(unsigned with_hash, unsigned with_data, unsigned table_index)
{
	unsigned i;
	const uint64_t start_tsc = rte_rdtsc();
	int32_t ret;

	for (i = 0; i < KEYS_TO_ADD; i++) {
		/* There are no delete functions with data, so just call two functions */
		if (with_hash)
			ret = rte_hash_del_key_with_hash(h[table_index],
							(const void *) keys[i],
							signatures[i]);
		else
			ret = rte_hash_del_key(h[table_index],
							(const void *) keys[i]);
		if (ret >= 0)
			positions[i] = ret;
		else {
			printf("Failed to add key number %u\n", ret);
			return -1;
		}
	}

	const uint64_t end_tsc = rte_rdtsc();
	const uint64_t time_taken = end_tsc - start_tsc;

	cycles[table_index][DELETE][with_hash][with_data] = time_taken/KEYS_TO_ADD;

	return 0;
}
开发者ID:Di0gen,项目名称:test_jenkins_project,代码行数:31,代码来源:test_hash_perf.c

示例8: rx_pkt_sw

uint16_t rx_pkt_sw(struct rte_mbuf **rx_mbuf, struct task_base *ptask)
{
	START_EMPTY_MEASSURE();
#ifdef BRAS_RX_BULK
	if (unlikely (rte_ring_sc_dequeue_bulk(ptask->rx_params_sw.rx_rings[ptask->rx_params_sw.last_read_ring], (void **)rx_mbuf, MAX_RING_BURST)) < 0) {
		++ptask->rx_params_sw.last_read_ring;
		if (unlikely(ptask->rx_params_sw.last_read_ring == ptask->rx_params_sw.nb_rxrings)) {
			ptask->rx_params_sw.last_read_ring = 0;
		}
		INCR_EMPTY_CYCLES(ptask->stats, rte_rdtsc() - cur_tsc);
		return 0;
	}
	else {

		return MAX_RING_BURST;
	}
#else
	uint16_t nb_rx = rte_ring_sc_dequeue_burst(ptask->rx_params_sw.rx_rings[ptask->rx_params_sw.last_read_ring], (void **)rx_mbuf, MAX_RING_BURST);
	++ptask->rx_params_sw.last_read_ring;
	if (unlikely(ptask->rx_params_sw.last_read_ring == ptask->rx_params_sw.nb_rxrings)) {
		ptask->rx_params_sw.last_read_ring = 0;
	}

	if (nb_rx != 0) {
		return nb_rx;
	}
	else {
		INCR_EMPTY_CYCLES(ptask->stats, rte_rdtsc() - cur_tsc);
		return 0;
	}
#endif
}
开发者ID:gonzopancho,项目名称:dppd-BRAS,代码行数:32,代码来源:rx_pkt.c

示例9: time_update

s32 time_update(void)
{
#if 0
	//int ret = US_RET_OK;
	//int sec_delta = 0; 
	//struct timeval tv;

	//cycles = rte_get_hpet_cycles();
	cycles = rte_rdtsc();

	if( (ret = gettimeofday((struct timeval*)&tv, NULL))< 0){
		return ret;
	}	

	sec_delta = ((tv.tv_sec - Ts.tv_sec)*1000000 + (tv.tv_usec - Ts.tv_nsec/1000))/1000;

	if (sec_delta > 0 ){
		jiffies += sec_delta;
		
		Ts.tv_sec = tv.tv_sec;
		Ts.tv_nsec = tv.tv_usec*1000;	
	}

#else
	
	u64 sec_1_cnt ;
	u64 ms_1_cnt ;
	u64	us_1_cnt ;
	u64 t_delta;
	
	sec_1_cnt = rte_get_timer_hz();
	ms_1_cnt  = sec_1_cnt/1000;
	us_1_cnt  = ms_1_cnt/1000;
	
	cycles = rte_rdtsc();

	t_delta = cycles - last_1us_cycle;
	if(t_delta > us_1_cnt){
		tv_usec += t_delta/us_1_cnt;
		if(Ts.tv_nsec >1000000){
			Ts.tv_nsec = 0;
			Ts.tv_sec++;
		}else{
			Ts.tv_nsec = tv_usec*1000;
		}
		last_1us_cycle = cycles;
	}
	
	t_delta = cycles - last_1ms_cycle;
	if(t_delta > ms_1_cnt){
		jiffies += t_delta/ms_1_cnt ;
		last_1ms_cycle = cycles;
	}
	
	return US_RET_OK;
#endif	
}
开发者ID:lehoon,项目名称:fast-tcp,代码行数:57,代码来源:us_time.c

示例10: softnic_fwd

/*
 * Softnic packet forward
 */
static void
softnic_fwd(struct fwd_stream *fs)
{
	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
	uint16_t nb_rx;
	uint16_t nb_tx;
	uint32_t retry;

#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
	uint64_t start_tsc;
	uint64_t end_tsc;
	uint64_t core_cycles;
#endif

#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
	start_tsc = rte_rdtsc();
#endif

	/*  Packets Receive */
	nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue,
			pkts_burst, nb_pkt_per_burst);
	fs->rx_packets += nb_rx;

#ifdef RTE_TEST_PMD_RECORD_BURST_STATS
	fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
#endif

	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
			pkts_burst, nb_rx);

	/* Retry if necessary */
	if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
		retry = 0;
		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
			rte_delay_us(burst_tx_delay_time);
			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
					&pkts_burst[nb_tx], nb_rx - nb_tx);
		}
	}
	fs->tx_packets += nb_tx;

#ifdef RTE_TEST_PMD_RECORD_BURST_STATS
	fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
#endif

	if (unlikely(nb_tx < nb_rx)) {
		fs->fwd_dropped += (nb_rx - nb_tx);
		do {
			rte_pktmbuf_free(pkts_burst[nb_tx]);
		} while (++nb_tx < nb_rx);
	}
#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
	end_tsc = rte_rdtsc();
	core_cycles = (end_tsc - start_tsc);
	fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
#endif
}
开发者ID:DrenfongWong,项目名称:dpdk,代码行数:60,代码来源:softnicfwd.c

示例11: estimate_tsc_freq

static uint64_t
estimate_tsc_freq(void)
{
	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
		" - clock timings may be less accurate.\n");
	/* assume that the sleep(1) will sleep for 1 second */
	uint64_t start = rte_rdtsc();
	sleep(1);
	return rte_rdtsc() - start;
}
开发者ID:Di0gen,项目名称:test_jenkins_project,代码行数:10,代码来源:eal_common_timer.c

示例12: enqueue_check

static __rte_always_inline uint32_t
enqueue_check(struct opdl_port *p,
		const struct rte_event ev[],
		uint16_t num,
		uint16_t num_events)
{
	uint16_t i;

	if (p->opdl->do_validation) {

		for (i = 0; i < num; i++) {
			if (ev[i].queue_id != p->next_external_qid) {
				PMD_DRV_LOG(ERR, "DEV_ID:[%02d] : "
					     "ERROR - port:[%u] - event wants"
					     " to enq to q_id[%u],"
					     " but should be [%u]",
					     opdl_pmd_dev_id(p->opdl),
					     p->id,
					     ev[i].queue_id,
					     p->next_external_qid);
				rte_errno = -EINVAL;
				return 0;
			}
		}

		/* Stats */
		if (p->p_type == OPDL_PURE_RX_PORT ||
				p->p_type == OPDL_ASYNC_PORT) {
			/* Stats */
			if (num_events) {
				p->port_stat[claim_pkts_requested] += num;
				p->port_stat[claim_pkts_granted] += num_events;
				p->port_stat[claim_non_empty]++;
				p->start_cycles = rte_rdtsc();
			} else {
				p->port_stat[claim_empty]++;
				p->start_cycles = 0;
			}
		} else {
			if (p->start_cycles) {
				uint64_t end_cycles = rte_rdtsc();
				p->port_stat[total_cycles] +=
					end_cycles - p->start_cycles;
			}
		}
	} else {
		if (num > 0 &&
				ev[0].queue_id != p->next_external_qid) {
			rte_errno = -EINVAL;
			return 0;
		}
	}

	return num;
}
开发者ID:bisdn,项目名称:dpdk-dev,代码行数:55,代码来源:opdl_evdev_init.c

示例13: thread_lb

int thread_lb(struct lcore_cfg *lconf)
{
	struct rte_mbuf *rx_mbuf[MAX_RING_BURST] __rte_cache_aligned;
	struct task_base *task[MAX_TASKS_PER_CORE];
	uint64_t cur_tsc = rte_rdtsc();
	uint64_t next_term_tsc = cur_tsc + TERM_TIMEOUT;
	uint64_t drain_tsc = cur_tsc + DRAIN_TIMEOUT;
	const uint8_t nb_tasks = lconf->nb_tasks;

	for (uint8_t task_id = 0; task_id < nb_tasks; ++task_id) {
		task[task_id] = lconf->task[task_id];
	}

	for (;;) {
		cur_tsc = rte_rdtsc();
		if (cur_tsc > drain_tsc) {
			drain_tsc = cur_tsc + DRAIN_TIMEOUT;

			FLUSH_STATS(lconf);
			/* check for termination request every timeout */
			if (cur_tsc > next_term_tsc) {
				next_term_tsc = cur_tsc + TERM_TIMEOUT;
				if (is_terminated(lconf)) {
					break;
				}


			}
			for (uint8_t task_id = 0; task_id < nb_tasks; ++task_id) {

				if (!(task[task_id]->flags & (FLAG_TX_FLUSH | FLAG_NEVER_FLUSH))) {
					// Do not flush packets if we transmitted packets in last drain_timeout
					// This avoid flushing queue under load every x seconds
					task[task_id]->flags |= FLAG_TX_FLUSH;
					continue;
				}
				/* This part of the code is only run on low load - when we need to flush,
				   i.e. when we did not send a bulk packets within last drain_timeout (16kpps if DRAIN_TIMEOUT=2msec).
				   All queues are flushed in this case */
				task[task_id]->flush_queues(task[task_id]);
			}
		}

		for (uint8_t task_id = 0; task_id < nb_tasks; ++task_id) {
			uint16_t nb_rx = task[task_id]->rx_pkt(rx_mbuf, task[task_id]);

			if (likely(nb_rx)) {
				INCR_NBRX(nb_rx);
				INCR_RX_PKT_COUNT(task[task_id]->stats, nb_rx);
				task[task_id]->handle_pkt_bulk(rx_mbuf, task[task_id], nb_rx);
			}
		}
	}
	return 0;
}
开发者ID:gonzopancho,项目名称:dppd-BRAS,代码行数:55,代码来源:thread_lb.c

示例14: app_ping

void
app_ping(void)
{
	unsigned i;
	uint64_t timestamp, diff_tsc;

	const uint64_t timeout = rte_get_tsc_hz() * APP_PING_TIMEOUT_SEC;

	for (i = 0; i < RTE_MAX_LCORE; i++) {
		struct app_core_params *p = &app.cores[i];
		struct rte_ring *ring_req, *ring_resp;
		void *msg;
		struct app_msg_req *req;
		int status;

		if ((p->core_type != APP_CORE_FC) &&
		    (p->core_type != APP_CORE_FW) &&
			(p->core_type != APP_CORE_RT) &&
			(p->core_type != APP_CORE_RX))
			continue;

		ring_req = app_get_ring_req(p->core_id);
		ring_resp = app_get_ring_resp(p->core_id);

		/* Fill request message */
		msg = (void *)rte_ctrlmbuf_alloc(app.msg_pool);
		if (msg == NULL)
			rte_panic("Unable to allocate new message\n");

		req = (struct app_msg_req *)
				rte_ctrlmbuf_data((struct rte_mbuf *)msg);
		req->type = APP_MSG_REQ_PING;

		/* Send request */
		do {
			status = rte_ring_sp_enqueue(ring_req, msg);
		} while (status == -ENOBUFS);

		/* Wait for response */
		timestamp = rte_rdtsc();
		do {
			status = rte_ring_sc_dequeue(ring_resp, &msg);
			diff_tsc = rte_rdtsc() - timestamp;

			if (unlikely(diff_tsc > timeout))
				rte_panic("Core %u of type %d does not respond "
					"to requests\n", p->core_id,
					p->core_type);
		} while (status != 0);

		/* Free message buffer */
		rte_ctrlmbuf_free(msg);
	}
}
开发者ID:Cosios,项目名称:dpdk,代码行数:54,代码来源:init.c

示例15: timed_adds

static int
timed_adds(unsigned with_hash, unsigned with_data, unsigned table_index)
{
	unsigned i;
	const uint64_t start_tsc = rte_rdtsc();
	void *data;
	int32_t ret;

	for (i = 0; i < KEYS_TO_ADD; i++) {
		data = (void *) ((uintptr_t) signatures[i]);
		if (with_hash && with_data) {
			ret = rte_hash_add_key_with_hash_data(h[table_index],
						(const void *) keys[i],
						signatures[i], data);
			if (ret < 0) {
				printf("Failed to add key number %u\n", ret);
				return -1;
			}
		} else if (with_hash && !with_data) {
			ret = rte_hash_add_key_with_hash(h[table_index],
						(const void *) keys[i],
						signatures[i]);
			if (ret >= 0)
				positions[i] = ret;
			else {
				printf("Failed to add key number %u\n", ret);
				return -1;
			}
		} else if (!with_hash && with_data) {
			ret = rte_hash_add_key_data(h[table_index],
						(const void *) keys[i],
						data);
			if (ret < 0) {
				printf("Failed to add key number %u\n", ret);
				return -1;
			}
		} else {
			ret = rte_hash_add_key(h[table_index], keys[i]);
			if (ret >= 0)
				positions[i] = ret;
			else {
				printf("Failed to add key number %u\n", ret);
				return -1;
			}
		}
	}

	const uint64_t end_tsc = rte_rdtsc();
	const uint64_t time_taken = end_tsc - start_tsc;

	cycles[table_index][ADD][with_hash][with_data] = time_taken/KEYS_TO_ADD;

	return 0;
}
开发者ID:Di0gen,项目名称:test_jenkins_project,代码行数:54,代码来源:test_hash_perf.c


注:本文中的rte_rdtsc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。