public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure
@ 2012-06-23  9:47 Marek Lindner
  2012-06-23  9:49 ` [B.A.T.M.A.N.] [PATCH] batctl: purge redundant statistic code Marek Lindner
  2012-06-25 11:07 ` [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Martin Hundebøll
  0 siblings, 2 replies; 5+ messages in thread
From: Marek Lindner @ 2012-06-23  9:47 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Marek Lindner

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 bridge_loop_avoidance.c |    5 ++-
 soft-interface.c        |   50 +++++++++++++++++++++++++++++++----------------
 types.h                 |    5 ++++
 3 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 1e2cfe5..b92b0ea 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -338,8 +338,9 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac,
 
 	skb_reset_mac_header(skb);
 	skb->protocol = eth_type_trans(skb, soft_iface);
-	bat_priv->stats.rx_packets++;
-	bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
+	batadv_inc_counter(bat_priv, BATADV_CNT_RX);
+	batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
+			   skb->len + ETH_HLEN);
 	soft_iface->last_rx = jiffies;
 
 	netif_rx(skb);
diff --git a/soft-interface.c b/soft-interface.c
index b7c655c..e06480a 100644
--- a/soft-interface.c
+++ b/soft-interface.c
@@ -93,7 +93,14 @@ static int batadv_interface_release(struct net_device *dev)
 static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
 {
 	struct batadv_priv *bat_priv = netdev_priv(dev);
-	return &bat_priv->stats;
+	struct net_device_stats *stats = &bat_priv->stats;
+
+	stats->tx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_TX);
+	stats->tx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_TX_BYTES);
+	stats->tx_dropped = batadv_sum_counter(bat_priv, BATADV_CNT_TX_DROPPED);
+	stats->rx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_RX);
+	stats->rx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_RX_BYTES);
+	return stats;
 }
 
 static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
@@ -245,14 +252,14 @@ static int batadv_interface_tx(struct sk_buff *skb,
 			goto dropped_freed;
 	}
 
-	bat_priv->stats.tx_packets++;
-	bat_priv->stats.tx_bytes += data_len;
+	batadv_inc_counter(bat_priv, BATADV_CNT_TX);
+	batadv_add_counter(bat_priv, BATADV_CNT_TX_BYTES, data_len);
 	goto end;
 
 dropped:
 	kfree_skb(skb);
 dropped_freed:
-	bat_priv->stats.tx_dropped++;
+	batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED);
 end:
 	if (primary_if)
 		batadv_hardif_free_ref(primary_if);
@@ -303,8 +310,9 @@ void batadv_interface_rx(struct net_device *soft_iface,
 
 	/* skb->ip_summed = CHECKSUM_UNNECESSARY; */
 
-	bat_priv->stats.rx_packets++;
-	bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
+	batadv_inc_counter(bat_priv, BATADV_CNT_RX);
+	batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
+			   skb->len + ETH_HLEN);
 
 	soft_iface->last_rx = jiffies;
 
@@ -374,15 +382,21 @@ struct net_device *batadv_softif_create(const char *name)
 	if (!soft_iface)
 		goto out;
 
+	bat_priv = netdev_priv(soft_iface);
+
+	/* batadv_interface_stats() needs to be available as soon as
+	 * register_netdevice() has been called */
+	bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t));
+	if (!bat_priv->bat_counters)
+		goto free_soft_iface;
+
 	ret = register_netdevice(soft_iface);
 	if (ret < 0) {
 		pr_err("Unable to register the batman interface '%s': %i\n",
 		       name, ret);
-		goto free_soft_iface;
+		goto free_bat_counters;
 	}
 
-	bat_priv = netdev_priv(soft_iface);
-
 	atomic_set(&bat_priv->aggregated_ogms, 1);
 	atomic_set(&bat_priv->bonding, 0);
 	atomic_set(&bat_priv->bridge_loop_avoidance, 0);
@@ -412,17 +426,13 @@ struct net_device *batadv_softif_create(const char *name)
 	bat_priv->primary_if = NULL;
 	bat_priv->num_ifaces = 0;
 
-	bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t));
-	if (!bat_priv->bat_counters)
-		goto unreg_soft_iface;
-
 	ret = batadv_algo_select(bat_priv, batadv_routing_algo);
 	if (ret < 0)
-		goto free_bat_counters;
+		goto unreg_soft_iface;
 
 	ret = batadv_sysfs_add_meshif(soft_iface);
 	if (ret < 0)
-		goto free_bat_counters;
+		goto unreg_soft_iface;
 
 	ret = batadv_debugfs_add_meshif(soft_iface);
 	if (ret < 0)
@@ -438,12 +448,13 @@ unreg_debugfs:
 	batadv_debugfs_del_meshif(soft_iface);
 unreg_sysfs:
 	batadv_sysfs_del_meshif(soft_iface);
-free_bat_counters:
-	free_percpu(bat_priv->bat_counters);
 unreg_soft_iface:
+	free_percpu(bat_priv->bat_counters);
 	unregister_netdevice(soft_iface);
 	return NULL;
 
+free_bat_counters:
+	free_percpu(bat_priv->bat_counters);
 free_soft_iface:
 	free_netdev(soft_iface);
 out:
@@ -513,6 +524,11 @@ static u32 batadv_get_link(struct net_device *dev)
 static const struct {
 	const char name[ETH_GSTRING_LEN];
 } batadv_counters_strings[] = {
+	{ "tx" },
+	{ "tx_bytes" },
+	{ "tx_dropped" },
+	{ "rx" },
+	{ "rx_bytes" },
 	{ "forward" },
 	{ "forward_bytes" },
 	{ "mgmt_tx" },
diff --git a/types.h b/types.h
index 2141c13..64b4317 100644
--- a/types.h
+++ b/types.h
@@ -144,6 +144,11 @@ struct batadv_bcast_duplist_entry {
 #endif
 
 enum batadv_counters {
+	BATADV_CNT_TX,
+	BATADV_CNT_TX_BYTES,
+	BATADV_CNT_TX_DROPPED,
+	BATADV_CNT_RX,
+	BATADV_CNT_RX_BYTES,
 	BATADV_CNT_FORWARD,
 	BATADV_CNT_FORWARD_BYTES,
 	BATADV_CNT_MGMT_TX,
-- 
1.7.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [B.A.T.M.A.N.] [PATCH] batctl: purge redundant statistic code
  2012-06-23  9:47 [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Marek Lindner
@ 2012-06-23  9:49 ` Marek Lindner
  2012-06-25 14:42   ` Marek Lindner
  2012-06-25 11:07 ` [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Martin Hundebøll
  1 sibling, 1 reply; 5+ messages in thread
From: Marek Lindner @ 2012-06-23  9:49 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Marek Lindner

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 ioctl.c |   51 ---------------------------------------------------
 1 files changed, 0 insertions(+), 51 deletions(-)

diff --git a/ioctl.c b/ioctl.c
index 92ffdb3..5056d2f 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -37,53 +37,6 @@
 
 typedef unsigned long long u64;
 
-const char proc_net_dev_path[] = "/proc/net/dev";
-
-static int statistics_common_get(char *mesh_iface)
-{
-	FILE *fp;
-	char iface[IFNAMSIZ + 1], *line_ptr = NULL;;
-	unsigned long long rx_bytes, rx_packets, tx_bytes, tx_packets;
-	unsigned long tx_errors;
-	size_t len = 0;
-	int res, ret = EXIT_FAILURE;
-
-	rx_bytes = rx_packets = tx_bytes = tx_packets = tx_errors = 0;
-
-	fp = fopen(proc_net_dev_path, "r");
-	if (!fp) {
-		printf("Error - can't open '%s' for read: %s\n",
-		       proc_net_dev_path, strerror(errno));
-		goto out;
-	}
-
-	while (getline(&line_ptr, &len, fp) != -1) {
-		res = sscanf(line_ptr, " %" STR(IFNAMSIZ) "[^: \t]: %llu %llu %*d %*d %*d %*d %*d %*d %llu %llu %lu\n",
-			     iface, &rx_bytes, &rx_packets, &tx_bytes, &tx_packets, &tx_errors);
-
-		if (res != 6)
-			continue;
-
-		if (strcmp(iface, mesh_iface) != 0)
-			continue;
-
-		printf("\t%.*s: %llu\n", ETH_GSTRING_LEN, "tx", tx_packets);
-		printf("\t%.*s: %llu\n", ETH_GSTRING_LEN, "tx_bytes", tx_bytes);
-		printf("\t%.*s: %lu\n", ETH_GSTRING_LEN, "tx_errors", tx_errors);
-		printf("\t%.*s: %llu\n", ETH_GSTRING_LEN, "rx", rx_packets);
-		printf("\t%.*s: %llu\n", ETH_GSTRING_LEN, "rx_bytes", rx_bytes);
-		ret = EXIT_SUCCESS;
-		goto out;
-	}
-
-	printf("Error - interface '%s' not found\n", mesh_iface);
-
-out:
-	fclose(fp);
-	free(line_ptr);
-	return ret;
-}
-
 /* code borrowed from ethtool */
 static int statistics_custom_get(int fd, struct ifreq *ifr)
 {
@@ -162,10 +115,6 @@ int ioctl_statistics_get(char *mesh_iface)
 		goto out;
 	}
 
-	ret = statistics_common_get(mesh_iface);
-	if (ret != EXIT_SUCCESS)
-		goto out;
-
 	ret = statistics_custom_get(fd, &ifr);
 
 out:
-- 
1.7.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure
  2012-06-23  9:47 [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Marek Lindner
  2012-06-23  9:49 ` [B.A.T.M.A.N.] [PATCH] batctl: purge redundant statistic code Marek Lindner
@ 2012-06-25 11:07 ` Martin Hundebøll
  2012-06-25 14:39   ` Marek Lindner
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Hundebøll @ 2012-06-25 11:07 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking; +Cc: Marek Lindner

On 06/23/2012 11:47 AM, Marek Lindner wrote:
> Signed-off-by: Marek Lindner<lindner_marek@yahoo.de>
Acked-by: Martin Hundebøll <martin@hundeboll.net>

-- 
Kind Regards
Martin Hundebøll
Frederiks Allé 99A, 1.th
8000 Aarhus C
Denmark
+45 61 65 54 61
martin@hundeboll.net



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure
  2012-06-25 11:07 ` [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Martin Hundebøll
@ 2012-06-25 14:39   ` Marek Lindner
  0 siblings, 0 replies; 5+ messages in thread
From: Marek Lindner @ 2012-06-25 14:39 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Monday, June 25, 2012 13:07:26 Martin Hundebøll wrote:
> On 06/23/2012 11:47 AM, Marek Lindner wrote:
> > Signed-off-by: Marek Lindner<lindner_marek@yahoo.de>
> 
> Acked-by: Martin Hundebøll <martin@hundeboll.net>

Applied in revision a81d0f9.

Regards,
Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batctl: purge redundant statistic code
  2012-06-23  9:49 ` [B.A.T.M.A.N.] [PATCH] batctl: purge redundant statistic code Marek Lindner
@ 2012-06-25 14:42   ` Marek Lindner
  0 siblings, 0 replies; 5+ messages in thread
From: Marek Lindner @ 2012-06-25 14:42 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Saturday, June 23, 2012 11:49:50 Marek Lindner wrote:
> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
> ---
>  ioctl.c |   51 ---------------------------------------------------
>  1 files changed, 0 insertions(+), 51 deletions(-)

Applied in revision a7d1ac6.

Regards,
Marek

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-06-25 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-23  9:47 [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Marek Lindner
2012-06-23  9:49 ` [B.A.T.M.A.N.] [PATCH] batctl: purge redundant statistic code Marek Lindner
2012-06-25 14:42   ` Marek Lindner
2012-06-25 11:07 ` [B.A.T.M.A.N.] [PATCH] batman-adv: convert remaining packet counters to per_cpu_ptr() infrastructure Martin Hundebøll
2012-06-25 14:39   ` Marek Lindner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox