ext/iodine/fio.c
/**
 * Returns the number of expected threads / processes to be used by facil.io.
 *
 * The pointers should start with valid values that match the expected threads /
 * processes values passed to `fio_run`.
 *
 * The data in the pointers will be overwritten with the result.
 */
Returns the number of expected threads / processes to be used by facil.io.
The pointers should start with valid values that match the expected threads
processes values passed to `fio_run`.

The data in the pointers will be overwritten with the result.
Returns the number of expected threads / processes to be used by facil . io . The pointers should start with valid values that match the expected threads processes values passed to ` fio_run ` . The data in the pointers will be overwritten with the result .
void fio_expected_concurrency(int16_t *threads, int16_t *processes) {
  if (!threads || !processes)
    return;
  if (!*threads && !*processes) {
    ssize_t cpu_count = fio_detect_cpu_cores();
#if FIO_CPU_CORES_LIMIT
    if (cpu_count > FIO_CPU_CORES_LIMIT) {
      static int print_cores_warning = 1;
      if (print_cores_warning) {
        FIO_LOG_WARNING(
            "Detected %zu cores. Capping auto-detection of cores to %zu.\n"
            "      Avoid this message by setting threads / workers manually.\n"
            "      To increase auto-detection limit, recompile with:\n"
            "             -DFIO_CPU_CORES_LIMIT=%zu",
            (size_t)cpu_count, (size_t)FIO_CPU_CORES_LIMIT, (size_t)cpu_count);
        print_cores_warning = 0;
      }
      cpu_count = FIO_CPU_CORES_LIMIT;
    }
#endif
    *threads = *processes = (int16_t)cpu_count;
    if (cpu_count > 3) {
      --(*processes);
    }
  } else if (*threads < 0 || *processes < 0) {
    ssize_t cpu_count = fio_detect_cpu_cores();
    size_t thread_cpu_adjust = (*threads <= 0 ? 1 : 0);
    size_t worker_cpu_adjust = (*processes <= 0 ? 1 : 0);
    if (cpu_count > 0) {
      int16_t tmp = 0;
      if (*threads < 0)
        tmp = (int16_t)(cpu_count / (*threads * -1));
      else if (*threads == 0) {
        tmp = -1 * *processes;
        thread_cpu_adjust = 0;
      } else
        tmp = *threads;
      if (*processes < 0)
        *processes = (int16_t)(cpu_count / (*processes * -1));
      else if (*processes == 0) {
        *processes = -1 * *threads;
        worker_cpu_adjust = 0;
      }
      *threads = tmp;
      tmp = *processes;
      if (worker_cpu_adjust && (*processes * *threads) >= cpu_count &&
          cpu_count > 3) {
        --*processes;
      }
      if (thread_cpu_adjust && (*threads * tmp) >= cpu_count && cpu_count > 3) {
        --*threads;
      }
    }
  }
  if (*processes <= 0)
    *processes = 1;
  if (*threads <= 0)
    *threads = 1;
}
void fio_expected_concurrency ( int16_t * threads , int16_t * processes ) { if ( ! threads || ! processes ) return ; if ( ! * threads && ! * processes ) { ssize_t cpu_count = fio_detect_cpu_cores ( ) ; #if FIO_CPU_CORES_LIMIT if ( cpu_count > FIO_CPU_CORES_LIMIT ) { static int print_cores_warning = 1 ; if ( print_cores_warning ) { FIO_LOG_WARNING ( " \n " " \n " " \n " " " , ( size_t ) cpu_count , ( size_t ) FIO_CPU_CORES_LIMIT , ( size_t ) cpu_count ) ; print_cores_warning = 0 ; } cpu_count = FIO_CPU_CORES_LIMIT ; } #endif * threads = * processes = ( int16_t ) cpu_count ; if ( cpu_count > 3 ) { -- ( * processes ) ; } } else if ( * threads < 0 || * processes < 0 ) { ssize_t cpu_count = fio_detect_cpu_cores ( ) ; size_t thread_cpu_adjust = ( * threads <= 0 ? 1 : 0 ) ; size_t worker_cpu_adjust = ( * processes <= 0 ? 1 : 0 ) ; if ( cpu_count > 0 ) { int16_t tmp = 0 ; if ( * threads < 0 ) tmp = ( int16_t ) ( cpu_count / ( * threads * -1 ) ) ; else if ( * threads == 0 ) { tmp = -1 * * processes ; thread_cpu_adjust = 0 ; } else tmp = * threads ; if ( * processes < 0 ) * processes = ( int16_t ) ( cpu_count / ( * processes * -1 ) ) ; else if ( * processes == 0 ) { * processes = -1 * * threads ; worker_cpu_adjust = 0 ; } * threads = tmp ; tmp = * processes ; if ( worker_cpu_adjust && ( * processes * * threads ) >= cpu_count && cpu_count > 3 ) { -- * processes ; } if ( thread_cpu_adjust && ( * threads * tmp ) >= cpu_count && cpu_count > 3 ) { -- * threads ; } } } if ( * processes <= 0 ) * processes = 1 ; if ( * threads <= 0 ) * threads = 1 ; }
Returns the number of expected threads / processes to be used by facil.io.
Returns the number of expected threads / processes to be used by facil . io .
/* both options set to 0 - default to cores*cores matrix */ /* leave a core available for the kernel */ /* Set any option that is less than 0 be equal to cores/value */ /* Set any option equal to 0 be equal to the other option in value */ /* leave a resources available for the kernel */ /* leave a resources available for the kernel */ /* make sure we have at least one process and at least one thread */