[all-commits] [llvm/llvm-project] d91284: [libomp] Set `KMP_USE_YIELD=2` when `OMP_WAIT_POLI...

Ryotaro Kasuga via All-commits all-commits at lists.llvm.org
Mon Sep 7 17:17:54 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d91284c7f5747ade780b944ef9d4cb6d8bfbbc1e
      https://github.com/llvm/llvm-project/commit/d91284c7f5747ade780b944ef9d4cb6d8bfbbc1e
  Author: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
  Date:   2026-09-08 (Tue, 08 Sep 2026)

  Changed paths:
    M openmp/runtime/src/kmp_settings.cpp

  Log Message:
  -----------
  [libomp] Set `KMP_USE_YIELD=2` when `OMP_WAIT_POLICY=active` if it's not specified explicitly (#199628)

This patch sets `KMP_USE_YIELD=0` when `OMP_WAIT_POLICY=active` and
`KMP_USE_YIELD` is not explicitly set by the user. This is the same as
the value of `KMP_BLOCKTIME` is set to infinite when `KMP_BLOCKTIME` is
not explicitly set and `OMP_WAIT_POLICY=active`.

### Background

`KMP_USE_YIELD` is an environment variable for libomp to control the
behavior of threads when they are idle. We can specify 0, 1, or 2 as the
value of `KMP_USE_YIELD`. As I read the code, the behavior is as
follows:

- `KMP_USE_YIELD=0`: Threads will NOT yield the CPU when they are idle.
- `KMP_USE_YIELD=1`: Threads will yield the CPU when they are idle.
- `KMP_USE_YIELD=2`: Threads will yield the CPU when they are idle if we
are oversubscribed (i.e., more threads than CPU cores).

The default value of `KMP_USE_YIELD` is 1, which means that threads will
yield the CPU when they are idle.

On the other hand, there is an environment variable `OMP_WAIT_POLICY`
that controls the waiting behavior of threads in OpenMP. The OpenMP 6.0
Specification
(https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-6-0.pdf)
states as follows:

> The active value specifies that waiting native threads should mostly
be active, consuming processor cycles, while waiting. A compliant
implementation may, for example, make waiting native threads spin.

Therefore, I think it is more consistent to set `KMP_USE_YIELD=2` when
`OMP_WAIT_POLICY=active`.
Note: Using `KMP_USE_YIELD=2` instead of 0 here to avoid hanging when
oversubscribed.

### Performance

To confirm the effect of this patch, I ran SPEC CPU 2017 with several
configurations, including with and without this patch. As a result, I
observed that the performance of some benchmarks improved significantly
with this patch. Also I didn't see any performance degradation. Here are
the details of the performance improvements:

- Machine: Neoverse V2 (Grace, binding 64 threads to 64 cores)
- Configuration: `OMP_WAIT_POLICY=active OMP_NUM_THREADS=64`

| Benchmark | Performance Improvement |
|-|-|
| 621.wrf_s | 2.6x |
| 628.pop2_s | 5.5x |

---

In conclusion, I think it's reasonable to set `KMP_USE_YIELD=0` (or 2)
by default when `OMP_WAIT_POLICY=active` is specified, when the user
likely expects the threads to be active while waiting.

Resolve #181784.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list