神刀安全网

Some Dynamic Measurements of Firefox on X86-64

This follows up on myprevious measurements of static properties of Firefox code on x86-64 with some measurements of dynamic properties obtained by instrumenting code. These are mostly for my own amusement but intuitions about how programs behave at the machine level, grounded in data, have sometimes been unexpectedly useful.

Dynamic properties are highly workload-dependent. Media codecs are more SSE/AVX intensive than regular code so if you do nothing but watch videos you’d expect qualitatively different results than if you just load Web pages. I used a mixed workload that starts Firefox (multi-process enabled, optimized build), loads the NZ Herald , scrolls to the bottom, loads an article with a video, plays the video for several seconds, then quits. It ran for about 30 seconds under rr and executes about 60 billion instructions.

I repeated my register usage result analysis, this time weighted by dynamic execution count and taking into account implicit register usage such as push using rsp . The results differ significantly on whether you count the consecutive iterations of a repeated string instruction (e.g. rep movsb ) as a single instruction execution or one instruction execution per iteration, so I show both. Unlike the static graphs, these results for all instructions executed anywhere in the process(es), including JITted code, not just libxul.

Some Dynamic Measurements of Firefox on X86-64

  • As expected, registers involved in string instructions get a big boost when you count string instruction repetitions individually. About 7 billion of the 64 billion instruction executions "with string repetitions" are iterations of string instructions. (In practice Intel CPUs can optimize these to execute 64 iterations at a time, under favourable conditions.)
  • As expected, sp is very frequently used once you consider its implicit uses.
  • String instructions aside, the dynamic results don’t look very different from the static results. Registers R8 to R11 look a bit more used in this graph, which may be because they tend to be allocated in highly optimized leaf functions, which are more likely to be hot code.

Some Dynamic Measurements of Firefox on X86-64

  • The surprising thing about the results for SSE/AVX registers is that they still don’t look very different to the static results. Even the bottom 8 registers still aren’t frequently used compared to most general-purpose registers, even though I deliberately tried to exercise codec code.
  • I wonder why R5 is the least used bottom-8 register by a significant margin. Maybe these results are dominated by a few hot loops that by chance don’t use that register much.

I was also interested in exploring the distribution of instruction execution frequencies:

Some Dynamic Measurements of Firefox on X86-64

A dot at position x, y on this graph means that fraction y of all instructions executed at least once is executed at most x times. So, we can see that about 19% of all instructions executed are executed only once. About 42% of instructions are executed at most 10 times. About 85% of instructions are executed at most 1000 times. These results treat consecutive iterations of a string instruction as a single execution. (It’s hard to precisely define what it means for an instruction to "be the same" in the presence of dynamic loading and JITted code. I’m assuming that every execution of an instruction at a particular address in a particular address space is an execution of "the same instruction".)

Interestingly, the five most frequently executed instructions are executed about 160M times. Those instructions are for this line , which is simply filling a large buffer with 0xff000000. gcc is generating quite slow code:

132e7b2: cmp    %rax,%rdx 132e7b5: je     132e7d1            132e7b7: movl   $0xff000000,(%r9,%rax,4) 132e7bf: inc    %rax 132e7c2: jmp    132e7b2           

That’s five instructions executed for every four bytes written. This could be done a lot faster in a variety of different ways — rep stosd or rep stosq

would probably get the fast-string optimization, but SSE/AVX might be faster.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Some Dynamic Measurements of Firefox on X86-64

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址