[lttng-dev] [PATCH lttng-modules 1/1] Introduce configure script to describe changes in linux kernel interface

Roxana Nicolescu roxana.nicolescu at canonical.com
Mon Jul 3 14:28:59 EDT 2023


This script is intented to be used for checking the changes in linux
kernel headers and keep the lttng module up-to-date.

It is introduced for a specific usecase where commit
d87a7b4c77a9: "jbd2: use the correct print format"
broke the interface between the kernel and lttng-module. 3 variables
changed their type to tid_t (transaction, head and tid) in multiple
function declarations. The lttng module was updated properly to ensure
backwards compatibility by using the version of the kernel.
But this change took into account only long term supported versions.
As an example, ubuntu 5.19 kernels picked the linux kernel change from
5.15 without actually changing the linux kernel upstream version. This
means the current tooling does not allow to fix the module for newer
ubuntu 5.19 kernels.

Configure script is supposed to make this change easier to integrate.
We check the linux kernel header (include/trace/events/jbd2.h) if
the type of tid, transaction and head variable has changes to tid_t
and define these 3 variables in 'include/generated/config.h':
TID_IS_TID_T 1
TRANSACTION_IS_TID_T 1
HEAD_IS_TID_T 1

In 'include/instrumentation/events/jbd2.h' we then check these to define
the proper type of transaction, head and tid variables that will be
later used in the function declarations that need them.

This change is meant to remove the dependency on linux kernel version
and the outcome is a bit cleaner that before.
As with the previous implementation, this may need changes in the future
if the kernel interface changes again.

Signed-off-by: Roxana Nicolescu <roxana.nicolescu at canonical.com>
---
 README.md                             |   3 +-
 configure                             |  36 +++++++++
 include/instrumentation/events/jbd2.h | 110 ++++++--------------------
 3 files changed, 61 insertions(+), 88 deletions(-)
 create mode 100755 configure

diff --git a/README.md b/README.md
index 06480d3b..231ba956 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,7 @@ Building
 To build and install LTTng-modules, you will need to have your kernel
 headers available (or access to your full kernel source tree), and do:
 
+    ./configure
     make
     sudo make modules_install
     sudo depmod -a
@@ -36,7 +37,7 @@ headers available (or access to your full kernel source tree), and do:
 The above commands will build LTTng-modules against your
 current kernel. If you need to build LTTng-modules against a custom
 kernel, do:
-
+    KERNELDIR=/path/to/custom/kernel ./configure
     make KERNELDIR=/path/to/custom/kernel
     sudo make KERNELDIR=/path/to/custom/kernel modules_install
     sudo depmod -a kernel_version
diff --git a/configure b/configure
new file mode 100755
index 00000000..a9fcd422
--- /dev/null
+++ b/configure
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+if [ -z "${KERNELDIR}" ]; then
+    KERNELDIR=/lib/modules/$(uname -r)/build
+fi
+
+INCLUDE_DIR="include/generated"
+if test ! -d "${INCLUDE_DIR}"; then
+	mkdir "${INCLUDE_DIR}"
+fi
+
+LINUX_HEADER_FILE="${KERNELDIR}/include/trace/events/jbd2.h"
+
+CONFIG_H_OUTPUT_FILE="${INCLUDE_DIR}/config.h"
+# cleanup old config file
+> ${CONFIG_H_OUTPUT_FILE}
+
+if test -f "${LINUX_HEADER_FILE}"; then
+    grep -q "tid_t tid" ${LINUX_HEADER_FILE}
+    status=$?
+    if [ $status -eq 0 ]; then
+        echo "#define TID_IS_TID_T 1" >> ${CONFIG_H_OUTPUT_FILE}
+    fi
+
+    grep -q "[[:blank:]]\+__field([[:blank:]]\+tid_t,[[:blank:]]\+transaction" ${LINUX_HEADER_FILE}
+    status=$?
+    if [ $status -eq 0 ]; then
+        echo "#define TRANSACTION_IS_TID_T 1" >> ${CONFIG_H_OUTPUT_FILE}
+    fi
+
+    grep -q "[[:blank:]]\+__field([[:blank:]]\+tid_t,[[:blank:]]\+head" ${LINUX_HEADER_FILE}
+    status=$?
+    if [ $status -eq 0 ]; then
+        echo "#define HEAD_IS_TID_T 1" >> ${CONFIG_H_OUTPUT_FILE}
+    fi
+fi
diff --git a/include/instrumentation/events/jbd2.h b/include/instrumentation/events/jbd2.h
index be217ffa..6f9bd013 100644
--- a/include/instrumentation/events/jbd2.h
+++ b/include/instrumentation/events/jbd2.h
@@ -8,6 +8,7 @@
 #include <lttng/tracepoint-event.h>
 #include <linux/jbd2.h>
 #include <lttng/kernel-version.h>
+#include <generated/config.h>
 
 #ifndef _TRACE_JBD2_DEF
 #define _TRACE_JBD2_DEF
@@ -27,25 +28,18 @@ LTTNG_TRACEPOINT_EVENT(jbd2_checkpoint,
 	)
 )
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,2,0) \
-	|| LTTNG_KERNEL_RANGE(5,4,229, 5,5,0) \
-	|| LTTNG_KERNEL_RANGE(5,10,163, 5,11,0) \
-	|| LTTNG_KERNEL_RANGE(5,15,87, 5,16,0) \
-	|| LTTNG_KERNEL_RANGE(6,0,18, 6,1,0) \
-	|| LTTNG_KERNEL_RANGE(6,1,4, 6,2,0))
-LTTNG_TRACEPOINT_EVENT_CLASS(jbd2_commit,
-
-	TP_PROTO(journal_t *journal, transaction_t *commit_transaction),
-
-	TP_ARGS(journal, commit_transaction),
+#ifdef TRANSACTION_IS_TID_T
+#define transaction_type tid_t
+#else
+#define transaction_type int
+#endif
 
-	TP_FIELDS(
-		ctf_integer(dev_t, dev, journal->j_fs_dev->bd_dev)
-		ctf_integer(char, sync_commit, commit_transaction->t_synchronous_commit)
-		ctf_integer(tid_t, transaction, commit_transaction->t_tid)
-	)
-)
+#ifdef HEAD_IS_TID_T
+#define head_type tid_t
 #else
+#define head_type int
+#endif
+
 LTTNG_TRACEPOINT_EVENT_CLASS(jbd2_commit,
 
 	TP_PROTO(journal_t *journal, transaction_t *commit_transaction),
@@ -55,10 +49,9 @@ LTTNG_TRACEPOINT_EVENT_CLASS(jbd2_commit,
 	TP_FIELDS(
 		ctf_integer(dev_t, dev, journal->j_fs_dev->bd_dev)
 		ctf_integer(char, sync_commit, commit_transaction->t_synchronous_commit)
-		ctf_integer(int, transaction, commit_transaction->t_tid)
+		ctf_integer(transaction_type, transaction, commit_transaction->t_tid)
 	)
 )
-#endif
 
 LTTNG_TRACEPOINT_EVENT_INSTANCE(jbd2_commit, jbd2_start_commit,
 
@@ -97,12 +90,6 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE(jbd2_commit, jbd2_drop_transaction,
 )
 #endif
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,2,0) \
-	|| LTTNG_KERNEL_RANGE(5,4,229, 5,5,0) \
-	|| LTTNG_KERNEL_RANGE(5,10,163, 5,11,0) \
-	|| LTTNG_KERNEL_RANGE(5,15,87, 5,16,0) \
-	|| LTTNG_KERNEL_RANGE(6,0,18, 6,1,0) \
-	|| LTTNG_KERNEL_RANGE(6,1,4, 6,2,0))
 LTTNG_TRACEPOINT_EVENT(jbd2_end_commit,
 	TP_PROTO(journal_t *journal, transaction_t *commit_transaction),
 
@@ -111,24 +98,10 @@ LTTNG_TRACEPOINT_EVENT(jbd2_end_commit,
 	TP_FIELDS(
 		ctf_integer(dev_t, dev, journal->j_fs_dev->bd_dev)
 		ctf_integer(char, sync_commit, commit_transaction->t_synchronous_commit)
-		ctf_integer(tid_t, transaction, commit_transaction->t_tid)
-		ctf_integer(tid_t, head, journal->j_tail_sequence)
+		ctf_integer(transaction_type, transaction, commit_transaction->t_tid)
+		ctf_integer(head_type, head, journal->j_tail_sequence)
 	)
 )
-#else
-LTTNG_TRACEPOINT_EVENT(jbd2_end_commit,
-	TP_PROTO(journal_t *journal, transaction_t *commit_transaction),
-
-	TP_ARGS(journal, commit_transaction),
-
-	TP_FIELDS(
-		ctf_integer(dev_t, dev, journal->j_fs_dev->bd_dev)
-		ctf_integer(char, sync_commit, commit_transaction->t_synchronous_commit)
-		ctf_integer(int, transaction, commit_transaction->t_tid)
-		ctf_integer(int, head, journal->j_tail_sequence)
-	)
-)
-#endif
 
 LTTNG_TRACEPOINT_EVENT(jbd2_submit_inode_data,
 	TP_PROTO(struct inode *inode),
@@ -141,57 +114,21 @@ LTTNG_TRACEPOINT_EVENT(jbd2_submit_inode_data,
 	)
 )
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,2,0) \
-	|| LTTNG_KERNEL_RANGE(5,4,229, 5,5,0) \
-	|| LTTNG_KERNEL_RANGE(5,10,163, 5,11,0) \
-	|| LTTNG_KERNEL_RANGE(5,15,87, 5,16,0) \
-	|| LTTNG_KERNEL_RANGE(6,0,18, 6,1,0) \
-	|| LTTNG_KERNEL_RANGE(6,1,4, 6,2,0))
-LTTNG_TRACEPOINT_EVENT(jbd2_run_stats,
-	TP_PROTO(dev_t dev, tid_t tid,
-		 struct transaction_run_stats_s *stats),
-
-	TP_ARGS(dev, tid, stats),
-
-	TP_FIELDS(
-		ctf_integer(dev_t, dev, dev)
-		ctf_integer(tid_t, tid, tid)
-		ctf_integer(unsigned long, wait, stats->rs_wait)
-		ctf_integer(unsigned long, running, stats->rs_running)
-		ctf_integer(unsigned long, locked, stats->rs_locked)
-		ctf_integer(unsigned long, flushing, stats->rs_flushing)
-		ctf_integer(unsigned long, logging, stats->rs_logging)
-		ctf_integer(__u32, handle_count, stats->rs_handle_count)
-		ctf_integer(__u32, blocks, stats->rs_blocks)
-		ctf_integer(__u32, blocks_logged, stats->rs_blocks_logged)
-	)
-)
-
-LTTNG_TRACEPOINT_EVENT(jbd2_checkpoint_stats,
-	TP_PROTO(dev_t dev, tid_t tid,
-		 struct transaction_chp_stats_s *stats),
-
-	TP_ARGS(dev, tid, stats),
-
-	TP_FIELDS(
-		ctf_integer(dev_t, dev, dev)
-		ctf_integer(tid_t, tid, tid)
-		ctf_integer(unsigned long, chp_time, stats->cs_chp_time)
-		ctf_integer(__u32, forced_to_close, stats->cs_forced_to_close)
-		ctf_integer(__u32, written, stats->cs_written)
-		ctf_integer(__u32, dropped, stats->cs_dropped)
-	)
-)
+#ifdef TID_IS_TID_T
+#define tid_type tid_t
 #else
+#define tid_type unsigned long
+#endif
+
 LTTNG_TRACEPOINT_EVENT(jbd2_run_stats,
-	TP_PROTO(dev_t dev, unsigned long tid,
+	TP_PROTO(dev_t dev, tid_type tid,
 		 struct transaction_run_stats_s *stats),
 
 	TP_ARGS(dev, tid, stats),
 
 	TP_FIELDS(
 		ctf_integer(dev_t, dev, dev)
-		ctf_integer(unsigned long, tid, tid)
+		ctf_integer(tid_type, tid, tid)
 		ctf_integer(unsigned long, wait, stats->rs_wait)
 		ctf_integer(unsigned long, running, stats->rs_running)
 		ctf_integer(unsigned long, locked, stats->rs_locked)
@@ -204,21 +141,20 @@ LTTNG_TRACEPOINT_EVENT(jbd2_run_stats,
 )
 
 LTTNG_TRACEPOINT_EVENT(jbd2_checkpoint_stats,
-	TP_PROTO(dev_t dev, unsigned long tid,
+	TP_PROTO(dev_t dev, tid_type tid,
 		 struct transaction_chp_stats_s *stats),
 
 	TP_ARGS(dev, tid, stats),
 
 	TP_FIELDS(
 		ctf_integer(dev_t, dev, dev)
-		ctf_integer(unsigned long, tid, tid)
+		ctf_integer(tid_type, tid, tid)
 		ctf_integer(unsigned long, chp_time, stats->cs_chp_time)
 		ctf_integer(__u32, forced_to_close, stats->cs_forced_to_close)
 		ctf_integer(__u32, written, stats->cs_written)
 		ctf_integer(__u32, dropped, stats->cs_dropped)
 	)
 )
-#endif
 
 LTTNG_TRACEPOINT_EVENT(jbd2_update_log_tail,
 	TP_PROTO(journal_t *journal, tid_t first_tid,
-- 
2.34.1



More information about the lttng-dev mailing list