Message ID | 20220908082523.906444-1-r.czerwinski@pengutronix.de |
---|---|
State | New |
Headers | show |
Series | [lttng-modules] Add new tracepoints for drm_scheduler | expand |
On 2022-09-08 04:25, Rouven Czerwinski via lttng-dev wrote: > Allows usage of the drm_gpu_scheduler tracepoints within lttng. > > Signed-off-by: Rouven Czerwinski <r.czerwinski at pengutronix.de> > --- > .../events/drm_gpu_scheduler.h | 63 +++++++++++++++++++ [...] > diff --git a/src/probes/Kbuild b/src/probes/Kbuild > index 7597389b..2846b0c7 100644 > --- a/src/probes/Kbuild > +++ b/src/probes/Kbuild > @@ -104,6 +104,13 @@ ifneq ($(CONFIG_DMA_SHARED_BUFFER),) > echo "lttng-probe-dma-fence.o" ; fi;) > endif # CONFIG_DMA_SHARED_BUFFER > > +ifneq ($(CONFIG_DRM_SCHED),) > + obj-$(CONFIG_LTTNG) += $(shell \ > + if [ $(VERSION) -ge 5 \ > + -o \( $VERSION -eq 4 -a $(PATCHLEVEL) -ge 16 \) ] ; then \ > + echo "lttng-probe-drm-sched.o" ; fi;) > +endif # CONFIG_DRM_SCHED > + > ifneq ($(CONFIG_BLOCK),) > # need blk_cmd_buf_len > ifneq ($(CONFIG_EVENT_TRACING),) > diff --git a/src/probes/lttng-probe-drm-sched.c b/src/probes/lttng-probe-drm-sched.c > new file mode 100644 > index 00000000..fe8f9cb2 > --- /dev/null > +++ b/src/probes/lttng-probe-drm-sched.c > @@ -0,0 +1,26 @@ > +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) > + * > + * probes/lttng-probe-drm-sched.c > + * > + * LTTng drm-sched probes. > + * > + * Copyright (C) 2022 Pengutronix, Rouven Czerwinski <entwicklung at pengutronix.de> > + */ > +#include <drm/gpu_scheduler.h> > + This patch is missing an important piece here, see similar situation for regmap: /* * Create the tracepoint static inlines from the kernel to validate that our * trace event macros match the kernel we run on. */ #include <../../drivers/base/regmap/trace.h> and its associated checks in Kbuild: ifneq ($(CONFIG_REGMAP),) regmap_dep_4_1 = $(srctree)/drivers/base/regmap/trace.h ifneq ($(wildcard $(regmap_dep_4_1)),) obj-$(CONFIG_LTTNG) += lttng-probe-regmap.o else $(warning File $(regmap_dep_4_1) not found. Probe "regmap" is disabled. Need Linux 4.1+ kernel source tree to enable it.) endif # $(wildcard $(regmap_dep_4_1)), endif # CONFIG_REGMAP This is required to validate that the tracepoint signature we build against indeed matches the types expected by the tracepoint probe callbacks. Unfortunately, the drm-sched instrumentation is located in drivers/gpu/drm/scheduler/gpu_scheduler_trace.h which is not available with installed kernel headers. So we really need access to the kernel sources to validate this signature. If we don't validate this at compile-time, this can generate kernel modules that will crash the kernel at runtime if the tracepoint signature changes in future kernels. This is something that is not acceptable. Thanks, Mathieu > +/* > + * Create LTTng tracepoint probes. > + */ > +#define LTTNG_PACKAGE_BUILD > +#define CREATE_TRACE_POINTS > +#define TRACE_INCLUDE_PATH instrumentation/events > + > +#include <instrumentation/events/drm_gpu_scheduler.h> > + > +MODULE_LICENSE("GPL and additional rights"); > +MODULE_AUTHOR("Rouven Czerwinski <r.czerwinski at pengutronix.de>"); > +MODULE_DESCRIPTION("LTTng drm-gpu-scheduler probes"); > +MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." > + __stringify(LTTNG_MODULES_MINOR_VERSION) "." > + __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) > + LTTNG_MODULES_EXTRAVERSION);
diff --git a/include/instrumentation/events/drm_gpu_scheduler.h b/include/instrumentation/events/drm_gpu_scheduler.h new file mode 100644 index 00000000..d217fcb2 --- /dev/null +++ b/include/instrumentation/events/drm_gpu_scheduler.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM drm_sched + +#if !defined(LTTNG_TRACE_DRM_GPU_SCHEDULER_H) || defined(TRACE_HEADER_MULTI_READ) +#define LTTNG_TRACE_DRM_GPU_SCHEDULER_H + +#include <lttng/tracepoint-event.h> + +LTTNG_TRACEPOINT_EVENT_CLASS(drm_sched_class, + + TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity), + + TP_ARGS(sched_job, entity), + + TP_FIELDS( + ctf_integer_hex(struct drm_sched_entity *, entity, entity) + ctf_integer_hex(struct dma_fence *, fence, &sched_job->s_fence->finished) + ctf_string(name, sched_job->sched->name) + ctf_integer(uint64_t, id, sched_job->id) + ctf_integer(u32, job_count, spsc_queue_count(&entity->job_queue)) + ctf_integer(int, hw_job_count, atomic_read(&sched_job->sched->hw_rq_count)) + ) +) + +LTTNG_TRACEPOINT_EVENT_INSTANCE(drm_sched_class, + drm_sched_job, + TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity), + TP_ARGS(sched_job, entity) +) + +LTTNG_TRACEPOINT_EVENT_INSTANCE(drm_sched_class, + drm_run_job, + TP_PROTO(struct drm_sched_job *sched_job, struct drm_sched_entity *entity), + TP_ARGS(sched_job, entity) +) + +LTTNG_TRACEPOINT_EVENT(drm_sched_process_job, + TP_PROTO(struct drm_sched_fence *fence), + TP_ARGS(fence), + + TP_FIELDS( + ctf_integer_hex(struct dma_fence *, fence, &fence->finished) + ) +) + +LTTNG_TRACEPOINT_EVENT(drm_sched_job_wait_dep, + TP_PROTO(struct drm_sched_job *sched_job, struct dma_fence *fence), + TP_ARGS(sched_job, fence), + + TP_FIELDS( + ctf_string(name, sched_job->sched->name) + ctf_integer(uint64_t, id, sched_job->id) + ctf_integer_hex(struct dma_fence *, fence, fence) + ctf_integer(uint64_t, ctx, fence->context) + ctf_integer(unsigned, seqno, fence->seqno) + ) +) + +#endif /* LTTNG_TRACE_DRM_SCHED_H */ + +/* This part must be outside protection */ +#include <lttng/define_trace.h> diff --git a/src/probes/Kbuild b/src/probes/Kbuild index 7597389b..2846b0c7 100644 --- a/src/probes/Kbuild +++ b/src/probes/Kbuild @@ -104,6 +104,13 @@ ifneq ($(CONFIG_DMA_SHARED_BUFFER),) echo "lttng-probe-dma-fence.o" ; fi;) endif # CONFIG_DMA_SHARED_BUFFER +ifneq ($(CONFIG_DRM_SCHED),) + obj-$(CONFIG_LTTNG) += $(shell \ + if [ $(VERSION) -ge 5 \ + -o \( $VERSION -eq 4 -a $(PATCHLEVEL) -ge 16 \) ] ; then \ + echo "lttng-probe-drm-sched.o" ; fi;) +endif # CONFIG_DRM_SCHED + ifneq ($(CONFIG_BLOCK),) # need blk_cmd_buf_len ifneq ($(CONFIG_EVENT_TRACING),) diff --git a/src/probes/lttng-probe-drm-sched.c b/src/probes/lttng-probe-drm-sched.c new file mode 100644 index 00000000..fe8f9cb2 --- /dev/null +++ b/src/probes/lttng-probe-drm-sched.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) + * + * probes/lttng-probe-drm-sched.c + * + * LTTng drm-sched probes. + * + * Copyright (C) 2022 Pengutronix, Rouven Czerwinski <entwicklung at pengutronix.de> + */ +#include <drm/gpu_scheduler.h> + +/* + * Create LTTng tracepoint probes. + */ +#define LTTNG_PACKAGE_BUILD +#define CREATE_TRACE_POINTS +#define TRACE_INCLUDE_PATH instrumentation/events + +#include <instrumentation/events/drm_gpu_scheduler.h> + +MODULE_LICENSE("GPL and additional rights"); +MODULE_AUTHOR("Rouven Czerwinski <r.czerwinski at pengutronix.de>"); +MODULE_DESCRIPTION("LTTng drm-gpu-scheduler probes"); +MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." + __stringify(LTTNG_MODULES_MINOR_VERSION) "." + __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) + LTTNG_MODULES_EXTRAVERSION);
Allows usage of the drm_gpu_scheduler tracepoints within lttng. Signed-off-by: Rouven Czerwinski <r.czerwinski at pengutronix.de> --- .../events/drm_gpu_scheduler.h | 63 +++++++++++++++++++ src/probes/Kbuild | 7 +++ src/probes/lttng-probe-drm-sched.c | 26 ++++++++ 3 files changed, 96 insertions(+) create mode 100644 include/instrumentation/events/drm_gpu_scheduler.h create mode 100644 src/probes/lttng-probe-drm-sched.c