From 58ee8fea5ffd5c65a77a94ce1c434bd6e8eb2efa Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 27 Apr 2015 10:57:34 -0400 Subject: [PATCH] Fix: discover Debian API Signed-off-by: Mathieu Desnoyers --- Makefile | 12 ++++++--- Makefile.ABI.workarounds | 11 ++++++++ abi-debian-version.sh | 30 ++++++++++++++++++++++ instrumentation/events/lttng-module/kmem.h | 3 ++- lib/Makefile | 4 +++ lttng-kernel-version.h | 14 ++++++++++ probes/Makefile | 4 +++ 7 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 Makefile.ABI.workarounds create mode 100755 abi-debian-version.sh diff --git a/Makefile b/Makefile index 07d9d72e..52773869 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ ifneq ($(KERNELRELEASE),) ifneq ($(CONFIG_TRACEPOINTS),) +KERNELDIR=${LTTNG_KERNELDIR} + lttng_check_linux_version = $(shell pwd)/include/linux/version.h lttng_check_generated_linux_version = $(shell pwd)/include/generated/uapi/linux/version.h @@ -19,6 +21,8 @@ $(error Duplicate version.h files found in $(lttng_check_linux_version) and $(lt endif endif +include $(KBUILD_EXTMOD)/Makefile.ABI.workarounds + obj-m += lttng-ring-buffer-client-discard.o obj-m += lttng-ring-buffer-client-overwrite.o obj-m += lttng-ring-buffer-metadata-client.o @@ -69,14 +73,14 @@ else # KERNELRELEASE CFLAGS = $(EXTCFLAGS) default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules + LTTNG_KERNELDIR=$(KERNELDIR) $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install + LTTNG_KERNELDIR=$(KERNELDIR) $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install clean: - $(MAKE) -C $(KERNELDIR) M=$(PWD) clean + LTTNG_KERNELDIR=$(KERNELDIR) $(MAKE) -C $(KERNELDIR) M=$(PWD) clean %.i: %.c - $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ + LTTNG_KERNELDIR=$(KERNELDIR) $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ endif # KERNELRELEASE diff --git a/Makefile.ABI.workarounds b/Makefile.ABI.workarounds new file mode 100644 index 00000000..f00340c9 --- /dev/null +++ b/Makefile.ABI.workarounds @@ -0,0 +1,11 @@ +# Work-around for distro-specific public modules ABI breakages. +# Some distributions break the public module instrumentation ABI +# compared to upstream stable kernels without providing other mean than +# the kernel EXTRAVERSION to figure it out. Translate this information +# into a define visible from the C preprocessor. + +DEB_API_VERSION=$(shell $(KBUILD_EXTMOD)/abi-debian-version.sh $(KERNELDIR)) + +ifneq ($(DEB_API_VERSION), 0) +ccflags-y += -DDEBIAN_API_VERSION=$(DEB_API_VERSION) +endif diff --git a/abi-debian-version.sh b/abi-debian-version.sh new file mode 100755 index 00000000..a864a211 --- /dev/null +++ b/abi-debian-version.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# First argument is the path to the kernel headers. +KPATH=$1 + +if [ ! -f ${KPATH}/include/generated/package.h ]; then + echo 0 + exit 0 +fi + +# Debian snippet courtesy of Ben Hutchings + +# Assuming KPATH is the target kernel headers directory +DEB_PACKAGE_VERSION=$(sed -rn 's/^#define LINUX_PACKAGE_ID " Debian (.*)"/\1/p' ${KPATH}/include/generated/package.h) +# Ignore backports part +DEB_PACKAGE_VERSION=$(echo ${DEB_PACKAGE_VERSION} | sed -r 's/~(bpo|deb).*//') +# Get -ckt update number, if present +KERNEL_CKT_UPDATE=$(echo ${DEB_PACKAGE_VERSION} | sed -rn 's/^[0-9]+\.[0-9]+\.[0-9]+-ckt([0-9]+).*/\1/p') +test -n "${KERNEL_CKT_UPDATE}" || KERNEL_CKT_UPDATE=0 +# Get package revision +DEB_PACKAGE_REVISION=$(echo ${DEB_PACKAGE_VERSION} | sed -r 's/.*-([^-]+)$/\1/') +# Get non-sec update number +DEB_PACKAGE_REVISION_BASE=$(echo ${DEB_PACKAGE_REVISION} | sed -r 's/^([0-9]+).*/\1/') +# Get security update number, if present +DEB_PACKAGE_REVISION_SECURITY=$(echo ${DEB_PACKAGE_REVISION} | sed -rn 's/.*\+(squeeze|deb[0-9])+u([0-9]+)$/\1/p') +test -n "${DEB_PACKAGE_REVISION_SECURITY}" || DEB_PACKAGE_REVISION_SECURITY=0 +# Combine all update numbers into one +DEB_API_VERSION=$((KERNEL_CKT_UPDATE * 10000 + DEB_PACKAGE_REVISION_BASE * 100 + DEB_PACKAGE_REVISION_SECURITY)) + +echo ${DEB_API_VERSION} diff --git a/instrumentation/events/lttng-module/kmem.h b/instrumentation/events/lttng-module/kmem.h index 710c9fa5..7efca3e8 100644 --- a/instrumentation/events/lttng-module/kmem.h +++ b/instrumentation/events/lttng-module/kmem.h @@ -287,7 +287,8 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE_PRINT(mm_page, mm_page_pcpu_drain, ) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,2) \ - || LTTNG_KERNEL_RANGE(3,14,36, 3,15,0)) + || LTTNG_KERNEL_RANGE(3,14,36, 3,15,0) \ + || LTTNG_DEBIAN_KERNEL_RANGE(3,16,7,9,0,0, 3,17,0,0,0,0)) LTTNG_TRACEPOINT_EVENT(mm_page_alloc_extfrag, diff --git a/lib/Makefile b/lib/Makefile index 5f092f55..420c85a5 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,3 +1,7 @@ +KERNELDIR=${LTTNG_KERNELDIR} + +include $(KBUILD_EXTMOD)/Makefile.ABI.workarounds + obj-m += lttng-lib-ring-buffer.o lttng-lib-ring-buffer-objs := \ diff --git a/lttng-kernel-version.h b/lttng-kernel-version.h index ec8cee0b..59e19df5 100644 --- a/lttng-kernel-version.h +++ b/lttng-kernel-version.h @@ -53,4 +53,18 @@ LTTNG_UBUNTU_VERSION_CODE < \ LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high)) +#define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \ + (((((a) << 16) + ((b) << 8) + (c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) + +#define LTTNG_DEBIAN_VERSION_CODE \ + ((LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION) + +#define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ + a_high, b_high, c_high, d_high, e_high, f_high) \ + (defined(DEBIAN_API_VERSION) && \ + LTTNG_DEBIAN_VERSION_CODE >= \ + LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ + LTTNG_DEBIAN_VERSION_CODE < \ + LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) + #endif /* _LTTNG_KERNEL_VERSION_H */ diff --git a/probes/Makefile b/probes/Makefile index a228f8a4..4d38199e 100644 --- a/probes/Makefile +++ b/probes/Makefile @@ -5,6 +5,10 @@ ifneq ($(KERNELRELEASE),) ifneq ($(CONFIG_TRACEPOINTS),) +KERNELDIR=${LTTNG_KERNELDIR} + +include $(KBUILD_EXTMOD)/Makefile.ABI.workarounds + ccflags-y += -I$(PWD)/probes obj-m += lttng-types.o -- 2.34.1