Files
ubports_kernel_google_msm/include/linux
Hagen Paul Pfeifer 01f2f3f6ef net: optimize Berkeley Packet Filter (BPF) processing
Gcc is currenlty not in the ability to optimize the switch statement in
sk_run_filter() because of dense case labels. This patch replace the
OR'd labels with ordered sequenced case labels. The sk_chk_filter()
function is modified to patch/replace the original OPCODES in a
ordered but equivalent form. gcc is now in the ability to transform the
switch statement in sk_run_filter into a jump table of complexity O(1).

Until this patch gcc generates a sequence of conditional branches (O(n) of 567
byte .text segment size (arch x86_64):

7ff: 8b 06                 mov    (%rsi),%eax
801: 66 83 f8 35           cmp    $0x35,%ax
805: 0f 84 d0 02 00 00     je     adb <sk_run_filter+0x31d>
80b: 0f 87 07 01 00 00     ja     918 <sk_run_filter+0x15a>
811: 66 83 f8 15           cmp    $0x15,%ax
815: 0f 84 c5 02 00 00     je     ae0 <sk_run_filter+0x322>
81b: 77 73                 ja     890 <sk_run_filter+0xd2>
81d: 66 83 f8 04           cmp    $0x4,%ax
821: 0f 84 17 02 00 00     je     a3e <sk_run_filter+0x280>
827: 77 29                 ja     852 <sk_run_filter+0x94>
829: 66 83 f8 01           cmp    $0x1,%ax
[...]

With the modification the compiler translate the switch statement into
the following jump table fragment:

7ff: 66 83 3e 2c           cmpw   $0x2c,(%rsi)
803: 0f 87 1f 02 00 00     ja     a28 <sk_run_filter+0x26a>
809: 0f b7 06              movzwl (%rsi),%eax
80c: ff 24 c5 00 00 00 00  jmpq   *0x0(,%rax,8)
813: 44 89 e3              mov    %r12d,%ebx
816: e9 43 03 00 00        jmpq   b5e <sk_run_filter+0x3a0>
81b: 41 89 dc              mov    %ebx,%r12d
81e: e9 3b 03 00 00        jmpq   b5e <sk_run_filter+0x3a0>

Furthermore, I reordered the instructions to reduce cache line misses by
order the most common instruction to the start.

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-06-25 21:33:12 -07:00
..
2010-05-17 22:39:48 -07:00
2010-05-28 01:38:00 +02:00
2010-05-03 08:33:00 -04:00
2010-06-04 16:00:42 -04:00
2010-05-14 17:08:01 -04:00
2010-05-27 09:12:53 -07:00
2010-05-19 13:38:54 -04:00
2010-06-24 21:30:09 -07:00
2010-05-19 22:41:57 -04:00
2010-05-10 16:08:01 -07:00
2010-05-17 16:30:58 -07:00
2010-05-21 19:30:44 +02:00
2010-04-09 08:36:07 +02:00
2010-05-27 22:05:02 -04:00
2010-05-27 22:15:33 -04:00
2010-05-25 08:07:01 -07:00
2010-05-27 09:12:42 -07:00
2010-05-21 09:34:29 -07:00
2010-06-03 03:21:52 -07:00
2010-06-03 03:21:52 -07:00
2010-06-03 03:21:52 -07:00
2010-06-03 03:21:52 -07:00
2010-06-03 03:21:52 -07:00
2010-06-23 13:16:38 -07:00
2010-05-11 12:01:10 -07:00
2010-06-03 03:21:52 -07:00
2010-05-03 11:50:57 +02:00
2010-06-03 03:21:52 -07:00
2010-04-23 02:08:44 +02:00
2010-05-21 09:37:29 -07:00
2010-05-14 15:09:32 -04:00
2010-05-17 12:17:10 +03:00
2010-05-25 19:41:19 -04:00
2010-06-03 03:21:52 -07:00
2010-05-11 14:40:55 +02:00
2010-04-13 14:49:34 -07:00
2010-06-03 03:21:52 -07:00
2010-06-03 03:21:52 -07:00
2010-05-17 05:27:42 +02:00
2010-06-03 03:21:52 -07:00
2010-05-19 13:44:27 +10:00
2010-06-03 03:21:52 -07:00
2010-05-10 23:08:19 +02:00
2010-05-03 15:53:54 -07:00
2010-06-03 03:21:52 -07:00
2010-05-27 09:12:50 -07:00
2010-05-30 09:02:47 -07:00
2010-05-11 10:09:47 +02:00
2010-06-03 03:21:52 -07:00
2010-05-06 10:56:07 +10:00
2010-05-25 11:41:43 -04:00
2010-06-16 14:55:35 -07:00
2010-05-10 11:08:35 -07:00
2010-05-27 09:12:43 -07:00
2010-05-15 23:28:39 -07:00
2010-04-13 12:43:42 +02:00
2010-05-12 23:02:23 -07:00
2010-05-21 09:34:29 -07:00
2010-05-19 22:40:47 -04:00
2010-05-19 22:15:46 +09:30
2010-06-03 03:21:52 -07:00