unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Konstantin Kharlamov <hi-angel@yandex.ru>
To: Alex Gramiak <agrambot@gmail.com>
Cc: Paul Eggert <eggert@cs.ucla.edu>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel@gnu.org
Subject: Re: Using __builtin_expect (likely/unlikely macros)
Date: Wed, 17 Apr 2019 00:27:50 +0300	[thread overview]
Message-ID: <1555450070.23658.4@yandex.ru> (raw)
In-Reply-To: <87sguhbrof.fsf@gmail.com>

FWIW I was in a similar search not so long ago, and I was told that 
e.g. "cold" attribute can sometimes produce unbearably slow code 
https://gcc.gnu.org/ml/gcc-help/2019-01/msg00035.html

В Вт, апр 16, 2019 at 14:50, Alex Gramiak <agrambot@gmail.com> 
написал:
> Paul Eggert <eggert@cs.ucla.edu> writes:
> 
>>  That being said, it might make sense for a few 
>> obviously-rarely-called
>>  functions like 'emacs-abort' to be marked with __attribute__ 
>> ((cold)),
>>  so long as we don't turn this into a mission to mark all cold 
>> functions
>>  (which would cost us more than it would benefit). That is what GCC
>>  itself does, with its own functions. However, I'd like to see
>>  performance figures. Could you try it out on the benchmark of 'cd 
>> lisp
>>  && time make compile-always'?
> 
> Right, I agree that if used, they should be used sparingly. I tested
> three versions a few times each with both 'make' and 'make -j4':
> 
> a) Regular Emacs master.
> b) The below diff with only the _Cold attribute
> c) The below diff with both _Cold and _Hot attributes
> 
> a) Normal
> real    4:17.97s
> user    3:57.18s
> sys     20.394s
> 
> real    1:17.67s
> user    4:23.78s
> sys     18.888s
> 
> b) Cold
> real    4:10.92s
> user    3:50.34s
> sys     20.178s
> 
> real    1:15.77s
> user    4:16.73s
> sys     18.943s
> 
> c) Hot/Cold
> real    4:11.43s
> user    3:51.07s
> sys     19.961s
> 
> real    1:16.01s
> user    4:17.63s
> sys     18.662s
> 
> So not much of a difference. For some reason the Hot/Cold performed
> consistently worse than Cold.
> 
> I also tested startup/shutdown with perf:
> 
>  Performance counter stats for '../emacs-normal -f kill-emacs' (20 
> runs):
> 
>             762.17 msec task-clock:u              #    0.844 CPUs 
> utilized            ( +-  0.23% )
>                  0      context-switches:u        #    0.000 K/sec
>                  0      cpu-migrations:u          #    0.000 K/sec
>             12,941      page-faults:u             #    0.017 M/sec    
>                 ( +-  0.01% )
>      2,998,322,125      cycles:u                  #    3.934 GHz      
>                 ( +-  0.06% )
>      1,392,869,413      stalled-cycles-frontend:u #   46.45% frontend 
> cycles idle     ( +-  0.15% )
>        982,206,843      stalled-cycles-backend:u  #   32.76% backend 
> cycles idle      ( +-  0.18% )
>      4,874,186,825      instructions:u            #    1.63  insn per 
> cycle
>                                                   #    0.29  stalled 
> cycles per insn  ( +-  0.01% )
>      1,037,929,374      branches:u                # 1361.802 M/sec    
>                 ( +-  0.01% )
>         17,930,471      branch-misses:u           #    1.73% of all 
> branches          ( +-  0.16% )
>      1,209,539,215      L1-dcache-loads:u         # 1586.960 M/sec    
>                 ( +-  0.01% )
>         42,346,229      L1-dcache-load-misses:u   #    3.50% of all 
> L1-dcache hits    ( +-  0.05% )
>          9,088,647      LLC-loads:u               #   11.925 M/sec    
>                 ( +-  0.29% )
>    <not supported>      LLC-load-misses:u
> 
>            0.90325 +- 0.00441 seconds time elapsed  ( +-  0.49% )
> 
> 
> 
>  Performance counter stats for '../emacs.cold -f kill-emacs' (20 
> runs):
> 
>             755.94 msec task-clock:u              #    0.845 CPUs 
> utilized            ( +-  0.24% )
>                  0      context-switches:u        #    0.000 K/sec
>                  0      cpu-migrations:u          #    0.000 K/sec
>             12,941      page-faults:u             #    0.017 M/sec    
>                 ( +-  0.01% )
>      2,976,036,365      cycles:u                  #    3.937 GHz      
>                 ( +-  0.06% )
>      1,374,451,779      stalled-cycles-frontend:u #   46.18% frontend 
> cycles idle     ( +-  0.14% )
>        990,227,732      stalled-cycles-backend:u  #   33.27% backend 
> cycles idle      ( +-  0.18% )
>      4,878,661,927      instructions:u            #    1.64  insn per 
> cycle
>                                                   #    0.28  stalled 
> cycles per insn  ( +-  0.00% )
>      1,038,495,525      branches:u                # 1373.782 M/sec    
>                 ( +-  0.00% )
>         17,859,906      branch-misses:u           #    1.72% of all 
> branches          ( +-  0.16% )
>      1,209,345,531      L1-dcache-loads:u         # 1599.792 M/sec    
>                 ( +-  0.00% )
>         42,444,358      L1-dcache-load-misses:u   #    3.51% of all 
> L1-dcache hits    ( +-  0.06% )
>          9,204,368      LLC-loads:u               #   12.176 M/sec    
>                 ( +-  0.41% )
>    <not supported>      LLC-load-misses:u
> 
>            0.89430 +- 0.00217 seconds time elapsed  ( +-  0.24% )
> 
> 
>  Performance counter stats for '../emacs.hot-cold -f kill-emacs' (20 
> runs):
> 
>             761.97 msec task-clock:u              #    0.845 CPUs 
> utilized            ( +-  0.20% )
>                  0      context-switches:u        #    0.000 K/sec
>                  0      cpu-migrations:u          #    0.000 K/sec
>             12,947      page-faults:u             #    0.017 M/sec    
>                 ( +-  0.01% )
>      2,989,750,359      cycles:u                  #    3.924 GHz      
>                 ( +-  0.04% )
>      1,383,312,275      stalled-cycles-frontend:u #   46.27% frontend 
> cycles idle     ( +-  0.12% )
>        994,643,853      stalled-cycles-backend:u  #   33.27% backend 
> cycles idle      ( +-  0.13% )
>      4,879,318,990      instructions:u            #    1.63  insn per 
> cycle
>                                                   #    0.28  stalled 
> cycles per insn  ( +-  0.00% )
>      1,038,584,045      branches:u                # 1363.022 M/sec    
>                 ( +-  0.00% )
>         17,863,736      branch-misses:u           #    1.72% of all 
> branches          ( +-  0.13% )
>      1,209,327,347      L1-dcache-loads:u         # 1587.103 M/sec    
>                 ( +-  0.00% )
>         42,501,374      L1-dcache-load-misses:u   #    3.51% of all 
> L1-dcache hits    ( +-  0.05% )
>          9,201,311      LLC-loads:u               #   12.076 M/sec    
>                 ( +-  0.28% )
>    <not supported>      LLC-load-misses:u
> 
>            0.90132 +- 0.00201 seconds time elapsed  ( +-  0.22% )
> 
> 
> Which again shows a slight improvement with the Cold attributes, and
> still shows the hot attributes degrading performance. Perhaps I was 
> too
> overzealous with the hot tagging?
> 





  parent reply	other threads:[~2019-04-16 21:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15  0:15 Using __builtin_expect (likely/unlikely macros) Alex Gramiak
2019-04-15  1:18 ` Paul Eggert
2019-04-15  3:11   ` Alex Gramiak
2019-04-15  4:41     ` Paul Eggert
2019-04-16  0:16       ` Alex Gramiak
2019-04-16  2:34         ` Eli Zaretskii
2019-04-16  5:33           ` Alex Gramiak
2019-04-16 15:23             ` Eli Zaretskii
2019-04-16 15:47               ` Alex Gramiak
2019-04-16  3:42         ` Paul Eggert
2019-04-16 13:05           ` Stefan Monnier
2019-04-16 15:22             ` Paul Eggert
2019-04-16 16:10               ` Alex Gramiak
2019-04-16 17:54                 ` Paul Eggert
2019-04-16 20:50                   ` Alex Gramiak
2019-04-16 21:11                     ` Alex Gramiak
2019-04-16 21:27                     ` Stefan Monnier
2019-04-16 21:27                     ` Konstantin Kharlamov [this message]
2019-04-18  8:25                       ` Paul Eggert
2019-04-18  8:43                         ` Konstantin Kharlamov
2019-04-18 13:47                         ` Andy Moreton
2019-04-18 17:27                           ` Paul Eggert
2019-04-18 17:56                             ` Andy Moreton
2019-04-18 19:32                               ` Paul Eggert
2019-04-19 13:45                         ` Alex Gramiak
2019-04-19 13:58                           ` Konstantin Kharlamov
2019-04-19 14:45                             ` Alex Gramiak
2019-04-19 17:33                           ` Paul Eggert
2019-04-19 20:53                             ` Alex Gramiak
2019-04-20  0:05                               ` Alan Mackenzie
2019-04-20  0:42                                 ` Paul Eggert
2019-04-20 19:46                                   ` Alan Mackenzie
2019-04-20 15:29                             ` Andy Moreton
2019-04-20 15:57                               ` Paul Eggert
2019-04-20 16:03                                 ` Eli Zaretskii
2019-04-20 16:11                                   ` Paul Eggert
2019-04-20 16:18                                     ` Eli Zaretskii
2019-04-20 16:57                                       ` Paul Eggert
2019-04-20 17:22                                         ` Eli Zaretskii
2019-04-20 19:13                                           ` Paul Eggert
2019-04-20 16:28                                 ` Óscar Fuentes
2019-04-20 18:58                                   ` Paul Eggert
2019-04-20 19:35                                     ` Óscar Fuentes
2019-04-20 22:54                                       ` Paul Eggert
2020-04-15  3:14   ` John Carter

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=1555450070.23658.4@yandex.ru \
    --to=hi-angel@yandex.ru \
    --cc=agrambot@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).