From: Maarten Lankhorst <maarten.lankhorst-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
To: Patrick Baggett
<baggett.patrick-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Emil Velikov
<emil.l.velikov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
ML nouveau
<nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
Maarten Lankhorst
<maarten.lankhorst-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH 2/2] nouveau: Do not add most bo's to the global bo list.
Date: Wed, 25 Feb 2015 18:55:20 +0100 [thread overview]
Message-ID: <54EE0C88.4010509@canonical.com> (raw)
In-Reply-To: <CAEk2St=0LWc-E-O-2DOHWvDtQYJiRe=+7yz7UaGy2KWNTCsbmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
On 25-02-15 18:26, Patrick Baggett wrote:
>>
>>
>> In general things don't get optimized across function calls, except in
>> case of inlinable functions.
>>
>> And for compiler attributes it's the opposite,__attribute__((const)) and
>> __attribute((pure)) can be used to indicate some kind of safety to optimize
>> across functions.
>>
>> https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
>>
>> This is true, but LTO increases the compiler's ability to make these sorts
> of optimizations across function calls and even C source file boundaries
> without you needing to explicitly mark functions as such.
Even if pthread_mutex_lock was completely inlined there would still be a asm volatile(("" ::: "memory")) in there acting as a complete memory barrier to the compiler.
Create a function called dummy.c, abusing the fact that gcc can't handle pointers well so it won't get reduced to a constant return value:
int x;
int *px = &x;
int main() {
if (*px == 1)
return 1;
asm volatile("" ::: "memory");
if (*px == 1)
return 1;
return -1;
}
Now compile with gcc test.c -O3 -fwhole-program, and run objdump -d a.out:
400400: 83 3d 49 0c 20 00 01 cmpl $0x1,0x200c49(%rip) # 601050 <x>
400407: 74 09 je 400412 <main+0x12>
400409: 83 3d 40 0c 20 00 01 cmpl $0x1,0x200c40(%rip) # 601050 <x>
400410: 75 06 jne 400418 <main+0x18>
400412: b8 01 00 00 00 mov $0x1,%eax
400417: c3 retq
400418: 83 c8 ff or $0xffffffff,%eax
40041b: c3 retq
Hey my second check didn't get compiled away.. magic.
And to show that a random function call does the same, replace the barrier with random():
0000000000400440 <main>:
400440: 83 3d 09 0c 20 00 01 cmpl $0x1,0x200c09(%rip) # 601050 <x>
400447: 74 1b je 400464 <main+0x24>
400449: 50 push %rax
40044a: 31 c0 xor %eax,%eax
40044c: e8 df ff ff ff callq 400430 <random@plt>
400451: 83 3d f8 0b 20 00 01 cmpl $0x1,0x200bf8(%rip) # 601050 <x>
400458: b8 01 00 00 00 mov $0x1,%eax
40045d: 75 0b jne 40046a <main+0x2a>
40045f: 48 83 c4 08 add $0x8,%rsp
400463: c3 retq
400464: b8 01 00 00 00 mov $0x1,%eax
400469: c3 retq
40046a: 83 c8 ff or $0xffffffff,%eax
40046d: eb f0 jmp 40045f <main+0x1f>
And just to be thorough, showing what happens without function call or barrier:
0000000000400400 <main>:
400400: 8b 05 4a 0c 20 00 mov 0x200c4a(%rip),%eax # 601050 <x>
400406: ba ff ff ff ff mov $0xffffffff,%edx
40040b: 83 f8 01 cmp $0x1,%eax
40040e: 0f 45 c2 cmovne %edx,%eax
400411: c3 retq
~Maarten
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau
next prev parent reply other threads:[~2015-02-25 17:55 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-24 9:01 [PATCH 1/2] nouveau: make nouveau importing global buffers completely thread-safe, with tests Maarten Lankhorst
[not found] ` <1424768511-25156-1-git-send-email-maarten.lankhorst-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-02-24 9:01 ` [PATCH 2/2] nouveau: Do not add most bo's to the global bo list Maarten Lankhorst
[not found] ` <1424768511-25156-2-git-send-email-maarten.lankhorst-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-02-25 14:11 ` Emil Velikov
[not found] ` <CACvgo53DRfa9JkweCRVB9va7oD5RoKVM9KFkXk99rQwO=vxi0g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 14:59 ` Maarten Lankhorst
[not found] ` <54EDE354.6030700-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-02-25 15:04 ` Patrick Baggett
[not found] ` <CAEk2Stmr7k+Tq_JH+9iuo8iz+NouhJ8tG3RaX9vJA-FHzewBAw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 15:07 ` Maarten Lankhorst
[not found] ` <54EDE51B.1070000-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-02-25 15:28 ` Patrick Baggett
[not found] ` <CAEk2Stk1x86MM0x6FLFutgBGC+0ksG+VKFLoEH=z+zLGKvYyRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 15:43 ` Maarten Lankhorst
[not found] ` <54EDED9B.3000303-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
2015-02-25 16:14 ` Emil Velikov
2015-02-25 16:28 ` Patrick Baggett
[not found] ` <CAEk2StmOwhMecfkNsVj7j3PbmnazNQ7CAPMs-VNvv-QtrSEmCQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 16:35 ` Ilia Mirkin
[not found] ` <CAKb7UvhinRCVezUKwVpJR2V4hwTs+8mgQZBvEtHE0MVp7PYc9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 16:59 ` Patrick Baggett
[not found] ` <CAEk2St=hxYL7QTnC=7=EnAyD8Bw4KJER4Dd+9pYKYckM5m+4Jg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 17:05 ` Ilia Mirkin
[not found] ` <CAKb7UvgnB-Tvy1EFF-8ERfOFUBGCzBbPjL0Yv1TZAWRm1Be0wg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 17:13 ` Maarten Lankhorst
[not found] ` <54EE02A8.2040004-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-02-25 17:26 ` Patrick Baggett
[not found] ` <CAEk2St=0LWc-E-O-2DOHWvDtQYJiRe=+7yz7UaGy2KWNTCsbmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 17:55 ` Maarten Lankhorst [this message]
[not found] ` <54EE0C88.4010509-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-02-25 19:04 ` Patrick Baggett
2015-02-25 14:14 ` [PATCH 1/2] nouveau: make nouveau importing global buffers completely thread-safe, with tests Emil Velikov
[not found] ` <CACvgo529aHY=pbBUqjvw4ecGE_Y3VD0M=p47MdZkuPdM-UYT6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-02-25 21:59 ` Maarten Lankhorst
[not found] ` <54EE45D6.9030604-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-02-26 9:52 ` Emil Velikov
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=54EE0C88.4010509@canonical.com \
--to=maarten.lankhorst-z7wlfzj8ewms+fvcfc7uqw@public.gmane.org \
--cc=baggett.patrick-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=emil.l.velikov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=maarten.lankhorst-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org \
--cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.