* [PATCH 1/2] ethtool: allow const ethtool_ops
@ 2006-09-08 18:16 Stephen Hemminger
2006-09-08 18:20 ` [PATCH 2/2] loopback: minor statistics optimization Stephen Hemminger
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-08 18:16 UTC (permalink / raw)
To: David S. Miller, Jeff Garzik; +Cc: netdev
The ethtool_ops structure is immutable, it expected to be setup
by the driver and is never changed. This patch allows drivers to
declare there ethtool_ops structure read-only.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- linux-2.6.orig/include/linux/netdevice.h
+++ linux-2.6/include/linux/netdevice.h
@@ -342,7 +342,7 @@ struct net_device
/* Instance data managed by the core of Wireless Extensions. */
struct iw_public_data * wireless_data;
- struct ethtool_ops *ethtool_ops;
+ const struct ethtool_ops *ethtool_ops;
/*
* This marks the end of the "visible" part of the structure. All
--- linux-2.6.orig/net/core/ethtool.c
+++ linux-2.6/net/core/ethtool.c
@@ -143,7 +143,7 @@ static int ethtool_set_settings(struct n
static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
{
struct ethtool_drvinfo info;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
if (!ops->get_drvinfo)
return -EOPNOTSUPP;
@@ -169,7 +169,7 @@ static int ethtool_get_drvinfo(struct ne
static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
{
struct ethtool_regs regs;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
void *regbuf;
int reglen, ret;
@@ -282,7 +282,7 @@ static int ethtool_get_link(struct net_d
static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
{
struct ethtool_eeprom eeprom;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
u8 *data;
int ret;
@@ -327,7 +327,7 @@ static int ethtool_get_eeprom(struct net
static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
{
struct ethtool_eeprom eeprom;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
u8 *data;
int ret;
@@ -640,7 +640,7 @@ static int ethtool_set_gso(struct net_de
static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
{
struct ethtool_test test;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
u64 *data;
int ret;
@@ -673,7 +673,7 @@ static int ethtool_self_test(struct net_
static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
{
struct ethtool_gstrings gstrings;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
u8 *data;
int ret;
@@ -733,7 +733,7 @@ static int ethtool_phys_id(struct net_de
static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
{
struct ethtool_stats stats;
- struct ethtool_ops *ops = dev->ethtool_ops;
+ const struct ethtool_ops *ops = dev->ethtool_ops;
u64 *data;
int ret;
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/2] loopback: minor statistics optimization
2006-09-08 18:16 [PATCH 1/2] ethtool: allow const ethtool_ops Stephen Hemminger
@ 2006-09-08 18:20 ` Stephen Hemminger
2006-09-28 3:04 ` David Miller
2006-09-12 16:08 ` [PATCH 1/2] ethtool: allow const ethtool_ops Jeff Garzik
2006-09-13 17:45 ` Jeff Garzik
2 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-08 18:20 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: David S. Miller, Jeff Garzik, netdev
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);
};
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
2006-09-08 18:16 [PATCH 1/2] ethtool: allow const ethtool_ops Stephen Hemminger
2006-09-08 18:20 ` [PATCH 2/2] loopback: minor statistics optimization Stephen Hemminger
@ 2006-09-12 16:08 ` Jeff Garzik
2006-09-13 2:08 ` Stephen Hemminger
2006-09-13 5:09 ` Stephen Hemminger
2006-09-13 17:45 ` Jeff Garzik
2 siblings, 2 replies; 13+ messages in thread
From: Jeff Garzik @ 2006-09-12 16:08 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: David S. Miller, netdev
Stephen Hemminger wrote:
> The ethtool_ops structure is immutable, it expected to be setup
> by the driver and is never changed. This patch allows drivers to
> declare there ethtool_ops structure read-only.
>
> Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
ACK, but I need the associated change-all-drivers patch, in order to
apply this.
Jeff
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
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 5:09 ` Stephen Hemminger
1 sibling, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-13 2:08 UTC (permalink / raw)
To: Jeff Garzik; +Cc: David S. Miller, netdev
On Tue, 12 Sep 2006 12:08:03 -0400
Jeff Garzik <jgarzik@pobox.com> wrote:
> Stephen Hemminger wrote:
> > The ethtool_ops structure is immutable, it expected to be setup
> > by the driver and is never changed. This patch allows drivers to
> > declare there ethtool_ops structure read-only.
> >
> > Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
>
> ACK, but I need the associated change-all-drivers patch, in order to
> apply this.
>
> Jeff
>
>
No, they can pass non-const and everthing works.
Changing the ethtool_ops to have const args would require a global change.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
2006-09-13 2:08 ` Stephen Hemminger
@ 2006-09-13 2:12 ` Jeff Garzik
2006-09-13 2:19 ` Stephen Hemminger
0 siblings, 1 reply; 13+ messages in thread
From: Jeff Garzik @ 2006-09-13 2:12 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: David S. Miller, netdev
Stephen Hemminger wrote:
> No, they can pass non-const and everthing works.
> Changing the ethtool_ops to have const args would require a global change.
Re-stating previous email: I need a patch which updates all drivers to
declare their ethtool_ops structs const.
Jeff
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
2006-09-13 2:12 ` Jeff Garzik
@ 2006-09-13 2:19 ` Stephen Hemminger
0 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-13 2:19 UTC (permalink / raw)
To: Jeff Garzik; +Cc: David S. Miller, netdev
On Tue, 12 Sep 2006 22:12:30 -0400
Jeff Garzik <jgarzik@pobox.com> wrote:
> Stephen Hemminger wrote:
> > No, they can pass non-const and everthing works.
> > Changing the ethtool_ops to have const args would require a global change.
>
> Re-stating previous email: I need a patch which updates all drivers to
> declare their ethtool_ops structs const.
>
> Jeff
>
>
I'll do one mondo patch for all drivers.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
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 5:09 ` Stephen Hemminger
2006-09-13 6:00 ` Jeff Garzik
1 sibling, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-13 5:09 UTC (permalink / raw)
To: Jeff Garzik; +Cc: David S. Miller, netdev
On Tue, 12 Sep 2006 12:08:03 -0400
Jeff Garzik <jgarzik@pobox.com> wrote:
> Stephen Hemminger wrote:
> > The ethtool_ops structure is immutable, it expected to be setup
> > by the driver and is never changed. This patch allows drivers to
> > declare there ethtool_ops structure read-only.
> >
> > Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
>
> ACK, but I need the associated change-all-drivers patch, in order to
> apply this.
>
> Jeff
>
>
Actually, no driver is immediately required since this is valid:
exiting_driver.c:
static struct ethtool_ops myops= { ... };
static int mydriver_probe(...) {
...
dev = alloc_etherdev(sizeof(struct mypriv));
...
dev->ethtool_ops = &myops;
...
return register_netdev(dev);
}
Remember difference between:
struct net_device {
struct ethtool_ops *ethtool_ops;
Existing definition, allow network core to change contents of
dev->ethtool_ops.
const struct ethtool_ops *ethtool_ops;
Proposed patch, network code treats dev->ethtool_ops contents
as read-only. Devices MAY make ethtool_ops const.
Radical change would be:
struct ethtool_ops *const ethtool_ops;
This would mean every device would have to define ethtool_ops
as const. Devices MUST make ethtool_ops const.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
2006-09-13 5:09 ` Stephen Hemminger
@ 2006-09-13 6:00 ` Jeff Garzik
0 siblings, 0 replies; 13+ messages in thread
From: Jeff Garzik @ 2006-09-13 6:00 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: David S. Miller, netdev
How hard can it be to grep? Can you please just provide the patch??
Jeff
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
2006-09-08 18:16 [PATCH 1/2] ethtool: allow const ethtool_ops Stephen Hemminger
2006-09-08 18:20 ` [PATCH 2/2] loopback: minor statistics optimization Stephen Hemminger
2006-09-12 16:08 ` [PATCH 1/2] ethtool: allow const ethtool_ops Jeff Garzik
@ 2006-09-13 17:45 ` Jeff Garzik
2006-09-14 1:54 ` Stephen Hemminger
2 siblings, 1 reply; 13+ messages in thread
From: Jeff Garzik @ 2006-09-13 17:45 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: David S. Miller, netdev
applied, then I fixed up all the drivers
Otherwise, it was a half-complete job that would take years to get
cleaned up.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] ethtool: allow const ethtool_ops
2006-09-13 17:45 ` Jeff Garzik
@ 2006-09-14 1:54 ` Stephen Hemminger
0 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-14 1:54 UTC (permalink / raw)
To: Jeff Garzik; +Cc: David S. Miller, netdev
On Wed, 13 Sep 2006 13:45:42 -0400
Jeff Garzik <jgarzik@pobox.com> wrote:
> applied, then I fixed up all the drivers
>
> Otherwise, it was a half-complete job that would take years to get
> cleaned up.
>
>
Thanks, I did the same effective patch last night but doing a "make allmodconfig"
build took overnight on a laptop.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] loopback: minor statistics optimization
2006-09-08 18:20 ` [PATCH 2/2] loopback: minor statistics optimization Stephen Hemminger
@ 2006-09-28 3:04 ` David Miller
2006-09-28 3:13 ` Stephen Hemminger
0 siblings, 1 reply; 13+ messages in thread
From: David Miller @ 2006-09-28 3:04 UTC (permalink / raw)
To: shemminger; +Cc: jgarzik, netdev
From: Stephen Hemminger <shemminger@osdl.org>
Date: Fri, 8 Sep 2006 11:20:56 -0700
> 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>
The ethtool bits are OK, but putting the loopback stats into
the image adds nearly 200 bytes of .data section space on
64-bit.
I don't really think it's that big of a deal to avoid the
kmalloc() call.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] loopback: minor statistics optimization
2006-09-28 3:04 ` David Miller
@ 2006-09-28 3:13 ` Stephen Hemminger
2006-09-28 3:25 ` David Miller
0 siblings, 1 reply; 13+ messages in thread
From: Stephen Hemminger @ 2006-09-28 3:13 UTC (permalink / raw)
To: David Miller; +Cc: jgarzik, netdev
David Miller wrote:
> From: Stephen Hemminger <shemminger@osdl.org>
> Date: Fri, 8 Sep 2006 11:20:56 -0700
>
>
>> 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>
>>
>
> The ethtool bits are OK, but putting the loopback stats into
> the image adds nearly 200 bytes of .data section space on
> 64-bit.
>
> I don't really think it's that big of a deal to avoid the
> kmalloc() call.
>
Yeah but doing the kmalloc is going to get a bigger chunk (rounded up),
anyway. The statistics should show up in BSS so it won't add to kernel size.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 2/2] loopback: minor statistics optimization
2006-09-28 3:13 ` Stephen Hemminger
@ 2006-09-28 3:25 ` David Miller
0 siblings, 0 replies; 13+ messages in thread
From: David Miller @ 2006-09-28 3:25 UTC (permalink / raw)
To: shemminger; +Cc: jgarzik, netdev
From: Stephen Hemminger <shemminger@osdl.org>
Date: Wed, 27 Sep 2006 20:13:14 -0700
> David Miller wrote:
> > From: Stephen Hemminger <shemminger@osdl.org>
> > Date: Fri, 8 Sep 2006 11:20:56 -0700
> >
> >
> >> 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>
> >>
> >
> > The ethtool bits are OK, but putting the loopback stats into
> > the image adds nearly 200 bytes of .data section space on
> > 64-bit.
> >
> > I don't really think it's that big of a deal to avoid the
> > kmalloc() call.
> >
> Yeah but doing the kmalloc is going to get a bigger chunk (rounded up),
> anyway. The statistics should show up in BSS so it won't add to kernel size.
Good point, I'll apply your patch.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2006-09-28 3:25 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-08 18:16 [PATCH 1/2] ethtool: allow const ethtool_ops Stephen Hemminger
2006-09-08 18:20 ` [PATCH 2/2] loopback: minor statistics optimization Stephen Hemminger
2006-09-28 3:04 ` 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
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).