From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751155AbdE2MyV (ORCPT ); Mon, 29 May 2017 08:54:21 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:34889 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750966AbdE2MyS (ORCPT ); Mon, 29 May 2017 08:54:18 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Arnd Bergmann Date: Mon, 29 May 2017 14:54:16 +0200 X-Google-Sender-Auth: 1cPI9VknxgOZLqUMU2IXOZazEhs Message-ID: Subject: Re: CPU_BIG_ENDIAN in generic code (was: Re: [PATCH v3 3/7] arch/sparc: Define config parameter CPU_BIG_ENDIAN) To: Max Filippov Cc: Geert Uytterhoeven , Babu Moger , "David S. Miller" , Peter Zijlstra , Ingo Molnar , sparclinux , "linux-kernel@vger.kernel.org" , Linux-Arch , "devicetree@vger.kernel.org" , "linux-serial@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 26, 2017 at 12:43 AM, Max Filippov wrote: > On Thu, May 25, 2017 at 3:27 PM, Max Filippov wrote: >> On Wed, May 24, 2017 at 3:18 AM, Arnd Bergmann wrote: >>> On Wed, May 24, 2017 at 11:59 AM, Geert Uytterhoeven >>> wrote: >>>> I guess the time is ripe for adding (both) symbols to all architectures? >>> >>> Good idea. I think we can do most of this by adding a few lines to >>> arch/Kconfig: >>> >>> config CPU_BIG_ENDIAN >>> bool >>> >>> config CPU_LITTLE_ENDIAN >>> def_bool !CPU_BIG_ENDIAN >>> >>> This way, we only need to add 'select CPU_BIG_ENDIAN' to the >>> architectures that are always big-endian, and we don't need to >>> change anything for the ones that have a single 'CPU_BIG_ENDIAN' >>> option. >>> >>> The three architectures that have a 'choice' statement (mips, ppc and >>> sh) will have to convert, and m32r will have to replace the >>> option with the opposite one, which could break 'make oldconfig', >>> but nobody really cares about m32r any more. >> >> Xtensa may have either endianness and for xtensa we define >> CONFIG_CPU_BIG_ENDIAN or CONFIG_CPU_LITTLE_ENDIAN >> in the arch/xtensa/Makefile based on the value of the compiler builtin >> macro. I can sort of see why xtensa did it the other way round from everyone else (letting the toolchain decide what the kernel is, rather than letting the kernel pass the respective flags to gcc), but I'd argue that it would be better overall for xtensa to change over so we do it consistently on all architectures. > Also, in outside the Kconfig files there's much more instances of > __{BIG,LITTLE}_ENDIAN than CONFIG_CPU_{BIG,LITTLE}_ENDIAN: > > $ git grep '__\(BIG\|LITTLE\)_ENDIAN' | wc -l > 4537 > $ git grep 'CONFIG_CPU_\(BIG\|LITTLE\)_ENDIAN' | wc -l > 247 > > My understanding is that CONFIG_CPU_{BIG,LITTLE}_ENDIAN was > intended to be used only in Kconfig files, and perhaps all of its uses > outside should be replaced with __{BIG,LITTLE}_ENDIAN. Right, but I also think that using the CONFIG_CPU_* symbols in code makes sense because it is less ambiguous: the way we use __{BIG,LITTLE}_ENDIAN in the kernel is different from how user space uses them in glibc, and this confuses everyone when they try to use them in the kernel after being familiar with the traditional way. The Kconfig symbols don't have this problem. Arnd