mirror of
https://github.com/torvalds/linux.git
synced 2024-12-26 21:02:19 +00:00
c7d03a00b5
Make struct pernet_operations::id unsigned. There are 2 reasons to do so: 1) This field is really an index into an zero based array and thus is unsigned entity. Using negative value is out-of-bound access by definition. 2) On x86_64 unsigned 32-bit data which are mixed with pointers via array indexing or offsets added or subtracted to pointers are preffered to signed 32-bit data. "int" being used as an array index needs to be sign-extended to 64-bit before being used. void f(long *p, int i) { g(p[i]); } roughly translates to movsx rsi, esi mov rdi, [rsi+...] call g MOVSX is 3 byte instruction which isn't necessary if the variable is unsigned because x86_64 is zero extending by default. Now, there is net_generic() function which, you guessed it right, uses "int" as an array index: static inline void *net_generic(const struct net *net, int id) { ... ptr = ng->ptr[id - 1]; ... } And this function is used a lot, so those sign extensions add up. Patch snipes ~1730 bytes on allyesconfig kernel (without all junk messing with code generation): add/remove: 0/0 grow/shrink: 70/598 up/down: 396/-2126 (-1730) Unfortunately some functions actually grow bigger. This is a semmingly random artefact of code generation with register allocator being used differently. gcc decides that some variable needs to live in new r8+ registers and every access now requires REX prefix. Or it is shifted into r12, so [r12+0] addressing mode has to be used which is longer than [r8] However, overall balance is in negative direction: add/remove: 0/0 grow/shrink: 70/598 up/down: 396/-2126 (-1730) function old new delta nfsd4_lock 3886 3959 +73 tipc_link_build_proto_msg 1096 1140 +44 mac80211_hwsim_new_radio 2776 2808 +32 tipc_mon_rcv 1032 1058 +26 svcauth_gss_legacy_init 1413 1429 +16 tipc_bcbase_select_primary 379 392 +13 nfsd4_exchange_id 1247 1260 +13 nfsd4_setclientid_confirm 782 793 +11 ... put_client_renew_locked 494 480 -14 ip_set_sockfn_get 730 716 -14 geneve_sock_add 829 813 -16 nfsd4_sequence_done 721 703 -18 nlmclnt_lookup_host 708 686 -22 nfsd4_lockt 1085 1063 -22 nfs_get_client 1077 1050 -27 tcf_bpf_init 1106 1076 -30 nfsd4_encode_fattr 5997 5930 -67 Total: Before=154856051, After=154854321, chg -0.00% Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
173 lines
4.6 KiB
C
173 lines
4.6 KiB
C
/*
|
|
* net/tipc/core.h: Include file for TIPC global declarations
|
|
*
|
|
* Copyright (c) 2005-2006, 2013 Ericsson AB
|
|
* Copyright (c) 2005-2007, 2010-2013, Wind River Systems
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. Neither the names of the copyright holders nor the names of its
|
|
* contributors may be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
* Software Foundation.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef _TIPC_CORE_H
|
|
#define _TIPC_CORE_H
|
|
|
|
#include <linux/tipc.h>
|
|
#include <linux/tipc_config.h>
|
|
#include <linux/tipc_netlink.h>
|
|
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/string.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/atomic.h>
|
|
#include <asm/hardirq.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/in.h>
|
|
#include <linux/list.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/rtnetlink.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <net/netns/generic.h>
|
|
#include <linux/rhashtable.h>
|
|
|
|
struct tipc_node;
|
|
struct tipc_bearer;
|
|
struct tipc_bc_base;
|
|
struct tipc_link;
|
|
struct tipc_name_table;
|
|
struct tipc_server;
|
|
struct tipc_monitor;
|
|
|
|
#define TIPC_MOD_VER "2.0.0"
|
|
|
|
#define NODE_HTABLE_SIZE 512
|
|
#define MAX_BEARERS 3
|
|
#define TIPC_DEF_MON_THRESHOLD 32
|
|
|
|
extern unsigned int tipc_net_id __read_mostly;
|
|
extern int sysctl_tipc_rmem[3] __read_mostly;
|
|
extern int sysctl_tipc_named_timeout __read_mostly;
|
|
|
|
struct tipc_net {
|
|
u32 own_addr;
|
|
int net_id;
|
|
int random;
|
|
|
|
/* Node table and node list */
|
|
spinlock_t node_list_lock;
|
|
struct hlist_head node_htable[NODE_HTABLE_SIZE];
|
|
struct list_head node_list;
|
|
u32 num_nodes;
|
|
u32 num_links;
|
|
|
|
/* Neighbor monitoring list */
|
|
struct tipc_monitor *monitors[MAX_BEARERS];
|
|
int mon_threshold;
|
|
|
|
/* Bearer list */
|
|
struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1];
|
|
|
|
/* Broadcast link */
|
|
spinlock_t bclock;
|
|
struct tipc_bc_base *bcbase;
|
|
struct tipc_link *bcl;
|
|
|
|
/* Socket hash table */
|
|
struct rhashtable sk_rht;
|
|
|
|
/* Name table */
|
|
spinlock_t nametbl_lock;
|
|
struct name_table *nametbl;
|
|
|
|
/* Name dist queue */
|
|
struct list_head dist_queue;
|
|
|
|
/* Topology subscription server */
|
|
struct tipc_server *topsrv;
|
|
atomic_t subscription_count;
|
|
};
|
|
|
|
static inline struct tipc_net *tipc_net(struct net *net)
|
|
{
|
|
return net_generic(net, tipc_net_id);
|
|
}
|
|
|
|
static inline int tipc_netid(struct net *net)
|
|
{
|
|
return tipc_net(net)->net_id;
|
|
}
|
|
|
|
static inline struct list_head *tipc_nodes(struct net *net)
|
|
{
|
|
return &tipc_net(net)->node_list;
|
|
}
|
|
|
|
static inline unsigned int tipc_hashfn(u32 addr)
|
|
{
|
|
return addr & (NODE_HTABLE_SIZE - 1);
|
|
}
|
|
|
|
static inline u16 mod(u16 x)
|
|
{
|
|
return x & 0xffffu;
|
|
}
|
|
|
|
static inline int less_eq(u16 left, u16 right)
|
|
{
|
|
return mod(right - left) < 32768u;
|
|
}
|
|
|
|
static inline int more(u16 left, u16 right)
|
|
{
|
|
return !less_eq(left, right);
|
|
}
|
|
|
|
static inline int less(u16 left, u16 right)
|
|
{
|
|
return less_eq(left, right) && (mod(right) != mod(left));
|
|
}
|
|
|
|
static inline int in_range(u16 val, u16 min, u16 max)
|
|
{
|
|
return !less(val, min) && !more(val, max);
|
|
}
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
int tipc_register_sysctl(void);
|
|
void tipc_unregister_sysctl(void);
|
|
#else
|
|
#define tipc_register_sysctl() 0
|
|
#define tipc_unregister_sysctl()
|
|
#endif
|
|
#endif
|