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