From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Andi Kleen <ak@muc.de>, "H. Peter Anvin" <hpa@zytor.com>,
Chuck Ebbert <cebbert@redhat.com>,
Christoph Hellwig <hch@infradead.org>
Subject: Re: [patch 4/7] Immediate Values - i386 Optimization
Date: Fri, 21 Sep 2007 09:31:07 -0400 [thread overview]
Message-ID: <20070921133107.GB13129@Krystal> (raw)
In-Reply-To: <200709201124.13097.vda.linux@googlemail.com>
* Denys Vlasenko (vda.linux@googlemail.com) wrote:
> On Tuesday 18 September 2007 22:07, Mathieu Desnoyers wrote:
> > i386 optimization of the immediate values which uses a movl with code patching
> > to set/unset the value used to populate the register used as variable source.
> >
> > Changelog:
> > - Use text_poke_early with cr0 WP save/restore to patch the bypass. We are doing
> > non atomic writes to a code region only touched by us (nobody can execute it
> > since we are protected by the immediate_mutex).
> > - Put immediate_set and _immediate_set in the architecture independent header.
>
> > +struct __immediate {
> > + long var; /* Pointer to the identifier variable of the
> > + * immediate value
> > + */
> > + long immediate; /*
> > + * Pointer to the memory location of the
> > + * immediate value within the instruction.
> > + */
> > + long size; /* Type size. */
> > +};
>
>
> > + case 2: \
> > + asm ( ".section __immediate, \"a\", @progbits;\n\t" \
> > + ".long %1, (0f)+2, 2;\n\t" \
> > + ".previous;\n\t" \
> > + "1:\n\t" \
> > + ".align 2;\n\t" \
> > + "0:\n\t" \
> > + "mov %2,%0;\n\t" \
> > + : "=r" (value) \
> > + : "m" (name##__immediate), \
> > + "i" (0)); \
>
> Instead of letting gcc use whatever instruction it sees fit best
> for accessing the variable (like add/cmp/test...)
> now we force it to use mov imm,reg first. Maybe with preceding nop
> due to "align 2".
>
Yes, this is true. So, the following branch:
char x;
void testb(void)
{
if (x > 5)
testa();
}
Would turn into:
56: b0 00 mov $0x0,%al
58: 3c 05 cmp $0x5,%al
5a: 7e 05 jle 61 <testb+0x11>
Rather than:
56: 80 3d 00 00 00 00 05 cmpb $0x5,0x0
5d: 7e 05 jle 64 <testb+0x14>
> And then we use 12 more bytes in __immediate section
> *for each* place where you read the variable.
>
Yes. You must consider the this section is only used when updating the
variable. It is never used by the read-side and therefore does not
consume data cache on hot paths.
> Do you plan to use the same approach on x86_64?
> I mean, longs there are twice as long.
>
Yup. It's a memory footprint vs active cacheline footprints tradeoff.
When GCC optimizes for size and we see kernel speedups, it is not so
because it "consumes" less memory, but rather that there is less junk
polluting the cachelines. So unless you worry about a few K of data and
are an embedded system developer, I really don't see why you worry about
this. Oh, and by the way, I provide the ability to disable immediate
values in the EMBEDDED menu.
> Can this be made conditional, on CONFIG_CC_OPTIMIZE_FOR_SIZE perhaps?
No. As I just stated, only embedded developers would have an interest in
disabling this features because they would have so few memory available
on their architecture. The memory consumed by the immediate values table
is out of the hot path cachelines and therefore does not impact overall
performance.
> --
> vda
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2007-09-21 13:31 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-18 21:07 [patch 0/7] Immediate Values for 2.6.23-rc6-mm1 Mathieu Desnoyers
2007-09-18 21:07 ` [patch 1/7] Immediate Values - Architecture Independent Code Mathieu Desnoyers
2007-09-18 21:07 ` [patch 2/7] Immediate Values - Kconfig menu in EMBEDDED Mathieu Desnoyers
2007-09-18 22:02 ` Randy Dunlap
2007-09-19 11:13 ` Mathieu Desnoyers
2007-09-18 21:07 ` [patch 3/7] Immediate Values - Move Kprobes i386 restore_interrupt to kdebug.h Mathieu Desnoyers
2007-09-18 21:07 ` [patch 4/7] Immediate Values - i386 Optimization Mathieu Desnoyers
2007-09-18 21:51 ` Jeremy Fitzhardinge
2007-09-18 22:12 ` H. Peter Anvin
2007-09-18 22:27 ` Jeremy Fitzhardinge
2007-09-19 13:01 ` Mathieu Desnoyers
2007-09-19 16:03 ` Mathieu Desnoyers
2007-09-19 16:12 ` H. Peter Anvin
2007-09-19 17:30 ` Jeremy Fitzhardinge
2007-09-19 17:39 ` H. Peter Anvin
2007-09-19 18:31 ` Mathieu Desnoyers
2007-09-19 18:22 ` Mathieu Desnoyers
2007-10-20 16:47 ` Mathieu Desnoyers
2007-10-20 18:32 ` H. Peter Anvin
2007-10-22 15:40 ` Mathieu Desnoyers
2007-10-22 16:39 ` H. Peter Anvin
2007-10-22 9:53 ` Andi Kleen
2007-09-19 11:00 ` Mathieu Desnoyers
2007-09-18 22:14 ` Andi Kleen
2007-09-18 22:29 ` Jeremy Fitzhardinge
2007-09-18 22:33 ` H. Peter Anvin
2007-09-18 22:44 ` Andi Kleen
2007-09-19 11:08 ` Mathieu Desnoyers
2007-09-19 11:14 ` Andi Kleen
2007-09-19 10:59 ` Mathieu Desnoyers
2007-09-20 10:24 ` Denys Vlasenko
2007-09-21 13:31 ` Mathieu Desnoyers [this message]
2007-09-18 21:07 ` [patch 5/7] Immediate Values - Powerpc Optimization Mathieu Desnoyers
2007-09-18 21:07 ` [patch 6/7] Immediate Values - Documentation Mathieu Desnoyers
2007-09-18 21:07 ` [patch 7/7] Scheduler Profiling - Use Immediate Values Mathieu Desnoyers
-- strict thread matches above, loose matches on Subject: below --
2007-09-17 18:42 [patch 0/7] " Mathieu Desnoyers
2007-09-17 18:42 ` [patch 4/7] Immediate Values - i386 Optimization Mathieu Desnoyers
2007-09-18 6:04 ` Borislav Petkov
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=20070921133107.GB13129@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=ak@muc.de \
--cc=akpm@linux-foundation.org \
--cc=cebbert@redhat.com \
--cc=hch@infradead.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=vda.linux@googlemail.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