linux-stable/Documentation
Daniel Bristot de Oliveira e88ed227f6 tracing/timerlat: Add user-space interface
Going a step further, we propose a way to use any user-space
workload as the task waiting for the timerlat timer. This is done
via a per-CPU file named osnoise/cpu$id/timerlat_fd file.

The tracef_fd allows a task to open at a time. When a task reads
the file, the timerlat timer is armed for future osnoise/timerlat_period_us
time. When the timer fires, it prints the IRQ latency and
wakes up the user-space thread waiting in the timerlat_fd.

The thread then starts to run, executes the timerlat measurement, prints
the thread scheduling latency and returns to user-space.

When the thread rereads the timerlat_fd, the tracer will print the
user-ret(urn) latency, which is an additional metric.

This additional metric is also traced by the tracer and can be used, for
example of measuring the context switch overhead from kernel-to-user and
user-to-kernel, or the response time for an arbitrary execution in
user-space.

The tracer supports one thread per CPU, the thread must be pinned to
the CPU, and it cannot migrate while holding the timerlat_fd. The reason
is that the tracer is per CPU (nothing prohibits the tracer from
allowing migrations in the future). The tracer monitors the migration
of the thread and disables the tracer if detected.

The timerlat_fd is only available for opening/reading when timerlat
tracer is enabled, and NO_OSNOISE_WORKLOAD is set.

The simplest way to activate this feature from user-space is:

 -------------------------------- %< -----------------------------------
 int main(void)
 {
	char buffer[1024];
	int timerlat_fd;
	int retval;
	long cpu = 0;	/* place in CPU 0 */
	cpu_set_t set;

	CPU_ZERO(&set);
	CPU_SET(cpu, &set);

	if (sched_setaffinity(gettid(), sizeof(set), &set) == -1)
		return 1;

	snprintf(buffer, sizeof(buffer),
		"/sys/kernel/tracing/osnoise/per_cpu/cpu%ld/timerlat_fd",
		cpu);

	timerlat_fd = open(buffer, O_RDONLY);
	if (timerlat_fd < 0) {
		printf("error opening %s: %s\n", buffer, strerror(errno));
		exit(1);
	}

	for (;;) {
		retval = read(timerlat_fd, buffer, 1024);
		if (retval < 0)
			break;
	}

	close(timerlat_fd);
	exit(0);
}
 -------------------------------- >% -----------------------------------

When disabling timerlat, if there is a workload holding the timerlat_fd,
the SIGKILL will be sent to the thread.

Link: https://lkml.kernel.org/r/69fe66a863d2792ff4c3a149bf9e32e26468bb3a.1686063934.git.bristot@kernel.org

Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: William White <chwhite@redhat.com>
Cc: Daniel Bristot de Oliveira <bristot@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
2023-06-22 10:39:56 -04:00
..
ABI dmaengine updates for v6.4 2023-05-03 11:11:56 -07:00
PCI
RCU
accel
accounting Scheduler changes for v6.4: 2023-04-28 14:53:30 -07:00
admin-guide cifs: correct references in Documentation to old fs/cifs path 2023-05-24 16:29:21 -05:00
arch A handful of late-arriving documentation fixes, plus one Spanish 2023-05-05 13:16:42 -07:00
arm ARM: SoC devicetree changes for 6.4 2023-04-25 12:11:54 -07:00
arm64 irqchip/gic-v3: Add Rockchip 3588001 erratum workaround 2023-04-18 17:31:17 +01:00
block Documentation/block: drop the request.rst file 2023-05-12 11:04:58 -06:00
bpf lsm/stable-6.4 PR 20230428 2023-04-29 10:17:05 -07:00
cdrom Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
core-api - Nick Piggin's "shoot lazy tlbs" series, to improve the peformance of 2023-04-27 19:42:02 -07:00
cpu-freq
crypto
dev-tools Mainly singleton patches all over the place. Series of note are: 2023-04-27 19:57:00 -07:00
devicetree Char/Misc driver fixes for 6.4-rc5 2023-06-04 08:32:30 -04:00
doc-guide
driver-api pwm: Changes for v6.4-rc1 2023-05-03 11:25:01 -07:00
fault-injection
fb
features
filesystems smb3: move Documentation/filesystems/cifs to Documentation/filesystems/smb 2023-05-24 16:29:21 -05:00
firmware-guide
firmware_class
fpga Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
gpu
hid
hwmon hwmon: (aquacomputer_d5next) Add support for Aquacomputer Aquastream XT 2023-04-21 07:27:23 -07:00
i2c
iio
images
infiniband
input
isdn
kbuild parisc: update kbuild doc. aliases for parisc64 2023-05-03 17:43:10 +02:00
kernel-hacking
leds - New Drivers 2023-05-02 10:36:02 -07:00
litmus-tests LKMM scripting updates for v6.4 2023-04-24 12:02:25 -07:00
livepatch Objtool changes for v6.4: 2023-04-28 14:02:54 -07:00
locking Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
loongarch
maintainer
mhi
mips
misc-devices
mm mm: page_table_check: Make it dependent on EXCLUSIVE_SYSTEM_RAM 2023-05-29 16:14:28 +01:00
netlabel
netlink netlink: specs: correct types of legacy arrays 2023-05-29 22:03:48 -07:00
networking mlx5-fixes-2023-05-24 2023-05-25 21:09:41 -07:00
nvdimm
nvme
pcmcia Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
peci
power regulator: consumer.rst: fix 'regulator_enable' typo. 2023-04-27 21:55:38 +01:00
powerpc
process docs: netdev: document the existence of the mail bot 2023-05-23 21:11:54 -07:00
riscv RISC-V Patches for the 6.4 Merge Window, Part 1 2023-04-28 16:55:39 -07:00
rust
s390 s390/iommu: get rid of S390_CCW_IOMMU and S390_AP_IOMMU 2023-05-17 15:20:18 +02:00
scheduler sh updates for v6.4 2023-04-27 17:41:23 -07:00
scsi
security lsm: move hook comments docs to security/security.c 2023-04-28 11:58:34 -04:00
sound ALSA: docs: Fix code block indentation in ALSA driver example 2023-05-03 08:08:25 +02:00
sphinx
sphinx-static
spi
staging Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
target
timers Documentation: use capitalization for chapters and acronyms 2023-05-16 12:49:31 -06:00
tools rtla/timerlat: Add auto-analysis only option 2023-04-25 19:26:17 -04:00
trace tracing/timerlat: Add user-space interface 2023-06-22 10:39:56 -04:00
translations A handful of late-arriving documentation fixes, plus one Spanish 2023-05-05 13:16:42 -07:00
usb
userspace-api cifs: correct references in Documentation to old fs/cifs path 2023-05-24 16:29:21 -05:00
virt VFIO updates for v6.4-rc1 2023-05-02 11:56:43 -07:00
w1
watchdog
.gitignore
Changes
CodingStyle
Kconfig
Makefile
SubmittingPatches
atomic_bitops.txt
atomic_t.txt
conf.py docs: turn off "smart quotes" in the HTML build 2023-04-20 17:53:18 -06:00
docutils.conf
dontdiff
index.rst
memory-barriers.txt
subsystem-apis.rst