Detecting instruction emulation with the emstat tool
To maintain compatibility with older binaries, the AIX kernel includes emulation routines that provide support for instructions that might not be included in a particular chip architecture. Attempting to execute a non-supported instruction results in an illegal instruction exception. The kernel decodes the illegal instruction, and if it is a non-supported instruction, the kernel runs an emulation routine that functionally emulates the instruction.
Depending upon the execution frequency of non-supported instructions and the their emulation path lengths, emulation can result in varying degrees of performance degradation due to kernel context switch and instruction emulation overhead. Even a very small percentage of emulation might result in a big performance difference. The following table shows estimated instruction path lengths for several of the non-supported instructions:
Instruction | Emulated in | Estimated Path Length (instructions) |
---|---|---|
abs | assembler | 117 |
doz | assembler | 120 |
mul | assembler | 127 |
rlmi | C | 425 |
sle | C | 447 |
clf | C | 542 |
div | C | 1079 |
Instructions that are not common on all platforms must be removed from code written in assembler, because recompilation is only effective for high-level source code. Routines coded in assembler must be changed so that they do not use missing instructions, because recompilation has no effect in this case.
The first step is to determine if instruction emulation is occurring by using the emstat tool.
# lslpp -lI bos.perf.tools
The emstat command works similarly to the vmstat command in that you specify an interval time in seconds, and optionally, the number of intervals. The value in the first column is the cumulative count since system boot, while the value in the second column is the number of instructions emulated during that interval. Emulations on the order of many thousands per second can have an impact on performance.
# emstat 1
Emulation Emulation
SinceBoot Delta
0 0
0 0
0 0
Once emulation has been detected, the next step is to determine which application is emulating instructions. This is much harder to determine. One way is to run only one application at a time and monitor it with the emstat program. Sometimes certain emulations cause a trace hook to be encountered. This can be viewed in the ASCII trace report file with the words PROGRAM CHECK. The process/thread associated with this trace event is emulating instructions either due to its own code emulating instructions, or it is executing library or code in other modules that are emulating instructions.