logo资料库

dpdk学习资料-经典.pdf

第1页 / 共205页
第2页 / 共205页
第3页 / 共205页
第4页 / 共205页
第5页 / 共205页
第6页 / 共205页
第7页 / 共205页
第8页 / 共205页
资料共205页,剩余部分请下载后查看
Introduction
Documentation Roadmap
Related Publications
Overview
Development Environment
Environment Abstraction Layer
Core Components
Ethernet* Poll Mode Driver Architecture
Packet Forwarding Algorithm Support
librte_net
Environment Abstraction Layer
EAL in a Linux-userland Execution Environment
Memory Segments and Memory Zones (memzone)
Multiple pthread
Malloc Library
Cookies
Alignment and NUMA Constraints
Use Cases
Internal Implementation
Ring Library
References for Ring Implementation in FreeBSD*
Lockless Ring Buffer in Linux*
Additional Features
Use Cases
Anatomy of a Ring Buffer
References
Mempool Library
Cookies
Stats
Memory Alignment Constraints
Local Cache
Use Cases
Mbuf Library
Design of Packet Buffers
Buffers Stored in Memory Pools
Constructors
Allocating and Freeing mbufs
Manipulating mbufs
Meta Information
Direct and Indirect Buffers
Debug
Use Cases
Poll Mode Driver
Requirements and Assumptions
Design Principles
Logical Cores, Memory and NIC Queues Relationships
Device Identification and Configuration
Poll Mode Driver API
IVSHMEM Library
IVHSHMEM Library API Overview
IVSHMEM Environment Configuration
Best Practices for Writing IVSHMEM Applications
Best Practices for Running IVSHMEM Applications
Link Bonding Poll Mode Driver Library
Link Bonding Modes Overview
Implementation Details
Using Link Bonding Devices
Timer Library
Implementation Details
Use Cases
References
Hash Library
Hash API Overview
Implementation Details
Use Case: Flow Classification
References
LPM Library
LPM API Overview
Implementation Details
LPM6 Library
LPM6 API Overview
Use Case: IPv6 Forwarding
Packet Distributor Library
Distributor Core Operation
Worker Operation
Reorder Library
Operation
Implementation Details
Use Case: Packet Distributor
IP Fragmentation and Reassembly Library
Packet fragmentation
Packet reassembly
Multi-process Support
Memory Sharing
Deployment Models
Multi-process Limitations
Kernel NIC Interface
The DPDK KNI Kernel Module
KNI Creation and Deletion
DPDK mbuf Flow
Use Case: Ingress
Use Case: Egress
Ethtool
Link state and MTU change
KNI Working as a Kernel vHost Backend
Thread Safety of DPDK Functions
Fast-Path APIs
Performance Insensitive API
Library Initialization
Interrupt Thread
Quality of Service (QoS) Framework
Packet Pipeline with QoS Support
Hierarchical Scheduler
Dropper
Traffic Metering
Power Management
CPU Frequency Scaling
Core-load Throttling through C-States
API Overview of the Power Library
User Cases
References
Packet Classification and Access Control
Overview
Application Programming Interface (API) Usage
Packet Framework
Design Objectives
Overview
Port Library Design
Table Library Design
Pipeline Library Design
Multicore Scaling
Interfacing with Accelerators
Vhost Library
Vhost API Overview
Vhost Implementation
Vhost supported vSwitch reference
Port Hotplug Framework
Overview
Port Hotplug API overview
Reference
Limitations
Source Organization
Makefiles and Config
Libraries
Applications
Development Kit Build System
Building the Development Kit Binary
Building External Applications
Makefile Description
Development Kit Root Makefile Help
Configuration Targets
Build Targets
Install Targets
Test Targets
Documentation Targets
Deps Targets
Misc Targets
Other Useful Command-line Variables
Make in a Build Directory
Compiling for Debug
Extending the DPDK
Example: Adding a New Library libfoo
Building Your Own Application
Compiling a Sample Application in the Development Kit Directory
Build Your Own Application Outside the Development Kit
Customizing Makefiles
External Application/Library Makefile help
Prerequisites
Build Targets
Help Targets
Other Useful Command-line Variables
Make from Another Directory
Performance Optimization Guidelines
Introduction
Writing Efficient Code
Memory
Communication Between lcores
PMD Driver
Locks and Atomic Operations
Coding Considerations
Setting the Target CPU Type
Profile Your Application
Glossary
Programmer’s Guide Release 2.0.0 April 24, 2015
CONTENTS 1 Introduction 1.1 Documentation Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Related Publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Overview 2.1 Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Environment Abstraction Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Core Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Ethernet* Poll Mode Driver Architecture . . . . . . . . . . . . . . . . . . . . . . . 2.5 Packet Forwarding Algorithm Support . . . . . . . . . . . . . . . . . . . . . . . . librte_net . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.6 1 1 2 3 3 4 4 6 6 7 3 Environment Abstraction Layer 8 3.1 EAL in a Linux-userland Execution Environment 8 3.2 Memory Segments and Memory Zones (memzone) . . . . . . . . . . . . . . . . 12 3.3 Multiple pthread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . . . . 4 Malloc Library 16 4.1 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.2 Alignment and NUMA Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.3 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.4 Internal Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 5 Ring Library Lockless Ring Buffer in Linux* 21 . . . . . . . . . . . . . . . . . 22 5.1 References for Ring Implementation in FreeBSD* . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.2 5.3 Additional Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.4 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 5.5 Anatomy of a Ring Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 5.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 6 Mempool Library 33 6.1 Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6.2 Stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6.3 Memory Alignment Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6.4 Local Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 6.5 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 7 Mbuf Library 36 7.1 Design of Packet Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 i
7.2 Buffers Stored in Memory Pools . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 7.3 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 7.4 Allocating and Freeing mbufs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 7.5 Manipulating mbufs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 7.6 Meta Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 7.7 Direct and Indirect Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 7.8 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 7.9 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 8 Poll Mode Driver 42 8.1 Requirements and Assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 8.2 Design Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 8.3 Logical Cores, Memory and NIC Queues Relationships . . . . . . . . . . . . . . 44 8.4 Device Identification and Configuration . . . . . . . . . . . . . . . . . . . . . . . 44 8.5 Poll Mode Driver API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 9 IVSHMEM Library 48 IVHSHMEM Library API Overview . . . . . . . . . . . . . . . . . . . . . . . . . . 49 9.1 9.2 IVSHMEM Environment Configuration . . . . . . . . . . . . . . . . . . . . . . . . 49 9.3 Best Practices for Writing IVSHMEM Applications . . . . . . . . . . . . . . . . . 50 9.4 Best Practices for Running IVSHMEM Applications . . . . . . . . . . . . . . . . 50 10 Link Bonding Poll Mode Driver Library 51 10.1 Link Bonding Modes Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 10.2 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 10.3 Using Link Bonding Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 11 Timer Library 62 11.1 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 11.2 Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 11.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 12 Hash Library 64 12.1 Hash API Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 12.2 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 12.3 Use Case: Flow Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 12.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 13 LPM Library 67 13.1 LPM API Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 13.2 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 14 LPM6 Library 71 14.1 LPM6 API Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 14.2 Use Case: IPv6 Forwarding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 15 Packet Distributor Library 76 15.1 Distributor Core Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 15.2 Worker Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 16 Reorder Library 79 16.1 Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 16.2 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 ii
16.3 Use Case: Packet Distributor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 17 IP Fragmentation and Reassembly Library 81 17.1 Packet fragmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 17.2 Packet reassembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 18 Multi-process Support 84 18.1 Memory Sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 18.2 Deployment Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 18.3 Multi-process Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 19 Kernel NIC Interface 88 19.1 The DPDK KNI Kernel Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 19.2 KNI Creation and Deletion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 19.3 DPDK mbuf Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 19.4 Use Case: Ingress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 19.5 Use Case: Egress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 19.6 Ethtool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 19.7 Link state and MTU change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 19.8 KNI Working as a Kernel vHost Backend . . . . . . . . . . . . . . . . . . . . . . 92 20 Thread Safety of DPDK Functions 95 20.1 Fast-Path APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 20.2 Performance Insensitive API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 20.3 Library Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 20.4 Interrupt Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 97 21 Quality of Service (QoS) Framework . . . . . . . . . . . . . . . . . . . . . . . . . . 97 21.1 Packet Pipeline with QoS Support 21.2 Hierarchical Scheduler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 21.3 Dropper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 21.4 Traffic Metering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 22 Power Management 134 22.1 CPU Frequency Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 22.2 Core-load Throttling through C-States . . . . . . . . . . . . . . . . . . . . . . . . 135 22.3 API Overview of the Power Library . . . . . . . . . . . . . . . . . . . . . . . . . . 135 22.4 User Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 22.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 23 Packet Classification and Access Control 136 23.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 23.2 Application Programming Interface (API) Usage . . . . . . . . . . . . . . . . . . 141 24 Packet Framework 144 24.1 Design Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 24.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 24.3 Port Library Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 24.4 Table Library Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 24.5 Pipeline Library Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 24.6 Multicore Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 24.7 Interfacing with Accelerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 iii
25 Vhost Library 164 25.1 Vhost API Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 25.2 Vhost Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 25.3 Vhost supported vSwitch reference . . . . . . . . . . . . . . . . . . . . . . . . . 166 26 Port Hotplug Framework 167 26.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 26.2 Port Hotplug API overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 26.3 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 26.4 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 27 Source Organization 169 27.1 Makefiles and Config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 27.2 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 27.3 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 28 Development Kit Build System 171 28.1 Building the Development Kit Binary . . . . . . . . . . . . . . . . . . . . . . . . . 171 28.2 Building External Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 28.3 Makefile Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 29 Development Kit Root Makefile Help 178 29.1 Configuration Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 29.2 Build Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 29.3 Install Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 29.4 Test Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 29.5 Documentation Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 29.6 Deps Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 29.7 Misc Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 29.8 Other Useful Command-line Variables . . . . . . . . . . . . . . . . . . . . . . . . 180 29.9 Make in a Build Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 29.10Compiling for Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 30 Extending the DPDK 182 30.1 Example: Adding a New Library libfoo . . . . . . . . . . . . . . . . . . . . . . . . 182 31 Building Your Own Application 184 31.1 Compiling a Sample Application in the Development Kit Directory . . . . . . . . 184 31.2 Build Your Own Application Outside the Development Kit . . . . . . . . . . . . . 184 31.3 Customizing Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 32 External Application/Library Makefile help 186 32.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 32.2 Build Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 32.3 Help Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 32.4 Other Useful Command-line Variables . . . . . . . . . . . . . . . . . . . . . . . . 187 32.5 Make from Another Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 33 Performance Optimization Guidelines 188 33.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 34 Writing Efficient Code 189 34.1 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 iv
34.2 Communication Between lcores . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 34.3 PMD Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 34.4 Locks and Atomic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 34.5 Coding Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 34.6 Setting the Target CPU Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 35 Profile Your Application 36 Glossary 193 194 v
CHAPTER ONE INTRODUCTION This document provides software architecture information, development environment informa- tion and optimization guidelines. For programming examples and for instructions on compiling and running each sample appli- cation, see the DPDK Sample Applications User Guide for details. For general information on compiling and running applications, see the DPDK Getting Started Guide. 1.1 Documentation Roadmap The following is a list of DPDK documents in the suggested reading order: • Release Notes (this document): Provides release-specific information, including sup- ported features, limitations, fixed issues, known issues and so on. Also, provides the answers to frequently asked questions in FAQ format. • Getting Started Guide : Describes how to install and configure the DPDK software; designed to get users up and running quickly with the software. • FreeBSD* Getting Started Guide : A document describing the use of the DPDK with FreeBSD* has been added in DPDK Release 1.6.0. Refer to this guide for installation and configuration instructions to get started using the DPDK with FreeBSD*. • Programmer’s Guide (this document): Describes: – The software architecture and how to use it (through examples), specifically in a Linux* application (linuxapp) environment – The content of the DPDK, the build system (including the commands that can be used in the root DPDK Makefile to build the development kit and an application) and guidelines for porting an application – Optimizations used in the software and those that should be considered for new development A glossary of terms is also provided. • API Reference : Provides detailed information about DPDK functions, data structures and other programming constructs. • Sample Applications User Guide: Describes a set of sample applications. Each chap- ter describes a sample application that showcases specific functionality and provides instructions on how to compile, run and use the sample application. 1
Programmer’s Guide, Release 2.0.0 1.2 Related Publications The following documents provide information that is relevant to the development of applications using the DPDK: • Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3A: System Pro- gramming Guide 1.2. Related Publications 2
分享到:
收藏