├── .dockerignore ├── .gitattributes ├── .github └── workflows │ ├── alpinelinux.yaml │ ├── docker.yaml │ ├── python-lint.yaml │ ├── test.yaml │ └── tests.yaml ├── .gitignore ├── .gitmodules ├── .gitorderfile ├── .mailmap ├── CMakeLists.txt ├── CONTRIBUTING.md ├── HACKING.md ├── LICENSE ├── NOTICE ├── README-DPDK.md ├── README.md ├── apps ├── CMakeLists.txt ├── httpd │ ├── CMakeLists.txt │ ├── demo.json │ └── main.cc ├── io_tester │ ├── CMakeLists.txt │ ├── conf.yaml │ ├── io_tester.cc │ └── ioinfo.cc ├── iotune │ ├── CMakeLists.txt │ └── iotune.cc ├── lib │ └── stop_signal.hh ├── memcached │ ├── CMakeLists.txt │ ├── ascii.rl │ ├── memcache.cc │ ├── memcached.hh │ └── tests │ │ ├── CMakeLists.txt │ │ ├── test.py │ │ ├── test_ascii_parser.cc │ │ └── test_memcached.py ├── rpc_tester │ ├── CMakeLists.txt │ ├── rpc_tester.cc │ └── sample-conf.yaml └── seawreck │ ├── CMakeLists.txt │ └── seawreck.cc ├── build.ninja ├── cmake ├── CheckGcc107852.cmake ├── CheckHeaders.cmake ├── CheckIncludeStyle.cmake ├── CheckLibc.cmake ├── CheckP2582R1.cmake ├── CxxModulesRules.cmake ├── FindGnuTLS.cmake ├── FindLibUring.cmake ├── FindLinuxMembarrier.cmake ├── FindPthreadSetName.cmake ├── FindSanitizers.cmake ├── FindSourceLocation.cmake ├── FindStdAtomic.cmake ├── FindSystemTap-SDT.cmake ├── FindValgrind.cmake ├── Findc-ares.cmake ├── Finddpdk.cmake ├── Findhwloc.cmake ├── Findlksctp-tools.cmake ├── Findlz4.cmake ├── Findragel.cmake ├── Findrt.cmake ├── Finducontext.cmake ├── Findyaml-cpp.cmake ├── SeastarConfig.cmake.in ├── SeastarDependencies.cmake ├── TriStateOption.cmake ├── check-seastar-include-style.py └── code_tests │ ├── LinuxMembarrier_test.cc │ ├── Sanitizers_fiber_test.cc │ ├── Source_location_default_argument.cc │ ├── Source_location_test.cc │ ├── rt_test.cc │ └── stdout_test.cc ├── coding-style.md ├── configure.py ├── cooking.sh ├── cooking_recipe.cmake ├── debug └── task-latency.stap ├── demos ├── CMakeLists.txt ├── block_discard_demo.cc ├── coroutines_demo.cc ├── echo_demo.cc ├── file_demo.cc ├── hello-cxx-module.cc ├── hello-world.cc ├── http_client_demo.cc ├── ip_demo.cc ├── l3_demo.cc ├── line_count_demo.cc ├── rpc_demo.cc ├── scheduling_group_demo.cc ├── sharded_parameter_demo.cc ├── tcp_demo.cc ├── tcp_sctp_client_demo.cc ├── tcp_sctp_server_demo.cc ├── tls_echo_server.hh ├── tls_echo_server_demo.cc ├── tls_simple_client_demo.cc ├── tutorial_examples.cc ├── udp_client_demo.cc ├── udp_server_demo.cc ├── udp_zero_copy_demo.cc └── websocket_server_demo.cc ├── doc ├── CMakeLists.txt ├── Doxyfile.in ├── DoxygenLayout.xml ├── building-docker.md ├── building-dpdk.md ├── compatibility.md ├── contributing.md ├── htmlsplit.py ├── io-properties-file.md ├── io-scheduler.md ├── io-tester.md ├── lambda-coroutine-fiasco.md ├── md2html ├── md2pdf ├── mini-tutorial.md ├── native-stack.md ├── network-configuration.md ├── network-connection-load-balancing.md ├── prometheus.md ├── rpc-compression.md ├── rpc-streaming.md ├── rpc.md ├── shared-token-bucket.md ├── signal.md ├── template.css ├── template.tex ├── testing.md ├── tutorial.md └── websocket.md ├── docker └── dev │ └── Dockerfile ├── include └── seastar │ ├── core │ ├── abort_on_ebadf.hh │ ├── abort_on_expiry.hh │ ├── abort_source.hh │ ├── abortable_fifo.hh │ ├── alien.hh │ ├── align.hh │ ├── aligned_buffer.hh │ ├── app-template.hh │ ├── array_map.hh │ ├── bitops.hh │ ├── bitset-iter.hh │ ├── byteorder.hh │ ├── cacheline.hh │ ├── checked_ptr.hh │ ├── chunked_fifo.hh │ ├── circular_buffer.hh │ ├── circular_buffer_fixed_capacity.hh │ ├── condition-variable.hh │ ├── coroutine.hh │ ├── deleter.hh │ ├── distributed.hh │ ├── do_with.hh │ ├── dpdk_rte.hh │ ├── enum.hh │ ├── exception_hacks.hh │ ├── execution_stage.hh │ ├── expiring_fifo.hh │ ├── fair_queue.hh │ ├── file-types.hh │ ├── file.hh │ ├── format.hh │ ├── fsnotify.hh │ ├── fsqual.hh │ ├── fstream.hh │ ├── function_traits.hh │ ├── future-util.hh │ ├── future.hh │ ├── gate.hh │ ├── idle_cpu_handler.hh │ ├── internal │ │ ├── api-level.hh │ │ ├── buffer_allocator.hh │ │ ├── estimated_histogram.hh │ │ ├── io_desc.hh │ │ ├── io_intent.hh │ │ ├── io_request.hh │ │ ├── io_sink.hh │ │ ├── poll.hh │ │ ├── pollable_fd.hh │ │ ├── read_state.hh │ │ ├── run_in_background.hh │ │ ├── stall_detector.hh │ │ └── uname.hh │ ├── io_intent.hh │ ├── io_priority_class.hh │ ├── io_queue.hh │ ├── iostream-impl.hh │ ├── iostream.hh │ ├── layered_file.hh │ ├── linux-aio.hh │ ├── loop.hh │ ├── lowres_clock.hh │ ├── make_task.hh │ ├── manual_clock.hh │ ├── map_reduce.hh │ ├── memory.hh │ ├── metrics.hh │ ├── metrics_api.hh │ ├── metrics_registration.hh │ ├── metrics_types.hh │ ├── on_internal_error.hh │ ├── pipe.hh │ ├── polymorphic_temporary_buffer.hh │ ├── posix.hh │ ├── preempt.hh │ ├── prefetch.hh │ ├── print.hh │ ├── prometheus.hh │ ├── queue.hh │ ├── ragel.hh │ ├── reactor.hh │ ├── reactor_config.hh │ ├── relabel_config.hh │ ├── report_exception.hh │ ├── resource.hh │ ├── rwlock.hh │ ├── scattered_message.hh │ ├── scheduling.hh │ ├── scheduling_specific.hh │ ├── scollectd.hh │ ├── scollectd_api.hh │ ├── seastar.hh │ ├── semaphore.hh │ ├── shard_id.hh │ ├── sharded.hh │ ├── shared_future.hh │ ├── shared_mutex.hh │ ├── shared_ptr.hh │ ├── shared_ptr_debug_helper.hh │ ├── shared_ptr_incomplete.hh │ ├── signal.hh │ ├── simple-stream.hh │ ├── slab.hh │ ├── sleep.hh │ ├── smp.hh │ ├── smp_options.hh │ ├── sstring.hh │ ├── stall_sampler.hh │ ├── stream.hh │ ├── systemwide_memory_barrier.hh │ ├── task.hh │ ├── temporary_buffer.hh │ ├── thread.hh │ ├── thread_cputime_clock.hh │ ├── thread_impl.hh │ ├── timed_out_error.hh │ ├── timer-set.hh │ ├── timer.hh │ ├── transfer.hh │ ├── unaligned.hh │ ├── units.hh │ ├── vector-data-sink.hh │ ├── weak_ptr.hh │ ├── when_all.hh │ ├── when_any.hh │ ├── with_scheduling_group.hh │ └── with_timeout.hh │ ├── coroutine │ ├── all.hh │ ├── as_future.hh │ ├── exception.hh │ ├── generator.hh │ ├── maybe_yield.hh │ ├── parallel_for_each.hh │ └── switch_to.hh │ ├── http │ ├── api_docs.hh │ ├── client.hh │ ├── common.hh │ ├── connection_factory.hh │ ├── exception.hh │ ├── file_handler.hh │ ├── function_handlers.hh │ ├── handlers.hh │ ├── httpd.hh │ ├── internal │ │ └── content_source.hh │ ├── json_path.hh │ ├── matcher.hh │ ├── matchrules.hh │ ├── mime_types.hh │ ├── reply.hh │ ├── request.hh │ ├── routes.hh │ ├── short_streams.hh │ ├── transformers.hh │ └── url.hh │ ├── json │ ├── formatter.hh │ └── json_elements.hh │ ├── net │ ├── api.hh │ ├── arp.hh │ ├── byteorder.hh │ ├── config.hh │ ├── const.hh │ ├── dhcp.hh │ ├── dns.hh │ ├── dpdk.hh │ ├── ethernet.hh │ ├── inet_address.hh │ ├── ip.hh │ ├── ip_checksum.hh │ ├── ipv4_address.hh │ ├── ipv6_address.hh │ ├── native-stack.hh │ ├── net.hh │ ├── packet-data-source.hh │ ├── packet-util.hh │ ├── packet.hh │ ├── posix-stack.hh │ ├── proxy.hh │ ├── socket_defs.hh │ ├── stack.hh │ ├── tcp-stack.hh │ ├── tcp.hh │ ├── tls.hh │ ├── toeplitz.hh │ ├── udp.hh │ ├── unix_address.hh │ ├── virtio-interface.hh │ └── virtio.hh │ ├── rpc │ ├── lz4_compressor.hh │ ├── lz4_fragmented_compressor.hh │ ├── multi_algo_compressor_factory.hh │ ├── rpc.hh │ ├── rpc_impl.hh │ └── rpc_types.hh │ ├── testing │ ├── entry_point.hh │ ├── exchanger.hh │ ├── linux_perf_event.hh │ ├── on_internal_error.hh │ ├── perf_tests.hh │ ├── random.hh │ ├── seastar_test.hh │ ├── test_case.hh │ ├── test_runner.hh │ └── thread_test_case.hh │ ├── util │ ├── alloc_failure_injector.hh │ ├── assert.hh │ ├── backtrace.hh │ ├── bool_class.hh │ ├── closeable.hh │ ├── concepts.hh │ ├── conversions.hh │ ├── critical_alloc_section.hh │ ├── defer.hh │ ├── eclipse.hh │ ├── exceptions.hh │ ├── file.hh │ ├── function_input_iterator.hh │ ├── indirect.hh │ ├── internal │ │ ├── iovec_utils.hh │ │ └── magic.hh │ ├── iostream.hh │ ├── is_smart_ptr.hh │ ├── later.hh │ ├── lazy.hh │ ├── log-cli.hh │ ├── log-impl.hh │ ├── log.hh │ ├── memory_diagnostics.hh │ ├── modules.hh │ ├── noncopyable_function.hh │ ├── optimized_optional.hh │ ├── print_safe.hh │ ├── process.hh │ ├── program-options.hh │ ├── read_first_line.hh │ ├── reference_wrapper.hh │ ├── sampler.hh │ ├── shared_token_bucket.hh │ ├── short_streams.hh │ ├── source_location-compat.hh │ ├── spinlock.hh │ ├── std-compat.hh │ ├── string_utils.hh │ ├── tmp_file.hh │ ├── transform_iterator.hh │ ├── tuple_utils.hh │ ├── used_size.hh │ └── variant_utils.hh │ └── websocket │ ├── common.hh │ ├── parser.hh │ └── server.hh ├── install-dependencies.sh ├── kvm ├── README.md ├── build.sh ├── register.sh └── scripts │ └── bootstrap.sh ├── licenses ├── cmake.txt ├── dpdk.txt └── freebsd.txt ├── pkgconfig ├── seastar-testing.pc.in └── seastar.pc.in ├── scripts ├── addr2line.py ├── dpdk_nic_bind.py ├── io-trace-parse.py ├── perftune.py ├── perftune.yaml ├── posix_net_conf.sh ├── pyproject.toml ├── run_with_dpdk.sh ├── seastar-addr2line ├── seastar-cpu-map.sh ├── seastar-json2code.py ├── stall-analyser.py └── tap.sh ├── seastar_cmake.py ├── src ├── CMakeLists.txt ├── core │ ├── alien.cc │ ├── app-template.cc │ ├── cgroup.hh │ ├── condition-variable.cc │ ├── dpdk_rte.cc │ ├── exception_hacks.cc │ ├── execution_stage.cc │ ├── fair_queue.cc │ ├── file-impl.hh │ ├── file.cc │ ├── fsnotify.cc │ ├── fsqual.cc │ ├── fstream.cc │ ├── future-util.cc │ ├── future.cc │ ├── io_queue.cc │ ├── linux-aio.cc │ ├── memory.cc │ ├── metrics.cc │ ├── on_internal_error.cc │ ├── posix.cc │ ├── prefault.hh │ ├── program_options.cc │ ├── program_options.hh │ ├── prometheus.cc │ ├── reactor.cc │ ├── reactor_backend.cc │ ├── reactor_backend.hh │ ├── resource.cc │ ├── scollectd-impl.hh │ ├── scollectd.cc │ ├── semaphore.cc │ ├── sharded.cc │ ├── signal.cc │ ├── smp.cc │ ├── sstring.cc │ ├── syscall_result.hh │ ├── syscall_work_queue.hh │ ├── systemwide_memory_barrier.cc │ ├── thread.cc │ ├── thread_pool.cc │ ├── thread_pool.hh │ ├── uname.cc │ └── vla.hh ├── http │ ├── api_docs.cc │ ├── chunk_parsers.rl │ ├── client.cc │ ├── common.cc │ ├── file_handler.cc │ ├── httpd.cc │ ├── json_path.cc │ ├── matcher.cc │ ├── mime_types.cc │ ├── reply.cc │ ├── request.cc │ ├── request_parser.rl │ ├── response_parser.rl │ ├── routes.cc │ ├── transformers.cc │ └── url.cc ├── json │ ├── formatter.cc │ └── json_elements.cc ├── net │ ├── arp.cc │ ├── config.cc │ ├── dhcp.cc │ ├── dns.cc │ ├── dpdk.cc │ ├── ethernet.cc │ ├── inet_address.cc │ ├── ip.cc │ ├── ip_checksum.cc │ ├── native-stack-impl.hh │ ├── native-stack.cc │ ├── net.cc │ ├── packet.cc │ ├── posix-stack.cc │ ├── proxy.cc │ ├── socket_address.cc │ ├── stack.cc │ ├── tcp.cc │ ├── tls.cc │ ├── udp.cc │ ├── unix_address.cc │ └── virtio.cc ├── proto │ └── metrics2.proto ├── rpc │ ├── lz4_compressor.cc │ ├── lz4_fragmented_compressor.cc │ └── rpc.cc ├── seastar.cc ├── testing │ ├── entry_point.cc │ ├── random.cc │ ├── seastar_test.cc │ └── test_runner.cc ├── util │ ├── alloc_failure_injector.cc │ ├── backtrace.cc │ ├── conversions.cc │ ├── exceptions.cc │ ├── file.cc │ ├── log.cc │ ├── process.cc │ ├── program-options.cc │ ├── read_first_line.cc │ ├── short_streams.cc │ └── tmp_file.cc └── websocket │ ├── common.cc │ ├── parser.cc │ └── server.cc ├── test.py └── tests ├── CMakeLists.txt ├── manual ├── iosched.py ├── iosched_reproducers │ ├── one_cpu_starved_shard_can_still_saturate_io.sh │ ├── one_cpu_starved_shard_has_reasonable_fairness.sh │ ├── scylla_tablet_migration.sh │ └── tau_nemesis.sh └── rl-iosched.py ├── perf ├── CMakeLists.txt ├── allocator_perf.cc ├── container_perf.cc ├── coroutine_perf.cc ├── fair_queue_perf.cc ├── fstream_perf.cc ├── future_util_perf.cc ├── http_client_perf.cc ├── linux_perf_event.cc ├── perf-tests.md ├── perf_tests.cc ├── perf_tests_perf.cc ├── rpc_perf.cc ├── shared_token_bucket.cc └── smp_submit_to_perf.cc └── unit ├── CMakeLists.txt ├── abort_source_test.cc ├── abortable_fifo_test.cc ├── alien_test.cc ├── alloc_test.cc ├── allocator_test.cc ├── api.json ├── app-template_test.cc ├── cert.cfg.in ├── checked_ptr_test.cc ├── chunk_parsers_test.cc ├── chunked_fifo_test.cc ├── circular_buffer_fixed_capacity_test.cc ├── circular_buffer_test.cc ├── closeable_test.cc ├── condition_variable_test.cc ├── conf-example.yaml ├── connect_test.cc ├── content_source_test.cc ├── coroutines_test.cc ├── defer_test.cc ├── deleter_test.cc ├── directory_test.cc ├── distributed_test.cc ├── dns_test.cc ├── exception_logging_test.cc ├── execution_stage_test.cc ├── expected_exception.hh ├── expiring_fifo_test.cc ├── fair_queue_test.cc ├── file_io_test.cc ├── file_utils_test.cc ├── foreign_ptr_test.cc ├── fsnotifier_test.cc ├── fstream_test.cc ├── futures_test.cc ├── gate_test.cc ├── httpd_test.cc ├── https-server.py ├── io_queue_test.cc ├── ipv6_test.cc ├── json2code_test.py ├── json_formatter_test.cc ├── libc_wrapper_test.cc ├── locking_test.cc ├── log_buf_test.cc ├── loopback_socket.hh ├── lowres_clock_test.cc ├── metrics_test.cc ├── metrics_tester.cc ├── mkcert.gmk ├── mkmtls.gmk ├── mock_file.hh ├── net_config_test.cc ├── network_interface_test.cc ├── noncopyable_function_test.cc ├── output_stream_test.cc ├── packet_test.cc ├── pipe_test.cc ├── program_options_test.cc ├── prometheus_http_test.cc ├── prometheus_test.py ├── queue_test.cc ├── request_parser_test.cc ├── rest_api_httpd.cc ├── rpc_test.cc ├── scheduling_group_test.cc ├── semaphore_test.cc ├── sharded_test.cc ├── shared_ptr_test.cc ├── shared_token_bucket_test.cc ├── signal_test.cc ├── simple_stream_test.cc ├── slab_test.cc ├── smp_test.cc ├── socket_test.cc ├── source_location_test.cc ├── spawn_test.cc ├── sstring_test.cc ├── stall_detector_test.cc ├── stream_reader_test.cc ├── thread_context_switch_test.cc ├── thread_test.cc ├── timer_test.cc ├── tl-generator.hh ├── tls-ca-bundle.pem ├── tls_test.cc ├── tmpdir.hh ├── tuple_utils_test.cc ├── uname_test.cc ├── unix_domain_test.cc ├── unwind_test.cc ├── weak_ptr_test.cc └── websocket_test.cc /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | build 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.cc diff=cpp 2 | *.hh diff=cpp 3 | -------------------------------------------------------------------------------- /.github/workflows/alpinelinux.yaml: -------------------------------------------------------------------------------- 1 | name: Alpine Linux 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: # Allows manual triggering 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} 10 | 11 | jobs: 12 | build-and-test: 13 | runs-on: ubuntu-latest 14 | container: 15 | image: alpine:latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Install build dependencies 22 | run: | 23 | apk update 24 | apk add --no-cache \ 25 | boost-dev \ 26 | bsd-compat-headers \ 27 | c-ares-dev \ 28 | cmake \ 29 | crypto++-dev \ 30 | gcc \ 31 | g++ \ 32 | fmt-dev \ 33 | gnutls-dev \ 34 | hwloc-dev \ 35 | libpciaccess-dev \ 36 | libucontext-dev \ 37 | libunwind-dev \ 38 | liburing-dev \ 39 | lksctp-tools-dev \ 40 | lz4-dev \ 41 | numactl-dev \ 42 | openssl \ 43 | openssl-dev \ 44 | protobuf-dev \ 45 | py3-yaml \ 46 | ragel \ 47 | samurai \ 48 | util-linux-dev \ 49 | valgrind-dev \ 50 | xfsprogs-dev \ 51 | yaml-cpp-dev 52 | 53 | - name: Configure build 54 | run: | 55 | cmake -B build -G Ninja \ 56 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 57 | -DSeastar_DOCS=OFF 58 | 59 | - name: Build Seastar 60 | run: | 61 | cmake --build build 62 | 63 | - name: Run unit tests 64 | run: | 65 | ctest --test-dir build --output-on-failure -j2 66 | -------------------------------------------------------------------------------- /.github/workflows/docker.yaml: -------------------------------------------------------------------------------- 1 | name: Verify Dockerfile Build 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - 'docker/dev/Dockerfile' 7 | - 'install-dependencies.sh' 8 | 9 | concurrency: 10 | group: ${{ github.workflow }}-${{ github.ref }} 11 | cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} 12 | 13 | jobs: 14 | build: 15 | timeout-minutes: 20 16 | runs-on: ubuntu-24.04 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v4 20 | with: 21 | sparse-checkout: | 22 | docker/dev/Dockerfile 23 | install-dependencies.sh 24 | 25 | - name: Set up Docker Buildx 26 | uses: docker/setup-buildx-action@v3 27 | 28 | - name: Build Docker image 29 | uses: docker/build-push-action@v6 30 | with: 31 | context: . 32 | file: docker/dev/Dockerfile 33 | push: false 34 | cache-from: type=gha 35 | cache-to: type=gha,mode=max 36 | -------------------------------------------------------------------------------- /.github/workflows/python-lint.yaml: -------------------------------------------------------------------------------- 1 | name: Python format 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | python-format: 7 | name: Enforce python format 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4 11 | - uses: psf/black@24.8.0 12 | with: 13 | version: "24.8.0" 14 | src: ./scripts 15 | # override options so that we can specify only specific files for now 16 | options: "--check --diff --include=.*addr2line.*" 17 | -------------------------------------------------------------------------------- /.github/workflows/tests.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | permissions: 4 | contents: read 5 | 6 | on: [push, pull_request] 7 | 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.ref }} 10 | cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} 11 | 12 | jobs: 13 | regular_test: 14 | name: "Test (${{ matrix.compiler }}, C++${{ matrix.standard}}, ${{ matrix.mode }})" 15 | uses: ./.github/workflows/test.yaml 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | compiler: [clang++, g++] 20 | standard: [20, 23] 21 | mode: [dev, debug, release] 22 | with: 23 | compiler: ${{ matrix.compiler }} 24 | standard: ${{ matrix.standard }} 25 | mode: ${{ matrix.mode }} 26 | enables: ${{ matrix.enables }} 27 | options: ${{ matrix.options }} 28 | build_with_dpdk: 29 | name: "Test with DPDK enabled" 30 | uses: ./.github/workflows/test.yaml 31 | strategy: 32 | fail-fast: false 33 | with: 34 | compiler: clang++ 35 | standard: 23 36 | mode: release 37 | enables: --enable-dpdk 38 | options: --cook dpdk 39 | build_with_cxx_modules: 40 | name: "Test with C++20 modules enabled" 41 | uses: ./.github/workflows/test.yaml 42 | strategy: 43 | fail-fast: false 44 | with: 45 | compiler: clang++ 46 | standard: 23 47 | mode: debug 48 | enables: --enable-cxx-modules 49 | enable-ccache: false 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cooking_memory 2 | .cproject 3 | .project 4 | .settings 5 | build* 6 | build.ninja 7 | cscope.* 8 | __pycache__/ 9 | cmake/Cooking.cmake 10 | tags 11 | .idea/ 12 | .vscode/ 13 | compile_commands.json 14 | .clangd 15 | .cache -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dpdk"] 2 | path = dpdk 3 | url = ../dpdk 4 | -------------------------------------------------------------------------------- /.gitorderfile: -------------------------------------------------------------------------------- 1 | *.py 2 | *.hh 3 | *.rl 4 | *.cc 5 | * 6 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Avi Kivity Avi Kivity' via seastar-dev 2 | Raphael S. Carvalho Raphael S. Carvalho' via seastar-dev 3 | Pavel Emelyanov Pavel Emelyanov' via seastar-dev 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Code to Seastar 2 | 3 | There are two ways to contribute code to Seastar: 4 | * send your changes as [patches](https://github.com/scylladb/scylla/wiki/Formatting-and-sending-patches) to the [mailing list](https://groups.google.com/forum/#!forum/seastar-dev). 5 | * alternatively, open a [github pull request](https://github.com/scylladb/seastar/pulls). 6 | 7 | # Asking questions or requesting help 8 | 9 | Use the [Seastar mailing list](https://groups.google.com/forum/#!forum/seastar-dev) for general questions and help. 10 | 11 | # Reporting an issue 12 | 13 | Please use the [Issue Tracker](https://github.com/scylladb/seastar/issues/) to report issues. Supply as much information about your environment as possible, especially for performance problems. 14 | 15 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Seastar Framework 2 | Copyright 2015 Cloudius Systems 3 | 4 | This works contains software from the OSv project (http://osv.io), licensed 5 | under the BSD license. 6 | 7 | This work contains software from the DPDK project (http://dpdk.org), licensed 8 | under the BSD license. The software is under the dpdk/ directory. 9 | 10 | This work contains software from the Android Open Source Project, 11 | licensed under the Apache2 license. 12 | The software is in the include/seastar/util/sampler.hh file. 13 | -------------------------------------------------------------------------------- /README-DPDK.md: -------------------------------------------------------------------------------- 1 | Seastar and DPDK 2 | ================ 3 | 4 | Seastar uses the Data Plane Development Kit to drive NIC hardware directly. This 5 | provides an enormous performance boost. 6 | 7 | To enable DPDK, specify `--enable-dpdk` to `./configure.py`, and `--dpdk-pmd` as a 8 | run-time parameter. This will use the DPDK package provided as a git submodule with the 9 | seastar sources. 10 | 11 | Please note, if `--enable-dpdk` is used to build DPDK on an aarch64 machine, you need to 12 | specify [target architecture](https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html) with optional 13 | [feature modifiers](https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#aarch64-feature-modifiers) 14 | with the `--cflags` option as well, like: 15 | ```console 16 | $ ./configure.py --mode debug --enable-dpdk --cflags='-march=armv8-a+crc+crypto' 17 | ``` 18 | 19 | To use your own self-compiled DPDK package, follow this procedure: 20 | 21 | 1. Setup host to compile DPDK: 22 | - Ubuntu 23 | `sudo apt-get install -y build-essential linux-image-extra-$(uname -r)` 24 | 2. Prepare a DPDK SDK: 25 | - Download the latest DPDK release: `wget https://fast.dpdk.org/rel/dpdk-23.07.tar.xz` 26 | - Untar it. 27 | - Follow the [Quick Start Guide](https://core.dpdk.org/doc/quick-start/) 28 | - Pass `-Dmbuf_refcnt_atomic=false` to meson. 29 | 3. Modify the CMake cache (`CMakeCache.txt`) to inform CMake of the location of the installed DPDK SDK. 30 | -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is open source software, licensed to you under the terms 2 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 3 | # distributed with this work for additional information regarding copyright 4 | # ownership. You may not use this file except in compliance with the License. 5 | # 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, 11 | # software distributed under the License is distributed on an 12 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | # KIND, either express or implied. See the License for the 14 | # specific language governing permissions and limitations 15 | # under the License. 16 | # 17 | 18 | # 19 | # Copyright (C) 2018 Scylladb, Ltd. 20 | # 21 | 22 | # Logical target for all applications. 23 | add_custom_target (apps) 24 | 25 | macro (seastar_add_app name) 26 | set (args ${ARGN}) 27 | 28 | cmake_parse_arguments ( 29 | parsed_args 30 | "" 31 | "" 32 | "SOURCES" 33 | ${args}) 34 | 35 | set (target app_${name}) 36 | add_executable (${target} ${parsed_args_SOURCES}) 37 | 38 | target_include_directories (${target} 39 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 40 | 41 | target_link_libraries (${target} 42 | PRIVATE seastar_private) 43 | 44 | set_target_properties (${target} 45 | PROPERTIES 46 | OUTPUT_NAME ${name}) 47 | 48 | add_dependencies (apps ${target}) 49 | endmacro () 50 | 51 | add_subdirectory (httpd) 52 | add_subdirectory (io_tester) 53 | add_subdirectory (rpc_tester) 54 | add_subdirectory (iotune) 55 | add_subdirectory (memcached) 56 | add_subdirectory (seawreck) 57 | -------------------------------------------------------------------------------- /apps/httpd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | seastar_generate_swagger ( 24 | TARGET app_httpd_swagger 25 | VAR app_httpd_swagger_files 26 | IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/demo.json 27 | OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) 28 | 29 | seastar_add_app (httpd 30 | SOURCES 31 | ${app_httpd_swagger_files} 32 | main.cc) 33 | 34 | target_include_directories (app_httpd 35 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 36 | 37 | add_dependencies (app_httpd app_httpd_swagger) 38 | -------------------------------------------------------------------------------- /apps/io_tester/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | seastar_add_app (io_tester 24 | SOURCES io_tester.cc) 25 | 26 | seastar_add_app (ioinfo 27 | SOURCES ioinfo.cc) 28 | 29 | target_link_libraries (app_io_tester 30 | PRIVATE yaml-cpp::yaml-cpp) 31 | 32 | target_link_libraries (app_ioinfo 33 | PRIVATE yaml-cpp::yaml-cpp) 34 | -------------------------------------------------------------------------------- /apps/io_tester/conf.yaml: -------------------------------------------------------------------------------- 1 | - name: big_writes 2 | shards: all 3 | type: seqwrite 4 | shard_info: 5 | parallelism: 10 6 | reqsize: 256kB 7 | shares: 10 8 | think_time: 0 9 | 10 | - name: latency_reads 11 | shards: [0] 12 | type: randread 13 | data_size: 1GB 14 | shard_info: 15 | parallelism: 1 16 | reqsize: 512 17 | shares: 100 18 | think_time: 1000us 19 | 20 | - name: cpu_hog 21 | shards: [0] 22 | type: cpu 23 | shard_info: 24 | parallelism: 1 25 | execution_time: 90us 26 | think_time: 10us 27 | 28 | - name: unlinking 29 | shards: all 30 | type: unlink 31 | data_size: 2GB 32 | files_count: 5000 33 | shard_info: 34 | parallelism: 10 35 | think_time: 10us 36 | -------------------------------------------------------------------------------- /apps/iotune/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | seastar_add_app (iotune 24 | SOURCES iotune.cc) 25 | 26 | target_link_libraries (app_iotune 27 | PRIVATE 28 | yaml-cpp::yaml-cpp) 29 | -------------------------------------------------------------------------------- /apps/memcached/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | set (Seastar_APP_MEMCACHED_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 24 | set (Seastar_APP_MEMCACHED_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 25 | 26 | seastar_generate_ragel ( 27 | TARGET app_memcached_ascii 28 | VAR app_memcached_ascii_file 29 | IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ascii.rl 30 | OUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/ascii.hh) 31 | 32 | seastar_add_app (memcached 33 | SOURCES 34 | ${app_memcached_ascii_file} 35 | memcache.cc 36 | memcached.hh) 37 | 38 | target_include_directories (app_memcached 39 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) 40 | 41 | add_dependencies (app_memcached app_memcached_ascii) 42 | 43 | # 44 | # Tests. 45 | # 46 | 47 | if (Seastar_TESTING) 48 | add_subdirectory (tests) 49 | endif () 50 | -------------------------------------------------------------------------------- /apps/memcached/memcached.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | namespace memcache { 24 | 25 | using namespace seastar; 26 | 27 | class item; 28 | class cache; 29 | 30 | class item_key { 31 | private: 32 | sstring _key; 33 | size_t _hash; 34 | public: 35 | item_key() = default; 36 | item_key(item_key&) = default; 37 | item_key(sstring key) 38 | : _key(key) 39 | , _hash(std::hash()(key)) 40 | {} 41 | item_key(item_key&& other) 42 | : _key(std::move(other._key)) 43 | , _hash(other._hash) 44 | { 45 | other._hash = 0; 46 | } 47 | size_t hash() const { 48 | return _hash; 49 | } 50 | const sstring& key() const { 51 | return _key; 52 | } 53 | bool operator==(const item_key& other) const { 54 | return other._hash == _hash && other._key == _key; 55 | } 56 | void operator=(item_key&& other) { 57 | _key = std::move(other._key); 58 | _hash = other._hash; 59 | other._hash = 0; 60 | } 61 | }; 62 | 63 | } 64 | 65 | namespace std { 66 | 67 | template <> 68 | struct hash { 69 | size_t operator()(const memcache::item_key& key) { 70 | return key.hash(); 71 | } 72 | }; 73 | 74 | } /* namespace std */ 75 | -------------------------------------------------------------------------------- /apps/memcached/tests/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # This file is open source software, licensed to you under the terms 4 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 5 | # distributed with this work for additional information regarding copyright 6 | # ownership. You may not use this file except in compliance with the License. 7 | # 8 | # 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, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | import time 20 | import sys 21 | import os 22 | import argparse 23 | import subprocess 24 | 25 | DIR_PATH = os.path.dirname(os.path.realpath(__file__)) 26 | 27 | def run(args, cmd): 28 | mc = subprocess.Popen([args.memcached, '--smp=2']) 29 | print('Memcached started.') 30 | try: 31 | cmdline = [DIR_PATH + '/test_memcached.py'] + cmd 32 | if args.fast: 33 | cmdline.append('--fast') 34 | print('Running: ' + ' '.join(cmdline)) 35 | subprocess.check_call(cmdline) 36 | finally: 37 | print('Killing memcached...') 38 | mc.terminate(); 39 | mc.wait() 40 | print('Memcached killed.') 41 | 42 | if __name__ == "__main__": 43 | parser = argparse.ArgumentParser(description="Seastar test runner") 44 | parser.add_argument('--fast', action="store_true", help="Run only fast tests") 45 | parser.add_argument('--memcached', required=True, help='Path of the memcached executable') 46 | args = parser.parse_args() 47 | 48 | run(args, []) 49 | run(args, ['-U']) 50 | -------------------------------------------------------------------------------- /apps/rpc_tester/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2022 Scylladb, Ltd. 21 | # 22 | 23 | seastar_add_app (rpc_tester 24 | SOURCES rpc_tester.cc) 25 | 26 | target_link_libraries (app_rpc_tester 27 | PRIVATE yaml-cpp::yaml-cpp) 28 | -------------------------------------------------------------------------------- /apps/rpc_tester/sample-conf.yaml: -------------------------------------------------------------------------------- 1 | client: 2 | nodelay: # bool, whether or not to set tcp_nodelay option 3 | server: 4 | nodelay: # bool, whether or not to set tcp_nodelay option 5 | jobs: 6 | - name: # any parseable string 7 | type: rpc 8 | verb: # string, one of: echo, vecho, write 9 | parallelism: # number of verbs to send simultaneously 10 | shares: # sched group shares (100 by default) 11 | payload: # number of bytes in the payload for write verb, accepts kB suffix 12 | sleep_time: # optional inactivity pause between sending messages 13 | timeout: # optional rpc send timeout duration 14 | - name: 15 | type: cpu 16 | execution_time: # time in [0-9]+[mun]?s format 17 | sleep_time: # optional inactivity pause between burning cpu 18 | side: # optional, 'client' or 'server' to specify which side to run on 19 | -------------------------------------------------------------------------------- /apps/seawreck/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | seastar_add_app (seawreck 24 | SOURCES seawreck.cc) 25 | -------------------------------------------------------------------------------- /build.ninja: -------------------------------------------------------------------------------- 1 | rule display_help 2 | command = echo 'Error: Execute Ninja in a build directory: `ninja -C build/release`' 3 | description = Help the poor user 4 | 5 | build help: display_help 6 | 7 | default help 8 | -------------------------------------------------------------------------------- /cmake/CheckGcc107852.cmake: -------------------------------------------------------------------------------- 1 | include (CheckCXXSourceCompiles) 2 | include (CMakePushCheckState) 3 | 4 | cmake_push_check_state (RESET) 5 | 6 | # these options are included by -Wall, which is in turn included by 7 | # Seastar_PRIVATE_CXX_FLAGS, which is not applied to CMAKE_CXX_FLAGS, so 8 | # let's apply them explicitly. 9 | set (CMAKE_REQUIRED_FLAGS "-Werror=stringop-overflow -Werror=array-bound") 10 | set (CMAKE_REQUIRED_LIBRARIES fmt::fmt) 11 | 12 | # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107852 13 | check_cxx_source_compiles (" 14 | #include 15 | 16 | int main() { 17 | float grades[] = {3.14}; 18 | fmt::print(\"{}\", grades); 19 | }" 20 | Cxx_Compiler_BZ107852_Free 21 | FAIL_REGEX "is out of the bounds") 22 | 23 | cmake_pop_check_state () 24 | 25 | -------------------------------------------------------------------------------- /cmake/CheckIncludeStyle.cmake: -------------------------------------------------------------------------------- 1 | # seastar_check_include_style() enforces that all source and header files under 2 | # specified directories include the headers with predefined list of prefixes 3 | # with angle brackets instead of quotes. 4 | 5 | find_package (Python3 COMPONENTS Interpreter) 6 | 7 | function (seastar_check_include_style target library) 8 | get_target_property (sources ${library} SOURCES) 9 | set (check-target "${target}-${library}") 10 | add_custom_target("${check-target}" 11 | COMMAND Python3::Interpreter ${CMAKE_CURRENT_LIST_DIR}/cmake/check-seastar-include-style.py ${sources} 12 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 13 | COMMENT "Checking include directive styles for ${library} source files" 14 | USES_TERMINAL) 15 | add_dependencies (${target} ${check-target}) 16 | endfunction () 17 | -------------------------------------------------------------------------------- /cmake/CheckLibc.cmake: -------------------------------------------------------------------------------- 1 | # check for the bits in different standard C library implementations we 2 | # care about 3 | 4 | include (CheckCXXSourceCompiles) 5 | file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/stdout_test.cc _stdout_test_code) 6 | check_cxx_source_compiles ("${_stdout_test_code}" Stdout_Can_Be_Used_As_Identifier) 7 | if (Stdout_Can_Be_Used_As_Identifier) 8 | # "stdout" is defined as a macro by the C++ standard, so we cannot assume 9 | # that the macro is always expanded into an identifier which can be re-used 10 | # to name a enumerator in the declaration of an enumeration. 11 | target_compile_definitions (seastar 12 | PUBLIC 13 | SEASTAR_LOGGER_TYPE_STDOUT) 14 | endif () 15 | 16 | check_cxx_source_compiles (" 17 | #include 18 | 19 | int main() { 20 | char buf; 21 | char* a = strerror_r(1, &buf, 0); 22 | static_cast(a); 23 | }" 24 | Strerror_R_Returns_Char_P) 25 | if (Strerror_R_Returns_Char_P) 26 | # define SEASTAR_STRERROR_R_CHAR_P if strerror_r() is GNU-specific version, 27 | # which returns a "char*" not "int". 28 | target_compile_definitions (seastar 29 | PRIVATE 30 | SEASTAR_STRERROR_R_CHAR_P) 31 | endif () 32 | 33 | include (CheckFunctionExists) 34 | 35 | check_function_exists (pthread_attr_setaffinity_np 36 | Pthread_Attr_Setaffinity_Np) 37 | if (Pthread_Attr_Setaffinity_Np) 38 | target_compile_definitions (seastar 39 | PRIVATE 40 | SEASTAR_PTHREAD_ATTR_SETAFFINITY_NP) 41 | endif () 42 | -------------------------------------------------------------------------------- /cmake/CheckP2582R1.cmake: -------------------------------------------------------------------------------- 1 | include (CheckCXXSourceCompiles) 2 | include (CMakePushCheckState) 3 | 4 | cmake_push_check_state (RESET) 5 | 6 | set (CMAKE_REQUIRED_FLAGS "-std=c++23") 7 | 8 | # check if the compiler implements the inherited vs non-inherited guide 9 | # tiebreaker specified by P2582R1, see https://wg21.link/P2582R1 10 | check_cxx_source_compiles (" 11 | template struct B { 12 | B(T...) {} 13 | }; 14 | 15 | template struct C : public B { 16 | using B::B; 17 | C(B) {} 18 | }; 19 | 20 | B(int) -> B; 21 | C c2(42); 22 | 23 | int main() {} 24 | " 25 | Cxx_Compiler_IMPLEMENTS_P2581R1) 26 | 27 | cmake_pop_check_state () 28 | -------------------------------------------------------------------------------- /cmake/CxxModulesRules.cmake: -------------------------------------------------------------------------------- 1 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 2 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) 3 | message (FATAL_ERROR "C++20 module needs Clang++-16 or up") 4 | endif () 5 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 6 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) 7 | message (FATAL_ERROR "C++20 module needs g++-14 or up") 8 | endif () 9 | else () 10 | message (FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") 11 | endif () 12 | 13 | if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) 14 | # CMake 3.28 has official support of C++20 modules 15 | elseif (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) 16 | set (CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7") 17 | elseif (CMAKE_VERSION VERSION_GREATER_EQUAL 3.26) 18 | set (CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE "") 19 | set (CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) 20 | set (CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a") 21 | endif () 22 | 23 | set (CMAKE_CXX_STANDARD_REQUIRED ON) 24 | # C++ extension does work with C++ module support so far 25 | set (CMAKE_CXX_EXTENSIONS OFF) 26 | -------------------------------------------------------------------------------- /cmake/FindGnuTLS.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | find_package (PkgConfig REQUIRED) 24 | 25 | pkg_check_modules (PC_GnuTLS QUIET gnutls) 26 | 27 | find_library (GnuTLS_LIBRARY 28 | NAMES gnutls 29 | HINTS 30 | ${PC_GnuTLS_LIBDIR} 31 | ${PC_GnuTLS_LIBRARY_DIRS}) 32 | 33 | find_path (GnuTLS_INCLUDE_DIR 34 | NAMES gnutls/gnutls.h 35 | HINTS 36 | ${PC_GnuTLS_INCLUDEDIR} 37 | ${PC_GnuTLS_INCLUDE_DIRS}) 38 | 39 | mark_as_advanced ( 40 | GnuTLS_LIBRARY 41 | GnuTLS_INCLUDE_DIR) 42 | 43 | include (FindPackageHandleStandardArgs) 44 | 45 | find_package_handle_standard_args (GnuTLS 46 | REQUIRED_VARS 47 | GnuTLS_LIBRARY 48 | GnuTLS_INCLUDE_DIR 49 | VERSION_VAR PC_GnuTLS_VERSION) 50 | 51 | if (GnuTLS_FOUND) 52 | set (GnuTLS_LIBRARIES ${GnuTLS_LIBRARY}) 53 | set (GnuTLS_INCLUDE_DIRS ${GnuTLS_INCLUDE_DIR}) 54 | if (NOT (TARGET GnuTLS::gnutls)) 55 | add_library (GnuTLS::gnutls UNKNOWN IMPORTED) 56 | 57 | set_target_properties (GnuTLS::gnutls 58 | PROPERTIES 59 | IMPORTED_LOCATION ${GnuTLS_LIBRARY} 60 | INTERFACE_INCLUDE_DIRECTORIES ${GnuTLS_INCLUDE_DIRS}) 61 | endif () 62 | endif () 63 | -------------------------------------------------------------------------------- /cmake/FindLinuxMembarrier.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | find_path (LinuxMembarrier_INCLUDE_DIR 24 | NAMES linux/membarrier.h) 25 | 26 | include (CheckCXXSourceCompiles) 27 | file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/LinuxMembarrier_test.cc _linuxmembarrier_test_code) 28 | check_cxx_source_compiles ("${_linuxmembarrier_test_code}" LinuxMembarrier_FOUND) 29 | 30 | if (LinuxMembarrier_FOUND) 31 | set (LinuxMembarrier_INCLUDE_DIRS ${LinuxMembarrier_INCLUDE_DIR}) 32 | endif () 33 | 34 | if (LinuxMembarrier_FOUND AND NOT (TARGET LinuxMembarrier::membarrier)) 35 | add_library (LinuxMembarrier::membarrier INTERFACE IMPORTED) 36 | 37 | set_target_properties (LinuxMembarrier::membarrier 38 | PROPERTIES 39 | INTERFACE_INCLUDE_DIRECTORIES ${LinuxMembarrier_INCLUDE_DIRS}) 40 | endif () 41 | -------------------------------------------------------------------------------- /cmake/FindPthreadSetName.cmake: -------------------------------------------------------------------------------- 1 | include (CheckSymbolExists) 2 | include (CMakePushCheckState) 3 | 4 | cmake_push_check_state (RESET) 5 | set (CMAKE_REQUIRED_FLAGS "-pthread") 6 | set (CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE") 7 | check_symbol_exists (pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP) 8 | cmake_pop_check_state () 9 | 10 | find_package_handle_standard_args (PthreadSetName 11 | FOUND_VAR PthreadSetName_FOUND 12 | REQUIRED_VARS 13 | HAVE_PTHREAD_SETNAME_NP) 14 | -------------------------------------------------------------------------------- /cmake/FindSourceLocation.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2022 Kefu Chai ( tchaikov@gmail.com ) 21 | # 22 | 23 | include (CheckCXXSourceCompiles) 24 | include (CheckCXXSourceRuns) 25 | include (CMakePushCheckState) 26 | 27 | cmake_push_check_state () 28 | file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/Source_location_test.cc _source_location_test_code) 29 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}") 30 | check_cxx_source_compiles ("${_source_location_test_code}" CxxSourceLocation_SUPPORTED) 31 | 32 | file (READ ${CMAKE_CURRENT_LIST_DIR}/code_tests/Source_location_default_argument.cc _source_location_test_code) 33 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}") 34 | # see also https://cplusplus.github.io/CWG/issues/2631.html 35 | check_cxx_source_runs ("${_source_location_test_code}" CxxSourceLocation_IMPLEMENTS_CWG2631) 36 | cmake_pop_check_state () 37 | 38 | if (NOT (TARGET SourceLocation::source_location)) 39 | add_library (SourceLocation::source_location INTERFACE IMPORTED) 40 | if ((NOT CxxSourceLocation_SUPPORTED) OR 41 | (NOT CxxSourceLocation_IMPLEMENTS_CWG2631)) 42 | set_target_properties (SourceLocation::source_location 43 | PROPERTIES 44 | INTERFACE_COMPILE_DEFINITIONS SEASTAR_BROKEN_SOURCE_LOCATION) 45 | endif () 46 | endif () 47 | -------------------------------------------------------------------------------- /cmake/FindStdAtomic.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2019 Scylladb, Ltd. 21 | # 22 | 23 | function (_stdatomic_can_link var) 24 | include (CheckCXXSourceCompiles) 25 | set (test_code "int main() {}") 26 | set (CMAKE_REQUIRED_LIBRARIES -latomic) 27 | check_cxx_source_compiles ("${test_code}" ${var}) 28 | endfunction () 29 | 30 | _stdatomic_can_link (StdAtomic_EXPLICIT_LINK) 31 | 32 | # 33 | # If linking against `-latomic` is successful, then do it unconditionally. 34 | # 35 | 36 | if (StdAtomic_EXPLICIT_LINK) 37 | set (StdAtomic_LIBRARY_NAME atomic) 38 | set (StdAtomic_LIBRARIES -l${StdAtomic_LIBRARY_NAME}) 39 | include (FindPackageHandleStandardArgs) 40 | 41 | find_package_handle_standard_args (StdAtomic 42 | REQUIRED_VARS StdAtomic_LIBRARIES) 43 | endif () 44 | 45 | if (NOT (TARGET StdAtomic::atomic)) 46 | add_library (StdAtomic::atomic INTERFACE IMPORTED) 47 | 48 | set_target_properties (StdAtomic::atomic 49 | PROPERTIES 50 | INTERFACE_LINK_LIBRARIES "${StdAtomic_LIBRARIES}") 51 | endif () 52 | -------------------------------------------------------------------------------- /cmake/FindSystemTap-SDT.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2023 Scylladb, Ltd. 21 | # 22 | 23 | find_path (SystemTap-SDT_INCLUDE_DIR 24 | NAMES sys/sdt.h) 25 | 26 | mark_as_advanced ( 27 | SystemTap-SDT_INCLUDE_DIR) 28 | 29 | include (FindPackageHandleStandardArgs) 30 | 31 | find_package_handle_standard_args (SystemTap-SDT 32 | REQUIRED_VARS SystemTap-SDT_INCLUDE_DIR) 33 | 34 | if (NOT TARGET SystemTap::SDT) 35 | add_library (SystemTap::SDT INTERFACE IMPORTED) 36 | set_target_properties (SystemTap::SDT 37 | PROPERTIES 38 | INTERFACE_INCLUDE_DIRECTORIES ${SystemTap-SDT_INCLUDE_DIR}) 39 | endif () 40 | -------------------------------------------------------------------------------- /cmake/FindValgrind.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2022 Kefu Chai ( tchaikov@gmail.com ) 21 | # 22 | 23 | 24 | find_package (PkgConfig REQUIRED) 25 | 26 | pkg_check_modules (PC_valgrind QUIET valgrind) 27 | 28 | find_path (Valgrind_INCLUDE_DIR 29 | NAMES valgrind/valgrind.h 30 | HINTS 31 | ${PC_valgrind_INCLUDEDIR} 32 | ${PC_valgrind_INCLUDE_DIRS}) 33 | 34 | mark_as_advanced ( 35 | Valgrind_INCLUDE_DIR) 36 | 37 | include (FindPackageHandleStandardArgs) 38 | 39 | find_package_handle_standard_args (Valgrind 40 | REQUIRED_VARS 41 | Valgrind_INCLUDE_DIR) 42 | 43 | if (Valgrind_FOUND) 44 | set (Valgrind_INCLUDE_DIRS ${Valgrind_INCLUDE_DIR}) 45 | 46 | if (NOT (TARGET Valgrind::valgrind)) 47 | add_library (Valgrind::valgrind INTERFACE IMPORTED) 48 | 49 | set_target_properties (Valgrind::valgrind 50 | PROPERTIES 51 | INTERFACE_INCLUDE_DIRECTORIES ${Valgrind_INCLUDE_DIRS}) 52 | endif () 53 | endif () 54 | -------------------------------------------------------------------------------- /cmake/Findhwloc.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | find_package (PkgConfig REQUIRED) 24 | 25 | pkg_search_module (PC_hwloc QUIET hwloc) 26 | 27 | find_library (hwloc_LIBRARY 28 | NAMES hwloc 29 | HINTS 30 | ${PC_hwloc_LIBDIR} 31 | ${PC_hwloc_LIBRARY_DIRS}) 32 | 33 | find_path (hwloc_INCLUDE_DIR 34 | NAMES hwloc.h 35 | HINTS 36 | ${PC_hwloc_INCLUDEDIR} 37 | ${PC_hwloc_INCLUDE_DIRS}) 38 | 39 | mark_as_advanced ( 40 | hwloc_LIBRARY 41 | hwloc_INCLUDE_DIR) 42 | 43 | include (FindPackageHandleStandardArgs) 44 | 45 | find_package_handle_standard_args (hwloc 46 | REQUIRED_VARS 47 | hwloc_LIBRARY 48 | hwloc_INCLUDE_DIR 49 | VERSION_VAR hwloc_VERSION) 50 | 51 | if (hwloc_FOUND) 52 | set (hwloc_LIBRARIES ${hwloc_LIBRARY}) 53 | set (hwloc_INCLUDE_DIRS ${hwloc_INCLUDE_DIR}) 54 | if (NOT (TARGET hwloc::hwloc)) 55 | add_library (hwloc::hwloc UNKNOWN IMPORTED) 56 | 57 | set_target_properties (hwloc::hwloc 58 | PROPERTIES 59 | IMPORTED_LOCATION ${hwloc_LIBRARY} 60 | INTERFACE_INCLUDE_DIRECTORIES ${hwloc_INCLUDE_DIRS}) 61 | endif () 62 | endif () 63 | -------------------------------------------------------------------------------- /cmake/Findlksctp-tools.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | find_library (lksctp-tools_LIBRARY 24 | NAMES sctp) 25 | 26 | find_path (lksctp-tools_INCLUDE_DIR 27 | NAMES netinet/sctp.h) 28 | 29 | mark_as_advanced ( 30 | lksctp-tools_LIBRARY 31 | lksctp-tools_INCLUDE_DIR) 32 | 33 | include (FindPackageHandleStandardArgs) 34 | 35 | find_package_handle_standard_args (lksctp-tools 36 | REQUIRED_VARS 37 | lksctp-tools_LIBRARY 38 | lksctp-tools_INCLUDE_DIR) 39 | 40 | set (lksctp-tools_LIBRARIES ${lksctp-tools_LIBRARY}) 41 | set (lksctp-tools_INCLUDE_DIRS ${lksctp-tools_INCLUDE_DIR}) 42 | 43 | if (lksctp-tools_FOUND AND NOT (TARGET lksctp-tools::lksctp-tools)) 44 | add_library (lksctp-tools::lksctp-tools UNKNOWN IMPORTED) 45 | 46 | set_target_properties (lksctp-tools::lksctp-tools 47 | PROPERTIES 48 | IMPORTED_LOCATION ${lksctp-tools_LIBRARIES} 49 | INTERFACE_INCLUDE_DIRECTORIES ${lksctp-tools_INCLUDE_DIRS}) 50 | endif () 51 | 52 | mark_as_advanced ( 53 | lksctp-tools_INCLUDE_DIR 54 | lksctp-tools_LIBRARY) 55 | -------------------------------------------------------------------------------- /cmake/Findlz4.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | find_package (PkgConfig REQUIRED) 24 | 25 | pkg_search_module (PC_lz4 QUIET liblz4) 26 | 27 | find_library (lz4_LIBRARY 28 | NAMES lz4 29 | HINTS 30 | ${PC_lz4_LIBDIR} 31 | ${PC_lz4_LIBRARY_DIRS}) 32 | 33 | find_path (lz4_INCLUDE_DIR 34 | NAMES lz4.h 35 | HINTS 36 | ${PC_lz4_INCLUDEDIR} 37 | ${PC_lz4_INCLUDE_DIRS}) 38 | 39 | mark_as_advanced ( 40 | lz4_LIBRARY 41 | lz4_INCLUDE_DIR) 42 | 43 | include (FindPackageHandleStandardArgs) 44 | 45 | find_package_handle_standard_args (lz4 46 | REQUIRED_VARS 47 | lz4_LIBRARY 48 | lz4_INCLUDE_DIR 49 | VERSION_VAR PC_lz4_VERSION) 50 | 51 | if (lz4_FOUND) 52 | set (CMAKE_REQUIRED_LIBRARIES ${lz4_LIBRARY}) 53 | 54 | set (lz4_LIBRARIES ${lz4_LIBRARY}) 55 | set (lz4_INCLUDE_DIRS ${lz4_INCLUDE_DIR}) 56 | 57 | if (NOT (TARGET lz4::lz4)) 58 | add_library (lz4::lz4 UNKNOWN IMPORTED) 59 | 60 | set_target_properties (lz4::lz4 61 | PROPERTIES 62 | IMPORTED_LOCATION ${lz4_LIBRARY} 63 | INTERFACE_INCLUDE_DIRECTORIES ${lz4_INCLUDE_DIRS}) 64 | endif () 65 | endif () 66 | -------------------------------------------------------------------------------- /cmake/Findragel.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | find_program ( 24 | ragel_RAGEL_EXECUTABLE 25 | ragel) 26 | if (NOT ragel_RAGEL_EXECUTABLE) 27 | message (FATAL_ERROR "ragel is required for processing .rl source files!") 28 | endif () 29 | 30 | mark_as_advanced (ragel_RAGEL_EXECUTABLE) 31 | 32 | set (_ragel_version_pattern "[0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9]+)?") 33 | 34 | if (ragel_RAGEL_EXECUTABLE) 35 | set (ragel_FOUND ON) 36 | 37 | execute_process (COMMAND ${ragel_RAGEL_EXECUTABLE} -v 38 | OUTPUT_VARIABLE _ragel_version_output) 39 | 40 | if (${_ragel_version_output} MATCHES "version (${_ragel_version_pattern})") 41 | set (ragel_VERSION ${CMAKE_MATCH_1}) 42 | endif () 43 | endif () 44 | 45 | find_package_handle_standard_args (ragel 46 | REQUIRED_VARS ragel_RAGEL_EXECUTABLE 47 | VERSION_VAR ragel_VERSION) 48 | -------------------------------------------------------------------------------- /cmake/Findrt.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | set (_rt_test_source ${CMAKE_CURRENT_LIST_DIR}/code_tests/rt_test.cc) 24 | 25 | # Try to compile without the library first. 26 | try_compile (rt_NO_EXPLICIT_LINK 27 | ${CMAKE_CURRENT_BINARY_DIR} 28 | SOURCES ${_rt_test_source}) 29 | 30 | if (rt_NO_EXPLICIT_LINK) 31 | set (rt_FOUND yes) 32 | else () 33 | # The `rt` library is required. 34 | 35 | try_compile (_rt_test 36 | ${CMAKE_CURRENT_BINARY_DIR} 37 | SOURCES ${_rt_test_source} 38 | LINK_LIBRARIES rt) 39 | 40 | if (_rt_test) 41 | set (rt_LIBRARY_NAME rt) 42 | set (rt_LIBRARIES -l${rt_LIBRARY_NAME}) 43 | endif () 44 | 45 | include (FindPackageHandleStandardArgs) 46 | 47 | find_package_handle_standard_args (rt 48 | REQUIRED_VARS rt_LIBRARIES) 49 | endif () 50 | 51 | if (rt_FOUND AND NOT (TARGET rt::rt)) 52 | add_library (rt::rt INTERFACE IMPORTED) 53 | 54 | set_target_properties (rt::rt 55 | PROPERTIES 56 | INTERFACE_LINK_LIBRARIES "${rt_LIBRARIES}") 57 | endif () 58 | -------------------------------------------------------------------------------- /cmake/Finducontext.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2023 Scylladb, Ltd. 21 | # 22 | 23 | # Try to compile without the library first. 24 | include (CheckFunctionExists) 25 | check_function_exists (getcontext 26 | ucontext_NO_EXPLICIT_LINK) 27 | 28 | if (ucontext_NO_EXPLICIT_LINK) 29 | set (ucontext_FOUND yes) 30 | else () 31 | # The `libucontext` library is required. 32 | find_package (PkgConfig QUIET REQUIRED) 33 | pkg_check_modules (PC_ucontext QUIET ucontext) 34 | find_library (ucontext_LIBRARY 35 | NAMES ucontext 36 | HINTS 37 | ${PC_ucontext_LIBDIR} 38 | ${PC_ucontext_LIBRARY_DIRS}) 39 | mark_as_advanced (ucontext_LIBRARY) 40 | include (FindPackageHandleStandardArgs) 41 | find_package_handle_standard_args (ucontext 42 | REQUIRED_VARS ucontext_LIBRARY) 43 | endif () 44 | 45 | if (ucontext_FOUND AND NOT (TARGET ucontext::ucontext)) 46 | add_library (ucontext::ucontext INTERFACE IMPORTED) 47 | 48 | set_target_properties (ucontext::ucontext 49 | PROPERTIES 50 | INTERFACE_LINK_LIBRARIES "${ucontext_LIBRARY}") 51 | endif () 52 | -------------------------------------------------------------------------------- /cmake/TriStateOption.cmake: -------------------------------------------------------------------------------- 1 | # the "option()" defined by CMake represents a boolean. but somtimes, we want 2 | # to enable/disable it depending on the CMAKE_BUILD_TYPE, if user leaves the 3 | # option unset. 4 | function (tri_state_option option) 5 | cmake_parse_arguments ( 6 | parsed_args 7 | "" 8 | "CONDITION" 9 | "DEFAULT_BUILD_TYPES" 10 | ${ARGN}) 11 | 12 | get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 13 | if (is_multi_config) 14 | set (all_build_types ${CMAKE_CONFIGURATION_TYPES}) 15 | else () 16 | set (all_build_types ${CMAKE_BUILD_TYPE}) 17 | endif () 18 | 19 | # generic boolean values passed as string, potentially from configure.py 20 | set (True_STRING_VALUES "ON" "yes" "Yes" "YES" "true" "True" "TRUE") 21 | set (Default_STRING_VALUES "DEFAULT" "default" "Default") 22 | 23 | if ("${option}" IN_LIST True_STRING_VALUES) 24 | set (enabled_types ${all_build_types}) 25 | elseif ("${option}" IN_LIST Default_STRING_VALUES) 26 | set (enabled_types ${parsed_args_DEFAULT_BUILD_TYPES}) 27 | else () 28 | set (enabled_types "") 29 | endif () 30 | 31 | if (is_multi_config) 32 | set (${parsed_args_CONDITION} "$,${enabled_types}>" PARENT_SCOPE) 33 | elseif (CMAKE_BUILD_TYPE IN_LIST enabled_types) 34 | set (${parsed_args_CONDITION} 1 PARENT_SCOPE) 35 | else () 36 | set (${parsed_args_CONDITION} 0 PARENT_SCOPE) 37 | endif () 38 | endfunction () 39 | -------------------------------------------------------------------------------- /cmake/check-seastar-include-style.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # This file is open source software, licensed to you under the terms 4 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 5 | # distributed with this work for additional information regarding copyright 6 | # ownership. You may not use this file except in compliance with the License. 7 | # 8 | # 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, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | import fileinput 21 | import os.path 22 | import re 23 | import sys 24 | 25 | 26 | def check_includes(files, dirname): 27 | # Check for include directives with quotes for specified dirname 28 | incorrect_include = re.compile(rf'#include\s+"({dirname}/[^\"]+)"') 29 | num_errors = 0 30 | for line in fileinput.input(files=files, encoding="utf-8"): 31 | # Look for #include \"seastar/...\" pattern 32 | if matched := incorrect_include.match(line): 33 | location = f"{fileinput.filename()}:{fileinput.lineno()}" 34 | header = matched.group(1) 35 | print(f"{location}: warning: please include seastar headers using: #include <{header}>") 36 | num_errors += 1 37 | return num_errors 38 | 39 | 40 | def main(): 41 | # If any incorrect includes are found, fail the check 42 | files = [fn for fn in sys.argv[1:] if os.path.exists(fn)] 43 | if check_includes(files, "seastar") > 0: 44 | sys.exit(1) 45 | 46 | 47 | if __name__ == '__main__': 48 | main() 49 | -------------------------------------------------------------------------------- /cmake/code_tests/LinuxMembarrier_test.cc: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include 3 | } 4 | 5 | int main() { 6 | int x = MEMBARRIER_CMD_PRIVATE_EXPEDITED | MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED; 7 | (void)x; 8 | } 9 | -------------------------------------------------------------------------------- /cmake/code_tests/Sanitizers_fiber_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" { 4 | void __sanitizer_start_switch_fiber(void**, const void*, size_t); 5 | void __sanitizer_finish_switch_fiber(void*, const void**, size_t*); 6 | } 7 | 8 | int main() { 9 | __sanitizer_start_switch_fiber(nullptr, nullptr, 0); 10 | __sanitizer_finish_switch_fiber(nullptr, nullptr, nullptr); 11 | } 12 | -------------------------------------------------------------------------------- /cmake/code_tests/Source_location_default_argument.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int test_source_location(int line, 4 | std::source_location loc = std::source_location::current()) { 5 | return line == loc.line() ? 0 : 1; 6 | } 7 | 8 | int main() { 9 | return test_source_location(__LINE__); 10 | } 11 | -------------------------------------------------------------------------------- /cmake/code_tests/Source_location_test.cc: -------------------------------------------------------------------------------- 1 | #if __has_include() 2 | #include 3 | #endif 4 | 5 | #ifdef __cpp_lib_source_location 6 | using source_location = std::source_location; 7 | #elif __has_include() 8 | #include 9 | using source_location = std::experimental::source_location; 10 | #endif 11 | 12 | #if defined(__cpp_lib_source_location) || defined(__cpp_lib_experimental_source_location) 13 | struct format_info { 14 | format_info(source_location loc = source_location::current()) noexcept 15 | : loc(loc) 16 | { } 17 | source_location loc; 18 | }; 19 | #else 20 | struct format_info { }; 21 | #endif 22 | 23 | int main() 24 | { 25 | format_info fi; 26 | } 27 | -------------------------------------------------------------------------------- /cmake/code_tests/rt_test.cc: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include 3 | #include 4 | } 5 | 6 | int main() { 7 | timer_t td; 8 | struct sigevent sev; 9 | timer_create(CLOCK_MONOTONIC, &sev, &td); 10 | } 11 | -------------------------------------------------------------------------------- /cmake/code_tests/stdout_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum class logger_type { 4 | stdout, 5 | stderr, 6 | }; 7 | 8 | int main() {} 9 | -------------------------------------------------------------------------------- /debug/task-latency.stap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/stap 2 | 3 | # usage: task_latency.stap process_name latency_threshold_ms 4 | 5 | global start_time 6 | 7 | probe process(@1).mark("reactor_run_tasks_single_start") { 8 | start_time[tid()] = gettimeofday_us() 9 | } 10 | 11 | probe process(@1).mark("reactor_run_tasks_single_end") { 12 | delete start_time[tid()] 13 | } 14 | 15 | probe timer.profile { 16 | if ([tid()] in start_time) { 17 | now = gettimeofday_us() 18 | start = start_time[tid()] 19 | if ((now - start) > $2 * 1000) { 20 | printf("detected tasks running for >%sms\n", @2) 21 | print_usyms(ubacktrace()) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demos/hello-cxx-module.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2023 ScyllaDB Ltd. 20 | */ 21 | 22 | import seastar; 23 | 24 | using namespace seastar; 25 | logger applog("app"); 26 | 27 | int main(int argc, char** argv) { 28 | seastar::app_template app; 29 | app.run(argc, argv, [] () -> future<> { 30 | applog.info("Hello world!"); 31 | return make_ready_future<>(); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /demos/hello-world.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2022 ScyllaDB Ltd. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace seastar; 27 | logger applog("app"); 28 | 29 | int main(int argc, char** argv) { 30 | seastar::app_template app; 31 | app.run(argc, argv, [] () -> future<> { 32 | applog.info("Hello world!"); 33 | return make_ready_future<>(); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /demos/ip_demo.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace seastar; 31 | using namespace net; 32 | 33 | int main(int ac, char** av) { 34 | native_stack_options opts; 35 | 36 | auto vnet = create_virtio_net_device(opts.virtio_opts, opts.lro); 37 | vnet->set_local_queue(vnet->init_local_queue(opts, 0)); 38 | 39 | interface netif(std::move(vnet)); 40 | ipv4 inet(&netif); 41 | inet.set_host_address(ipv4_address("192.168.122.2")); 42 | engine().run(); 43 | return 0; 44 | } 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /demos/l3_demo.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace seastar; 29 | using namespace net; 30 | 31 | void dump_arp_packets(l3_protocol& proto) { 32 | // FIXME: ignored future 33 | (void)proto.receive([] (packet p, ethernet_address from) { 34 | std::cout << "seen arp packet\n"; 35 | return make_ready_future<>(); 36 | }, [] (forward_hash& out_hash_data, packet& p, size_t off) {return false;}); 37 | } 38 | 39 | int main(int ac, char** av) { 40 | native_stack_options opts; 41 | 42 | auto vnet = create_virtio_net_device(opts.virtio_opts, opts.lro); 43 | interface netif(std::move(vnet)); 44 | l3_protocol arp(&netif, eth_protocol_num::arp, []{ return std::optional(); }); 45 | dump_arp_packets(arp); 46 | engine().run(); 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /doc/building-docker.md: -------------------------------------------------------------------------------- 1 | ## Building seastar in Docker container 2 | 3 | To build a Docker image: 4 | 5 | ``` 6 | docker build -t seastar-dev -f docker/dev/Dockerfile . 7 | ``` 8 | 9 | Building is done with two commands: 10 | 11 | ``` 12 | $ ./configure.py 13 | $ ninja -C build/release 14 | ``` 15 | 16 | You can run them inside container, e.g. like this 17 | 18 | ``` 19 | $ seabuild() { docker run -v $HOME/seastar/:/seastar -u $(id -u):$(id -g) -w /seastar -t seastar-dev "$@"; } 20 | $ seabuild ./configure.py 21 | $ seabuild ninja -C build/release 22 | ``` 23 | -------------------------------------------------------------------------------- /doc/building-dpdk.md: -------------------------------------------------------------------------------- 1 | ## Building with a DPDK network backend 2 | 3 | 1. Setup host to compile DPDK: 4 | - Ubuntu 5 | `sudo apt-get install -y build-essential linux-image-extra-$(uname -r)` 6 | 2. Configure the project with DPDK enabled: `./configure.py --mode=release --enable-dpdk` 7 | 3. Run `ninja-build build/release`. 8 | 9 | To run with the DPDK backend for a native stack give the seastar application `--dpdk-pmd 1` parameter. 10 | 11 | You can also configure DPDK as an [external package](/README-DPDK.md). 12 | -------------------------------------------------------------------------------- /doc/contributing.md: -------------------------------------------------------------------------------- 1 | Contributing to Seastar 2 | ======================= 3 | 4 | # Sending Patches 5 | Seastar follows a patch submission similar to Linux. Send patches to seastar-dev, with a DCO signed off message. Use git send-email to send your patch. 6 | 7 | Example: 8 | 9 | 1. When you commit, use "-s " in your git commit command, which adds a DCO signed off message. DCO is a "Developer's Certificate of Origin" http://elinux.org/Developer_Certificate_Of_Origin 10 | 11 | For the commit message, you can prefix a tag for an area of the codebase the patch is addressing 12 | 13 | git commit -s -m "core: some descriptive commit message" 14 | 15 | 2. then send an email to the google group 16 | 17 | git send-email .. --to seastar-dev@googlegroups.com 18 | 19 | NOTE: for sending replies to patches, use --in-reply-to with the message ID of the original message. Also, if you are sending out a new version of the change, use git rebase and then a `git send-email` with a `-v2`, for instance, to denote that it is a second version. 20 | 21 | # Testing and Approval 22 | Run test.py and ensure tests are passing (at least) as well as before the patch. 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /doc/md2html: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | # Copyright (C) 2018 ScyllaDB 19 | 20 | dir=$(dirname "$0") 21 | 22 | case `pandoc --version` in 23 | "pandoc 1."*) 24 | SMART_OPT=--smart 25 | SMART_EXT= 26 | ;; 27 | *) 28 | SMART_OPT= 29 | SMART_EXT=+smart 30 | esac 31 | pandoc --self-contained $SMART_OPT --toc -c ${dir}/template.css --number-sections -f markdown+pandoc_title_block+implicit_header_references$SMART_EXT -V lang=en --highlight-style tango "$1" -o "$2" 32 | -------------------------------------------------------------------------------- /doc/md2pdf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | # Copyright (C) 2018 ScyllaDB 19 | 20 | dir=$(dirname "$0") 21 | 22 | pandoc -f markdown+pandoc_title_block+implicit_header_references --highlight-style tango --template=${dir}/template.tex "$1" -o "$2" 23 | 24 | -------------------------------------------------------------------------------- /doc/signal.md: -------------------------------------------------------------------------------- 1 | # Signals 2 | 3 | Seastar provides an interface to handle signals natively and safely as asynchronous tasks. 4 | 5 | ## Default Signal Handlers 6 | 7 | Seastar sets by default signal handlers for SIGINT/SIGTERM that call reactor::stop(). The reactor will then execute callbacks installed by reactor::at_exit(). 8 | 9 | You can disable this behavior, by setting `app_template::config::auto_handle_sigint_sigterm` to false. This flag is provided in the header [seastar/core/app-template.hh](../include/seastar/core/app-template..hh). Then, Seastar will not set signal handlers, and the default behavior of the Linux kernel will be preserved (terminate the program). 10 | 11 | ### Examples 12 | 13 | ```C++ 14 | #include 15 | 16 | int main(int ac, char** av) { 17 | seastar::app_template::config cfg; 18 | cfg.auto_handle_sigint_sigterm = false; 19 | seastar::app_template app(std::move(cfg)); 20 | 21 | return app.run(argc, argv, [] { 22 | std::cout << "SIGINT/SIGTERM will terminate the program\n"; 23 | }); 24 | } 25 | ``` 26 | 27 | ## Custom Signal Handler 28 | 29 | In order to set a custom signal handler, Seastar provides a procedure called `seastar::handle_signal` in the header [seastar/core/signal.hh](../include/seastar/core/signal.hh). It registers a custom handler for the specified signal based on the configuration params. 30 | 31 | The procedure must be called inside the `app.run()` lambda, otherwise it's UB. 32 | 33 | ### Examples 34 | 35 | ```C++ 36 | #include 37 | #include 38 | 39 | int main(int argc, char** argv) { 40 | seastar::app_template app; 41 | return app.run(argc, argv, [] { 42 | seastar::handle_signal(SIGINT, [&] { 43 | std::cout << "caught sigint\n"; 44 | }, true); 45 | }); 46 | } 47 | ``` 48 | 49 | - [tests/unit/signal_test.cc](../tests/unit/signal_test.cc) 50 | - [apps/lib/stop_signal.hh](../apps/lib/stop_signal.hh) 51 | -------------------------------------------------------------------------------- /docker/dev/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM ubuntu:oracular 4 | 5 | RUN --mount=type=bind,source=./install-dependencies.sh,target=/install-dependencies.sh \ 6 | apt-get update && apt-get install -y \ 7 | curl \ 8 | gnupg \ 9 | && echo "deb http://apt.llvm.org/oracular/ llvm-toolchain-oracular-18 main" \ 10 | >> /etc/apt/sources.list.d/llvm.list \ 11 | && echo "deb http://apt.llvm.org/oracular/ llvm-toolchain-oracular-19 main" \ 12 | >> /etc/apt/sources.list.d/llvm.list \ 13 | && curl -sSL https://apt.llvm.org/llvm-snapshot.gpg.key -o /etc/apt/trusted.gpg.d/apt.llvm.org.asc \ 14 | && apt-get update && apt-get install -y \ 15 | build-essential \ 16 | clang-18 \ 17 | clang-19 \ 18 | clang-tools-19 \ 19 | gcc-13 \ 20 | g++-13 \ 21 | gcc-14 \ 22 | g++-14 \ 23 | pandoc \ 24 | && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 \ 25 | && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13 \ 26 | && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 \ 27 | && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 14 \ 28 | && update-alternatives --install /usr/bin/clang clang /usr/bin/clang-18 18 \ 29 | && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 19 \ 30 | && update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 19 \ 31 | && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 19 \ 32 | && bash ./install-dependencies.sh \ 33 | && apt-get clean \ 34 | && rm -rf /var/lib/apt/lists/* 35 | 36 | CMD ["/bin/bash"] 37 | -------------------------------------------------------------------------------- /include/seastar/core/abort_on_ebadf.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2019 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | SEASTAR_MODULE_EXPORT_BEGIN 29 | 30 | /// Determines whether seastar should throw or abort when operation made by 31 | /// seastar fails because the target file descriptor is not valid. This is 32 | /// detected when underlying system calls return EBADF or ENOTSOCK. 33 | /// The default behavior is to throw std::system_error. 34 | void set_abort_on_ebadf(bool do_abort); 35 | 36 | /// Queries the current setting for seastar's behavior on invalid file descriptor access. 37 | /// See set_abort_on_ebadf(). 38 | bool is_abort_on_ebadf_enabled(); 39 | 40 | SEASTAR_MODULE_EXPORT_END 41 | 42 | } 43 | -------------------------------------------------------------------------------- /include/seastar/core/align.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #include 28 | #endif 29 | 30 | namespace seastar { 31 | 32 | SEASTAR_MODULE_EXPORT_BEGIN 33 | 34 | template 35 | inline constexpr 36 | T align_up(T v, T align) { 37 | return (v + align - 1) & ~(align - 1); 38 | } 39 | 40 | template 41 | inline constexpr 42 | T* align_up(T* v, size_t align) { 43 | static_assert(sizeof(T) == 1, "align byte pointers only"); 44 | return reinterpret_cast(align_up(reinterpret_cast(v), align)); 45 | } 46 | 47 | template 48 | inline constexpr 49 | T align_down(T v, T align) { 50 | return v & ~(align - 1); 51 | } 52 | 53 | template 54 | inline constexpr 55 | T* align_down(T* v, size_t align) { 56 | static_assert(sizeof(T) == 1, "align byte pointers only"); 57 | return reinterpret_cast(align_down(reinterpret_cast(v), align)); 58 | } 59 | 60 | SEASTAR_MODULE_EXPORT_END 61 | 62 | } 63 | -------------------------------------------------------------------------------- /include/seastar/core/aligned_buffer.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2016 ScyllaDB. 20 | */ 21 | #pragma once 22 | #ifndef SEASTAR_MODULE 23 | #include 24 | #include 25 | #include 26 | #endif 27 | 28 | namespace seastar { 29 | 30 | namespace internal { 31 | void* allocate_aligned_buffer_impl(size_t size, size_t align); 32 | } 33 | 34 | SEASTAR_MODULE_EXPORT_BEGIN 35 | 36 | struct free_deleter { 37 | void operator()(void* p) { ::free(p); } 38 | }; 39 | 40 | template 41 | inline 42 | std::unique_ptr allocate_aligned_buffer(size_t size, size_t align) { 43 | static_assert(sizeof(CharType) == 1, "must allocate byte type"); 44 | void* ret = internal::allocate_aligned_buffer_impl(size, align); 45 | return std::unique_ptr(reinterpret_cast(ret)); 46 | } 47 | 48 | SEASTAR_MODULE_EXPORT_END 49 | 50 | } 51 | -------------------------------------------------------------------------------- /include/seastar/core/array_map.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #endif 32 | 33 | namespace seastar { 34 | 35 | // unordered_map implemented as a simple array 36 | 37 | SEASTAR_MODULE_EXPORT 38 | template 39 | class array_map { 40 | std::array _a {}; 41 | public: 42 | array_map(std::initializer_list> i) { 43 | for (auto kv : i) { 44 | _a[kv.first] = kv.second; 45 | } 46 | } 47 | Value& operator[](size_t key) { return _a[key]; } 48 | const Value& operator[](size_t key) const { return _a[key]; } 49 | 50 | Value& at(size_t key) { 51 | if (key >= Max) { 52 | throw std::out_of_range(std::to_string(key) + " >= " + std::to_string(Max)); 53 | } 54 | return _a[key]; 55 | } 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /include/seastar/core/cacheline.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2017 IBM. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #endif 28 | 29 | namespace seastar { 30 | 31 | SEASTAR_MODULE_EXPORT_BEGIN 32 | 33 | // Platform-dependent cache line size for alignment and padding purposes. 34 | constexpr size_t cache_line_size = 35 | #if defined(__x86_64__) || defined(__i386__) 36 | 64; 37 | #elif defined(__s390x__) || defined(__zarch__) 38 | 256; 39 | #elif defined(__PPC64__) 40 | 128; 41 | #elif defined(__aarch64__) 42 | 128; // from Linux, may vary among different microarchitetures? 43 | #else 44 | #error "cache_line_size not defined for this architecture" 45 | #endif 46 | 47 | SEASTAR_MODULE_EXPORT_END 48 | 49 | } 50 | -------------------------------------------------------------------------------- /include/seastar/core/distributed.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2015 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #endif 28 | 29 | namespace seastar { 30 | 31 | SEASTAR_MODULE_EXPORT_BEGIN 32 | 33 | template 34 | using distributed = sharded; 35 | 36 | SEASTAR_MODULE_EXPORT_END 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/seastar/core/enum.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2015 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | /* 25 | * This header file defines a hash function for enum types, using the 26 | * standard hash function of the underlying type (such as int). This makes 27 | * it possible to inherit from this type to 28 | */ 29 | 30 | #ifndef SEASTAR_MODULE 31 | #include 32 | #include 33 | #include 34 | #include 35 | #endif 36 | 37 | namespace seastar { 38 | 39 | SEASTAR_MODULE_EXPORT 40 | template 41 | class enum_hash { 42 | static_assert(std::is_enum_v, "must be an enum"); 43 | public: 44 | std::size_t operator()(const T& e) const { 45 | using utype = std::underlying_type_t; 46 | return std::hash()(static_cast(e)); 47 | } 48 | }; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /include/seastar/core/exception_hacks.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2017 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace seastar { 25 | void init_phdr_cache(); 26 | } 27 | -------------------------------------------------------------------------------- /include/seastar/core/format.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #ifndef SEASTAR_MODULE 26 | #include 27 | #endif 28 | 29 | namespace seastar { 30 | 31 | /** 32 | * Evaluate the formatted string in a native fmt library format 33 | * 34 | * @param fmt format string with the native fmt library syntax 35 | * @param a positional parameters 36 | * 37 | * @return sstring object with the result of applying the given positional 38 | * parameters on a given format string. 39 | */ 40 | template 41 | sstring 42 | format(fmt::format_string fmt, A&&... a) { 43 | fmt::memory_buffer out; 44 | fmt::format_to(fmt::appender(out), fmt, std::forward(a)...); 45 | return sstring{out.data(), out.size()}; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/seastar/core/fsqual.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ScyllaDB 3 | */ 4 | /* 5 | * This file is open source software, licensed to you under the terms 6 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 7 | * distributed with this work for additional information regarding copyright 8 | * ownership. You may not use this file except in compliance with the License. 9 | * 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | bool filesystem_has_good_aio_support(sstring directory, bool verbose = false); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /include/seastar/core/future-util.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | -------------------------------------------------------------------------------- /include/seastar/core/internal/api-level.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2019 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | // For IDEs that don't see SEASTAR_API_LEVEL, generate a nice default 25 | #ifndef SEASTAR_API_LEVEL 26 | #define SEASTAR_API_LEVEL 7 27 | #endif 28 | 29 | #if SEASTAR_API_LEVEL == 7 30 | #define SEASTAR_INCLUDE_API_V7 inline 31 | #else 32 | #define SEASTAR_INCLUDE_API_V7 33 | #endif 34 | 35 | // Declare them here so we don't have to use the macros everywhere 36 | namespace seastar { 37 | SEASTAR_INCLUDE_API_V7 namespace api_v7 { 38 | inline namespace and_newer { 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /include/seastar/core/internal/buffer_allocator.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2020 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace seastar { 25 | 26 | template 27 | class temporary_buffer; 28 | 29 | namespace internal { 30 | 31 | // Internal interface for allocating buffers for reads. Used to decouple 32 | // allocation strategies (where to allocate from, and what sizes) from the 33 | // point where allocation happens, to make it as late as possible. 34 | class buffer_allocator { 35 | public: 36 | virtual ~buffer_allocator() = default; 37 | virtual temporary_buffer allocate_buffer() = 0; 38 | }; 39 | 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /include/seastar/core/internal/io_desc.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2019 ScyllaDB Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | class kernel_completion { 29 | protected: 30 | kernel_completion() = default; 31 | kernel_completion(kernel_completion&&) = default; 32 | kernel_completion& operator=(kernel_completion&&) = default; 33 | ~kernel_completion() = default; 34 | public: 35 | virtual void complete_with(ssize_t res) = 0; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /include/seastar/core/internal/run_in_background.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2023 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar::internal { 27 | 28 | void run_in_background(future<> f); 29 | 30 | template 31 | void run_in_background(Func&& func) { 32 | run_in_background(futurize_invoke(std::forward(func))); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/seastar/core/io_priority_class.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2021 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #include 28 | 29 | #endif 30 | 31 | namespace seastar { 32 | 33 | class io_queue; 34 | 35 | SEASTAR_MODULE_EXPORT_BEGIN 36 | 37 | using io_priority_class_id = unsigned; 38 | 39 | SEASTAR_MODULE_EXPORT_END 40 | 41 | namespace internal { 42 | struct maybe_priority_class_ref { 43 | }; 44 | } 45 | 46 | } // namespace seastar 47 | -------------------------------------------------------------------------------- /include/seastar/core/manual_clock.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2016 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #endif 31 | 32 | namespace seastar { 33 | 34 | SEASTAR_MODULE_EXPORT 35 | class manual_clock { 36 | public: 37 | using rep = int64_t; 38 | using period = std::chrono::nanoseconds::period; 39 | using duration = std::chrono::duration; 40 | using time_point = std::chrono::time_point; 41 | private: 42 | static std::atomic _now; 43 | static void expire_timers() noexcept; 44 | public: 45 | manual_clock() noexcept; 46 | static time_point now() noexcept { 47 | return time_point(duration(_now.load(std::memory_order_relaxed))); 48 | } 49 | static void advance(duration d) noexcept; 50 | }; 51 | 52 | extern template class timer; 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /include/seastar/core/polymorphic_temporary_buffer.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2019 Elazar Leibovich 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #include 28 | #include 29 | #endif 30 | 31 | namespace seastar { 32 | 33 | /// Creates a `temporary_buffer` allocated by a custom allocator 34 | /// 35 | /// \param allocator allocator to use when allocating the temporary_buffer 36 | /// \param size size of the temporary buffer 37 | SEASTAR_MODULE_EXPORT 38 | template 39 | temporary_buffer make_temporary_buffer(std::pmr::polymorphic_allocator* allocator, std::size_t size) { 40 | if (allocator == memory::malloc_allocator) { 41 | return temporary_buffer(size); 42 | } 43 | CharType *buffer = allocator->allocate(size); 44 | return temporary_buffer(buffer, size, 45 | make_deleter(deleter(), [allocator, buffer, size] () mutable { allocator->deallocate(buffer, size); })); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/seastar/core/report_exception.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2014 Cloudius Systems 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace seastar { 28 | 29 | void report_exception(std::string_view message, std::exception_ptr) noexcept; 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /include/seastar/core/scollectd_api.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Cloudius Systems 3 | */ 4 | 5 | #pragma once 6 | 7 | #ifndef SEASTAR_MODULE 8 | #include 9 | #include 10 | #include 11 | #include 12 | #endif 13 | 14 | namespace seastar { 15 | 16 | namespace scollectd { 17 | 18 | SEASTAR_MODULE_EXPORT_BEGIN 19 | 20 | using collectd_value = seastar::metrics::impl::metric_value; 21 | 22 | std::vector get_collectd_value( 23 | const scollectd::type_instance_id& id); 24 | 25 | std::vector get_collectd_ids(); 26 | 27 | sstring get_collectd_description_str(const scollectd::type_instance_id&); 28 | 29 | bool is_enabled(const scollectd::type_instance_id& id); 30 | /** 31 | * Enable or disable collectd metrics on local instance 32 | * @param id - the metric to enable or disable 33 | * @param enable - should the collectd metrics be enable or disable 34 | */ 35 | void enable(const scollectd::type_instance_id& id, bool enable); 36 | 37 | 38 | metrics::impl::value_map get_value_map(); 39 | 40 | SEASTAR_MODULE_EXPORT_END 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/seastar/core/shard_id.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2023-present ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | /// \file 27 | 28 | namespace seastar { 29 | 30 | SEASTAR_MODULE_EXPORT_BEGIN 31 | 32 | using shard_id = unsigned; 33 | 34 | SEASTAR_MODULE_EXPORT_END 35 | 36 | namespace internal { 37 | 38 | #ifdef SEASTAR_BUILD_SHARED_LIBS 39 | shard_id* this_shard_id_ptr() noexcept; 40 | #else 41 | inline shard_id* this_shard_id_ptr() noexcept { 42 | static thread_local shard_id g_this_shard_id; 43 | return &g_this_shard_id; 44 | } 45 | #endif 46 | 47 | } // namespace internal 48 | 49 | SEASTAR_MODULE_EXPORT_BEGIN 50 | 51 | /// Returns shard_id of the of the current shard. 52 | inline shard_id this_shard_id() noexcept { 53 | return *internal::this_shard_id_ptr(); 54 | } 55 | 56 | SEASTAR_MODULE_EXPORT_END 57 | 58 | 59 | } // namespace seastar 60 | -------------------------------------------------------------------------------- /include/seastar/core/shared_ptr_incomplete.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2017 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | 27 | /// \file 28 | /// \brief Include this header files when using \c lw_shared_ptr, at the point 29 | /// where \c some_incomplete_type is defined. 30 | 31 | namespace seastar { 32 | 33 | namespace internal { 34 | 35 | // Overload when lw_shared_ptr_deleter specialized 36 | template 37 | T* 38 | lw_shared_ptr_accessors{})>>::to_value(lw_shared_ptr_counter_base* counter) { 39 | return static_cast(counter); 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/seastar/core/signal.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | #pragma once 20 | 21 | /// \file 22 | 23 | // Seastar interface for POSIX signals. 24 | #include 25 | #include 26 | 27 | namespace seastar { 28 | 29 | SEASTAR_MODULE_EXPORT_BEGIN 30 | 31 | /// \brief Sets a signal handler for the specified signal. 32 | /// 33 | /// \param signo Signal number. 34 | /// \param handler Function to handle the signal. 35 | /// \param once Should the handler be invoked only once. 36 | void handle_signal(int signo, noncopyable_function&& handler, bool once = false); 37 | 38 | SEASTAR_MODULE_EXPORT_END 39 | 40 | } 41 | -------------------------------------------------------------------------------- /include/seastar/core/stall_sampler.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 ScyllaDB 3 | */ 4 | 5 | /* 6 | * This file is open source software, licensed to you under the terms 7 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 8 | * distributed with this work for additional information regarding copyright 9 | * ownership. You may not use this file except in compliance with the License. 10 | * 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, 16 | * software distributed under the License is distributed on an 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | * KIND, either express or implied. See the License for the 19 | * specific language governing permissions and limitations 20 | * under the License. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | // Instrumentation to detect context switches during reactor execution 31 | // and associated stall time, intended for use in tests 32 | 33 | namespace seastar { 34 | 35 | namespace internal { 36 | 37 | struct stall_report { 38 | uint64_t kernel_stalls; 39 | sched_clock::duration run_wall_time; // excludes sleeps 40 | sched_clock::duration stall_time; 41 | }; 42 | 43 | /// Run the unit-under-test (uut) function until completion, and report on any 44 | /// reactor stalls it generated. 45 | future report_reactor_stalls(noncopyable_function ()> uut); 46 | 47 | std::ostream& operator<<(std::ostream& os, const stall_report& sr); 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /include/seastar/core/systemwide_memory_barrier.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2015 Scylla DB 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace seastar { 25 | 26 | /// \cond internal 27 | 28 | // cause all threads to invoke a full memory barrier 29 | void systemwide_memory_barrier(); 30 | // attempt to invoke a systemwide memory barrier; return false 31 | // if doing so would cause lock contention in the kernel 32 | bool try_systemwide_memory_barrier(); 33 | 34 | /// \endcond 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /include/seastar/core/thread_cputime_clock.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2018 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #endif 28 | #include 29 | 30 | namespace seastar { 31 | 32 | class thread_cputime_clock { 33 | public: 34 | using rep = int64_t; 35 | using period = std::chrono::nanoseconds::period; 36 | using duration = std::chrono::duration; 37 | using time_point = std::chrono::time_point; 38 | public: 39 | static time_point now() { 40 | using namespace std::chrono_literals; 41 | 42 | struct timespec tp; 43 | [[gnu::unused]] auto ret = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp); 44 | SEASTAR_ASSERT(ret == 0); 45 | return time_point(tp.tv_nsec * 1ns + tp.tv_sec * 1s); 46 | } 47 | }; 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /include/seastar/core/timed_out_error.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright 2020 ScyllaDB 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef SEASTAR_MODULE 26 | #include 27 | #include 28 | #include 29 | #endif 30 | 31 | namespace seastar { 32 | 33 | SEASTAR_MODULE_EXPORT 34 | class timed_out_error : public std::exception { 35 | public: 36 | virtual const char* what() const noexcept { 37 | return "timedout"; 38 | } 39 | }; 40 | 41 | SEASTAR_MODULE_EXPORT 42 | struct default_timeout_exception_factory { 43 | static auto timeout() { 44 | return timed_out_error(); 45 | } 46 | }; 47 | 48 | } // namespace seastar 49 | 50 | #if FMT_VERSION < 100000 51 | // fmt v10 introduced formatter for std::exception 52 | template <> 53 | struct fmt::formatter : fmt::formatter { 54 | auto format(const seastar::timed_out_error& e, fmt::format_context& ctx) const { 55 | return fmt::format_to(ctx.out(), "{}", e.what()); 56 | } 57 | }; 58 | #endif 59 | -------------------------------------------------------------------------------- /include/seastar/core/units.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #endif 27 | #include 28 | 29 | namespace seastar { 30 | 31 | SEASTAR_MODULE_EXPORT_BEGIN 32 | 33 | constexpr size_t KB = 1 << 10; 34 | constexpr size_t MB = 1 << 20; 35 | constexpr size_t GB = 1 << 30; 36 | 37 | constexpr size_t operator""_KiB(unsigned long long n) { return n << 10; } 38 | constexpr size_t operator""_MiB(unsigned long long n) { return n << 20; } 39 | constexpr size_t operator""_GiB(unsigned long long n) { return n << 30; } 40 | constexpr size_t operator""_TiB(unsigned long long n) { return n << 40; } 41 | 42 | SEASTAR_MODULE_EXPORT_END 43 | } 44 | -------------------------------------------------------------------------------- /include/seastar/core/vector-data-sink.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2014 Cloudius Systems 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #endif 28 | 29 | namespace seastar { 30 | 31 | SEASTAR_MODULE_EXPORT 32 | class vector_data_sink final : public data_sink_impl { 33 | public: 34 | using vector_type = std::vector; 35 | private: 36 | vector_type& _v; 37 | public: 38 | vector_data_sink(vector_type& v) : _v(v) {} 39 | 40 | virtual future<> put(net::packet p) override { 41 | _v.push_back(std::move(p)); 42 | return make_ready_future<>(); 43 | } 44 | 45 | virtual future<> close() override { 46 | // TODO: close on local side 47 | return make_ready_future<>(); 48 | } 49 | }; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /include/seastar/http/mime_types.hh: -------------------------------------------------------------------------------- 1 | // 2 | // mime_types.hpp 3 | // ~~~~~~~~~~~~~~ 4 | // 5 | // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | // 10 | 11 | #pragma once 12 | 13 | #include 14 | #include 15 | 16 | namespace seastar { 17 | 18 | namespace http { 19 | 20 | namespace mime_types { 21 | 22 | /** 23 | * Convert a file extension into a MIME type. 24 | * 25 | * @param extension the file extension 26 | * @return the mime type as a string 27 | */ 28 | SEASTAR_MODULE_EXPORT 29 | const char* extension_to_type(const sstring& extension); 30 | 31 | } // namespace mime_types 32 | 33 | } // namespace httpd 34 | 35 | namespace httpd { 36 | namespace mime_types { 37 | [[deprecated("Use http::mime_types::extension_to_type instead")]] 38 | inline const char* extension_to_type(const sstring& extension) { 39 | return http::mime_types::extension_to_type(extension); 40 | } 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/seastar/http/transformers.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2015 Cloudius Systems 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace seastar { 29 | 30 | namespace httpd { 31 | 32 | /** 33 | * content_replace replaces variable in a file with a dynamic value. 34 | * It would take the host from request and will replace the variable 35 | * in a file 36 | * 37 | * The replacement can be restricted to an extension. 38 | * 39 | * We are currently support only one file type for replacement. 40 | * It could be extend if we will need it 41 | * 42 | */ 43 | SEASTAR_MODULE_EXPORT 44 | class content_replace : public file_transformer { 45 | public: 46 | virtual output_stream transform(std::unique_ptr req, 47 | const sstring& extension, output_stream&& s); 48 | /** 49 | * the constructor get the file extension the replace would work on. 50 | * @param extension file extension, when not set all files extension 51 | */ 52 | explicit content_replace(const sstring& extension = "") 53 | : extension(extension) { 54 | } 55 | private: 56 | sstring extension; 57 | }; 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /include/seastar/http/url.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2022 Scylladb, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | namespace http { 29 | namespace internal { 30 | 31 | bool url_decode(std::string_view in, sstring& out); 32 | 33 | bool path_decode(std::string_view in, sstring& out); 34 | 35 | /** 36 | * Makes a percent-encoded string out of the given parameter 37 | * 38 | * Note, that it does NOT parse and encode a URL correctly handling 39 | * all the delimeters in arguments. It's up to the caller to split 40 | * the URL into path and arguments (both names and values) and use 41 | * this helper to encode individual strings 42 | */ 43 | sstring url_encode(std::string_view in); 44 | 45 | } // internal namespace 46 | } // http namespace 47 | 48 | } // seastar namespace 49 | -------------------------------------------------------------------------------- /include/seastar/net/config.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2017 Marek Waszkiewicz ( marek.waszkiewicz77@gmail.com ) 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace seastar { 30 | namespace net { 31 | 32 | struct ipv4_config { 33 | std::string ip; 34 | std::string netmask; 35 | std::string gateway; 36 | bool dhcp{ false }; 37 | }; 38 | 39 | struct hw_config { 40 | std::string pci_address; 41 | std::optional port_index; 42 | bool lro{ true }; 43 | bool tso{ true }; 44 | bool ufo{ true }; 45 | bool hw_fc{ true }; 46 | bool event_index{ true }; 47 | bool csum_offload{ true }; 48 | std::optional ring_size; 49 | }; 50 | 51 | struct device_config { 52 | ipv4_config ip_cfg; 53 | hw_config hw_cfg; 54 | }; 55 | 56 | std::unordered_map parse_config(std::istream& input); 57 | 58 | class config_exception : public std::runtime_error { 59 | public: 60 | config_exception(const std::string& msg) 61 | : std::runtime_error(msg) { 62 | } 63 | }; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /include/seastar/net/const.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | namespace net { 29 | 30 | enum class ip_protocol_num : uint8_t { 31 | icmp = 1, tcp = 6, udp = 17, unused = 255 32 | }; 33 | 34 | enum class eth_protocol_num : uint16_t { 35 | ipv4 = 0x0800, arp = 0x0806, ipv6 = 0x86dd 36 | }; 37 | 38 | const uint8_t eth_hdr_len = 14; 39 | const uint8_t tcp_hdr_len_min = 20; 40 | const uint8_t ipv4_hdr_len_min = 20; 41 | const uint8_t ipv6_hdr_len_min = 40; 42 | const uint16_t ip_packet_len_max = 65535; 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /include/seastar/net/packet-data-source.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | namespace seastar { 24 | 25 | namespace net { 26 | 27 | class packet_data_source final : public data_source_impl { 28 | size_t _cur_frag = 0; 29 | packet _p; 30 | public: 31 | explicit packet_data_source(net::packet&& p) 32 | : _p(std::move(p)) 33 | {} 34 | 35 | virtual future> get() override { 36 | if (_cur_frag != _p.nr_frags()) { 37 | auto& f = _p.fragments()[_cur_frag++]; 38 | return make_ready_future>( 39 | temporary_buffer(f.base, f.size, 40 | make_deleter(deleter(), [p = _p.share()] () mutable {}))); 41 | } 42 | return make_ready_future>(temporary_buffer()); 43 | } 44 | }; 45 | 46 | static inline 47 | input_stream as_input_stream(packet&& p) { 48 | return input_stream(data_source(std::make_unique(std::move(p)))); 49 | } 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /include/seastar/net/proxy.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | #pragma once 19 | 20 | #ifndef SEASTAR_MODULE 21 | #include 22 | #endif 23 | #include 24 | #include 25 | 26 | namespace seastar { 27 | 28 | namespace net { 29 | 30 | std::unique_ptr create_proxy_net_device(unsigned master_cpu, device* dev); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /include/seastar/net/tcp-stack.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | // tcp/network-stack integration 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | 29 | namespace seastar { 30 | 31 | struct listen_options; 32 | 33 | class server_socket; 34 | class socket; 35 | class connected_socket; 36 | 37 | namespace net { 38 | 39 | struct ipv4_traits; 40 | template 41 | class tcp; 42 | 43 | server_socket 44 | tcpv4_listen(tcp& tcpv4, uint16_t port, listen_options opts); 45 | 46 | seastar::socket 47 | tcpv4_socket(tcp& tcpv4); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /include/seastar/net/udp.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | * 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifndef SEASTAR_MODULE 26 | #include 27 | #include 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace seastar { 37 | 38 | namespace net { 39 | 40 | struct udp_hdr { 41 | packed src_port; 42 | packed dst_port; 43 | packed len; 44 | packed cksum; 45 | 46 | template 47 | auto adjust_endianness(Adjuster a) { 48 | return a(src_port, dst_port, len, cksum); 49 | } 50 | } __attribute__((packed)); 51 | 52 | struct udp_channel_state { 53 | queue _queue; 54 | // Limit number of data queued into send queue 55 | semaphore _user_queue_space = {212992}; 56 | udp_channel_state(size_t queue_size) : _queue(queue_size) {} 57 | future<> wait_for_send_buffer(size_t len) { return _user_queue_space.wait(len); } 58 | void complete_send(size_t len) { _user_queue_space.signal(len); } 59 | }; 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /include/seastar/rpc/lz4_compressor.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2016 Scylladb, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace seastar { 28 | 29 | namespace rpc { 30 | class lz4_compressor : public compressor { 31 | public: 32 | class factory: public rpc::compressor::factory { 33 | public: 34 | virtual const sstring& supported() const override; 35 | virtual std::unique_ptr negotiate(sstring feature, bool is_server) const override; 36 | }; 37 | public: 38 | ~lz4_compressor() {} 39 | // compress data, leaving head_space empty in returned buffer 40 | snd_buf compress(size_t head_space, snd_buf data) override; 41 | // decompress data 42 | rcv_buf decompress(rcv_buf data) override; 43 | sstring name() const override; 44 | }; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /include/seastar/rpc/lz4_fragmented_compressor.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2019 Scylladb, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace seastar { 28 | namespace rpc { 29 | 30 | class lz4_fragmented_compressor final : public compressor { 31 | public: 32 | class factory final : public rpc::compressor::factory { 33 | public: 34 | virtual const sstring& supported() const override; 35 | virtual std::unique_ptr negotiate(sstring feature, bool is_server) const override; 36 | }; 37 | public: 38 | virtual snd_buf compress(size_t head_space, snd_buf data) override; 39 | virtual rcv_buf decompress(rcv_buf data) override; 40 | sstring name() const override; 41 | }; 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /include/seastar/testing/entry_point.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2018 ScyllaDB Ltd. 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace seastar { 26 | 27 | namespace testing { 28 | 29 | int entry_point(int argc, char **argv); 30 | 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /include/seastar/testing/linux_perf_event.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021-present ScyllaDB 3 | */ 4 | 5 | /* 6 | * This file is open source software, licensed to you under the terms 7 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 8 | * distributed with this work for additional information regarding copyright 9 | * ownership. You may not use this file except in compliance with the License. 10 | * 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, 16 | * software distributed under the License is distributed on an 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 | * KIND, either express or implied. See the License for the 19 | * specific language governing permissions and limitations 20 | * under the License. 21 | */ 22 | 23 | /* 24 | * This file was copied from Scylla (https://github.com/scylladb/scylla) 25 | */ 26 | 27 | #pragma once 28 | 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | struct perf_event_attr; // from 35 | 36 | class linux_perf_event { 37 | int _fd = -1; 38 | public: 39 | linux_perf_event(const struct ::perf_event_attr& attr, pid_t pid, int cpu, int group_fd, unsigned long flags); 40 | linux_perf_event(linux_perf_event&& x) noexcept : _fd(std::exchange(x._fd, -1)) {} 41 | linux_perf_event& operator=(linux_perf_event&& x) noexcept; 42 | ~linux_perf_event(); 43 | uint64_t read(); 44 | void enable(); 45 | void disable(); 46 | public: 47 | static linux_perf_event user_instructions_retired(); 48 | static linux_perf_event user_cpu_cycles_retired(); 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /include/seastar/testing/on_internal_error.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2020 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace seastar { 25 | namespace testing { 26 | 27 | // Disables aborting in on_internal_error() for a scope. 28 | // 29 | // Intended for tests, which want to test error paths that invoke 30 | // on_internal_error() without aborting, at the same time, having it enabled 31 | // for other, indirectly affected code paths, that are not a direct target of 32 | // the test. 33 | class scoped_no_abort_on_internal_error { 34 | bool _prev; 35 | public: 36 | scoped_no_abort_on_internal_error() noexcept; 37 | ~scoped_no_abort_on_internal_error(); 38 | }; 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /include/seastar/testing/random.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2020 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | namespace testing { 29 | 30 | extern thread_local std::default_random_engine local_random_engine; 31 | 32 | } // namespace testing 33 | 34 | } // namespace seastar 35 | -------------------------------------------------------------------------------- /include/seastar/testing/test_runner.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2015 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace seastar { 32 | 33 | namespace testing { 34 | 35 | class test_runner { 36 | private: 37 | std::unique_ptr _thread; 38 | std::atomic _started{false}; 39 | exchanger()>> _task; 40 | bool _done = false; 41 | int _exit_code{0}; 42 | 43 | struct start_thread_args { 44 | int ac; 45 | char** av; 46 | start_thread_args(int ac_, char** av_) noexcept : ac(ac_), av(av_) {} 47 | }; 48 | std::unique_ptr _st_args; 49 | bool start_thread(int ac, char** av); 50 | public: 51 | // Returns whether initialization was successful. 52 | // Will return as soon as the seastar::app was started. 53 | bool start(int argc, char** argv); 54 | ~test_runner(); 55 | void run_sync(std::function()> task); 56 | // Returns the return value of the underlying `seastar::app::run()`. 57 | int finalize(); 58 | }; 59 | 60 | test_runner& global_test_runner(); 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /include/seastar/util/assert.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2025 Redpanda Data. 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace seastar::internal { 25 | [[noreturn]] void assert_fail(const char *msg, const char *file, int line, 26 | const char *func); 27 | } 28 | 29 | /// Like assert(), but independent of NDEBUG. Active in all build modes. 30 | #define SEASTAR_ASSERT(x) \ 31 | do { \ 32 | if (!(x)) [[unlikely]] { \ 33 | seastar::internal::assert_fail(#x, __FILE__, __LINE__, \ 34 | __PRETTY_FUNCTION__); \ 35 | } \ 36 | } while (0) 37 | -------------------------------------------------------------------------------- /include/seastar/util/concepts.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2020 ScyllaDB 20 | */ 21 | #pragma once 22 | 23 | #include 24 | 25 | #if defined(__cpp_concepts) && __cpp_concepts >= 201907 && \ 26 | defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 201907 27 | // good 28 | #else 29 | #error the language support and/or library support for concepts is missing 30 | #endif 31 | 32 | // provided for backward compatibility 33 | #define SEASTAR_CONCEPT(x...) x 34 | #define SEASTAR_NO_CONCEPT(x...) 35 | -------------------------------------------------------------------------------- /include/seastar/util/conversions.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #include 28 | #endif 29 | #include 30 | 31 | namespace seastar { 32 | 33 | // Convert a string to a memory size, allowing binary SI 34 | // suffixes (intentionally, even though SI suffixes are 35 | // decimal, to follow existing usage). A string matched 36 | // by following BNF is accetped: 37 | // 38 | // memory_size ::= + ? "i"? "B"? 39 | // suffix ::= ("k" | "K" | "M" | "G" | "T") 40 | // 41 | // for instance: 42 | // 43 | // "5" -> 5 44 | // "4k" -> (4 << 10) 45 | // "8Mi" -> (8 << 20) 46 | // "7GB" -> (7 << 30) 47 | // "1TiB" -> (1 << 40) 48 | // anything else: exception 49 | SEASTAR_MODULE_EXPORT 50 | size_t parse_memory_size(std::string_view s); 51 | 52 | static inline std::vector string2vector(std::string_view str) { 53 | auto v = std::vector(str.begin(), str.end()); 54 | v.push_back('\0'); 55 | return v; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /include/seastar/util/eclipse.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | * 21 | */ 22 | 23 | #pragma once 24 | 25 | // Workarounds for deficiencies in Eclipse's C++ parser 26 | // 27 | // Tell Eclipse that IN_ECLIPSE is defined so it will ignore all the unknown syntax. 28 | 29 | #ifndef IN_ECLIPSE 30 | 31 | #else 32 | 33 | // Eclipse doesn't grok alignof 34 | #define alignof sizeof 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/seastar/util/exceptions.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright 2020 ScyllaDB 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace seastar { 28 | 29 | /// \brief make a filesystem_error for system calls with a single file operand. 30 | /// 31 | /// \param what - describes the action that failed 32 | /// \param path - path of the file that hit the error 33 | /// \param error - the system error number (see errno(3)) 34 | /// 35 | std::filesystem::filesystem_error make_filesystem_error(const std::string& what, std::filesystem::path path, int error); 36 | 37 | /// \brief make a filesystem_error for system calls with two file operands. 38 | /// 39 | /// \param what - describes the action that failed 40 | /// \param path1, path2 - paths of the files that hit the error 41 | /// \param error - the system error number (see errno(3)) 42 | /// 43 | std::filesystem::filesystem_error make_filesystem_error(const std::string& what, std::filesystem::path path1, std::filesystem::path path2, int error); 44 | 45 | } // namespace seastar 46 | -------------------------------------------------------------------------------- /include/seastar/util/internal/iovec_utils.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2022 ScyllaDB. 20 | */ 21 | 22 | #ifndef SEASTAR_MODULE 23 | #include 24 | #endif 25 | 26 | #pragma once 27 | 28 | namespace seastar { 29 | namespace internal { 30 | 31 | inline size_t iovec_len(const iovec* begin, size_t len) 32 | { 33 | size_t ret = 0; 34 | auto end = begin + len; 35 | while (begin != end) { 36 | ret += begin++->iov_len; 37 | } 38 | return ret; 39 | } 40 | 41 | inline size_t iovec_len(const std::vector& iov) 42 | { 43 | size_t ret = 0; 44 | for (auto&& e : iov) { 45 | ret += e.iov_len; 46 | } 47 | return ret; 48 | } 49 | 50 | // Given a properly aligned vector of iovecs, ensures that it respects the 51 | // IOV_MAX limit, by trimming if necessary. The modified vector still satisfied 52 | // the alignment requirements. 53 | // Returns the final total length of all iovecs. 54 | size_t sanitize_iovecs(std::vector& iov, size_t disk_alignment) noexcept; 55 | 56 | } // internal namespace 57 | } // seastar namespace 58 | -------------------------------------------------------------------------------- /include/seastar/util/is_smart_ptr.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2015 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include // for std::unique_ptr 25 | #include 26 | 27 | namespace seastar { 28 | 29 | template 30 | struct is_smart_ptr : std::false_type {}; 31 | 32 | template 33 | struct is_smart_ptr> : std::true_type {}; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/seastar/util/modules.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2023 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef SEASTAR_MODULE 25 | # define SEASTAR_MODULE_EXPORT export 26 | # define SEASTAR_MODULE_EXPORT_BEGIN export { 27 | # define SEASTAR_MODULE_EXPORT_END } 28 | #else 29 | # define SEASTAR_MODULE_EXPORT 30 | # define SEASTAR_MODULE_EXPORT_BEGIN 31 | # define SEASTAR_MODULE_EXPORT_END 32 | #endif 33 | -------------------------------------------------------------------------------- /include/seastar/util/read_first_line.hh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifndef SEASTAR_MODULE 4 | #include 5 | #endif 6 | 7 | namespace seastar { 8 | 9 | sstring read_first_line(std::filesystem::path sys_file); 10 | 11 | template 12 | Type read_first_line_as(std::filesystem::path sys_file) { 13 | return boost::lexical_cast(read_first_line(sys_file)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /include/seastar/util/short_streams.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2021 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace seastar { 30 | 31 | namespace util { 32 | 33 | SEASTAR_MODULE_EXPORT_BEGIN 34 | /// Returns all bytes from the stream until eof, accessible in chunks. 35 | /// 36 | /// \note use only on short streams to avoid running out of memory. 37 | /// 38 | /// \param inp \ref input_stream to be read. 39 | future>> read_entire_stream(input_stream& inp); 40 | 41 | /// Returns all bytes from the stream until eof as a single buffer. 42 | /// 43 | /// \note use only on short streams to avoid running out of memory. 44 | /// 45 | /// \param inp \ref input_stream to be read. 46 | future read_entire_stream_contiguous(input_stream& inp); 47 | 48 | /// Ignores all bytes in the stream, until eos. 49 | /// 50 | /// \param inp \ref input_stream to be read. 51 | future<> skip_entire_stream(input_stream& inp); 52 | 53 | SEASTAR_MODULE_EXPORT_END 54 | } // namespace util 55 | 56 | } // namespace seastar 57 | -------------------------------------------------------------------------------- /include/seastar/util/source_location-compat.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2021 ScyllaDB 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace seastar::internal { 26 | 27 | class source_location { 28 | const char* _file; 29 | const char* _func; 30 | int _line; 31 | int _col; 32 | 33 | constexpr source_location(const char* file, const char* func, int line, int col) noexcept 34 | : _file(file) 35 | , _func(func) 36 | , _line(line) 37 | , _col(col) 38 | { } 39 | public: 40 | constexpr source_location() noexcept 41 | : _file("unknown") 42 | , _func(_file) 43 | , _line(0) 44 | , _col(0) 45 | { } 46 | static 47 | #ifdef __cpp_consteval 48 | consteval 49 | #endif 50 | source_location current(const char* file = __builtin_FILE(), const char* func = __builtin_FUNCTION(), int line = __builtin_LINE(), int col = 0) noexcept { 51 | return source_location(file, func, line, col); 52 | } 53 | 54 | constexpr const char* file_name() const noexcept { return _file; } 55 | constexpr const char* function_name() const noexcept { return _func; } 56 | constexpr int line() const noexcept { return _line; } 57 | constexpr int column() const noexcept { return _col; } 58 | }; 59 | 60 | } // namespace seastar::internal 61 | -------------------------------------------------------------------------------- /include/seastar/util/string_utils.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2015 Cloudius Systems 20 | */ 21 | 22 | // 23 | // request.hpp 24 | // ~~~~~~~~~~~ 25 | // 26 | // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) 27 | // 28 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 29 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 30 | 31 | #pragma once 32 | 33 | #ifndef SEASTAR_MODULE 34 | #include 35 | #include 36 | #endif 37 | 38 | #include 39 | #include 40 | 41 | namespace seastar { 42 | 43 | namespace internal { 44 | 45 | SEASTAR_MODULE_EXPORT_BEGIN 46 | // 47 | // Collection of utilities for working with strings . 48 | // 49 | 50 | struct case_insensitive_cmp { 51 | bool operator()(const sstring& s1, const sstring& s2) const { 52 | return std::equal(s1.begin(), s1.end(), s2.begin(), s2.end(), 53 | [](char a, char b) { return ::tolower(a) == ::tolower(b); }); 54 | } 55 | }; 56 | 57 | struct case_insensitive_hash { 58 | size_t operator()(sstring s) const { 59 | std::transform(s.begin(), s.end(), s.begin(), ::tolower); 60 | return std::hash()(s); 61 | } 62 | }; 63 | 64 | SEASTAR_MODULE_EXPORT_END 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /include/seastar/util/transform_iterator.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace seastar { 25 | 26 | template 27 | class transform_iterator { 28 | Iterator _i; 29 | Func _f; 30 | public: 31 | transform_iterator(Iterator i, Func f) : _i(i), _f(f) {} 32 | auto operator*() { return _f(*_i); } 33 | transform_iterator& operator++() { 34 | ++_i; 35 | return *this; 36 | } 37 | transform_iterator operator++(int) { 38 | transform_iterator ret(*this); 39 | _i++; 40 | return ret; 41 | } 42 | bool operator==(const transform_iterator& x) const { 43 | return _i == x._i; 44 | } 45 | bool operator!=(const transform_iterator& x) const { 46 | return !operator==(x); 47 | } 48 | }; 49 | 50 | template 51 | inline 52 | transform_iterator 53 | make_transform_iterator(Iterator i, Func f) { 54 | return transform_iterator(i, f); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /include/seastar/util/used_size.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2020 ScyllaDB Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifndef SEASTAR_MODULE 25 | #include 26 | #include 27 | #endif 28 | 29 | namespace seastar { 30 | namespace internal { 31 | // Empty types have a size of 1, but that byte is not actually 32 | // used. This helper is used to avoid accessing that byte. 33 | template 34 | struct used_size { 35 | static constexpr size_t value = std::is_empty_v ? 0 : sizeof(T); 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /kvm/README.md: -------------------------------------------------------------------------------- 1 | # seastar-in-kvm 2 | Create a VM for Seastar development environment 3 | 4 | # Why we need this 5 | SeaStar scores muximum performance with DPDK, but it cannot live with existing NIC driver/Linux kernel network stack. 6 | Also it directly accesses NIC device, it's bit hard to try it on remote node. 7 | 8 | seastar-in-kvm offers Fedora VM with SeaStar + DPDK without setup, it's easiest way to begin SeaStar application development. 9 | 10 | ### Prerequire 11 | 12 | On Fedora 21: 13 | ``` 14 | yum install @virtualization 15 | systemctl enable libvirtd 16 | systemctl start libvirtd 17 | yum install libguestfs-tools-c virt-install 18 | ``` 19 | 20 | ### How to build & run 21 | ``` 22 | ./build.sh 23 | ./register.sh 24 | virsh start seastar-dev && virsh console seastar-dev 25 | (Try login as 'seastar' after firstboot.sh finished, Fedora will ask new password for the user) 26 | ``` 27 | 28 | ### Usage of the VM 29 | 30 | Wait until finish running setup script on first startup. 31 | Then login as 'seastar', login prompt will ask for entering new password. 32 | 33 | After login to seastar, initialize DPDK module by following instruction: 34 | ``` 35 | sudo su - # entering root user 36 | resize # extend console to actual terminal window size 37 | export TERM=xterm-256color # set terminal type 38 | cd ~/dpdk 39 | ./tools/setup.sh 40 | 41 | # input numbers by following order: 42 | (type 9 to re-compile DPDK) 43 | (type 12 to insert IGB UIO module) 44 | (type 15, then input "64" to setup hugepage mappings) 45 | (type 18, then input PCI device id something like "0000:xx:yy.z", 46 | which is shown at 'Network devices using DPDK-compatible driver') 47 | (type 30 to exit) 48 | 49 | cd ~/seastar 50 | # httpd example 51 | env LD_LIBRARY_PATH=~/dpdk/x86_64-native-linuxapp-gcc/lib/ \ 52 | ./build/release/apps/httpd/httpd --network-stack native --dpdk-pmd --csum-offload off 53 | ``` 54 | 55 | 56 | -------------------------------------------------------------------------------- /kvm/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -rf /tmp/seastar 4 | cp -a ../ /tmp/seastar 5 | virt-builder fedora-21 -o seastar-dev.qcow2 --format qcow2 --size 20G --hostname seastar-dev --install "@core" --update --selinux-relabel --copy-in /tmp/seastar:/root/ --firstboot scripts/bootstrap.sh 6 | rm -rf /tmp/seastar 7 | -------------------------------------------------------------------------------- /kvm/register.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | virt-install --import --noreboot --name seastar-dev --vcpus 4 --ram 4096 --disk path=`realpath seastar-dev.qcow2`,format=qcow2,bus=virtio --accelerate --network=network:default,model=virtio --serial pty --cpu host --rng=/dev/random 4 | -------------------------------------------------------------------------------- /kvm/scripts/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | nmcli c modify eth0 ipv4.ignore-auto-dns "yes" 3 | systemctl restart network 4 | echo nameserver 8.8.8.8 > /etc/resolv.conf 5 | useradd -m -p "" -g wheel seastar 6 | chage -d 0 seastar 7 | yum install -y gcc gcc-c++ libaio-devel ninja-build ragel hwloc-devel numactl-devel libpciaccess-devel boost-devel kernel-devel libxml2-devel zlib-devel libasan libubsan git wget python3 tar pciutils xterm 8 | cd /root 9 | wget http://dpdk.org/browse/dpdk/snapshot/dpdk-2.0.0.tar.gz 10 | tar -xpf dpdk-2.0.0.tar.gz 11 | mv dpdk-2.0.0 dpdk 12 | cd dpdk 13 | cat config/common_linuxapp | sed -e "s/CONFIG_RTE_MBUF_REFCNT_ATOMIC=y/CONFIG_RTE_MBUF_REFCNT_ATOMIC=n/g" | sed -e "s/CONFIG_RTE_BUILD_SHARED_LIB=n/CONFIG_RTE_BUILD_SHARED_LIB=y/g" > /tmp/common_linuxapp 14 | mv /tmp/common_linuxapp config 15 | make T=x86_64-native-linuxapp-gcc install 16 | cd - 17 | cd seastar 18 | ./configure.py --dpdk-target ~/dpdk/x86_64-native-linuxapp-gcc 19 | ninja-build -j2 20 | -------------------------------------------------------------------------------- /licenses/cmake.txt: -------------------------------------------------------------------------------- 1 | CMake - Cross Platform Makefile Generator 2 | Copyright 2000-2018 Kitware, Inc. and Contributors 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Kitware, Inc. nor the names of Contributors 17 | may be used to endorse or promote products derived from this 18 | software without specific prior written permission. 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 24 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /licenses/dpdk.txt: -------------------------------------------------------------------------------- 1 | This project contains files from DPDK project that are distributed under BSD license. 2 | -------------------------------------------------------------------------------- /licenses/freebsd.txt: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 1. Redistributions of source code must retain the above copyright 5 | notice, this list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright 7 | notice, this list of conditions and the following disclaimer in the 8 | documentation and/or other materials provided with the distribution. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 11 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 14 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 15 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 16 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 17 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 18 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 19 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 20 | SUCH DAMAGE. 21 | -------------------------------------------------------------------------------- /pkgconfig/seastar-testing.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@Seastar_PKG_CONFIG_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@Seastar_PKG_CONFIG_LIBDIR@ 4 | 5 | Name: Seastar testing 6 | Url: http://seastar-project.org 7 | Description: Testing tools for libraries and applications built with Seastar 8 | Version: @PROJECT_VERSION@ 9 | 10 | # Dependencies. 11 | boost_cflags=-I$ 12 | boost_unit_test_libs=$ 13 | 14 | # Us. 15 | seastar_testing_cflags= 16 | seastar_testing_libs=${libdir}/$ 17 | 18 | Requires: seastar >= 1.0 19 | Conflicts: 20 | Cflags: ${boost_cflags} ${seastar_testing_cflags} 21 | Libs: ${boost_unit_test_libs} ${seastar_testing_libs} 22 | -------------------------------------------------------------------------------- /scripts/perftune.yaml: -------------------------------------------------------------------------------- 1 | # Mode is one of the following values: 2 | # - 'mq' 3 | # - 'sq' 4 | # - 'sq_split' 5 | #mode: 'sq_split' 6 | 7 | # Name of the NIC to tune, e.g. eth7. 8 | # By default would use 'eth0'. 9 | #nic: eth7 10 | 11 | # If 'true' the script will the CPU mask to be used for compute. 12 | #get_cpu_mask: true 13 | 14 | # Define what to tune: could be any combination of the values from {'net', 'disks'} set. 15 | #tune: 16 | # - net 17 | # - disks 18 | 19 | # Mask of cores to use, by default use all available cores. 20 | #cpu_mask: '0x00f,,,0x0,,0x00f' 21 | 22 | # Set of directories to optimize. 23 | #dir: 24 | # - /root 25 | # - /home 26 | 27 | # Set of disk devices to optimize 28 | #dev: 29 | # - /dev/sda2 30 | # - /dev/md0 31 | 32 | # write_back_cache: false 33 | 34 | -------------------------------------------------------------------------------- /scripts/pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 100 3 | skip-string-normalization = true 4 | -------------------------------------------------------------------------------- /scripts/seastar-cpu-map.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ! 3 | # ! Usage: ./seastar-cpu-map.sh -p -n -s (optional) 4 | # ! 5 | # ! List CPU affinity for a particular running process 6 | # ! providing a map of threads -> shard, for any seastar apps. 7 | # ! Ex.: ./seastar-cpu-map.sh -n scylla 8 | # ! ./seastar-cpu-map.sh -n scylla -s 0 9 | # ! ./seastar-cpu-map.sh -p 34 10 | # ! ./seastar-cpu-map.sh -p 32 -s 12 11 | 12 | usage() { 13 | cat $0 | grep ^"# !" | cut -d"!" -f2- 14 | } 15 | 16 | while getopts 'p:n:s:' option; do 17 | case "$option" in 18 | p) PID=$OPTARG 19 | ;; 20 | n) PID=`pgrep --newest --exact $OPTARG` 21 | ;; 22 | s) SHARD=$OPTARG 23 | ;; 24 | :) printf "missing argument for -%s\n" "$OPTARG" >&2 25 | usage >&2 26 | exit 1 27 | ;; 28 | \?) printf "illegal option: -%s\n" "$OPTARG" >&2 29 | usage >&2 30 | exit 1 31 | ;; 32 | esac 33 | done 34 | 35 | if [ $# -eq 0 ]; then usage >&2; exit 1; fi 36 | 37 | if [ -e "/proc/$PID/task" ]; then 38 | # get list of threads for given PID 39 | THREADS=`ls /proc/$PID/task` 40 | for i in $THREADS; do 41 | # get shards from threads 42 | # there were three options here to get the shard number: 43 | # reactor-xx, syscall-xx and timer-xx 44 | # syscall was preferred because reactor as a special case (reactor-0 is called scylla) 45 | SYSCALL=`grep syscall /proc/$i/comm | cut -d"-" -f2` 46 | if [ -n "$SYSCALL" ] && [ "$SYSCALL" = "$SHARD" ]; then 47 | echo -e "shard: $SYSCALL, cpu:$(taskset -c -p $i | cut -d":" -f2)" 48 | elif [ -n "$SYSCALL" ] && [ -z "$SHARD" ]; then 49 | echo -e "shard: $SYSCALL, cpu:$(taskset -c -p $i | cut -d":" -f2)" 50 | fi 51 | done 52 | else 53 | echo "Process does not exist" 54 | fi 55 | -------------------------------------------------------------------------------- /scripts/tap.sh: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | ### Set up a tap device for seastar 20 | tap=tap0 21 | bridge=virbr0 22 | user=`whoami` 23 | sudo ip link del $tap 24 | sudo ip tuntap add mode tap dev $tap user $user one_queue vnet_hdr 25 | sudo ifconfig $tap up 26 | sudo brctl addif $bridge $tap 27 | sudo brctl stp $bridge off 28 | sudo modprobe vhost-net 29 | sudo chown $user.$user /dev/vhost-net 30 | sudo brctl show $bridge 31 | sudo ifconfig $bridge 32 | -------------------------------------------------------------------------------- /src/core/cgroup.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2019 ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace seastar { 29 | 30 | namespace cgroup { 31 | 32 | using std::optional; 33 | using cpuset = std::set; 34 | 35 | optional cpu_set(); 36 | size_t memory_limit(); 37 | 38 | template 39 | optional read_setting_as(std::string path); 40 | 41 | template 42 | optional read_setting_V1V2_as(std::string cg1_path, std::string cg2_fname); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/core/prefault.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | // Copyright 2023 ScyllaDB 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace seastar::alien { 34 | 35 | class instance; 36 | 37 | }; 38 | 39 | namespace seastar::internal { 40 | 41 | // Responsible for pre-faulting in memory so soft page fault latency doesn't impact applications 42 | class memory_prefaulter { 43 | std::atomic _stop_request = false; 44 | std::vector _worker_threads; 45 | // Keep this in object scope to avoid allocating in worker thread 46 | std::unordered_map> _layout_by_node_id; 47 | std::atomic _active_threads = 0; 48 | public: 49 | explicit memory_prefaulter(alien::instance& alien, const resource::resources& res, memory::internal::numa_layout layout); 50 | ~memory_prefaulter(); 51 | private: 52 | void work(std::vector& ranges, size_t page_size, std::optional huge_page_size_opt); 53 | void join_threads() noexcept; 54 | }; 55 | 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/core/sharded.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2018 ScyllaDB 20 | */ 21 | 22 | #ifdef SEASTAR_MODULE 23 | module; 24 | #endif 25 | 26 | #include 27 | 28 | #ifdef SEASTAR_MODULE 29 | module seastar; 30 | #else 31 | #include 32 | #include 33 | #endif 34 | 35 | namespace seastar { 36 | 37 | namespace internal { 38 | 39 | 40 | future<> 41 | sharded_parallel_for_each(unsigned nr_shards, on_each_shard_func on_each_shard) noexcept(std::is_nothrow_move_constructible_v) { 42 | return parallel_for_each(std::views::iota(0u, nr_shards), std::move(on_each_shard)); 43 | } 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/core/signal.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | #ifdef SEASTAR_MODULE 20 | module; 21 | #endif 22 | 23 | #include 24 | 25 | #ifdef SEASTAR_MODULE 26 | module seastar; 27 | #else 28 | #include 29 | #include 30 | #endif 31 | 32 | namespace seastar { 33 | 34 | void handle_signal(int signo, noncopyable_function&& handler, bool once) { 35 | auto& r = engine(); 36 | if (once) { 37 | r._signals.handle_signal_once(signo, std::move(handler)); 38 | } else { 39 | r._signals.handle_signal(signo, std::move(handler)); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/core/sstring.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2020 ScyllaDB 20 | */ 21 | 22 | #ifdef SEASTAR_MODULE 23 | module; 24 | #include 25 | #include 26 | #include 27 | module seastar; 28 | #else 29 | #include 30 | #endif 31 | 32 | using namespace seastar; 33 | 34 | [[noreturn]] void internal::throw_bad_alloc() { 35 | throw std::bad_alloc(); 36 | } 37 | 38 | [[noreturn]] void internal::throw_sstring_overflow() { 39 | throw std::overflow_error("sstring overflow"); 40 | } 41 | 42 | [[noreturn]] void internal::throw_sstring_out_of_range() { 43 | throw std::out_of_range("sstring out of range"); 44 | } 45 | -------------------------------------------------------------------------------- /src/core/vla.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace seastar { 29 | 30 | // Some C APIs have a structure with a variable length array at the end. 31 | // This is a helper function to help allocate it. 32 | // 33 | // for a structure 34 | // 35 | // struct xx { int a; float b[0]; }; 36 | // 37 | // use 38 | // 39 | // make_struct_with_vla(&xx::b, number_of_bs); 40 | // 41 | // to allocate it. 42 | // 43 | template 44 | inline 45 | std::unique_ptr 46 | make_struct_with_vla(E S::*last, size_t nr) { 47 | auto fake = reinterpret_cast(0); 48 | size_t offset = reinterpret_cast(&(fake->*last)); 49 | size_t element_size = sizeof((fake->*last)[0]); 50 | SEASTAR_ASSERT(offset == sizeof(S)); 51 | auto p = std::unique_ptr( 52 | reinterpret_cast(::malloc(offset + element_size * nr))); 53 | auto s = std::unique_ptr(new (p.get()) S()); 54 | p.release(); 55 | return s; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/http/mime_types.cc: -------------------------------------------------------------------------------- 1 | // 2 | // mime_types.cpp 3 | // ~~~~~~~~~~~~~~ 4 | // 5 | // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | // 10 | 11 | #ifdef SEASTAR_MODULE 12 | module; 13 | module seastar; 14 | #else 15 | #include 16 | #endif 17 | 18 | namespace seastar { 19 | 20 | namespace http { 21 | namespace mime_types { 22 | 23 | struct mapping { 24 | const char* extension; 25 | const char* mime_type; 26 | } mappings[] = { 27 | { "json", "application/json"}, 28 | { "xml", "application/xml"}, 29 | { "gif", "image/gif" }, 30 | { "htm", "text/html" }, 31 | { "css", "text/css" }, 32 | { "js", "text/javascript" }, 33 | { "html", "text/html" }, 34 | { "jpg", "image/jpeg" }, 35 | { "svg", "image/svg+xml" }, 36 | { "png", "image/png" }, 37 | { "txt", "text/plain" }, 38 | { "ico", "image/x-icon" }, 39 | { "bin", "application/octet-stream" }, 40 | { "proto", "application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited"}, 41 | }; 42 | 43 | const char* extension_to_type(const sstring& extension) 44 | { 45 | for (mapping m : mappings) { 46 | if (extension == m.extension) { 47 | return m.mime_type; 48 | } 49 | } 50 | return "text/plain"; 51 | } 52 | 53 | } // namespace mime_types 54 | 55 | } // http 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/net/ethernet.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace seastar { 29 | 30 | namespace net { 31 | 32 | std::ostream& operator<<(std::ostream& os, ethernet_address ea) { 33 | auto& m = ea.mac; 34 | using u = uint32_t; 35 | fmt::print(os, "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", 36 | u(m[0]), u(m[1]), u(m[2]), u(m[3]), u(m[4]), u(m[5])); 37 | return os; 38 | } 39 | 40 | ethernet_address parse_ethernet_address(std::string addr) 41 | { 42 | std::vector v; 43 | boost::split(v, addr , boost::algorithm::is_any_of(":")); 44 | 45 | if (v.size() != 6) { 46 | throw std::runtime_error("invalid mac address\n"); 47 | } 48 | 49 | ethernet_address a; 50 | unsigned i = 0; 51 | for (auto &x: v) { 52 | a.mac[i++] = std::stoi(x, nullptr,16); 53 | } 54 | return a; 55 | } 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/net/unix_address.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2019 Red Hat, Inc. 20 | */ 21 | /*! \file 22 | \brief unix-domain address structures, to be used for creating socket_address-es for unix-domain 23 | sockets. 24 | 25 | Note that the path in a unix-domain address may start with a null character. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace seastar { 33 | 34 | std::ostream& operator<<(std::ostream& os, const unix_domain_addr& addr) { 35 | if (addr.path_length() == 0) { 36 | return os << "{unnamed}"; 37 | } 38 | if (addr.name[0]) { 39 | // regular (filesystem-namespace) path 40 | return os << addr.name; 41 | } 42 | 43 | os << '@'; 44 | const char* src = addr.path_bytes() + 1; 45 | 46 | for (auto k = addr.path_length(); --k > 0; src++) { 47 | os << (std::isprint(*src) ? *src : '_'); 48 | } 49 | return os; 50 | } 51 | 52 | } // namespace seastar 53 | 54 | size_t std::hash::operator()(const seastar::unix_domain_addr& a) const { 55 | return std::hash()(a.name); 56 | } 57 | -------------------------------------------------------------------------------- /src/testing/random.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2020 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | namespace seastar { 26 | 27 | namespace testing { 28 | 29 | thread_local std::default_random_engine local_random_engine; 30 | 31 | } // namespace testing 32 | 33 | } // namespace seastar 34 | -------------------------------------------------------------------------------- /src/util/conversions.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #ifdef SEASTAR_MODULE 23 | module; 24 | #endif 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef SEASTAR_MODULE 31 | module seastar; 32 | #else 33 | #include 34 | #include 35 | #endif 36 | 37 | namespace seastar { 38 | 39 | static constexpr struct { 40 | std::string_view suffix; 41 | unsigned power; 42 | } suffixes[] = { 43 | {"k", 10}, 44 | {"K", 10}, 45 | {"M", 20}, 46 | {"G", 30}, 47 | {"T", 40}, 48 | }; 49 | 50 | size_t parse_memory_size(std::string_view s) { 51 | for (std::string_view unit : {"i", "iB", "B"}) { 52 | if (boost::algorithm::ends_with(s, unit)) { 53 | s.remove_suffix(unit.size()); 54 | break; 55 | } 56 | } 57 | size_t factor = 1; 58 | for (auto [suffix, power] : suffixes) { 59 | if (boost::algorithm::ends_with(s, suffix)) { 60 | factor <<= power; 61 | s.remove_suffix(suffix.size()); 62 | break; 63 | } 64 | } 65 | return boost::lexical_cast(s) * factor; 66 | } 67 | 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/util/exceptions.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright 2020 ScyllaDB 21 | */ 22 | 23 | #include 24 | 25 | namespace seastar { 26 | 27 | std::filesystem::filesystem_error make_filesystem_error(const std::string& what, std::filesystem::path path, int error) { 28 | return std::filesystem::filesystem_error(what, std::move(path), std::error_code(error, std::system_category())); 29 | } 30 | 31 | std::filesystem::filesystem_error make_filesystem_error(const std::string& what, std::filesystem::path path1, std::filesystem::path path2, int error) { 32 | return std::filesystem::filesystem_error(what, std::move(path1), std::move(path1), std::error_code(error, std::system_category())); 33 | } 34 | 35 | } // namespace seastar 36 | -------------------------------------------------------------------------------- /src/util/read_first_line.cc: -------------------------------------------------------------------------------- 1 | #ifdef SEASTAR_MODULE 2 | module; 3 | #include 4 | #include 5 | module seastar; 6 | #else 7 | #include 8 | #include 9 | #endif 10 | 11 | namespace seastar { 12 | 13 | sstring read_first_line(std::filesystem::path sys_file) { 14 | auto file = file_desc::open(sys_file.string(), O_RDONLY | O_CLOEXEC); 15 | sstring buf; 16 | size_t n = 0; 17 | do { 18 | // try to avoid allocations 19 | sstring tmp = uninitialized_string(8); 20 | auto ret = file.read(tmp.data(), 8ul); 21 | if (!ret) { // EAGAIN 22 | continue; 23 | } 24 | n = *ret; 25 | if (n > 0) { 26 | buf += tmp; 27 | } 28 | } while (n != 0); 29 | auto end = buf.find('\n'); 30 | auto value = buf.substr(0, end); 31 | file.close(); 32 | return value; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is open source software, licensed to you under the terms 3 | # of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | # distributed with this work for additional information regarding copyright 5 | # ownership. You may not use this file except in compliance with the License. 6 | # 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | # 20 | # Copyright (C) 2018 Scylladb, Ltd. 21 | # 22 | 23 | function (seastar_jenkins_arguments test_name var) 24 | string (TOLOWER ${CMAKE_BUILD_TYPE} mode) 25 | set (output_file "${CMAKE_SOURCE_DIR}/${Seastar_JENKINS}.${mode}.${test_name}_test.boost.xml") 26 | 27 | set (${var} 28 | --output_format=XML 29 | --log_level=all 30 | --report_level=no 31 | --log_sink=${output_file} 32 | PARENT_SCOPE) 33 | endfunction () 34 | 35 | # Performance tests. 36 | add_subdirectory (perf) 37 | 38 | # Unit tests. 39 | add_subdirectory (unit) 40 | -------------------------------------------------------------------------------- /tests/manual/iosched_reproducers/one_cpu_starved_shard_can_still_saturate_io.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Test scenario: 4 | # A single CPU-starved shard has a batch IO job. 5 | # Goal: it should be able to utilize the entire bandwidth of the disk, 6 | # despite the rare polls. 7 | 8 | if [ $# -ne 1 ]; then 9 | echo "Usage: $0 IO_TESTER_EXECUTABLE" >&2 10 | exit 1 11 | fi 12 | 13 | "$1" --smp=7 --storage=/dev/null --conf=<(cat <<'EOF' 14 | - name: tablet-streaming 15 | data_size: 1GB 16 | shards: [0] 17 | type: seqread 18 | shard_info: 19 | parallelism: 50 20 | reqsize: 128kB 21 | shares: 200 22 | - name: cpuhog 23 | type: cpu 24 | shards: [0] 25 | shard_info: 26 | parallelism: 1 27 | execution_time: 550us 28 | 29 | EOF 30 | ) --io-properties-file=<(cat <<'EOF' 31 | # i4i.2xlarge 32 | disks: 33 | - mountpoint: /dev 34 | read_bandwidth: 1542559872 35 | read_iops: 218786 36 | write_bandwidth: 1130867072 37 | write_iops: 121499 38 | EOF 39 | ) 40 | -------------------------------------------------------------------------------- /tests/manual/iosched_reproducers/one_cpu_starved_shard_has_reasonable_fairness.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Test scenario: 4 | # all shards contend for IO, but one shard is additionally CPU-starved 5 | # and polls rarely. 6 | # Goal: it should still be getting a reasonably fair share of disk bandwidth. 7 | 8 | if [ $# -ne 1 ]; then 9 | echo "Usage: $0 IO_TESTER_EXECUTABLE" >&2 10 | exit 1 11 | fi 12 | 13 | "$1" --smp=7 --storage=/dev/null --conf=<(cat <<'EOF' 14 | - name: tablet-streaming 15 | data_size: 1GB 16 | shards: all 17 | type: seqread 18 | shard_info: 19 | parallelism: 50 20 | reqsize: 128kB 21 | shares: 200 22 | - name: cpuhog 23 | type: cpu 24 | shards: [0] 25 | shard_info: 26 | parallelism: 1 27 | execution_time: 550us 28 | 29 | EOF 30 | ) --io-properties-file=<(cat <<'EOF' 31 | # i4i.2xlarge 32 | disks: 33 | - mountpoint: /dev 34 | read_bandwidth: 1542559872 35 | read_iops: 218786 36 | write_bandwidth: 1130867072 37 | write_iops: 121499 38 | EOF 39 | ) --duration=2 40 | -------------------------------------------------------------------------------- /tests/manual/iosched_reproducers/tau_nemesis.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # There is a `tau` mechanism in `fair_queue` which lets newly-activated 4 | # IO classes to monopolize the shard's IO queue for a while. 5 | # 6 | # This isn't very useful and can result in major performance problems, 7 | # as this test illustrates. The `highprio` workload could have tail latency 8 | # of about 2 milliseconds, but the `bursty_lowprio` is allowed by `tau` to butt in 9 | # periodically and preempt `highprio` for ~30ms, bringing its tail latency 10 | # to that threshold. 11 | 12 | if [ $# -ne 1 ]; then 13 | echo "Usage: $0 IO_TESTER_EXECUTABLE" >&2 14 | exit 1 15 | fi 16 | 17 | "$1" --smp=7 --storage=/dev/null --conf=<(cat <<'EOF' 18 | - name: filler 19 | data_size: 1GB 20 | shards: all 21 | type: seqread 22 | shard_info: 23 | parallelism: 10 24 | reqsize: 128kB 25 | shares: 10 26 | - name: bursty_lowprio 27 | data_size: 1GB 28 | shards: all 29 | type: seqread 30 | shard_info: 31 | parallelism: 1 32 | reqsize: 128kB 33 | shares: 100 34 | batch: 50 35 | rps: 8 36 | - name: highprio 37 | shards: all 38 | type: randread 39 | data_size: 1GB 40 | shard_info: 41 | parallelism: 100 42 | reqsize: 1536 43 | shares: 1000 44 | rps: 50 45 | options: 46 | pause_distribution: poisson 47 | sleep_type: steady 48 | EOF 49 | ) --io-properties-file=<(cat <<'EOF' 50 | # i4i.2xlarge 51 | disks: 52 | - mountpoint: /dev 53 | read_bandwidth: 1542559872 54 | read_iops: 218786 55 | write_bandwidth: 1130867072 56 | write_iops: 121499 57 | EOF 58 | ) 59 | -------------------------------------------------------------------------------- /tests/perf/coroutine_perf.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2022-present ScyllaDB 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | struct coroutine_test { 28 | }; 29 | 30 | PERF_TEST_C(coroutine_test, empty) 31 | { 32 | co_return; 33 | } 34 | 35 | PERF_TEST_C(coroutine_test, without_preemption_check) 36 | { 37 | co_await coroutine::without_preemption_check(make_ready_future<>()); 38 | } 39 | 40 | PERF_TEST_C(coroutine_test, ready) 41 | { 42 | co_await make_ready_future<>(); 43 | } 44 | 45 | PERF_TEST_C(coroutine_test, maybe_yield) 46 | { 47 | co_await coroutine::maybe_yield(); 48 | } 49 | -------------------------------------------------------------------------------- /tests/unit/cert.cfg.in: -------------------------------------------------------------------------------- 1 | [ req ] 2 | default_bits = @CERT_WIDTH@ 3 | default_keyfile = @CERT_PRIVKEY@ 4 | default_md = sha256 5 | distinguished_name = req_distinguished_name 6 | req_extensions = v3_req 7 | prompt = no 8 | [ req_distinguished_name ] 9 | C = @CERT_COUNTRY@ 10 | ST = @CERT_STATE@ 11 | L = @CERT_LOCALITY@ 12 | O = @CERT_ORG@ 13 | OU = @CERT_UNIT@ 14 | CN= @CERT_COMMON@ 15 | emailAddress = @CERT_EMAIL@ 16 | [v3_ca] 17 | subjectKeyIdentifier=hash 18 | authorityKeyIdentifier=keyid:always,issuer:always 19 | basicConstraints = CA:true 20 | [v3_req] 21 | # Extensions to add to a certificate request 22 | basicConstraints = CA:FALSE 23 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 24 | 25 | [req_ext] 26 | subjectAltName=email:@CERT_ALT_EMAIL_1@,email:@CERT_ALT_EMAIL_2@,IP:@CERT_ALT_IP_1@,DNS:@CERT_ALT_DNS@ 27 | -------------------------------------------------------------------------------- /tests/unit/conf-example.yaml: -------------------------------------------------------------------------------- 1 | metrics: 2 | - name: hist1 3 | type: histogram 4 | values: [1000,2000,3000] 5 | labels: 6 | private: "1" 7 | - name: gag1 8 | type: gauge 9 | values: [5] 10 | labels: 11 | private: "1" 12 | - name: count1 13 | type: counter 14 | labels: 15 | private: "1" 16 | values: [7] 17 | - name: counter_1 18 | type: counter 19 | labels: 20 | private: "2" 21 | values: [1] 22 | - name: counter_1 23 | type: counter 24 | labels: 25 | private: "3" 26 | values: [2] 27 | metric_family_config: 28 | - name: test_group_counter_1 29 | aggregate_labels: 30 | - private 31 | -------------------------------------------------------------------------------- /tests/unit/expected_exception.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright 2025-present ScyllaDB 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace seastar { 27 | 28 | class expected_exception : public std::runtime_error { 29 | public: 30 | expected_exception() : std::runtime_error("expected") {} 31 | }; 32 | 33 | } // namespace seastar 34 | -------------------------------------------------------------------------------- /tests/unit/libc_wrapper_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2024 ScyllaDB. 21 | */ 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | using namespace seastar; 32 | 33 | SEASTAR_TEST_CASE(getgrnam_group_name_does_not_exist_test) { 34 | // A better approach would be to use a test setup and teardown to create a fake group 35 | // with members in it and in the teardown delete the fake group. 36 | std::optional grp = co_await getgrnam("roo"); 37 | BOOST_REQUIRE(!grp.has_value()); 38 | } 39 | 40 | SEASTAR_TEST_CASE(getgrnam_group_name_exists_test) { 41 | std::optional grp = co_await getgrnam("root"); 42 | BOOST_REQUIRE(grp.has_value()); 43 | BOOST_REQUIRE_EQUAL(grp.value().group_name.c_str(), "root"); 44 | } -------------------------------------------------------------------------------- /tests/unit/mkmtls.gmk: -------------------------------------------------------------------------------- 1 | server = $(shell hostname) 2 | domain = $(shell dnsdomainname) 3 | name = $(server) 4 | 5 | country = SE 6 | state = Stockholm 7 | locality= $(state) 8 | org = $(domain) 9 | unit = $(domain) 10 | mail = mx 11 | common = $(server).$(domain) 12 | subj = "/C=$(country)/ST=$(state)/L=$(locality)/O=$(domain)/OU=$(domain)/CN=$(common)" 13 | client1 = "/C=$(country)/ST=$(state)/L=$(locality)/O=$(domain)/OU=$(domain)/CN=client1.org" 14 | client2 = "/C=$(country)/ST=$(state)/L=$(locality)/O=$(domain)/OU=$(domain)/CN=client2.org" 15 | mtls_certs : 16 | openssl ecparam -name prime256v1 -genkey -noout -out mtls_ca.key 17 | openssl req -new -x509 -sha256 -key mtls_ca.key -out mtls_ca.crt -subj $(subj) 18 | openssl ecparam -name prime256v1 -genkey -noout -out mtls_server.key 19 | openssl req -new -sha256 -key mtls_server.key -out mtls_server.csr -subj $(subj) 20 | openssl x509 -req -in mtls_server.csr -CA mtls_ca.crt -CAkey mtls_ca.key -CAcreateserial -out mtls_server.crt -days 1000 -sha256 21 | 22 | openssl ecparam -name prime256v1 -genkey -noout -out mtls_client1.key 23 | openssl req -new -sha256 -key mtls_client1.key -out mtls_client1.csr -subj $(client1) 24 | openssl x509 -req -in mtls_client1.csr -CA mtls_ca.crt -CAkey mtls_ca.key -CAcreateserial -out mtls_client1.crt -days 1000 -sha256 25 | 26 | openssl ecparam -name prime256v1 -genkey -noout -out mtls_client2.key 27 | openssl req -new -sha256 -key mtls_client2.key -out mtls_client2.csr -subj $(client2) 28 | openssl x509 -req -in mtls_client2.csr -CA mtls_ca.crt -CAkey mtls_ca.key -CAcreateserial -out mtls_client2.crt -days 1000 -sha256 29 | 30 | -------------------------------------------------------------------------------- /tests/unit/pipe_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright 2021-present ScyllaDB 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using namespace seastar; 29 | 30 | static_assert(!std::is_default_constructible_v>); 31 | static_assert(!std::is_default_constructible_v>); 32 | 33 | static_assert(std::is_nothrow_move_constructible_v>); 34 | static_assert(std::is_nothrow_move_assignable_v>); 35 | 36 | static_assert(std::is_nothrow_move_constructible_v>); 37 | static_assert(std::is_nothrow_move_assignable_v>); 38 | 39 | SEASTAR_THREAD_TEST_CASE(simple_pipe_test) { 40 | seastar::pipe p(1); 41 | 42 | auto f0 = p.reader.read(); 43 | BOOST_CHECK(!f0.available()); 44 | p.writer.write(17).get(); 45 | BOOST_REQUIRE_EQUAL(*f0.get(), 17); 46 | 47 | p.writer.write(42).get(); 48 | auto f2 = p.reader.read(); 49 | BOOST_CHECK(f2.available()); 50 | BOOST_REQUIRE_EQUAL(*f2.get(), 42); 51 | } 52 | -------------------------------------------------------------------------------- /tests/unit/signal_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | /* 19 | * Copyright (C) 2014 Cloudius Systems, Ltd. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace seastar; 28 | 29 | extern "C" { 30 | #include 31 | #include 32 | #include 33 | } 34 | 35 | SEASTAR_TEST_CASE(test_sighup) { 36 | return do_with(make_lw_shared>(), false, [](auto const& p, bool& signaled) { 37 | seastar::handle_signal(SIGHUP, [p, &signaled] { 38 | signaled = true; 39 | p->set_value(); 40 | }); 41 | 42 | kill(getpid(), SIGHUP); 43 | 44 | return p->get_future().then([&] { 45 | BOOST_REQUIRE_EQUAL(signaled, true); 46 | }); 47 | }); 48 | } 49 | -------------------------------------------------------------------------------- /tests/unit/source_location_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2021 ScyllaDB 21 | */ 22 | 23 | #define BOOST_TEST_MODULE core 24 | 25 | #include 26 | 27 | #include 28 | 29 | using namespace seastar; 30 | 31 | static void test_source_location_callee(const char* ref_file, const char* ref_func, int ref_line, compat::source_location loc = compat::source_location::current()) { 32 | BOOST_REQUIRE_EQUAL(loc.file_name(), ref_file); 33 | BOOST_REQUIRE_EQUAL(loc.line(), ref_line); 34 | BOOST_REQUIRE(std::string(loc.function_name()).find(ref_func) != std::string::npos); 35 | } 36 | 37 | static void test_source_location_caller() { 38 | test_source_location_callee(__FILE__, __func__, __LINE__); 39 | } 40 | 41 | BOOST_AUTO_TEST_CASE(test_source_location) { 42 | test_source_location_caller(); 43 | } 44 | -------------------------------------------------------------------------------- /tests/unit/tmpdir.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is open source software, licensed to you under the terms 3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file 4 | * distributed with this work for additional information regarding copyright 5 | * ownership. You may not use this file except in compliance with the License. 6 | * 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | /* 20 | * Copyright (C) 2020 ScyllaDB Ltd. 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace seastar { 28 | 29 | /** 30 | * Temp dir helper for RAII usage when doing tests 31 | * in seastar threads. Will not work in "normal" mode. 32 | * Just use tmp_dir::do_with for that. 33 | */ 34 | class tmpdir { 35 | seastar::tmp_dir _tmp; 36 | public: 37 | tmpdir(tmpdir&&) = default; 38 | tmpdir(const tmpdir&) = delete; 39 | 40 | tmpdir(const sstring& name = sstring(seastar::default_tmpdir()) + "/testXXXX") { 41 | _tmp.create(std::filesystem::path(name)).get(); 42 | } 43 | ~tmpdir() { 44 | _tmp.remove().get(); 45 | } 46 | auto path() const { 47 | return _tmp.get_path(); 48 | } 49 | }; 50 | 51 | } 52 | --------------------------------------------------------------------------------