Skip to content

Commit

Permalink
[NET]: move struct proto_ops to const
Browse files Browse the repository at this point in the history
I noticed that some of 'struct proto_ops' used in the kernel may share
a cache line used by locks or other heavily modified data. (default
linker alignement is 32 bytes, and L1_CACHE_LINE is 64 or 128 at
least)

This patch makes sure a 'struct proto_ops' can be declared as const,
so that all cpus can share all parts of it without false sharing.

This is not mandatory : a driver can still use a read/write structure
if it needs to (and eventually a __read_mostly)

I made a global stubstitute to change all existing occurences to make
them const.

This should reduce the possibility of false sharing on SMP, and
speedup some socket system calls.

Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Jan 3, 2006
1 parent 77d76ea commit 90ddc4f
Show file tree
Hide file tree
Showing 33 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ enum sock_type {
struct socket {
socket_state state;
unsigned long flags;
struct proto_ops *ops;
const struct proto_ops *ops;
struct fasync_struct *fasync_list;
struct file *file;
struct sock *sk;
Expand Down Expand Up @@ -260,7 +260,7 @@ SOCKCALL_WRAP(name, recvmsg, (struct kiocb *iocb, struct socket *sock, struct ms
SOCKCALL_WRAP(name, mmap, (struct file *file, struct socket *sock, struct vm_area_struct *vma), \
(file, sock, vma)) \
\
static struct proto_ops name##_ops = { \
static const struct proto_ops name##_ops = { \
.family = fam, \
.owner = THIS_MODULE, \
.release = __lock_##name##_release, \
Expand Down
4 changes: 2 additions & 2 deletions include/net/inet_common.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _INET_COMMON_H
#define _INET_COMMON_H

extern struct proto_ops inet_stream_ops;
extern struct proto_ops inet_dgram_ops;
extern const struct proto_ops inet_stream_ops;
extern const struct proto_ops inet_dgram_ops;

/*
* INET4 prototypes used by INET6
Expand Down
4 changes: 2 additions & 2 deletions include/net/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ extern int sysctl_ip6frag_low_thresh;
extern int sysctl_ip6frag_time;
extern int sysctl_ip6frag_secret_interval;

extern struct proto_ops inet6_stream_ops;
extern struct proto_ops inet6_dgram_ops;
extern const struct proto_ops inet6_stream_ops;
extern const struct proto_ops inet6_dgram_ops;

extern int ip6_mc_source(int add, int omode, struct sock *sk,
struct group_source_req *pgsr);
Expand Down
2 changes: 1 addition & 1 deletion include/net/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct inet_protosw {
int protocol; /* This is the L4 protocol number. */

struct proto *prot;
struct proto_ops *ops;
const struct proto_ops *ops;

int capability; /* Which (if any) capability do
* we need to use this socket
Expand Down
4 changes: 2 additions & 2 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#include <linux/atalk.h>

struct datalink_proto *ddp_dl, *aarp_dl;
static struct proto_ops atalk_dgram_ops;
static const struct proto_ops atalk_dgram_ops;

/**************************************************************************\
* *
Expand Down Expand Up @@ -1841,7 +1841,7 @@ static struct net_proto_family atalk_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
.family = PF_APPLETALK,
.owner = THIS_MODULE,
.release = atalk_release,
Expand Down
2 changes: 1 addition & 1 deletion net/atm/pvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static int pvc_getname(struct socket *sock,struct sockaddr *sockaddr,
}


static struct proto_ops pvc_proto_ops = {
static const struct proto_ops pvc_proto_ops = {
.family = PF_ATMPVC,
.owner = THIS_MODULE,

Expand Down
2 changes: 1 addition & 1 deletion net/atm/svc.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ static int svc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
return error;
}

static struct proto_ops svc_proto_ops = {
static const struct proto_ops svc_proto_ops = {
.family = PF_ATMSVC,
.owner = THIS_MODULE,

Expand Down
4 changes: 2 additions & 2 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
HLIST_HEAD(ax25_list);
DEFINE_SPINLOCK(ax25_list_lock);

static struct proto_ops ax25_proto_ops;
static const struct proto_ops ax25_proto_ops;

static void ax25_free_sock(struct sock *sk)
{
Expand Down Expand Up @@ -1944,7 +1944,7 @@ static struct net_proto_family ax25_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops ax25_proto_ops = {
static const struct proto_ops ax25_proto_ops = {
.family = PF_AX25,
.owner = THIS_MODULE,
.release = ax25_release,
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/bnep/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static int bnep_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
return 0;
}

static struct proto_ops bnep_sock_ops = {
static const struct proto_ops bnep_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = bnep_sock_release,
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/cmtp/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static int cmtp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
return -EINVAL;
}

static struct proto_ops cmtp_sock_ops = {
static const struct proto_ops cmtp_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = cmtp_sock_release,
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char
return 0;
}

static struct proto_ops hci_sock_ops = {
static const struct proto_ops hci_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = hci_sock_release,
Expand Down
2 changes: 1 addition & 1 deletion net/bluetooth/hidp/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static int hidp_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long
return -EINVAL;
}

static struct proto_ops hidp_sock_ops = {
static const struct proto_ops hidp_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = hidp_sock_release,
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

#define VERSION "2.8"

static struct proto_ops l2cap_sock_ops;
static const struct proto_ops l2cap_sock_ops;

static struct bt_sock_list l2cap_sk_list = {
.lock = RW_LOCK_UNLOCKED
Expand Down Expand Up @@ -2161,7 +2161,7 @@ static ssize_t l2cap_sysfs_show(struct class *dev, char *buf)

static CLASS_ATTR(l2cap, S_IRUGO, l2cap_sysfs_show, NULL);

static struct proto_ops l2cap_sock_ops = {
static const struct proto_ops l2cap_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = l2cap_sock_release,
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/rfcomm/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#define BT_DBG(D...)
#endif

static struct proto_ops rfcomm_sock_ops;
static const struct proto_ops rfcomm_sock_ops;

static struct bt_sock_list rfcomm_sk_list = {
.lock = RW_LOCK_UNLOCKED
Expand Down Expand Up @@ -907,7 +907,7 @@ static ssize_t rfcomm_sock_sysfs_show(struct class *dev, char *buf)

static CLASS_ATTR(rfcomm, S_IRUGO, rfcomm_sock_sysfs_show, NULL);

static struct proto_ops rfcomm_sock_ops = {
static const struct proto_ops rfcomm_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = rfcomm_sock_release,
Expand Down
4 changes: 2 additions & 2 deletions net/bluetooth/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

#define VERSION "0.5"

static struct proto_ops sco_sock_ops;
static const struct proto_ops sco_sock_ops;

static struct bt_sock_list sco_sk_list = {
.lock = RW_LOCK_UNLOCKED
Expand Down Expand Up @@ -914,7 +914,7 @@ static ssize_t sco_sysfs_show(struct class *dev, char *buf)

static CLASS_ATTR(sco, S_IRUGO, sco_sysfs_show, NULL);

static struct proto_ops sco_sock_ops = {
static const struct proto_ops sco_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = sco_sock_release,
Expand Down
2 changes: 1 addition & 1 deletion net/dccp/proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void dccp_shutdown(struct sock *sk, int how)

EXPORT_SYMBOL_GPL(dccp_shutdown);

static struct proto_ops inet_dccp_ops = {
static const struct proto_ops inet_dccp_ops = {
.family = PF_INET,
.owner = THIS_MODULE,
.release = inet_release,
Expand Down
4 changes: 2 additions & 2 deletions net/decnet/af_decnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void dn_keepalive(struct sock *sk);
#define DN_SK_HASH_MASK (DN_SK_HASH_SIZE - 1)


static struct proto_ops dn_proto_ops;
static const struct proto_ops dn_proto_ops;
static DEFINE_RWLOCK(dn_hash_lock);
static struct hlist_head dn_sk_hash[DN_SK_HASH_SIZE];
static struct hlist_head dn_wild_sk;
Expand Down Expand Up @@ -2342,7 +2342,7 @@ static struct net_proto_family dn_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops dn_proto_ops = {
static const struct proto_ops dn_proto_ops = {
.family = AF_DECnet,
.owner = THIS_MODULE,
.release = dn_release,
Expand Down
4 changes: 2 additions & 2 deletions net/econet/af_econet.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <asm/uaccess.h>
#include <asm/system.h>

static struct proto_ops econet_ops;
static const struct proto_ops econet_ops;
static struct hlist_head econet_sklist;
static DEFINE_RWLOCK(econet_lock);

Expand Down Expand Up @@ -698,7 +698,7 @@ static struct net_proto_family econet_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops SOCKOPS_WRAPPED(econet_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(econet_ops) = {
.family = PF_ECONET,
.owner = THIS_MODULE,
.release = econet_release,
Expand Down
6 changes: 3 additions & 3 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
return err;
}

struct proto_ops inet_stream_ops = {
const struct proto_ops inet_stream_ops = {
.family = PF_INET,
.owner = THIS_MODULE,
.release = inet_release,
Expand All @@ -806,7 +806,7 @@ struct proto_ops inet_stream_ops = {
.sendpage = tcp_sendpage
};

struct proto_ops inet_dgram_ops = {
const struct proto_ops inet_dgram_ops = {
.family = PF_INET,
.owner = THIS_MODULE,
.release = inet_release,
Expand All @@ -831,7 +831,7 @@ struct proto_ops inet_dgram_ops = {
* For SOCK_RAW sockets; should be the same as inet_dgram_ops but without
* udp_poll
*/
static struct proto_ops inet_sockraw_ops = {
static const struct proto_ops inet_sockraw_ops = {
.family = PF_INET,
.owner = THIS_MODULE,
.release = inet_release,
Expand Down
6 changes: 3 additions & 3 deletions net/ipv6/af_inet6.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
return(0);
}

struct proto_ops inet6_stream_ops = {
const struct proto_ops inet6_stream_ops = {
.family = PF_INET6,
.owner = THIS_MODULE,
.release = inet6_release,
Expand All @@ -483,7 +483,7 @@ struct proto_ops inet6_stream_ops = {
.sendpage = tcp_sendpage
};

struct proto_ops inet6_dgram_ops = {
const struct proto_ops inet6_dgram_ops = {
.family = PF_INET6,
.owner = THIS_MODULE,
.release = inet6_release,
Expand Down Expand Up @@ -511,7 +511,7 @@ static struct net_proto_family inet6_family_ops = {
};

/* Same as inet6_dgram_ops, sans udp_poll. */
static struct proto_ops inet6_sockraw_ops = {
static const struct proto_ops inet6_sockraw_ops = {
.family = PF_INET6,
.owner = THIS_MODULE,
.release = inet6_release,
Expand Down
4 changes: 2 additions & 2 deletions net/ipx/af_ipx.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static struct datalink_proto *pEII_datalink;
static struct datalink_proto *p8023_datalink;
static struct datalink_proto *pSNAP_datalink;

static struct proto_ops ipx_dgram_ops;
static const struct proto_ops ipx_dgram_ops;

LIST_HEAD(ipx_interfaces);
DEFINE_SPINLOCK(ipx_interfaces_lock);
Expand Down Expand Up @@ -1901,7 +1901,7 @@ static struct net_proto_family ipx_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops SOCKOPS_WRAPPED(ipx_dgram_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(ipx_dgram_ops) = {
.family = PF_IPX,
.owner = THIS_MODULE,
.release = ipx_release,
Expand Down
16 changes: 8 additions & 8 deletions net/irda/af_irda.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@

static int irda_create(struct socket *sock, int protocol);

static struct proto_ops irda_stream_ops;
static struct proto_ops irda_seqpacket_ops;
static struct proto_ops irda_dgram_ops;
static const struct proto_ops irda_stream_ops;
static const struct proto_ops irda_seqpacket_ops;
static const struct proto_ops irda_dgram_ops;

#ifdef CONFIG_IRDA_ULTRA
static struct proto_ops irda_ultra_ops;
static const struct proto_ops irda_ultra_ops;
#define ULTRA_MAX_DATA 382
#endif /* CONFIG_IRDA_ULTRA */

Expand Down Expand Up @@ -2464,7 +2464,7 @@ static struct net_proto_family irda_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
.family = PF_IRDA,
.owner = THIS_MODULE,
.release = irda_release,
Expand All @@ -2485,7 +2485,7 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_stream_ops) = {
.sendpage = sock_no_sendpage,
};

static struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
.family = PF_IRDA,
.owner = THIS_MODULE,
.release = irda_release,
Expand All @@ -2506,7 +2506,7 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_seqpacket_ops) = {
.sendpage = sock_no_sendpage,
};

static struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
.family = PF_IRDA,
.owner = THIS_MODULE,
.release = irda_release,
Expand All @@ -2528,7 +2528,7 @@ static struct proto_ops SOCKOPS_WRAPPED(irda_dgram_ops) = {
};

#ifdef CONFIG_IRDA_ULTRA
static struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
static const struct proto_ops SOCKOPS_WRAPPED(irda_ultra_ops) = {
.family = PF_IRDA,
.owner = THIS_MODULE,
.release = irda_release,
Expand Down
4 changes: 2 additions & 2 deletions net/key/af_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static __inline__ void pfkey_unlock_table(void)
}


static struct proto_ops pfkey_ops;
static const struct proto_ops pfkey_ops;

static void pfkey_insert(struct sock *sk)
{
Expand Down Expand Up @@ -3127,7 +3127,7 @@ static int pfkey_recvmsg(struct kiocb *kiocb,
return err;
}

static struct proto_ops pfkey_ops = {
static const struct proto_ops pfkey_ops = {
.family = PF_KEY,
.owner = THIS_MODULE,
/* Operations that make no sense on pfkey sockets. */
Expand Down
4 changes: 2 additions & 2 deletions net/llc/af_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static u16 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
static u16 llc_ui_sap_link_no_max[256];
static struct sockaddr_llc llc_ui_addrnull;
static struct proto_ops llc_ui_ops;
static const struct proto_ops llc_ui_ops;

static int llc_ui_wait_for_conn(struct sock *sk, long timeout);
static int llc_ui_wait_for_disc(struct sock *sk, long timeout);
Expand Down Expand Up @@ -1098,7 +1098,7 @@ static struct net_proto_family llc_ui_family_ops = {
.owner = THIS_MODULE,
};

static struct proto_ops llc_ui_ops = {
static const struct proto_ops llc_ui_ops = {
.family = PF_LLC,
.owner = THIS_MODULE,
.release = llc_ui_release,
Expand Down
Loading

0 comments on commit 90ddc4f

Please sign in to comment.