Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compilation errors in the perf trampoline on older macOS versions.
18 changes: 18 additions & 0 deletions Python/perf_jit_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
# include <sys/syscall.h> // System call interface
#endif

#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) \
&& (!defined(MAC_OS_X_VERSION_10_12) || \
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12)
#define PY_PERF_JIT_USE_MACH_TIME
#include <inttypes.h>
#include <mach/mach_time.h> // mach_absolute_time
#endif
#endif

// =============================================================================
// CONSTANTS AND CONFIGURATION
// =============================================================================
Expand Down Expand Up @@ -284,6 +295,12 @@ static const intptr_t nanoseconds_per_second = 1000000000;
* Returns: Current monotonic time in nanoseconds since an arbitrary epoch
*/
static int64_t get_current_monotonic_ticks(void) {
#if defined(__APPLE__) && defined(PY_PERF_JIT_USE_MACH_TIME)
/* clock_gettime() is not available before macOS 10.12.
* mach_absolute_time() should always return a value in
* nanoseconds on x86. */
return (int64_t)mach_absolute_time();
#else
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
Py_UNREACHABLE(); // Should never fail on supported systems
Expand All @@ -295,6 +312,7 @@ static int64_t get_current_monotonic_ticks(void) {
result *= nanoseconds_per_second;
result += ts.tv_nsec;
return result;
#endif
}

/*
Expand Down
3 changes: 3 additions & 0 deletions Python/perf_trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ any DWARF information available for them).
#include <unistd.h> // sysconf()
#include <sys/time.h> // gettimeofday()

#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
# define MAP_ANONYMOUS MAP_ANON
#endif

#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
#define PY_HAVE_INVALIDATE_ICACHE
Expand Down
10 changes: 9 additions & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,10 @@ AC_MSG_CHECKING([perf trampoline])
AS_CASE([$PLATFORM_TRIPLET],
[x86_64-linux-gnu], [perf_trampoline=yes],
[aarch64-linux-gnu], [perf_trampoline=yes],
[darwin], [perf_trampoline=yes],
[darwin], AS_CASE([$host_cpu],
[p*pc*], [perf_trampoline=no],
[*], [perf_trampoline=yes]
),
[perf_trampoline=no]
)
AC_MSG_RESULT([$perf_trampoline])
Expand Down
Loading