]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add WITH_QATLIB to build against qatlib
authorCasey Bodley <cbodley@redhat.com>
Fri, 24 Nov 2023 17:23:57 +0000 (12:23 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 7 Feb 2024 15:37:47 +0000 (10:37 -0500)
FindQAT.cmake adds library targets QAT::qat and QAT::usdm for qatlib,
and FindQatDrv.cmake adds alias targets to the same

src/compressor and src/crypto/qat link against these common QAT targets

src/crypto/qat/qcccrypto.h uses new HAVE_QATDRV define to determine
which headers to include

Signed-off-by: Casey Bodley <cbodley@redhat.com>
CMakeLists.txt
cmake/modules/FindQAT.cmake [new file with mode: 0644]
cmake/modules/FindQatDrv.cmake
src/compressor/CMakeLists.txt
src/crypto/CMakeLists.txt
src/crypto/qat/CMakeLists.txt
src/crypto/qat/qcccrypto.cc
src/crypto/qat/qcccrypto.h

index 50c8905ca0a00fb0adbf2589b528a165dadd8f98..213c6b6947311262a2ef77dee1ee16e7938e3b51 100644 (file)
@@ -307,10 +307,15 @@ endif()
 
 option(WITH_BLUEFS "libbluefs library" OFF)
 
+option(WITH_QATLIB "Enable QAT with qatlib" OFF)
 option(WITH_QATDRV "Enable QAT with out-of-tree driver" OFF)
+
 if(WITH_QATDRV)
   find_package(QatDrv REQUIRED COMPONENTS qat_s usdm_drv_s)
-  set(HAVE_QATDRV TRUE)
+  set(HAVE_QAT TRUE)
+elseif(WITH_QATLIB)
+  find_package(QAT REQUIRED)
+  set(HAVE_QAT TRUE)
 endif()
 
 option(WITH_QATZIP "Enable QATZIP" OFF)
diff --git a/cmake/modules/FindQAT.cmake b/cmake/modules/FindQAT.cmake
new file mode 100644 (file)
index 0000000..9044e54
--- /dev/null
@@ -0,0 +1,40 @@
+find_package(PkgConfig)
+pkg_search_module(PC_QAT libqat qatlib QUIET)
+
+find_path(QAT_INCLUDE_DIR
+  NAMES qat/cpa.h
+  HINTS ${PC_QAT_INCLUDE_DIRS})
+
+find_library(QAT_LIBRARY
+  NAMES qat
+  HINTS ${PC_QAT_LIBRARY_DIRS})
+
+find_library(QAT_USDM_LIBRARY
+  NAMES usdm
+  HINTS ${PC_QAT_LIBRARY_DIRS})
+
+set(QAT_VERSION ${PC_QAT_VERSION})
+set(QAT_LIBRARIES ${QAT_LIBRARY} ${QAT_USDM_LIBRARY})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(QAT
+  REQUIRED_VARS QAT_LIBRARY QAT_USDM_LIBRARY QAT_INCLUDE_DIR
+  VERSION_VAR QAT_VERSION)
+
+mark_as_advanced(QAT_LIBRARY QAT_USDM_LIBRARY QAT_LIBRARIES QAT_INCLUDE_DIR QAT_VERSION)
+
+if(QAT_FOUND AND NOT (TARGET QAT::qat))
+  add_library(QAT::qat UNKNOWN IMPORTED)
+  set_target_properties(QAT::qat PROPERTIES
+    INTERFACE_INCLUDE_DIRECTORIES "${QAT_INCLUDE_DIR}"
+    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+    IMPORTED_LOCATION "${QAT_LIBRARY}")
+endif()
+
+if(QAT_FOUND AND NOT (TARGET QAT::usdm))
+  add_library(QAT::usdm UNKNOWN IMPORTED)
+  set_target_properties(QAT::usdm PROPERTIES
+    INTERFACE_INCLUDE_DIRECTORIES "${QAT_INCLUDE_DIR}"
+    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+    IMPORTED_LOCATION "${QAT_USDM_LIBRARY}")
+endif()
index 3305a38c06cb958840a021eb4e668a93e58c508a..e2849d9c89becb141e4b54af88d3619a526cc797 100644 (file)
@@ -74,7 +74,15 @@ foreach(component ${QatDrv_FIND_COMPONENTS})
     add_library(QatDrv::${component} STATIC IMPORTED GLOBAL)
     set_target_properties(QatDrv::${component} PROPERTIES
                           INTERFACE_INCLUDE_DIRECTORIES "${QatDrv_INCLUDE_DIRS}"
+                          INTERFACE_COMPILE_OPTIONS "-DHAVE_QATDRV"
                           IMPORTED_LINK_INTERFACE_LANGUAGES "C"
                           IMPORTED_LOCATION "${QatDrv_${component}_LIBRARIES}")
   endif()
+
+  # add alias targets to match FindQAT.cmake
+  if(component STREQUAL "qat_s")
+    add_library(QAT::qat ALIAS QatDrv::qat_s)
+  elseif(component STREQUAL "usdm_drv_s")
+    add_library(QAT::usdm ALIAS QatDrv::usdm_drv_s)
+  endif()
 endforeach()
index 3e99f8b73875894ce9ee509926b8aa29072815bb..1f9cab5f3c7086b4a12ba58875c67bad04cdfe84 100644 (file)
@@ -6,10 +6,10 @@ if (HAVE_QATZIP)
 endif()
 add_library(compressor_objs OBJECT ${compressor_srcs})
 add_dependencies(compressor_objs common-objs)
-if(HAVE_QATZIP AND HAVE_QATDRV)
+if(HAVE_QATZIP AND HAVE_QAT)
   target_link_libraries(compressor_objs PRIVATE
-                        QatDrv::qat_s
-                        QatDrv::usdm_drv_s
+                        QAT::qat
+                        QAT::usdm
                         qatzip::qatzip
                        )
 endif()
index 33daee114821d056c6c46c896b7cd2eb05dced6c..d1ba381999f2b97aa7bcb87336f855abe82c665b 100644 (file)
@@ -7,6 +7,6 @@ if(HAVE_INTEL AND HAVE_NASM_X64_AVX2 AND (NOT APPLE))
   add_subdirectory(isa-l)
 endif()
 
-if(WITH_QATDRV)
+if(HAVE_QAT)
   add_subdirectory(qat)
 endif()
index 77791cacf79b386d5864ded4dbecf42a3ffc2180..04bc0b7e7f4309fe037a367d100acc7cbdaaf336 100644 (file)
@@ -12,8 +12,8 @@ add_library(ceph_crypto_qat SHARED ${qat_crypto_plugin_srcs})
 add_dependencies(crypto_plugins ceph_crypto_qat)
 
 target_link_libraries(ceph_crypto_qat PRIVATE
-                      QatDrv::qat_s
-                      QatDrv::usdm_drv_s
+                      QAT::qat
+                      QAT::usdm
                       spawn)
 
 add_dependencies(crypto_plugins ceph_crypto_qat)
index 6110e28c7921bb250d4cadf30b5751b3907ce19f..56681c74517cff0e27947df24d3aab79011ad7c6 100644 (file)
@@ -88,7 +88,9 @@ void QccCrypto::QccFreeInstance(int entry) {
 
 void QccCrypto::cleanup() {
   icp_sal_userStop();
+#ifdef HAVE_QATDRV
   qaeMemDestroy();
+#endif
   is_init = false;
   init_called = false;
   derr << "Failure during QAT init sequence. Quitting" << dendl;
@@ -139,6 +141,7 @@ bool QccCrypto::init(const size_t chunk_size, const size_t max_requests) {
   dout(15) << "First init for QAT" << dendl;
   init_called = true;
 
+#ifdef HAVE_QATDRV
   // Find if the usermode memory driver is available. We need to this to
   // create contiguous memory needed by QAT.
   stat = qaeMemInit();
@@ -147,7 +150,7 @@ bool QccCrypto::init(const size_t chunk_size, const size_t max_requests) {
     this->cleanup();
     return false;
   }
-
+#endif
   stat = icp_sal_userStart("CEPH");
   if (stat != CPA_STATUS_SUCCESS) {
     derr << "Unable to start qat device" << dendl;
@@ -300,7 +303,9 @@ bool QccCrypto::destroy() {
 
   //Un-init memory driver and QAT HW
   icp_sal_userStop();
+#ifdef HAVE_QATDRV
   qaeMemDestroy();
+#endif
   init_called = false;
   is_init = false;
   return true;
index 973688fbf0c5540549f2cd2d155b4dcb52254cd3..cd17a909e2d6913ead93208b2685cff2ce2868c0 100644 (file)
@@ -20,6 +20,7 @@
 #include <boost/asio/thread_pool.hpp>
 #include <boost/asio/use_future.hpp>
 extern "C" {
+#ifdef HAVE_QATDRV
 #include "cpa.h"
 #include "cpa_cy_sym_dp.h"
 #include "cpa_cy_im.h"
@@ -29,6 +30,15 @@ extern "C" {
 #include "icp_sal_user.h"
 #include "icp_sal_poll.h"
 #include "qae_mem_utils.h"
+#else
+#include <qat/cpa.h>
+#include <qat/cpa_cy_im.h>
+#include <qat/cpa_cy_sym_dp.h>
+#include <qat/cpa_cy_sym.h>
+#include <qat/qae_mem.h>
+#include <qat/icp_sal_user.h>
+#include <qat/icp_sal_poll.h>
+#endif
 }
 
 class QccCrypto {