diff --git a/llvm/cmake/modules/FindLibpfm.cmake b/llvm/cmake/modules/FindLibpfm.cmake --- a/llvm/cmake/modules/FindLibpfm.cmake +++ b/llvm/cmake/modules/FindLibpfm.cmake @@ -16,6 +16,16 @@ check_include_file(perfmon/pfmlib_perf_event.h HAVE_PERFMON_PFMLIB_PERF_EVENT_H) if(HAVE_PERFMON_PERF_EVENT_H AND HAVE_PERFMON_PFMLIB_H AND HAVE_PERFMON_PFMLIB_PERF_EVENT_H) set(HAVE_LIBPFM 1) + # If the kernel is too old, we can't use it. + # 4.3 is the earliest version that has the perf_branch_entry format we need. + set(check_kernel ${LLVM_MAIN_SRC_DIR}/cmake/modules/check_kernel) + execute_process(COMMAND sh ${check_kernel} 4.3 + RESULT_VARIABLE TT_RV + OUTPUT_VARIABLE TT_OUT + OUTPUT_STRIP_TRAILING_WHITESPACE) + if( NOT TT_RV EQUAL 0) + set(HAVE_LIBPFM 0) + endif( NOT TT_RV EQUAL 0) endif() endif() endif() diff --git a/llvm/cmake/modules/check_kernel b/llvm/cmake/modules/check_kernel new file mode 100755 --- /dev/null +++ b/llvm/cmake/modules/check_kernel @@ -0,0 +1,25 @@ +#! /bin/sh +# Check whether the local kernel's version is at least a specified version. +# This is used by llvm/cmake/modules/FindLibpfm.cmake to check the format +# of perf_branch_entry struct. + +if [[ $# -ne 1 ]] ; then + echo "Usage: check_kernel " + exit -1 +fi + +UNAME_R=`(uname -r) 2>/dev/null` || UNAME_R=unknown +if [[ $UNAME_R == "unknown" ]]; then + exit 1 +fi + +VER=`echo $UNAME_R | awk -F '.' '{print $1}'` +MAJOR_VER=`echo $UNAME_R | awk -F '.' '{print $2}'` + +EXPECTED_VER=`echo $1 | awk -F '.' '{print $1}'` +EXPECTED_MAJOR_VER=`echo $1 | awk -F '.' '{print $2}'` + +if [[ ( "$VER" > "$EXPECTED_VER" ) || ( ( "$VER" == "$EXPECTED_VER" ) && !( "$EXPECTED_MAJOR_VER" > "$MAJOR_VER" ) ) ]]; then + exit 0 +fi +exit 2