aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2010-11-19 12:49:59 -0500
committerDavid S. Miller <davem@davemloft.net>2010-11-19 12:49:59 -0500
commit93aaae2e01e57483256b7da05c9a7ebd65ad4686 (patch)
treeb3e4117bbf39814ef58ce1d012d977d2d5393c38 /drivers
parent0a80410dc53cf68e56456bef1ca66949b87412f9 (diff)
filter: optimize sk_run_filter
Remove pc variable to avoid arithmetic to compute fentry at each filter instruction. Jumps directly manipulate fentry pointer. As the last instruction of filter[] is guaranteed to be a RETURN, and all jumps are before the last instruction, we dont need to check filter bounds (number of instructions in filter array) at each iteration, so we remove it from sk_run_filter() params. On x86_32 remove f_k var introduced in commit 57fe93b374a6b871 (filter: make sure filters dont read uninitialized memory) Note : We could use a CONFIG_ARCH_HAS_{FEW|MANY}_REGISTERS in order to avoid too many ifdefs in this code. This helps compiler to use cpu registers to hold fentry and A accumulator. On x86_32, this saves 401 bytes, and more important, sk_run_filter() runs much faster because less register pressure (One less conditional branch per BPF instruction) # size net/core/filter.o net/core/filter_pre.o text data bss dec hex filename 2948 0 0 2948 b84 net/core/filter.o 3349 0 0 3349 d15 net/core/filter_pre.o on x86_64 : # size net/core/filter.o net/core/filter_pre.o text data bss dec hex filename 5173 0 0 5173 1435 net/core/filter.o 5224 0 0 5224 1468 net/core/filter_pre.o Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Changli Gao <xiaosuo@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c14
-rw-r--r--drivers/net/ppp_generic.c12
2 files changed, 10 insertions, 16 deletions
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 97c5cc2997f5..9e8162c80bb0 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -1147,15 +1147,14 @@ isdn_ppp_push_higher(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buff
1147 } 1147 }
1148 1148
1149 if (is->pass_filter 1149 if (is->pass_filter
1150 && sk_run_filter(skb, is->pass_filter, is->pass_len) == 0) { 1150 && sk_run_filter(skb, is->pass_filter) == 0) {
1151 if (is->debug & 0x2) 1151 if (is->debug & 0x2)
1152 printk(KERN_DEBUG "IPPP: inbound frame filtered.\n"); 1152 printk(KERN_DEBUG "IPPP: inbound frame filtered.\n");
1153 kfree_skb(skb); 1153 kfree_skb(skb);
1154 return; 1154 return;
1155 } 1155 }
1156 if (!(is->active_filter 1156 if (!(is->active_filter
1157 && sk_run_filter(skb, is->active_filter, 1157 && sk_run_filter(skb, is->active_filter) == 0)) {
1158 is->active_len) == 0)) {
1159 if (is->debug & 0x2) 1158 if (is->debug & 0x2)
1160 printk(KERN_DEBUG "IPPP: link-active filter: reseting huptimer.\n"); 1159 printk(KERN_DEBUG "IPPP: link-active filter: reseting huptimer.\n");
1161 lp->huptimer = 0; 1160 lp->huptimer = 0;
@@ -1294,15 +1293,14 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
1294 } 1293 }
1295 1294
1296 if (ipt->pass_filter 1295 if (ipt->pass_filter
1297 && sk_run_filter(skb, ipt->pass_filter, ipt->pass_len) == 0) { 1296 && sk_run_filter(skb, ipt->pass_filter) == 0) {
1298 if (ipt->debug & 0x4) 1297 if (ipt->debug & 0x4)
1299 printk(KERN_DEBUG "IPPP: outbound frame filtered.\n"); 1298 printk(KERN_DEBUG "IPPP: outbound frame filtered.\n");
1300 kfree_skb(skb); 1299 kfree_skb(skb);
1301 goto unlock; 1300 goto unlock;
1302 } 1301 }
1303 if (!(ipt->active_filter 1302 if (!(ipt->active_filter
1304 && sk_run_filter(skb, ipt->active_filter, 1303 && sk_run_filter(skb, ipt->active_filter) == 0)) {
1305 ipt->active_len) == 0)) {
1306 if (ipt->debug & 0x4) 1304 if (ipt->debug & 0x4)
1307 printk(KERN_DEBUG "IPPP: link-active filter: reseting huptimer.\n"); 1305 printk(KERN_DEBUG "IPPP: link-active filter: reseting huptimer.\n");
1308 lp->huptimer = 0; 1306 lp->huptimer = 0;
@@ -1492,9 +1490,9 @@ int isdn_ppp_autodial_filter(struct sk_buff *skb, isdn_net_local *lp)
1492 } 1490 }
1493 1491
1494 drop |= is->pass_filter 1492 drop |= is->pass_filter
1495 && sk_run_filter(skb, is->pass_filter, is->pass_len) == 0; 1493 && sk_run_filter(skb, is->pass_filter) == 0;
1496 drop |= is->active_filter 1494 drop |= is->active_filter
1497 && sk_run_filter(skb, is->active_filter, is->active_len) == 0; 1495 && sk_run_filter(skb, is->active_filter) == 0;
1498 1496
1499 skb_push(skb, IPPP_MAX_HEADER - 4); 1497 skb_push(skb, IPPP_MAX_HEADER - 4);
1500 return drop; 1498 return drop;
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 09cf56d0416a..0c91598ae280 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -1136,8 +1136,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1136 a four-byte PPP header on each packet */ 1136 a four-byte PPP header on each packet */
1137 *skb_push(skb, 2) = 1; 1137 *skb_push(skb, 2) = 1;
1138 if (ppp->pass_filter && 1138 if (ppp->pass_filter &&
1139 sk_run_filter(skb, ppp->pass_filter, 1139 sk_run_filter(skb, ppp->pass_filter) == 0) {
1140 ppp->pass_len) == 0) {
1141 if (ppp->debug & 1) 1140 if (ppp->debug & 1)
1142 printk(KERN_DEBUG "PPP: outbound frame not passed\n"); 1141 printk(KERN_DEBUG "PPP: outbound frame not passed\n");
1143 kfree_skb(skb); 1142 kfree_skb(skb);
@@ -1145,8 +1144,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1145 } 1144 }
1146 /* if this packet passes the active filter, record the time */ 1145 /* if this packet passes the active filter, record the time */
1147 if (!(ppp->active_filter && 1146 if (!(ppp->active_filter &&
1148 sk_run_filter(skb, ppp->active_filter, 1147 sk_run_filter(skb, ppp->active_filter) == 0))
1149 ppp->active_len) == 0))
1150 ppp->last_xmit = jiffies; 1148 ppp->last_xmit = jiffies;
1151 skb_pull(skb, 2); 1149 skb_pull(skb, 2);
1152#else 1150#else
@@ -1758,8 +1756,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1758 1756
1759 *skb_push(skb, 2) = 0; 1757 *skb_push(skb, 2) = 0;
1760 if (ppp->pass_filter && 1758 if (ppp->pass_filter &&
1761 sk_run_filter(skb, ppp->pass_filter, 1759 sk_run_filter(skb, ppp->pass_filter) == 0) {
1762 ppp->pass_len) == 0) {
1763 if (ppp->debug & 1) 1760 if (ppp->debug & 1)
1764 printk(KERN_DEBUG "PPP: inbound frame " 1761 printk(KERN_DEBUG "PPP: inbound frame "
1765 "not passed\n"); 1762 "not passed\n");
@@ -1767,8 +1764,7 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1767 return; 1764 return;
1768 } 1765 }
1769 if (!(ppp->active_filter && 1766 if (!(ppp->active_filter &&
1770 sk_run_filter(skb, ppp->active_filter, 1767 sk_run_filter(skb, ppp->active_filter) == 0))
1771 ppp->active_len) == 0))
1772 ppp->last_recv = jiffies; 1768 ppp->last_recv = jiffies;
1773 __skb_pull(skb, 2); 1769 __skb_pull(skb, 2);
1774 } else 1770 } else