Using DPDK with Go. Takanari Hayama Technology Consulting Company IGEL Co.,Ltd.

Similar documents
Wireless Base Band Device (bbdev) Amr Mokhtar DPDK Summit Userspace - Dublin- 2017

Supporting Cloud Native with DPDK and containers KEITH INTEL CORPORATION

FAQ. Release rc2

Go Forth and Code. Jonathan Gertig. CSC 415: Programing Languages. Dr. Lyle

RCU and C++ Paul E. McKenney, IBM Distinguished Engineer, Linux Technology Center Member, IBM Academy of Technology CPPCON, September 23, 2016

DPDK+eBPF KONSTANTIN ANANYEV INTEL

Compression Device Drivers. Release rc3

Chapter 1 Getting Started

lib/librte_ipsec A NATIVE DPDK IPSEC LIBRARY UPDATE 2018/12 DECLAN DOHERTY, MOHAMMAD ABDUL AWAL, KONSTANTIN ANANYEV

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Object-Oriented Principles and Practice / C++

Concurrent Server Design Multiple- vs. Single-Thread

Last class: Today: Thread Background. Thread Systems

DPDK Summit 2016 OpenContrail vrouter / DPDK Architecture. Raja Sivaramakrishnan, Distinguished Engineer Aniket Daptari, Sr.

Ethernet switch support in the Linux kernel

A class is a user-defined type. It is composed of built-in types, other user-defined types and

High Performance Computing and Programming, Lecture 3

Event Device Drivers. Release rc1

CMSC 330: Organization of Programming Languages. Ownership, References, and Lifetimes in Rust

Summary of Go Syntax /

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

OpenACC Course. Office Hour #2 Q&A

QUIZ. What is wrong with this code that uses default arguments?

Understanding C/C++ Strict Aliasing

A practical introduction to XDP

Chapter 17 vector and Free Store. Bjarne Stroustrup

Accelerating VM networking through XDP. Jason Wang Red Hat

Bringing the Power of ebpf to Open vswitch. Linux Plumber 2018 William Tu, Joe Stringer, Yifeng Sun, Yi-Hung Wei VMware Inc. and Cilium.

C++ Coding Standards. 101 Rules, Guidelines, and Best Practices. Herb Sutter Andrei Alexandrescu. Boston. 'Y.'YAddison-Wesley

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

GO IDIOMATIC CONVENTIONS EXPLAINED IN COLOR

Ideas for adding generic HW accelerators to DPDK. Hemant Agrawal, NXP DPDK Summit Userspace - Dublin- 2017

Chenyu Zheng. CSCI 5828 Spring 2010 Prof. Kenneth M. Anderson University of Colorado at Boulder

Improving DPDK Performance

Concurrent Programming in the D Programming Language. by Walter Bright Digital Mars

Updating gopy to support Python3 and PyPy

Fast packet processing in the cloud. Dániel Géhberger Ericsson Research

EL6483: Brief Overview of C Programming Language

Overload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018

QUIZ. Can you find 5 errors in this code?

Go Tutorial. To do. A brief, gentle intro to Go. Next Networking. q Today

III. Classes (Chap. 3)

It's kind of fun to do the impossible with DPDK Yoshihiro Nakajima, Hirokazu Takahashi, Kunihiro Ishiguro, Koji Yamazaki NTT Labs

CS162: Introduction to Computer Science II. Primitive Types. Primitive types. Operations on primitive types. Limitations

T4P4S: When P4 meets DPDK. Sandor Laki DPDK Summit Userspace - Dublin- 2017

Open vswitch DPDK Acceleration Using HW Classification

Short Notes of CS201

National Aeronautics and Space and Administration Space Administration. cfe Release 6.6

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

CS201 - Introduction to Programming Glossary By

SpiNNaker Application Programming Interface (API)

QUIZ Friends class Y;

Ch. 12: Operator Overloading

Jaguar: Enabling Efficient Communication and I/O in Java

Final Step #7. Memory mapping For Sunday 15/05 23h59

M.EC201 Programming language

A Fast Review of C Essentials Part II

RDMA-like VirtIO Network Device for Palacios Virtual Machines

Administrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6

DPDK Tools User Guides. Release

Porting Objective-C to Swift. Richard Ekle

DAY 3. CS3600, Northeastern University. Alan Mislove

CS193D Handout 10 Winter 2005/2006 January 23, 2006 Pimp Your Classes

COSC 2P95 Lab 9 Signals, Mutexes, and Threads

Function Declarations. Reference and Pointer Pitfalls. Overloaded Functions. Default Arguments

Demystifying Network Cards

Basic Types, Variables, Literals, Constants

Vector and Free Store (Pointers and Memory Allocation)

Open vswitch: A Whirlwind Tour. Jus8n Pe:t March 3, 2011

The issues. Programming in C++ Common storage modes. Static storage in C++ Session 8 Memory Management

CS162: Introduction to Computer Science II

Bridging the gap between hardware functionality in DPDK applications and vendor neutrality in the open source community

Memory management COSC346

Chapter 17 vector and Free Store

Heap Arrays and Linked Lists. Steven R. Bagley

INT G bit TCP Offload Engine SOC

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Chapter 17 vector and Free Store

The Go Programming Language. Frank Roberts

Introduction to C: Pointers

10. Abstract Data Types

High-Speed Forwarding: A P4 Compiler with a Hardware Abstraction Library for Intel DPDK

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?

Enabling Fast, Dynamic Network Processing with ClickOS

Object Oriented Software Design II

Object Oriented Software Design II

Scope. Chapter Ten Modern Programming Languages 1

COMP322 - Introduction to C++ Lecture 10 - Overloading Operators and Exceptions

Understand Computer Storage and Data Types

Baseband Device Drivers. Release rc1

CPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2

URDMA: RDMA VERBS OVER DPDK

Type Checking and Type Equality

SmartHeap for Multi-Core

Reversing. Time to get with the program

Overview of C Feabhas Ltd 2012

Pierce Ch. 3, 8, 11, 15. Type Systems

Page 1. Last Time. Today. Embedded Compilers. Compiler Requirements. What We Get. What We Want

Evolution of the netmap architecture

Laboratory work in TDDB68 Pintos Assignments 2, 3. Viacheslav Izosimov

Transcription:

Using DPDK with Go Technology Consulting Company Research, Development & Global Standard Takanari Hayama taki@igel.co.jp Technology Consulting Company IGEL Co.,Ltd. 1

BACKGROUND 2017/9/26,27 DPDK Summit Userspace 2017 2

Background Lagopus (https://github.com/lagopus/lagopus) Open Source OpenFlow 1.3 Software Switch DPDK or Raw Socket C Lagopus2 (https://github.com/lagopus/vsw) OpenSource Software Router (VLAN, IPsec, Match-Action) DPDK Only Go + C 2017/9/26,27 DPDK Summit Userspace 2017 3

Goals of Lagopus2 Performance Maintainability + Extensibility 2017/9/26,27 DPDK Summit Userspace 2017 4

Goals of Lagopus2 Performance DPDK + C Maintainability + Extensibility Go 2017/9/26,27 DPDK Summit Userspace 2017 5

What is Go? Open Source Programming Language Simple Strong Type System Statically Typed with Flexibility Concurrency Garbage Collection Compiled Language Can use C Library via CGo 2017/9/26,27 DPDK Summit Userspace 2017 6

Go vs C Go C Complexity Simple by Design Can Become Complex Performance Moderate Very Fast Key-Value Data Type Yes (Map) No (requires other library) Concurrency Yes (channel and go func) No (requires other tools) Memory Management Yes (Garbage Collection) No Compiled Language Yes Yes Build System Built-in Your Choice 2017/9/26,27 DPDK Summit Userspace 2017 7

Performance Goal Data Plane shall run fast Control Plane can be slow Control Plane shall not disturb Data Plane Design Use C + DPDK directly where we need performance Let C to focus on packet processing Complicated tasks to be offloaded to Go Use DPDK Ring for communication between C and Go codes Make lock-free where possible 2017/9/26,27 DPDK Summit Userspace 2017 8

Maintainability + Extensibility Goal Keep the code simple Design Anything performance is not that important, do it in Go Make C part as simple as possible Make good use of Go types, i.e. Slice and Map, to make code simple Make good use of existing library, i.e. DPDK 2017/9/26,27 DPDK Summit Userspace 2017 9

Lagopus2 Architecture Netlink Agent Config Agent Tap Module ETHDEV Module Bridge Module Router Module HostIF Module ETHDEV- RX Bridge ETHDEV- TX Router Lagopus2 Core Scheduler Scheduler Non-DPDK Core Master Lcore Slave Lcore 1 Slave Lcore N Components written in Go Components written in C Physical CPU Core 2017/9/26,27 DPDK Summit Userspace 2017 10

Architecture Modules that require performance Module that don't require performance Control in Go Ring Ring Control and Packet Processing in Go Input Ring Packet Processing in C References to Output Rings Input Ring References to Output Rings 2017/9/26,27 DPDK Summit Userspace 2017 11

USING DPDK FROM GO 2017/9/26,27 DPDK Summit Userspace 2017 12

Making Good Use of Go Type Safety Simplicity Performance 2017/9/26,27 DPDK Summit Userspace 2017 13

Type Safety DPDK API make heavy use of generic types, such as unsigned, int, uint8_t, like any other C based library. For Go, we should have type safety. e.g. Make sure port_id passed to rte_eth_dev_* APIs is always valid port ID. 2017/9/26,27 DPDK Summit Userspace 2017 14

Example: Type Safety type EthDev struct { port_id uint socket_id int } type EthDevInfo C.struct_rte_eth_dev_info func EthDevOpen(port_id uint) (*EthDev, error) { pid := C.uint8_t(port_id) if int(c.rte_eth_dev_is_valid_port(pid)) == 0 { return nil, fmt.errorf("invalid port ID: %v", port_id) } return &EthDev{port_id, int(c.rte_eth_dev_socket_id(pid))}, nil } func (re *EthDev) DevInfo() *EthDevInfo { var di EthDevInfo C.rte_eth_dev_info_get(C.uint8_t(re.port_id), (*C.struct_rte_eth_dev_info)(&di)) return &di } 2017/9/26,27 DPDK Summit Userspace 2017 15

Simplicity Most of DPDK API such as rte_ring passes around handles. Define API as Methods, not Functions, to wrap DPDK API for particular types. Clarify that the APIs are for particular types. Hide details that are not necessary for callers. Minimize the risks for anything may go wrong. 2017/9/26,27 DPDK Summit Userspace 2017 16

Example: Simplicity type Ring C.struct_rte_ring type RingFlags uint const ( RING_F_SP_ENQ = RingFlags(C.RING_F_SP_ENQ) RING_F_SC_DEQ = RingFlags(C.RING_F_SC_DEQ) ) func RingCreate(name string, count uint, socket_id int, flags RingFlags) *Ring { cname := C.CString(name) defer C.free((unsafe.Pointer)(cname)) return (*Ring)(C.rte_ring_create(cname, C.unsigned(count), C.int(socket_id), C.unsigned(flags))) } func (r *Ring) Free() { C.rte_ring_free((*C.struct_rte_ring)(r)) } func (r *Ring) Enqueue(obj unsafe.pointer) bool { return int(c.rte_ring_enqueue((*c.struct_rte_ring)(r), obj)) == 0 } 2017/9/26,27 DPDK Summit Userspace 2017 17

Performance Even though we can't achieve real performance in Go, we definitely want relatively good performance. Avoiding memory copy is cruicial. 2017/9/26,27 DPDK Summit Userspace 2017 18

Example: Performance type EtherHdr []byte func (mb *Mbuf) EtherHdr() EtherHdr { len := C.sizeof_struct_ether_hdr mb.checkandupdatembuflen() return (EtherHdr)((*[1 << 30]byte)(unsafe.Pointer(uintptr(mb.buf_addr) + uintptr(mb.data_off)))[:len:len]) } You can create a Go slice from the underlying C array without copying the array. When the slice is released, only the reference to the C array is released. Underlying C array remains until the array is explicitly released in C. 2017/9/26,27 DPDK Summit Userspace 2017 19

But You Need to be Careful Go automatically releases memory allocated in Go when they're not needed anymore. HOWEVER, anything allocated in C shall be released explicitly. You have full responsibility! E.g., you must explicitly free ring when you don't need it anymore. No destructor, deinit or something similar to free C memory automatically in Go. 2017/9/26,27 DPDK Summit Userspace 2017 20

Your C type may be different from mine type Ring C.struct_rte_ring tells, that the type Ring is an alias to struct rte_ring in C. However, if the type is defined in different package, Go can't check the identity of C types. ring := dpdk.ringcreate("ring", 10, dpdk.socket_id_any, 0) var cring *C.struct_rte_ring cring = ring // Error cring = (*C.struct_rte_ring)(ring) // Error cring = (*C.struct_rte_ring)(unsafe.Pointer(ring)) // Ok! Not quite type safe here unsafe is really unsafe. 2017/9/26,27 DPDK Summit Userspace 2017 21

Regular C struct members are invisible Any name starting with upper characters are exported in Go, i.e. has a global scope. /* struct my_struct { int Visible; int invisible; } */ import "C" type MyStruct C.struct_my_struct You can access to MyStruct.Visible but not to MyStruct.invisible from outside the package. Should define setter/getter where needed. func (di *EthDevInfo) DefaultRxConf() *EthRxConf { rc := di.default_rxconf return (*EthRxConf)(&rc) } 2017/9/26,27 DPDK Summit Userspace 2017 22

Conclusions Could make DPDK API Go friendly. Memory management and type conversion requires extra care. Heavy use of unsafe may cause lots of problem, but sometime they're inevitable. 2017/9/26,27 DPDK Summit Userspace 2017 23

Useful References Command cgo - https://golang.org/cmd/cgo/ C? Go? Cgo! - https://blog.golang.org/c-go-cgo cgo - https://github.com/golang/go/wiki/cgo 2017/9/26,27 DPDK Summit Userspace 2017 24

QUESTIONS? 2017/9/26,27 DPDK Summit Userspace 2017 25