cpu_affinity_posix.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_CPU_AFFINITY_POSIX_H_
  5. #define BASE_CPU_AFFINITY_POSIX_H_
  6. #include "base/process/process_handle.h"
  7. #include "base/threading/platform_thread.h"
  8. namespace base {
  9. enum class CpuAffinityMode {
  10. // No restrictions on affinity.
  11. kDefault,
  12. // Restrict execution to LITTLE cores only. Only has an effect on platforms
  13. // where we detect presence of big.LITTLE-like CPU architectures.
  14. kLittleCoresOnly
  15. };
  16. // Sets or clears restrictions on the CPU affinity of the specified thread.
  17. // Returns false if updating the affinity failed.
  18. BASE_EXPORT bool SetThreadCpuAffinityMode(PlatformThreadId thread_id,
  19. CpuAffinityMode affinity);
  20. // Like SetThreadAffinityMode, but affects all current and future threads of
  21. // the given process. Note that this may not apply to threads that are created
  22. // in parallel to the execution of this function.
  23. BASE_EXPORT bool SetProcessCpuAffinityMode(ProcessHandle process_handle,
  24. CpuAffinityMode affinity);
  25. // Return true if the current architecture has big or bigger cores.
  26. BASE_EXPORT bool HasBigCpuCores();
  27. // For architectures with big cores, return the affinity mode that matches
  28. // the CPU affinity of the current thread. If no affinity mode exactly matches,
  29. // or if the architecture doesn't have different types of cores,
  30. // return nullopt.
  31. BASE_EXPORT base::Optional<CpuAffinityMode> CurrentThreadCpuAffinityMode();
  32. } // namespace base
  33. #endif // BASE_CPU_AFFINITY_POSIX_H_