Column: Embedded design
Compiler options and their impact on the performance of userspace applications
#include <math.h> #include <lttng/tracef.h>
int main(int argc, char *argv[]) {
int x;
float sample_freq = 1000; float freq = 100; float sample; float t;
Mohammed Billoo, founder of MAB Labs, charts his experiences with the new Linux support by Percepio’s Tracealyzer v4.4 tool through real-world projects
W
e previously discussed how to use LTTng to instrument userspace applications
and view the trace data in Tracealyzer for evaluation purposes. Tis tool can come in handy when evaluating the performance of multiple candidate implementations of a particular feature. Today we’ll visit the way the combination of LTTng and Tracealyzer can highlight compiler options impact performance – traditionally a relatively difficult task. We will see how floating-point compiler options affect the performance of even the most innocuous calculations – a sine function – leading to more complicated calculations. Tis is the snippet of code as the basis for the experiment:
08 June 2021
www.electronicsworld.co.uk
for (t = 0; t < 1000; t++) {
sample = sin((2*M_ PI*freq*t)/sample_freq); tracef(“%f”, sample); } return 0; }
Here we are calculating 1000 points of a sine wave at 100Hz, sampled at 1kHz. Te following is the Makefile used to build the code snippet:
.PHONY: all all: hello
sine_test: sine_test.o ${CC} -o sine_test sine_test.o
-llttng-ust -ldl -lm sine_test.o: sine_test.c
${CC} -c sine_test.c
We begin an LTTng session, execute the compiled binary on the command line, and terminate the session (discussed in a previous article). We then transfer the trace to the PC; open it in Tracealyze and configure the User Event interpretation; there is the user event signal plot as shown in Figure 1. However, there appears a discontinuity in the sine wave. If add a printf call to the
Capturing another trace and opening it in Tracealyzer, a different graph shows; see Figure 4. While there is still discontinuity in the
resulting waveform, we can see that the time gap has been reduced significantly (recall that the time between two points on this graph is a real-time value).
Compile options Let’s discuss the compile options added in the Makefile in the context of floating- point operations and why there was an impact on performance. Remember, the
Capturing another trace, we see the graph in Figure 3. Again, there’s the discontinuity. Let’s
update the Makefile to add another compiler option:
.PHONY: all all: hello
sine_test: sine_test.o ${CC} -o sine_test sine_test.o -llttng-ust -ldl -lm
sine_test.o: sine_test.c -mfloat-abi=hard -mfpu=neon
code snippet that prints each sample to a file, and then graph the contents of the file, we see the image in Figure 2. Figure 3, however, shows there’s
a regular sine wave without any discontinuity. Te reason is that when printing the values to a file there is no concept of time. We’re simply outputting the calculated values against the sample count. However, when outputting the calculated values to a trace file, the system time is included with each trace value. We then update the Makefile to add a
compiler option, and see the following result:
.PHONY: all all: hello
sine_test: sine_test.o ${CC} -o sine_test sine_test.o -llttng-ust -ldl -lm sine_test.o: sine_test.c -mfloat-abi=hard
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46