doc: Convert docs to Markdown language
[cascardo/ovs.git] / INSTALL.DPDK.md
1 Using Open vSwitch with DPDK
2 ============================
3
4 Open vSwitch can use Intel(R) DPDK lib to operate entirely in
5 userspace. This file explains how to install and use Open vSwitch in
6 such a mode.
7
8 The DPDK support of Open vSwitch is considered experimental.
9 It has not been thoroughly tested.
10
11 This version of Open vSwitch should be built manually with `configure`
12 and `make`.
13
14 OVS needs a system with 1GB hugepages support.
15
16 Building and Installing:
17 ------------------------
18
19 Required DPDK 1.7
20
21 1. Configure build & install DPDK:
22   1. Set `$DPDK_DIR`
23
24      ```
25      export DPDK_DIR=/usr/src/dpdk-1.7.1
26      cd $DPDK_DIR
27      ```
28
29   2. Update `config/common_linuxapp` so that DPDK generate single lib file.
30      (modification also required for IVSHMEM build)
31
32      `CONFIG_RTE_BUILD_COMBINE_LIBS=y`
33
34      Then run `make install` to build and isntall the library.
35      For default install without IVSHMEM:
36
37      `make install T=x86_64-native-linuxapp-gcc`
38
39      To include IVSHMEM (shared memory):
40
41      `make install T=x86_64-ivshmem-linuxapp-gcc`
42
43      For further details refer to http://dpdk.org/
44
45 2. Configure & build the Linux kernel:
46
47    Refer to intel-dpdk-getting-started-guide.pdf for understanding
48    DPDK kernel requirement.
49
50 3. Configure & build OVS:
51
52    * Non IVSHMEM:
53
54      `export DPDK_BUILD=$DPDK_DIR/x86_64-native-linuxapp-gcc/`
55
56    * IVSHMEM:
57
58      `export DPDK_BUILD=$DPDK_DIR/x86_64-ivshmem-linuxapp-gcc/`
59
60    ```
61    cd $(OVS_DIR)/openvswitch
62    ./boot.sh
63    ./configure --with-dpdk=$DPDK_BUILD
64    make
65    ```
66
67 To have better performance one can enable aggressive compiler optimizations and
68 use the special instructions(popcnt, crc32) that may not be available on all
69 machines. Instead of typing `make`, type:
70
71 `make CFLAGS='-O3 -march=native'`
72
73 Refer to [INSTALL.userspace](INSTALL.userspace.md) for general requirements of
74 building userspace OVS.
75
76 Using the DPDK with ovs-vswitchd:
77 ---------------------------------
78
79 1. Setup system boot
80    Add the following options to the kernel bootline:
81    
82    `default_hugepagesz=1GB hugepagesz=1G hugepages=1`
83
84 2. Setup DPDK devices:
85    1. insert uio.ko: `modprobe uio`
86    2. insert igb_uio.ko: `insmod $DPDK_BUILD/kmod/igb_uio.ko`
87    3. Bind network device to igb_uio: `$DPDK_DIR/tools/dpdk_nic_bind.py --bind=igb_uio eth1`
88
89 3. Mount the hugetable filsystem
90
91    `mount -t hugetlbfs -o pagesize=1G none /dev/hugepages`
92
93    Ref to http://www.dpdk.org/doc/quick-start for verifying DPDK setup.
94
95 4. Start ovsdb-server as discussed in [INSTALL](INSTALL.md) doc:
96    1. First time only db creation (or clearing):
97
98         ```
99         mkdir -p /usr/local/etc/openvswitch
100         mkdir -p /usr/local/var/run/openvswitch
101         rm /usr/local/etc/openvswitch/conf.db
102         cd $OVS_DIR
103         ./ovsdb/ovsdb-tool create /usr/local/etc/openvswitch/conf.db \
104              ./vswitchd/vswitch.ovsschema
105         ```
106
107     2. start ovsdb-server
108
109         ```
110         cd $OVS_DIR
111         ./ovsdb/ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
112           --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
113           --private-key=db:Open_vSwitch,SSL,private_key \
114           --certificate=Open_vSwitch,SSL,certificate \
115           --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --pidfile --detach
116         ```
117
118     3. First time after db creation, initialize:
119
120         ```
121         cd $OVS_DIR
122         ./utilities/ovs-vsctl --no-wait init
123         ```
124
125 5. Start vswitchd:
126
127    DPDK configuration arguments can be passed to vswitchd via `--dpdk`
128    argument. This needs to be first argument passed to vswitchd process.
129    dpdk arg -c is ignored by ovs-dpdk, but it is a required parameter
130    for dpdk initialization.
131
132         export DB_SOCK=/usr/local/var/run/openvswitch/db.sock
133         ./vswitchd/ovs-vswitchd --dpdk -c 0x1 -n 4 -- unix:$DB_SOCK --pidfile --detach
134
135    If allocated more than one GB hugepage (as for IVSHMEM), set amount and use NUMA
136    node 0 memory:
137
138         ./vswitchd/ovs-vswitchd --dpdk -c 0x1 -n 4 --socket-mem 1024,0 \
139           -- unix:$DB_SOCK --pidfile --detach
140
141 6. Add bridge & ports
142           
143    To use ovs-vswitchd with DPDK, create a bridge with datapath_type
144    "netdev" in the configuration database.  For example:
145
146         `ovs-vsctl add-br br0 -- set bridge br0 datapath_type=netdev`
147
148    Now you can add dpdk devices. OVS expect DPDK device name start with dpdk
149    and end with portid. vswitchd should print (in the log file) the number of dpdk
150    devices found.
151
152         ovs-vsctl add-port br0 dpdk0 -- set Interface dpdk0 type=dpdk
153         ovs-vsctl add-port br0 dpdk1 -- set Interface dpdk1 type=dpdk
154
155     Once first DPDK port is added to vswitchd, it creates a Polling thread and
156     polls dpdk device in continuous loop. Therefore CPU utilization
157     for that thread is always 100%.
158
159 7. Add test flows
160
161    Test flow script across NICs (assuming ovs in /usr/src/ovs):
162    Execute script:
163
164    ```
165    #! /bin/sh
166    # Move to command directory
167    cd /usr/src/ovs/utilities/
168
169    # Clear current flows
170    ./ovs-ofctl del-flows br0
171
172    # Add flows between port 1 (dpdk0) to port 2 (dpdk1)
173    ./ovs-ofctl add-flow br0 in_port=1,action=output:2
174    ./ovs-ofctl add-flow br0 in_port=2,action=output:1
175    ```
176
177 8. Performance tuning
178
179    With pmd multi-threading support, OVS creates one pmd thread for each
180    numa node as default.  The pmd thread handles the I/O of all DPDK
181    interfaces on the same numa node.  The following two commands can be used
182    to configure the multi-threading behavior.
183
184         ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=<hex string>
185
186    The command above asks for a CPU mask for setting the affinity of pmd threads.
187    A set bit in the mask means a pmd thread is created and pinned to the
188    corresponding CPU core.  For more information, please refer to
189    `man ovs-vswitchd.conf.db`
190
191         ovs-vsctl set Open_vSwitch . other_config:n-dpdk-rxqs=<integer>
192
193    The command above sets the number of rx queues of each DPDK interface. The
194    rx queues are assigned to pmd threads on the same numa node in round-robin
195    fashion.  For more information, please refer to `man ovs-vswitchd.conf.db`
196
197    Ideally for maximum throughput, the pmd thread should not be scheduled out
198    which temporarily halts its execution. The following affinitization methods
199    can help.
200
201    Lets pick core 4,6,8,10 for pmd threads to run on.  Also assume a dual 8 core
202    sandy bridge system with hyperthreading enabled where CPU1 has cores 0,...,7
203    and 16,...,23 & CPU2 cores 8,...,15 & 24,...,31.  (A different cpu
204    configuration could have different core mask requirements).
205
206    To kernel bootline add core isolation list for cores and associated hype cores
207    (e.g.  isolcpus=4,20,6,22,8,24,10,26,).  Reboot system for isolation to take
208    effect, restart everything.
209
210    Configure pmd threads on core 4,6,8,10 using 'pmd-cpu-mask':
211
212         ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=00000550
213
214    You should be able to check that pmd threads are pinned to the correct cores
215    via:
216
217         top -p `pidof ovs-vswitchd` -H -d1
218
219    Note, the pmd threads on a numa node are only created if there is at least
220    one DPDK interface from the numa node that has been added to OVS.
221
222    Note, core 0 is always reserved from non-pmd threads and should never be set
223    in the cpu mask.
224
225 DPDK Rings :
226 ------------
227
228 Following the steps above to create a bridge, you can now add dpdk rings
229 as a port to the vswitch.  OVS will expect the DPDK ring device name to
230 start with dpdkr and end with a portid.
231
232     ovs-vsctl add-port br0 dpdkr0 -- set Interface dpdkr0 type=dpdkr
233
234 DPDK rings client test application
235
236 Included in the test directory is a sample DPDK application for testing
237 the rings.  This is from the base dpdk directory and modified to work
238 with the ring naming used within ovs.
239
240 location tests/ovs_client
241
242 To run the client :
243
244     cd /usr/src/ovs/tests/
245     ovsclient -c 1 -n 4 --proc-type=secondary -- -n "port id you gave dpdkr"
246
247 In the case of the dpdkr example above the "port id you gave dpdkr" is 0.
248
249 It is essential to have --proc-type=secondary
250
251 The application simply receives an mbuf on the receive queue of the
252 ethernet ring and then places that same mbuf on the transmit ring of
253 the ethernet ring.  It is a trivial loopback application.
254
255 DPDK rings in VM (IVSHMEM shared memory communications)
256 -------------------------------------------------------
257
258 In addition to executing the client in the host, you can execute it within
259 a guest VM. To do so you will need a patched qemu.  You can download the
260 patch and getting started guide at :
261
262 https://01.org/packet-processing/downloads
263
264 A general rule of thumb for better performance is that the client
265 application should not be assigned the same dpdk core mask "-c" as
266 the vswitchd.
267
268 Restrictions:
269 -------------
270
271   - This Support is for Physical NIC. I have tested with Intel NIC only.
272   - Work with 1500 MTU, needs few changes in DPDK lib to fix this issue.
273   - Currently DPDK port does not make use any offload functionality.
274
275   ivshmem:
276   - The shared memory is currently restricted to the use of a 1GB
277     huge pages.
278   - All huge pages are shared amongst the host, clients, virtual
279     machines etc.
280
281 Bug Reporting:
282 --------------
283
284 Please report problems to bugs@openvswitch.org.