Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions CMakeLists.txt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add some text to the readme describing these options and saying how to configure them.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ endif()
include(GNUInstallDirs)
set(CMAKE_INSTALL_LIBDIR lib)

# Options to enable/disable library support (on by default)
option(DTO_ACCEL_CONFIG_SUPPORT "Enable accel-config for automatic DSA discovery (requires libaccel-config)" ON)
option(DTO_NUMA_SUPPORT "Enable NUMA awareness support (requires libnuma)" ON)

# Options to statically link dependencies into libdto.so
option(DTO_STATIC_ACCEL_CONFIG "Statically link accel-config into libdto.so" OFF)
option(DTO_STATIC_NUMA "Statically link numa into libdto.so (requires PIC-compiled libnuma.a)" OFF)

# Build the shared library
add_library(dto SHARED dto.c)
add_library(DTO::dto ALIAS dto)
Expand All @@ -29,10 +37,62 @@ add_compile_definitions(_GNU_SOURCE)
# Add the -DDTO_STATS_SUPPORT preprocessor definition
target_compile_definitions(dto PRIVATE DTO_STATS_SUPPORT)

# Link libraries. Use PRIVATE so accel-config/numa/dl are the shared library's
# own dependencies (resolved via its DT_NEEDED) rather than INTERFACE
# Link libraries
set(DTO_STATIC_LIBS "")
set(DTO_DYNAMIC_LIBS dl)

# Handle accel-config support
if(DTO_ACCEL_CONFIG_SUPPORT)
target_compile_definitions(dto PRIVATE DTO_ACCEL_CONFIG_SUPPORT)
message(STATUS "accel-config support: enabled")

if(DTO_STATIC_ACCEL_CONFIG)
find_library(ACCEL_CONFIG_STATIC NAMES libaccel-config.a PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
if(NOT ACCEL_CONFIG_STATIC)
message(FATAL_ERROR "libaccel-config.a not found. Install static accel-config or disable DTO_STATIC_ACCEL_CONFIG.")
endif()
message(STATUS "Statically linking accel-config: ${ACCEL_CONFIG_STATIC}")
list(APPEND DTO_STATIC_LIBS ${ACCEL_CONFIG_STATIC})
else()
list(APPEND DTO_DYNAMIC_LIBS accel-config)
endif()
else()
message(STATUS "accel-config support: disabled (DTO_WQ_LIST env var required at runtime)")
endif()

# Handle numa support
if(DTO_NUMA_SUPPORT)
target_compile_definitions(dto PRIVATE DTO_NUMA_SUPPORT)
message(STATUS "NUMA support: enabled")

if(DTO_STATIC_NUMA)
find_library(NUMA_STATIC NAMES libnuma.a PATHS /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
if(NOT NUMA_STATIC)
message(FATAL_ERROR "libnuma.a not found. Install static numa or disable DTO_STATIC_NUMA.")
endif()
message(STATUS "Statically linking numa: ${NUMA_STATIC}")
message(STATUS " (Note: libnuma.a must be compiled with -fPIC)")
list(APPEND DTO_STATIC_LIBS ${NUMA_STATIC})
else()
list(APPEND DTO_DYNAMIC_LIBS numa)
endif()
else()
message(STATUS "NUMA support: disabled")
endif()

# Link everything together. Use PRIVATE so accel-config/numa/dl are the shared
# library's own dependencies (resolved via its DT_NEEDED) rather than INTERFACE
# requirements that would be forced onto every downstream consumer of DTO::dto.
target_link_libraries(dto PRIVATE dl accel-config numa)
if(DTO_STATIC_LIBS)
target_link_libraries(dto PRIVATE
-Wl,--whole-archive
${DTO_STATIC_LIBS}
-Wl,--no-whole-archive
${DTO_DYNAMIC_LIBS}
)
else()
target_link_libraries(dto PRIVATE ${DTO_DYNAMIC_LIBS})
endif()

include(CheckCCompilerFlag)
check_c_compiler_flag("-mwaitpkg" HAS_WAITPKG)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Comment thread
byrnedj marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ all: libdto dto-test-wodto
DML_LIB_CXX=-D_GNU_SOURCE

libdto: dto.c
gcc -shared -fPIC -Wl,-soname,libdto.so dto.c $(DML_LIB_CXX) -DDTO_STATS_SUPPORT -o libdto.so.1.0 -laccel-config -ldl -lnuma -mwaitpkg
gcc -shared -fPIC -Wl,-soname,libdto.so dto.c $(DML_LIB_CXX) -DDTO_STATS_SUPPORT -DDTO_ACCEL_CONFIG_SUPPORT -DDTO_NUMA_SUPPORT -o libdto.so.1.0 -laccel-config -ldl -lnuma -mwaitpkg

libdto_nostats: dto.c
gcc -shared -fPIC -Wl,-soname,libdto.so dto.c $(DML_LIB_CXX) -o libdto.so.1.0 -laccel-config -ldl -lnuma -mwaitpkg
gcc -shared -fPIC -Wl,-soname,libdto.so dto.c $(DML_LIB_CXX) -DDTO_ACCEL_CONFIG_SUPPORT -DDTO_NUMA_SUPPORT -o libdto.so.1.0 -laccel-config -ldl -lnuma -mwaitpkg

install:
cp libdto.so.1.0 /usr/lib64/
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ Following environment variables control the behavior of DTO library:
DTO_CPU_SIZE_FRACTION=0.xx (specifies fraction of job performed by CPU, in parallel to DSA). Default is 0.00
DTO_AUTO_ADJUST_KNOBS=0/1 (disables/enables auto tuning of cpu_size_fraction and dsa_min_bytes parameters. 0 -- disable, 1 -- enable (default))
DTO_IS_NUMA_AWARE=0/1/2 (disables/buffer-centric/cpu-centric numa awareness. 0 -- disable (default), 1 -- buffer-centric, 2 - cpu-centric)
Only available when DTO is built with NUMA support (see Build options).
DTO_WQ_LIST="semi-colon(;) separated list of DSA WQs to use". The WQ names should match their names in /dev/dsa/ directory (see example below).
If not specified, DTO will try to auto-discover and use all available WQs.
If not specified, DTO will try to auto-discover and use all available WQs. Auto-discovery requires DTO to be
built with accel-config support (see Build options); otherwise DTO_WQ_LIST is mandatory.
DTO_DSA_MEMCPY=0/1, 1 (default) - DTO uses DSA to process memcpy, 0 - DTO uses system memcpy
DTO_DSA_MEMMOVE=0/1, 1 (default) - DTO uses DSA to process memmove, 0 - DTO uses system memmove
DTO_DSA_MEMSET=0/1, 1 (default) - DTO uses DSA to process memset, 0 - DTO use system memset
Expand Down Expand Up @@ -103,13 +105,36 @@ On Fedora/CentOS/Rhel: kernel-headers, accel-config-devel, libuuid-devel, libnum

On Ubuntu/Debian: linux-libc-dev, libaccel-config-dev, uuid-dev, libnuma-dev

The accel-config and numa packages are only required when the corresponding build options are enabled (they are enabled by default, see [Build options](#build-options) below).

### CMake ###
```bash
cmake -B build
cmake --build build -j
sudo cmake --install build
```

#### Build options ####

The accel-config and libnuma dependencies are optional and can be disabled at configure time:

| Option | Default | Description |
| --- | --- | --- |
| `DTO_ACCEL_CONFIG_SUPPORT` | `ON` | Use libaccel-config to auto-discover configured DSA work queues. When disabled, libdto does not link against libaccel-config, and the `DTO_WQ_LIST` environment variable **must** be set at runtime (e.g., `export DTO_WQ_LIST="wq0.0;wq1.0"`) since auto-discovery is unavailable. |
| `DTO_NUMA_SUPPORT` | `ON` | Use libnuma for NUMA-aware work queue selection. When disabled, libdto does not link against libnuma and the `DTO_IS_NUMA_AWARE` environment variable has no effect (work queues are used in round-robin order). |
| `DTO_STATIC_ACCEL_CONFIG` | `OFF` | Statically link libaccel-config into libdto.so instead of depending on the shared library at runtime. Requires `libaccel-config.a` to be installed. |
| `DTO_STATIC_NUMA` | `OFF` | Statically link libnuma into libdto.so instead of depending on the shared library at runtime. Requires a `libnuma.a` compiled with `-fPIC`. |

Example: build without either dependency:
```bash
cmake -B build -DDTO_ACCEL_CONFIG_SUPPORT=OFF -DDTO_NUMA_SUPPORT=OFF
cmake --build build -j
```

The deprecated Makefile always builds with both features enabled (it passes
`-DDTO_ACCEL_CONFIG_SUPPORT -DDTO_NUMA_SUPPORT` to the compiler); use CMake if
you need to build without them.

The CMake build also produces the test applications in the build directory:
`dto-test` (for the -ldto method) and `dto-test-wodto` (for the LD_PRELOAD method).

Expand Down
Loading