bonding: simple macro cleanup
cover bonding: simple macro cleanup
Hi,
That's a trivial patchset that tries to unify the macro usage of bonding modes. I've split it into two approaches - either BOND_*, which takes bonding struct as a param, or MODE_*, which takes the mode itself. Also, introduce BOND_MODE(bond) instead of ugly bond->params.mode.
--- drivers/net/bonding/bond_alb.c | 4 +- drivers/net/bonding/bond_debugfs.c | 2 +- drivers/net/bonding/bond_main.c | 114 ++++++++++++++++----------------- drivers/net/bonding/bond_netlink.c | 6 +- drivers/net/bonding/bond_options.c | 6 +- drivers/net/bonding/bond_procfs.c | 14 ++-- drivers/net/bonding/bond_sysfs.c | 14 ++-- drivers/net/bonding/bond_sysfs_slave.c | 2 +- drivers/net/bonding/bonding.h | 24 +++---- 9 files changed, 91 insertions(+), 95 deletions(-)
PATCH 1/5 bonding: use macro instead of bond_is_lb()
From: Veaceslav Falico <[email protected]>
--- drivers/net/bonding/bond_main.c | 18 +++++++++--------- drivers/net/bonding/bonding.h | 13 ++++--------- 2 files changed, 13 insertions(+), 18 deletions(-)
drivers/net/bonding/bond_main.c +9 -9
@@ -320,7 +320,7 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,bond_for_each_slave (bond, slave, iter)vlan_vid_del (slave->dev, proto, vid); -if (bond_is_lb (bond)) +if (BOND_IS_LB (bond))bond_alb_clear_vlan (bond, vid);return 0 ;
@@ -813,7 +813,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)if (bond->params.mode ==BOND_MODE_8023AD )bond_3ad_handle_link_change (new_active,BOND_LINK_UP ); -if (bond_is_lb (bond)) +if (BOND_IS_LB (bond))bond_alb_handle_link_change (bond, new_active,BOND_LINK_UP ); }else {if (USES_PRIMARY (bond->params.mode)) {
@@ -826,7 +826,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)if (USES_PRIMARY (bond->params.mode))bond_hw_addr_swap (bond, new_active, old_active); -if (bond_is_lb (bond)) { +if (BOND_IS_LB (bond)) {bond_alb_handle_active_change (bond, new_active);if (old_active) bond_set_slave_inactive_flags(old_active,
@@ -1342,7 +1342,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) new_slave->dev = slave_dev; slave_dev->priv_flags |=IFF_BONDING ; -if (bond_is_lb (bond)) { +if (BOND_IS_LB (bond)) {/* bond_alb_init_slave() must be called before all other stages since * it might fail and we do not want to have to undo everything */
@@ -1694,7 +1694,7 @@ static int __bond_release_one(struct net_device *bond_dev,write_unlock_bh (&bond->curr_slave_lock); } -if (bond_is_lb (bond)) { +if (BOND_IS_LB (bond)) {/* Must be called only after the slave has been * detached from the list and the curr_active_slave * has been cleared (if our_slave == old_current),
@@ -1988,7 +1988,7 @@ static void bond_miimon_commit(struct bonding *bond)if (bond->params.mode ==BOND_MODE_8023AD )bond_3ad_handle_link_change (slave,BOND_LINK_UP ); -if (bond_is_lb (bond)) +if (BOND_IS_LB (bond))bond_alb_handle_link_change (bond, slave,BOND_LINK_UP );
@@ -2016,7 +2016,7 @@ static void bond_miimon_commit(struct bonding *bond)bond_3ad_handle_link_change (slave,BOND_LINK_DOWN ); -if (bond_is_lb (bond)) +if (BOND_IS_LB (bond))bond_alb_handle_link_change (bond, slave,BOND_LINK_DOWN );
@@ -3090,7 +3090,7 @@ static int bond_open(struct net_device *bond_dev)bond_work_init_all (bond); -if (bond_is_lb (bond)) { +if (BOND_IS_LB (bond)) {/* bond_alb_initialize must be called before the timer * is started. */
@@ -3124,7 +3124,7 @@ static int bond_close(struct net_device *bond_dev)bond_work_cancel_all (bond); bond->send_peer_notif =0 ; -if (bond_is_lb (bond)) +if (BOND_IS_LB (bond))bond_alb_deinitialize (bond); bond->recv_probe =NULL ;
drivers/net/bonding/bonding.h +4 -9
@@ -69,9 +69,9 @@ (((mode) ==BOND_MODE_ACTIVEBACKUP ) || \ ((mode) == BOND_MODE_ROUNDROBIN)) -#define BOND_MODE_IS_LB (mode) \ - (((mode) == BOND_MODE_TLB) || \ - ((mode) == BOND_MODE_ALB)) +#define BOND_IS_LB (bond) \ + (((bond->params.mode) == BOND_MODE_TLB) || \ + ((bond->params.mode) == BOND_MODE_ALB))#define IS_IP_TARGET_UNUSABLE_ADDRESS (a) \ ((htonl(INADDR_BROADCAST) == a) || \
@@ -288,11 +288,6 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)return slave->bond; } -static inline bool bond_is_lb (const struct bonding *bond) -{ -return BOND_MODE_IS_LB (bond->params.mode); -} -static inline void bond_set_active_slave (struct slave *slave) {if (slave->backup) {
@@ -443,7 +438,7 @@ static inline void bond_netpoll_send_skb(const struct slave *slave,static inline void bond_set_slave_inactive_flags (struct slave *slave,bool notify) { -if (!bond_is_lb (slave->bond)) +if (!BOND_IS_LB (slave->bond))bond_set_slave_state (slave,BOND_STATE_BACKUP , notify);if (!slave->bond->params.all_slaves_active) slave->inactive =1 ;
Signature · 1 line
1.8.4
PATCH 2/5 bonding: rename {,BOND}_TX_QUEUE_OVERRIDE and make it accept bond struct
In reply to Veaceslav FalicoFrom: Veaceslav Falico <[email protected]>
--- drivers/net/bonding/bond_main.c | 2 +- drivers/net/bonding/bonding.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/bonding/bond_main.c +1 -1
@@ -3758,7 +3758,7 @@ static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev {struct bonding *bond =netdev_priv (dev); -if (TX_QUEUE_OVERRIDE (bond->params.mode)) { +if (BOND_TX_QUEUE_OVERRIDE (bond)) {if (!bond_slave_override (bond, skb))return NETDEV_TX_OK ; }
drivers/net/bonding/bonding.h +3 -3
@@ -65,9 +65,9 @@ ((mode) == BOND_MODE_TLB) || \ ((mode) == BOND_MODE_ALB)) -#define TX_QUEUE_OVERRIDE (mode) \ - (((mode) == BOND_MODE_ACTIVEBACKUP) || \ - ((mode) == BOND_MODE_ROUNDROBIN)) +#define BOND_TX_QUEUE_OVERRIDE (bond) \ + (((bond->params.mode) == BOND_MODE_ACTIVEBACKUP) || \ + ((bond->params.mode) == BOND_MODE_ROUNDROBIN))#define BOND_IS_LB (bond) \ (((bond->params.mode) == BOND_MODE_TLB) || \
Signature · 1 line
1.8.4
PATCH 3/5 bonding: rename {BOND_NO,MODE_NOT}_USES_ARP to better reflect its meaning
In reply to Veaceslav FalicoFrom: Veaceslav Falico <[email protected]>
--- drivers/net/bonding/bond_main.c | 2 +- drivers/net/bonding/bond_options.c | 2 +- drivers/net/bonding/bonding.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +1 -1
@@ -4084,7 +4084,7 @@ static int bond_check_params(struct bond_params *params) }/* reset values for 802.3ad/TLB/ALB */ -if (BOND_NO_USES_ARP (bond_mode)) { +if (MODE_NOT_USES_ARP (bond_mode)) {if (!miimon) {pr_warn ("Warning: miimon must be specified, otherwise bonding will not detect link failure, speed and duplex which are essential for 802.3ad operation\n" );pr_warn ("Forcing miimon to 100msec\n" );
drivers/net/bonding/bond_options.c +1 -1
@@ -672,7 +672,7 @@ const struct bond_option *bond_opt_get(unsigned int option)int bond_option_mode_set (struct bonding *bond,const struct bond_opt_value *newval) { -if (BOND_NO_USES_ARP (newval->value) && bond->params.arp_interval) { +if (MODE_NOT_USES_ARP (newval->value) && bond->params.arp_interval) {pr_info ("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n" , bond->dev->name, newval->string);/* disable arp monitoring */
drivers/net/bonding/bonding.h +1 -1
@@ -60,7 +60,7 @@ ((mode) == BOND_MODE_TLB) || \ ((mode) == BOND_MODE_ALB)) -#define BOND_NO_USES_ARP (mode) \ +#define MODE_NOT_USES_ARP (mode) \ (((mode) == BOND_MODE_8023AD) || \ ((mode) == BOND_MODE_TLB) || \ ((mode) == BOND_MODE_ALB))
Signature · 1 line
1.8.4
PATCH 4/5 bonding: rename {,MODE_}USES_PRIMARY to better reflect its meaning
In reply to Veaceslav FalicoFrom: Veaceslav Falico <[email protected]>
--- drivers/net/bonding/bond_main.c | 30 +++++++++++++++--------------- drivers/net/bonding/bond_options.c | 2 +- drivers/net/bonding/bond_procfs.c | 2 +- drivers/net/bonding/bonding.h | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-)
drivers/net/bonding/bond_main.c +15 -15
@@ -497,7 +497,7 @@ static int bond_set_promiscuity(struct bonding *bond, int inc)struct list_head *iter;int err =0 ; -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) {/* write lock already acquired */ if (bond->curr_active_slave) { err = dev_set_promiscuity(bond->curr_active_slave->dev,
@@ -523,7 +523,7 @@ static int bond_set_allmulti(struct bonding *bond, int inc)struct list_head *iter;int err =0 ; -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) {/* write lock already acquired */ if (bond->curr_active_slave) { err = dev_set_allmulti(bond->curr_active_slave->dev,
@@ -801,7 +801,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active) new_active->last_link_up = jiffies;if (new_active->link ==BOND_LINK_BACK ) { -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) {pr_info ("%s: making interface %s the new active one %d ms earlier\n" , bond->dev->name, new_active->dev->name, (bond->params.updelay - new_active->delay) * bond->params.miimon);
@@ -816,14 +816,14 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)if (BOND_IS_LB (bond))bond_alb_handle_link_change (bond, new_active,BOND_LINK_UP ); }else { -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) {pr_info ("%s: making interface %s the new active one\n" , bond->dev->name, new_active->dev->name); } } } -if (USES_PRIMARY (bond->params.mode)) +if (MODE_USES_PRIMARY (bond->params.mode))bond_hw_addr_swap (bond, new_active, old_active);if (BOND_IS_LB (bond)) {
@@ -876,7 +876,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)* resend only if bond is brought up with the affected * bonding modes and the retransmission is enabled */ if (netif_running (bond->dev) && (bond->params.resend_igmp >0 ) && - ((USES_PRIMARY (bond->params.mode) && new_active) || + ((MODE_USES_PRIMARY (bond->params.mode) && new_active) || bond->params.mode ==BOND_MODE_ROUNDROBIN )) { bond->igmp_retrans = bond->params.resend_igmp;queue_delayed_work (bond->wq, &bond->mcast_work,1 );
@@ -1354,7 +1354,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)/* If the mode USES_PRIMARY, then the following is handled by * bond_change_active_slave(). */ -if (!USES_PRIMARY (bond->params.mode)) { +if (!MODE_USES_PRIMARY (bond->params.mode)) {/* set promiscuity level to new slave */ if (bond_dev->flags &IFF_PROMISC ) { res =dev_set_promiscuity (slave_dev,1 );
@@ -1450,7 +1450,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) new_slave->link ==BOND_LINK_DOWN ?"DOWN" : (new_slave->link == BOND_LINK_UP ? "UP" : "BACK")); -if (USES_PRIMARY (bond->params.mode) && bond->params.primary[0 ]) { +if (MODE_USES_PRIMARY (bond->params.mode) && bond->params.primary[0 ]) {/* if there is a primary slave, remember it */ if (strcmp (bond->params.primary, new_slave->dev->name) ==0 ) { bond->primary_slave = new_slave;
@@ -1539,7 +1539,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)bond_compute_features (bond);bond_set_carrier (bond); -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) {block_netpoll_tx ();write_lock_bh (&bond->curr_slave_lock);bond_select_active_slave (bond);
@@ -1563,7 +1563,7 @@ err_unregister:netdev_rx_handler_unregister (slave_dev); err_detach: -if (!USES_PRIMARY (bond->params.mode)) +if (!MODE_USES_PRIMARY (bond->params.mode))bond_hw_addr_flush (bond_dev, slave_dev);vlan_vids_del_by_dev (slave_dev, bond_dev);
@@ -1751,7 +1751,7 @@ static int __bond_release_one(struct net_device *bond_dev,/* If the mode USES_PRIMARY, then this cases was handled above by * bond_change_active_slave(..., NULL) */ -if (!USES_PRIMARY (bond->params.mode)) { +if (!MODE_USES_PRIMARY (bond->params.mode)) {/* unset promiscuity level from slave * NOTE: The NETDEV_CHANGEADDR call above may change the value * of the IFF_PROMISC flag in the bond_dev, but we need the
@@ -2885,7 +2885,7 @@ static int bond_slave_netdev_event(unsigned long event,break ;case NETDEV_CHANGENAME :/* we don't care if we don't have primary set */ -if (!USES_PRIMARY (bond->params.mode) || +if (!MODE_USES_PRIMARY (bond->params.mode) || !bond->params.primary[0 ])break ;
@@ -3075,7 +3075,7 @@ static int bond_open(struct net_device *bond_dev)if (bond_has_slaves (bond)) {read_lock (&bond->curr_slave_lock);bond_for_each_slave (bond, slave, iter) { -if (USES_PRIMARY (bond->params.mode) +if (MODE_USES_PRIMARY (bond->params.mode) && (slave != bond->curr_active_slave)) {bond_set_slave_inactive_flags (slave,BOND_SLAVE_NOTIFY_NOW );
@@ -3313,7 +3313,7 @@ static void bond_set_rx_mode(struct net_device *bond_dev)rcu_read_lock (); -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) { slave =rcu_dereference (bond->curr_active_slave);if (slave) {dev_uc_sync (slave->dev, bond_dev);
@@ -4239,7 +4239,7 @@ static int bond_check_params(struct bond_params *params)pr_debug ("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details\n" ); } -if (primary && !USES_PRIMARY (bond_mode)) { +if (primary && !MODE_USES_PRIMARY (bond_mode)) {/* currently, using a primary only makes sense * in active backup, TLB or ALB modes */
drivers/net/bonding/bond_options.c +1 -1
@@ -693,7 +693,7 @@ int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newvstatic struct net_device *__bond_option_active_slave_get (struct bonding *bond,struct slave *slave) { -return USES_PRIMARY (bond->params.mode) && slave ? slave->dev :NULL ; +return MODE_USES_PRIMARY (bond->params.mode) && slave ? slave->dev :NULL ; }struct net_device *bond_option_active_slave_get_rcu (struct bonding *bond)
drivers/net/bonding/bond_procfs.c +1 -1
@@ -91,7 +91,7 @@ static void bond_info_show_master(struct seq_file *seq) optval->string, bond->params.xmit_policy); } -if (USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (bond->params.mode)) {seq_printf (seq,"Primary Slave: %s" , (bond->primary_slave) ? bond->primary_slave->dev->name :"None" );
drivers/net/bonding/bonding.h +1 -1
@@ -55,7 +55,7 @@ bond_is_active_slave(slave)) -#define USES_PRIMARY (mode) \ +#define MODE_USES_PRIMARY (mode) \ (((mode) == BOND_MODE_ACTIVEBACKUP) || \ ((mode) == BOND_MODE_TLB) || \ ((mode) == BOND_MODE_ALB))
Signature · 1 line
1.8.4
PATCH 5/5 bonding: create a macro for bond mode and use it
In reply to Veaceslav FalicoFrom: Veaceslav Falico <[email protected]>
--- drivers/net/bonding/bond_alb.c | 4 +- drivers/net/bonding/bond_debugfs.c | 2 +- drivers/net/bonding/bond_main.c | 90 +++++++++++++++++----------------- drivers/net/bonding/bond_netlink.c | 6 +-- drivers/net/bonding/bond_options.c | 4 +- drivers/net/bonding/bond_procfs.c | 14 +++--- drivers/net/bonding/bond_sysfs.c | 14 +++--- drivers/net/bonding/bond_sysfs_slave.c | 2 +- drivers/net/bonding/bonding.h | 9 ++-- 9 files changed, 73 insertions(+), 72 deletions(-)
drivers/net/bonding/bond_alb.c +2 -2
@@ -1057,7 +1057,7 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])struct net_device *dev = slave->dev;struct sockaddr s_addr; -if (slave->bond->params.mode ==BOND_MODE_TLB ) { +if (BOND_MODE (slave->bond) ==BOND_MODE_TLB ) {memcpy (dev->dev_addr, addr, dev->addr_len);return 0 ; }
@@ -1745,7 +1745,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave/* in TLB mode, the slave might flip down/up with the old dev_addr, * and thus filter bond->dev_addr's packets, so force bond's mac */ -if (bond->params.mode ==BOND_MODE_TLB ) { +if (BOND_MODE (bond) ==BOND_MODE_TLB ) {struct sockaddr sa;u8 tmp_addr[ETH_ALEN ];
drivers/net/bonding/bond_debugfs.c +1 -1
@@ -23,7 +23,7 @@ static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)struct rlb_client_info *client_info;u32 hash_index; -if (bond->params.mode !=BOND_MODE_ALB ) +if (BOND_MODE (bond) !=BOND_MODE_ALB )return 0 ; seq_printf(m, "SourceIP DestinationIP "
drivers/net/bonding/bond_main.c +45 -45
343 lines not on this page · raw message
drivers/net/bonding/bond_netlink.c +3 -3
@@ -56,7 +56,7 @@ static int bond_fill_slave_info(struct sk_buff *skb,if (nla_put_u16 (skb,IFLA_BOND_SLAVE_QUEUE_ID , slave->queue_id)) goto nla_put_failure; -if (slave->bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (slave->bond) ==BOND_MODE_8023AD ) {const struct aggregator *agg; agg =SLAVE_AD_INFO (slave).port.aggregator;
@@ -407,7 +407,7 @@ static int bond_fill_info(struct sk_buff *skb,unsigned int packets_per_slave;int i, targets_added; -if (nla_put_u8 (skb,IFLA_BOND_MODE , bond->params.mode)) +if (nla_put_u8 (skb,IFLA_BOND_MODE ,BOND_MODE (bond))) goto nla_put_failure; if (slave_dev &&
@@ -505,7 +505,7 @@ static int bond_fill_info(struct sk_buff *skb, bond->params.ad_select)) goto nla_put_failure; -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info info;if (!bond_3ad_get_active_agg_info (bond, &info)) {
drivers/net/bonding/bond_options.c +2 -2
@@ -685,7 +685,7 @@ int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newv/* don't cache arp_validate between modes */ bond->params.arp_validate =BOND_ARP_VALIDATE_NONE ; - bond->params.mode = newval->value; +BOND_MODE (bond) = newval->value;return 0 ; }
@@ -693,7 +693,7 @@ int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newvstatic struct net_device *__bond_option_active_slave_get (struct bonding *bond,struct slave *slave) { -return MODE_USES_PRIMARY (bond->params.mode) && slave ? slave->dev :NULL ; +return MODE_USES_PRIMARY (BOND_MODE (bond)) && slave ? slave->dev :NULL ; }struct net_device *bond_option_active_slave_get_rcu (struct bonding *bond)
drivers/net/bonding/bond_procfs.c +7 -7
@@ -72,9 +72,9 @@ static void bond_info_show_master(struct seq_file *seq) curr =rcu_dereference (bond->curr_active_slave);seq_printf (seq,"Bonding Mode: %s" , -bond_mode_name (bond->params.mode)); +bond_mode_name (BOND_MODE (bond))); -if (bond->params.mode ==BOND_MODE_ACTIVEBACKUP && +if (BOND_MODE (bond) ==BOND_MODE_ACTIVEBACKUP && bond->params.fail_over_mac) { optval =bond_opt_get_val (BOND_OPT_FAIL_OVER_MAC , bond->params.fail_over_mac);
@@ -83,15 +83,15 @@ static void bond_info_show_master(struct seq_file *seq)seq_printf (seq,"\n" ); -if (bond->params.mode ==BOND_MODE_XOR || - bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_XOR || +BOND_MODE (bond) ==BOND_MODE_8023AD ) { optval =bond_opt_get_val (BOND_OPT_XMIT_HASH , bond->params.xmit_policy);seq_printf (seq,"Transmit Hash Policy: %s (%d)\n" , optval->string, bond->params.xmit_policy); } -if (MODE_USES_PRIMARY (bond->params.mode)) { +if (MODE_USES_PRIMARY (BOND_MODE (bond))) {seq_printf (seq,"Primary Slave: %s" , (bond->primary_slave) ? bond->primary_slave->dev->name :"None" );
@@ -134,7 +134,7 @@ static void bond_info_show_master(struct seq_file *seq)seq_printf (seq,"\n" ); } -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info ad_info;seq_puts (seq,"\n802.3ad info\n" );
@@ -188,7 +188,7 @@ static void bond_info_show_slave(struct seq_file *seq,seq_printf (seq,"Permanent HW addr: %pM\n" , slave->perm_hwaddr); -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {const struct aggregator *agg =SLAVE_AD_INFO (slave).port.aggregator;
drivers/net/bonding/bond_sysfs.c +7 -7
@@ -214,9 +214,9 @@ static ssize_t bonding_show_mode(struct device *d,struct bonding *bond =to_bond (d);const struct bond_opt_value *val; - val =bond_opt_get_val (BOND_OPT_MODE , bond->params.mode); + val =bond_opt_get_val (BOND_OPT_MODE ,BOND_MODE (bond)); -return sprintf (buf,"%s %d\n" , val->string, bond->params.mode); +return sprintf (buf,"%s %d\n" , val->string,BOND_MODE (bond)); } static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_sysfs_store_option);
@@ -505,7 +505,7 @@ static ssize_t bonding_show_ad_aggregator(struct device *d,int count =0 ;struct bonding *bond =to_bond (d); -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info ad_info; count =sprintf (buf,"%d\n" , bond_3ad_get_active_agg_info(bond, &ad_info)
@@ -525,7 +525,7 @@ static ssize_t bonding_show_ad_num_ports(struct device *d,int count =0 ;struct bonding *bond =to_bond (d); -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info ad_info; count =sprintf (buf,"%d\n" , bond_3ad_get_active_agg_info(bond, &ad_info)
@@ -545,7 +545,7 @@ static ssize_t bonding_show_ad_actor_key(struct device *d,int count =0 ;struct bonding *bond =to_bond (d); -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info ad_info; count =sprintf (buf,"%d\n" , bond_3ad_get_active_agg_info(bond, &ad_info)
@@ -565,7 +565,7 @@ static ssize_t bonding_show_ad_partner_key(struct device *d,int count =0 ;struct bonding *bond =to_bond (d); -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info ad_info; count =sprintf (buf,"%d\n" , bond_3ad_get_active_agg_info(bond, &ad_info)
@@ -585,7 +585,7 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d,int count =0 ;struct bonding *bond =to_bond (d); -if (bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) {struct ad_info ad_info;if (!bond_3ad_get_active_agg_info (bond, &ad_info)) count =sprintf (buf,"%pM\n" , ad_info.partner_system);
drivers/net/bonding/bond_sysfs_slave.c +1 -1
@@ -69,7 +69,7 @@ static ssize_t ad_aggregator_id_show(struct slave *slave, char *buf) {const struct aggregator *agg; -if (slave->bond->params.mode ==BOND_MODE_8023AD ) { +if (BOND_MODE (slave->bond) ==BOND_MODE_8023AD ) { agg =SLAVE_AD_INFO (slave).port.aggregator;if (agg) return sprintf(buf, "%d\n",
drivers/net/bonding/bonding.h +5 -4
@@ -54,6 +54,7 @@ ((slave)->link == BOND_LINK_UP) && \ bond_is_active_slave(slave)) +#define BOND_MODE (bond) ((bond)->params.mode)#define MODE_USES_PRIMARY (mode) \ (((mode) == BOND_MODE_ACTIVEBACKUP) || \
@@ -66,12 +67,12 @@ ((mode) == BOND_MODE_ALB))#define BOND_TX_QUEUE_OVERRIDE (bond) \ - (((bond->params.mode) == BOND_MODE_ACTIVEBACKUP) || \ - ((bond->params.mode) == BOND_MODE_ROUNDROBIN)) + (((BOND_MODE(bond)) == BOND_MODE_ACTIVEBACKUP) || \ + ((BOND_MODE(bond)) == BOND_MODE_ROUNDROBIN))#define BOND_IS_LB (bond) \ - (((bond->params.mode) == BOND_MODE_TLB) || \ - ((bond->params.mode) == BOND_MODE_ALB)) + (((BOND_MODE(bond)) == BOND_MODE_TLB) || \ + ((BOND_MODE(bond)) == BOND_MODE_ALB))#define IS_IP_TARGET_UNUSABLE_ADDRESS (a) \ ((htonl(INADDR_BROADCAST) == a) || \
Signature · 1 line
1.8.4
From: Veaceslav Falico
Quoted 6 lines
Hi,
That's a trivial patchset that tries to unify the macro usage of bonding modes. I've split it into two approaches - either BOND_*, which takes bonding struct as a param, or MODE_*, which takes the mode itself. Also, introduce
BOND_MODE(bond)instead of uglybond->params.mode.
I'm not sure these are improvements....
I thought that netdev (in particular) preferred static inline functions to #defines - and especially #defines that expand their argument(s) more than once.
IMHO Simple access functions are just a PITA when reading code since they cause the reader to go off somewhere and look up the definition.
David
Quoted 8 lines · David Laight
From: Veaceslav Falico
Quoted 6 lines
Hi,
That's a trivial patchset that tries to unify the macro usage of bonding modes. I've split it into two approaches - either BOND_*, which takes bonding struct as a param, or MODE_*, which takes the mode itself. Also, introduce
BOND_MODE(bond)instead of uglybond->params.mode.
Quoted 5 lines
I'm not sure these are improvements....
I thought that netdev (in particular) preferred static inline functions to #defines - and especially #defines that expand their argument(s) more than once.
There's only one static inline function removal - which was completely different from the usual macros (bond_is_lb()). Other macros are just renames to quicker understand the code.
Quoted 3 lines
IMHO Simple access functions are just a PITA when reading code since they cause the reader to go off somewhere and look up the definition.
I can make them either way, I've made this patchset while doing other patchset, and the basic idea was that currently the usage of these macros is quite illogical - some take bond as an argument, some the mode, and there's a function that is a macro...
Anyway, I don't have a strong feeling either way, so if people think that it's better the way it is - I'm ok with that.
Quoted 5 lines
David
Quoted 29 lines · Veaceslav Falico
Quoted 11 lines · David Laight
From: Veaceslav Falico
Quoted 7 lines
Hi,
That's a trivial patchset that tries to unify the macro usage of bonding modes. I've split it into two approaches - either BOND_*, which takes bonding struct as a param, or MODE_*, which takes the mode itself. Also, introduce
BOND_MODE(bond)instead of uglybond->params.mode.Quoted 5 lines
I'm not sure these are improvements....
I thought that netdev (in particular) preferred static inline functions to #defines - and especially #defines that expand their argument(s) more than once.
There's only one static inline function removal - which was completely different from the usual macros (
bond_is_lb()). Other macros are just renames to quicker understand the code.Quoted 3 lines
IMHO Simple access functions are just a PITA when reading code since they cause the reader to go off somewhere and look up the definition.
Quoted 7 lines
I can make them either way, I've made this patchset while doing other patchset, and the basic idea was that currently the usage of these macros is quite illogical - some take bond as an argument, some the mode, and there's a function that is a macro...
Anyway, I don't have a strong feeling either way, so if people think that it's better the way it is - I'm ok with that.
from compiler point of view it's actually easier to deal with inline functions than macros. I'd suggest to do the full conversion the other way around:
convert all macros to static inline. Developers will enjoy better type safety and compiler will enjoy more opportunities to optimize code.
Quoted 4 lines · Alexei Starovoitov
from compiler point of view it's actually easier to deal with inline functions than macros. I'd suggest to do the full conversion the other way around:
convert all macros to static inline. Developers will enjoy better type safety and compiler will enjoy more opportunities to optimize code.
Agree about the type safety, but sometimes a compiler will generate worse code with static inlines than #defines.
Quoted 8 lines · Joe Perches
Quoted 4 lines · Alexei Starovoitov
from compiler point of view it's actually easier to deal with inline functions than macros. I'd suggest to do the full conversion the other way around:
convert all macros to static inline. Developers will enjoy better type safety and compiler will enjoy more opportunities to optimize code.Agree about the type safety, but sometimes a compiler will generate worse code with static inlines than #defines.
yep, sometimes compiler heuristics of size increase due to inline vs cost of call
vs further optimizations after inline are guessing things wrong. always_inline can force it in such cases.
Online articles about macro vs static inline mainly talk about inlining and type safety.
I'm trying to make a point that there is more to it from compiler point of view. 'static inline' approach changes the scope of arguments whereas macro pushes code into the scope of callsite.
Here is a synthetic example:
struct S {
int v1;
int v2;
int v3;
};
static inline void f(struct S *s)
{
s->v1 = 0;
s->v2 = 0;
s->v3 = 0;
}
#define F(s) \
({ \
s->v1 = 0; \
s->v2 = 0; \
s->v3 = 0; \})
struct S *s1;
void test1()
{
f(s1);
}
void test2()
{
F(s1);
}
$ gcc -O2 -S -fno-strict-aliasing
test1:
movq s1(%rip), %rax
movl $0, (%rax)
movl $0, 4(%rax)
movl $0, 8(%rax)
ret
test2:
movq s1(%rip), %rax
movl $0, (%rax)
movq s1(%rip), %rax
movl $0, 4(%rax)
movq s1(%rip), %rax
movl $0, 8(%rax)
retI cannot imagine the case where macro would be faster than static inline unless it wasn't inlined.
Quoted 2 lines · Alexei Starovoitov
I cannot imagine the case where macro would be faster than static inline unless it wasn't inlined.
For an example, look at commit 4153577a8d
("tg3: Use different macros for pci_chip_rev_id accesses")
Converting these macros to static inline produces
larger/slower code. (at least with gcc 4.7.3)
+#define tg3_chip_rev_id(tp) \
+ ((tp)->pci_chip_rev_id)
+#define tg3_asic_rev(tp) \
+ ((tp)->pci_chip_rev_id >> 12)
+#define tg3_chip_rev(tp) \
+ ((tp)->pci_chip_rev_id >> 8)
Quoted 11 lines · Joe Perches
Quoted 2 lines · Alexei Starovoitov
I cannot imagine the case where macro would be faster than static inline unless it wasn't inlined.
For an example, look at commit
4153577a8d
("tg3: Use different macros forpci_chip_rev_idaccesses")Converting these macros to static inline produces
larger/slower code. (at least with gcc 4.7.3)
Review
Quoted 6 lines
(quoted diff) +6
-0+#define tg3_chip_rev_id(tp) \ + ((tp)->pci_chip_rev_id) +#define tg3_asic_rev(tp) \ + ((tp)->pci_chip_rev_id >> 12) +#define tg3_chip_rev(tp) \ + ((tp)->pci_chip_rev_id >> 8)
hmm. interesting.
Using gcc 4.7.2 object file size is larger with 'static inline' 2893016 vs 2868112
but that's due to larger debug info.
.text is actually smaller 000207c4 vs 00020824
and these three calls were inlined (even without __always_inline), so I suspect it's better optimized..
though better optimized can very well mean slower.
PATCH 1/1 tg3: Use static inlines not macros
Newer versions of gcc produce better code
so convert some macros to static inlines.
$ gcc --version gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
(x86/defconfig)
$ size drivers/net/ethernet/broadcom/tg3.o.* text data bss dec hex filename 134282 963 0 135245 2104d drivers/net/ethernet/broadcom/tg3.o.new 134613 963 0 135576 21198 drivers/net/ethernet/broadcom/tg3.o.old
---
Quoted 11 lines · Alexei Starovoitov
Quoted 10 lines · Joe Perches
Quoted 2 lines · Alexei Starovoitov
I cannot imagine the case where macro would be faster than static inline unless it wasn't inlined.
For an example, look at commit
4153577a8d
("tg3: Use different macros forpci_chip_rev_idaccesses")Converting these macros to static inline produces
larger/slower code. (at least with gcc 4.7.3)
Quoted 16 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+#define tg3_chip_rev_id(tp) \ + ((tp)->pci_chip_rev_id) +#define tg3_asic_rev(tp) \ + ((tp)->pci_chip_rev_id >> 12) +#define tg3_chip_rev(tp) \ + ((tp)->pci_chip_rev_id >> 8)hmm. interesting.
Using gcc 4.7.2 object file size is larger with 'static inline' 2893016 vs 2868112
but that's due to larger debug info.
.text is actually smaller000207c4vs 00020824
and these three calls were inlined (even without__always_inline), so I suspect it's better optimized..
though better optimized can very well mean slower.
Compiler optimizers change with every version too.
drivers/net/ethernet/broadcom/tg3.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/tg3.h +14 -6
@@ -3416,11 +3416,19 @@ struct tg3 {* Using statement expression macros to check tp with * typecheck(struct tg3 *, tp) also creates larger objects. */ -#define tg3_chip_rev_id (tp) \ - ((tp)->pci_chip_rev_id) -#define tg3_asic_rev (tp) \ - ((tp)->pci_chip_rev_id >> 12) -#define tg3_chip_rev (tp) \ - ((tp)->pci_chip_rev_id >> 8) +static inline u32 tg3_chip_rev_id (const struct tg3 *tp) +{ +return tp->pci_chip_rev_id; +} + +static inline u32 tg3_asic_rev (const struct tg3 *tp) +{ +return tp->pci_chip_rev_id >>12 ; +} + +static inline u32 tg3_chip_rev (const struct tg3 *tp) +{ +return tp->pci_chip_rev_id >>8 ; +}#endif /* !(_T3_H) */
Re: [PATCH] tg3: Use static inlines not macros
Quoted 47 lines · Joe Perches
Newer versions of gcc produce better code
so convert some macros to static inlines.$ gcc --version gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.(x86/defconfig)
$ size drivers/net/ethernet/broadcom/tg3.o.* text data bss dec hex filename 134282 963 0 135245 2104d drivers/net/ethernet/broadcom/tg3.o.new 134613 963 0 135576 21198 drivers/net/ethernet/broadcom/tg3.o.oldSigned-off-by Joe Perches <[email protected]>---
Quoted 11 lines · Alexei Starovoitov
Quoted 10 lines · Joe Perches
Quoted 2 lines · Alexei Starovoitov
I cannot imagine the case where macro would be faster than static inline unless it wasn't inlined.
For an example, look at commit
4153577a8d
("tg3: Use different macros forpci_chip_rev_idaccesses")Converting these macros to static inline produces
larger/slower code. (at least with gcc 4.7.3)Quoted 16 lines
Review
Quoted 7 lines
(quoted diff) +6
-0+#define tg3_chip_rev_id(tp) \ + ((tp)->pci_chip_rev_id) +#define tg3_asic_rev(tp) \ + ((tp)->pci_chip_rev_id >> 12) +#define tg3_chip_rev(tp) \ + ((tp)->pci_chip_rev_id >> 8)hmm. interesting.
Using gcc 4.7.2 object file size is larger with 'static inline' 2893016 vs 2868112
but that's due to larger debug info.
.text is actually smaller000207c4vs 00020824
and these three calls were inlined (even without__always_inline), so I suspect it's better optimized..
though better optimized can very well mean slower.
Quoted 1 line
Compiler optimizers change with every version too.
Nice. Would interesting to hear whether performance stayed the same or not.
drivers/net/ethernet/broadcom/tg3.h struct tg3 { · line 3418
Quoted 11 lines
drivers/net/ethernet/broadcom/tg3.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/net/ethernet/broadcom/tg3.h +0
-0@@ -3416,11 +3416,19 @@ struct tg3 {* Using statement expression macros to check tp with * typecheck(struct tg3 *, tp) also creates larger objects. */
nit: the comment above needs updating.
Quoted 24 lines
drivers/net/ethernet/broadcom/tg3.h +14
-6-#define tg3_chip_rev_id (tp) \ - ((tp)->pci_chip_rev_id) -#define tg3_asic_rev (tp) \ - ((tp)->pci_chip_rev_id >> 12) -#define tg3_chip_rev (tp) \ - ((tp)->pci_chip_rev_id >> 8) +static inline u32 tg3_chip_rev_id (const struct tg3 *tp) +{ +return tp->pci_chip_rev_id; +} + +static inline u32 tg3_asic_rev (const struct tg3 *tp) +{ +return tp->pci_chip_rev_id >>12 ; +} + +static inline u32 tg3_chip_rev (const struct tg3 *tp) +{ +return tp->pci_chip_rev_id >>8 ; +}#endif /* !(_T3_H) */
From: Joe Perches
Quoted 8 lines · Alexei Starovoitov
Quoted 4 lines
from compiler point of view it's actually easier to deal with inline functions than macros. I'd suggest to do the full conversion the other way around:
convert all macros to static inline. Developers will enjoy better type safety and compiler will enjoy more opportunities to optimize code.Agree about the type safety, but sometimes a compiler will generate worse code with static inlines than #defines.
Sometimes yes - mainly because the #define version happens at a much earlier stage in the compilation so is subject to additional optimisations.
For most functions it either has no effect, or doesn't matter.
If you are trying to squeeze out every last unwanted clock cycle then #defines can help.
Take the following real example:
#define ASM_COMMENT(text) asm volatile( "#" text " line " STR(__LINE__) :: )
#define hdlc_put_ind(rx_hdlc) do { \
(++hdlc_ind_next - 1)->hi_rqst = rx_hdlc; \
if (predict_false(hdlc_ind_next == hdlc_ind_last)) { \
hdlc_ind_next = hdlc_ind; \
ASM_COMMENT("ring wrapped"); \
} \
} while (0)The ASM_COMMENT here is important - it stops gcc tail merging the call in code like:
if (foo) {
...
hdlc_put_ind(bar);
} else {
...
hdlc_put_ind(baz);
}
continue;With an inline function you can't force two copies be generated.
But most of the network stack isn't optimised to that level!
David
Quoted 4 lines · Alexei Starovoitov
from compiler point of view it's actually easier to deal with inline functions than macros. I'd suggest to do the full conversion the other way around:
convert all macros to static inline. Developers will enjoy better type safety and compiler will enjoy more opportunities to optimize code.
Ok, will move everything into inline functions.
Thanks for an interesting discussion :)