-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the spinloop pause / yield hint
Unfortunately, C still lacks a standard function for pause (x86, sparc) or yeild (arm) instructions, for use in spin lock or CAS loops. BIND has its own based on vendor intrinsics or inline asm. Previously, it was buried in the `isc_rwlock` implementation. This commit renames `isc_rwlock_pause()` to `isc_pause()` and moves it into <isc/pause.h>. This commit also fixes the configure script so that it detects ARM yield support on systems that identify as `aarch*` instead of `arm*`. On 64-bit ARM systems we now use the ISB (instruction synchronization barrier) instruction in preference to yield. The ISB instruction pauses the CPU for longer, several nanoseconds, which is more like the x86 pause instruction. There are more details in a Rust pull request, which also refers to MySQL making the same change: rust-lang/rust#84725
- Loading branch information
Showing
5 changed files
with
50 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC") | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See the COPYRIGHT file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if defined(__x86_64__) | ||
#include <immintrin.h> | ||
#define isc_pause() _mm_pause() | ||
#elif defined(__i386__) | ||
#define isc_pause() __asm__ __volatile__("rep; nop") | ||
#elif defined(__ia64__) | ||
#define isc_pause() __asm__ __volatile__("hint @pause") | ||
#elif defined(__aarch64__) | ||
#define isc_pause() __asm__ __volatile__("isb") | ||
#elif defined(__arm__) && HAVE_ARM_YIELD | ||
#define isc_pause() __asm__ __volatile__("yield") | ||
#elif defined(sun) && (defined(__sparc) || defined(__sparc__)) | ||
#include <synch.h> | ||
#define isc_pause() smt_pause() | ||
#elif (defined(__sparc) || defined(__sparc__)) && HAVE_SPARC_PAUSE | ||
#define isc_pause() __asm__ __volatile__("pause") | ||
#elif defined(__ppc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || \ | ||
defined(_ARCH_PWR2) || defined(_POWER) | ||
#define isc_pause() __asm__ volatile("or 27,27,27") | ||
#else | ||
#define isc_pause() sched_yield() | ||
#endif | ||
|
||
#define isc_pause_n(iters) \ | ||
for (size_t __pause = 0; __pause < iters; __pause++) { \ | ||
isc_pause(); \ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters