1、Using the Thrift RPC Framework in Zephyr2023-06-28:Embedded Open Source SummitChris FriedtEmbedded SWE,MetaThrift Module Maintainerhttps:/bit.ly/442kJrJ Agenda01 What is Thrift?02 Thrift in Zephyr03 Status Update&Additional Work01 What is Thrift?https:/bit.ly/433nA2phttps:/bit.ly/44nXnwq 01 WHAT IS
2、THRIFT?Remote Procedure Call Frameworks RPC is nothing new Solution for ad-hoc,hand-rolled,bit-stuffed“protocols”Solution for re-inventing TCP 1000 x times Reliable asynchronous communication is hard ASN.1(1984,ITU-T)now ISO/IEC 8825-1:2021 Sun RPC(1984-1986,part of NFS)Part of glibc(and others)to t
3、his day(rpcgen)TLV(Tag-Length-Value)representation E.g.Netlink,MISB(oddly I did MISB in Thrift!)Some issues with SunRPC every message(procedure)required a version absolute nightmare for inter-version compatibility Protobufs,Thrift,and gRPC started around the“downfall of Sun”Drop message versions(jus
4、t use new Tag)Do not reuse Tags Guaranteed consistence+/-one rev(mit)01 WHAT IS THRIFT?https:/bit.ly/4411BdP 01 WHAT IS THRIFT?codePrincessThrift History/Internals Created at Facebook(now Meta)2006-2007 Inspired by Protocol Buffers Used extensively throughout Meta infra Released to the ASF in 2007,o
5、riginal whitepaper Adopted by several cloud companies,some OSS projects Not only primitive types such as bool,i32,and double,but also rich types such as enum,list,map,and struct Not only Binary,Compact Binary,but also e.g.JSON Procedures(methods)can throw any kind of struct and take any number of ar
6、guments All OSs,27 Languages,Facebook forked Thrift in 2014 to create fbthrift01 WHAT IS THRIFT?https:/bit.ly/3CS4PV8 https:/bit.ly/443gpse https:/ 02 Thrift in Zephyrhttps:/bit.ly/3Xv60D9 https:/bit.ly/3JvDyeP https:/zephyrproject.org/store/https:/bit.ly/3JxrVUs Thrift ported to Zephyr by Young Mei
7、(StdElectronics)Zephyr Blog Post C+Code Generation Supported Features Binary Protocol Compressed Binary Protocol Zlib Transport(via uzlib,muzic)TLS sockets via MbedTLS All Zephyr Architectures Supported All Thrift features(ThriftTest.thrift,Zephyr testsuite)Multi-OS,Multi-language samples Released i
8、n Zephyr v3.3.0(-zlib)EXPERIMENTALGoogle Summer of Code,202202 THRIFT IN ZEPHYRhttps:/bit.ly/43aC5le Nice features about Thrift is it is Transport Agnostic,but also ways to stitch things together TFDTransport anything that can be represented as a file descriptor socket(TCP,UDP,socketpair),text file,
9、In Linux,“everything is a file”/dev/mem,/dev/gpu0,/dev/accel0,TMemoryBuffer e.g.dual-port SRAM,DMA buffer In Zephyr,I wonder if its possible to wrap an arbitrary const struct device*with an integer file descriptor fdtable What if I wanted to use Thrift over a UART?How Can I use Thrift in Zephyr?02 T
10、HRIFT IN ZEPHYR Partial C+Support in Zephyr See C+Roadmap(#45785)Support for std:thread and std:this_thread(#25569)Get std:mutex,std:condition_variable,free No async(due to missing std:thread support)C+Requirements Zephyr SDK needs gthr-posix.h(#43729)Support pthread_create()dynamic stacks(#25973)so
11、cketpair()(testing)needs subsys/net(#51211)POSIX requirements Well,dynamic thread stacks benefit all languages Fix at kernel level Several workarounds(no Mutex synchronization)Integration Challenges02 THRIFT IN ZEPHYR We used eventfd()for notification in TFDServer eventfd_read()/eventfd_write()deadl
12、ock(#58790)Fixed(with 10 x performance improvement)No Compression/Decompression subsys yet Code size is huge-can run/test in Qemu but very difficult to fit onto practically size SRAM requirements were quite large(for zlib)but reduced dramatically by Young during GSoC 2022Integration Challenges02 THR
13、IFT IN ZEPHYR 03 Status Update&Additional Work https:/ Major C+enhancements over Apache Thrift Fully asynchronous Server performance gains of 5-10k queries/s Switch to Google Test Framework Now uses std:coroutine(C+20)Dramatically lower latency across the board Code size reduction Use std:string_vie
14、w(C+17)where possible Zero-copy buffers,fbthrift03 STATUS UPDATE&ADDITIONAL WORKhttps:/bit.ly/3r67vf6 latency and throughput Even more recent improvements.fbthrift03 STATUS UPDATE&ADDITIONAL WORKhttps:/bit.ly/3r67vf6 After 4 years of“hacking in my spare time”Received this from Flavio literally this morning!With/without MMU,with/without Userspace Collaboration from Andy,Flavio,Daniel,Anas and others at Intel,Stephanos Ioannis,Keith Packard Dynamic Kernel Thread Stacks Working!11!03 STATUS UPDATE&ADDITIONAL WORKQuestions?/Feedback