Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Nicolas Pitre <nico@fluxnic.net>, Stephen Boyd <sboyd@codeaurora.org>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	"Michal Marek" <mmarek@suse.com>,
	linux-kbuild@vger.kernel.org, "Arnd Bergmann" <arnd@arndb.de>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Måns Rullgård" <mans@mansr.com>,
	"Thomas Petazzoni" <thomas.petazzoni@free-electrons.com>
Subject: Re: [PATCH v2 2/2] ARM: Replace calls to __aeabi_{u}idiv with udiv/sdiv instructions
Date: Thu, 26 Nov 2015 00:05:51 +0000	[thread overview]
Message-ID: <20151126000551.GU8644@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <alpine.LFD.2.20.1511251733570.22569@knanqh.ubzr>

On Wed, Nov 25, 2015 at 06:09:13PM -0500, Nicolas Pitre wrote:
> 3) In fact I was wondering if the overhead of the branch and back is 
>    really significant compared to the non trivial cost of a idiv 
>    instruction and all the complex infrastructure required to patch 
>    those branches directly, and consequently if the performance 
>    difference is actually worth it versus simply doing (2) alone.

I definitely agree with you on this, given that modern CPUs which
are going to be benefitting from idiv are modern CPUs with a branch
predictor (and if it's not predicting such unconditional calls and
returns it's not much use as a branch predictor!)

I think what we need to see is the performance of existing kernels,
vs patching the idiv instructions at every callsite, vs patching
the called function itself.

> > +#ifdef CONFIG_ARM_PATCH_UIDIV
> > +/* "sdiv r0, r0, r1" or "mrc p6, 1, r0, CR0, CR1, 4" if we're on pj4 w/o MP */
> > +static u32 __attribute_const__ sdiv_instruction(void)
> > +{
> > +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
> > +		if (cpu_is_pj4_nomp())
> > +			return __opcode_to_mem_thumb32(0xee300691);
> > +		return __opcode_to_mem_thumb32(0xfb90f0f1);
> > +	}
> > +
> > +	if (cpu_is_pj4_nomp())
> > +		return __opcode_to_mem_arm(0xee300691);
> > +	return __opcode_to_mem_arm(0xe710f110);
> > +}
> > +
> > +/* "udiv r0, r0, r1" or "mrc p6, 1, r0, CR0, CR1, 0" if we're on pj4 w/o MP */
> > +static u32 __attribute_const__ udiv_instruction(void)
> > +{
> > +	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
> > +		if (cpu_is_pj4_nomp())
> > +			return __opcode_to_mem_thumb32(0xee300611);
> > +		return __opcode_to_mem_thumb32(0xfbb0f0f1);
> > +	}
> > +
> > +	if (cpu_is_pj4_nomp())
> > +		return __opcode_to_mem_arm(0xee300611);
> > +	return __opcode_to_mem_arm(0xe730f110);
> > +}

Any reason the above aren't marked with __init_or_module as well, as
the compiler can choose not to inline them?

> > +
> > +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_udiv(void *addr, size_t size)
> > +{
> > +	patch(addr, size, udiv_instruction());
> > +}
> > +
> > +void __init_or_module patch_sdiv(void *addr, size_t size)
> > +{
> > +	return patch(addr, size, sdiv_instruction());
> > +}
> > +
> > +static void __init patch_aeabi_uidiv(void)
> > +{
> > +	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))
> > +		mask = HWCAP_IDIVT;
> > +	else
> > +		mask = HWCAP_IDIVA;
> > +
> > +	if (!(elf_hwcap & mask))
> > +		return;
> > +
> > +	patch_udiv(__start_udiv_loc, __stop_udiv_loc - __start_udiv_loc);
> > +	patch_sdiv(__start_idiv_loc, __stop_idiv_loc - __start_idiv_loc);

I'm left really concerned about this.  We're modifying code with all
the caches on, and the above is not only missing any coherency of the
I/D paths, it's also missing any branch predictor maintanence.  So, if
we've executed any divisions at this point, the predictor could already
predicted one of these branches that's being modified.

-- 
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

  reply	other threads:[~2015-11-26  0:05 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 21:51 [PATCH v2 0/2] ARM: Use udiv/sdiv for __aeabi_{u}idiv library functions Stephen Boyd
2015-11-25 21:51 ` [PATCH v2 1/2] scripts: Add a recorduidiv program Stephen Boyd
2015-11-25 23:47   ` Russell King - ARM Linux
2015-11-30 15:11     ` Michal Marek
2015-11-30 15:32       ` Russell King - ARM Linux
2015-11-30 15:40         ` Michal Marek
2015-12-01 16:07           ` Michal Marek
2015-12-01 16:19             ` Russell King - ARM Linux
2015-12-01 16:43               ` Michal Marek
2015-12-01 16:49               ` Steven Rostedt
2015-12-01 17:10                 ` Russell King - ARM Linux
2015-12-01 17:22                   ` Steven Rostedt
2015-12-01 18:16                     ` Russell King - ARM Linux
2015-12-01 21:39                       ` Michal Marek
2015-12-02 10:23                       ` Russell King - ARM Linux
2015-12-02 14:05                         ` Steven Rostedt
2015-12-11 12:09                           ` [PATCH] scripts: recordmcount: break hardlinks Russell King
2015-12-11 14:31                             ` Steven Rostedt
2015-12-11 14:45                               ` Russell King - ARM Linux
2015-12-11 15:08                                 ` Steven Rostedt
2015-12-11 18:10                                 ` Steven Rostedt
2015-12-11 18:33                                   ` Russell King - ARM Linux
2015-12-11 18:51                                     ` Steven Rostedt
2015-12-11 18:58                                       ` Russell King - ARM Linux
2015-12-11 19:28                                         ` Steven Rostedt
2015-11-25 21:51 ` [PATCH v2 2/2] ARM: Replace calls to __aeabi_{u}idiv with udiv/sdiv instructions Stephen Boyd
2015-11-25 23:09   ` Nicolas Pitre
2015-11-26  0:05     ` Russell King - ARM Linux [this message]
2015-11-26  0:07     ` Måns Rullgård
2015-11-26  0:44       ` Nicolas Pitre
2015-11-26  0:50         ` Måns Rullgård
2015-11-26  1:28           ` Russell King - ARM Linux
2015-11-26  2:19             ` Måns Rullgård
2015-11-26  5:32               ` Nicolas Pitre
2015-11-26 12:41                 ` Måns Rullgård
2015-11-26  0:08   ` 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=20151126000551.GU8644@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mans@mansr.com \
    --cc=mmarek@suse.com \
    --cc=nico@fluxnic.net \
    --cc=rostedt@goodmis.org \
    --cc=sboyd@codeaurora.org \
    --cc=thomas.petazzoni@free-electrons.com \
    /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