Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jul 2010 14:08:45 GMT
From:      Alexandre Fiveg <afiveg@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180821 for review
Message-ID:  <201007121408.o6CE8jRQ046574@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@180821?ac=10

Change 180821 by afiveg@cottonmouth on 2010/07/12 14:08:31

	Extending the easy_pcap.c. easy_pcap is a program for testing ringmap. Now it can measure the cpu usage: after receive the first packet easy_pcap reads the "kern.cp_time" counters. By stopping capturing it reads the counters again and compute percent values for user, nice, syst, intr and idle.

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#10 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#10 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#12 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#17 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#25 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#24 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#22 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#14 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#28 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#28 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#12 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#13 edit
.. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#8 edit
.. //depot/projects/soc2010/ringmap/tests/libpcap/easy_pcap.c#7 edit

Differences ...

==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#10 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#10 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#12 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#17 (text+ko) ====

@@ -342,10 +342,11 @@
 		return (-1);
 	}
 
-	printf("\nSYSTEM STATISTICS:\n");
-	printf("----------------- \n");
 	printf("Ring-Full  counter:  %llu\n", p->ring->kern_wait_user);
 	printf("Ring-Empty counter:  %llu\n", p->ring->user_wait_kern);
+	printf("Interrupt counter:  %llu\n", p->ring->intr_num);
+	printf("Pkts per interrupt:  %llu\n", 
+			(p->ring->pkt_counter / p->ring->intr_num));
 
 	return (err);
 }

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#25 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#24 (text+ko) ====

@@ -142,25 +142,25 @@
 {
 	struct adapter	*adapter = (struct adapter *)context;
 	struct capt_object *co = NULL;
+	struct timeval	last_ts;
 
 	RINGMAP_INTR(start);
+	RINGMAP_LOCK(adapter->rm);
 
-	RINGMAP_LOCK(adapter->rm);
+	getmicrotime(&last_ts);
+	rm_8254_sync_tail(adapter->dev);
 
 	SLIST_FOREACH(co, &adapter->rm->object_list, objects) {
 		if (co->ring != NULL) {
 #if (__RINGMAP_DEB)
 			PRINT_RING_PTRS(co->ring);
 #endif
-			rm_8254_sync_tail(adapter->dev);
-#ifdef RINGMAP_TIMESTAMP
-			getmicrotime(&co->ring->last_ts);
-#endif
+			co->ring->last_ts = last_ts;
+			co->ring->intr_num = co->rm->interrupts_counter;
 		}
 	}
 
 	RINGMAP_UNLOCK(adapter->rm);
-
 	RINGMAP_INTR(end);
 }
 

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#22 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#14 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#28 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#28 (text+ko) ====

@@ -126,6 +126,8 @@
 
 	struct timeval	last_ts;
 
+	unsigned long long intr_num;
+
 	/* Ring identification. Should be initialized with process ID */
 	unsigned int pid;
 

==== //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#12 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#13 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#8 (text+ko) ====


==== //depot/projects/soc2010/ringmap/tests/libpcap/easy_pcap.c#7 (text+ko) ====

@@ -9,6 +9,9 @@
 #include <time.h>
 #include <signal.h>
 
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
 #include <machine/bus.h>
 
 #include <pcap-int.h>
@@ -27,6 +30,16 @@
 unsigned long pcnt = 0;
 long pkt_limit = 0;
 
+#define CPUSAGE "kern.cp_time"
+/* 
+ * Arrays of the cpu times 
+ * 'user', 'nice', 'sys', 'intr', 'idle'.
+ */
+int cpusage_first[5];
+int cpusage_last[5];
+
+
+
 /* Time stamps from first and last captured packets */
 struct timeval first_timestamp ;
 struct timeval last_timestamp ;
@@ -137,21 +150,32 @@
 {
 	unsigned long pps = 0;
 	unsigned long cap_time = 0;
-		
+	float cpusage_sum;
+	float user_perc, idle_perc, syst_perc, intr_perc, nice_perc;
+
 	stop_cpusage_measurement();
 
+	/* Time for capturing + pkts/sec */
 	cap_time = 
 		((last_timestamp.tv_sec*1000000+last_timestamp.tv_usec)  - 
 		(first_timestamp.tv_sec*1000000+first_timestamp.tv_usec))/1000000;
 	if ( !cap_time )
 		cap_time = 1;
+	pps = pcnt / cap_time;
 
-	pps = pcnt / cap_time;
+	/* CPU usage */
+	cpusage_sum = (cpusage_last[0] + cpusage_last[1] + cpusage_last[2] + 
+			cpusage_last[3] + cpusage_last[4]) - 
+				  (cpusage_first[0] + cpusage_first[1] + cpusage_first[2] + 
+			cpusage_first[3] + cpusage_first[4]);
+	user_perc = (((cpusage_last[0] - cpusage_first[0]) * 100) / cpusage_sum) ;
+	nice_perc = (((cpusage_last[1] - cpusage_first[1]) * 100) / cpusage_sum) ;
+	syst_perc = (((cpusage_last[2] - cpusage_first[2]) * 100) / cpusage_sum) ;
+	intr_perc = (((cpusage_last[3] - cpusage_first[3]) * 100) / cpusage_sum) ;
+	idle_perc = (((cpusage_last[4] - cpusage_first[4]) * 100) / cpusage_sum) ;
 
 	/* Print stats */
-	printf("\n\nRESULTS:\n \n");
-	printf("++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
-	printf("\n");
+	printf("\n\nRESULTS:\n\n");
 	printf("PROCESS STATISTICS: \n");
 	printf("------------------  \n");
 	printf("Captured: %lu pkts\n", pcnt);
@@ -163,19 +187,42 @@
 	/* Our function from libpcap */
 	printf("RINGMAP STATISTICS: \n");
 	printf("------------------  \n");
+	print_ring_stats(handle);
+	printf("------------------  \n\n");
 #endif 
 
+unsigned int a=5, b=3, c;
+	c = a*100/b;
+
+	/* Print cpu usage */
+	printf("CPU usage:  \n");
+	printf("------------------  \n");
+	printf("user: %.2f , nice: %.2f , syst: %.2f , intr: %.2f , idle: %.2f\n", 
+			user_perc, nice_perc, syst_perc, intr_perc, idle_perc);
+	printf("------------------  \n");
+
 
 	/* close pcap */
 	if (handle != NULL)
 		pcap_close(handle);
 }
 
+/*
+ * TODO: do it better with one func :)
+ */
 void stop_cpusage_measurement()
 {
-	;
+	size_t oldlenp = sizeof(int[5]);
+
+	if (sysctlbyname(CPUSAGE, cpusage_last, &oldlenp, NULL, 0) == -1)
+		perror("sysctl");
 }
+
+
 void start_cpusage_measurement()
 {
-	;
+	size_t oldlenp = sizeof(int[5]);
+
+	if (sysctlbyname(CPUSAGE, cpusage_first, &oldlenp, NULL, 0) == -1)
+		perror("sysctl");
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007121408.o6CE8jRQ046574>