1*c88d5105SVincent Donnefort.. SPDX-License-Identifier: GPL-2.0 2*c88d5105SVincent Donnefort 3*c88d5105SVincent Donnefort=============== 4*c88d5105SVincent DonnefortTracing Remotes 5*c88d5105SVincent Donnefort=============== 6*c88d5105SVincent Donnefort 7*c88d5105SVincent Donnefort:Author: Vincent Donnefort <vdonnefort@google.com> 8*c88d5105SVincent Donnefort 9*c88d5105SVincent DonnefortOverview 10*c88d5105SVincent Donnefort======== 11*c88d5105SVincent DonnefortFirmware and hypervisors are black boxes to the kernel. Having a way to see what 12*c88d5105SVincent Donnefortthey are doing can be useful to debug both. This is where remote tracing buffers 13*c88d5105SVincent Donnefortcome in. A remote tracing buffer is a ring buffer executed by the firmware or 14*c88d5105SVincent Donneforthypervisor into memory that is memory mapped to the host kernel. This is similar 15*c88d5105SVincent Donnefortto how user space memory maps the kernel ring buffer but in this case the kernel 16*c88d5105SVincent Donnefortis acting like user space and the firmware or hypervisor is the "kernel" side. 17*c88d5105SVincent DonnefortWith a trace remote ring buffer, the firmware and hypervisor can record events 18*c88d5105SVincent Donnefortfor which the host kernel can see and expose to user space. 19*c88d5105SVincent Donnefort 20*c88d5105SVincent DonnefortRegister a remote 21*c88d5105SVincent Donnefort================= 22*c88d5105SVincent DonnefortA remote must provide a set of callbacks `struct trace_remote_callbacks` whom 23*c88d5105SVincent Donnefortdescription can be found below. Those callbacks allows Tracefs to enable and 24*c88d5105SVincent Donnefortdisable tracing and events, to load and unload a tracing buffer (a set of 25*c88d5105SVincent Donnefortring-buffers) and to swap a reader page with the head page, which enables 26*c88d5105SVincent Donnefortconsuming reading. 27*c88d5105SVincent Donnefort 28*c88d5105SVincent Donnefort.. kernel-doc:: include/linux/trace_remote.h 29*c88d5105SVincent Donnefort 30*c88d5105SVincent DonnefortOnce registered, an instance will appear for this remote in the Tracefs 31*c88d5105SVincent Donnefortdirectory **remotes/**. Buffers can then be read using the usual Tracefs files 32*c88d5105SVincent Donnefort**trace_pipe** and **trace**. 33*c88d5105SVincent Donnefort 34*c88d5105SVincent DonnefortDeclare a remote event 35*c88d5105SVincent Donnefort====================== 36*c88d5105SVincent DonnefortMacros are provided to ease the declaration of remote events, in a similar 37*c88d5105SVincent Donnefortfashion to in-kernel events. A declaration must provide an ID, a description of 38*c88d5105SVincent Donnefortthe event arguments and how to print the event: 39*c88d5105SVincent Donnefort 40*c88d5105SVincent Donnefort.. code-block:: c 41*c88d5105SVincent Donnefort 42*c88d5105SVincent Donnefort REMOTE_EVENT(foo, EVENT_FOO_ID, 43*c88d5105SVincent Donnefort RE_STRUCT( 44*c88d5105SVincent Donnefort re_field(u64, bar) 45*c88d5105SVincent Donnefort ), 46*c88d5105SVincent Donnefort RE_PRINTK("bar=%lld", __entry->bar) 47*c88d5105SVincent Donnefort ); 48*c88d5105SVincent Donnefort 49*c88d5105SVincent DonnefortThen those events must be declared in a C file with the following: 50*c88d5105SVincent Donnefort 51*c88d5105SVincent Donnefort.. code-block:: c 52*c88d5105SVincent Donnefort 53*c88d5105SVincent Donnefort #define REMOTE_EVENT_INCLUDE_FILE foo_events.h 54*c88d5105SVincent Donnefort #include <trace/define_remote_events.h> 55*c88d5105SVincent Donnefort 56*c88d5105SVincent DonnefortThis will provide a `struct remote_event remote_event_foo` that can be given to 57*c88d5105SVincent Donnefort`trace_remote_register`. 58*c88d5105SVincent Donnefort 59*c88d5105SVincent DonnefortRegistered events appear in the remote directory under **events/**. 60*c88d5105SVincent Donnefort 61*c88d5105SVincent DonnefortSimple ring-buffer 62*c88d5105SVincent Donnefort================== 63*c88d5105SVincent DonnefortA simple implementation for a ring-buffer writer can be found in 64*c88d5105SVincent Donnefortkernel/trace/simple_ring_buffer.c. 65*c88d5105SVincent Donnefort 66*c88d5105SVincent Donnefort.. kernel-doc:: include/linux/simple_ring_buffer.h 67