├── .clang-format ├── .gitmodules ├── BUILD.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── apps ├── helloworld-pool │ ├── CMakeLists.txt │ ├── Makefile │ ├── cmake │ │ ├── FindCapnp.cmake │ │ └── FindTBB.cmake │ ├── expect.py │ └── src │ │ ├── StaticEbbIds.h │ │ ├── baremetal │ │ ├── Printer.cc │ │ ├── Printer.h │ │ └── helloworld.cc │ │ └── hosted │ │ ├── Printer.cc │ │ ├── Printer.h │ │ └── helloworld.cc ├── helloworld │ ├── CMakeLists.txt │ ├── Makefile │ ├── cmake │ │ ├── FindCapnp.cmake │ │ └── FindTBB.cmake │ ├── expect.py │ └── src │ │ ├── StaticEbbIds.h │ │ ├── baremetal │ │ ├── Printer.cc │ │ ├── Printer.h │ │ └── helloworld.cc │ │ └── hosted │ │ ├── Printer.cc │ │ ├── Printer.h │ │ └── helloworld.cc ├── iperf │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── cmake │ │ ├── FindCapnp.cmake │ │ └── FindTBB.cmake │ └── src │ │ ├── hosted │ │ └── iperf.cc │ │ └── native │ │ └── iperf.cc ├── msgtst │ ├── CMakeLists.txt │ ├── Makefile │ ├── cmake │ │ ├── FindCapnp.cmake │ │ └── FindTBB.cmake │ └── src │ │ ├── MsgTst.cc │ │ ├── MsgTst.h │ │ ├── StaticEbbIds.h │ │ └── hosted │ │ └── msgtst.cc └── zookeeper_app │ ├── CMakeLists.txt │ ├── Makefile │ ├── cmake │ ├── FindCapnp.cmake │ └── FindTBB.cmake │ └── src │ ├── InstallGlobalIdMap.cc │ └── zktest.cc ├── contrib ├── appgen │ ├── README.md │ ├── appgen.py │ └── template │ │ ├── default │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── cmake │ │ │ ├── FindCapnp.cmake │ │ │ └── FindTBB.cmake │ │ └── src │ │ │ ├── StaticEbbIds.h │ │ │ ├── hosted │ │ │ ├── Printer.cc │ │ │ ├── Printer.h │ │ │ └── title.cc │ │ │ └── native │ │ │ ├── Printer.cc │ │ │ ├── Printer.h │ │ │ └── title.cc │ │ └── native │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ └── src │ │ └── title.cc ├── clean_running_apps.sh ├── dschatz │ ├── cpplint.py │ ├── howtorun │ ├── pre-commit.sh │ └── test.cpp ├── jappavoo.html └── launch.sh ├── doc ├── debugging.md ├── ebbrt-OSDI_16.pdf ├── ebbs.md ├── img │ ├── memcached_results.png │ ├── nodejs_results.png │ └── objective.png └── native-boot-sequence.md ├── libs ├── CMakeLists.txt ├── cmdline │ ├── CMakeLists.txt │ ├── CmdLineArgs.capnp │ ├── CmdLineArgs.cc │ ├── CmdLineArgs.h │ ├── EbbRTCmdLineConfig.cmake.in │ ├── README.md │ └── cmake │ │ └── FindCapnp.cmake ├── filesystem │ ├── CMakeLists.txt │ ├── EbbRTFilesystemConfig.cmake.in │ ├── FileSystem.capnp │ ├── FileSystem.cc │ ├── FileSystem.h │ ├── README.md │ └── cmake │ │ └── FindCapnp.cmake ├── socket │ ├── CMakeLists.txt │ ├── EbbRTSocketConfig.cmake.in │ ├── README.md │ ├── SocketApi.cc │ ├── SocketManager.cc │ ├── SocketManager.h │ ├── Vfs.cc │ ├── Vfs.h │ ├── gnu │ │ └── include │ │ │ ├── bits │ │ │ └── poll.h │ │ │ ├── features.h │ │ │ ├── poll.h │ │ │ └── sys │ │ │ └── poll.h │ └── lwip │ │ ├── api │ │ └── netdb.c │ │ ├── core │ │ ├── def.c │ │ ├── ip_addr.c │ │ └── memp.c │ │ ├── include │ │ ├── arch │ │ │ └── sys_arch.h │ │ ├── lwip │ │ │ ├── api.h │ │ │ ├── api_msg.h │ │ │ ├── arch.h │ │ │ ├── arch │ │ │ │ └── cc.h │ │ │ ├── autoip.h │ │ │ ├── debug.h │ │ │ ├── def.h │ │ │ ├── dhcp.h │ │ │ ├── dns.h │ │ │ ├── err.h │ │ │ ├── icmp.h │ │ │ ├── igmp.h │ │ │ ├── inet.h │ │ │ ├── inet_chksum.h │ │ │ ├── init.h │ │ │ ├── ip.h │ │ │ ├── ip_addr.h │ │ │ ├── ip_frag.h │ │ │ ├── mem.h │ │ │ ├── memp.h │ │ │ ├── memp_std.h │ │ │ ├── netbuf.h │ │ │ ├── netdb.h │ │ │ ├── netif.h │ │ │ ├── netifapi.h │ │ │ ├── opt.h │ │ │ ├── pbuf.h │ │ │ ├── raw.h │ │ │ ├── sio.h │ │ │ ├── snmp.h │ │ │ ├── snmp_asn1.h │ │ │ ├── snmp_msg.h │ │ │ ├── snmp_structs.h │ │ │ ├── sockets.h │ │ │ ├── stats.h │ │ │ ├── sys.h │ │ │ ├── tcp.h │ │ │ ├── tcp_impl.h │ │ │ ├── tcpip.h │ │ │ ├── timers.h │ │ │ └── udp.h │ │ ├── lwipopts.h │ │ ├── netif │ │ │ ├── etharp.h │ │ │ ├── ppp_oe.h │ │ │ └── slipif.h │ │ └── posix │ │ │ ├── arpa │ │ │ ├── inet.h │ │ │ └── inet_aton.h │ │ │ ├── netdb.h │ │ │ ├── netinet │ │ │ ├── in.h │ │ │ └── tcp.h │ │ │ └── sys │ │ │ └── socket.h │ │ └── inet │ │ ├── inet_ntop.c │ │ └── inet_pton.c └── zookeeper │ ├── CMakeLists.txt │ ├── EbbRTZooKeeperConfig.cmake.in │ ├── README.md │ ├── ZKGlobalIdMap.h │ ├── ZooKeeper.cc │ ├── ZooKeeper.h │ └── zookeeper │ ├── README │ ├── etc │ ├── config.h │ └── kludge.h │ ├── include │ ├── proto.h │ ├── recordio.h │ ├── winconfig.h │ ├── winstdint.h │ ├── zookeeper.h │ ├── zookeeper.jute.h │ ├── zookeeper_log.h │ └── zookeeper_version.h │ └── src │ ├── hashtable │ ├── LICENSE.txt │ ├── hashtable.c │ ├── hashtable.h │ ├── hashtable_itr.c │ ├── hashtable_itr.h │ └── hashtable_private.h │ ├── recordio.c │ ├── st_adaptor.c │ ├── winport.c │ ├── winport.h │ ├── zk_adaptor.h │ ├── zk_hashtable.c │ ├── zk_hashtable.h │ ├── zk_log.c │ ├── zookeeper.c │ └── zookeeper.jute.c ├── misc ├── docker │ ├── build-environment │ │ └── Dockerfile │ ├── buildbot-master │ │ └── Dockerfile │ ├── buildbot-slave │ │ ├── Dockerfile │ │ └── supervisord.conf │ ├── homu │ │ └── Dockerfile │ └── kvm-qemu │ │ ├── Dockerfile │ │ ├── launch.sh │ │ └── start.sh ├── ebbrt.kallsyms └── grub.cfg ├── src ├── Align.h ├── AtomicUniquePtr.h ├── CMakeLists.txt ├── CacheAligned.h ├── CapnpMessage.cc ├── CapnpMessage.h ├── Clock.h ├── Compiler.h ├── Console.h ├── Cpu.h ├── Debug.h ├── EbbAllocator.cc ├── EbbAllocator.h ├── EbbId.h ├── EbbRef.h ├── EventManager.h ├── ExplicitlyConstructed.h ├── Future.h ├── GlobalIdMap.h ├── GlobalIdMapBase.h ├── GlobalIdMessage.capnp ├── GlobalStaticIds.h ├── Hash.h ├── IOBuf.cc ├── IOBuf.h ├── IOBufRef.cc ├── IOBufRef.h ├── LocalEntry.h ├── LocalIdMap.h ├── Message.cc ├── Message.h ├── Messenger.h ├── MoveLambda.h ├── MulticoreEbb.h ├── MulticoreEbbStatic.h ├── Nid.h ├── Runtime.h ├── RuntimeInfo.capnp ├── SharedEbb.h ├── SharedIOBufRef.cc ├── SharedIOBufRef.h ├── SpinBarrier.h ├── SpinLock.h ├── StaticIOBuf.cc ├── StaticIOBuf.h ├── StaticIds.h ├── StaticSharedEbb.h ├── Timer.h ├── TypeTraits.h ├── UniqueIOBuf.cc ├── UniqueIOBuf.h ├── cmake │ ├── Modules │ │ ├── FindCapnProto.cmake │ │ ├── FindCapnp.cmake │ │ └── FindTBB.cmake │ ├── Platform │ │ └── EbbRT.cmake │ └── ebbrt.cmake ├── hosted │ ├── .gitignore │ ├── Clock.cc │ ├── Clock.h │ ├── Console.cc │ ├── Context.cc │ ├── Context.h │ ├── ContextActivation.cc │ ├── ContextActivation.h │ ├── Cpu.cc │ ├── Cpu.h │ ├── Debug.cc │ ├── Debug.h │ ├── EbbRTConfig.cmake.in │ ├── EbbRef.h │ ├── EventContext.h │ ├── EventManager.cc │ ├── EventManager.h │ ├── GlobalIdMap.cc │ ├── GlobalIdMap.h │ ├── LocalEntry.cc │ ├── LocalIdMap.cc │ ├── LocalIdMap.h │ ├── Messenger.cc │ ├── Messenger.h │ ├── NodeAllocator.cc │ ├── NodeAllocator.h │ ├── PoolAllocator.cc │ ├── PoolAllocator.h │ ├── Runtime.cc │ ├── Runtime.h │ ├── StaticIds.h │ ├── Timer.cc │ └── config.cmake └── native │ ├── Acpi.cc │ ├── Acpi.h │ ├── Apic.cc │ ├── Apic.h │ ├── Argv.h │ ├── Boot.S │ ├── CDebug.h │ ├── Clock.cc │ ├── Clock.h │ ├── Clock_internal.h │ ├── Cpu.cc │ ├── Cpu.h │ ├── CpuAsm.h │ ├── Cpuid.cc │ ├── Cpuid.h │ ├── Debug.cc │ ├── Debug.h │ ├── E820.cc │ ├── E820.h │ ├── EarlyPageAllocator.cc │ ├── EarlyPageAllocator.h │ ├── EbbRef.h │ ├── EventManager.cc │ ├── EventManager.h │ ├── Fls.h │ ├── GeneralPurposeAllocator.h │ ├── GlobalIdMap.cc │ ├── GlobalIdMap.h │ ├── Gthread.cc │ ├── Gthread.h │ ├── Idt.cc │ ├── Idt.h │ ├── Io.h │ ├── Isr.S │ ├── Isr.h │ ├── LocalEntry.cc │ ├── LocalIdMap.cc │ ├── LocalIdMap.h │ ├── Main.cc │ ├── Main.h │ ├── MemMap.cc │ ├── MemMap.h │ ├── Memchr.S │ ├── Memcpy.S │ ├── Memset.S │ ├── Messenger.cc │ ├── Messenger.h │ ├── Msr.h │ ├── Multiboot.cc │ ├── Multiboot.h │ ├── Net.cc │ ├── Net.h │ ├── NetChecksum.cc │ ├── NetChecksum.h │ ├── NetDhcp.cc │ ├── NetDhcp.h │ ├── NetEth.cc │ ├── NetEth.h │ ├── NetIcmp.cc │ ├── NetIcmp.h │ ├── NetIp.cc │ ├── NetIp.h │ ├── NetIpAddress.h │ ├── NetMisc.h │ ├── NetTcp.cc │ ├── NetTcp.h │ ├── NetTcpHandler.h │ ├── NetUdp.cc │ ├── NetUdp.h │ ├── Newlib.cc │ ├── Newlib.h │ ├── Numa.cc │ ├── Numa.h │ ├── PMem.h │ ├── PageAllocator.cc │ ├── PageAllocator.h │ ├── Pci.cc │ ├── Pci.h │ ├── Perf.cc │ ├── Perf.h │ ├── Pfn.h │ ├── Pic.cc │ ├── Pic.h │ ├── PitClock.cc │ ├── PitClock.h │ ├── Preprocessor.h │ ├── PvClock.cc │ ├── PvClock.h │ ├── Random.cc │ ├── Random.h │ ├── Rcu.h │ ├── RcuList.h │ ├── RcuTable.h │ ├── Rdtsc.h │ ├── Runtime.cc │ ├── Runtime.h │ ├── Semaphore.h │ ├── SharedPoolAllocator.h │ ├── SlabAllocator.cc │ ├── SlabAllocator.h │ ├── SlabObject.h │ ├── Smp.cc │ ├── Smp.h │ ├── Stack.S │ ├── StaticIds.h │ ├── Timer.cc │ ├── Tls.cc │ ├── Tls.h │ ├── Trace.cc │ ├── Trace.h │ ├── Trans.cc │ ├── Trans.h │ ├── Uart8250.cc │ ├── VMem.cc │ ├── VMem.h │ ├── VMemAllocator.cc │ ├── VMemAllocator.h │ ├── Virtio.h │ ├── VirtioNet.cc │ ├── VirtioNet.h │ ├── config.cmake │ ├── config.h.in │ └── ebbrt.ld └── toolchain ├── .gitignore ├── Makefile └── patches ├── binutils-2.26.patch ├── capnproto-c++-0.4.0.patch ├── gcc-5.3.0.patch └── newlib-2.0.0.patch /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -1 5 | ConstructorInitializerIndentWidth: 4 6 | AlignEscapedNewlinesLeft: false 7 | AlignTrailingComments: false 8 | AllowAllParametersOfDeclarationOnNextLine: true 9 | AllowShortIfStatementsOnASingleLine: false 10 | AllowShortLoopsOnASingleLine: false 11 | AllowShortFunctionsOnASingleLine: true 12 | AlwaysBreakTemplateDeclarations: false 13 | AlwaysBreakBeforeMultilineStrings: false 14 | BreakBeforeBinaryOperators: false 15 | BreakBeforeTernaryOperators: true 16 | BreakConstructorInitializersBeforeComma: false 17 | BinPackParameters: true 18 | ColumnLimit: 80 19 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 20 | Cpp11BracedListStyle: true 21 | DerivePointerBinding: false 22 | ExperimentalAutoDetectBinPacking: false 23 | IndentCaseLabels: false 24 | MaxEmptyLinesToKeep: 1 25 | NamespaceIndentation: None 26 | ObjCSpaceBeforeProtocolList: true 27 | PenaltyBreakBeforeFirstCallParameter: 19 28 | PenaltyBreakComment: 300 29 | PenaltyBreakString: 1000 30 | PenaltyBreakFirstLessLess: 120 31 | PenaltyExcessCharacter: 1000000 32 | PenaltyReturnTypeOnItsOwnLine: 60 33 | PointerBindsToType: true 34 | SpacesBeforeTrailingComments: 2 35 | Standard: Cpp11 36 | IndentWidth: 2 37 | TabWidth: 8 38 | UseTab: Never 39 | BreakBeforeBraces: Attach 40 | IndentFunctionDeclarationAfterType: false 41 | SpacesInParentheses: false 42 | SpacesInAngles: false 43 | SpaceInEmptyParentheses: false 44 | SpacesInCStyleCastParentheses: false 45 | SpacesInContainerLiterals: true 46 | SpaceBeforeAssignmentOperators: true 47 | ContinuationIndentWidth: 4 48 | CommentPragmas: '^ IWYU pragma:' 49 | SpaceBeforeParens: ControlStatements 50 | ... 51 | 52 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "apps/node"] 2 | path = apps/node 3 | url = https://github.com/sesa/ebbrt-node-app 4 | [submodule "toolchain/ext/acpica"] 5 | path = toolchain/ext/acpica 6 | url = https://github.com/SESA/EbbRT-ACPICA.git 7 | [submodule "toolchain/ext/boost"] 8 | path = toolchain/ext/boost 9 | url = https://github.com/SESA/EbbRT-boost.git 10 | [submodule "toolchain/ext/capnp"] 11 | path = toolchain/ext/capnp 12 | url = https://github.com/SESA/EbbRT-capnp.git 13 | [submodule "toolchain/ext/tbb"] 14 | path = toolchain/ext/tbb 15 | url = https://github.com/SESA/EbbRT-tbb 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /apps/helloworld-pool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("helloworld-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | 11 | set(HOSTED_SOURCES 12 | src/hosted/helloworld.cc 13 | src/hosted/Printer.cc) 14 | 15 | set(BAREMETAL_SOURCES 16 | src/baremetal/helloworld.cc 17 | src/baremetal/Printer.cc) 18 | 19 | # Baremetal ======================================================== 20 | 21 | if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") 22 | 23 | add_executable(helloworld.elf ${BAREMETAL_SOURCES}) 24 | add_custom_command(TARGET helloworld.elf POST_BUILD 25 | COMMAND objcopy -O elf32-i386 helloworld.elf helloworld.elf32 ) 26 | 27 | # Hosted =========================================================== 28 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) 29 | 30 | # TODO(jmcadden): remove source-dir requirement 31 | if(DEFINED ENV{EBBRT_SRCDIR}) 32 | list(APPEND CMAKE_MODULE_PATH 33 | "$ENV{EBBRT_SRCDIR}/hosted/cmake/Modules") 34 | endif() 35 | 36 | find_package(EbbRT REQUIRED) 37 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 38 | filesystem system coroutine context ) 39 | find_package(Capnp REQUIRED) 40 | find_package(TBB REQUIRED) 41 | find_package(Threads REQUIRED) 42 | 43 | include_directories(${EBBRT_INCLUDE_DIRS}) 44 | add_executable(helloworld ${HOSTED_SOURCES}) 45 | target_link_libraries(helloworld ${EBBRT_LIBRARIES} 46 | ${CAPNP_LIBRARIES_LITE} ${CMAKE_THREAD_LIBS_INIT} 47 | ${Boost_LIBRARIES} ${TBB_LIBRARIES} 48 | ) 49 | else() 50 | message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") 51 | endif() 52 | -------------------------------------------------------------------------------- /apps/helloworld-pool/expect.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import pexpect 4 | import sys 5 | import time 6 | 7 | filename = sys.argv[1] 8 | child = pexpect.spawn(filename) 9 | child.logfile = sys.stdout 10 | child.expect('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}: Hello World', timeout=60) 11 | child.sendcontrol('c') 12 | child.wait() 13 | -------------------------------------------------------------------------------- /apps/helloworld-pool/src/StaticEbbIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_HELLOWORLD_SRC_STATICEBBIDS_H_ 6 | #define APPS_HELLOWORLD_SRC_STATICEBBIDS_H_ 7 | 8 | #include 9 | 10 | enum : ebbrt::EbbId { kPrinterEbbId = ebbrt::kFirstStaticUserId }; 11 | 12 | #endif // APPS_HELLOWORLD_SRC_STATICEBBIDS_H_ 13 | -------------------------------------------------------------------------------- /apps/helloworld-pool/src/baremetal/Printer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_HELLOWORLD_BAREMETAL_SRC_PRINTER_H_ 6 | #define APPS_HELLOWORLD_BAREMETAL_SRC_PRINTER_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "../../src/StaticEbbIds.h" 13 | 14 | class Printer : public ebbrt::Messagable { 15 | public: 16 | explicit Printer(ebbrt::Messenger::NetworkId nid); 17 | 18 | static Printer& HandleFault(ebbrt::EbbId id); 19 | 20 | void Print(const char* string); 21 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 22 | std::unique_ptr&& buffer); 23 | 24 | private: 25 | ebbrt::Messenger::NetworkId remote_nid_; 26 | }; 27 | 28 | constexpr auto printer = ebbrt::EbbRef(kPrinterEbbId); 29 | 30 | #endif // APPS_HELLOWORLD_BAREMETAL_SRC_PRINTER_H_ 31 | -------------------------------------------------------------------------------- /apps/helloworld-pool/src/baremetal/helloworld.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include "Printer.h" 7 | 8 | void AppMain() { printer->Print("Hello World\n"); } 9 | -------------------------------------------------------------------------------- /apps/helloworld-pool/src/hosted/Printer.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Printer.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | EBBRT_PUBLISH_TYPE(, Printer); 14 | 15 | Printer::Printer() : ebbrt::Messagable(kPrinterEbbId) {} 16 | 17 | ebbrt::Future Printer::Init() { 18 | return ebbrt::global_id_map->Set( 19 | kPrinterEbbId, ebbrt::GlobalIdMap::OptArgs({.data=ebbrt::messenger->LocalNetworkId().ToBytes()})); 20 | } 21 | 22 | void Printer::Print(const char* str) {} 23 | 24 | void Printer::Execute(ebbrt::Messenger::NetworkId nid) { 25 | const char* str = "exec"; 26 | auto len = strlen(str) + 1; 27 | auto buf = ebbrt::MakeUniqueIOBuf(len); 28 | snprintf(reinterpret_cast(buf->MutData()), len, "%s", str); 29 | std::cout << "Sending to " << nid.ToString() << std::endl; 30 | SendMessage(nid, std::move(buf)); 31 | 32 | } 33 | 34 | void Printer::ReceiveMessage(ebbrt::Messenger::NetworkId nid, 35 | std::unique_ptr&& buffer) { 36 | auto output = std::string(reinterpret_cast(buffer->Data()), 37 | buffer->Length()); 38 | std::cout << nid.ToString() << ": " << output; 39 | } 40 | -------------------------------------------------------------------------------- /apps/helloworld-pool/src/hosted/Printer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_HELLOWORLD_HOSTED_SRC_PRINTER_H_ 6 | #define APPS_HELLOWORLD_HOSTED_SRC_PRINTER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "../../src/StaticEbbIds.h" 14 | 15 | class Printer : public ebbrt::StaticSharedEbb, 16 | public ebbrt::Messagable { 17 | public: 18 | Printer(); 19 | 20 | static ebbrt::Future Init(); 21 | void Print(const char* string); 22 | void Execute(ebbrt::Messenger::NetworkId); 23 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 24 | std::unique_ptr&& buffer); 25 | }; 26 | 27 | constexpr auto printer = ebbrt::EbbRef(kPrinterEbbId); 28 | 29 | #endif // APPS_HELLOWORLD_HOSTED_SRC_PRINTER_H_ 30 | -------------------------------------------------------------------------------- /apps/helloworld-pool/src/hosted/helloworld.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "Printer.h" 16 | 17 | static char* ExecName = 0; 18 | static unsigned int NumNodes = 2; 19 | 20 | void AppMain() { 21 | auto bindir = boost::filesystem::system_complete(ExecName).parent_path() / 22 | "/bm/helloworld.elf32"; 23 | unsigned int num_nodes = NumNodes; 24 | 25 | struct timeval START_TIME; 26 | gettimeofday(&START_TIME, NULL); 27 | Printer::Init().Then([bindir, num_nodes](ebbrt::Future f) { 28 | f.Get(); 29 | try { 30 | ebbrt::pool_allocator->AllocatePool(bindir.string(), num_nodes); 31 | } catch (std::runtime_error& e) { 32 | std::cout << e.what() << std::endl; 33 | exit(1); 34 | } 35 | }); 36 | 37 | 38 | ebbrt::pool_allocator->waitPool().Then([START_TIME](ebbrt::Future f) { 39 | f.Get(); 40 | struct timeval END_TIME; 41 | gettimeofday(&END_TIME, NULL); 42 | std::printf("ALLOCATION TIME: %lf seconds\n", 43 | (END_TIME.tv_sec - START_TIME.tv_sec) + 44 | ((END_TIME.tv_usec - START_TIME.tv_usec) / 1000000.0)); 45 | }); 46 | } 47 | 48 | int main(int argc, char** argv) { 49 | void* status; 50 | 51 | ExecName = argv[0]; 52 | if (argc > 1) { 53 | NumNodes = std::atoi(argv[1]); 54 | } 55 | 56 | pthread_t tid = ebbrt::Cpu::EarlyInit((size_t) NumNodes); 57 | pthread_join(tid, &status); 58 | 59 | // This is redundant I think but I think it is also likely safe 60 | ebbrt::Cpu::Exit(0); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /apps/helloworld/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("helloworld-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | 11 | set(HOSTED_SOURCES 12 | src/hosted/helloworld.cc 13 | src/hosted/Printer.cc) 14 | 15 | set(BAREMETAL_SOURCES 16 | src/baremetal/helloworld.cc 17 | src/baremetal/Printer.cc) 18 | 19 | # Baremetal ======================================================== 20 | 21 | if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") 22 | 23 | add_executable(helloworld.elf ${BAREMETAL_SOURCES}) 24 | add_custom_command(TARGET helloworld.elf POST_BUILD 25 | COMMAND objcopy -O elf32-i386 helloworld.elf helloworld.elf32 ) 26 | 27 | # Hosted =========================================================== 28 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) 29 | 30 | # TODO(jmcadden): remove source-dir requirement 31 | if(DEFINED ENV{EBBRT_SRCDIR}) 32 | list(APPEND CMAKE_MODULE_PATH 33 | "$ENV{EBBRT_SRCDIR}/hosted/cmake/Modules") 34 | endif() 35 | 36 | find_package(EbbRT REQUIRED) 37 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 38 | filesystem system coroutine context ) 39 | find_package(Capnp REQUIRED) 40 | find_package(TBB REQUIRED) 41 | find_package(Threads REQUIRED) 42 | 43 | include_directories(${EBBRT_INCLUDE_DIRS}) 44 | add_executable(helloworld ${HOSTED_SOURCES}) 45 | target_link_libraries(helloworld ${EBBRT_LIBRARIES} 46 | ${CAPNP_LIBRARIES_LITE} ${CMAKE_THREAD_LIBS_INIT} 47 | ${Boost_LIBRARIES} ${TBB_LIBRARIES} 48 | ) 49 | else() 50 | message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") 51 | endif() 52 | -------------------------------------------------------------------------------- /apps/helloworld/expect.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import pexpect 4 | import sys 5 | import time 6 | 7 | filename = sys.argv[1] 8 | child = pexpect.spawn(filename) 9 | child.logfile = sys.stdout 10 | child.expect('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}: Hello World', timeout=60) 11 | child.sendcontrol('c') 12 | child.wait() 13 | -------------------------------------------------------------------------------- /apps/helloworld/src/StaticEbbIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_HELLOWORLD_SRC_STATICEBBIDS_H_ 6 | #define APPS_HELLOWORLD_SRC_STATICEBBIDS_H_ 7 | 8 | #include 9 | 10 | enum : ebbrt::EbbId { kPrinterEbbId = ebbrt::kFirstStaticUserId }; 11 | 12 | #endif // APPS_HELLOWORLD_SRC_STATICEBBIDS_H_ 13 | -------------------------------------------------------------------------------- /apps/helloworld/src/baremetal/Printer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_HELLOWORLD_BAREMETAL_SRC_PRINTER_H_ 6 | #define APPS_HELLOWORLD_BAREMETAL_SRC_PRINTER_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "../../src/StaticEbbIds.h" 13 | 14 | class Printer : public ebbrt::Messagable { 15 | public: 16 | explicit Printer(ebbrt::Messenger::NetworkId nid); 17 | 18 | static Printer& HandleFault(ebbrt::EbbId id); 19 | 20 | void Print(const char* string); 21 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 22 | std::unique_ptr&& buffer); 23 | 24 | private: 25 | ebbrt::Messenger::NetworkId remote_nid_; 26 | }; 27 | 28 | constexpr auto printer = ebbrt::EbbRef(kPrinterEbbId); 29 | 30 | #endif // APPS_HELLOWORLD_BAREMETAL_SRC_PRINTER_H_ 31 | -------------------------------------------------------------------------------- /apps/helloworld/src/baremetal/helloworld.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include "Printer.h" 7 | 8 | void AppMain() { printer->Print("Hello World\n"); } 9 | -------------------------------------------------------------------------------- /apps/helloworld/src/hosted/Printer.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Printer.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | EBBRT_PUBLISH_TYPE(, Printer); 12 | 13 | Printer::Printer() : ebbrt::Messagable(kPrinterEbbId) {} 14 | 15 | ebbrt::Future Printer::Init() { 16 | return ebbrt::global_id_map->Set( 17 | kPrinterEbbId, ebbrt::GlobalIdMap::OptArgs({.data=ebbrt::messenger->LocalNetworkId().ToBytes()})); 18 | } 19 | 20 | void Printer::Print(const char* str) {} 21 | 22 | void Printer::ReceiveMessage(ebbrt::Messenger::NetworkId nid, 23 | std::unique_ptr&& buffer) { 24 | auto output = std::string(reinterpret_cast(buffer->Data()), 25 | buffer->Length()); 26 | std::cout << nid.ToString() << ": " << output; 27 | } 28 | -------------------------------------------------------------------------------- /apps/helloworld/src/hosted/Printer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_HELLOWORLD_HOSTED_SRC_PRINTER_H_ 6 | #define APPS_HELLOWORLD_HOSTED_SRC_PRINTER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "../../src/StaticEbbIds.h" 14 | 15 | class Printer : public ebbrt::StaticSharedEbb, 16 | public ebbrt::Messagable { 17 | public: 18 | Printer(); 19 | 20 | static ebbrt::Future Init(); 21 | void Print(const char* string); 22 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 23 | std::unique_ptr&& buffer); 24 | }; 25 | 26 | constexpr auto printer = ebbrt::EbbRef(kPrinterEbbId); 27 | 28 | #endif // APPS_HELLOWORLD_HOSTED_SRC_PRINTER_H_ 29 | -------------------------------------------------------------------------------- /apps/helloworld/src/hosted/helloworld.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "Printer.h" 15 | 16 | static char* ExecName = 0; 17 | static int NumNodes; 18 | static int ALLOCATED_NODES = 0; 19 | 20 | void AppMain() { 21 | auto bindir = boost::filesystem::system_complete(ExecName).parent_path() / 22 | "/bm/helloworld.elf32"; 23 | 24 | struct timeval START_TIME; 25 | gettimeofday(&START_TIME, NULL); 26 | Printer::Init().Then([bindir, START_TIME](ebbrt::Future f) { 27 | f.Get(); 28 | try { 29 | for (int i = 0; i < NumNodes; i++) { 30 | auto node_desc = ebbrt::node_allocator->AllocateNode(bindir.string()); 31 | node_desc.NetworkId().Then( 32 | [START_TIME](ebbrt::Future f) { 33 | f.Get(); 34 | ALLOCATED_NODES++; 35 | if (ALLOCATED_NODES == NumNodes) { 36 | struct timeval END_TIME; 37 | gettimeofday(&END_TIME, NULL); 38 | std::printf("ALLOCATION TIME: %lf seconds\n", 39 | (END_TIME.tv_sec - START_TIME.tv_sec) + 40 | ((END_TIME.tv_usec - START_TIME.tv_usec) / 1000000.0)); 41 | } 42 | }); 43 | } 44 | } catch (std::runtime_error& e) { 45 | std::cout << e.what() << std::endl; 46 | exit(1); 47 | } 48 | }); 49 | } 50 | 51 | int main(int argc, char** argv) { 52 | void* status; 53 | 54 | ExecName = argv[0]; 55 | if (argc > 1) { 56 | NumNodes = atoi(argv[1]); 57 | } else { 58 | NumNodes = 1; 59 | } 60 | 61 | pthread_t tid = ebbrt::Cpu::EarlyInit(1); 62 | pthread_join(tid, &status); 63 | 64 | // This is redundant I think but I think it is also likely safe 65 | ebbrt::Cpu::Exit(0); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /apps/iperf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("iperf-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | 11 | set(HOSTED_SOURCES 12 | src/hosted/iperf.cc 13 | ) 14 | 15 | set(BAREMETAL_SOURCES 16 | src/native/iperf.cc 17 | ) 18 | 19 | # Baremetal ======================================================== 20 | if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") 21 | add_executable(iperf.elf ${BAREMETAL_SOURCES}) 22 | add_custom_command(TARGET iperf.elf POST_BUILD 23 | COMMAND objcopy -O elf32-i386 iperf.elf iperf.elf32 ) 24 | 25 | # Hosted =========================================================== 26 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) 27 | find_package(EbbRT REQUIRED) 28 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 29 | filesystem system coroutine context ) 30 | find_package(Capnp REQUIRED) 31 | find_package(TBB REQUIRED) 32 | find_package(Threads REQUIRED) 33 | 34 | include_directories(${EBBRT_INCLUDE_DIRS}) 35 | add_executable(iperf ${HOSTED_SOURCES}) 36 | target_link_libraries(iperf ${EBBRT_LIBRARIES} 37 | ${CAPNP_LIBRARIES_LITE} ${CMAKE_THREAD_LIBS_INIT} 38 | ${Boost_LIBRARIES} ${TBB_LIBRARIES} 39 | ) 40 | else() 41 | message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") 42 | endif() 43 | -------------------------------------------------------------------------------- /apps/iperf/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SESA/EbbRT/cc15c2545b0e003d91e946f0f2ffffe5f6b1bff0/apps/iperf/README.md -------------------------------------------------------------------------------- /apps/iperf/src/hosted/iperf.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | static char* ExecName = 0; 17 | 18 | void AppMain() { 19 | auto bindir = boost::filesystem::system_complete(ExecName).parent_path() / 20 | "/bm/iperf.elf32"; 21 | std::cout << "EbbRT-iperf server supports a standard iperf client run with the '-C' compatibility flag" << std::endl; 22 | try { 23 | auto node = ebbrt::node_allocator->AllocateNode(bindir.string(), 2, 2, 2); 24 | node.NetworkId().Then( 25 | [](ebbrt::Future net_if) { 26 | auto net_id = net_if.Get(); 27 | std::cout << "EbbRT-iperf server online: " << net_id.ToString() << ":5201" << std::endl; 28 | 29 | }); 30 | } catch (std::runtime_error &e) { 31 | std::cout << e.what() << std::endl; 32 | exit(1); 33 | } 34 | } 35 | 36 | int main(int argc, char **argv) { 37 | void *status; 38 | 39 | ExecName = argv[0]; 40 | 41 | pthread_t tid = ebbrt::Cpu::EarlyInit(1); 42 | 43 | pthread_join(tid, &status); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /apps/iperf/src/native/iperf.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace ebbrt { 15 | class iPerf : public StaticSharedEbb, public CacheAligned { 16 | public: 17 | iPerf(){}; 18 | void Start(uint16_t port){ 19 | listening_pcb_.Bind(port, [this](NetworkManager::TcpPcb pcb) { 20 | // round-robin connections to cores 21 | static std::atomic cpu_index{0}; 22 | auto index = cpu_index.fetch_add(1) % ebbrt::Cpu::Count(); 23 | pcb.BindCpu(index); 24 | auto connection = new TcpSession(this, std::move(pcb)); 25 | connection->Install(); 26 | }); 27 | } 28 | 29 | private: 30 | class TcpSession : public ebbrt::TcpHandler { 31 | public: 32 | TcpSession(iPerf *iperf, ebbrt::NetworkManager::TcpPcb pcb) 33 | : ebbrt::TcpHandler(std::move(pcb)), iperf_(iperf) {} 34 | void Close(){} 35 | void Abort(){} 36 | void Receive(std::unique_ptr b){ 37 | return; 38 | } 39 | private: 40 | iPerf *iperf_; 41 | }; 42 | NetworkManager::ListeningTcpPcb listening_pcb_; 43 | }; 44 | } 45 | 46 | void AppMain() { 47 | auto iperf = ebbrt::EbbRef(ebbrt::ebb_allocator->AllocateLocal()); 48 | iperf->Start(5201); 49 | ebbrt::kprintf("iPerf server listening on port 5201\n"); 50 | } 51 | -------------------------------------------------------------------------------- /apps/msgtst/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("msgtst-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | 11 | set(HOSTED_SOURCES 12 | src/hosted/msgtst.cc 13 | src/MsgTst.cc) 14 | 15 | set(BAREMETAL_SOURCES 16 | src/MsgTst.cc) 17 | 18 | # Baremetal ======================================================== 19 | if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") 20 | add_executable(msgtst.elf ${BAREMETAL_SOURCES}) 21 | add_custom_command(TARGET msgtst.elf POST_BUILD 22 | COMMAND objcopy -O elf32-i386 msgtst.elf msgtst.elf32 ) 23 | 24 | # Hosted =========================================================== 25 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) 26 | find_package(EbbRT REQUIRED) 27 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 28 | filesystem system coroutine context ) 29 | find_package(Capnp REQUIRED) 30 | find_package(TBB REQUIRED) 31 | find_package(Threads REQUIRED) 32 | 33 | include_directories(${EBBRT_INCLUDE_DIRS}) 34 | add_executable(msgtst ${HOSTED_SOURCES}) 35 | target_link_libraries(msgtst ${EBBRT_LIBRARIES} 36 | ${CAPNP_LIBRARIES_LITE} ${CMAKE_THREAD_LIBS_INIT} 37 | ${Boost_LIBRARIES} ${TBB_LIBRARIES} 38 | ) 39 | else() 40 | message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") 41 | endif() 42 | -------------------------------------------------------------------------------- /apps/msgtst/src/MsgTst.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_MSGTST_SRC_MSGTST_H_ 6 | #define APPS_MSGTST_SRC_MSGTST_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /* The MsgTst Ebb allows both hosted and native implementations to send "PING" 22 | * messages via the messenger to another node (machine). The remote node 23 | * responds back and the initiator fulfills its Promise. */ 24 | 25 | static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 26 | 27 | class MsgTst : public ebbrt::Messagable { 28 | public: 29 | static ebbrt::EbbRef 30 | Create(ebbrt::EbbId id = ebbrt::ebb_allocator->Allocate()); 31 | 32 | MsgTst(ebbrt::EbbId ebbid); 33 | std::unique_ptr RandomMsg(size_t bytes); 34 | static MsgTst& HandleFault(ebbrt::EbbId id); 35 | std::vector> SendMessages(ebbrt::Messenger::NetworkId nid, uint32_t count, size_t size); 36 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 37 | std::unique_ptr&& buffer); 38 | 39 | private: 40 | std::mutex m_; 41 | std::unordered_map> promise_map_; 42 | uint32_t id_{0}; 43 | }; 44 | 45 | #endif // APPS_MSGTST_SRC_MSGTST_H_ 46 | -------------------------------------------------------------------------------- /apps/msgtst/src/StaticEbbIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_MSGTST_SRC_STATICEBBIDS_H_ 6 | #define APPS_MSGTST_SRC_STATICEBBIDS_H_ 7 | 8 | #include 9 | 10 | enum : ebbrt::EbbId { kPrinterEbbId = ebbrt::kFirstStaticUserId }; 11 | 12 | #endif // APPS_MSGTST_SRC_STATICEBBIDS_H_ 13 | -------------------------------------------------------------------------------- /apps/zookeeper_app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("zktest-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | 11 | set(HOSTED_SOURCES 12 | src/InstallGlobalIdMap.cc 13 | src/zktest.cc 14 | ) 15 | 16 | find_package(EbbRTZooKeeper REQUIRED) 17 | find_package(EbbRT REQUIRED) 18 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 19 | filesystem system coroutine context ) 20 | find_package(Capnp REQUIRED) 21 | find_package(TBB REQUIRED) 22 | find_package(Threads REQUIRED) 23 | 24 | include_directories(${EBBRT_INCLUDE_DIRS} 25 | ${EBBRT-ZOOKEEPER_INCLUDE_DIRS}) 26 | add_executable(zktest ${HOSTED_SOURCES}) 27 | target_link_libraries(zktest ${EBBRT_LIBRARIES} 28 | ${CAPNP_LIBRARIES_LITE} ${CMAKE_THREAD_LIBS_INIT} 29 | ${Boost_LIBRARIES} ${TBB_LIBRARIES} 30 | ${EBBRT-ZOOKEEPER_LIBRARIES} ${EBBRT_LIBRARIES} 31 | ) 32 | -------------------------------------------------------------------------------- /apps/zookeeper_app/src/InstallGlobalIdMap.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void ebbrt::InstallGlobalIdMap(){ 5 | ebbrt::kprintf("Installing ZooKeeper GlobalIdMap\n"); 6 | ebbrt::ZKGlobalIdMap::Create(ebbrt::kGlobalIdMapId); 7 | // Do this asynchronously to allow clean bring-up of CPU context 8 | // TODO: do not spawn 9 | #ifndef __ebbrt__ 10 | ebbrt::event_manager->Spawn([]() { zkglobal_id_map->Init();/*.Block();*/ }); 11 | #else 12 | zkglobal_id_map->Init(); 13 | #endif 14 | } 15 | -------------------------------------------------------------------------------- /contrib/appgen/README.md: -------------------------------------------------------------------------------- 1 | # EbbRT Application Generator 2 | 3 | Use this script to generate a simple "hello world" hosted + native EbbRT 4 | application. Usage: `./appgen` 5 | 6 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("{{ title }}-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | 11 | set(HOSTED_SOURCES 12 | src/hosted/{{ title }}.cc 13 | src/hosted/Printer.cc) 14 | 15 | set(BAREMETAL_SOURCES 16 | src/native/{{ title }}.cc 17 | src/native/Printer.cc) 18 | 19 | # Baremetal ======================================================== 20 | if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") 21 | add_executable({{ title }}.elf ${BAREMETAL_SOURCES}) 22 | add_custom_command(TARGET {{ title }}.elf POST_BUILD 23 | COMMAND objcopy -O elf32-i386 {{ title }}.elf {{ title }}.elf32 ) 24 | 25 | # Hosted =========================================================== 26 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) 27 | find_package(EbbRT REQUIRED) 28 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 29 | filesystem system coroutine context ) 30 | find_package(Capnp REQUIRED) 31 | find_package(TBB REQUIRED) 32 | find_package(Threads REQUIRED) 33 | 34 | include_directories(${EBBRT_INCLUDE_DIRS}) 35 | add_executable({{ title }} ${HOSTED_SOURCES}) 36 | target_link_libraries({{ title }} ${EBBRT_LIBRARIES} 37 | ${CAPNP_LIBRARIES_LITE} ${CMAKE_THREAD_LIBS_INIT} 38 | ${Boost_LIBRARIES} ${TBB_LIBRARIES} 39 | ) 40 | else() 41 | message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") 42 | endif() 43 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/src/StaticEbbIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_{{ CAP_TITLE }}_SRC_STATICEBBIDS_H_ 6 | #define APPS_{{ CAP_TITLE }}_SRC_STATICEBBIDS_H_ 7 | 8 | #include 9 | 10 | enum : ebbrt::EbbId { kPrinterEbbId = ebbrt::kFirstStaticUserId }; 11 | 12 | #endif // APPS_{{ CAP_TITLE }}_SRC_STATICEBBIDS_H_ 13 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/src/hosted/Printer.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Printer.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | EBBRT_PUBLISH_TYPE(, Printer); 12 | 13 | Printer::Printer() : ebbrt::Messagable(kPrinterEbbId) {} 14 | 15 | ebbrt::Future Printer::Init() { 16 | return ebbrt::global_id_map->Set( 17 | kPrinterEbbId, ebbrt::GlobalIdMap::OptArgs({.data=ebbrt::messenger->LocalNetworkId().ToBytes()})); 18 | } 19 | 20 | void Printer::Print(const char* str) {} 21 | 22 | void Printer::ReceiveMessage(ebbrt::Messenger::NetworkId nid, 23 | std::unique_ptr&& buffer) { 24 | auto output = std::string(reinterpret_cast(buffer->Data()), 25 | buffer->Length()); 26 | std::cout << nid.ToString() << ": " << output; 27 | } 28 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/src/hosted/Printer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_{{ CAP_TITLE }}_HOSTED_SRC_PRINTER_H_ 6 | #define APPS_{{ CAP_TITLE }}_HOSTED_SRC_PRINTER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "../../src/StaticEbbIds.h" 14 | 15 | class Printer : public ebbrt::StaticSharedEbb, 16 | public ebbrt::Messagable { 17 | public: 18 | Printer(); 19 | 20 | static ebbrt::Future Init(); 21 | void Print(const char* string); 22 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 23 | std::unique_ptr&& buffer); 24 | }; 25 | 26 | constexpr auto printer = ebbrt::EbbRef(kPrinterEbbId); 27 | 28 | #endif // APPS_{{ CAP_TITLE }}_HOSTED_SRC_PRINTER_H_ 29 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/src/hosted/title.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "Printer.h" 15 | 16 | static char* ExecName = 0; 17 | 18 | void AppMain() { 19 | auto bindir = boost::filesystem::system_complete(ExecName).parent_path() / 20 | "/bm/{{ title }}.elf32"; 21 | 22 | Printer::Init().Then([bindir](ebbrt::Future f) { 23 | f.Get(); 24 | try { 25 | ebbrt::node_allocator->AllocateNode(bindir.string()); 26 | } catch (std::runtime_error &e) { 27 | std::cout << e.what() << std::endl; 28 | exit(1); 29 | } 30 | }); 31 | } 32 | 33 | int main(int argc, char **argv) { 34 | void *status; 35 | 36 | ExecName = argv[0]; 37 | 38 | pthread_t tid = ebbrt::Cpu::EarlyInit(1); 39 | 40 | pthread_join(tid, &status); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/src/native/Printer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef APPS_{{ CAP_TITLE }}_BAREMETAL_SRC_PRINTER_H_ 6 | #define APPS_{{ CAP_TITLE }}_BAREMETAL_SRC_PRINTER_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "../../src/StaticEbbIds.h" 13 | 14 | class Printer : public ebbrt::Messagable { 15 | public: 16 | explicit Printer(ebbrt::Messenger::NetworkId nid); 17 | 18 | static Printer& HandleFault(ebbrt::EbbId id); 19 | 20 | void Print(const char* string); 21 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 22 | std::unique_ptr&& buffer); 23 | 24 | private: 25 | ebbrt::Messenger::NetworkId remote_nid_; 26 | }; 27 | 28 | constexpr auto printer = ebbrt::EbbRef(kPrinterEbbId); 29 | 30 | #endif // APPS_{{ CAP_TITLE }}_BAREMETAL_SRC_PRINTER_H_ 31 | -------------------------------------------------------------------------------- /contrib/appgen/template/default/src/native/title.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include "Printer.h" 7 | 8 | void AppMain() { printer->Print("{{ CAP_TITLE }} BACKEND UP.\n"); } 9 | -------------------------------------------------------------------------------- /contrib/appgen/template/native/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 2 | project("{{ title }}-ebbrt" C CXX) 3 | 4 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 6 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 8 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -Wall -Werror") 10 | set(BAREMETAL_SOURCES src/{{ title }}.cc) 11 | 12 | if( ${CMAKE_SYSTEM_NAME} STREQUAL "EbbRT") 13 | add_executable({{ title }}.elf ${BAREMETAL_SOURCES}) 14 | add_custom_command(TARGET {{ title }}.elf POST_BUILD 15 | COMMAND objcopy -O elf32-i386 {{ title }}.elf {{ title }}.elf32 ) 16 | 17 | # Hosted =========================================================== 18 | elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) 19 | message(FATAL_ERROR "System name unsupported: ${CMAKE_SYSTEM_NAME}") 20 | endif() 21 | -------------------------------------------------------------------------------- /contrib/appgen/template/native/Makefile: -------------------------------------------------------------------------------- 1 | MYDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) 2 | 3 | CD ?= cd 4 | CMAKE ?= cmake 5 | CP ?= cp 6 | ECHO ?= echo 7 | MAKE ?= make 8 | MKDIR ?= mkdir 9 | 10 | EBBRTSYSROOT ?= $(abspath $(EBBRT_SYSROOT)) 11 | CMAKE_TOOLCHAIN_FILE ?= $(EBBRTSYSROOT)/usr/misc/ebbrt.cmake 12 | BAREMETAL_PREFIX_PATH= $(EBBRTSYSROOT)/usr/ 13 | 14 | BUILD_PATH ?= $(MYDIR) 15 | DEBUG_PATH ?= $(BUILD_PATH)/Debug 16 | RELEASE_PATH ?= $(BUILD_PATH)/Release 17 | BAREMETAL_DEBUG_DIR ?= $(DEBUG_PATH) 18 | BAREMETAL_RELEASE_DIR ?= $(RELEASE_PATH) 19 | 20 | all: Debug Release 21 | native: native-debug native-release 22 | Debug: native-debug 23 | Release: native-release 24 | 25 | # ENVIRONMENT VARIABLES 26 | check-ebbrt-sysroot: 27 | ifndef EBBRT_SYSROOT 28 | $(error EBBRT_SYSROOT is undefined) 29 | endif 30 | 31 | $(BUILD_PATH): 32 | $(MKDIR) $@ 33 | 34 | $(DEBUG_PATH): | $(BUILD_PATH) 35 | $(MKDIR) $@ 36 | 37 | $(RELEASE_PATH): | $(BUILD_PATH) 38 | $(MKDIR) $@ 39 | 40 | ifneq ($(DEBUG_PATH), $(BAREMETAL_DEBUG_DIR)) 41 | $(BAREMETAL_DEBUG_DIR): | $(DEBUG_PATH) 42 | $(MKDIR) $@ 43 | endif 44 | 45 | ifneq ($(RELEASE_PATH), $(BAREMETAL_RELEASE_DIR)) 46 | $(BAREMETAL_RELEASE_DIR): | $(RELEASE_PATH) 47 | $(MKDIR) $@ 48 | endif 49 | 50 | native-debug: | check-ebbrt-sysroot $(BAREMETAL_DEBUG_DIR) 51 | $(CD) $(BAREMETAL_DEBUG_DIR) && \ 52 | EBBRT_SYSROOT=$(EBBRTSYSROOT) $(CMAKE) -DCMAKE_BUILD_TYPE=Debug \ 53 | -DCMAKE_PREFIX_PATH=$(BAREMETAL_PREFIX_PATH) \ 54 | -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) $(MYDIR) && $(MAKE) 55 | 56 | native-release: | check-ebbrt-sysroot $(BAREMETAL_RELEASE_DIR) 57 | $(CD) $(BAREMETAL_RELEASE_DIR) && \ 58 | EBBRT_SYSROOT=$(EBBRTSYSROOT) $(CMAKE) -DCMAKE_BUILD_TYPE=Release \ 59 | -DCMAKE_PREFIX_PATH=$(BAREMETAL_PREFIX_PATH) \ 60 | -DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) $(MYDIR) && \ 61 | $(MAKE) 62 | 63 | 64 | clean: 65 | $(MAKE) clean -C $(BAREMETAL_DEBUG_DIR) && \ 66 | $(MAKE) clean -C $(BAREMETAL_RELEASE_DIR) 67 | 68 | .PHONY: Debug Release all clean native native-debug native-release 69 | -------------------------------------------------------------------------------- /contrib/appgen/template/native/src/title.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | void AppMain() { ebbrt::kprintf_force("{{ CAP_TITLE }} BACKEND UP.\n"); } 9 | -------------------------------------------------------------------------------- /contrib/clean_running_apps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Manual clean-up of docker networks and containers created by the EbbRT NodeAllocator 4 | if [[ -z $1 ]]; then 5 | read -p "Remove all of your ($USER) ebbrt networks and nodes. Continue [Y]es, [n]o? " c 6 | case "$c" in 7 | n|N ) exit 0; 8 | esac 9 | fi 10 | 11 | echo "Removing docker containers..." 12 | docker ps | grep ebbrt-$(id -u) | cut -d ' ' -f 1 | while read id; do docker rm -f $id; done 13 | 14 | echo "Removing docker networks..." 15 | docker network ls | grep ebbrt-$(id -u) | cut -d ' ' -f 9 | while read id; do docker network rm $id; done 16 | 17 | -------------------------------------------------------------------------------- /contrib/dschatz/howtorun: -------------------------------------------------------------------------------- 1 | g++ -g3 -std=c++11 -I /home/dschatz/Work/SESA/EbbRT/hosted/src/include/ -I /home/dschatz/Work/SESA/EbbRT/common/src/include/ test.cpp libEbbRT.a -lboost_filesystem -lboost_system -lcapnp -lkj -lfdt -pthread -o test 2 | -------------------------------------------------------------------------------- /contrib/dschatz/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | 4 | # To enable this Git hook, copy file to: /.git/hooks/pre-commit 5 | 6 | git diff --full-index --binary > /tmp/stash.$$ 7 | git stash -q --keep-index 8 | 9 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 10 | GIT_ROOT=$DIR/../.. 11 | RESULT=0 12 | while read status file 13 | do 14 | clang-format -style=file "$GIT_ROOT/$file" | \ 15 | diff "$GIT_ROOT/$file" - 16 | if [ $? -ne 0 ]; then 17 | echo "$file is not clang-formatted" 18 | let RESULT=1 19 | continue 20 | fi 21 | $GIT_ROOT/contrib/dschatz/cpplint.py \ 22 | --filter=-build/include_order,-runtime/references,-build/c++11,-whitespace/operators "$GIT_ROOT/$file" 23 | if [ $? -ne 0 ]; then 24 | let RESULT=1 25 | continue 26 | fi 27 | done < <(git diff --cached --name-status --diff-filter=ACM | \ 28 | grep -P '\.((cc)|(h))$') 29 | 30 | if [ -s /tmp/stash.$$ ]; then 31 | git apply --whitespace=nowarn < /tmp/stash.$$ && git stash drop -q 32 | else 33 | git stash drop -q 34 | fi 35 | 36 | rm /tmp/stash.$$ 37 | 38 | [ $RESULT -ne 0 ] && exit 1 39 | exit 0 40 | -------------------------------------------------------------------------------- /contrib/dschatz/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() { 11 | ebbrt::Runtime runtime; 12 | ebbrt::Context c(runtime); 13 | boost::asio::signal_set sig(c.io_service_, SIGINT); 14 | { 15 | ebbrt::ContextActivation activation(c); 16 | 17 | // ensure clean quit on ctrl-c 18 | sig.async_wait([&c](const boost::system::error_code& ec, 19 | int signal_number) { c.io_service_.stop(); }); 20 | 21 | ebbrt::global_id_map->Set(ebbrt::kFirstStaticUserId, "test\n").Then([]( 22 | ebbrt::Future f) { 23 | f.Get(); 24 | ebbrt::node_allocator->AllocateNode( 25 | "/home/dschatz/Work/SESA/EbbRT/baremetal/build/debug/ebbrt.elf32"); 26 | }); 27 | } 28 | c.Run(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /contrib/jappavoo.html: -------------------------------------------------------------------------------- 1 |

2 | Clone the following respository any place you like. 3 | It contains some applications that can be compiled 4 | by pointing it back to where you have the EbbRT source. 5 |

6 | 7 |

8 | http://github.com/jappavoo/ebbrt-contrib 9 |

10 | -------------------------------------------------------------------------------- /contrib/launch.sh: -------------------------------------------------------------------------------- 1 | ../misc/docker/kvm-qemu/launch.sh -------------------------------------------------------------------------------- /doc/debugging.md: -------------------------------------------------------------------------------- 1 | # Debugging the EbbRT native runtime with GDB 2 | The EbbRT native runtime provides support for the gdb debugger, which can be 3 | used to connect remotly to a running EbbRT back-end VM. Debugging on EbbRT supports the normal `gdb` commands and functionality. 4 | 5 | Note, for full debug transparency, building you application unoptimised and with debug symbols is not enough. Your application must also link with Ebb libraries that have been similarly build for debugging. In general, this is done by passing `CMAKE_BUILD_TYPE=Debug` when using `cmake`. See our build tutorial for instructions for building the EbbRT toolchain for debugging. 6 | 7 | ####Step 1. 8 | When a new node is allocated, the `NodeAllocator` will give a local and remote gdb address: 9 | ``` 10 | Node Allocation Details: 11 | | gdb: 172.19.0.2:1234 12 | | gdb(local): localhost:34042 13 | | container: 227e3f58fade 14 | ``` 15 | Note, only the Debug `NodeAllocator` will provide the gdb service on back-ends. 16 | 17 | ####Step 2. 18 | Open the native `.elf` file in gdb (*note: not the .elf32*) 19 | ``` 20 | $ gdb app.elf 21 | ``` 22 | 23 | ####Step 4. 24 | Within gdb, connect to the remote gdb addresses. It may take a few seconds to connect... 25 | ``` 26 | (gdb) target remote 172.19.0.2:34042 27 | ``` 28 | Once gdb connect, the native runtime will have already have begun execution. Normal `gdb` commands and functions are supported. Good luck! 29 | -------------------------------------------------------------------------------- /doc/ebbrt-OSDI_16.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SESA/EbbRT/cc15c2545b0e003d91e946f0f2ffffe5f6b1bff0/doc/ebbrt-OSDI_16.pdf -------------------------------------------------------------------------------- /doc/img/memcached_results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SESA/EbbRT/cc15c2545b0e003d91e946f0f2ffffe5f6b1bff0/doc/img/memcached_results.png -------------------------------------------------------------------------------- /doc/img/nodejs_results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SESA/EbbRT/cc15c2545b0e003d91e946f0f2ffffe5f6b1bff0/doc/img/nodejs_results.png -------------------------------------------------------------------------------- /doc/img/objective.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SESA/EbbRT/cc15c2545b0e003d91e946f0f2ffffe5f6b1bff0/doc/img/objective.png -------------------------------------------------------------------------------- /libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | project(EbbRT-libs CXX ASM) 3 | 4 | # EbbRT Library to build by default 5 | set(subdirs 6 | cmdline 7 | filesystem 8 | socket 9 | ) 10 | foreach(subdir ${subdirs}) 11 | add_subdirectory(${subdir}) 12 | endforeach() 13 | -------------------------------------------------------------------------------- /libs/cmdline/CmdLineArgs.capnp: -------------------------------------------------------------------------------- 1 | @0x9b8d5550476d8341; 2 | 3 | using Cxx = import "/capnp/c++.capnp"; 4 | $Cxx.namespace("cmdlineargs"); 5 | 6 | struct GlobalData { 7 | args @0 :List(Text); 8 | } -------------------------------------------------------------------------------- /libs/cmdline/CmdLineArgs.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CMDLINEARGS_H_ 6 | #define CMDLINEARGS_H_ 7 | 8 | #include 9 | #include 10 | 11 | class CmdLineArgs { 12 | public: 13 | CmdLineArgs(std::vector args); 14 | 15 | static CmdLineArgs &HandleFault(ebbrt::EbbId id); 16 | static ebbrt::Future > 17 | Create(int argc, char **argv, 18 | ebbrt::EbbId id = ebbrt::ebb_allocator->Allocate()); 19 | 20 | int argc() { return args_.size(); } 21 | char **argv() { return argv_.data(); } 22 | 23 | private: 24 | std::vector args_; 25 | std::vector argv_; 26 | }; 27 | 28 | #endif // CMDLINEARGS_H_ 29 | -------------------------------------------------------------------------------- /libs/cmdline/EbbRTCmdLineConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set_and_check(EBBRT-CMDLINE_INCLUDE_DIRS "@PACKAGE_INSTALL_INCLUDE_DIR@") 4 | set_and_check(EBBRT-CMDLINE_LIBRARIES "@PACKAGE_INSTALL_LIB_DIR@/libebbrt-cmdline.a") 5 | 6 | check_required_components(ebbrt-cmdline) 7 | -------------------------------------------------------------------------------- /libs/cmdline/README.md: -------------------------------------------------------------------------------- 1 | EbbRT cmdline library 2 | === 3 | 4 | ## Requirements 5 | 6 | * (Optional) Set the `EBBRT_SRCDIR` environment variable to point to 7 | EbbRT source directory `export EBBRT_SRCDIR=~/EbbRT` 8 | * Build and install EbbRT native toolchain, assume installed at `~/sysroot/native` 9 | * Build and install EbbRT hosted library, assume installed at `~/sysroot/hosted` 10 | 11 | ## Build and install for hosted 12 | 13 | ``` 14 | mkdir hosted 15 | cd hosted 16 | cmake -DCMAKE_INSTALL_PREFIX=~/sysroot/hosted -DCMAKE_PREFIX_PATH=~/sysroot/hosted .. 17 | make -j install 18 | ``` 19 | 20 | ## Build and install for native 21 | 22 | ``` 23 | mkdir native 24 | cd native 25 | cmake -DCMAKE_TOOLCHAIN_FILE=~/sysroot/native/usr/misc/ebbrt.cmake .. 26 | make -j install 27 | ``` 28 | -------------------------------------------------------------------------------- /libs/filesystem/EbbRTFilesystemConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set_and_check(EBBRT-FILESYSTEM_INCLUDE_DIRS "@PACKAGE_INSTALL_INCLUDE_DIR@") 4 | set_and_check(EBBRT-FILESYSTEM_LIBRARIES "@PACKAGE_INSTALL_LIB_DIR@/libebbrt-filesystem.a") 5 | 6 | check_required_components(ebbrt-filesystem) 7 | -------------------------------------------------------------------------------- /libs/filesystem/FileSystem.capnp: -------------------------------------------------------------------------------- 1 | @0xa11e7074f65137ca; 2 | 3 | using Cxx = import "/capnp/c++.capnp"; 4 | $Cxx.namespace("filesystem"); 5 | 6 | struct GlobalData { 7 | networkAddress @0 :Data; 8 | } 9 | 10 | struct StatRequest { 11 | id @0 :UInt32; 12 | file :union { 13 | path @1 :Text; 14 | lpath @2 :Text; 15 | fd @3 :Int32; 16 | } 17 | } 18 | 19 | struct StatReply { 20 | id @0 :UInt32; 21 | dev @1 :UInt64; 22 | ino @2 :UInt64; 23 | mode @3 :UInt64; 24 | nlink @4 :UInt64; 25 | uid @5 :UInt64; 26 | gid @6 :UInt64; 27 | rdev @7 :UInt64; 28 | size @8 :UInt64; 29 | atime @9 :UInt64; 30 | mtime @10 :UInt64; 31 | ctime @11 :UInt64; 32 | } 33 | 34 | struct GetCwdRequest { 35 | id @0 :UInt32; 36 | } 37 | 38 | struct GetCwdReply { 39 | id @0 :UInt32; 40 | cwd @1 :Text; 41 | } 42 | 43 | struct OpenRequest { 44 | id @0 :UInt32; 45 | flags @1 :Int32; 46 | mode @2 :Int32; 47 | path @3 :Text; 48 | } 49 | 50 | struct OpenReply { 51 | id @0 :UInt32; 52 | fd @1 :UInt32; 53 | } 54 | 55 | struct ReadRequest { 56 | id @0 :UInt32; 57 | fd @1 :UInt32; 58 | length @2 :UInt64; 59 | offset @3 :Int64; 60 | } 61 | 62 | struct ReadReply { 63 | id @0 :UInt32; 64 | data @1 :Data; 65 | } 66 | 67 | struct Request { 68 | union { 69 | statRequest @0 :StatRequest; 70 | getCwdRequest @1 :GetCwdRequest; 71 | openRequest @2 :OpenRequest; 72 | readRequest @3 :ReadRequest; 73 | } 74 | } 75 | 76 | struct Reply { 77 | union { 78 | statReply @0 :StatReply; 79 | getCwdReply @1 :GetCwdReply; 80 | openReply @2 :OpenReply; 81 | readReply @3 :ReadReply; 82 | } 83 | } 84 | 85 | struct Message { 86 | union { 87 | request @0 :Request; 88 | reply @1 :Reply; 89 | } 90 | } -------------------------------------------------------------------------------- /libs/filesystem/FileSystem.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef FILESYSTEM_H_ 6 | #define FILESYSTEM_H_ 7 | 8 | #include 9 | #include 10 | 11 | class FileSystem : public ebbrt::SharedEbb, 12 | public ebbrt::Messagable { 13 | public: 14 | struct StatInfo { 15 | uint64_t stat_dev; 16 | uint64_t stat_ino; 17 | uint64_t stat_mode; 18 | uint64_t stat_nlink; 19 | uint64_t stat_uid; 20 | uint64_t stat_gid; 21 | uint64_t stat_rdev; 22 | uint64_t stat_size; 23 | uint64_t stat_atime; 24 | uint64_t stat_mtime; 25 | uint64_t stat_ctime; 26 | }; 27 | 28 | FileSystem(ebbrt::EbbId id, ebbrt::Messenger::NetworkId frontend_id); 29 | 30 | static ebbrt::Future PreCreate(ebbrt::EbbId id); 31 | static FileSystem &CreateRep(ebbrt::EbbId id); 32 | static void DestroyRep(ebbrt::EbbId id, FileSystem &rep); 33 | ebbrt::Future Stat(const char *path); 34 | ebbrt::Future LStat(const char *path); 35 | ebbrt::Future FStat(int fd); 36 | ebbrt::Future GetCwd(); 37 | ebbrt::Future Open(const char *path, int flags, int mode); 38 | ebbrt::Future Read(int fd, size_t length, int64_t offset); 39 | 40 | private: 41 | void ReceiveMessage(ebbrt::Messenger::NetworkId nid, 42 | std::unique_ptr &&buffer); 43 | 44 | ebbrt::Messenger::NetworkId frontend_id_; 45 | std::mutex lock_; 46 | uint32_t request_; 47 | std::unordered_map > stat_promises_; 48 | std::unordered_map > string_promises_; 49 | std::unordered_map > open_promises_; 50 | 51 | friend ebbrt::Messagable; 52 | }; 53 | 54 | #endif // FILESYSTEM_H_ 55 | -------------------------------------------------------------------------------- /libs/filesystem/README.md: -------------------------------------------------------------------------------- 1 | EbbRT filesystem library 2 | === 3 | 4 | ## Requirements 5 | 6 | * (Optional) Set the `EBBRT_SRCDIR` environment variable to point to 7 | EbbRT source directory `export EBBRT_SRCDIR=~/EbbRT` 8 | * Build and install EbbRT native toolchain, assume installed at `~/sysroot/native` 9 | * Build and install EbbRT hosted library, assume installed at `~/sysroot/hosted` 10 | 11 | ## Build and install for hosted 12 | 13 | ``` 14 | mkdir hosted 15 | cd hosted 16 | cmake -DCMAKE_INSTALL_PREFIX=~/sysroot/hosted -DCMAKE_PREFIX_PATH=~/sysroot/hosted .. 17 | make -j install 18 | ``` 19 | 20 | ## Build and install for native 21 | 22 | ``` 23 | mkdir native 24 | cd native 25 | cmake -DCMAKE_TOOLCHAIN_FILE=~/sysroot/native/usr/misc/ebbrt.cmake .. 26 | make -j install 27 | ``` 28 | -------------------------------------------------------------------------------- /libs/socket/EbbRTSocketConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | set_and_check(EBBRT-SOCKET_INCLUDE_DIR "@PACKAGE_INSTALL_INCLUDE_DIR@") 3 | set_and_check(EBBRT-SOCKET_LWIP_INCLUDE_DIR "@PACKAGE_INSTALL_LWIP_INCLUDE_DIR@") 4 | set_and_check(EBBRT-SOCKET_GNU_INCLUDE_DIR "@PACKAGE_INSTALL_GNU_INCLUDE_DIR@") 5 | set_and_check(EBBRT-SOCKET_POSIX_INCLUDE_DIR "@PACKAGE_INSTALL_POSIX_INCLUDE_DIR@") 6 | set_and_check(EBBRT-SOCKET_LIBRARIES "@PACKAGE_INSTALL_LIB_DIR@/libebbrt-socket.a") 7 | 8 | set( EBBRT-SOCKET_INCLUDE_DIRS 9 | ${EBBRT-SOCKET_INCLUDE_DIR} 10 | ${EBBRT-SOCKET_LWIP_INCLUDE_DIR} 11 | ${EBBRT-SOCKET_POSIX_INCLUDE_DIR} 12 | ${EBBRT-SOCKET_GNU_INCLUDE_DIR} 13 | ) 14 | 15 | check_required_components(ebbrt-socket) 16 | -------------------------------------------------------------------------------- /libs/socket/README.md: -------------------------------------------------------------------------------- 1 | # EbbRT-Socket 2 | Socket API library for EbbRT native runtime 3 | -------------------------------------------------------------------------------- /libs/socket/Vfs.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | // 6 | 7 | #include "Vfs.h" 8 | #include 9 | 10 | int ebbrt::Vfs::RegisterFd(ebbrt::EbbRef ref) { 11 | auto fd = fd_++; 12 | descriptor_map_.emplace(fd, std::move(ref)); 13 | return fd; 14 | } 15 | 16 | ebbrt::EbbRef ebbrt::Vfs::Lookup(int fd) { 17 | auto it = descriptor_map_.find(fd); 18 | if (it == descriptor_map_.end()) { 19 | throw std::invalid_argument("Failed to locate file descriptor"); 20 | } 21 | return it->second; 22 | } 23 | -------------------------------------------------------------------------------- /libs/socket/Vfs.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2016. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef VFS_H_ 6 | #define VFS_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace ebbrt { 20 | 21 | class Vfs : public ebbrt::StaticSharedEbb, public CacheAligned { 22 | public: 23 | class Fd { 24 | public: 25 | class Root { 26 | public: 27 | virtual Fd& HandleFault(EbbId id) = 0; 28 | 29 | private: 30 | friend class Fd; 31 | }; 32 | static Fd& HandleFault(EbbId id) { 33 | LocalIdMap::ConstAccessor accessor; 34 | auto found = local_id_map->Find(accessor, id); 35 | if (!found) 36 | throw std::runtime_error("Failed to find root for Fd"); 37 | auto rep = boost::any_cast(accessor->second); 38 | return rep->HandleFault(id); 39 | }; 40 | virtual ~Fd(){}; 41 | virtual ebbrt::Future> Read(size_t len) = 0; 42 | virtual ebbrt::Future Close() = 0; 43 | // virtual void IsReady() = 0; 44 | // virtual void Lseek() = 0; 45 | virtual void Write(std::unique_ptr) = 0; 46 | virtual uint32_t GetFlags() = 0; 47 | virtual void SetFlags(uint32_t) = 0; 48 | }; 49 | explicit Vfs() : fd_{0} {}; 50 | int RegisterFd(ebbrt::EbbRef); 51 | ebbrt::EbbRef Lookup(int fd_int); 52 | 53 | private: 54 | std::atomic_int fd_; 55 | std::unordered_map> descriptor_map_; 56 | }; 57 | 58 | static const auto root_vfs = EbbRef(GenerateStaticEbbId("Vfs")); 59 | 60 | } // namespace ebbrt 61 | #endif // VFS_H_ 62 | -------------------------------------------------------------------------------- /libs/socket/gnu/include/features.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libs/socket/gnu/include/poll.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/arch/sys_arch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SESA/EbbRT/cc15c2545b0e003d91e946f0f2ffffe5f6b1bff0/libs/socket/lwip/include/arch/sys_arch.h -------------------------------------------------------------------------------- /libs/socket/lwip/include/lwip/arch/cc.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_LWIPCC_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_LWIPCC_H_ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #ifndef BYTE_ORDER 17 | #if __BYTE_ORDER == __ORDER_BIG_ENDIAN__ 18 | #define BYTE_ORDER BIG_ENDIAN 19 | #else 20 | #define BYTE_ORDER LITTLE_ENDIAN 21 | #endif 22 | #endif 23 | 24 | typedef uint8_t u8_t; 25 | typedef int8_t s8_t; 26 | typedef uint16_t u16_t; 27 | typedef int16_t s16_t; 28 | typedef uint32_t u32_t; 29 | typedef int32_t s32_t; 30 | 31 | typedef uintptr_t mem_ptr_t; 32 | 33 | #define LWIP_ERR_T int 34 | 35 | #define U16_F PRIu16 36 | #define S16_F PRId16 37 | #define X16_F PRIx16 38 | #define U32_F PRIu32 39 | #define S32_F PRId32 40 | #define X32_F PRIx32 41 | 42 | #define PACK_STRUCT_FIELD(x) x 43 | #define PACK_STRUCT_STRUCT __attribute__((packed)) 44 | #define PACK_STRUCT_BEGIN 45 | #define PACK_STRUCT_END 46 | 47 | extern void lwip_printf(const char* fmt, ...); 48 | 49 | #define LWIP_PLATFORM_DIAG(x) \ 50 | do { \ 51 | lwip_printf x; \ 52 | } while (0) 53 | 54 | extern void lwip_assert(const char* fmt, ...); 55 | 56 | #define LWIP_PLATFORM_ASSERT(x) \ 57 | do { \ 58 | lwip_assert(x); \ 59 | } while (1) 60 | 61 | extern uint32_t lwip_rand(); 62 | 63 | #define LWIP_RAND() lwip_rand() 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_LWIPCC_H_ 70 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/lwipopts.h: -------------------------------------------------------------------------------- 1 | #include "errno.h" 2 | #define LWIP_NETCONN 1 3 | #define NO_SYS 1 4 | #define MEM_LIBC_MALLOC 1 5 | #define MEMP_MEM_MALLOC 1 6 | #define LWIP_DNS 1 7 | #define LWIP_TIMEVAL_PRIVATE 0 /* timeval available in time.h */ 8 | #define SYS_ARCH_TIMEOUT 0 9 | #define LWIP_PREFIX_BYTEORDER_FUNCS 0 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/posix/arpa/inet.h: -------------------------------------------------------------------------------- 1 | #include "lwip/sockets.h" 2 | #include "posix/arpa/inet_aton.h" 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | uint32_t htonl(uint32_t hostlong); 9 | 10 | uint16_t htons(uint16_t hostshort); 11 | 12 | uint32_t ntohl(uint32_t netlong); 13 | 14 | uint16_t ntohs(uint16_t netshort); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/posix/netdb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/netdb.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/netdb.h" 34 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/posix/netinet/in.h: -------------------------------------------------------------------------------- 1 | #include "posix/arpa/inet.h" 2 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/posix/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | #include "lwip/sockets.h" 2 | -------------------------------------------------------------------------------- /libs/socket/lwip/include/posix/sys/socket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/sockets.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/sockets.h" 34 | -------------------------------------------------------------------------------- /libs/zookeeper/EbbRTZooKeeperConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | set_and_check(EBBRT-ZOOKEEPER_LIBRARIES 3 | "@PACKAGE_INSTALL_LIB_DIR@/libebbrt-zookeeper.a") 4 | set_and_check(EBBRT-ZOOKEEPER_INCLUDE_DIR "@PACKAGE_INSTALL_INCLUDE_DIR@") 5 | set_and_check(EBBRT-ZOOKEEPER_ZOOKEEPER_INCLUDE_DIR 6 | "@PACKAGE_INSTALL_ZOOKEEPER_INCLUDE_DIR@") 7 | 8 | set( EBBRT-ZOOKEEPER_INCLUDE_DIRS 9 | ${EBBRT_ZOOKEEPER_INCLUDE_DIR} 10 | ${EBBRT-ZOOKEEPER_ZOOKEEPER_INCLUDE_DIR} 11 | ) 12 | 13 | 14 | check_required_components(ebbrt-zookeeper) 15 | -------------------------------------------------------------------------------- /libs/zookeeper/README.md: -------------------------------------------------------------------------------- 1 | ## ZooKeeper Ebb Library 2 | 3 | ### Build: 4 | 5 | **Hosted:** 6 | Hosted requires libzookeeper-mt 7 | ``` 8 | mkdir -p build/hosted 9 | cmake -DCMAKE_INSTALL_PREFIX={HOSTED_INSTALL_PATH} -DCMAKE_PREFIX_PATH={HOSTED_INSTALL_PATH} ../../ 10 | make -j install 11 | ``` 12 | 13 | **Native:** 14 | Native required EbbRT-socket library to be installed to the sysroot 15 | ``` 16 | mkdir -p build/hosted 17 | EBBRT_SYSROOT={NATIVE_INSTALL_PATH} cmake -DCMAKE_TOOLCHAIN_FILE={NATIVE_INSTALL_PATH}/usr/misc/ebbrt.cmake 18 | make -j install 19 | ``` 20 | -------------------------------------------------------------------------------- /libs/zookeeper/zookeeper/README: -------------------------------------------------------------------------------- 1 | 2 | Removes mt files: 3 | src/cli.c 4 | src/load_gen.c 5 | src/mt_adaptor.c 6 | 7 | Stub out includes: 8 | sys/select.h // main 9 | poll.h // zookeeper.c 10 | netinet/in.h 11 | netinet/tcp.h 12 | arpa/inet.h 13 | 14 | 15 | 16 | 17 | ADD TO POSIX: 18 | arpa/inet.h -> (only) htonl, htons, ntohl, ntohs 19 | stdlib.h -> random, srandom 20 | -------------------------------------------------------------------------------- /libs/zookeeper/zookeeper/etc/kludge.h: -------------------------------------------------------------------------------- 1 | #ifdef __ebbrt__ 2 | #define srandom(x) 3 | #define random() 0 4 | #endif 5 | -------------------------------------------------------------------------------- /libs/zookeeper/zookeeper/include/proto.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef PROTO_H_ 19 | #define PROTO_H_ 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define ZOO_NOTIFY_OP 0 26 | #define ZOO_CREATE_OP 1 27 | #define ZOO_DELETE_OP 2 28 | #define ZOO_EXISTS_OP 3 29 | #define ZOO_GETDATA_OP 4 30 | #define ZOO_SETDATA_OP 5 31 | #define ZOO_GETACL_OP 6 32 | #define ZOO_SETACL_OP 7 33 | #define ZOO_GETCHILDREN_OP 8 34 | #define ZOO_SYNC_OP 9 35 | #define ZOO_PING_OP 11 36 | #define ZOO_GETCHILDREN2_OP 12 37 | #define ZOO_CHECK_OP 13 38 | #define ZOO_MULTI_OP 14 39 | #define ZOO_CLOSE_OP -11 40 | #define ZOO_SETAUTH_OP 100 41 | #define ZOO_SETWATCHES_OP 101 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /*PROTO_H_*/ 48 | -------------------------------------------------------------------------------- /libs/zookeeper/zookeeper/include/zookeeper_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #ifndef ZK_LOG_H_ 20 | #define ZK_LOG_H_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | extern ZOOAPI ZooLogLevel logLevel; 29 | #define LOGSTREAM getLogStream() 30 | 31 | #define LOG_ERROR(x) if(logLevel>=ZOO_LOG_LEVEL_ERROR) \ 32 | log_message(ZOO_LOG_LEVEL_ERROR,__LINE__,__func__,format_log_message x) 33 | #define LOG_WARN(x) if(logLevel>=ZOO_LOG_LEVEL_WARN) \ 34 | log_message(ZOO_LOG_LEVEL_WARN,__LINE__,__func__,format_log_message x) 35 | #define LOG_INFO(x) if(logLevel>=ZOO_LOG_LEVEL_INFO) \ 36 | log_message(ZOO_LOG_LEVEL_INFO,__LINE__,__func__,format_log_message x) 37 | #define LOG_DEBUG(x) if(logLevel==ZOO_LOG_LEVEL_DEBUG) \ 38 | log_message(ZOO_LOG_LEVEL_DEBUG,__LINE__,__func__,format_log_message x) 39 | 40 | ZOOAPI void log_message(ZooLogLevel curLevel, int line,const char* funcName, 41 | const char* message); 42 | 43 | ZOOAPI const char* format_log_message(const char* format,...); 44 | 45 | FILE* getLogStream(); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /*ZK_LOG_H_*/ 52 | -------------------------------------------------------------------------------- /libs/zookeeper/zookeeper/include/zookeeper_version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef ZOOKEEPER_VERSION_H_ 19 | #define ZOOKEEPER_VERSION_H_ 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define ZOO_MAJOR_VERSION 3 26 | #define ZOO_MINOR_VERSION 4 27 | #define ZOO_PATCH_VERSION 8 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* ZOOKEEPER_VERSION_H_ */ 34 | -------------------------------------------------------------------------------- /libs/zookeeper/zookeeper/src/hashtable/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002, 2004, Christopher Clark 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | * Neither the name of the original author; nor the names of any contributors 16 | may be used to endorse or promote products derived from this software 17 | without specific prior written permission. 18 | 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /misc/docker/build-environment/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | RUN apt-get update -yqq 4 | RUN apt-get install -yqq \ 5 | autoconf \ 6 | automake \ 7 | build-essential \ 8 | cmake \ 9 | curl \ 10 | git \ 11 | libboost-coroutine-dev \ 12 | libboost-dev \ 13 | libboost-filesystem-dev \ 14 | libfdt-dev \ 15 | libglib2.0-dev \ 16 | libtbb-dev \ 17 | libtool \ 18 | libtool \ 19 | pkg-config \ 20 | software-properties-common \ 21 | texinfo \ 22 | wget \ 23 | zlib1g-dev 24 | 25 | RUN mkdir -p /tmp 26 | 27 | # DOCKER 28 | ENV DOCKER_BUCKET test.docker.com 29 | ENV DOCKER_VERSION 1.12.0-rc2 30 | ENV DOCKER_SHA256 6df54c3360f713370aa59b758c45185b9a62889899f1f6185a08497ffd57a39b 31 | 32 | RUN set -x \ 33 | && curl -fSL "https://${DOCKER_BUCKET}/builds/Linux/x86_64/docker-$DOCKER_VERSION.tgz" -o docker.tgz \ 34 | && echo "${DOCKER_SHA256} *docker.tgz" | sha256sum -c - \ 35 | && tar -xzvf docker.tgz \ 36 | && mv docker/* /usr/local/bin/ \ 37 | && rmdir docker \ 38 | && rm docker.tgz \ 39 | && docker -v 40 | 41 | # QEMU 42 | RUN git clone -b pin-threads https://github.com/SESA/qemu.git /tmp/qemu 43 | WORKDIR /tmp/qemu 44 | RUN git submodule update --init pixman 45 | RUN ./configure --target-list=x86_64-softmmu --enable-vhost-net --enable-kvm 46 | RUN make -j 47 | RUN make install 48 | RUN make clean 49 | 50 | # CAPNPROTO 51 | RUN wget -O /tmp/capnproto.tar.gz https://github.com/sandstorm-io/capnproto/archive/v0.4.0.tar.gz 52 | WORKDIR /tmp 53 | RUN tar -xf /tmp/capnproto.tar.gz 54 | WORKDIR /tmp/capnproto-0.4.0/c++ 55 | RUN autoreconf -i 56 | RUN CXXFLAGS=-fpermissive ./configure 57 | RUN make -j 58 | RUN make install 59 | RUN make clean 60 | 61 | # Cleanup 62 | WORKDIR / 63 | RUN rm /tmp/capnproto.tar.gz 64 | RUN rm -rf /tmp/capnproto-0.4.0 65 | RUN rm -rf /tmp/qemu 66 | -------------------------------------------------------------------------------- /misc/docker/buildbot-master/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | 3 | RUN /bin/echo -e "\ 4 | deb http://archive.ubuntu.com/ubuntu trusty main universe\n\ 5 | deb http://archive.ubuntu.com/ubuntu trusty-updates main universe" > \ 6 | /etc/apt/sources.list 7 | RUN apt-get update 8 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python-pip python-dev \ 9 | git 10 | RUN pip install buildbot 11 | RUN groupadd -g 5001 buildbot 12 | RUN useradd -u 5001 -g buildbot buildbot 13 | USER buildbot 14 | WORKDIR /buildbotdata 15 | EXPOSE 8010 16 | CMD ["buildbot", "start", "--nodaemon", "master"] 17 | -------------------------------------------------------------------------------- /misc/docker/buildbot-slave/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ebbrt/build-environment 2 | 3 | RUN apt-get update 4 | RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -y 5 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \ 6 | clang-format-3.8 \ 7 | git \ 8 | iputils-ping \ 9 | netcat \ 10 | python-dev \ 11 | python-pexpect \ 12 | python-pip \ 13 | supervisor \ 14 | texinfo 15 | 16 | # BuildBot 17 | RUN pip install buildbot_slave 18 | RUN groupadd -g 5001 buildbot 19 | RUN useradd -u 5001 -g buildbot buildbot 20 | 21 | COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf 22 | WORKDIR /buildbotslavedata 23 | CMD ["/usr/bin/supervisord"] 24 | -------------------------------------------------------------------------------- /misc/docker/buildbot-slave/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:buildslave] 5 | command=buildslave start --nodaemon slave 6 | environment=HOME="/home/buildbot" 7 | -------------------------------------------------------------------------------- /misc/docker/homu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fedora 2 | RUN yum -y install git python-pip findutils && \ 3 | yum clean all && \ 4 | mkdir /app && \ 5 | cd /app && \ 6 | git clone https://github.com/servo/homu.git && \ 7 | pip3 install ./homu && \ 8 | find /usr/lib/python* -name git_helper.py -exec chmod a+x {} ';' 9 | ADD known_hosts /root/.ssh/known_hosts 10 | WORKDIR /homudata 11 | EXPOSE 54856 12 | CMD ["/usr/bin/homu", "-v"] 13 | -------------------------------------------------------------------------------- /misc/docker/kvm-qemu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | RUN apt-get update && \ 3 | apt-get install -y \ 4 | autoconf \ 5 | automake \ 6 | build-essential \ 7 | git \ 8 | libglib2.0-dev \ 9 | libpixman-1-dev \ 10 | zlib1g-dev \ 11 | iputils-ping \ 12 | iproute2 \ 13 | ebtables \ 14 | dnsmasq 15 | 16 | RUN git clone -b pin-threads https://github.com/SESA/qemu.git /qemu 17 | WORKDIR /qemu 18 | RUN ./configure --target-list=x86_64-softmmu --enable-vhost-net --enable-kvm 19 | RUN make -j 20 | RUN make install 21 | RUN make clean 22 | WORKDIR / 23 | RUN rm -rf /qemu 24 | 25 | COPY start.sh /root/start.sh 26 | COPY launch.sh /root/launch.sh 27 | 28 | RUN apt-get update && apt-get install -y gdb 29 | 30 | EXPOSE 22 31 | EXPOSE 1234 32 | ENTRYPOINT ["/root/start.sh"] 33 | -------------------------------------------------------------------------------- /misc/docker/kvm-qemu/launch.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | # Launch a native EbbRT 'backend' with kvm-qemu 3 | # 4 | # Usage: 5 | # ./launch.sh 6 | # 7 | if [ -n "$DEBUG" ]; then set -x; fi 8 | if [ -n "$DRY_RUN" ]; then 9 | echo "***DRY RUN***: Command will not be executed" 10 | LAUNCHER=echo 11 | fi 12 | if [ -n "$NO_NETWORK" ]; then 13 | echo "***No Networking***" 14 | fi 15 | if [ -n "$GDB" ]; then 16 | echo "***GDB Enabled @localhost:1234 ***" 17 | fi 18 | 19 | # configure virtual machine 20 | VCPU=${VM_CPU:-2} 21 | VMEM=${VM_MEM:-2G} 22 | VNUMA=${VM_NUMA:-0} # numa 23 | WAIT=${VM_WAIT:-false} 24 | TAP=${TAP_IFACE:-tap0} 25 | MAC=$VM_MAC 26 | VQS=$VCPU 27 | NETVEC=$(($((${VCPU}*2))+ 2)) 28 | if [ $VCPU -eq 1 ] 29 | then 30 | VQS=2 31 | fi 32 | # configure networking 33 | if [ -n "$NO_NETWORK" ]; then 34 | : ${KVM_NET_OPTS:=""} 35 | else 36 | : ${KVM_NET_OPTS:="-netdev tap,script=no,downscript=no,\ 37 | ifname=\$TAP,id=net0,vhost=on,queues=\$VQS \ 38 | -device virtio-net-pci,netdev=net0,mac=\$MAC,mq=on,\ 39 | vectors=\$NETVEC"} 40 | 41 | # Generate random MAC address if one isn't set already 42 | if [ -z "$MAC" ]; then 43 | echo "***No Mac Address Specified***" 44 | hexchars="0123456789ABCDEF" 45 | end=$( for i in {1..8} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' ) 46 | MAC=`echo 06:FE$end` 47 | fi 48 | fi # end NETWORK 49 | if [ -z "$KVM_ARGS" ]; then 50 | # No boot configuration passed in 51 | BOOTIMG=${BOOT_IMG:-$1} 52 | # verify boot image exists 53 | if [[ ! -f "$BOOTIMG" ]]; then echo "Boot image not found: $1"; exit 1; fi 54 | KVM_ARGS="-kernel $BOOTIMG" 55 | fi 56 | if [ -n "$GDB" ]; then 57 | KVM_ARGS="-s $KVM_ARGS" 58 | fi 59 | if [ -n "$NO_NETWORK" ]; then 60 | KVM_ARGS="$KVM_ARGS -append 'nodhcp;'" 61 | fi 62 | 63 | # numa 64 | NUMA_CMD="" 65 | if [ $VNUMA -ne 0 ] 66 | then 67 | for i in $(seq 1 $VNUMA); 68 | do 69 | NUMA_CMD="$NUMA_CMD -numa node " 70 | done 71 | fi 72 | 73 | $LAUNCHER qemu-system-x86_64 -m $VMEM -smp cpus=$VCPU $NUMA_CMD -cpu host -serial stdio -display none -enable-kvm `eval echo $KVM_NET_OPTS` $KVM_ARGS 74 | 75 | -------------------------------------------------------------------------------- /misc/ebbrt.kallsyms: -------------------------------------------------------------------------------- 1 | 100000 T _text 2 | 100000 T _stext 3 | -------------------------------------------------------------------------------- /misc/grub.cfg: -------------------------------------------------------------------------------- 1 | set default=0 2 | set timeout=0 3 | 4 | menuentry "EbbRT" { 5 | multiboot /boot/ebbrt 6 | boot 7 | } -------------------------------------------------------------------------------- /src/Align.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_ALIGN_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_ALIGN_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace ebbrt { 12 | namespace align { 13 | template constexpr T Down(T val, S alignment) { 14 | return val & ~(alignment - 1); 15 | } 16 | 17 | template constexpr T Up(T val, S alignment) { 18 | return Down(val + alignment - 1, alignment); 19 | } 20 | 21 | template T* Down(T* ptr, S alignment) { 22 | auto val = reinterpret_cast(ptr); 23 | return reinterpret_cast(Down(val, alignment)); 24 | } 25 | 26 | template T* Up(T* ptr, S alignment) { 27 | auto val = reinterpret_cast(ptr); 28 | return reinterpret_cast(Up(val, alignment)); 29 | } 30 | } // namespace align 31 | } // namespace ebbrt 32 | 33 | #endif // COMMON_SRC_INCLUDE_EBBRT_ALIGN_H_ 34 | -------------------------------------------------------------------------------- /src/AtomicUniquePtr.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_ATOMICUNIQUEPTR_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_ATOMICUNIQUEPTR_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace ebbrt { 12 | template > 13 | class atomic_unique_ptr { 14 | std::atomic ptr_; 15 | Deleter deleter_; 16 | 17 | public: 18 | explicit atomic_unique_ptr(T* ptr) : ptr_(ptr), deleter_(Deleter()) {} 19 | 20 | atomic_unique_ptr(atomic_unique_ptr&& other) 21 | : ptr_(other.exchange(nullptr).release()), 22 | deleter_(std::move(other.deleter_)) {} 23 | ~atomic_unique_ptr() { 24 | auto p = get(); 25 | if (p) 26 | deleter_(p); 27 | } 28 | T* get() const { return ptr_.load(std::memory_order_consume); } 29 | T* operator->() const { return get(); } 30 | T& operator*() const { return *get(); } 31 | void store(T* desired) { 32 | auto p = exchange(desired); 33 | if (!p) 34 | deleter_(p.release()); 35 | } 36 | std::unique_ptr exchange(T* desired) { 37 | return std::unique_ptr( 38 | ptr_.exchange(desired, std::memory_order_release)); 39 | } 40 | }; 41 | } // namespace ebbrt 42 | #endif // COMMON_SRC_INCLUDE_EBBRT_ATOMICUNIQUEPTR_H_ 43 | -------------------------------------------------------------------------------- /src/CacheAligned.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_CACHEALIGNED_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_CACHEALIGNED_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace ebbrt { 14 | const constexpr size_t cache_size = 64; 15 | 16 | struct alignas(cache_size) CacheAligned { 17 | #ifdef __EXCEPTIONS 18 | void* operator new(size_t size) { 19 | auto ret = memalign(cache_size, size); 20 | if (ret == nullptr) { 21 | throw std::bad_alloc(); 22 | } 23 | return ret; 24 | } 25 | void operator delete(void* p) { free(p); } 26 | #endif 27 | }; 28 | } // namespace ebbrt 29 | 30 | #endif // COMMON_SRC_INCLUDE_EBBRT_CACHEALIGNED_H_ 31 | -------------------------------------------------------------------------------- /src/CapnpMessage.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "CapnpMessage.h" 6 | 7 | struct Header { 8 | uint32_t num_segments; 9 | uint32_t segment_sizes[0]; 10 | }; 11 | 12 | std::unique_ptr 13 | ebbrt::AppendHeader(ebbrt::IOBufMessageBuilder& builder) { 14 | auto segs = builder.getSegmentsForOutput(); 15 | auto nsegs = segs.size(); 16 | auto header_size = align::Up(4 + 4 * nsegs, 8); 17 | auto header_buf = MakeUniqueIOBuf(header_size, true); 18 | auto dp = header_buf->GetMutDataPointer(); 19 | auto& h = dp.Get
(); 20 | h.num_segments = nsegs - 1; 21 | unsigned i = 0; 22 | for (auto& seg : segs) { 23 | h.segment_sizes[i] = seg.size(); 24 | ++i; 25 | } 26 | header_buf->PrependChain(std::move(builder.Move())); 27 | return std::move(header_buf); 28 | } 29 | -------------------------------------------------------------------------------- /src/Clock.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_CLOCK_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_CLOCK_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/Clock.h" 10 | #else 11 | #include "hosted/Clock.h" 12 | #endif 13 | 14 | #endif // COMMON_SRC_INCLUDE_EBBRT_CLOCK_H_ 15 | -------------------------------------------------------------------------------- /src/Compiler.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_COMPILER_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_COMPILER_H_ 7 | 8 | #define likely(x) __builtin_expect(static_cast(x), 1) 9 | #define unlikely(x) __builtin_expect(static_cast(x), 0) 10 | 11 | #endif // COMMON_SRC_INCLUDE_EBBRT_COMPILER_H_ 12 | -------------------------------------------------------------------------------- /src/Console.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_CONSOLE_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_CONSOLE_H_ 7 | 8 | namespace ebbrt { 9 | namespace console { 10 | __attribute__((no_instrument_function)) void Init() noexcept; 11 | __attribute__((no_instrument_function)) void Write(const char* str) noexcept; 12 | __attribute__((no_instrument_function)) int Write(const char* buf, 13 | int len) noexcept; 14 | } 15 | } 16 | 17 | #endif // COMMON_SRC_INCLUDE_EBBRT_CONSOLE_H_ 18 | -------------------------------------------------------------------------------- /src/Cpu.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_CPU_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_CPU_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/Cpu.h" 10 | #else 11 | #include "hosted/Cpu.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_CPU_H_ 15 | -------------------------------------------------------------------------------- /src/Debug.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_DEBUG_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_DEBUG_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/Debug.h" 10 | #else 11 | #include "hosted/Debug.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_DEBUG_H_ 15 | -------------------------------------------------------------------------------- /src/EbbAllocator.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include "Debug.h" 9 | #include "EbbAllocator.h" 10 | 11 | ebbrt::EbbAllocator::EbbAllocator() { 12 | auto start_ids = 13 | boost::icl::interval::type(kFirstFreeId, kFirstStaticUserId - 1); 14 | free_ids_.insert(std::move(start_ids)); 15 | #ifndef __ebbrt__ 16 | auto global_start = 1 << 16; 17 | auto global_end = (2 << 16) - 1; 18 | auto global_ids = boost::icl::interval::type(global_start, global_end); 19 | free_global_ids_.insert(std::move(global_ids)); 20 | #endif 21 | } 22 | 23 | ebbrt::EbbId ebbrt::EbbAllocator::AllocateLocal() { 24 | std::lock_guard lock(lock_); 25 | kbugon(free_ids_.empty()); 26 | auto ret = boost::icl::first(free_ids_); 27 | free_ids_.erase(ret); 28 | return ret; 29 | } 30 | 31 | ebbrt::EbbId ebbrt::EbbAllocator::Allocate() { 32 | std::lock_guard lock(lock_); 33 | if (free_global_ids_.empty()) 34 | throw std::runtime_error("Out of Global Ids!"); 35 | 36 | auto ret = boost::icl::first(free_global_ids_); 37 | free_global_ids_.erase(ret); 38 | return ret; 39 | } 40 | 41 | #ifdef __ebbrt__ 42 | void ebbrt::EbbAllocator::SetIdSpace(uint16_t space) { 43 | auto id_start = space << 16; 44 | auto id_end = ((space + 1) << 16) - 1; 45 | kprintf("Allocating Global EbbIds from %x - %x\n", id_start, id_end); 46 | auto start_ids = boost::icl::interval::type(id_start, id_end); 47 | free_global_ids_.insert(std::move(start_ids)); 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/EbbAllocator.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_EBBALLOCATOR_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_EBBALLOCATOR_H_ 7 | 8 | #include 9 | 10 | #pragma GCC diagnostic push 11 | #pragma GCC diagnostic ignored "-Wunused-local-typedefs" 12 | #include 13 | #pragma GCC diagnostic pop 14 | 15 | #include "CacheAligned.h" 16 | #include "EbbRef.h" 17 | #include "Runtime.h" 18 | #include "StaticIds.h" 19 | #include "StaticSharedEbb.h" 20 | #include "SpinLock.h" 21 | 22 | namespace ebbrt { 23 | class EbbAllocator : public CacheAligned, public StaticSharedEbb { 24 | public: 25 | static void ClassInit() {} // no class wide static initialization logic 26 | 27 | EbbAllocator(); 28 | EbbId AllocateLocal(); 29 | EbbId Allocate(); 30 | #ifdef __ebbrt__ 31 | void SetIdSpace(uint16_t id_space); 32 | #endif 33 | 34 | private: 35 | ebbrt::SpinLock lock_; 36 | boost::icl::interval_set free_ids_; 37 | boost::icl::interval_set free_global_ids_; 38 | }; 39 | 40 | constexpr auto ebb_allocator = EbbRef(kEbbAllocatorId); 41 | } // namespace ebbrt 42 | 43 | #endif // COMMON_SRC_INCLUDE_EBBRT_EBBALLOCATOR_H_ 44 | -------------------------------------------------------------------------------- /src/EbbId.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_EBBID_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_EBBID_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | typedef uint32_t EbbId; 12 | } 13 | 14 | #endif // COMMON_SRC_INCLUDE_EBBRT_EBBID_H_ 15 | -------------------------------------------------------------------------------- /src/EbbRef.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_EBBREF_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_EBBREF_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/EbbRef.h" 10 | #else 11 | #include "hosted/EbbRef.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_EBBREF_H_ 15 | -------------------------------------------------------------------------------- /src/EventManager.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_EVENTMANAGER_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_EVENTMANAGER_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/EventManager.h" 10 | #else 11 | #include "hosted/EventManager.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_EVENTMANAGER_H_ 15 | -------------------------------------------------------------------------------- /src/ExplicitlyConstructed.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_EXPLICITLYCONSTRUCTED_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_EXPLICITLYCONSTRUCTED_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace ebbrt { 13 | template class ExplicitlyConstructed { 14 | public: 15 | template void construct(Args&&... args) { 16 | ::new (&storage_) T(std::forward(args)...); 17 | } 18 | void destruct() { 19 | auto ptr = reinterpret_cast(&storage_); 20 | ptr->~T(); 21 | } 22 | 23 | const T* operator->() const { return reinterpret_cast(&storage_); } 24 | 25 | T* operator->() { return reinterpret_cast(&storage_); } 26 | 27 | const T& operator*() const { return *reinterpret_cast(&storage_); } 28 | 29 | T& operator*() { return *reinterpret_cast(&storage_); } 30 | 31 | ExplicitlyConstructed() = default; 32 | ExplicitlyConstructed(const ExplicitlyConstructed&) = delete; 33 | ExplicitlyConstructed& operator=(const ExplicitlyConstructed&) = delete; 34 | ExplicitlyConstructed(ExplicitlyConstructed&&) = delete; 35 | ExplicitlyConstructed& operator=(const ExplicitlyConstructed&&) = delete; 36 | 37 | private: 38 | typename std::aligned_storage::type storage_; 39 | } __attribute__((packed)); 40 | } // namespace ebbrt 41 | 42 | #endif // COMMON_SRC_INCLUDE_EBBRT_EXPLICITLYCONSTRUCTED_H_ 43 | -------------------------------------------------------------------------------- /src/GlobalIdMap.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_GLOBALIDMAP_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_GLOBALIDMAP_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/GlobalIdMap.h" 10 | #else 11 | #include "hosted/GlobalIdMap.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_GLOBALIDMAP_H_ 15 | -------------------------------------------------------------------------------- /src/GlobalIdMapBase.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_SRC_INCLUDE_EBBRT_GLOBALIDMAPBASE_H_ 2 | #define COMMON_SRC_INCLUDE_EBBRT_GLOBALIDMAPBASE_H_ 3 | 4 | #include "Future.h" 5 | #include "LocalIdMap.h" 6 | 7 | // Virtual base class for polymorphic GlobalIdMap Ebb 8 | namespace ebbrt { 9 | 10 | extern void InstallGlobalIdMap(); 11 | 12 | class GlobalIdMap { 13 | 14 | public: 15 | struct OptArgs { 16 | std::string data; 17 | }; 18 | 19 | // Base class used in Ebb translation 20 | class Base { 21 | public: 22 | virtual GlobalIdMap& Construct(EbbId id) = 0; 23 | 24 | private: 25 | friend class GlobalIdMap; 26 | }; 27 | // Miss uses base class from the local_id_map to construct the rep 28 | // This base class instance was previously constructed by the child type 29 | static GlobalIdMap& HandleFault(EbbId id) { 30 | LocalIdMap::ConstAccessor accessor; 31 | auto found = local_id_map->Find(accessor, id); 32 | if (!found) 33 | throw std::runtime_error("Failed to find base type for GlobalIdBase"); 34 | auto base = boost::any_cast(accessor->second); 35 | return base->Construct(id); 36 | } 37 | virtual Future Get(EbbId id, const OptArgs& args) = 0; 38 | virtual Future Set(EbbId id, const OptArgs& args) = 0; 39 | }; 40 | } 41 | #endif // COMMON_SRC_INCLUDE_EBBRT_GLOBALIDMAPBASE_H_ 42 | -------------------------------------------------------------------------------- /src/GlobalIdMessage.capnp: -------------------------------------------------------------------------------- 1 | @0xab1ac5096afdee55; 2 | 3 | using Cxx = import "/capnp/c++.capnp"; 4 | $Cxx.namespace("ebbrt::global_id_map_message"); 5 | 6 | struct GetRequest { 7 | messageId @0 :UInt64; 8 | ebbId @1 :UInt32; 9 | } 10 | 11 | struct SetRequest { 12 | messageId @0 :UInt64; 13 | ebbId @1 :UInt32; 14 | data @2 :Data; 15 | } 16 | 17 | struct Request { 18 | union { 19 | getRequest @0 :GetRequest; 20 | setRequest @1 :SetRequest; 21 | } 22 | } 23 | 24 | struct GetReply { 25 | messageId @0 :UInt64; 26 | data @1 :Data; 27 | } 28 | 29 | struct SetReply { 30 | messageId @0 :UInt64; 31 | } 32 | 33 | struct Reply { 34 | union { 35 | getReply @0 :GetReply; 36 | setReply @1 :SetReply; 37 | } 38 | } -------------------------------------------------------------------------------- /src/GlobalStaticIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_GLOBALSTATICIDS_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_GLOBALSTATICIDS_H_ 7 | 8 | #include "Hash.h" 9 | 10 | namespace ebbrt { 11 | enum : EbbId { kGlobalIdMapId, kFirstLocalId }; 12 | const constexpr EbbId kFirstStaticUserId = 0x8000; 13 | const constexpr EbbId GenerateStaticEbbId(hash::conststr a) { 14 | return kFirstStaticUserId | (static_string_hash(a) % 0x1000); 15 | } 16 | } // namespace ebbrt 17 | 18 | #endif // COMMON_SRC_INCLUDE_EBBRT_GLOBALSTATICIDS_H_ 19 | -------------------------------------------------------------------------------- /src/Hash.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_HASH_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_HASH_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace hash { 12 | 13 | // string literal 14 | class conststr { 15 | public: 16 | template 17 | constexpr conststr(const char (&a)[N]) : p(a), sz(N - 1) {} 18 | 19 | constexpr char operator[](std::size_t n) const { 20 | return n < sz ? p[n] : throw std::out_of_range(""); 21 | } 22 | constexpr std::size_t size() const { return sz; } 23 | 24 | private: 25 | const char* p; 26 | std::size_t sz; 27 | }; 28 | 29 | /* Jenkin's one-at-a-time Hash 30 | * https://en.wikipedia.org/wiki/Jenkins_hash_function */ 31 | constexpr uint32_t rsx(uint32_t hash, uint8_t rshift) { 32 | return hash ^ (hash >> rshift); 33 | } 34 | constexpr uint32_t lsa(uint32_t hash, uint8_t lshift) { 35 | return hash + ((hash << lshift) & 0xFFFFFFFF); 36 | } 37 | constexpr uint32_t oaat_loop(conststr s, uint32_t hash, std::uint32_t len) { 38 | return len == 0 ? hash 39 | : oaat_loop(s, rsx(lsa(((hash << 1) + s[(len - 1)]), 10), 6), 40 | len - 1); 41 | } 42 | constexpr uint32_t one_at_a_time_hash(conststr s, uint32_t seed) { 43 | return lsa(rsx(lsa(oaat_loop(s, seed, s.size()), 3), 11), 15); 44 | } 45 | } 46 | 47 | using hash::conststr; 48 | using hash::one_at_a_time_hash; 49 | 50 | constexpr uint32_t static_string_hash(conststr s, uint32_t seed = 0) { 51 | return one_at_a_time_hash(s, seed); 52 | } 53 | } 54 | 55 | #endif // COMMON_SRC_INCLUDE_EBBRT_HASH_H_ 56 | -------------------------------------------------------------------------------- /src/IOBufRef.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "IOBufRef.h" 6 | 7 | const constexpr ebbrt::IOBufRefOwner::CloneView_s 8 | ebbrt::IOBufRefOwner::CloneView; 9 | 10 | ebbrt::IOBufRefOwner::IOBufRefOwner(const IOBuf& buf) 11 | : buffer_(buf.Buffer()), capacity_(buf.Capacity()) {} 12 | 13 | const uint8_t* ebbrt::IOBufRefOwner::Buffer() const { return buffer_; } 14 | 15 | size_t ebbrt::IOBufRefOwner::Capacity() const { return capacity_; } 16 | 17 | std::unique_ptr ebbrt::CreateRef(const IOBuf& buf) { 18 | auto head = std::unique_ptr(new IOBufRef(buf)); 19 | head->Advance(buf.Data() - buf.Buffer()); 20 | head->TrimEnd(head->Length() - buf.Length()); 21 | 22 | return head; 23 | } 24 | 25 | std::unique_ptr ebbrt::CreateRef(const MutIOBuf& buf) { 26 | auto p = CreateRef(static_cast(buf)); 27 | auto d = reinterpret_cast(p.release()); 28 | return std::unique_ptr(d); 29 | } 30 | 31 | std::unique_ptr ebbrt::CreateRefChain(const IOBuf& buf) { 32 | auto head = CreateRef(buf); 33 | 34 | for (auto it = ++(buf.begin()); it != buf.end(); ++it) { 35 | head->PrependChain(CreateRef(*it)); 36 | } 37 | 38 | return head; 39 | } 40 | 41 | std::unique_ptr ebbrt::CreateRefChain(const MutIOBuf& buf) { 42 | auto p = CreateRefChain(static_cast(buf)); 43 | auto d = reinterpret_cast(p.release()); 44 | return std::unique_ptr(d); 45 | } 46 | -------------------------------------------------------------------------------- /src/LocalEntry.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_LOCALENTRY_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_LOCALENTRY_H_ 7 | 8 | #include "EbbId.h" 9 | 10 | namespace ebbrt { 11 | struct LocalEntry { 12 | LocalEntry() : ref(nullptr) {} 13 | void* ref; 14 | }; 15 | 16 | LocalEntry GetLocalEntry(EbbId id); 17 | void SetLocalEntry(EbbId id, LocalEntry le); 18 | } // namespace ebbrt 19 | 20 | #endif // COMMON_SRC_INCLUDE_EBBRT_LOCALENTRY_H_ 21 | -------------------------------------------------------------------------------- /src/LocalIdMap.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/LocalIdMap.h" 10 | #else 11 | #include "hosted/LocalIdMap.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 15 | -------------------------------------------------------------------------------- /src/Message.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Message.h" 6 | #include "Debug.h" 7 | 8 | #include 9 | 10 | std::unordered_map 12 | ebbrt::fault_map __attribute__((init_priority(101))); 13 | 14 | std::unordered_map 16 | ebbrt::cast_map __attribute__((init_priority(102))); 17 | 18 | ebbrt::MessagableBase& ebbrt::GetMessagableRef(EbbId id, uint64_t type_code) { 19 | auto local_entry = GetLocalEntry(id); 20 | if (local_entry.ref == nullptr){ 21 | auto it = fault_map.find(type_code); 22 | if (it == fault_map.end()) 23 | ebbrt::kabort("GetMessagableRef missing fault for type code"); 24 | return it->second(id); 25 | } else { 26 | auto it = cast_map.find(type_code); 27 | if (it == cast_map.end()) 28 | ebbrt::kabort("GetMessagableRef missing cast function for type code"); 29 | return it->second(local_entry.ref); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Messenger.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_MESSENGER_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_MESSENGER_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/Messenger.h" 10 | #else 11 | #include "hosted/Messenger.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_MESSENGER_H_ 15 | -------------------------------------------------------------------------------- /src/MulticoreEbbStatic.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_MULTICOREEBBSTATIC_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_MULTICOREEBBSTATIC_H_ 7 | 8 | #include 9 | 10 | #include "Cpu.h" 11 | #include "Debug.h" 12 | #include "LocalIdMap.h" 13 | 14 | namespace ebbrt { 15 | template class MulticoreEbbStatic { 16 | public: 17 | static void Init() { 18 | local_id_map->Insert(std::make_pair(T::static_id, RepMap())); 19 | T::ClassInit(); 20 | } 21 | static T& HandleFault(EbbId id) { 22 | kassert(id == T::static_id); 23 | { 24 | // acquire read only to find rep 25 | LocalIdMap::ConstAccessor accessor; 26 | auto found = local_id_map->Find(accessor, id); 27 | kassert(found); 28 | auto rep_map = boost::any_cast(accessor->second); 29 | auto it = rep_map.find(Cpu::GetMine()); 30 | if (it != rep_map.end()) { 31 | EbbRef::CacheRef(id, *it->second); 32 | return *it->second; 33 | } 34 | } 35 | // we failed to find a rep, we must construct one 36 | auto rep = new T; 37 | // TODO(dschatz): make the rep_map thread safe so we can acquire r/o access 38 | LocalIdMap::Accessor accessor; 39 | auto found = local_id_map->Find(accessor, id); 40 | kassert(found); 41 | auto rep_map = boost::any_cast(accessor->second); 42 | rep_map[Cpu::GetMine()] = rep; 43 | EbbRef::CacheRef(id, *rep); 44 | return *rep; 45 | } 46 | 47 | private: 48 | typedef boost::container::flat_map RepMap; 49 | }; 50 | } // namespace ebbrt 51 | 52 | #endif // COMMON_SRC_INCLUDE_EBBRT_MULTICOREEBBSTATIC_H_ 53 | -------------------------------------------------------------------------------- /src/Nid.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_NID_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_NID_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | class Nid { 12 | public: 13 | constexpr Nid() : val_(-1) {} 14 | explicit constexpr Nid(int val) : val_(val) {} 15 | 16 | static constexpr Nid None() { return Nid(-1); } 17 | static constexpr Nid Any() { return Nid(-2); } 18 | 19 | int val() const noexcept { return val_; } 20 | 21 | private: 22 | int val_; 23 | }; 24 | 25 | inline bool operator==(const Nid& lhs, const Nid& rhs) { 26 | return lhs.val() == rhs.val(); 27 | } 28 | 29 | inline bool operator!=(const Nid& lhs, const Nid& rhs) { 30 | return !operator==(lhs, rhs); 31 | } 32 | 33 | inline bool operator<(const Nid& lhs, const Nid& rhs) { 34 | return lhs.val() < rhs.val(); 35 | } 36 | 37 | inline bool operator>(const Nid& lhs, const Nid& rhs) { 38 | return operator<(rhs, lhs); 39 | } 40 | 41 | inline bool operator<=(const Nid& lhs, const Nid& rhs) { 42 | return !operator>(lhs, rhs); 43 | } 44 | 45 | inline bool operator>=(const Nid& lhs, const Nid& rhs) { 46 | return !operator<(lhs, rhs); 47 | } 48 | 49 | inline size_t operator-(const Nid& lhs, const Nid& rhs) { 50 | return lhs.val() - rhs.val(); 51 | } 52 | 53 | } // namespace ebbrt 54 | 55 | #endif // COMMON_SRC_INCLUDE_EBBRT_NID_H_ 56 | -------------------------------------------------------------------------------- /src/Runtime.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_RUNTIME_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_RUNTIME_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/Runtime.h" 10 | #else 11 | #include "hosted/Runtime.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_RUNTIME_H_ 15 | -------------------------------------------------------------------------------- /src/RuntimeInfo.capnp: -------------------------------------------------------------------------------- 1 | @0xdde6597835216252; 2 | struct RuntimeInfo { 3 | ebbIdSpace @0 :UInt16; 4 | messengerPort @1 :UInt16; 5 | globalIdMapAddress @2 :UInt32; 6 | } 7 | -------------------------------------------------------------------------------- /src/SharedEbb.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_SHAREDEBB_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_SHAREDEBB_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "EbbAllocator.h" 13 | #include "EbbRef.h" 14 | #include "LocalIdMap.h" 15 | 16 | namespace ebbrt { 17 | template class SharedEbb { 18 | public: 19 | static EbbRef Create(T* rep, EbbId id = ebb_allocator->Allocate()) { 20 | local_id_map->Insert(std::make_pair(id, std::move(rep))); 21 | return EbbRef(id); 22 | } 23 | static T& HandleFault(EbbId id) { 24 | LocalIdMap::ConstAccessor accessor; 25 | auto found = local_id_map->Find(accessor, id); 26 | if (!found) 27 | throw std::runtime_error("Failed to find root for SharedEbb"); 28 | 29 | auto rep = boost::any_cast(accessor->second); 30 | EbbRef::CacheRef(id, *rep); 31 | return *rep; 32 | } 33 | }; 34 | 35 | } // namespace ebbrt 36 | 37 | #endif // COMMON_SRC_INCLUDE_EBBRT_SHAREDEBB_H_ 38 | -------------------------------------------------------------------------------- /src/SharedIOBufRef.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "SharedIOBufRef.h" 6 | 7 | const constexpr ebbrt::SharedIOBufRefOwner::CloneView_s 8 | ebbrt::SharedIOBufRefOwner::CloneView; 9 | 10 | ebbrt::SharedIOBufRefOwner::SharedIOBufRefOwner(std::unique_ptr&& buf) 11 | : buf_(std::move(buf)) {} 12 | 13 | const uint8_t* ebbrt::SharedIOBufRefOwner::Buffer() const { 14 | return buf_->Buffer(); 15 | } 16 | 17 | size_t ebbrt::SharedIOBufRefOwner::Capacity() const { return buf_->Capacity(); } 18 | -------------------------------------------------------------------------------- /src/SpinBarrier.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_SPINBARRIER_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_SPINBARRIER_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | class SpinBarrier { 12 | public: 13 | explicit SpinBarrier(unsigned int n) : n_(n), waiters_(0), completed_(0) {} 14 | 15 | void Wait() { 16 | auto step = completed_.load(); 17 | 18 | if (waiters_.fetch_add(1) == n_ - 1) { 19 | waiters_.store(0); 20 | completed_.fetch_add(1); 21 | } else { 22 | while (completed_.load() == step) { 23 | } 24 | } 25 | } 26 | 27 | private: 28 | const unsigned int n_; 29 | std::atomic waiters_; 30 | std::atomic completed_; 31 | }; 32 | } // namespace ebbrt 33 | 34 | #endif // COMMON_SRC_INCLUDE_EBBRT_SPINBARRIER_H_ 35 | -------------------------------------------------------------------------------- /src/SpinLock.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_SPINLOCK_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_SPINLOCK_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | class SpinLock { 12 | public: 13 | SpinLock() : lock_(ATOMIC_FLAG_INIT) {} 14 | // We use lowercase naming for these functions so they are compatible with STL 15 | // locks 16 | void lock() { 17 | while (lock_.test_and_set(std::memory_order_acquire)) { 18 | } 19 | } 20 | void unlock() { lock_.clear(std::memory_order_release); } 21 | 22 | private: 23 | std::atomic_flag lock_; 24 | }; 25 | } // namespace ebbrt 26 | 27 | #endif // COMMON_SRC_INCLUDE_EBBRT_SPINLOCK_H_ 28 | -------------------------------------------------------------------------------- /src/StaticIOBuf.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "StaticIOBuf.h" 6 | 7 | #include 8 | 9 | ebbrt::StaticIOBufOwner::StaticIOBufOwner(const char* s) noexcept { 10 | ptr_ = reinterpret_cast(s); 11 | capacity_ = strlen(s); 12 | } 13 | 14 | ebbrt::StaticIOBufOwner::StaticIOBufOwner(const uint8_t* ptr, 15 | size_t len) noexcept { 16 | ptr_ = ptr; 17 | capacity_ = len; 18 | } 19 | 20 | const uint8_t* ebbrt::StaticIOBufOwner::Buffer() const { return ptr_; } 21 | 22 | size_t ebbrt::StaticIOBufOwner::Capacity() const { return capacity_; } 23 | -------------------------------------------------------------------------------- /src/StaticIOBuf.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_STATICIOBUF_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_STATICIOBUF_H_ 7 | 8 | #include 9 | 10 | #include "IOBuf.h" 11 | 12 | namespace ebbrt { 13 | class StaticIOBufOwner { 14 | public: 15 | explicit StaticIOBufOwner(const char* s) noexcept; 16 | StaticIOBufOwner(const uint8_t* ptr, size_t len) noexcept; 17 | 18 | const uint8_t* Buffer() const; 19 | size_t Capacity() const; 20 | 21 | private: 22 | const uint8_t* ptr_; 23 | size_t capacity_; 24 | }; 25 | 26 | typedef IOBufBase StaticIOBuf; 27 | } // namespace ebbrt 28 | 29 | #endif // COMMON_SRC_INCLUDE_EBBRT_STATICIOBUF_H_ 30 | -------------------------------------------------------------------------------- /src/StaticIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_STATICIDS_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_STATICIDS_H_ 7 | 8 | #ifdef __ebbrt__ 9 | #include "native/StaticIds.h" 10 | #else 11 | #include "hosted/StaticIds.h" 12 | #endif 13 | 14 | #endif //COMMON_SRC_INCLUDE_EBBRT_STATICIDS_H_ 15 | -------------------------------------------------------------------------------- /src/StaticSharedEbb.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_STATICSHAREDEBB_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_STATICSHAREDEBB_H_ 7 | 8 | #include "EbbRef.h" 9 | 10 | namespace ebbrt { 11 | template class StaticSharedEbb { 12 | public: 13 | static void Init() { T::ClassInit(); } 14 | static T& HandleFault(EbbId id) { 15 | static T rep; 16 | EbbRef::CacheRef(id, rep); 17 | return rep; 18 | } 19 | }; 20 | } // namespace ebbrt 21 | 22 | #endif // COMMON_SRC_INCLUDE_EBBRT_STATICSHAREDEBB_H_ 23 | -------------------------------------------------------------------------------- /src/Timer.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_TIMER_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_TIMER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "MulticoreEbbStatic.h" 14 | 15 | namespace ebbrt { 16 | 17 | class Timer : public MulticoreEbbStatic { 18 | public: 19 | static void ClassInit() {} // no class wide static initialization logic 20 | 21 | class Hook : public boost::intrusive::set_base_hook<> { 22 | public: 23 | virtual ~Hook() {} 24 | virtual void Fire() = 0; 25 | 26 | bool operator==(const Hook& rhs) const { 27 | return fire_time_ == rhs.fire_time_; 28 | } 29 | 30 | bool operator!=(const ebbrt::Timer::Hook& rhs) const { 31 | return !(*this == rhs); 32 | } 33 | 34 | bool operator<(const Hook& rhs) const { 35 | return fire_time_ < rhs.fire_time_; 36 | } 37 | 38 | bool operator>(const ebbrt::Timer::Hook& rhs) const { return rhs < *this; } 39 | 40 | bool operator<=(const ebbrt::Timer::Hook& rhs) const { 41 | return !(*this > rhs); 42 | } 43 | 44 | bool operator>=(const ebbrt::Timer::Hook& rhs) const { 45 | return !(*this < rhs); 46 | } 47 | 48 | private: 49 | std::chrono::nanoseconds fire_time_; 50 | std::chrono::microseconds repeat_us_; 51 | 52 | friend Timer; 53 | }; 54 | 55 | static const constexpr EbbId static_id = kTimerId; 56 | 57 | Timer(); 58 | 59 | void Start(Hook&, std::chrono::microseconds timeout, bool repeat); 60 | void Stop(Hook&); 61 | 62 | private: 63 | void SetTimer(std::chrono::microseconds from_now); 64 | void StopTimer(); 65 | 66 | uint64_t ticks_per_us_; 67 | boost::intrusive::multiset timers_; 68 | }; 69 | 70 | const constexpr auto timer = EbbRef(Timer::static_id); 71 | } // namespace ebbrt 72 | 73 | #endif // COMMON_SRC_INCLUDE_EBBRT_TIMER_H_ 74 | -------------------------------------------------------------------------------- /src/TypeTraits.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMMON_SRC_INCLUDE_EBBRT_TYPETRAITS_H_ 6 | #define COMMON_SRC_INCLUDE_EBBRT_TYPETRAITS_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | 12 | template struct is_explicitly_convertible { 13 | template static void f(T); 14 | 15 | template 16 | static constexpr auto test(int) // NOLINT 17 | -> decltype(f(static_cast(std::declval())), true) { 18 | return true; 19 | } 20 | 21 | template static constexpr auto test(...) -> bool { 22 | return false; 23 | } 24 | 25 | static bool const value = test(0); 26 | }; 27 | 28 | } // namespace ebbrt 29 | 30 | #endif // COMMON_SRC_INCLUDE_EBBRT_TYPETRAITS_H_ 31 | -------------------------------------------------------------------------------- /src/UniqueIOBuf.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Compiler.h" 6 | #include "UniqueIOBuf.h" 7 | 8 | ebbrt::UniqueIOBufOwner::UniqueIOBufOwner(uint8_t* p, size_t capacity) 9 | : ptr_(p), capacity_(capacity) {} 10 | 11 | const uint8_t* ebbrt::UniqueIOBufOwner::Buffer() const { return ptr_; } 12 | 13 | size_t ebbrt::UniqueIOBufOwner::Capacity() const { return capacity_; } 14 | 15 | void ebbrt::UniqueIOBufOwner::operator delete(void* ptr) { 16 | // ptr came from malloc or calloc, so just free it 17 | free(ptr); 18 | } 19 | 20 | std::unique_ptr 21 | ebbrt::MakeUniqueIOBuf(size_t capacity, bool zero_memory) { 22 | auto size = sizeof(MutUniqueIOBuf) + capacity; 23 | void* b; 24 | if (zero_memory) { 25 | b = std::calloc(1, size); 26 | } else { 27 | b = std::malloc(size); 28 | } 29 | 30 | if (unlikely(b == nullptr)) 31 | throw std::bad_alloc(); 32 | 33 | auto buf = static_cast(b) + sizeof(MutUniqueIOBuf); 34 | 35 | return std::unique_ptr(new (b) MutUniqueIOBuf(buf, capacity)); 36 | } 37 | -------------------------------------------------------------------------------- /src/cmake/Platform/EbbRT.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_LINK_LIBRARY_SUFFIX "") 2 | set(CMAKE_STATIC_LIBRARY_PREFIX "lib") # lib 3 | set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") # .a 4 | 5 | set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) 6 | set(CMAKE_FIND_LIBRARY_PREFIXES "lib") 7 | set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") 8 | -------------------------------------------------------------------------------- /src/cmake/ebbrt.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME EbbRT) 2 | 3 | if (NOT DEFINED ENV{EBBRT_SYSROOT}) 4 | message(FATAL_ERROR "EBBRT_SYSROOT environment variable not set") 5 | endif() 6 | 7 | if (NOT IS_DIRECTORY $ENV{EBBRT_SYSROOT}) 8 | message(FATAL_ERROR "EBBRT_SYSROOT is not a directory") 9 | endif() 10 | 11 | # where is the target environment 12 | SET(CMAKE_SYSROOT $ENV{EBBRT_SYSROOT}) 13 | SET(CMAKE_INSTALL_PREFIX "${CMAKE_SYSROOT}/usr" CACHE PATH "default install path" FORCE ) 14 | 15 | # specify the cross compiler 16 | SET(CMAKE_C_COMPILER ${CMAKE_SYSROOT}/usr/bin/x86_64-pc-ebbrt-gcc) 17 | SET(CMAKE_CXX_COMPILER ${CMAKE_SYSROOT}/usr/bin/x86_64-pc-ebbrt-g++) 18 | SET(CMAKE_ASM_COMPILER ${CMAKE_SYSROOT}/usr/bin/x86_64-pc-ebbrt-g++) 19 | SET(CMAKE_AR ${CMAKE_SYSROOT}/usr/bin/x86_64-pc-ebbrt-gcc-ar CACHE FILEPATH "Archiver") 20 | SET(CMAKE_RANLIB ${CMAKE_SYSROOT}/usr/bin/x86_64-pc-ebbrt-gcc-ranlib CACHE FILEPATH "Archiver") 21 | 22 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14" ) 23 | 24 | SET(CMAKE_STAGING_PREFIX ${CMAKE_SYSROOT}/usr) 25 | SET(CMAKE_SYSTEM_PREFIX_PATH ${CMAKE_SYSROOT}/usr) 26 | 27 | # search for programs in the build host directories 28 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 29 | # for libraries and headers in the target directories 30 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 31 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 32 | -------------------------------------------------------------------------------- /src/hosted/.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /src/hosted/Clock.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Clock.h" 6 | 7 | ebbrt::clock::HighResTimer::DoOnce ebbrt::clock::HighResTimer::once; 8 | -------------------------------------------------------------------------------- /src/hosted/Console.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../Console.h" 11 | 12 | void ebbrt::console::Init() noexcept {} 13 | 14 | void ebbrt::console::Write(const char* str) noexcept { 15 | size_t len = strlen(str); 16 | int n = 0; 17 | do { 18 | n = write(STDOUT_FILENO, str, len); 19 | assert(n > 0); 20 | len -= n; 21 | } while (len > 0); 22 | } 23 | 24 | int ebbrt::console::Write(const char* buf, int len) noexcept { 25 | return write(STDOUT_FILENO, buf, len); 26 | } 27 | -------------------------------------------------------------------------------- /src/hosted/Context.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include "Context.h" 8 | #include "ContextActivation.h" 9 | #include "Cpu.h" 10 | #include "Runtime.h" 11 | 12 | thread_local ebbrt::Context* ebbrt::active_context; 13 | 14 | ebbrt::Context::Context(Runtime& runtime) : runtime_(runtime) { 15 | index_ = runtime.indices_.fetch_add(1, std::memory_order_relaxed); 16 | { 17 | ContextActivation activation(*this); 18 | runtime.Initialize(); 19 | } 20 | } 21 | 22 | void ebbrt::Context::Activate() { active_context = this; } 23 | 24 | void ebbrt::Context::Deactivate() { active_context = nullptr; } 25 | 26 | size_t ebbrt::Context::GetIndex() { 27 | assert(active_context); 28 | return index_; 29 | } 30 | 31 | void ebbrt::Context::Run() { 32 | ContextActivation active(*this); 33 | io_service_.run(); 34 | } 35 | 36 | void ebbrt::Context::RunOne() { 37 | ContextActivation active(*this); 38 | io_service_.run_one(); 39 | } 40 | 41 | void ebbrt::Context::PollOne() { 42 | ContextActivation active(*this); 43 | io_service_.poll_one(); 44 | } 45 | 46 | void ebbrt::Context::Stop() { io_service_.stop(); } 47 | 48 | void ebbrt::Context::Reset() { io_service_.reset(); } 49 | -------------------------------------------------------------------------------- /src/hosted/Context.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_CONTEXT_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_CONTEXT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "../EbbId.h" 14 | #include "../LocalEntry.h" 15 | #include "EventContext.h" 16 | 17 | namespace ebbrt { 18 | class Runtime; 19 | class EventManager; 20 | 21 | class Context { 22 | public: 23 | explicit Context(Runtime& runtime); 24 | Context(Context&&) = default; 25 | Context& operator=(Context&&) = default; 26 | void Activate(); 27 | void Deactivate(); 28 | size_t GetIndex(); 29 | void Run(); 30 | void RunOne(); 31 | void PollOne(); 32 | void Stop(); 33 | void Reset(); 34 | LocalEntry GetLocalEntry(EbbId id) { return local_table_[id]; } 35 | void SetLocalEntry(EbbId id, LocalEntry le) { local_table_[id] = le; } 36 | operator size_t() const { return index_; } 37 | 38 | boost::asio::io_service io_service_; 39 | 40 | private: 41 | Runtime& runtime_; 42 | size_t index_; 43 | std::unordered_map local_table_; 44 | EventContext active_event_context_; 45 | 46 | friend class Runtime; 47 | friend class EventManager; 48 | }; 49 | 50 | extern thread_local Context* active_context; 51 | } // namespace ebbrt 52 | 53 | #endif // HOSTED_SRC_INCLUDE_EBBRT_CONTEXT_H_ 54 | -------------------------------------------------------------------------------- /src/hosted/ContextActivation.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Context.h" 6 | #include "ContextActivation.h" 7 | 8 | ebbrt::ContextActivation::ContextActivation(Context& c) : c_(c) { 9 | c.Activate(); 10 | } 11 | 12 | ebbrt::ContextActivation::~ContextActivation() { c_.Deactivate(); } 13 | -------------------------------------------------------------------------------- /src/hosted/ContextActivation.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_CONTEXTACTIVATION_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_CONTEXTACTIVATION_H_ 7 | 8 | namespace ebbrt { 9 | class Context; 10 | class ContextActivation { 11 | Context& c_; 12 | 13 | public: 14 | explicit ContextActivation(Context& c); 15 | ~ContextActivation(); 16 | }; 17 | } // namespace ebbrt 18 | 19 | #endif // HOSTED_SRC_INCLUDE_EBBRT_CONTEXTACTIVATION_H_ 20 | -------------------------------------------------------------------------------- /src/hosted/Cpu.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_CPU_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_CPU_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "../Nid.h" 12 | #include "Context.h" 13 | 14 | namespace ebbrt { 15 | class Cpu { 16 | public: 17 | static const constexpr size_t kMaxCpus = 256; 18 | Cpu(size_t index) : index_(index), ctxt_(rt_) { 19 | // printf("%p: index=%zd index_=%zd\n", this, index, index_); 20 | } 21 | 22 | static Cpu& GetMine() { return *my_cpu_tls_; } 23 | static Nid GetMyNode() { return GetMine().nid(); } 24 | static Cpu* GetByIndex(size_t index); 25 | static size_t Count(); 26 | static pthread_t EarlyInit(size_t num = 0); 27 | static int GetPhysCpus() { return ebbrt::Cpu::DefaultPhysCpus_; } 28 | static void Shutdown(void); 29 | static void Exit(int val); 30 | 31 | void Init(); 32 | operator size_t() const { return index_; } 33 | Nid nid() const { return nid_; } 34 | void set_nid(Nid nid) { nid_ = nid; } 35 | void set_tid(pthread_t tid) { tid_ = tid; }; 36 | pthread_t get_tid() { return tid_; } 37 | Context* get_context() { return &ctxt_; } 38 | 39 | private: 40 | static Cpu* Create(size_t index); 41 | static volatile int running_; 42 | static volatile int created_; 43 | static volatile int inited_; 44 | static void* run(void* arg); 45 | static Runtime rt_; 46 | static thread_local Cpu* my_cpu_tls_; 47 | static std::mutex init_lock_; 48 | static size_t numCpus_; 49 | static std::atomic shutdown_; 50 | static size_t DefaultPhysCpus_; 51 | size_t index_; 52 | pthread_t tid_; 53 | Nid nid_; 54 | Context ctxt_; 55 | friend class EventManager; 56 | }; 57 | }; 58 | 59 | #endif // HOSTED_SRC_INCLUDE_EBBRT_CPU_H_ 60 | -------------------------------------------------------------------------------- /src/hosted/Debug.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | 8 | #include "Debug.h" 9 | 10 | void ebbrt::kprintf(const char* __restrict format, ...) { 11 | #ifndef NDEBUG 12 | va_list ap; 13 | va_start(ap, format); 14 | vprintf(format, ap); 15 | va_end(ap); 16 | #endif 17 | } 18 | 19 | void ebbrt::kprintf_force(const char* __restrict format, ...) { 20 | va_list ap; 21 | va_start(ap, format); 22 | vprintf(format, ap); 23 | va_end(ap); 24 | } 25 | -------------------------------------------------------------------------------- /src/hosted/Debug.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_DEBUG_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_DEBUG_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #ifndef NDEBUG 13 | #define kassert(expr) assert(expr) 14 | #else 15 | #define kassert(expr) \ 16 | do { \ 17 | (void)sizeof(expr); \ 18 | } while (0) 19 | #endif 20 | #define EBBRT_UNIMPLEMENTED() kabort() 21 | 22 | namespace ebbrt { 23 | 24 | __attribute__((no_instrument_function)) void 25 | kprintf(const char* __restrict format, ...); 26 | __attribute__((no_instrument_function)) void 27 | kprintf_force(const char* __restrict format, ...); 28 | 29 | static __attribute__((noreturn)) void kabort() { abort(); } 30 | 31 | template 32 | __attribute__((noreturn)) void kabort(Args&&... args) { 33 | kprintf_force(std::forward(args)...); // NOLINT 34 | kabort(); 35 | } 36 | 37 | template void kbugon(bool expr, const Args&... args) { 38 | if (expr) { 39 | kabort(args...); 40 | } 41 | } 42 | 43 | } // namespace ebbrt 44 | 45 | #endif // HOSTED_SRC_INCLUDE_EBBRT_DEBUG_H_ 46 | -------------------------------------------------------------------------------- /src/hosted/EbbRTConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | # - Config file for the EbbRT hosted package 3 | # It defines the following variables 4 | # EBBRT_INCLUDE_DIRS - include directories for EbbRT 5 | # EBBRT_LIBRARIES - libraries to link against 6 | 7 | set_and_check(EBBRT_INCLUDE_DIRS "@PACKAGE_INSTALL_INCLUDE_DIR@") 8 | set_and_check(EBBRT_LIBRARIES "@PACKAGE_INSTALL_LIB_DIR@libEbbRT.a") 9 | 10 | check_required_components(EbbRT) 11 | -------------------------------------------------------------------------------- /src/hosted/EbbRef.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_EBBREF_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_EBBREF_H_ 7 | 8 | #include 9 | 10 | #include "../EbbId.h" 11 | #include "../LocalEntry.h" 12 | #include "../TypeTraits.h" 13 | #include "Context.h" 14 | 15 | namespace ebbrt { 16 | template class EbbRef { 17 | public: 18 | constexpr explicit EbbRef(EbbId id = 0) : ebbid_(id) {} 19 | 20 | template 21 | EbbRef(const EbbRef& from, 22 | typename std::enable_if_t::value>* = 23 | nullptr) 24 | : ebbid_(from.ebbid_) {} 25 | 26 | template 27 | explicit EbbRef( 28 | const EbbRef& from, 29 | typename std::enable_if_t::value && 30 | !std::is_convertible::value>* = 31 | nullptr) 32 | : ebbid_(from.ebbid_) {} 33 | 34 | T* operator->() const { return &operator*(); } 35 | 36 | T& operator*() const { 37 | if (active_context == nullptr) { 38 | throw std::runtime_error("Cannot invoke Ebb without active context"); 39 | } 40 | auto local_entry = active_context->GetLocalEntry(ebbid_); 41 | auto lref = static_cast(local_entry.ref); 42 | if (lref == nullptr) { 43 | lref = &(T::HandleFault(ebbid_)); 44 | } 45 | return *lref; 46 | } 47 | 48 | static void CacheRef(EbbId id, T& ref) { 49 | LocalEntry le; 50 | le.ref = static_cast(&ref); 51 | active_context->SetLocalEntry(id, le); 52 | } 53 | 54 | explicit operator EbbId() const { return ebbid_; } 55 | 56 | private: 57 | template friend class EbbRef; 58 | EbbId ebbid_; 59 | }; 60 | 61 | } // namespace ebbrt 62 | 63 | #endif // HOSTED_SRC_INCLUDE_EBBRT_EBBREF_H_ 64 | -------------------------------------------------------------------------------- /src/hosted/EventContext.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_EVENTCONTEXT_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_EVENTCONTEXT_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace ebbrt { 12 | class EventContext { 13 | #if BOOST_VERSION > 105500 14 | typedef boost::coroutines::symmetric_coroutine::call_type coro_type; 15 | typedef boost::coroutines::symmetric_coroutine::yield_type caller_type; 16 | #else 17 | typedef boost::coroutines::coroutine coro_type; 18 | typedef boost::coroutines::coroutine::caller_type caller_type; 19 | #endif 20 | private: 21 | coro_type coro; 22 | caller_type* caller; 23 | 24 | friend class EventManager; 25 | }; 26 | } // namespace ebbrt 27 | 28 | #endif // HOSTED_SRC_INCLUDE_EBBRT_EVENTCONTEXT_H_ 29 | -------------------------------------------------------------------------------- /src/hosted/EventManager.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include "EventManager.h" 7 | #include "Context.h" 8 | 9 | void ebbrt::EventManager::Spawn(MovableFunction func, 10 | ebbrt::Context* ctxt, bool force_async) { 11 | // movable function cannot be copied so we put it on the heap 12 | auto f = new MovableFunction(std::move(func)); 13 | // async dispatch 14 | ctxt->io_service_.post([f, this, ctxt]() { 15 | // create and run a new coroutine to run the event on 16 | ctxt->active_event_context_.coro = 17 | EventContext::coro_type([f, this, ctxt](EventContext::caller_type& ca) { 18 | #if BOOST_VERSION <= 105500 19 | ca(); 20 | #endif 21 | // store the caller for later if we need to save the context 22 | ctxt->active_event_context_.caller = &ca; 23 | InvokeFunction(f); 24 | delete f; 25 | }); 26 | ctxt->active_event_context_.coro(); 27 | }); 28 | } 29 | 30 | void ebbrt::EventManager::ActivateContext( 31 | EventManager::EventContext&& context) { 32 | auto c = new EventManager::EventContext(std::move(context)); 33 | ebbrt::Context* ctxt = active_context; 34 | ctxt->io_service_.post([c, this, ctxt]() { 35 | ctxt->active_event_context_ = std::move(*c); 36 | ctxt->active_event_context_.coro(); 37 | delete c; 38 | }); 39 | } 40 | 41 | void ebbrt::EventManager::SaveContext(EventManager::EventContext& context) { 42 | context = std::move(active_context->active_event_context_); 43 | (*context.caller)(); 44 | } 45 | -------------------------------------------------------------------------------- /src/hosted/LocalEntry.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "../LocalEntry.h" 6 | #include "Context.h" 7 | 8 | ebbrt::LocalEntry ebbrt::GetLocalEntry(EbbId id) { 9 | return active_context->GetLocalEntry(id); 10 | } 11 | 12 | void ebbrt::SetLocalEntry(EbbId id, LocalEntry le) { 13 | active_context->SetLocalEntry(id, le); 14 | } 15 | -------------------------------------------------------------------------------- /src/hosted/LocalIdMap.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "LocalIdMap.h" 6 | 7 | bool ebbrt::LocalIdMap::Insert(const ValueType& value) { 8 | return map_.insert(value); 9 | } 10 | 11 | bool ebbrt::LocalIdMap::Insert(Accessor& result, const EbbId& key) { 12 | return map_.insert(result, key); 13 | } 14 | 15 | bool ebbrt::LocalIdMap::Find(ConstAccessor& result, const EbbId& key) const { 16 | return map_.find(result, key); 17 | } 18 | 19 | bool ebbrt::LocalIdMap::Find(Accessor& result, const EbbId& key) { 20 | return map_.find(result, key); 21 | } 22 | -------------------------------------------------------------------------------- /src/hosted/LocalIdMap.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "../CacheAligned.h" 15 | #include "../EbbRef.h" 16 | #include "../StaticSharedEbb.h" 17 | #include "StaticIds.h" 18 | 19 | namespace ebbrt { 20 | class LocalIdMap : public StaticSharedEbb, public CacheAligned { 21 | public: 22 | static void ClassInit() {} // no class wide static initialization logic 23 | 24 | typedef tbb::concurrent_hash_map< 25 | EbbId, boost::any, tbb::tbb_hash_compare, 26 | std::allocator>> 27 | MapType; 28 | 29 | typedef MapType::const_accessor ConstAccessor; 30 | typedef MapType::accessor Accessor; 31 | typedef MapType::value_type ValueType; 32 | 33 | bool Find(ConstAccessor& result, const EbbId& key) const; 34 | bool Find(Accessor& result, const EbbId& key); 35 | bool Insert(ConstAccessor& result, const EbbId& key); 36 | bool Insert(Accessor& result, const EbbId& key); 37 | bool Insert(ConstAccessor& result, const ValueType& value); 38 | bool Insert(Accessor& result, const ValueType& value); 39 | bool Insert(const ValueType& value); 40 | bool Erase(const EbbId& key); 41 | bool Erase(ConstAccessor& item_accessor); 42 | bool Erase(Accessor& item_accessor); 43 | 44 | private: 45 | MapType map_; 46 | }; 47 | 48 | constexpr auto local_id_map = EbbRef(kLocalIdMapId); 49 | } // namespace ebbrt 50 | 51 | #endif // HOSTED_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 52 | -------------------------------------------------------------------------------- /src/hosted/PoolAllocator.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_POOLALLOCATOR_H_ 7 | #define HOSTED_SRC_INCLUDE_EBBRT_POOLALLOCATOR_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "../StaticSharedEbb.h" 15 | #include "EbbRef.h" 16 | #include "Messenger.h" 17 | #include "NodeAllocator.h" 18 | #include "StaticIds.h" 19 | 20 | namespace ebbrt { 21 | class PoolAllocator : public StaticSharedEbb { 22 | private: 23 | ebbrt::Messenger::NetworkId* nids_; 24 | int num_nodes_; 25 | std::atomic num_nodes_alloc_; 26 | std::string binary_path_; 27 | ebbrt::Promise pool_promise_; 28 | std::vector nodes_; 29 | 30 | public: 31 | std::string RunCmd(std::string cmd); 32 | void AllocatePool(std::string binary_path, int numNodes, 33 | std::vector cpu_ids); 34 | void AllocatePool(std::string binary_path, int numNodes) { 35 | std::vector cpu_ids(numNodes); 36 | std::iota(std::begin(cpu_ids), std::end(cpu_ids), 0); 37 | AllocatePool(binary_path, numNodes, cpu_ids); 38 | } 39 | void AllocateNode(int i); 40 | ebbrt::NodeAllocator::NodeDescriptor GetNodeDescriptor(int i); 41 | ebbrt::Messenger::NetworkId GetNidAt(int i) { return nids_[i]; }; 42 | ebbrt::Future waitPool() { 43 | return std::move(pool_promise_.GetFuture()); 44 | } 45 | void EmptyPool() { 46 | node_allocator->FreeAllNodes(); 47 | node_allocator->RemoveNetwork(); 48 | } 49 | }; 50 | const constexpr auto pool_allocator = EbbRef(kPoolAllocatorId); 51 | } 52 | #endif // HOSTED_SRC_INCLUDE_EBBRT_POOLALLOCATOR_H_ 53 | -------------------------------------------------------------------------------- /src/hosted/Runtime.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Runtime.h" 6 | #include "../EbbAllocator.h" 7 | #include "../Timer.h" 8 | #include "Context.h" 9 | #include "EventManager.h" 10 | #include "LocalIdMap.h" 11 | #include "Messenger.h" 12 | #include "NodeAllocator.h" 13 | #include "../GlobalIdMap.h" 14 | #include "../StaticIds.h" 15 | 16 | ebbrt::Runtime::Runtime() : initialized_(false), indices_(0) {} 17 | 18 | void ebbrt::Runtime::Initialize() { 19 | if (active_context == nullptr) { 20 | throw std::runtime_error( 21 | "Runtime cannot initialize without an active context"); 22 | } 23 | if (active_context->index_ == 0) { 24 | DoInitialization(); 25 | 26 | std::lock_guard lock(init_lock_); 27 | initialized_ = true; 28 | init_cv_.notify_all(); 29 | } else { 30 | std::unique_lock lock(init_lock_); 31 | if (!initialized_) { 32 | init_cv_.wait(lock, [&] { return initialized_; }); 33 | } 34 | } 35 | } 36 | 37 | void ebbrt::Runtime::DoInitialization() { 38 | EventManager::Init(); 39 | LocalIdMap::Init(); 40 | EbbAllocator::Init(); 41 | Messenger::Init(); 42 | Timer::Init(); 43 | ebbrt::InstallGlobalIdMap(); 44 | NodeAllocator::Init(); 45 | } 46 | -------------------------------------------------------------------------------- /src/hosted/Runtime.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_RUNTIME_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_RUNTIME_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace ebbrt { 13 | class Runtime { 14 | std::mutex init_lock_; 15 | std::condition_variable init_cv_; 16 | bool initialized_; 17 | std::atomic indices_; 18 | 19 | friend class Context; 20 | void Initialize(); 21 | void DoInitialization(); 22 | 23 | public: 24 | Runtime(); 25 | }; 26 | namespace runtime { 27 | // dummy runtime init to keep compatability with baremetal 28 | void Init() __attribute__((unused)); 29 | inline uint32_t AllocationId() { return 0;}; 30 | } 31 | } // namespace ebbrt 32 | 33 | #endif // HOSTED_SRC_INCLUDE_EBBRT_RUNTIME_H_ 34 | -------------------------------------------------------------------------------- /src/hosted/StaticIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HOSTED_SRC_INCLUDE_EBBRT_STATICIDS_H_ 6 | #define HOSTED_SRC_INCLUDE_EBBRT_STATICIDS_H_ 7 | 8 | #include "../EbbId.h" 9 | #include "../GlobalStaticIds.h" 10 | 11 | namespace ebbrt { 12 | enum : EbbId { 13 | kLocalIdMapId = kFirstLocalId, 14 | kEbbAllocatorId, 15 | kNetworkManagerId, 16 | kNodeAllocatorId, 17 | kPoolAllocatorId, 18 | kMessengerId, 19 | kEventManagerId, 20 | kGlobalMapId, 21 | kTimerId, 22 | kFirstFreeId 23 | }; 24 | } // namespace ebbrt 25 | 26 | #endif // HOSTED_SRC_INCLUDE_EBBRT_STATICIDS_H_ 27 | -------------------------------------------------------------------------------- /src/hosted/Timer.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | // 6 | #include "../Timer.h" 7 | #include "Context.h" 8 | #include "EventManager.h" 9 | 10 | const constexpr ebbrt::EbbId ebbrt::Timer::static_id; 11 | 12 | ebbrt::Timer::Timer() {} 13 | 14 | void ebbrt::Timer::SetTimer(std::chrono::microseconds from_now) { 15 | EBBRT_UNIMPLEMENTED(); 16 | } 17 | 18 | void ebbrt::Timer::StopTimer() { EBBRT_UNIMPLEMENTED(); } 19 | 20 | void ebbrt::Timer::Start(Hook& hook, std::chrono::microseconds timeout, 21 | bool repeat) { 22 | auto t = std::make_shared( 23 | active_context->io_service_, 24 | boost::posix_time::microseconds(timeout.count())); 25 | 26 | t->async_wait(EventManager::WrapHandler( 27 | [&hook, t, repeat, timeout](const boost::system::error_code& e) { 28 | if (e) { 29 | ebbrt::kabort("ASIO Error: %d\n", e.value()); 30 | } 31 | if (repeat) { 32 | timer->Start(hook, timeout, repeat); 33 | } 34 | hook.Fire(); 35 | })); 36 | } 37 | 38 | void ebbrt::Timer::Stop(Hook& hook) { EBBRT_UNIMPLEMENTED(); } 39 | -------------------------------------------------------------------------------- /src/hosted/config.cmake: -------------------------------------------------------------------------------- 1 | # EbbRT hosted platform-specific configuration 2 | set(CMAKE_CXX_FLAGS "-Wall -Werror -std=gnu++14") 3 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 4 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 5 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 6 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 7 | 8 | find_package(Boost 1.53.0 REQUIRED COMPONENTS 9 | filesystem system coroutine context ) 10 | find_package(Capnp REQUIRED) 11 | find_package(TBB REQUIRED) 12 | include_directories(${Boost_INCLUDE_DIRS}) 13 | include_directories(${CAPNP_INCLUDE_DIRS}) 14 | include_directories(${TBB_INCLUDE_DIRS}) 15 | -------------------------------------------------------------------------------- /src/native/Acpi.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_ACPI_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_ACPI_H_ 7 | 8 | namespace ebbrt { 9 | namespace acpi { 10 | void BootInit(); 11 | void PowerOff(); 12 | } 13 | } 14 | 15 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_ACPI_H_ 16 | -------------------------------------------------------------------------------- /src/native/Apic.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Apic.h" 6 | 7 | #include 8 | 9 | #include "Cpu.h" 10 | #include "Cpuid.h" 11 | #include "Msr.h" 12 | 13 | void ebbrt::apic::Init() { 14 | auto apic_base = msr::Read(msr::kIa32ApicBase); 15 | // enable x2apic mode 16 | msr::Write(msr::kIa32ApicBase, apic_base | 0xc00); 17 | msr::Write(msr::kX2apicSvr, 0x100); 18 | } 19 | 20 | namespace { 21 | std::array eoi_words; 22 | 23 | bool PvEoi() { 24 | uint8_t ret; 25 | asm volatile("btr %[zero], %[eoi_word];" 26 | "setc %[ret]" 27 | : [eoi_word] "+m"(eoi_words[ebbrt::Cpu::GetMine()]), 28 | [ret] "=rm"(ret) 29 | : [zero] "r"(0)); 30 | return ret; 31 | } 32 | } // namespace 33 | 34 | void ebbrt::apic::PVEoiInit(size_t cpu) { 35 | if (cpuid::features.kvm_pv_eoi) { 36 | msr::Write(msr::kKvmPvEoi, 37 | reinterpret_cast(&eoi_words[cpu]) | 1); 38 | } 39 | } 40 | 41 | void ebbrt::apic::Ipi(uint8_t apic_id, uint8_t vector, bool level, 42 | uint8_t delivery_mode) { 43 | auto val = (uint64_t(apic_id) << 32) | (uint64_t(level) << 14) | 44 | (uint64_t(delivery_mode) << 8) | vector; 45 | msr::Write(msr::kX2apicIcr, val); 46 | } 47 | 48 | uint32_t ebbrt::apic::GetId() { return msr::Read(msr::kX2apicIdr); } 49 | 50 | void ebbrt::apic::Eoi() { 51 | if (PvEoi()) 52 | return; 53 | 54 | msr::Write(msr::kX2apicEoi, 0); 55 | } 56 | -------------------------------------------------------------------------------- /src/native/Apic.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_APIC_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_APIC_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace apic { 12 | void Init(); 13 | const constexpr uint8_t kDeliveryFixed = 0; 14 | const constexpr uint8_t kDeliverySmi = 2; 15 | const constexpr uint8_t kDeliveryNmi = 4; 16 | const constexpr uint8_t kDeliveryInit = 5; 17 | const constexpr uint8_t kDeliveryStartup = 6; 18 | 19 | void Ipi(uint8_t apic_id, uint8_t vector, bool level = true, 20 | uint8_t delivery_mode = kDeliveryFixed); 21 | void PVEoiInit(std::size_t cpu); 22 | uint32_t GetId(); 23 | void Eoi(); 24 | } // namespace apic 25 | } // namespace ebbrt 26 | 27 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_APIC_H_ 28 | -------------------------------------------------------------------------------- /src/native/Argv.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_ARGV_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_ARGV_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace ebbrt { 12 | namespace argv { 13 | const constexpr size_t kCmdLength = 256; 14 | 15 | struct Data { 16 | char cmdline_string[kCmdLength]; 17 | size_t len; 18 | }; 19 | extern Data data; 20 | 21 | size_t Init(const char* str); 22 | } // namespace argv 23 | } // namespace ebbrt 24 | 25 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_ARGV_H_ 26 | -------------------------------------------------------------------------------- /src/native/CDebug.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_CDEBUG_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_CDEBUG_H_ 7 | 8 | #ifdef __cplusplus 9 | extern "C" __attribute__((noreturn)) void 10 | ebbrt_kabort(const char* __restrict format, ...); 11 | #else 12 | __attribute__((noreturn)) void ebbrt_kabort(const char* __restrict format, ...); 13 | #endif 14 | 15 | #define EBBRT_UNIMPLEMENTED() \ 16 | do { \ 17 | ebbrt_kabort("%s: unimplemented\n", __PRETTY_FUNCTION__); \ 18 | } while (0) 19 | 20 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_CDEBUG_H_ 21 | -------------------------------------------------------------------------------- /src/native/Clock.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Clock_internal.h" 6 | 7 | #include "Cpuid.h" 8 | #include "Debug.h" 9 | #include "PitClock.h" 10 | #include "PvClock.h" 11 | 12 | namespace { 13 | ebbrt::clock::Clock* the_clock; 14 | } // namespace 15 | 16 | void ebbrt::clock::Init() { 17 | if (cpuid::features.kvm_clocksource2) { 18 | the_clock = PvClock::GetClock(); 19 | } else { 20 | the_clock = PitClock::GetClock(); 21 | } 22 | } 23 | 24 | void ebbrt::clock::ApInit() { the_clock->ApInit(); } 25 | 26 | ebbrt::clock::Wall::time_point ebbrt::clock::Wall::Now() noexcept { 27 | return the_clock->Now(); 28 | } 29 | 30 | std::chrono::nanoseconds ebbrt::clock::Uptime() noexcept { 31 | return the_clock->Uptime(); 32 | } 33 | 34 | std::chrono::nanoseconds ebbrt::clock::TscToNano(uint64_t tsc) noexcept { 35 | return the_clock->TscToNano(tsc); 36 | } 37 | 38 | void ebbrt::clock::SleepMilli(uint32_t t) { 39 | auto t1 = ebbrt::clock::Wall::Now(); 40 | while ((ebbrt::clock::Wall::Now() - t1) < std::chrono::milliseconds(t)) { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/native/Clock.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_CLOCK_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_CLOCK_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace clock { 12 | void Init(); 13 | void ApInit(); 14 | 15 | class Wall { 16 | public: 17 | typedef std::chrono::nanoseconds duration; 18 | typedef std::chrono::time_point time_point; 19 | 20 | static time_point Now() noexcept; 21 | // To keep compatability with standard clock interfaces 22 | static time_point now() { return Now(); } 23 | }; 24 | 25 | std::chrono::nanoseconds Uptime() noexcept; 26 | std::chrono::nanoseconds TscToNano(uint64_t tsc) noexcept; 27 | void SleepMilli(uint32_t t); 28 | 29 | class HighResTimer { 30 | public: 31 | void tick() __attribute__((always_inline)) { 32 | asm volatile("cpuid;" 33 | "rdtsc;" 34 | "mov %%edx, %0;" 35 | "mov %%eax, %1;" 36 | : "=r"(cycles_high_), "=r"(cycles_low_)::"%rax", "%rbx", 37 | "%rcx", "%rdx"); 38 | } 39 | std::chrono::nanoseconds tock() __attribute__((always_inline)) { 40 | uint32_t cycles_high1, cycles_low1; 41 | asm volatile("rdtscp;" 42 | "mov %%edx, %0;" 43 | "mov %%eax, %1;" 44 | "cpuid;" 45 | : "=r"(cycles_high1), "=r"(cycles_low1)::"%rax", "%rbx", 46 | "%rcx", "%rdx"); 47 | auto start = (((uint64_t)cycles_high_ << 32) | cycles_low_); 48 | auto end = (((uint64_t)cycles_high1 << 32 | cycles_low1)); 49 | auto sample = end - start; 50 | return TscToNano(sample); 51 | } 52 | 53 | private: 54 | uint32_t cycles_low_; 55 | uint32_t cycles_high_; 56 | }; 57 | } // namespace clock 58 | } // namespace ebbrt 59 | 60 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_CLOCK_H_ 61 | -------------------------------------------------------------------------------- /src/native/Clock_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_CLOCK_INTERNAL_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_CLOCK_INTERNAL_H_ 7 | 8 | #include "Clock.h" 9 | 10 | namespace ebbrt { 11 | namespace clock { 12 | class Clock { 13 | public: 14 | virtual void ApInit() = 0; 15 | virtual Wall::time_point Now() noexcept = 0; 16 | virtual std::chrono::nanoseconds Uptime() noexcept = 0; 17 | virtual std::chrono::nanoseconds TscToNano(uint64_t tsc) noexcept = 0; 18 | }; 19 | } 20 | } // namespace ebbrt 21 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_CLOCK_INTERNAL_H_ 22 | -------------------------------------------------------------------------------- /src/native/Cpu.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Cpu.h" 6 | 7 | #include "../ExplicitlyConstructed.h" 8 | #include "PageAllocator.h" 9 | 10 | namespace { 11 | ebbrt::ExplicitlyConstructed< 12 | boost::container::static_vector> 13 | cpus; 14 | } 15 | 16 | thread_local ebbrt::Cpu* ebbrt::Cpu::my_cpu_tls_; 17 | 18 | char ebbrt::Cpu::boot_interrupt_stack_[ebbrt::pmem::kPageSize]; 19 | 20 | void ebbrt::Cpu::EarlyInit() { cpus.construct(); } 21 | 22 | void ebbrt::Cpu::Init() { 23 | my_cpu_tls_ = this; 24 | gdt_.SetTssAddr(reinterpret_cast(&atss_.tss)); 25 | uint64_t interrupt_stack; 26 | if (index_ == 0) { 27 | interrupt_stack = 28 | reinterpret_cast(boot_interrupt_stack_ + pmem::kPageSize); 29 | } else { 30 | auto page = page_allocator->Alloc(); 31 | kbugon(page == Pfn::None(), 32 | "Unable to allocate page for interrupt stack\n"); 33 | interrupt_stack = page.ToAddr() + pmem::kPageSize; 34 | } 35 | atss_.tss.SetIstEntry(1, interrupt_stack); 36 | gdt_.Load(); 37 | idt::Load(); 38 | } 39 | 40 | void ebbrt::Cpu::SetEventStack(uintptr_t top_of_stack) { 41 | atss_.tss.SetIstEntry(2, top_of_stack); 42 | } 43 | 44 | ebbrt::Cpu* ebbrt::Cpu::GetByIndex(size_t index) { 45 | if (index > cpus->size() - 1) { 46 | return nullptr; 47 | } 48 | return &((*cpus)[index]); 49 | } 50 | 51 | ebbrt::Cpu& ebbrt::Cpu::Create() { 52 | cpus->emplace_back(cpus->size(), 0, 0); 53 | return (*cpus)[cpus->size() - 1]; 54 | } 55 | 56 | ebbrt::Cpu* ebbrt::Cpu::GetByApicId(size_t apic_id) { 57 | auto it = std::find_if(cpus->begin(), cpus->end(), 58 | [=](const Cpu& c) { return c.apic_id() == apic_id; }); 59 | if (it == cpus->end()) 60 | return nullptr; 61 | return &(*it); 62 | } 63 | 64 | size_t ebbrt::Cpu::Count() { return cpus->size(); } 65 | -------------------------------------------------------------------------------- /src/native/CpuAsm.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_CPUASM_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_CPUASM_H_ 7 | 8 | namespace ebbrt { 9 | inline uintptr_t ReadCr3() { 10 | uintptr_t cr3; 11 | asm volatile("mov %%cr3, %[cr3]" : [cr3] "=r"(cr3)); 12 | return cr3; 13 | } 14 | } 15 | 16 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_CPUASM_H_ 17 | -------------------------------------------------------------------------------- /src/native/Cpuid.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_CPUID_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_CPUID_H_ 7 | 8 | #include 9 | namespace ebbrt { 10 | namespace cpuid { 11 | 12 | struct Result { 13 | uint32_t eax; 14 | uint32_t ebx; 15 | uint32_t ecx; 16 | uint32_t edx; 17 | }; 18 | 19 | struct Features { 20 | bool x2apic; 21 | bool kvm_pv_eoi; 22 | bool kvm_clocksource2; 23 | }; 24 | 25 | extern Features features; 26 | 27 | Result Cpuid(uint32_t leaf); 28 | void Init(); 29 | } // namespace cpuid 30 | } // namespace ebbrt 31 | 32 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_CPUID_H_ 33 | -------------------------------------------------------------------------------- /src/native/Debug.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Debug.h" 6 | 7 | #include "../Console.h" 8 | 9 | void ebbrt::kvprintf(const char* __restrict format, va_list va) { 10 | va_list va2; 11 | va_copy(va2, va); 12 | auto len = vsnprintf(nullptr, 0, format, va); 13 | char buffer[len + 1]; // NOLINT 14 | vsnprintf(buffer, len + 1, format, va2); 15 | console::Write(buffer); 16 | } 17 | 18 | void ebbrt::kprintf(const char* __restrict format, ...) { 19 | #ifndef NDEBUG 20 | va_list ap; 21 | va_start(ap, format); 22 | kvprintf(format, ap); 23 | va_end(ap); 24 | #endif 25 | } 26 | 27 | void ebbrt::kprintf_force(const char* __restrict format, ...) { 28 | va_list ap; 29 | va_start(ap, format); 30 | kvprintf(format, ap); 31 | va_end(ap); 32 | } 33 | 34 | extern "C" void ebbrt_kabort(const char* __restrict format, ...) { 35 | va_list ap; 36 | va_start(ap, format); 37 | ebbrt::kvprintf(format, ap); 38 | va_end(ap); 39 | ebbrt::kabort(); 40 | } 41 | -------------------------------------------------------------------------------- /src/native/E820.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "E820.h" 6 | 7 | #include 8 | 9 | #include "../ExplicitlyConstructed.h" 10 | #include "Debug.h" 11 | 12 | ebbrt::ExplicitlyConstructed> 14 | ebbrt::e820::map; 15 | 16 | void ebbrt::e820::Init(multiboot::Information* mbi) { 17 | map.construct(); 18 | multiboot::MemoryRegion::ForEachRegion( 19 | reinterpret_cast(mbi->memory_map_address_), 20 | mbi->memory_map_length_, [](const multiboot::MemoryRegion& mmregion) { 21 | map->emplace_back(mmregion.base_address_, mmregion.length_, 22 | mmregion.type_); 23 | }); 24 | 25 | std::sort(std::begin(*map), std::end(*map)); 26 | } 27 | 28 | void ebbrt::e820::PrintMap() { 29 | kprintf("e820::map:\n"); 30 | std::for_each(std::begin(*map), std::end(*map), [](const Entry& entry) { 31 | kprintf("%#018" PRIx64 "-%#018" PRIx64 " ", entry.addr(), 32 | entry.addr() + entry.length() - 1); 33 | switch (entry.type()) { 34 | case Entry::kTypeRam: 35 | kprintf("usable"); 36 | break; 37 | case Entry::kTypeReservedUnusable: 38 | kprintf("reserved"); 39 | break; 40 | case Entry::kTypeAcpiReclaimable: 41 | kprintf("ACPI data"); 42 | break; 43 | case Entry::kTypeAcpiNvs: 44 | kprintf("ACPI NVS"); 45 | break; 46 | case Entry::kTypeBadMemory: 47 | kprintf("unusable"); 48 | break; 49 | default: 50 | kprintf("type %" PRIu32, entry.type()); 51 | break; 52 | } 53 | kprintf("\n"); 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /src/native/Fls.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_FLS_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_FLS_H_ 7 | 8 | namespace ebbrt { 9 | inline unsigned Fls(uint64_t word) { return 63 - __builtin_clzll(word); } 10 | } 11 | 12 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_FLS_H_ 13 | -------------------------------------------------------------------------------- /src/native/Io.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_IO_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_IO_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace io { 12 | inline void Out8(uint16_t port, uint8_t val) noexcept { 13 | asm volatile("outb %b[val], %w[port]" 14 | : // no output 15 | : [val] "a"(val), [port] "Nd"(port)); 16 | } 17 | inline void Out16(uint16_t port, uint16_t val) noexcept { 18 | asm volatile("outw %w[val], %w[port]" 19 | : // no output 20 | : [val] "a"(val), [port] "Nd"(port)); 21 | } 22 | inline void Out32(uint16_t port, uint32_t val) noexcept { 23 | asm volatile("outl %[val], %w[port]" 24 | : // no output 25 | : [val] "a"(val), [port] "Nd"(port)); 26 | } 27 | 28 | inline uint8_t In8(uint16_t port) noexcept { 29 | uint8_t val; 30 | asm volatile("inb %w[port], %b[val]" : [val] "=a"(val) : [port] "Nd"(port)); 31 | return val; 32 | } 33 | 34 | inline uint16_t In16(uint16_t port) noexcept { 35 | uint16_t val; 36 | asm volatile("inw %w[port], %w[val]" : [val] "=a"(val) : [port] "Nd"(port)); 37 | return val; 38 | } 39 | 40 | inline uint32_t In32(uint16_t port) noexcept { 41 | uint32_t val; 42 | asm volatile("inl %w[port], %[val]" : [val] "=a"(val) : [port] "Nd"(port)); 43 | return val; 44 | } 45 | } // namespace io 46 | } // namespace ebbrt 47 | 48 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_IO_H_ 49 | -------------------------------------------------------------------------------- /src/native/Isr.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_ISR_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_ISR_H_ 7 | 8 | namespace ebbrt { 9 | extern "C" void EventInterrupt(int num); 10 | } 11 | 12 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_ISR_H_ 13 | -------------------------------------------------------------------------------- /src/native/LocalEntry.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "../LocalEntry.h" 6 | 7 | #include "Trans.h" 8 | 9 | ebbrt::LocalEntry ebbrt::GetLocalEntry(EbbId id) { 10 | auto lref = reinterpret_cast(trans::kVMemStart + 11 | sizeof(LocalEntry) * id); 12 | return *lref; 13 | } 14 | 15 | void ebbrt::SetLocalEntry(EbbId id, LocalEntry le) { 16 | auto lref = reinterpret_cast(trans::kVMemStart + 17 | sizeof(LocalEntry) * id); 18 | *lref = le; 19 | } 20 | -------------------------------------------------------------------------------- /src/native/LocalIdMap.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "LocalIdMap.h" 6 | 7 | #include "../ExplicitlyConstructed.h" 8 | 9 | namespace { 10 | ebbrt::ExplicitlyConstructed the_map; 11 | } 12 | 13 | void ebbrt::LocalIdMap::Init() { the_map.construct(); } 14 | 15 | ebbrt::LocalIdMap& ebbrt::LocalIdMap::HandleFault(EbbId id) { 16 | kassert(id == kLocalIdMapId); 17 | auto& ref = *the_map; 18 | EbbRef::CacheRef(id, ref); 19 | return ref; 20 | } 21 | 22 | bool ebbrt::LocalIdMap::Insert(const ValueType& value) { 23 | return map_.insert(value); 24 | } 25 | 26 | bool ebbrt::LocalIdMap::Insert(Accessor& result, const EbbId& key) { 27 | return map_.insert(result, key); 28 | } 29 | 30 | bool ebbrt::LocalIdMap::Find(ConstAccessor& result, const EbbId& key) const { 31 | return map_.find(result, key); 32 | } 33 | 34 | bool ebbrt::LocalIdMap::Find(Accessor& result, const EbbId& key) { 35 | return map_.find(result, key); 36 | } 37 | -------------------------------------------------------------------------------- /src/native/LocalIdMap.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "../CacheAligned.h" 15 | #include "../StaticSharedEbb.h" 16 | #include "EbbRef.h" 17 | #include "StaticIds.h" 18 | 19 | namespace ebbrt { 20 | class LocalIdMap : public CacheAligned { 21 | public: 22 | typedef tbb::concurrent_hash_map< 23 | EbbId, boost::any, tbb::tbb_hash_compare, 24 | std::allocator>> 25 | MapType; 26 | 27 | typedef MapType::const_accessor ConstAccessor; 28 | typedef MapType::accessor Accessor; 29 | typedef MapType::value_type ValueType; 30 | 31 | static void Init(); 32 | static LocalIdMap& HandleFault(EbbId id); 33 | bool Find(ConstAccessor& result, const EbbId& key) const; 34 | bool Find(Accessor& result, const EbbId& key); 35 | bool Insert(ConstAccessor& result, const EbbId& key); 36 | bool Insert(Accessor& result, const EbbId& key); 37 | bool Insert(ConstAccessor& result, const ValueType& value); 38 | bool Insert(Accessor& result, const ValueType& value); 39 | bool Insert(const ValueType& value); 40 | bool Erase(const EbbId& key); 41 | bool Erase(ConstAccessor& item_accessor); 42 | bool Erase(Accessor& item_accessor); 43 | 44 | private: 45 | MapType map_; 46 | }; 47 | 48 | constexpr auto local_id_map = EbbRef(kLocalIdMapId); 49 | } // namespace ebbrt 50 | 51 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_LOCALIDMAP_H_ 52 | -------------------------------------------------------------------------------- /src/native/Main.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_MAIN_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_MAIN_H_ 7 | 8 | #include "Multiboot.h" 9 | 10 | namespace ebbrt { 11 | 12 | extern "C" __attribute__((noreturn)) void 13 | Main(ebbrt::multiboot::Information* mbi); 14 | } 15 | 16 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_MAIN_H_ 17 | -------------------------------------------------------------------------------- /src/native/MemMap.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "MemMap.h" 6 | 7 | #include "../Align.h" 8 | #include "EarlyPageAllocator.h" 9 | #include "Numa.h" 10 | 11 | std::array 12 | ebbrt::mem_map::sections; 13 | 14 | void ebbrt::mem_map::Init() { 15 | for (const auto& node : (*numa::nodes)) { 16 | for (const auto& memblock : node.memblocks) { 17 | auto nid = memblock.nid; 18 | auto start = memblock.start; 19 | auto end = memblock.end; 20 | 21 | start = Pfn(start.val() & kPageSectionMask); 22 | for (auto pfn = start; pfn < end; pfn += kPagesPerSection) { 23 | auto& section = PfnToSection(pfn); 24 | if (!section.Present()) { 25 | section.SetEarlyNid(nid); 26 | } 27 | } 28 | } 29 | } 30 | 31 | const auto section_map_bytes = kPagesPerSection * sizeof(Page); 32 | const auto section_map_pages = 33 | align::Up(section_map_bytes, pmem::kPageSize) >> pmem::kPageShift; 34 | for (unsigned i = 0; i < sections.size(); ++i) { 35 | auto& section = sections[i]; 36 | if (section.Present()) { 37 | auto nid = section.EarlyNid(); 38 | auto map_pfn = early_page_allocator::AllocatePage(section_map_pages, nid); 39 | auto map_addr = map_pfn.ToAddr(); 40 | auto map = reinterpret_cast(map_addr); 41 | for (unsigned j = 0; j < kPagesPerSection; j++) { 42 | new (reinterpret_cast(&map[j])) Page(nid); 43 | } 44 | section.SetMap(map_addr, i); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/native/Msr.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_MSR_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_MSR_H_ 7 | 8 | namespace ebbrt { 9 | namespace msr { 10 | const constexpr uint32_t kIa32ApicBase = 0x0000001b; 11 | const constexpr uint32_t kX2apicIdr = 0x00000802; 12 | const constexpr uint32_t kX2apicEoi = 0x0000080b; 13 | const constexpr uint32_t kX2apicSvr = 0x0000080f; 14 | const constexpr uint32_t kX2apicIcr = 0x00000830; 15 | const constexpr uint32_t kX2apicLvtTimer = 0x832; 16 | const constexpr uint32_t kX2apicInitCount = 0x838; 17 | const constexpr uint32_t kX2apicCurrentCount = 0x839; 18 | const constexpr uint32_t kX2apicDcr = 0x83e; 19 | const constexpr uint32_t kKvmWallClockNew = 0x4b564d00; 20 | const constexpr uint32_t kKvmSystemTimeNew = 0x4b564d01; 21 | const constexpr uint32_t kKvmPvEoi = 0x4b564d04; 22 | const constexpr uint32_t kIa32FsBase = 0xC0000100; 23 | 24 | inline uint64_t Read(uint32_t index) { 25 | uint32_t low, high; 26 | asm volatile("rdmsr" : "=a"(low), "=d"(high) : "c"(index)); 27 | return low | (uint64_t(high) << 32); 28 | } 29 | 30 | inline void Write(uint32_t index, uint64_t data) { 31 | uint32_t low = data; 32 | uint32_t high = data >> 32; 33 | asm volatile("wrmsr" : : "c"(index), "a"(low), "d"(high)); 34 | } 35 | } // namespace msr 36 | } // namespace ebbrt 37 | 38 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_MSR_H_ 39 | -------------------------------------------------------------------------------- /src/native/Multiboot.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Multiboot.h" 6 | 7 | #include 8 | 9 | #include "EarlyPageAllocator.h" 10 | 11 | uintptr_t ebbrt::multiboot::cmdline_addr_; 12 | uintptr_t ebbrt::multiboot::cmdline_len_; 13 | ebbrt::multiboot::Information* ebbrt::multiboot::info; 14 | 15 | void ebbrt::multiboot::Reserve(Information* mbi) { 16 | info = mbi; 17 | auto mbi_addr = reinterpret_cast(mbi); 18 | early_page_allocator::ReserveRange(mbi_addr, mbi_addr + sizeof(*mbi)); 19 | if (mbi->has_command_line_) { 20 | cmdline_addr_ = mbi->command_line_; 21 | auto cmdline = reinterpret_cast(cmdline_addr_); 22 | cmdline_len_ = std::strlen(cmdline); 23 | early_page_allocator::ReserveRange(cmdline_addr_, 24 | cmdline_addr_ + cmdline_len_ + 1); 25 | } 26 | 27 | if (mbi->has_boot_modules_ && mbi->modules_count_ > 0) { 28 | uintptr_t module_addr = mbi->modules_address_; 29 | auto module_end = module_addr + mbi->modules_count_ * sizeof(Module); 30 | early_page_allocator::ReserveRange(module_addr, module_end); 31 | auto mods = reinterpret_cast(module_addr); 32 | for (uint32_t i = 0; i < mbi->modules_count_; ++i) { 33 | early_page_allocator::ReserveRange(mods[i].start, mods[i].end); 34 | uintptr_t str_addr = mods[i].string; 35 | auto str = reinterpret_cast(str_addr); 36 | auto len = std::strlen(str); 37 | early_page_allocator::ReserveRange(str_addr, str_addr + len + 1); 38 | } 39 | } 40 | 41 | // TODO(dschatz): reserve ELF section headers and others 42 | } 43 | 44 | const char* ebbrt::multiboot::CmdLine() { 45 | return reinterpret_cast(cmdline_addr_); 46 | } 47 | -------------------------------------------------------------------------------- /src/native/Net.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Net.h" 6 | 7 | void ebbrt::NetworkManager::Init() {} 8 | 9 | ebbrt::NetworkManager::Interface& 10 | ebbrt::NetworkManager::NewInterface(EthernetDevice& ether_dev) { 11 | interface_.reset(new Interface(ether_dev)); 12 | return *interface_; 13 | } 14 | 15 | ebbrt::NetworkManager::Interface& 16 | ebbrt::NetworkManager::GetInterface() { 17 | if (!interface_) 18 | std::runtime_error("No interface available"); 19 | return *interface_; 20 | } 21 | 22 | ebbrt::NetworkManager::Interface& 23 | ebbrt::NetworkManager::NewLoopback(EthernetDevice& ether_dev) { 24 | loopback_.reset(new Interface(ether_dev)); 25 | return *loopback_; 26 | } 27 | 28 | void ebbrt::NetworkManager::Interface::Receive(std::unique_ptr buf) { 29 | auto packet_len = buf->ComputeChainDataLength(); 30 | 31 | // Drop packets that are too small 32 | if (packet_len <= sizeof(EthernetHeader)) 33 | return; 34 | 35 | auto dp = buf->GetMutDataPointer(); 36 | auto& eth_header = dp.Get(); 37 | 38 | buf->Advance(sizeof(EthernetHeader)); 39 | 40 | switch (ntohs(eth_header.type)) { 41 | case kEthTypeIp: { 42 | ReceiveIp(eth_header, std::move(buf)); 43 | break; 44 | } 45 | case kEthTypeArp: { 46 | ReceiveArp(eth_header, std::move(buf)); 47 | break; 48 | } 49 | } 50 | } 51 | 52 | const ebbrt::EthernetAddress& ebbrt::NetworkManager::Interface::MacAddress() { 53 | return ether_dev_.GetMacAddress(); 54 | } 55 | 56 | void ebbrt::NetworkManager::Interface::Send(std::unique_ptr b, 57 | PacketInfo pinfo) { 58 | ether_dev_.Send(std::move(b), std::move(pinfo)); 59 | } 60 | -------------------------------------------------------------------------------- /src/native/NetChecksum.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_NETCHECKSUM_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_NETCHECKSUM_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "../IOBuf.h" 12 | #include "NetIp.h" 13 | 14 | namespace ebbrt { 15 | uint16_t OffloadPseudoCsum(const IOBuf& buf, uint8_t proto, Ipv4Address src, 16 | Ipv4Address dst); 17 | uint16_t IpPseudoCsum(const IOBuf& buf, uint8_t proto, Ipv4Address src, 18 | Ipv4Address dst); 19 | uint16_t IpCsum(const IOBuf& buf); 20 | uint16_t IpCsum(const uint8_t* buf, size_t len); 21 | } // namespace ebbrt 22 | 23 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_NETCHECKSUM_H_ 24 | -------------------------------------------------------------------------------- /src/native/NetIcmp.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Net.h" 6 | 7 | #include "NetChecksum.h" 8 | #include "NetIcmp.h" 9 | // Receive an ICMP packet. Currently, if we get a request (ping) we just send 10 | // back a reply 11 | void ebbrt::NetworkManager::Interface::ReceiveIcmp( 12 | EthernetHeader& eth_header, Ipv4Header& ip_header, 13 | std::unique_ptr buf) { 14 | auto packet_len = buf->ComputeChainDataLength(); 15 | 16 | if (unlikely(packet_len < sizeof(IcmpHeader))) 17 | return; 18 | 19 | auto dp = buf->GetMutDataPointer(); 20 | auto& icmp_header = dp.Get(); 21 | 22 | // checksum 23 | if (IpCsum(*buf)) 24 | return; 25 | 26 | // if echo_request, send reply 27 | if (icmp_header.type == kIcmpEchoRequest) { 28 | // we reuse the incoming packet to send the reply 29 | auto tmp = ip_header.dst; 30 | ip_header.dst = ip_header.src; 31 | ip_header.src = tmp; 32 | 33 | icmp_header.type = kIcmpEchoReply; 34 | 35 | // adjust checksum 36 | auto addend = static_cast(kIcmpEchoRequest) << 8; 37 | // check wrap of checksum 38 | if (icmp_header.checksum >= htons(0xffff - addend)) { 39 | icmp_header.checksum += htons(addend) + 1; 40 | } else { 41 | icmp_header.checksum += htons(addend); 42 | } 43 | 44 | ip_header.ttl = kIpDefaultTtl; 45 | ip_header.chksum = 0; 46 | ip_header.chksum = ip_header.ComputeChecksum(); 47 | 48 | buf->Retreat(ip_header.HeaderLength()); 49 | EthArpSend(kEthTypeIp, ip_header, std::move(buf)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/native/NetIcmp.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_NETICMP_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_NETICMP_H_ 7 | 8 | namespace ebbrt { 9 | struct __attribute__((packed)) IcmpHeader { 10 | uint8_t type; 11 | uint8_t code; 12 | uint16_t checksum; 13 | uint32_t remainder; 14 | }; 15 | 16 | const constexpr uint8_t kIcmpEchoReply = 0; 17 | const constexpr uint8_t kIcmpEchoRequest = 8; 18 | } // namespace ebbrt 19 | 20 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_NETICMP_H_ 21 | -------------------------------------------------------------------------------- /src/native/NetMisc.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_NETMISC_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_NETMISC_H_ 7 | 8 | namespace ebbrt { 9 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 10 | constexpr uint32_t htonl(uint32_t data) { return __builtin_bswap32(data); } 11 | constexpr uint16_t htons(uint16_t data) { return __builtin_bswap16(data); } 12 | #else 13 | constexpr uint32_t htonl(uint32_t data) { return data; } 14 | constexpr uint16_t htons(uint16_t data) { return data; } 15 | #endif 16 | constexpr uint32_t ntohl(uint32_t data) { return htonl(data); } 17 | constexpr uint16_t ntohs(uint16_t data) { return htons(data); } 18 | } // namespace ebbrt 19 | 20 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_NETMISC_H_ 21 | -------------------------------------------------------------------------------- /src/native/NetTcp.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_NETTCP_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_NETTCP_H_ 7 | 8 | namespace ebbrt { 9 | const constexpr size_t kTcpMss = 1460; 10 | const constexpr uint32_t kTcpWnd = 1 << 21; 11 | const constexpr uint8_t kWindowShift = 7; 12 | 13 | const constexpr uint16_t TcpWindow16(uint32_t sz) { 14 | return sz >> kWindowShift; 15 | } 16 | 17 | const constexpr uint16_t kTcpFin = 0x01; 18 | const constexpr uint16_t kTcpSyn = 0x02; 19 | const constexpr uint16_t kTcpRst = 0x04; 20 | const constexpr uint16_t kTcpPsh = 0x08; 21 | const constexpr uint16_t kTcpAck = 0x10; 22 | const constexpr uint16_t kTcpUrg = 0x20; 23 | const constexpr uint16_t kTcpEce = 0x40; 24 | const constexpr uint16_t kTcpCwr = 0x80; 25 | 26 | const constexpr uint16_t kTcpFlagMask = 0x3f; 27 | 28 | struct __attribute__((packed)) TcpHeader { 29 | void SetHdrLenFlags(size_t header_len, uint16_t flags) { 30 | auto header_words = header_len / 4; 31 | hdrlen_flags = htons((header_words << 12) | flags); 32 | } 33 | 34 | void SetFlags(uint16_t flags) { 35 | hdrlen_flags &= ~htons(0xFFF); 36 | hdrlen_flags |= htons(flags & 0xFFF); 37 | } 38 | 39 | size_t HdrLen() const { return (ntohs(hdrlen_flags) >> 12) * 4; } 40 | 41 | uint16_t Flags() const { return ntohs(hdrlen_flags) & kTcpFlagMask; } 42 | uint16_t src_port; 43 | uint16_t dst_port; 44 | uint32_t seqno; 45 | uint32_t ackno; 46 | uint16_t hdrlen_flags; 47 | uint16_t wnd; 48 | uint16_t checksum; 49 | uint16_t urgp; 50 | char options[]; 51 | }; 52 | 53 | struct TcpInfo { 54 | uint16_t src_port; 55 | uint16_t dst_port; 56 | uint32_t seqno; 57 | uint32_t ackno; 58 | size_t tcplen; 59 | }; 60 | 61 | } // namespace ebbrt 62 | 63 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_NETTCP_H_ 64 | -------------------------------------------------------------------------------- /src/native/NetUdp.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_NETUDP_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_NETUDP_H_ 7 | 8 | namespace ebbrt { 9 | struct __attribute__((packed)) UdpHeader { 10 | uint16_t src_port; 11 | uint16_t dst_port; 12 | uint16_t length; 13 | uint16_t checksum; 14 | }; 15 | } // namespace ebbrt 16 | 17 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_NETUDP_H_ 18 | -------------------------------------------------------------------------------- /src/native/Numa.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_NUMA_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_NUMA_H_ 7 | 8 | #include 9 | 10 | #include "../ExplicitlyConstructed.h" 11 | #include "../Nid.h" 12 | #include "Pfn.h" 13 | 14 | namespace ebbrt { 15 | namespace numa { 16 | const constexpr size_t kMaxNodes = 256; 17 | const constexpr size_t kMaxMemblocks = 256; 18 | 19 | struct Memblock { 20 | Memblock(Pfn start, Pfn end, Nid nid) : start(start), end(end), nid(nid) {} 21 | Pfn start; 22 | Pfn end; 23 | Nid nid; 24 | }; 25 | 26 | inline bool operator<(const Memblock& lhs, const Memblock& rhs) noexcept { 27 | return lhs.start < rhs.start; 28 | } 29 | 30 | struct Node { 31 | boost::container::static_vector memblocks; 32 | Pfn pfn_start; 33 | Pfn pfn_end; 34 | }; 35 | 36 | void EarlyInit(); 37 | void Init(); 38 | Nid SetupNode(size_t proximity_domain); 39 | void MapApicToNode(size_t apic_id, Nid nid); 40 | void AddMemBlock(Nid nid, Pfn start, Pfn End); 41 | 42 | extern ebbrt::ExplicitlyConstructed< 43 | boost::container::static_vector> 44 | nodes; 45 | 46 | } // namespace numa 47 | } // namespace ebbrt 48 | 49 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_NUMA_H_ 50 | -------------------------------------------------------------------------------- /src/native/PMem.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_PMEM_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_PMEM_H_ 7 | 8 | namespace ebbrt { 9 | namespace pmem { 10 | const constexpr size_t kPageShift = 12; 11 | const constexpr size_t kPageSize = 1 << kPageShift; 12 | 13 | const constexpr size_t kLargePageShift = 21; 14 | const constexpr size_t kLargePageSize = 1 << kLargePageShift; 15 | } 16 | } 17 | 18 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_PMEM_H_ 19 | -------------------------------------------------------------------------------- /src/native/Pic.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Pic.h" 6 | 7 | #include "Cpuid.h" 8 | #include "Debug.h" 9 | #include "Io.h" 10 | 11 | void ebbrt::pic::Disable() { 12 | if (!cpuid::features.x2apic) { 13 | kprintf("No support for x2apic! Aborting\n"); 14 | kabort(); 15 | } 16 | 17 | // disable pic by masking all irqs 18 | io::Out8(0x21, 0xff); 19 | io::Out8(0xa1, 0xff); 20 | } 21 | -------------------------------------------------------------------------------- /src/native/Pic.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_PIC_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_PIC_H_ 7 | 8 | namespace ebbrt { 9 | namespace pic { 10 | void Disable(); 11 | } 12 | } 13 | 14 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_PIC_H_ 15 | -------------------------------------------------------------------------------- /src/native/PitClock.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_PITCLOCK_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_PITCLOCK_H_ 7 | 8 | #include "Clock_internal.h" 9 | 10 | namespace ebbrt { 11 | namespace clock { 12 | class PitClock : public Clock { 13 | public: 14 | static PitClock* GetClock(); 15 | 16 | PitClock(); 17 | 18 | void ApInit() override; 19 | Wall::time_point Now() noexcept override; 20 | std::chrono::nanoseconds Uptime() noexcept override; 21 | std::chrono::nanoseconds TscToNano(uint64_t tsc) noexcept override; 22 | }; 23 | } // namespace clock 24 | } // namespace ebbrt 25 | 26 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_PITCLOCK_H_ 27 | -------------------------------------------------------------------------------- /src/native/Preprocessor.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_PREPROCESSOR_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_PREPROCESSOR_H_ 7 | 8 | #define STR(x) #x 9 | #define STR2(x) STR(x) 10 | 11 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_PREPROCESSOR_H_ 12 | -------------------------------------------------------------------------------- /src/native/PvClock.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_PVCLOCK_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_PVCLOCK_H_ 7 | 8 | #include "Clock_internal.h" 9 | 10 | namespace ebbrt { 11 | namespace clock { 12 | class PvClock : public Clock { 13 | public: 14 | static PvClock* GetClock(); 15 | 16 | PvClock(); 17 | 18 | void ApInit() override; 19 | Wall::time_point Now() noexcept override; 20 | std::chrono::nanoseconds Uptime() noexcept override; 21 | std::chrono::nanoseconds TscToNano(uint64_t tsc) noexcept override; 22 | }; 23 | } // namespace clock 24 | } // namespace ebbrt 25 | 26 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_PVCLOCK_H_ 27 | -------------------------------------------------------------------------------- /src/native/Random.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Random.h" 6 | 7 | #include 8 | 9 | #include "../ExplicitlyConstructed.h" 10 | #include "Clock.h" 11 | 12 | namespace { 13 | ebbrt::ExplicitlyConstructed gen; 14 | ebbrt::ExplicitlyConstructed> dis; 15 | } 16 | 17 | void ebbrt::random::Init() { 18 | gen.construct(clock::Wall::Now().time_since_epoch().count()); 19 | dis.construct(); 20 | } 21 | 22 | uint64_t ebbrt::random::Get() { return (*dis)(*gen); } 23 | -------------------------------------------------------------------------------- /src/native/Random.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_RANDOM_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_RANDOM_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace random { 12 | void Init(); 13 | uint64_t Get(); 14 | } 15 | } 16 | 17 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_RANDOM_H_ 18 | -------------------------------------------------------------------------------- /src/native/Rdtsc.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_RDTSC_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_RDTSC_H_ 7 | 8 | namespace ebbrt { 9 | inline uint64_t rdtsc() { 10 | uint64_t tsc; 11 | asm volatile("rdtsc;" 12 | "shl $32,%%rdx;" 13 | "or %%rdx,%%rax" 14 | : "=a"(tsc) 15 | : 16 | : "%rcx", "%rdx"); 17 | return tsc; 18 | } 19 | 20 | inline uint64_t rdtscp() { 21 | uint64_t tsc; 22 | asm volatile("rdtscp;" 23 | "shl $32,%%rdx;" 24 | "or %%rdx,%%rax" 25 | : "=a"(tsc) 26 | : 27 | : "%rcx", "%rdx"); 28 | return tsc; 29 | } 30 | } // namespace ebbrt 31 | 32 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_RDTSC_H_ 33 | -------------------------------------------------------------------------------- /src/native/Runtime.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_RUNTIME_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_RUNTIME_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace runtime { 12 | uint32_t Frontend(); 13 | uint32_t AllocationId(); 14 | void Init(); 15 | } 16 | } 17 | 18 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_RUNTIME_H_ 19 | -------------------------------------------------------------------------------- /src/native/Semaphore.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_SEMAPHORE_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_SEMAPHORE_H_ 7 | 8 | namespace ebbrt { 9 | class Semaphore {}; 10 | } 11 | 12 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_SEMAPHORE_H_ 13 | -------------------------------------------------------------------------------- /src/native/SharedPoolAllocator.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_SHAREDPOOLALLOCATOR_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_SHAREDPOOLALLOCATOR_H_ 7 | 8 | #pragma GCC diagnostic push 9 | #pragma GCC diagnostic ignored "-Wunused-local-typedefs" 10 | #include 11 | #include 12 | #pragma GCC diagnostic pop 13 | #include 14 | 15 | #include "../CacheAligned.h" 16 | #include "../SharedEbb.h" 17 | 18 | namespace ebbrt { 19 | template 20 | class SharedPoolAllocator : public SharedEbb>, 21 | public CacheAligned { 22 | public: 23 | static EbbRef> 24 | Create(T begin, T end, EbbId id = ebb_allocator->Allocate()) { 25 | return SharedEbb>::Create( 26 | new SharedPoolAllocator(begin, end), id); 27 | } 28 | 29 | SharedPoolAllocator(T begin, T end) { 30 | set_ += typename boost::icl::interval::type(begin, end); 31 | } 32 | 33 | boost::optional Allocate() { 34 | std::lock_guard guard(lock_); 35 | if (unlikely(set_.empty())) { 36 | return boost::optional(); 37 | } 38 | 39 | auto ret = boost::icl::lower(set_); 40 | set_ -= ret; 41 | return boost::optional(ret); 42 | } 43 | 44 | bool Reserve(const T& val) { 45 | std::lock_guard guard(lock_); 46 | if (boost::icl::contains(set_, val)) { 47 | set_ -= val; 48 | return true; 49 | } 50 | return false; 51 | } 52 | 53 | void Free(T val) { 54 | std::lock_guard guard(lock_); 55 | set_ += val; 56 | } 57 | 58 | private: 59 | ebbrt::SpinLock lock_; 60 | boost::icl::interval_set set_; 61 | }; 62 | } // namespace ebbrt 63 | 64 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_SHAREDPOOLALLOCATOR_H_ 65 | -------------------------------------------------------------------------------- /src/native/SlabObject.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_SLABOBJECT_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_SLABOBJECT_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | class FreeObject { 12 | public: 13 | void* addr() { return this; } 14 | 15 | boost::intrusive::slist_member_hook< 16 | boost::intrusive::link_mode> 17 | member_hook_; 18 | }; 19 | 20 | typedef boost::intrusive::slist< 21 | FreeObject, boost::intrusive::cache_last, 22 | boost::intrusive::member_hook< 23 | FreeObject, 24 | boost::intrusive::slist_member_hook< 25 | boost::intrusive::link_mode>, 26 | &FreeObject::member_hook_>> 27 | FreeObjectList; 28 | 29 | typedef boost::intrusive::slist< // NOLINT 30 | FreeObject, boost::intrusive::constant_time_size, 31 | boost::intrusive::member_hook< 32 | FreeObject, 33 | boost::intrusive::slist_member_hook< 34 | boost::intrusive::link_mode>, 35 | &FreeObject::member_hook_>> 36 | CompactFreeObjectList; 37 | } // namespace ebbrt 38 | 39 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_SLABOBJECT_H_ 40 | -------------------------------------------------------------------------------- /src/native/Smp.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_SMP_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_SMP_H_ 7 | 8 | #define SMP_START_ADDRESS (0x4000) 9 | 10 | #ifndef ASSEMBLY 11 | namespace ebbrt { 12 | namespace smp { 13 | void Init(); 14 | extern "C" __attribute__((noreturn)) void SmpMain(); 15 | } 16 | } 17 | #endif 18 | 19 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_SMP_H_ 20 | -------------------------------------------------------------------------------- /src/native/Stack.S: -------------------------------------------------------------------------------- 1 | .global SwitchStack 2 | SwitchStack: 3 | .cfi_startproc simple 4 | .cfi_def_cfa %rsp, 0 5 | .cfi_undefined %rip 6 | mov %rsi, %rsp 7 | callq *%rdx 8 | .cfi_endproc 9 | 10 | .global SaveContextAndSwitch 11 | SaveContextAndSwitch: 12 | .cfi_startproc simple 13 | .cfi_def_cfa %rsp, 0 14 | .cfi_undefined %rip 15 | mov %rbx, (%rcx) 16 | mov %rsp, 8(%rcx) 17 | mov %rbp, 16(%rcx) 18 | mov %r12, 24(%rcx) 19 | mov %r13, 32(%rcx) 20 | mov %r14, 40(%rcx) 21 | mov %r15, 48(%rcx) 22 | mov %rsi, %rsp 23 | callq *%rdx 24 | // will not get here return happens at ActivateContextAndReturn 25 | .cfi_endproc 26 | 27 | 28 | .global ActivateContextAndReturn 29 | ActivateContextAndReturn: 30 | mov (%rdi), %rbx 31 | mov 8(%rdi), %rsp 32 | mov 16(%rdi), %rbp 33 | mov 24(%rdi), %r12 34 | mov 32(%rdi), %r13 35 | mov 40(%rdi), %r14 36 | mov 48(%rdi), %r15 37 | ret 38 | 39 | .global SaveContextAndActivate 40 | SaveContextAndActivate: 41 | // Save to first arg 42 | mov %rbx, (%rdi) 43 | mov %rsp, 8(%rdi) 44 | mov %rbp, 16(%rdi) 45 | mov %r12, 24(%rdi) 46 | mov %r13, 32(%rdi) 47 | mov %r14, 40(%rdi) 48 | mov %r15, 48(%rdi) 49 | // Reload from other 50 | mov (%rsi), %rbx 51 | mov 8(%rsi), %rsp 52 | mov 16(%rsi), %rbp 53 | mov 24(%rsi), %r12 54 | mov 32(%rsi), %r13 55 | mov 40(%rsi), %r14 56 | mov 48(%rsi), %r15 57 | ret 58 | 59 | -------------------------------------------------------------------------------- /src/native/StaticIds.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_STATICIDS_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_STATICIDS_H_ 7 | 8 | #include "../EbbId.h" 9 | #include "../GlobalStaticIds.h" 10 | 11 | namespace ebbrt { 12 | enum : EbbId { 13 | kPageAllocatorId = kFirstLocalId, 14 | kGpAllocatorId, 15 | kLocalIdMapId, 16 | kEbbAllocatorId, 17 | kEventManagerId, 18 | kVMemAllocatorId, 19 | kTimerId, 20 | kNetworkManagerId, 21 | kMessengerId, 22 | kFirstFreeId 23 | }; 24 | 25 | static_assert(kFirstFreeId < kFirstStaticUserId, "Id clash!"); 26 | } // namespace ebbrt 27 | 28 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_STATICIDS_H_ 29 | -------------------------------------------------------------------------------- /src/native/Tls.cc: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include "Tls.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include "../ExplicitlyConstructed.h" 12 | #include "Cpu.h" 13 | #include "GeneralPurposeAllocator.h" 14 | #include "Msr.h" 15 | 16 | struct ThreadControlBlock { 17 | ThreadControlBlock* self; 18 | }; 19 | 20 | extern char tcb0[]; 21 | extern char tls_start[]; 22 | extern char tls_end[]; 23 | 24 | namespace { 25 | ebbrt::ExplicitlyConstructed< 26 | boost::container::static_vector> 27 | tls_ptrs; 28 | } 29 | 30 | void ebbrt::tls::Init() { 31 | auto tls_size = tls_end - tls_start; 32 | std::copy(tls_start, tls_end, tcb0); 33 | auto p = reinterpret_cast(tcb0 + tls_size); 34 | p->self = p; 35 | 36 | msr::Write(msr::kIa32FsBase, reinterpret_cast(p)); 37 | tls_ptrs.construct(); 38 | } 39 | 40 | void ebbrt::tls::SmpInit() { 41 | tls_ptrs->emplace_back(static_cast(tcb0)); 42 | auto tls_size = align::Up(tls_end - tls_start + 8, 64); 43 | for (size_t i = 1; i < Cpu::Count(); ++i) { 44 | auto nid = Cpu::GetByIndex(i)->nid(); 45 | auto ptr = gp_allocator->AllocNid(tls_size, nid); 46 | kbugon(ptr == nullptr, "Failed to allocate TLS region\n"); 47 | tls_ptrs->emplace_back(ptr); 48 | } 49 | } 50 | 51 | void ebbrt::tls::ApInit(size_t index) { 52 | auto tcb = static_cast((*tls_ptrs)[index]); 53 | std::copy(tls_start, tls_end, tcb); 54 | auto tls_size = tls_end - tls_start; 55 | auto p = reinterpret_cast(tcb + tls_size); 56 | p->self = p; 57 | 58 | msr::Write(msr::kIa32FsBase, reinterpret_cast(p)); 59 | } 60 | -------------------------------------------------------------------------------- /src/native/Tls.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_TLS_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_TLS_H_ 7 | 8 | #include 9 | 10 | namespace ebbrt { 11 | namespace tls { 12 | void Init(); 13 | void SmpInit(); 14 | void ApInit(size_t size); 15 | } 16 | } 17 | 18 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_TLS_H_ 19 | -------------------------------------------------------------------------------- /src/native/Trans.h: -------------------------------------------------------------------------------- 1 | // Copyright Boston University SESA Group 2013 - 2014. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BAREMETAL_SRC_INCLUDE_EBBRT_TRANS_H_ 6 | #define BAREMETAL_SRC_INCLUDE_EBBRT_TRANS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "Idt.h" 12 | 13 | namespace ebbrt { 14 | namespace trans { 15 | // last 2^32 bits of virtual address space are reserved for translation tables 16 | const constexpr uintptr_t kVMemStart = 0xFFFFFFFF00000000; 17 | 18 | void Init(); 19 | void ApInit(size_t index); 20 | void HandleFault(idt::ExceptionFrame* ef, uintptr_t fault_addr); 21 | } 22 | } 23 | 24 | #endif // BAREMETAL_SRC_INCLUDE_EBBRT_TRANS_H_ 25 | -------------------------------------------------------------------------------- /src/native/config.cmake: -------------------------------------------------------------------------------- 1 | # EbbRT native platform-specific configuration 2 | option(__EBBRT_ENABLE_DISTRIBUTED_RUNTIME__ "Enable Distributed Runtime Support" ON) 3 | option(__EBBRT_ENABLE_NETWORKING__ "Enable Networking" ON) 4 | option(__EBBRT_ENABLE_TRACE__ "Enable Tracing Subsystem" OFF) 5 | option(LARGE_WINDOW_HACK "Enable Large TCP Window Hack" OFF) 6 | option(PAGE_CHECKER "Enable Page Checker" OFF) 7 | option(VIRTIO_ZERO_COPY "Enable Virtio Zero Copy" OFF) 8 | option(VIRTIO_NET_POLL "Enable Poll-Only VirtioNet Driver" OFF) 9 | configure_file(${PLATFORM_SOURCE_DIR}/config.h.in config.h @ONLY) 10 | 11 | # Build Settings 12 | set(CMAKE_CXX_FLAGS "-Wall -Werror -std=gnu++14 -include ${CMAKE_CURRENT_BINARY_DIR}/config.h") 13 | set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") 14 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 15 | set(CMAKE_CXX_FLAGS_RELEASE "-O4 -flto -DNDEBUG") 16 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g3") 17 | set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) 18 | set(CMAKE_ASM_FLAGS "-DASSEMBLY") 19 | 20 | # This is a bit of a hack to get the host capnp import path, rather than 21 | # the sysroot ones which will be found by default 22 | find_package(CapnProto QUIET) 23 | get_filename_component(capnp_dir_path "${CAPNP_EXECUTABLE}" DIRECTORY) 24 | get_filename_component(CAPNPC_IMPORT_DIRS "${capnp_dir_path}/../include" ABSOLUTE) 25 | -------------------------------------------------------------------------------- /src/native/config.h.in: -------------------------------------------------------------------------------- 1 | #cmakedefine __EBBRT_ENABLE_DISTRIBUTED_RUNTIME__ 2 | #cmakedefine __EBBRT_ENABLE_NETWORKING__ 3 | #cmakedefine __EBBRT_ENABLE_TRACE__ 4 | #cmakedefine LARGE_WINDOW_HACK 5 | #cmakedefine PAGE_CHECKER 6 | #cmakedefine VIRTIO_ZERO_COPY 7 | #cmakedefine VIRTIO_NET_POLL 8 | -------------------------------------------------------------------------------- /toolchain/.gitignore: -------------------------------------------------------------------------------- 1 | config.mk 2 | build 3 | deps 4 | src 5 | sysroot 6 | -------------------------------------------------------------------------------- /toolchain/patches/capnproto-c++-0.4.0.patch: -------------------------------------------------------------------------------- 1 | --- a/src/capnp/schema.c++ 2016-07-09 18:22:39.020528106 -0400 2 | +++ b/src/capnp/schema.c++ 2016-07-09 18:21:48.746358085 -0400 3 | @@ -439,7 +439,7 @@ 4 | bool InterfaceSchema::extends(InterfaceSchema other, uint& counter) const { 5 | // Security: Don't let someone DOS us with a dynamic schema containing cyclic inheritance. 6 | KJ_REQUIRE(counter++ < MAX_SUPERCLASSES, "Cyclic or absurdly-large inheritance graph detected.") { 7 | - return nullptr; 8 | + return false; 9 | } 10 | 11 | if (other == *this) { 12 | --------------------------------------------------------------------------------