Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1234311

Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for four elements

From Denys Vlasenko <dvlasenk@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for four elements
Date 2015-09-28 19:30 +0200
Message-ID <qdKps-62N-7@gated-at.bofh.it> (permalink)
References <qdFSO-5O5-19@gated-at.bofh.it> <qdH8e-1eq-13@gated-at.bofh.it> <qdHrA-1Q9-5@gated-at.bofh.it> <qdHBg-21o-21@gated-at.bofh.it> <qdIH0-3xT-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 09/28/2015 05:32 PM, David Laight wrote:
> From: Eric Dumazet
>> Sent: 28 September 2015 15:27
>> On Mon, 2015-09-28 at 14:12 +0000, David Laight wrote:
>>> From: Neil Horman
>>>> Sent: 28 September 2015 14:51
>>>> On Mon, Sep 28, 2015 at 02:34:04PM +0200, Denys Vlasenko wrote:
>>>>> Seemingly innocuous sctp_trans_state_to_prio_map[] array
>>>>> is way bigger than it looks, since
>>>>> "[SCTP_UNKNOWN] = 2" expands into "[0xffff] = 2" !
>>>>>
>>>>> This patch replaces it with switch() statement.
>>>
>>> What about just adding 1 (and masking) before indexing the array?
>>> That might require a static inline function with a local static array.
>>>
>>> Or define the array as (say) [16] and just mask the state before using
>>> it as an index?
>>
>> Just let the compiler do its job, instead of obfuscating source.
>>
>> Compilers can transform a switch into an (optimal) table if it is really
>> a gain.
> 
> The compiler can choose between a jump table and nested ifs for a switch
> statement. I've never seen it convert one into a data array index.

I don't know why people are fixated on a lookup table here.

For just four possible values, the amount of generated code
is less than one Icache cacheline.

Instruction cachelines are efficiently prefetched and branches
are predicted on all modern CPUs.
Possible data access for lookup table can not be prefetched
as efficiently.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for four elements Denys Vlasenko <dvlasenk@redhat.com> - 2015-09-28 14:40 +0200
  Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> - 2015-09-28 14:50 +0200
  Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements Neil Horman <nhorman@tuxdriver.com> - 2015-09-28 16:00 +0200
    RE: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements David Laight <David.Laight@ACULAB.COM> - 2015-09-28 16:20 +0200
      Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements Eric Dumazet <eric.dumazet@gmail.com> - 2015-09-28 16:30 +0200
        RE: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements David Laight <David.Laight@ACULAB.COM> - 2015-09-28 17:40 +0200
          Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements Denys Vlasenko <dvlasenk@redhat.com> - 2015-09-28 19:30 +0200
  Re: [PATCH v2] net: sctp: Don't use 64 kilobyte lookup table for  four elements David Miller <davem@davemloft.net> - 2015-09-29 08:00 +0200

csiph-web