1.. _smp_pktqueue:
2
3SMP pktqueue
4############
5
6Overview
7********
8
9This sample application performs a simplified network layer forwarding function
10(essentially checksum calculation from IP Header Validation) of the Internet protocol
11suite specified in RFC1812 "Requirements for IP Version 4 Routers" which
12can be found at http://www.faqs.org/rfcs/rfc1812.html. This application
13provides an indication of the potential performance of a microprocessor in an
14IP router system.
15
16At the beginning of the application the array (size defined in SIZE_OF_QUEUE)
17of packet headers is initialized. Each header contains some random data of size
18defined in SIZE_OF_HEADER and calculated crc16 header checksum
19in appropriate field defined by CRC_BYTE_1 and CRC_BYTE_2. The contents of
20header follows:
21
22   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23   | 0 - 3 | 4 - 7 |     8 - 15    |            16 - 31            |
24   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25   |Version|  IHL  |Type of Service|          Total Length         |
26   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27   |         Identification        |Flags|      Fragment Offset    |
28   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29   |  Time to Live |    Protocol   |         Header Checksum       |
30   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31   |                       Source Address                          |
32   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33   |                    Destination Address                        |
34   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35   |                    Options                    |    Padding    |
36   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37
38The headers then are stored in multiple "sender" queues (the number is defined
39in QUEUE_NUM). After that for each pair of "sender"/"receiver" queues one thread
40is created, which will control "sender" queue processing.
41
42Then in each queue-related thread several(defined in THREADS_NUM) threads are created. Each
43of them first pick the header from "sender" queue, calculates crc and if
44crc is correct put the header to "receiver" queue. Only one thread in a
45time can access to sender or receiver queue.
46
47As soon as all headers in each pair of queues are moved from "sender" to
48"receiver" queue the execution of threads(related to pair) are terminated.
49
50By changing the value of CONFIG_MP_MAX_NUM_CPUS on SMP systems, you
51can see that using more cores takes almost linearly less time
52to complete the computational task.
53
54You can also edit the sample source code to change the
55number of parallel executed pairs of queues(``QUEUE_NUM``),
56the number of threads per pair of queues(``THREADS_NUM``),
57the number of headers in queue (``SIZE_OF_QUEUE``), and
58size of header in bytes (``SIZE_OF_HEADER``).
59
60Building and Running
61********************
62
63This project outputs total time required for processing all packet headers.
64It can be built and executed on QEMU as follows:
65
66.. zephyr-app-commands::
67   :zephyr-app: samples/arch/smp/pktqueue
68   :host-os: unix
69   :board: qemu_x86_64
70   :goals: run
71   :compact:
72
73Sample Output
74=============
75
76.. code-block:: console
77
78    Simulating IP header validation on multiple cores.
79    Each of 2 parallel queues is processed by 3 threads on 2 cores and contain 5000 packet headers.
80    Bytes in packet header: 24
81
82    RESULT: OK
83    Application ran successfully.
84    All 20000 packet headers were processed in 89 msec
85