mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Kris Katterjohn" <kjak@ispwest.com>
To: linux-kernel@vger.kernel.org
Cc: torvalds@osdl.org
Subject: Re: [PATCH] Resetting packet statistics
Date: Tue, 29 Nov 2005 01:20:37 -0800	[thread overview]
Message-ID: <82da9c5ea4034883941a054aedfc7a02.kjak@ispwest.com> (raw)

From: David S. Miller
Sent: 11/28/2005 11:02:24 PM
> Or, you can create a new call that says "from now on, do not
> reset statistics on calls using this socket."  That's another
> clean, and backwards compatible way, to deal with this
> kind of issue.

I like that one. Here are the updated patches and descriptions:

PACKET_AUTO_STATISTICS (default) lets the kernel reset the stats with each call
of PACKET_STATISTICS and PACKET_MANUAL_STATISTICS won't reset them unless
PACKET_RESET_STATISTICS is called. AUTO and MANUAL can be called multiple times
to change the "state" if necessary.

I didn't check for auto_reset_stats under PACKET_RESET_STATISTICS so it can still
be used to reset the stats while in "auto mode".

Also, just to be sure, is changing PACKET_COPY_THRESH's value in if_packet.h
okay?


Thanks a lot!


--- x/net/packet/af_packet.c	2005-10-27 19:02:08.000000000 -0500
+++ y/net/packet/af_packet.c	2005-11-29 03:02:19.000000000 -0600
@@ -41,6 +41,12 @@
  *					will simply extend the hardware address
  *					byte arrays at the end of sockaddr_ll 
  *					and packet_mreq.
+ *		Kris Katterjohn :	Added setsockopt options:
+ *					PACKET_AUTO_STATISTICS,
+ *					PACKET_MANUAL_STATISTICS, and
+ *					PACKET_RESET_STATISTICS	to handle the
+ *					zero-ing of packet stats when using
+ *					PACKET_STATISTICS. 2005-11-29.
  *
  *		This program is free software; you can redistribute it and/or
  *		modify it under the terms of the GNU General Public License
@@ -189,6 +195,7 @@ struct packet_sock {
 	/* struct sock has to be the first member of packet_sock */
 	struct sock		sk;
 	struct tpacket_stats	stats;
+	int			auto_reset_stats;
 #ifdef CONFIG_PACKET_MMAP
 	char *			*pg_vec;
 	unsigned int		head;
@@ -1020,6 +1027,7 @@ static int packet_create(struct socket *
 	po = pkt_sk(sk);
 	sk->sk_family = PF_PACKET;
 	po->num = protocol;
+	po->auto_reset_stats = 1;
 
 	sk->sk_destruct = packet_sock_destruct;
 	atomic_inc(&packet_socks_nr);
@@ -1324,6 +1332,7 @@ static int
 packet_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
 {
 	struct sock *sk = sock->sk;
+	struct packet_sock *po = pkt_sk(sk);
 	int ret;
 
 	if (level != SOL_PACKET)
@@ -1352,6 +1361,21 @@ packet_setsockopt(struct socket *sock, i
 		return ret;
 	}
 #endif
+
+	case PACKET_AUTO_STATISTICS:
+		po->auto_reset_stats = 1;
+		return 0;
+
+	case PACKET_MANUAL_STATISTICS:
+		po->auto_reset_stats = 0;
+		return 0;
+
+	case PACKET_RESET_STATISTICS:
+		spin_lock_bh(&sk->sk_receive_queue.lock);
+		memset(&po->stats, 0, sizeof(po->stats));
+		spin_unlock_bh(&sk->sk_receive_queue.lock);
+		return 0;
+
 #ifdef CONFIG_PACKET_MMAP
 	case PACKET_RX_RING:
 	{
@@ -1406,7 +1430,8 @@ static int packet_getsockopt(struct sock
 			len = sizeof(struct tpacket_stats);
 		spin_lock_bh(&sk->sk_receive_queue.lock);
 		st = po->stats;
-		memset(&po->stats, 0, sizeof(st));
+		if (po->auto_reset_stats)
+			memset(&po->stats, 0, sizeof(po->stats));
 		spin_unlock_bh(&sk->sk_receive_queue.lock);
 		st.tp_packets += st.tp_drops;

 
--- x/include/linux/if_packet.h	2005-10-27 19:02:08.000000000 -0500
+++ y/include/linux/if_packet.h	2005-11-29 03:02:19.000000000 -0600
@@ -38,7 +38,10 @@ struct sockaddr_ll
 /* Value 4 is still used by obsolete turbo-packet. */
 #define PACKET_RX_RING			5
 #define PACKET_STATISTICS		6
-#define PACKET_COPY_THRESH		7
+#define PACKET_AUTO_STATISTICS		7
+#define PACKET_MANUAL_STATISTICS	8
+#define PACKET_RESET_STATISTICS		9
+#define PACKET_COPY_THRESH		10
 
 struct tpacket_stats
 {



             reply	other threads:[~2005-11-29  9:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-29  9:20 Kris Katterjohn [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-11-29  6:28 Kris Katterjohn
2005-11-29  7:02 ` David S. Miller
2005-11-29  3:55 Kris Katterjohn
2005-11-29  6:12 ` David S. Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=82da9c5ea4034883941a054aedfc7a02.kjak@ispwest.com \
    --to=kjak@ispwest.com \
    --cc=kjak@users.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®