From patchwork Thu Nov 7 21:03:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 11233775 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8384139A for ; Thu, 7 Nov 2019 21:03:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FEC721D79 for ; Thu, 7 Nov 2019 21:03:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FEC721D79 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=poorly.run Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A17BC6F7C0; Thu, 7 Nov 2019 21:03:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw1-xc42.google.com (mail-yw1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7DF496F7BB for ; Thu, 7 Nov 2019 21:03:22 +0000 (UTC) Received: by mail-yw1-xc42.google.com with SMTP id y64so1132458ywe.3 for ; Thu, 07 Nov 2019 13:03:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KC2BYUStyaQkIOsxmJMEfiQ0fY/TMGO96+PzuKi2DJc=; b=K67exyRfdqt+Vj3uBXpaRz6tKrt5C1eZ4MtluswHwXMmhObjE+BJZCWn+EFB1IgUmO X3gX+rzEcb1EkSCifPAT/uHktNb0lIcbCWBmkJdRhpyri09G7rjnZHFMdg8GAD+XXvTH nLi08WL8SPTtnyKBp95fXBcNz4ZMcWTsaHcgUU6SHr5Lqki2/1ipK0q11p79f6cO+mUe QhmkYi6xEALUe1v0x0K7recHKuMCgMR0cRj28185TfNClu1U6sJRlWgQDAmmwD/Sy1kh 0UxnyktTvJ7BYYgzyhn20v88+bt4Huwi8YxWl7zwzYZjpu6hEOt/0gOhRBIeQWDUY2bD vYsg== X-Gm-Message-State: APjAAAXWmdJNA/zOBoOAhIYS+Z8ucCJTH0ZjjRln10OmWoqZ7A29IQtO e7vxwCqBvikg8sVWqZ9k2iaDmS92Tq8= X-Google-Smtp-Source: APXvYqzfibwXErR/EA/byC5kF15E4MvEvfW1qd1LMC5jKits8K7Thg64+dk8r8vIRPpj56gzvxsgfA== X-Received: by 2002:a81:5ac6:: with SMTP id o189mr1149824ywb.110.1573160601381; Thu, 07 Nov 2019 13:03:21 -0800 (PST) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id r14sm1064196ywl.97.2019.11.07.13.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 13:03:20 -0800 (PST) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/6] drm: trace: Introduce drm_trace() and trace event classes Date: Thu, 7 Nov 2019 16:03:01 -0500 Message-Id: <20191107210316.143216-3-sean@poorly.run> X-Mailer: git-send-email 2.24.0.rc1.363.gb1bccd3e3d-goog In-Reply-To: <20191107210316.143216-1-sean@poorly.run> References: <20191107210316.143216-1-sean@poorly.run> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KC2BYUStyaQkIOsxmJMEfiQ0fY/TMGO96+PzuKi2DJc=; b=X6pw+z6SxoXc3DzqXjLqzRChFgreSAmqyw1VA/DalFdyvrpzXb23rv3L3QlBtiN8fp ii89eqm9cdWh4YK2tkqVkAGz3Dn17QDYL1oWWmZ71TxQf6CJCrA3GGRrs4xtl4xwEn8E 58XIIiA8EeK3ljen+gkdducb/bqg1LWVxE7V23zmGNxXvsy21F0kRhNAULpaRN/CENXz sfAryRet3rwqI15DLJcLhkKHwxoTWEMl4sW0eBBBZkWa1d2qxTT9Dd+4uVcUsyfJlWX3 FcXqyykQCS8YBCY5Ca+AAIXiWOZS0AmqZ1MwpAJOOiIRQza0KLIrqleP17jX8FTWfo6x hCYA== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, Sean Paul , tzimmermann@suse.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sean Paul This patch is the first step in expanding trace events in drm. It introduces a new enum used to classify trace events as well as a couple helper macros to issue trace events from around drm. It's a bit of a toy right now since we're just converting one class (vblank) and there aren't any error events in this class. However later patches in this series will add more interesting classes. Signed-off-by: Sean Paul --- Documentation/gpu/drm-internals.rst | 9 +++ drivers/gpu/drm/drm_trace.h | 109 ++++++++++++++++++++++++++-- drivers/gpu/drm/drm_vblank.c | 8 +- 3 files changed, 114 insertions(+), 12 deletions(-) diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst index 966bd2d9f0ccd..ac87a94b7057a 100644 --- a/Documentation/gpu/drm-internals.rst +++ b/Documentation/gpu/drm-internals.rst @@ -176,6 +176,15 @@ Printer .. kernel-doc:: drivers/gpu/drm/drm_print.c :export: +Tracing +------- + +.. kernel-doc:: drivers/gpu/drm/drm_trace.h + :doc: overview + +.. kernel-doc:: drivers/gpu/drm/drm_trace.h + :internal: + Utilities --------- diff --git a/drivers/gpu/drm/drm_trace.h b/drivers/gpu/drm/drm_trace.h index 487bc3478efec..19e5f04210586 100644 --- a/drivers/gpu/drm/drm_trace.h +++ b/drivers/gpu/drm/drm_trace.h @@ -7,21 +7,109 @@ #include struct drm_file; +/** + * DOC: overview + * + * DRM trace events can be used to trace important moments occurring in the DRM + * core or helpers without incurring a significant performance penalty (like you + * would with console logging). + */ + +#if !defined(_DRM_TRACE_EVENT_CLASS_ENUM) +#define _DRM_TRACE_EVENT_CLASS_ENUM + +/** + * enum drm_trace_event_class - the trace class of an event + * + * Trace events are broken into different classes (much the same as we do for + * console logging) to make sifting through the logs easier. If you want to + * isolate one or more classes (or disable a subset of classes), you can write + * an expession using the event_class entry field as a tracepoints filter. The + * event_class field is not printed as part of the trace log, it's just there + * for filtering. + * + * The classes are bitfields to make filtering easier, but also to allow trace + * events to be classified under multiple classes (ie: if you're tracing an + * error that occurred with a crtc, you can ensure that these events are + * surfaced for filters looking for either crtc or error classes). + * + * An example filter is: + * Assume you want to view all trace events in failure paths, you would + * write a filter which isolates events with the drm_trace_class_error bit + * set in their event_class field. This allows you to enable all trace + * events in the drm trace system and only consume errors. + * + * ; echo "event_class & 0x1" > /sys/kernel/tracing/events/drm/filter + * ; echo 1 > /sys/kernel/tracing/events/drm/enable + * + * Similarly, to view all vblank traces plus any error traces, you select + * both classes in the filter. + * + * ; echo "event_class & 0x3" > /sys/kernel/tracing/events/drm/filter + */ +enum drm_trace_event_class { + /** + * @drm_trace_class_error: Denotes that the trace event is coming from + * an error path. + */ + drm_trace_class_error = BIT(0), + + /** + * @drm_trace_class_vblank: Use this to track trace events that track + * vblanks and vblank events. + */ + drm_trace_class_vblank = BIT(1), +}; + +/** + * drm_trace - add a drm trace event + * @_c: class name (the part that comes after drm_trace_class_) + * @_e: event name (the part that comes after drm_$class_) + * + * Use this macro to simplify adding a trace event for non-failure paths in + * drm code. The macro simply assembles the trace event from the class and name, + * and sets the correct event_code for this trace. + * + * It's recommended that this macro is not used in failure paths. For failure + * paths, use drm_trace_err(). + */ +#define drm_trace(_c, _e, ...) \ + trace_drm_##_c##_##_e(drm_trace_class_##_c, __VA_ARGS__) + +/** + * drm_trace_err - add a drm trace event in a failure path + * @_c: class name (the part that comes after drm_trace_class_) + * @_e: event name (the part that comes after drm_$class_) + * + * This is virtually the same as drm_trace(), however it sets the error class on + * the event as well. This is beneficial for those filtering events by + * class_error. + * + * For non-failure paths, please use drm_trace(). + */ +#define drm_trace_err(_c, _e, ...) \ + trace_drm_##_c##_##_e(drm_trace_class_##_c | drm_trace_class_error, \ + __VA_ARGS__) + +#endif #undef TRACE_SYSTEM #define TRACE_SYSTEM drm #define TRACE_INCLUDE_FILE drm_trace TRACE_EVENT(drm_vblank_event, - TP_PROTO(int crtc, unsigned int seq, ktime_t time, bool high_prec), - TP_ARGS(crtc, seq, time, high_prec), + TP_PROTO(unsigned int event_class, int crtc, unsigned int seq, + ktime_t time, bool high_prec), + TP_ARGS(event_class, crtc, seq, time, high_prec), TP_STRUCT__entry( + __field(unsigned int, event_class) __field(int, crtc) __field(unsigned int, seq) __field(ktime_t, time) __field(bool, high_prec) ), TP_fast_assign( + __entry->event_class = event_class; __entry->crtc = crtc; __entry->seq = seq; __entry->time = time; @@ -33,14 +121,17 @@ TRACE_EVENT(drm_vblank_event, ); DECLARE_EVENT_CLASS(class_drm_vblank_event, - TP_PROTO(struct drm_file *file, int crtc, unsigned int seq), - TP_ARGS(file, crtc, seq), + TP_PROTO(unsigned int event_class, struct drm_file *file, + int crtc, unsigned int seq), + TP_ARGS(event_class, file, crtc, seq), TP_STRUCT__entry( + __field(unsigned int, event_class) __field(struct drm_file *, file) __field(int, crtc) __field(unsigned int, seq) ), TP_fast_assign( + __entry->event_class = event_class; __entry->file = file; __entry->crtc = crtc; __entry->seq = seq; @@ -49,12 +140,14 @@ DECLARE_EVENT_CLASS(class_drm_vblank_event, __entry->seq) ); DEFINE_EVENT(class_drm_vblank_event, drm_vblank_event_queued, - TP_PROTO(struct drm_file *file, int crtc, unsigned int seq), - TP_ARGS(file, crtc, seq) + TP_PROTO(unsigned int event_class, struct drm_file *file, int crtc, + unsigned int seq), + TP_ARGS(event_class, file, crtc, seq) ); DEFINE_EVENT(class_drm_vblank_event, drm_vblank_event_delivered, - TP_PROTO(struct drm_file *file, int crtc, unsigned int seq), - TP_ARGS(file, crtc, seq) + TP_PROTO(unsigned int event_class, struct drm_file *file, int crtc, + unsigned int seq), + TP_ARGS(event_class, file, crtc, seq) ); #endif /* _DRM_TRACE_H_ */ diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 1659b13b178c2..19a63a94586ad 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -880,7 +880,7 @@ static void send_vblank_event(struct drm_device *dev, e->event.seq.time_ns = ktime_to_ns(now); break; } - trace_drm_vblank_event_delivered(e->base.file_priv, e->pipe, seq); + drm_trace(vblank, event_delivered, e->base.file_priv, e->pipe, seq); drm_send_event_locked(dev, &e->base); } @@ -1529,7 +1529,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, DRM_DEBUG("event on vblank count %llu, current %llu, crtc %u\n", req_seq, seq, pipe); - trace_drm_vblank_event_queued(file_priv, pipe, req_seq); + drm_trace(vblank, event_queued, file_priv, pipe, req_seq); e->sequence = req_seq; if (vblank_passed(seq, req_seq)) { @@ -1760,8 +1760,8 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe) send_vblank_event(dev, e, seq, now); } - trace_drm_vblank_event(pipe, seq, now, - dev->driver->get_vblank_timestamp != NULL); + drm_trace(vblank, event, pipe, seq, now, + dev->driver->get_vblank_timestamp != NULL); } /**