* [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol @ 2008-03-20 14:34 Johannes Berg 2008-03-20 14:39 ` Will Newton 2008-03-20 18:13 ` Sam Ravnborg 0 siblings, 2 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 14:34 UTC (permalink / raw) To: Daniel Drake; +Cc: Linux Kernel list, linux-wireless, netdev In many cases, especially in networking, it can be beneficial to know at compile time whether the architecture can do unaligned accesses. This patch introduces a new Kconfig symbol ARCH_CAN_UNALIGNED_ACCESS for that purpose and adds it to the powerpc and x86 architectures. Also add some documentation about alignment and networking, and especially one intended use of this symbol. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> --- Users will be added later, especially wireless networking can benefit. Documentation/unaligned-memory-access.txt | 32 +++++++++++++++++++++++++++--- arch/powerpc/Kconfig | 3 ++ arch/x86/Kconfig | 3 ++ 3 files changed, 35 insertions(+), 3 deletions(-) --- everything.orig/Documentation/unaligned-memory-access.txt 2008-03-20 15:19:06.000000000 +0100 +++ everything/Documentation/unaligned-memory-access.txt 2008-03-20 15:29:13.000000000 +0100 @@ -218,9 +218,35 @@ If use of such macros is not convenient, where the source or destination (or both) are of type u8* or unsigned char*. Due to the byte-wise nature of this operation, unaligned accesses are avoided. + +Alignment vs. Networking +======================== + +On architectures that require aligned loads, networking requires that the IP +header is aligned on a four-byte boundary to optimise the IP stack. For +regular ethernet hardware, the constant NET_IP_ALIGN is used, on most +architectures this constant has the value 2 because the normal ethernet +header is 14 bytes long, so in order to get proper alignment one needs to +DMA to an address that is can be expressed as 4*n + 2. One notable exception +here is powerpc which defines NET_IP_ALIGN to 0 because DMA to unaligned +addresses can be very expensive and dwarf the cost of unaligned loads. + +For some ethernet hardware that cannot DMA to unaligned addresses like +4*n+2 or non-ethernet hardware, this can be a problem, and it is then +required to copy the incoming frame into an aligned buffer. Because this is +unnecessary on architectures that can do unaligned accesses, the code can be +made depend on CONFIG_ARCH_CAN_UNALIGNED_ACCESS like so: + +#ifdef CONFIG_ARCH_CAN_UNALIGNED_ACCESS + skb = copy skb +#else + skb = original skb +#endif + -- -Author: Daniel Drake <dsd@gentoo.org> +Authors: Daniel Drake <dsd@gentoo.org>, + Johannes Berg <johannes@sipsolutions.net> With help from: Alan Cox, Avuton Olrich, Heikki Orsila, Jan Engelhardt, -Johannes Berg, Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, -Uli Kunitz, Vadim Lobanov +Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, Uli Kunitz, +Vadim Lobanov --- everything.orig/arch/powerpc/Kconfig 2008-03-20 15:17:50.000000000 +0100 +++ everything/arch/powerpc/Kconfig 2008-03-20 15:19:00.000000000 +0100 @@ -84,6 +84,9 @@ config GENERIC_FIND_NEXT_BIT config ARCH_NO_VIRT_TO_BUS def_bool PPC64 +config ARCH_CAN_UNALIGNED_ACCESS + def_bool y + config PPC bool default y --- everything.orig/arch/x86/Kconfig 2008-03-20 15:29:31.000000000 +0100 +++ everything/arch/x86/Kconfig 2008-03-20 15:29:49.000000000 +0100 @@ -144,6 +144,9 @@ config AUDIT_ARCH config ARCH_SUPPORTS_AOUT def_bool y +config ARCH_CAN_UNALIGNED_ACCESS + def_bool y + # Use the generic interrupt handling code in kernel/irq/: config GENERIC_HARDIRQS bool ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 14:34 [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol Johannes Berg @ 2008-03-20 14:39 ` Will Newton 2008-03-20 14:58 ` Johannes Berg 2008-03-20 18:13 ` Sam Ravnborg 1 sibling, 1 reply; 19+ messages in thread From: Will Newton @ 2008-03-20 14:39 UTC (permalink / raw) To: Johannes Berg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev On Thu, Mar 20, 2008 at 2:34 PM, Johannes Berg <johannes@sipsolutions.net> wrote: > +For some ethernet hardware that cannot DMA to unaligned addresses like > +4*n+2 or non-ethernet hardware, this can be a problem, and it is then > +required to copy the incoming frame into an aligned buffer. Because this is > +unnecessary on architectures that can do unaligned accesses, the code can be > +made depend on CONFIG_ARCH_CAN_UNALIGNED_ACCESS like so: > + > +#ifdef CONFIG_ARCH_CAN_UNALIGNED_ACCESS > + skb = copy skb > +#else > + skb = original skb > +#endif Is this logic reversed? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 14:39 ` Will Newton @ 2008-03-20 14:58 ` Johannes Berg 0 siblings, 0 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 14:58 UTC (permalink / raw) To: Will Newton; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev [-- Attachment #1: Type: text/plain, Size: 786 bytes --] On Thu, 2008-03-20 at 14:39 +0000, Will Newton wrote: > On Thu, Mar 20, 2008 at 2:34 PM, Johannes Berg > <johannes@sipsolutions.net> wrote: > > > +For some ethernet hardware that cannot DMA to unaligned addresses like > > +4*n+2 or non-ethernet hardware, this can be a problem, and it is then > > +required to copy the incoming frame into an aligned buffer. Because this is > > +unnecessary on architectures that can do unaligned accesses, the code can be > > +made depend on CONFIG_ARCH_CAN_UNALIGNED_ACCESS like so: > > + > > +#ifdef CONFIG_ARCH_CAN_UNALIGNED_ACCESS > > + skb = copy skb > > +#else > > + skb = original skb > > +#endif > > Is this logic reversed? Euh, indeed, thanks. Will repost after having more comments. johannes [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 828 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 14:34 [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol Johannes Berg 2008-03-20 14:39 ` Will Newton @ 2008-03-20 18:13 ` Sam Ravnborg 2008-03-20 18:35 ` Johannes Berg 2008-03-20 18:39 ` [PATCH/RFC v2] " Johannes Berg 1 sibling, 2 replies; 19+ messages in thread From: Sam Ravnborg @ 2008-03-20 18:13 UTC (permalink / raw) To: Johannes Berg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev On Thu, Mar 20, 2008 at 03:34:55PM +0100, Johannes Berg wrote: > In many cases, especially in networking, it can be beneficial to > know at compile time whether the architecture can do unaligned > accesses. This patch introduces a new Kconfig symbol > ARCH_CAN_UNALIGNED_ACCESS Can we please have a single symbol defined and name it: HAVE_* Then the architectures that HAVE this feature can select the symbol. So somewhere in maybe lib/Kconfig or maybe arch/Kconfig add: config HAVE_UNALIGNED_ACCESS_SUPPORT bool And then for x86 select the symbol: config X86 + select HAVE_UNALIGNED_ACCESS_SUPPORT This follows the suggestion as available in Documentation/kbuild/kconfig-language.txt Sam ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 18:13 ` Sam Ravnborg @ 2008-03-20 18:35 ` Johannes Berg 2008-03-20 18:39 ` [PATCH/RFC v2] " Johannes Berg 1 sibling, 0 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 18:35 UTC (permalink / raw) To: Sam Ravnborg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev [-- Attachment #1: Type: text/plain, Size: 699 bytes --] On Thu, 2008-03-20 at 19:13 +0100, Sam Ravnborg wrote: > On Thu, Mar 20, 2008 at 03:34:55PM +0100, Johannes Berg wrote: > > In many cases, especially in networking, it can be beneficial to > > know at compile time whether the architecture can do unaligned > > accesses. This patch introduces a new Kconfig symbol > > ARCH_CAN_UNALIGNED_ACCESS > > Can we please have a single symbol defined and name it: > HAVE_* > > Then the architectures that HAVE this feature can select the symbol. Sure. Where should it be defined? arch/Kconfig? > This follows the suggestion as available in > Documentation/kbuild/kconfig-language.txt Guess I haven't read that in a while. johannes [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 828 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 18:13 ` Sam Ravnborg 2008-03-20 18:35 ` Johannes Berg @ 2008-03-20 18:39 ` Johannes Berg 2008-03-20 18:45 ` [PATCH/RFC v3] " Johannes Berg 2008-03-20 21:13 ` [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS " David Miller 1 sibling, 2 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 18:39 UTC (permalink / raw) To: Sam Ravnborg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev In many cases, especially in networking, it can be beneficial to know at compile time whether the architecture can do unaligned accesses. This patch introduces a new Kconfig symbol ARCH_CAN_UNALIGNED_ACCESS for that purpose and adds it to the powerpc and x86 architectures. Also add some documentation about alignment and networking, and especially one intended use of this symbol. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> --- Fixes thanks to Sam and Will. Documentation/unaligned-memory-access.txt | 32 +++++++++++++++++++++++++++--- arch/Kconfig | 3 ++ arch/powerpc/Kconfig | 1 arch/x86/Kconfig | 1 4 files changed, 34 insertions(+), 3 deletions(-) --- everything.orig/Documentation/unaligned-memory-access.txt 2008-03-20 15:30:38.000000000 +0100 +++ everything/Documentation/unaligned-memory-access.txt 2008-03-20 19:38:30.000000000 +0100 @@ -218,9 +218,35 @@ If use of such macros is not convenient, where the source or destination (or both) are of type u8* or unsigned char*. Due to the byte-wise nature of this operation, unaligned accesses are avoided. + +Alignment vs. Networking +======================== + +On architectures that require aligned loads, networking requires that the IP +header is aligned on a four-byte boundary to optimise the IP stack. For +regular ethernet hardware, the constant NET_IP_ALIGN is used, on most +architectures this constant has the value 2 because the normal ethernet +header is 14 bytes long, so in order to get proper alignment one needs to +DMA to an address that is can be expressed as 4*n + 2. One notable exception +here is powerpc which defines NET_IP_ALIGN to 0 because DMA to unaligned +addresses can be very expensive and dwarf the cost of unaligned loads. + +For some ethernet hardware that cannot DMA to unaligned addresses like +4*n+2 or non-ethernet hardware, this can be a problem, and it is then +required to copy the incoming frame into an aligned buffer. Because this is +unnecessary on architectures that can do unaligned accesses, the code can be +made depend on CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT like so: + +#ifdef CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT + skb = original skb +#else + skb = copy skb +#endif + -- -Author: Daniel Drake <dsd@gentoo.org> +Authors: Daniel Drake <dsd@gentoo.org>, + Johannes Berg <johannes@sipsolutions.net> With help from: Alan Cox, Avuton Olrich, Heikki Orsila, Jan Engelhardt, -Johannes Berg, Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, -Uli Kunitz, Vadim Lobanov +Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, Uli Kunitz, +Vadim Lobanov --- everything.orig/arch/powerpc/Kconfig 2008-03-20 15:30:38.000000000 +0100 +++ everything/arch/powerpc/Kconfig 2008-03-20 19:37:22.000000000 +0100 @@ -91,6 +91,7 @@ config PPC select HAVE_OPROFILE select HAVE_KPROBES select HAVE_KRETPROBES + select HAVE_UNALIGNED_ACCESS_SUPPORT config EARLY_PRINTK bool --- everything.orig/arch/x86/Kconfig 2008-03-20 15:30:38.000000000 +0100 +++ everything/arch/x86/Kconfig 2008-03-20 19:38:08.000000000 +0100 @@ -23,6 +23,7 @@ config X86 select HAVE_KPROBES select HAVE_KRETPROBES select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64) + select HAVE_UNALIGNED_ACCESS_SUPPORT config GENERIC_LOCKBREAK --- everything.orig/arch/Kconfig 2008-03-20 19:37:26.000000000 +0100 +++ everything/arch/Kconfig 2008-03-20 19:37:34.000000000 +0100 @@ -36,3 +36,6 @@ config HAVE_KPROBES config HAVE_KRETPROBES def_bool n + +config HAVE_UNALIGNED_ACCESS_SUPPORT + def_bool n ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH/RFC v3] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 18:39 ` [PATCH/RFC v2] " Johannes Berg @ 2008-03-20 18:45 ` Johannes Berg 2008-03-20 19:09 ` Harvey Harrison 2008-03-20 19:41 ` Sam Ravnborg 2008-03-20 21:13 ` [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS " David Miller 1 sibling, 2 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 18:45 UTC (permalink / raw) To: Sam Ravnborg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev Subject: introduce HAVE_UNALIGNED_ACCESS_SUPPORT Kconfig symbol In many cases, especially in networking, it can be beneficial to know at compile time whether the architecture can do unaligned accesses. This patch introduces a new Kconfig symbol HAVE_UNALIGNED_ACCESS_SUPPORT for that purpose and adds it to the powerpc and x86 architectures. Also add some documentation about alignment and networking, and especially one intended use of this symbol. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> --- Erm. I should update the patch description and title too... Documentation/unaligned-memory-access.txt | 32 +++++++++++++++++++++++++++--- arch/Kconfig | 3 ++ arch/powerpc/Kconfig | 1 arch/x86/Kconfig | 1 4 files changed, 34 insertions(+), 3 deletions(-) --- everything.orig/Documentation/unaligned-memory-access.txt 2008-03-20 15:30:38.000000000 +0100 +++ everything/Documentation/unaligned-memory-access.txt 2008-03-20 19:38:30.000000000 +0100 @@ -218,9 +218,35 @@ If use of such macros is not convenient, where the source or destination (or both) are of type u8* or unsigned char*. Due to the byte-wise nature of this operation, unaligned accesses are avoided. + +Alignment vs. Networking +======================== + +On architectures that require aligned loads, networking requires that the IP +header is aligned on a four-byte boundary to optimise the IP stack. For +regular ethernet hardware, the constant NET_IP_ALIGN is used, on most +architectures this constant has the value 2 because the normal ethernet +header is 14 bytes long, so in order to get proper alignment one needs to +DMA to an address that is can be expressed as 4*n + 2. One notable exception +here is powerpc which defines NET_IP_ALIGN to 0 because DMA to unaligned +addresses can be very expensive and dwarf the cost of unaligned loads. + +For some ethernet hardware that cannot DMA to unaligned addresses like +4*n+2 or non-ethernet hardware, this can be a problem, and it is then +required to copy the incoming frame into an aligned buffer. Because this is +unnecessary on architectures that can do unaligned accesses, the code can be +made depend on CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT like so: + +#ifdef CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT + skb = original skb +#else + skb = copy skb +#endif + -- -Author: Daniel Drake <dsd@gentoo.org> +Authors: Daniel Drake <dsd@gentoo.org>, + Johannes Berg <johannes@sipsolutions.net> With help from: Alan Cox, Avuton Olrich, Heikki Orsila, Jan Engelhardt, -Johannes Berg, Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, -Uli Kunitz, Vadim Lobanov +Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, Uli Kunitz, +Vadim Lobanov --- everything.orig/arch/powerpc/Kconfig 2008-03-20 15:30:38.000000000 +0100 +++ everything/arch/powerpc/Kconfig 2008-03-20 19:37:22.000000000 +0100 @@ -91,6 +91,7 @@ config PPC select HAVE_OPROFILE select HAVE_KPROBES select HAVE_KRETPROBES + select HAVE_UNALIGNED_ACCESS_SUPPORT config EARLY_PRINTK bool --- everything.orig/arch/x86/Kconfig 2008-03-20 15:30:38.000000000 +0100 +++ everything/arch/x86/Kconfig 2008-03-20 19:38:08.000000000 +0100 @@ -23,6 +23,7 @@ config X86 select HAVE_KPROBES select HAVE_KRETPROBES select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64) + select HAVE_UNALIGNED_ACCESS_SUPPORT config GENERIC_LOCKBREAK --- everything.orig/arch/Kconfig 2008-03-20 19:37:26.000000000 +0100 +++ everything/arch/Kconfig 2008-03-20 19:37:34.000000000 +0100 @@ -36,3 +36,6 @@ config HAVE_KPROBES config HAVE_KRETPROBES def_bool n + +config HAVE_UNALIGNED_ACCESS_SUPPORT + def_bool n ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v3] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 18:45 ` [PATCH/RFC v3] " Johannes Berg @ 2008-03-20 19:09 ` Harvey Harrison 2008-03-20 19:12 ` Johannes Berg 2008-03-20 19:41 ` Sam Ravnborg 1 sibling, 1 reply; 19+ messages in thread From: Harvey Harrison @ 2008-03-20 19:09 UTC (permalink / raw) To: Johannes Berg Cc: Sam Ravnborg, Daniel Drake, Linux Kernel list, linux-wireless, netdev On Thu, 2008-03-20 at 19:45 +0100, Johannes Berg wrote: > +For some ethernet hardware that cannot DMA to unaligned addresses like > +4*n+2 or non-ethernet hardware, this can be a problem, and it is then > +required to copy the incoming frame into an aligned buffer. Because this is > +unnecessary on architectures that can do unaligned accesses, the code can be > +made depend on CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT like so: > + > +#ifdef CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT > + skb = original skb > +#else > + skb = copy skb > +#endif > + Couldn't this just be made an inline in a networking header somewhere, instead of ifdefs in the code? Harvey ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v3] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 19:09 ` Harvey Harrison @ 2008-03-20 19:12 ` Johannes Berg 0 siblings, 0 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 19:12 UTC (permalink / raw) To: Harvey Harrison Cc: Sam Ravnborg, Daniel Drake, Linux Kernel list, linux-wireless, netdev [-- Attachment #1: Type: text/plain, Size: 430 bytes --] > > +#ifdef CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT > > + skb = original skb > > +#else > > + skb = copy skb > > +#endif > > + > > Couldn't this just be made an inline in a networking header somewhere, > instead of ifdefs in the code? That was just an example, you might want to do other things too. If it turns out that a similar code pattern will be used all over the place we can then consolidate that. johannes [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 828 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v3] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 18:45 ` [PATCH/RFC v3] " Johannes Berg 2008-03-20 19:09 ` Harvey Harrison @ 2008-03-20 19:41 ` Sam Ravnborg 2008-03-20 19:50 ` [PATCH/RFC v4] introduce HAVE_UNALIGNED_ACCESS_SUPPORT " Johannes Berg 1 sibling, 1 reply; 19+ messages in thread From: Sam Ravnborg @ 2008-03-20 19:41 UTC (permalink / raw) To: Johannes Berg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev On Thu, Mar 20, 2008 at 07:45:34PM +0100, Johannes Berg wrote: > Subject: introduce HAVE_UNALIGNED_ACCESS_SUPPORT Kconfig symbol > > In many cases, especially in networking, it can be beneficial to > know at compile time whether the architecture can do unaligned > accesses. This patch introduces a new Kconfig symbol > HAVE_UNALIGNED_ACCESS_SUPPORT > for that purpose and adds it to the powerpc and x86 architectures. > Also add some documentation about alignment and networking, and > especially one intended use of this symbol. > > Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Sam Ravnborg <sam@ravnborg.org> Sam ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH/RFC v4] introduce HAVE_UNALIGNED_ACCESS_SUPPORT Kconfig symbol 2008-03-20 19:41 ` Sam Ravnborg @ 2008-03-20 19:50 ` Johannes Berg 2008-03-21 8:45 ` Ingo Molnar 0 siblings, 1 reply; 19+ messages in thread From: Johannes Berg @ 2008-03-20 19:50 UTC (permalink / raw) To: Sam Ravnborg; +Cc: Daniel Drake, Linux Kernel list, linux-wireless, netdev In many cases, especially in networking, it can be beneficial to know at compile time whether the architecture can do unaligned accesses. This patch introduces a new Kconfig symbol HAVE_UNALIGNED_ACCESS_SUPPORT for that purpose and adds it to the powerpc and x86 architectures. Also add some documentation about alignment and networking, and especially one intended use of this symbol. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Sam Ravnborg <sam@ravnborg.org> --- Didn't I say I was going to fix the subject? Sorry. Documentation/unaligned-memory-access.txt | 32 +++++++++++++++++++++++++++--- arch/Kconfig | 3 ++ arch/powerpc/Kconfig | 1 arch/x86/Kconfig | 1 4 files changed, 34 insertions(+), 3 deletions(-) --- everything.orig/Documentation/unaligned-memory-access.txt 2008-03-20 15:30:38.000000000 +0100 +++ everything/Documentation/unaligned-memory-access.txt 2008-03-20 19:38:30.000000000 +0100 @@ -218,9 +218,35 @@ If use of such macros is not convenient, where the source or destination (or both) are of type u8* or unsigned char*. Due to the byte-wise nature of this operation, unaligned accesses are avoided. + +Alignment vs. Networking +======================== + +On architectures that require aligned loads, networking requires that the IP +header is aligned on a four-byte boundary to optimise the IP stack. For +regular ethernet hardware, the constant NET_IP_ALIGN is used, on most +architectures this constant has the value 2 because the normal ethernet +header is 14 bytes long, so in order to get proper alignment one needs to +DMA to an address that is can be expressed as 4*n + 2. One notable exception +here is powerpc which defines NET_IP_ALIGN to 0 because DMA to unaligned +addresses can be very expensive and dwarf the cost of unaligned loads. + +For some ethernet hardware that cannot DMA to unaligned addresses like +4*n+2 or non-ethernet hardware, this can be a problem, and it is then +required to copy the incoming frame into an aligned buffer. Because this is +unnecessary on architectures that can do unaligned accesses, the code can be +made depend on CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT like so: + +#ifdef CONFIG_HAVE_UNALIGNED_ACCESS_SUPPORT + skb = original skb +#else + skb = copy skb +#endif + -- -Author: Daniel Drake <dsd@gentoo.org> +Authors: Daniel Drake <dsd@gentoo.org>, + Johannes Berg <johannes@sipsolutions.net> With help from: Alan Cox, Avuton Olrich, Heikki Orsila, Jan Engelhardt, -Johannes Berg, Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, -Uli Kunitz, Vadim Lobanov +Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, Uli Kunitz, +Vadim Lobanov --- everything.orig/arch/powerpc/Kconfig 2008-03-20 15:30:38.000000000 +0100 +++ everything/arch/powerpc/Kconfig 2008-03-20 19:37:22.000000000 +0100 @@ -91,6 +91,7 @@ config PPC select HAVE_OPROFILE select HAVE_KPROBES select HAVE_KRETPROBES + select HAVE_UNALIGNED_ACCESS_SUPPORT config EARLY_PRINTK bool --- everything.orig/arch/x86/Kconfig 2008-03-20 15:30:38.000000000 +0100 +++ everything/arch/x86/Kconfig 2008-03-20 19:38:08.000000000 +0100 @@ -23,6 +23,7 @@ config X86 select HAVE_KPROBES select HAVE_KRETPROBES select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64) + select HAVE_UNALIGNED_ACCESS_SUPPORT config GENERIC_LOCKBREAK --- everything.orig/arch/Kconfig 2008-03-20 19:37:26.000000000 +0100 +++ everything/arch/Kconfig 2008-03-20 19:37:34.000000000 +0100 @@ -36,3 +36,6 @@ config HAVE_KPROBES config HAVE_KRETPROBES def_bool n + +config HAVE_UNALIGNED_ACCESS_SUPPORT + def_bool n ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v4] introduce HAVE_UNALIGNED_ACCESS_SUPPORT Kconfig symbol 2008-03-20 19:50 ` [PATCH/RFC v4] introduce HAVE_UNALIGNED_ACCESS_SUPPORT " Johannes Berg @ 2008-03-21 8:45 ` Ingo Molnar 0 siblings, 0 replies; 19+ messages in thread From: Ingo Molnar @ 2008-03-21 8:45 UTC (permalink / raw) To: Johannes Berg Cc: Sam Ravnborg, Daniel Drake, Linux Kernel list, linux-wireless, netdev * Johannes Berg <johannes@sipsolutions.net> wrote: > --- everything.orig/arch/x86/Kconfig 2008-03-20 15:30:38.000000000 +0100 > +++ everything/arch/x86/Kconfig 2008-03-20 19:38:08.000000000 +0100 > @@ -23,6 +23,7 @@ config X86 > select HAVE_KPROBES > select HAVE_KRETPROBES > select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64) > + select HAVE_UNALIGNED_ACCESS_SUPPORT Acked-by: Ingo Molnar <mingo@elte.hu> Ingo ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 18:39 ` [PATCH/RFC v2] " Johannes Berg 2008-03-20 18:45 ` [PATCH/RFC v3] " Johannes Berg @ 2008-03-20 21:13 ` David Miller 2008-03-20 21:21 ` Johannes Berg 2008-03-25 14:11 ` [PATCH/RFC v5] introduce HAVE_EFFICIENT_UNALIGNED_ACCESS " Johannes Berg 1 sibling, 2 replies; 19+ messages in thread From: David Miller @ 2008-03-20 21:13 UTC (permalink / raw) To: johannes; +Cc: sam, dsd, linux-kernel, linux-wireless, netdev From: Johannes Berg <johannes@sipsolutions.net> Date: Thu, 20 Mar 2008 19:39:33 +0100 > In many cases, especially in networking, it can be beneficial to > know at compile time whether the architecture can do unaligned > accesses. This patch introduces a new Kconfig symbol > ARCH_CAN_UNALIGNED_ACCESS > for that purpose and adds it to the powerpc and x86 architectures. > Also add some documentation about alignment and networking, and > especially one intended use of this symbol. > > Signed-off-by: Johannes Berg <johannes@sipsolutions.net> I think you're semantically testing the wrong thing. It's not if unaligned accesses are supported, it's if they are efficient enough or not. For example, sparc64 fully handles unaligned accesses but taking the trap to fix it up is slow. So sparc64 "can" handle unaligned accesses, but whether we want to set this symbol or not is another matter. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 21:13 ` [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS " David Miller @ 2008-03-20 21:21 ` Johannes Berg 2008-03-20 21:27 ` David Miller 2008-03-20 22:03 ` John W. Linville 2008-03-25 14:11 ` [PATCH/RFC v5] introduce HAVE_EFFICIENT_UNALIGNED_ACCESS " Johannes Berg 1 sibling, 2 replies; 19+ messages in thread From: Johannes Berg @ 2008-03-20 21:21 UTC (permalink / raw) To: David Miller; +Cc: sam, dsd, linux-kernel, linux-wireless, netdev [-- Attachment #1: Type: text/plain, Size: 682 bytes --] > I think you're semantically testing the wrong thing. > > It's not if unaligned accesses are supported, it's if they are > efficient enough or not. > > For example, sparc64 fully handles unaligned accesses but taking the > trap to fix it up is slow. So sparc64 "can" handle unaligned > accesses, but whether we want to set this symbol or not is another > matter. Yeah, good point. Should I rename it to HAVE_EFFICIENT_UNALIGNED_ACCESS or similar? Or have it defined as some sort of number so you can make actually make tradeoffs? Like Dave Woodhouse suggested at some point to have get_unaligned() take an argument that indicates the probability... johannes [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 828 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 21:21 ` Johannes Berg @ 2008-03-20 21:27 ` David Miller 2008-03-20 22:03 ` John W. Linville 1 sibling, 0 replies; 19+ messages in thread From: David Miller @ 2008-03-20 21:27 UTC (permalink / raw) To: johannes; +Cc: sam, dsd, linux-kernel, linux-wireless, netdev From: Johannes Berg <johannes@sipsolutions.net> Date: Thu, 20 Mar 2008 22:21:46 +0100 > Yeah, good point. Should I rename it to HAVE_EFFICIENT_UNALIGNED_ACCESS > or similar? Or have it defined as some sort of number so you can make > actually make tradeoffs? Like Dave Woodhouse suggested at some point to > have get_unaligned() take an argument that indicates the probability... Yes, that name and something with a "score" of some sort would be nice. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 21:21 ` Johannes Berg 2008-03-20 21:27 ` David Miller @ 2008-03-20 22:03 ` John W. Linville 2008-03-20 22:10 ` David Miller 1 sibling, 1 reply; 19+ messages in thread From: John W. Linville @ 2008-03-20 22:03 UTC (permalink / raw) To: Johannes Berg Cc: David Miller, sam, dsd, linux-kernel, linux-wireless, netdev On Thu, Mar 20, 2008 at 10:21:46PM +0100, Johannes Berg wrote: > > > I think you're semantically testing the wrong thing. > > > > It's not if unaligned accesses are supported, it's if they are > > efficient enough or not. > > > > For example, sparc64 fully handles unaligned accesses but taking the > > trap to fix it up is slow. So sparc64 "can" handle unaligned > > accesses, but whether we want to set this symbol or not is another > > matter. > > Yeah, good point. Should I rename it to HAVE_EFFICIENT_UNALIGNED_ACCESS > or similar? Or have it defined as some sort of number so you can make > actually make tradeoffs? Like Dave Woodhouse suggested at some point to > have get_unaligned() take an argument that indicates the probability... Ugh...that sounds like premature optimization to me... While I think Dave has a point, I don't think you should labor the word choice too much. Try to document it as clearly as possible and hope for the best -- I hear that the arch maintainers are top notch! :-) John -- John W. Linville linville@tuxdriver.com ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 22:03 ` John W. Linville @ 2008-03-20 22:10 ` David Miller 0 siblings, 0 replies; 19+ messages in thread From: David Miller @ 2008-03-20 22:10 UTC (permalink / raw) To: linville; +Cc: johannes, sam, dsd, linux-kernel, linux-wireless, netdev From: "John W. Linville" <linville@tuxdriver.com> Date: Thu, 20 Mar 2008 18:03:48 -0400 > While I think Dave has a point, I don't think you should labor the word > choice too much. Try to document it as clearly as possible and hope > for the best -- I hear that the arch maintainers are top notch! :-) I think the name of the macro is very important. Non-arch people will see this thing and wonder what in the world it means. You can document something with kerneldoc foo as much as you like, still the initial impression the reader gets from the name is of utmost importance. ^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH/RFC v5] introduce HAVE_EFFICIENT_UNALIGNED_ACCESS Kconfig symbol 2008-03-20 21:13 ` [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS " David Miller 2008-03-20 21:21 ` Johannes Berg @ 2008-03-25 14:11 ` Johannes Berg 2008-04-02 10:24 ` Johannes Berg 1 sibling, 1 reply; 19+ messages in thread From: Johannes Berg @ 2008-03-25 14:11 UTC (permalink / raw) To: David Miller Cc: sam, dsd, linux-kernel, linux-wireless, netdev, Ingo Molnar, David Woodhouse In many cases, especially in networking, it can be beneficial to know at compile time whether the architecture can do unaligned accesses efficiently. This patch introduces a new Kconfig symbol HAVE_EFFICIENT_UNALIGNED_ACCESS for that purpose and adds it to the powerpc and x86 architectures. Also add some documentation about alignment and networking, and especially one intended use of this symbol. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Sam Ravnborg <sam@ravnborg.org> Acked-by: Ingo Molnar <mingo@elte.hu> [x86 architecture part] --- v5: rename to HAVE_EFFICIENT_UNALIGNED_ACCESS I have opted to not introduce any symbol associated with the cost of unaligned accesses, David Woodhouse once suggested that such a cost should be combined with a probability of (un-)alignment even in the get_unaligned/put_unaligned macros and I think this should be combined with a patch introducing a global cost constant. Also, this would require architecture changes because if some code knew the likelyhood of unaligned accesses was small enough over the cost of them, architectures that complain in the trap handle would still complain in that unlikely case although the code explicitly made a trade-off based on the cost/probability. Documentation/unaligned-memory-access.txt | 32 +++++++++++++++++++++++++++--- arch/Kconfig | 19 +++++++++++++++++ arch/powerpc/Kconfig | 1 arch/x86/Kconfig | 1 4 files changed, 50 insertions(+), 3 deletions(-) --- everything.orig/Documentation/unaligned-memory-access.txt 2008-03-25 14:54:11.000000000 +0100 +++ everything/Documentation/unaligned-memory-access.txt 2008-03-25 14:58:57.000000000 +0100 @@ -218,9 +218,35 @@ If use of such macros is not convenient, where the source or destination (or both) are of type u8* or unsigned char*. Due to the byte-wise nature of this operation, unaligned accesses are avoided. + +Alignment vs. Networking +======================== + +On architectures that require aligned loads, networking requires that the IP +header is aligned on a four-byte boundary to optimise the IP stack. For +regular ethernet hardware, the constant NET_IP_ALIGN is used, on most +architectures this constant has the value 2 because the normal ethernet +header is 14 bytes long, so in order to get proper alignment one needs to +DMA to an address that is can be expressed as 4*n + 2. One notable exception +here is powerpc which defines NET_IP_ALIGN to 0 because DMA to unaligned +addresses can be very expensive and dwarf the cost of unaligned loads. + +For some ethernet hardware that cannot DMA to unaligned addresses like +4*n+2 or non-ethernet hardware, this can be a problem, and it is then +required to copy the incoming frame into an aligned buffer. Because this is +unnecessary on architectures that can do unaligned accesses, the code can be +made depend on CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS like so: + +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS + skb = original skb +#else + skb = copy skb +#endif + -- -Author: Daniel Drake <dsd@gentoo.org> +Authors: Daniel Drake <dsd@gentoo.org>, + Johannes Berg <johannes@sipsolutions.net> With help from: Alan Cox, Avuton Olrich, Heikki Orsila, Jan Engelhardt, -Johannes Berg, Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, -Uli Kunitz, Vadim Lobanov +Kyle McMartin, Kyle Moffett, Randy Dunlap, Robert Hancock, Uli Kunitz, +Vadim Lobanov --- everything.orig/arch/powerpc/Kconfig 2008-03-25 14:54:10.000000000 +0100 +++ everything/arch/powerpc/Kconfig 2008-03-25 14:58:30.000000000 +0100 @@ -91,6 +91,7 @@ config PPC select HAVE_OPROFILE select HAVE_KPROBES select HAVE_KRETPROBES + select HAVE_EFFICIENT_UNALIGNED_ACCESS config EARLY_PRINTK bool --- everything.orig/arch/x86/Kconfig 2008-03-25 14:54:10.000000000 +0100 +++ everything/arch/x86/Kconfig 2008-03-25 14:58:38.000000000 +0100 @@ -23,6 +23,7 @@ config X86 select HAVE_KPROBES select HAVE_KRETPROBES select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64) + select HAVE_EFFICIENT_UNALIGNED_ACCESS config GENERIC_LOCKBREAK --- everything.orig/arch/Kconfig 2008-03-25 14:54:10.000000000 +0100 +++ everything/arch/Kconfig 2008-03-25 15:08:06.000000000 +0100 @@ -36,3 +36,22 @@ config HAVE_KPROBES config HAVE_KRETPROBES def_bool n + +config HAVE_EFFICIENT_UNALIGNED_ACCESS + def_bool n + help + Some architectures are unable to perform unaligned accesses + without the use of get_unaligned/put_unaligned. Others are + unable to perform such accesses efficiently (e.g. trap on + unaligned access and require fixing it up in the exception + handler.) + + This symbol should be selected by an architecture if it can + perform unaligned accesses efficiently to allow different + code paths to be selected for these cases. Some network + drivers, for example, could opt to not fix up alignment + problems with received packets if doing so would not help + much. + + See Documentation/unaligned-memory-access.txt for more + information on the topic of unaligned memory accesses. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH/RFC v5] introduce HAVE_EFFICIENT_UNALIGNED_ACCESS Kconfig symbol 2008-03-25 14:11 ` [PATCH/RFC v5] introduce HAVE_EFFICIENT_UNALIGNED_ACCESS " Johannes Berg @ 2008-04-02 10:24 ` Johannes Berg 0 siblings, 0 replies; 19+ messages in thread From: Johannes Berg @ 2008-04-02 10:24 UTC (permalink / raw) To: David Miller Cc: sam, dsd, linux-kernel, linux-wireless, netdev, Ingo Molnar, David Woodhouse [-- Attachment #1: Type: text/plain, Size: 778 bytes --] On Tue, 2008-03-25 at 15:11 +0100, Johannes Berg wrote: > In many cases, especially in networking, it can be beneficial to > know at compile time whether the architecture can do unaligned > accesses efficiently. This patch introduces a new Kconfig symbol > HAVE_EFFICIENT_UNALIGNED_ACCESS > for that purpose and adds it to the powerpc and x86 architectures. > Also add some documentation about alignment and networking, and > especially one intended use of this symbol. I haven't had comments on this last version, any objections to sending it to akpm for inclusion? I would like to start building on it in the wireless tree. Also, what's the best way to get arch maintainers to note this and evaluate whether they want to set the symbol or not? johannes [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 828 bytes --] ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2008-04-02 10:24 UTC | newest] Thread overview: 19+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-03-20 14:34 [PATCH/RFC] introduce ARCH_CAN_UNALIGNED_ACCESS Kconfig symbol Johannes Berg 2008-03-20 14:39 ` Will Newton 2008-03-20 14:58 ` Johannes Berg 2008-03-20 18:13 ` Sam Ravnborg 2008-03-20 18:35 ` Johannes Berg 2008-03-20 18:39 ` [PATCH/RFC v2] " Johannes Berg 2008-03-20 18:45 ` [PATCH/RFC v3] " Johannes Berg 2008-03-20 19:09 ` Harvey Harrison 2008-03-20 19:12 ` Johannes Berg 2008-03-20 19:41 ` Sam Ravnborg 2008-03-20 19:50 ` [PATCH/RFC v4] introduce HAVE_UNALIGNED_ACCESS_SUPPORT " Johannes Berg 2008-03-21 8:45 ` Ingo Molnar 2008-03-20 21:13 ` [PATCH/RFC v2] introduce ARCH_CAN_UNALIGNED_ACCESS " David Miller 2008-03-20 21:21 ` Johannes Berg 2008-03-20 21:27 ` David Miller 2008-03-20 22:03 ` John W. Linville 2008-03-20 22:10 ` David Miller 2008-03-25 14:11 ` [PATCH/RFC v5] introduce HAVE_EFFICIENT_UNALIGNED_ACCESS " Johannes Berg 2008-04-02 10:24 ` Johannes Berg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).