From: Stephen Hemminger <shemminger@osdl.org>
To: Stephen Hemminger <shemminger@osdl.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Jeff Garzik <jgarzik@pobox.com>,
netdev@vger.kernel.org
Subject: [PATCH 2/2] loopback: minor statistics optimization
Date: Fri, 8 Sep 2006 11:20:56 -0700 [thread overview]
Message-ID: <20060908112056.7ef03bac@localhost.localdomain> (raw)
In-Reply-To: <20060908111613.12c1f9b8@localhost.localdomain>
Minor loopback enhancements for 2.6.19
The loopback device status structure is a singleton and doesn't
need to be allocated. Add ethtool_ops hooks to show checksum always on,
and make ethtool_ops const.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- linux-2.6.orig/drivers/net/loopback.c
+++ linux-2.6/drivers/net/loopback.c
@@ -161,15 +161,13 @@ static int loopback_xmit(struct sk_buff
return(0);
}
+static struct net_device_stats loopback_stats;
+
static struct net_device_stats *get_stats(struct net_device *dev)
{
- struct net_device_stats *stats = dev->priv;
+ struct net_device_stats *stats = &loopback_stats;
int i;
- if (!stats) {
- return NULL;
- }
-
memset(stats, 0, sizeof(struct net_device_stats));
for_each_possible_cpu(i) {
@@ -185,19 +183,28 @@ static struct net_device_stats *get_stat
return stats;
}
-static u32 loopback_get_link(struct net_device *dev)
+static u32 always_on(struct net_device *dev)
{
return 1;
}
-static struct ethtool_ops loopback_ethtool_ops = {
- .get_link = loopback_get_link,
+static const struct ethtool_ops loopback_ethtool_ops = {
+ .get_link = always_on,
.get_tso = ethtool_op_get_tso,
.set_tso = ethtool_op_set_tso,
+ .get_tx_csum = always_on,
+ .get_sg = always_on,
+ .get_rx_csum = always_on,
};
+/*
+ * The loopback device is special. There is only one instance and
+ * it is statically allocated. Don't do this for other devices.
+ */
struct net_device loopback_dev = {
.name = "lo",
+ .get_stats = &get_stats,
+ .priv = &loopback_stats,
.mtu = (16 * 1024) + 20 + 20 + 12,
.hard_start_xmit = loopback_xmit,
.hard_header = eth_header,
@@ -221,16 +228,6 @@ struct net_device loopback_dev = {
/* Setup and register the loopback device. */
int __init loopback_init(void)
{
- struct net_device_stats *stats;
-
- /* Can survive without statistics */
- stats = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL);
- if (stats) {
- memset(stats, 0, sizeof(struct net_device_stats));
- loopback_dev.priv = stats;
- loopback_dev.get_stats = &get_stats;
- }
-
return register_netdev(&loopback_dev);
};
next prev parent reply other threads:[~2006-09-08 18:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-08 18:16 [PATCH 1/2] ethtool: allow const ethtool_ops Stephen Hemminger
2006-09-08 18:20 ` Stephen Hemminger [this message]
2006-09-28 3:04 ` [PATCH 2/2] loopback: minor statistics optimization David Miller
2006-09-28 3:13 ` Stephen Hemminger
2006-09-28 3:25 ` David Miller
2006-09-12 16:08 ` [PATCH 1/2] ethtool: allow const ethtool_ops Jeff Garzik
2006-09-13 2:08 ` Stephen Hemminger
2006-09-13 2:12 ` Jeff Garzik
2006-09-13 2:19 ` Stephen Hemminger
2006-09-13 5:09 ` Stephen Hemminger
2006-09-13 6:00 ` Jeff Garzik
2006-09-13 17:45 ` Jeff Garzik
2006-09-14 1:54 ` Stephen Hemminger
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=20060908112056.7ef03bac@localhost.localdomain \
--to=shemminger@osdl.org \
--cc=davem@davemloft.net \
--cc=jgarzik@pobox.com \
--cc=netdev@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).