summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiuwen Lu <[email protected]>2015-12-23 14:27:18 +0800
committerQiuwen Lu <[email protected]>2015-12-23 14:27:18 +0800
commit01383b63d12f3c20a1c45e9d44dd507a840ba8c7 (patch)
treedc295a24cf1d2d232a379375e24fe68d36b55400
parent000b5ac525c2df8a21b650773fb8022bd175eabd (diff)
增加用于性能分析的统计功能udpstack-20151223
-rw-r--r--worker/udpstack.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/worker/udpstack.c b/worker/udpstack.c
index c12c6f2..2f3f9ef 100644
--- a/worker/udpstack.c
+++ b/worker/udpstack.c
@@ -24,19 +24,20 @@
#include <rte_spinlock.h>
#include <rte_rwlock.h>
#include <rte_byteorder.h>
+#include <rte_cycles.h>
+#include <rte_ethdev.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <MESA_prof_load.h>
-
#include "udpstack.h"
#include "main.h"
#include "sw_config.h"
-#include <rte_ethdev.h>
#include "nstat.h"
+
#ifdef _MSC_VER
#define rte_cpu_to_be_16(x) htons(x)
#define rte_be_to_cpu_32(x) ntohl(x)
@@ -49,6 +50,11 @@
#define USE_UDPSTACK_ARP_HOLD 0
#endif
+/* 运行时间统计 */
+#ifndef UDPSTACK_STAT_RUNTIME
+#define UDPSTACK_STAT_RUNTIME 1
+#endif
+
/* 最大的FD数量 */
#ifndef UDPSTACK_MAX_FD
#define UDPSTACK_MAX_FD 65536
@@ -315,9 +321,9 @@ struct udpstack_arp_table_rule
/* 待处理的数据包数量 */
unsigned int nb_hold;
/* 上次发送ARP请求的时间 */
- volatile time_t time;
+ time_t time;
/* 标志 */
- volatile uint8_t flags;
+ uint8_t flags;
};
struct udpstack_arp_table
@@ -610,6 +616,9 @@ struct udpstack_stat_record
uint64_t arp_request_recv;
uint64_t arp_reply_send;
uint64_t arp_reply_recv;
+
+ uint64_t runtime;
+ uint64_t cycles;
};
struct udpstack_lcore_handle
@@ -817,6 +826,13 @@ int udpstack_stat_dump(FILE * fp, struct udpstack_stat_record * handle)
fprintf(fp, " %-20s : %-20"PRIu64"\n", "ARP Request Recv", handle->arp_request_recv);
fprintf(fp, " %-20s : %-20"PRIu64"\n", "ARP Reply Send", handle->arp_reply_send);
fprintf(fp, " %-20s : %-20"PRIu64"\n", "ARP Reply Recv", handle->arp_reply_recv);
+
+#if UDPSTACK_STAT_RUNTIME
+ float runtime_per_cycle;
+ runtime_per_cycle = handle->cycles == 0 ? 0 : handle->runtime / (float)handle->cycles;
+ fprintf(fp, " %-20s : %-20.2f\n", "Runtime", runtime_per_cycle);
+#endif
+
return 0;
}
@@ -1190,6 +1206,10 @@ failure:
static ssize_t inline udpstack_sendto_bulk(int marsio_fd, struct marsio_udp_buff * buff, int flags,
struct sockaddr * to[], socklen_t addrlen[], int nb_sockaddrs)
{
+#if UDPSTACK_STAT_RUNTIME
+ uint64_t _tsc_start = rte_rdtsc();
+#endif
+
struct udpstack_lcore_handle * thread_handle = __get_thread_handle();
int ret = 0;
@@ -1228,6 +1248,13 @@ struct sockaddr * to[], socklen_t addrlen[], int nb_sockaddrs)
ret = udpstack_route_send_burst(header_mbuf, dst_ip, src_ip, l4_proto, nb_sockaddrs);
if (ret < 0) goto failure;
+
+#if UDPSTACK_STAT_RUNTIME
+ uint64_t _tsc_end = rte_rdtsc();
+ thread_handle->stat->runtime += _tsc_end - _tsc_start;
+ thread_handle->stat->cycles++;
+#endif
+
return 0;
failure: