mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Stephen Boyd <sboyd@codeaurora.org>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	Nicolas Pitre <nico@fluxnic.net>, Arnd Bergmann <arnd@arndb.de>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [RFC/PATCH 3/3] ARM: Replace calls to __aeabi_{u}idiv with udiv/sdiv instructions
Date: Mon, 23 Nov 2015 20:54:48 +0000	[thread overview]
Message-ID: <yw1x1tbgsag7.fsf@unicorn.mansr.com> (raw)
In-Reply-To: <20151123204955.GC19156@codeaurora.org> (Stephen Boyd's message of "Mon, 23 Nov 2015 12:49:55 -0800")

Stephen Boyd <sboyd@codeaurora.org> writes:

> On 11/21, Måns Rullgård wrote:
>> Stephen Boyd <sboyd@codeaurora.org> writes:
>> 
>> > +static int module_patch_aeabi_uidiv(unsigned long loc, const Elf32_Sym *sym)
>> > +{
>> > +	extern char __aeabi_uidiv[], __aeabi_idiv[];
>> > +	unsigned long udiv_addr = (unsigned long)__aeabi_uidiv;
>> > +	unsigned long sdiv_addr = (unsigned long)__aeabi_idiv;
>> > +	unsigned int udiv_insn, sdiv_insn, mask;
>> > +
>> > +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
>> > +		mask = HWCAP_IDIVT;
>> > +		udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1);
>> > +		sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1);
>> > +	} else {
>> > +		mask = HWCAP_IDIVA;
>> > +		udiv_insn = __opcode_to_mem_arm(0xe730f110);
>> > +		sdiv_insn = __opcode_to_mem_arm(0xe710f110);
>> > +	}
>> > +
>> > +	if (elf_hwcap & mask) {
>> > +		if (sym->st_value == udiv_addr) {
>> > +			*(u32 *)loc = udiv_insn;
>> > +			return 1;
>> > +		} else if (sym->st_value == sdiv_addr) {
>> > +			*(u32 *)loc = sdiv_insn;
>> > +			return 1;
>> > +		}
>> > +	}
>> > +
>> > +	return 0;
>> > +}
>> 
>> [...]
>> 
>> > +static void __init patch_aeabi_uidiv(void)
>> > +{
>> > +	extern unsigned long *__start_udiv_loc[], *__stop_udiv_loc[];
>> > +	extern unsigned long *__start_idiv_loc[], *__stop_idiv_loc[];
>> > +	unsigned long **p;
>> > +	unsigned int udiv_insn, sdiv_insn, mask;
>> > +
>> > +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
>> > +		mask = HWCAP_IDIVT;
>> > +		udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1);
>> > +		sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1);
>> > +	} else {
>> > +		mask = HWCAP_IDIVA;
>> > +		udiv_insn = __opcode_to_mem_arm(0xe730f110);
>> > +		sdiv_insn = __opcode_to_mem_arm(0xe710f110);
>> > +	}
>> > +
>> > +	if (elf_hwcap & mask) {
>> > +		for (p = __start_udiv_loc; p < __stop_udiv_loc; p++) {
>> > +			unsigned long *inst = *p;
>> > +			*inst = udiv_insn;
>> > +		}
>> > +		for (p = __start_idiv_loc; p < __stop_idiv_loc; p++) {
>> > +			unsigned long *inst = *p;
>> > +			*inst = sdiv_insn;
>> > +		}
>> > +	}
>> > +}
>> 
>> These functions are rather similar.  Perhaps they could be combined
>> somehow.
>> 
>
> Yes. I have this patch on top, just haven't folded it in because
> it doesn't reduce the lines of code.

I don't see any reason to split it anyhow.  The end result isn't any
harder to understand than the intermediate.

> ----8<----
> From: Stephen Boyd <sboyd@codeaurora.org>
> Subject: [PATCH] consolidate with module code
>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
> ---
>  arch/arm/include/asm/setup.h |  3 +++
>  arch/arm/kernel/module.c     | 16 +++++--------
>  arch/arm/kernel/setup.c      | 54 +++++++++++++++++++++++++++-----------------
>  3 files changed, 42 insertions(+), 31 deletions(-)
>
> diff --git a/arch/arm/include/asm/setup.h b/arch/arm/include/asm/setup.h
> index e0adb9f1bf94..3f251cdb94ef 100644
> --- a/arch/arm/include/asm/setup.h
> +++ b/arch/arm/include/asm/setup.h
> @@ -25,4 +25,7 @@ extern int arm_add_memory(u64 start, u64 size);
>  extern void early_print(const char *str, ...);
>  extern void dump_machine_table(void);
>
> +extern void patch_uidiv(void *addr, size_t size);
> +extern void patch_idiv(void *addr, size_t size);

Why not call things sdiv and udiv like the actual instructions?

>  #endif
> diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
> index 064e6ae60e08..684a68f1085b 100644
> --- a/arch/arm/kernel/module.c
> +++ b/arch/arm/kernel/module.c
> @@ -22,6 +22,7 @@
>
>  #include <asm/hwcap.h>
>  #include <asm/pgtable.h>
> +#include <asm/setup.h>
>  #include <asm/sections.h>
>  #include <asm/smp_plat.h>
>  #include <asm/unwind.h>
> @@ -58,24 +59,19 @@ static int module_patch_aeabi_uidiv(unsigned long loc, const Elf32_Sym *sym)
>  	extern char __aeabi_uidiv[], __aeabi_idiv[];
>  	unsigned long udiv_addr = (unsigned long)__aeabi_uidiv;
>  	unsigned long sdiv_addr = (unsigned long)__aeabi_idiv;
> -	unsigned int udiv_insn, sdiv_insn, mask;
> +	unsigned int mask;
>
> -	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
> +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
>  		mask = HWCAP_IDIVT;
> -		udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1);
> -		sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1);
> -	} else {
> +	else
>  		mask = HWCAP_IDIVA;
> -		udiv_insn = __opcode_to_mem_arm(0xe730f110);
> -		sdiv_insn = __opcode_to_mem_arm(0xe710f110);
> -	}
>
>  	if (elf_hwcap & mask) {
>  		if (sym->st_value == udiv_addr) {
> -			*(u32 *)loc = udiv_insn;
> +			patch_uidiv(&loc, sizeof(loc));
>  			return 1;
>  		} else if (sym->st_value == sdiv_addr) {
> -			*(u32 *)loc = sdiv_insn;
> +			patch_idiv(&loc, sizeof(loc));
>  			return 1;
>  		}
>  	}
> diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
> index d2a3d165dcae..cb86012c47d1 100644
> --- a/arch/arm/kernel/setup.c
> +++ b/arch/arm/kernel/setup.c
> @@ -376,33 +376,45 @@ void __init early_print(const char *str, ...)
>  }
>
>  #ifdef CONFIG_ARM_PATCH_UIDIV
> +static void __init_or_module patch(u32 **addr, size_t count, u32 insn)
> +{
> +	for (; count != 0; count -= 4)
> +		**addr++ = insn;
> +}
> +
> +void __init_or_module patch_uidiv(void *addr, size_t size)
> +{
> +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
> +		patch(addr, size, __opcode_to_mem_thumb32(0xfbb0f0f1));
> +	else
> +		patch(addr, size, __opcode_to_mem_arm(0xe730f110));
> +
> +}
> +
> +void __init_or_module patch_idiv(void *addr, size_t size)
> +{
> +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
> +		patch(addr, size, __opcode_to_mem_thumb32(0xfb90f0f1));
> +	else
> +		patch(addr, size, __opcode_to_mem_arm(0xe710f110));
> +}
> +
>  static void __init patch_aeabi_uidiv(void)
>  {
> -	extern unsigned long *__start_udiv_loc[], *__stop_udiv_loc[];
> -	extern unsigned long *__start_idiv_loc[], *__stop_idiv_loc[];
> -	unsigned long **p;
> -	unsigned int udiv_insn, sdiv_insn, mask;
> +	extern char __start_udiv_loc[], __stop_udiv_loc[];
> +	extern char __start_idiv_loc[], __stop_idiv_loc[];
> +	unsigned int mask;
>
> -	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
> +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
>  		mask = HWCAP_IDIVT;
> -		udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1);
> -		sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1);
> -	} else {
> +	else
>  		mask = HWCAP_IDIVA;
> -		udiv_insn = __opcode_to_mem_arm(0xe730f110);
> -		sdiv_insn = __opcode_to_mem_arm(0xe710f110);
> -	}
>
> -	if (elf_hwcap & mask) {
> -		for (p = __start_udiv_loc; p < __stop_udiv_loc; p++) {
> -			unsigned long *inst = *p;
> -			*inst = udiv_insn;
> -		}
> -		for (p = __start_idiv_loc; p < __stop_idiv_loc; p++) {
> -			unsigned long *inst = *p;
> -			*inst = sdiv_insn;
> -		}
> -	}
> +	if (!(elf_hwcap & mask))
> +		return;
> +
> +	patch_uidiv(__start_udiv_loc, __stop_udiv_loc - __start_udiv_loc);
> +	patch_idiv(__start_idiv_loc, __stop_idiv_loc - __start_idiv_loc);
>  }
>  #else
>  static void __init patch_aeabi_uidiv(void) { }
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project

-- 
Måns Rullgård
mans@mansr.com

  reply	other threads:[~2015-11-23 20:54 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-21  1:23 [RFC/PATCH 0/3] ARM: Use udiv/sdiv for __aeabi_{u}idiv library functions Stephen Boyd
2015-11-21  1:23 ` [RFC/PATCH 1/3] scripts: Allow recordmcount to be used without tracing enabled Stephen Boyd
2015-11-21  1:23 ` [RFC/PATCH 2/3] recordmcount: Record locations of __aeabi_{u}idiv() calls on ARM Stephen Boyd
2015-11-21 10:13   ` Russell King - ARM Linux
2015-11-23 20:53     ` Stephen Boyd
2015-11-23 20:58       ` Steven Rostedt
2015-11-23 21:03       ` Russell King - ARM Linux
2015-11-23 21:16         ` Stephen Boyd
2015-11-23 21:33           ` Russell King - ARM Linux
2015-11-24  1:04             ` Stephen Boyd
2015-11-21  1:23 ` [RFC/PATCH 3/3] ARM: Replace calls to __aeabi_{u}idiv with udiv/sdiv instructions Stephen Boyd
2015-11-21 11:50   ` Måns Rullgård
2015-11-23 20:49     ` Stephen Boyd
2015-11-23 20:54       ` Måns Rullgård [this message]
2015-11-23 21:16         ` Stephen Boyd
2015-11-21 20:39 ` [RFC/PATCH 0/3] ARM: Use udiv/sdiv for __aeabi_{u}idiv library functions Arnd Bergmann
2015-11-21 20:45   ` Måns Rullgård
2015-11-21 21:00     ` Arnd Bergmann
2015-11-21 22:11       ` Måns Rullgård
2015-11-21 23:14         ` Arnd Bergmann
2015-11-21 23:21           ` Arnd Bergmann
2015-11-22 13:29             ` Peter Maydell
2015-11-22 19:25               ` Arnd Bergmann
2015-11-22 19:30                 ` Måns Rullgård
2015-11-22 19:47                 ` Russell King - ARM Linux
2015-11-22 19:58                   ` Arnd Bergmann
2015-11-22 20:03                     ` Russell King - ARM Linux
2015-11-22 20:37                       ` Arnd Bergmann
2015-11-22 20:39                         ` Måns Rullgård
2015-11-22 21:18                           ` Arnd Bergmann
2015-11-23  2:36                     ` Nicolas Pitre
2015-11-23  8:15                       ` Arnd Bergmann
2015-11-23 14:14                         ` Christopher Covington
2015-11-23 15:32                           ` Arnd Bergmann
2015-11-23 20:38                             ` Stephen Boyd
2015-11-23 21:19                               ` Arnd Bergmann
2015-11-23 21:32                                 ` Stephen Boyd
2015-11-23 21:57                                   ` Arnd Bergmann
2015-11-23 23:13                                     ` Stephen Boyd
2015-11-24 10:17                                       ` Arnd Bergmann
2015-11-24 12:15                                         ` Måns Rullgård
2015-11-24 13:45                                           ` Arnd Bergmann
2015-11-25  1:51                                         ` Stephen Boyd
2015-11-25  7:21                                           ` Arnd Bergmann
2015-11-24  0:13                                     ` Stephen Boyd
2015-11-24  8:53                                       ` Stephen Boyd
2015-11-24 10:38                                         ` Arnd Bergmann
2015-11-24 10:42                                           ` Russell King - ARM Linux
2015-11-24 12:10                                             ` Måns Rullgård
2015-11-24 12:23                                               ` Russell King - ARM Linux
2015-11-24 12:29                                                 ` Måns Rullgård
2015-11-24 14:00                                                   ` Russell King - ARM Linux
2015-11-24 14:03                                                     ` Måns Rullgård
2015-11-24 10:39                                         ` Russell King - ARM Linux
2015-11-24 20:07                                           ` Stephen Boyd
2015-11-24 20:35                                             ` Russell King - ARM Linux
2015-11-24 21:11                                               ` Arnd Bergmann
2016-01-13  1:51                                               ` Stephen Boyd
2015-11-24 10:37                                       ` Russell King - ARM Linux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1x1tbgsag7.fsf@unicorn.mansr.com \
    --to=mans@mansr.com \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nico@fluxnic.net \
    --cc=rostedt@goodmis.org \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®