Add kernel tracing instrumentation

This commit is contained in:
Simon Ser 2021-10-01 14:25:22 +02:00
parent 28d074e5ab
commit a003206c38
6 changed files with 83 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include "log.h" #include "log.h"
#include "private.h" #include "private.h"
#include "trace.h"
/* Plane allocation algorithm /* Plane allocation algorithm
* *
@ -674,6 +675,10 @@ liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req,
update_layers_priority(device); update_layers_priority(device);
liftoff_tracer_mark(&device->tracer,
"output_apply (begin_ctx=%d)",
device->page_flip_counter);
ret = reuse_previous_alloc(output, req, flags); ret = reuse_previous_alloc(output, req, flags);
if (ret == 0) { if (ret == 0) {
log_reuse(output); log_reuse(output);
@ -776,5 +781,9 @@ liftoff_output_apply(struct liftoff_output *output, drmModeAtomicReq *req,
mark_layers_clean(output); mark_layers_clean(output);
liftoff_tracer_mark(&device->tracer,
"output_apply (end_ctx=%d)",
device->page_flip_counter);
return 0; return 0;
} }

View file

@ -20,6 +20,8 @@ liftoff_device_create(int drm_fd)
liftoff_list_init(&device->planes); liftoff_list_init(&device->planes);
liftoff_list_init(&device->outputs); liftoff_list_init(&device->outputs);
liftoff_tracer_init(&device->tracer);
device->drm_fd = dup(drm_fd); device->drm_fd = dup(drm_fd);
if (device->drm_fd < 0) { if (device->drm_fd < 0) {
liftoff_log_errno(LIFTOFF_ERROR, "dup"); liftoff_log_errno(LIFTOFF_ERROR, "dup");
@ -59,6 +61,7 @@ liftoff_device_destroy(struct liftoff_device *device)
return; return;
} }
liftoff_tracer_finish(&device->tracer);
close(device->drm_fd); close(device->drm_fd);
liftoff_list_for_each_safe(plane, tmp, &device->planes, link) { liftoff_list_for_each_safe(plane, tmp, &device->planes, link) {
liftoff_plane_destroy(plane); liftoff_plane_destroy(plane);
@ -97,6 +100,10 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
device->test_commit_counter++; device->test_commit_counter++;
liftoff_tracer_mark(&device->tracer,
"device_test_commit (begin_ctx=%d)",
device->test_commit_counter);
flags &= ~DRM_MODE_PAGE_FLIP_EVENT; flags &= ~DRM_MODE_PAGE_FLIP_EVENT;
do { do {
ret = drmModeAtomicCommit(device->drm_fd, req, ret = drmModeAtomicCommit(device->drm_fd, req,
@ -104,6 +111,10 @@ device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
NULL); NULL);
} while (ret == -EINTR || ret == -EAGAIN); } while (ret == -EINTR || ret == -EAGAIN);
liftoff_tracer_mark(&device->tracer,
"device_test_commit (end_ctx=%d)",
device->test_commit_counter);
/* The kernel will return -EINVAL for invalid configuration, -ERANGE for /* The kernel will return -EINVAL for invalid configuration, -ERANGE for
* CRTC coords overflow, and -ENOSPC for invalid SRC coords. */ * CRTC coords overflow, and -ENOSPC for invalid SRC coords. */
if (ret != 0 && ret != -EINVAL && ret != -ERANGE && ret != -ENOSPC) { if (ret != 0 && ret != -EINVAL && ret != -ERANGE && ret != -ENOSPC) {

View file

@ -4,6 +4,7 @@
#include <libliftoff.h> #include <libliftoff.h>
#include "list.h" #include "list.h"
#include "log.h" #include "log.h"
#include "trace.h"
/* Layer priority is assigned depending on the number of updates during a /* Layer priority is assigned depending on the number of updates during a
* given number of page-flips */ * given number of page-flips */
@ -18,6 +19,7 @@ struct liftoff_device {
uint32_t *crtcs; uint32_t *crtcs;
size_t crtcs_len; size_t crtcs_len;
struct liftoff_tracer tracer;
int page_flip_counter; int page_flip_counter;
int test_commit_counter; int test_commit_counter;
}; };

21
include/trace.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef TRACE_H
#define TRACE_H
#include <stdio.h>
#include "log.h"
struct liftoff_tracer {
FILE *f;
};
int
liftoff_tracer_init(struct liftoff_tracer *tracer);
void
liftoff_tracer_finish(struct liftoff_tracer *tracer);
void
liftoff_tracer_mark(struct liftoff_tracer *tracer, const char *format, ...)
_LIFTOFF_ATTRIB_PRINTF(2, 3);
#endif

View file

@ -38,6 +38,7 @@ liftoff_lib = library(
'log.c', 'log.c',
'output.c', 'output.c',
'plane.c', 'plane.c',
'trace.c',
), ),
include_directories: liftoff_inc, include_directories: liftoff_inc,
version: meson.project_version(), version: meson.project_version(),

39
trace.c Normal file
View file

@ -0,0 +1,39 @@
#include <errno.h>
#include "trace.h"
int
liftoff_tracer_init(struct liftoff_tracer *tracer)
{
tracer->f = fopen("/sys/kernel/tracing/trace_marker", "w");
if (tracer->f == NULL) {
return -errno;
}
liftoff_log(LIFTOFF_DEBUG, "Kernel tracing is enabled");
return 0;
}
void
liftoff_tracer_finish(struct liftoff_tracer *tracer)
{
if (tracer->f != NULL) {
fclose(tracer->f);
}
}
void
liftoff_tracer_mark(struct liftoff_tracer *tracer, const char *format, ...)
{
if (tracer->f == NULL) {
return;
}
fprintf(tracer->f, "libliftoff: ");
va_list args;
va_start(args, format);
vfprintf(tracer->f, format, args);
va_end(args);
fprintf(tracer->f, "\n");
fflush(tracer->f);
}