Root/atben/misc/atben-spi-performance.txt

1Performance analysis of SPI drivers for ATBEN
2=============================================
3
4This was originally posted on April 10 2013 to the linux-zigbee and
5the qi-hardware list. The URLs have been updated for stability.
6
7Note that the code referenced in this analysis is meant to illustrate
8the general concepts. Some variants have been dropped since and the
9ones still in existence have been cleaned up and debugged in
10preparation for upstream submission. The current versions can be
11found in https://github.com/wpwrak/ben-wpan-linux
12
13
14What this is all about
15----------------------
16
17The ATBEN board on the Ben NanoNote needs a bit-banging SPI driver.
18There are several ways to implement this, ranging from reuse of the
19generic spi-gpio driver to an optimized driver that's specific for
20this platform.
21
22I implemented several such approaches and measured their performance
23in the Ben NanoNote. Below are my findings.
24
25Comments welcome.
26
27
28Cast and characters
29-------------------
30
31spi_atben_gpio: NanoNote-specific framework for setting up the
32AT86RF230/1 with SPI-GPIO or one of the optimized drivers (below).
33The name derives from spi_atben (see below) and should be changed
34(maybe to atben_spi or atben_spi_gpio ?) since it is not an SPI
35driver but merely a framework that provides configuration data and
36performs miscellaneous platform setup.
37https://github.com/wpwrak/ben-wpan-linux/blob/perfcomp/drivers/net/ieee802154/spi_atben_gpio.c
38
39spi_atben: like spi_atben_gpio, but contains a highly optimized
40SPI driver for the ATBEN configuration in the Ben NanoNote.
41https://github.com/wpwrak/ben-wpan-linux/blob/perfcomp/drivers/net/ieee802154/spi_atben.c
42
43spi-jz4740-gpio: SPI-GPIO driver optimized for the Jz4740. Uses the
44optimized register accesses from spi_atben but pin assignment is not
45restricted to ATBEN. The only limitation is that MOSI, MISO, and
46SCLK must be on the same port.
47https://github.com/wpwrak/ben-wpan-linux/blob/perfcomp/drivers/spi/spi-jz4740-gpio.c
48
49spi-gpio-atben: task-specific SPI-GPIO driver using the #include
50"spi-gpio.c" method. Replaces gpiolib functions with register
51accesses specific to the ATBEN configuration in the Ben NanoNote.
52Note that some of the code could be moved into Jz4740
53architecture-specific GPIO support.
54https://github.com/wpwrak/ben-wpan-linux/blob/perfcomp/drivers/spi/spi-gpio-atben.c
55
56In the following sections, we abbreviate the stack configurations
57as follows:
58
59Abbreviation Framework Transport Chip driver
60--------------- --------------- --------------- -----------
61spi-gpio spi_atben_gpio spi-gpio at86rf230
62spi-gpio-atben spi_atben_gpio spi-gpio-atben at86rf230
63spi-jz4740-gpio spi_atben_gpio spi-jz4740-gpio at86rf230
64spi_atben spi_atben at86rf230
65
66
67Measurements
68------------
69
70Access time to AT86RF231 registers and buffer, in microseconds, on
71an otherwise idle Ben NanoNote:
72
73Driver read from 0x51 read 120 bytes from buffer
74| | write 0x0a to 0x15 write 1 byte to buffer (0x33)
75| | | read 1 byte from buffer write 120 bytes
76| | | | | | |
77spi-gpio 81 85 186 1696 97 1596
78spi-gpio-atben 63 59 123 498 65 437
79spi-jz4740-gpio 10 8 21 280 10 231
80spi_atben 10 7 21 280 10 230
81
82Data rate for hypothetical buffer accesses of infinite length.
83I.e., kbps = 1000*119*8/(t_write120-t_write1)
84
85Driver buffer read (kbps) buffer write (kbps)
86--------------- ----------------------- -------------------
87spi-gpio 630 635
88spi-gpio-atben 2549 2559
89spi-jz4740-gpio 3676 4308
90spi_atben 3676 4327
91
92At the air interface, IEEE 802.15.4 has a data rate of 250 kbps.
93The AT86RF231 transceiver also supports non-standard higher data
94rates up to 2 Mbps.
95
96Driver(s) Code size (lines)
97--------------------------------------- -----------------
98spi_atben_gpio 128
99spi_atben_gpio + spi-gpio-atben 128+ 53
100spi_atben_gpio + spi-jz4740-gpio 128+416
101spi_atben 423
102
103
104Computational cost
105------------------
106
107The high-level operations of sending and receiving produce the
108following major low-level operations:
109
110Operation register buffer waitqueue
111        read write read write
112--------------- ------- ------- ------- ------- ---------
113reception 1 - 1 - 1
114transmission 9 4 - 1 1
115
116Using the measured data from above, we get the following total
117computational overhead in microseconds, without considering the
118waitqueue scheduling delay:
119
120Driver reception transmission
121        1 120 127 1 120 125 (bytes)
122--------------- ------- ------- ------- ------- ------- -------
123spi-gpio 267 1777 1866 1166 2665 2727
124spi-gpio-atben 186 561 583 868 1240 1256
125spi-jz4740-gpio 31 290 304 132 353 362
126
127Note that the minimum frame length in IEEE 802.15.4 is 5 bytes.
128The values for 125 (excluding CRC) and 127 (including CRC) bytes
129are extrapolated.
130
131According to [1], maximum-sized frames can be sent/received,
132including CSMA/CA and acknowledgement, at a rate between one
133every 4928 us and one every 7168 us.
134
135We would therefore get the following maximum CPU load:
136
137Driver Reception Transmission
138--------------- --------------- ------------
139spi-gpio 38% 55%
140spi-gpio-atben 12% 25%
141spi-jz4740-gpio 6% 7%
142
143
144Observations
145------------
146
147spi-gpio needs the smallest amount of new code but is also very
148inefficient, making it questionable whether this configuration
149would yield acceptable performance in regular use.
150
151With spi-gpio-atben, only a small amount of code is added, but
152buffer accesses become almost 4 times faster. Register reads and
153writes are still fairly slow.
154
155spi_atben and spi-jz4740-gpio both achieve the best performance
156without significant differences between them. Both add a complete
157SPI driver. Of the two, spi-jz4740-gpio is preferable, because it
158uses the nearly universal spi_atben_gpio framework driver.
159
160
161Conclusion
162----------
163
164I think performance trumps most other considerations in this case.
165spi-gpio is clearly too inefficient. spi_atben_gpio with
166spi-jz4740-gpio offers the best performance and has a low impact
167on the system load (< 10%). In case this solution would be met
168with strong resistance for some reason, spi-gpio-atben would offer
169a compromise between performance and the amount of code.
170
171
172References
173----------
174
175[1] http://www.jennic.com/files/support_files/JN-AN-1035%20Calculating%20802-15-4%20Data%20Rates-1v0.pdf
176

Archive Download this file

Branches:
buffer-frames
master



interactive