]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: Intelligently set job limits for sccache 56865/head
authorZack Cerza <zack@redhat.com>
Thu, 4 Apr 2024 19:01:05 +0000 (13:01 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 6 May 2024 20:03:14 +0000 (14:03 -0600)
If we are correctly configured for distributed mode, use the cluster's CPU count
instead of ours. If we are configured for sccache but without distributed mode,
inform the user but continue with normal job limits.

Signed-off-by: Zack Cerza <zack@redhat.com>
CMakeLists.txt
cmake/modules/LimitJobs.cmake

index b2a9334a5cfef95388159b8aac4b9c25a9f767bf..5f989e0a8401dc48bf813a5bf134a36b04ea5d8f 100644 (file)
@@ -85,17 +85,36 @@ endif(WITH_CCACHE)
 
 option(WITH_SCCACHE "Build with sccache.")
 if(WITH_SCCACHE)
-  if(CMAKE_C_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER_LAUNCHER)
-    message(WARNING "Compiler launcher already set. stop configuring sccache")
-  else()
-    find_program(SCCACHE_EXECUTABLE sccache)
-    if(NOT SCCACHE_EXECUTABLE)
-      message(FATAL_ERROR "Can't find sccache. Is it installed?")
+  find_program(SCCACHE_EXECUTABLE sccache)
+  if(NOT SCCACHE_EXECUTABLE)
+    message(FATAL_ERROR "Can't find sccache. Is it installed?")
+  endif()
+  if(NOT NINJA_MAX_COMPILE_JOBS)
+    if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
+      execute_process(
+        COMMAND "sccache" "--dist-status"
+        OUTPUT_VARIABLE sccache_dist_status
+      )
+      string(
+        JSON sccache_cores
+        ERROR_VARIABLE sccache_dist_status_error
+        GET "${sccache_dist_status}" SchedulerStatus 1 num_cpus
+      )
+      string(FIND "${sccache_dist_status}" "disabled" find_result)
+      if(find_result EQUAL -1)
+        message(STATUS "Using sccache with distributed compilation. Effective cores: ${sccache_cores}")
+        set(NINJA_MAX_COMPILE_JOBS ${sccache_cores})
+        set(NINJA_MAX_LINK_JOBS ${sccache_cores})
+      else()
+        message(WARNING "Using sccache, but it is not configured for distributed complilation")
+      endif()
+    else()
+      message(WARNING "Using sccache, but cannot determine maximum job value since cmake version is <3.19")
     endif()
-    message(STATUS "Building with sccache: ${SCCACHE_EXECUTABLE}, SCCACHE_CONF=$ENV{SCCACHE_CONF}")
-    set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
-    set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
   endif()
+  message(STATUS "Building with sccache: ${SCCACHE_EXECUTABLE}, SCCACHE_CONF=$ENV{SCCACHE_CONF}")
+  set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
+  set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_EXECUTABLE})
 endif(WITH_SCCACHE)
 
 option(WITH_MANPAGE "Build man pages." ON)
index 591a9321b668de8c712c71e32b24b4bc2c265013..2dcad24a806ada21d022002ffebea09e87578f14 100644 (file)
@@ -4,16 +4,20 @@ set(MAX_LINK_MEM 4500 CACHE INTERNAL "maximum memory used by each linking job (i
 cmake_host_system_information(RESULT _num_cores QUERY NUMBER_OF_LOGICAL_CORES)
 cmake_host_system_information(RESULT _total_mem QUERY TOTAL_PHYSICAL_MEMORY)
 
-math(EXPR _avg_compile_jobs "${_total_mem} / ${MAX_COMPILE_MEM}")
-if(_avg_compile_jobs EQUAL 0)
-  set(_avg_compile_jobs 1)
-endif()
-if(_num_cores LESS _avg_compile_jobs)
-  set(_avg_compile_jobs ${_num_cores})
+if(NINJA_MAX_COMPILE_JOBS)
+  set(_avg_compile_jobs "${NINJA_MAX_COMPILE_JOBS}")
+else()
+  math(EXPR _avg_compile_jobs "${_total_mem} / ${MAX_COMPILE_MEM}")
+  if(_avg_compile_jobs EQUAL 0)
+    set(_avg_compile_jobs 1)
+  endif()
+  if(_num_cores LESS _avg_compile_jobs)
+    set(_avg_compile_jobs "${_num_cores}")
+  endif()
+  set(NINJA_MAX_COMPILE_JOBS "${_avg_compile_jobs}" CACHE STRING
+    "The maximum number of concurrent compilation jobs, for Ninja build system." FORCE)
+  mark_as_advanced(NINJA_MAX_COMPILE_JOBS)
 endif()
-set(NINJA_MAX_COMPILE_JOBS "${_avg_compile_jobs}" CACHE STRING
-  "The maximum number of concurrent compilation jobs, for Ninja build system." FORCE)
-mark_as_advanced(NINJA_MAX_COMPILE_JOBS)
 if(NINJA_MAX_COMPILE_JOBS)
   math(EXPR _heavy_compile_jobs "${_avg_compile_jobs} / 2")
   if(_heavy_compile_jobs EQUAL 0)
@@ -25,16 +29,20 @@ if(NINJA_MAX_COMPILE_JOBS)
   set(CMAKE_JOB_POOL_COMPILE avg_compile_job_pool)
 endif()
 
-math(EXPR _avg_link_jobs "${_total_mem} / ${MAX_LINK_MEM}")
-if(_avg_link_jobs EQUAL 0)
-  set(_avg_link_jobs 1)
-endif()
-if(_num_cores LESS _avg_link_jobs)
-  set(_avg_link_jobs ${_num_cores})
+if(NINJA_MAX_LINK_JOBS)
+  set(_avg_link_jobs "${NINJA_MAX_LINK_JOBS}")
+else()
+  math(EXPR _avg_link_jobs "${_total_mem} / ${MAX_LINK_MEM}")
+  if(_avg_link_jobs EQUAL 0)
+    set(_avg_link_jobs 1)
+  endif()
+  if(_num_cores LESS _avg_link_jobs)
+    set(_avg_link_jobs "${_num_cores}")
+  endif()
+  set(NINJA_MAX_LINK_JOBS "${_avg_link_jobs}" CACHE STRING
+    "The maximum number of concurrent link jobs, for Ninja build system." FORCE)
+  mark_as_advanced(NINJA_MAX_LINK_JOBS)
 endif()
-set(NINJA_MAX_LINK_JOBS "${_avg_link_jobs}" CACHE STRING
-  "The maximum number of concurrent link jobs, for Ninja build system." FORCE)
-mark_as_advanced(NINJA_MAX_LINK_JOBS)
 if(NINJA_MAX_LINK_JOBS)
   math(EXPR _heavy_link_jobs "${_avg_link_jobs} / 2")
   if(_heavy_link_jobs EQUAL 0)