From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90053259C9C for ; Fri, 15 May 2026 13:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778850525; cv=none; b=T76JhHbeeOue4zoZh5gnaA6h/ShabZRaAmtmhZkT6A6f6bfqDlyTmMvtVCWhh71AwITdRad8bgtAlDhq6LQ7c1qAOUgzR87pCh1n90rtdDzNJeuMIwe2GZOgRjNcCaNm6oIv6pL9pFBe60JK9Tr660XOB/bIOkqKTbgtxkw6YFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778850525; c=relaxed/simple; bh=DZRUwXImKlXe3MhgvWeIi4ZMiMl8dGgxIbSxw2YzVGs=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=az2lnw21t+cmx+ZVPtLr3Q7Kxh6Sdj/eU2YT5Ww9tIwur2c/Jn8PPhu+sqo8jwZlWVpvpkc+rLfbMFT5IrVMQ+0nooByf6Qj7kMT92x02yzULb9LAplnDwGpeRxeTIcvrtIOx/63A2pCzOlNCu0mFoXUSqGu1J5dSXNScJDEW0c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=e1V4m550; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=RsTfmlyz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e1V4m550"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="RsTfmlyz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778850522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=DZRUwXImKlXe3MhgvWeIi4ZMiMl8dGgxIbSxw2YzVGs=; b=e1V4m550bMOWcoY0dq4v3CMyfHq3b13gUnp7c4ykePozBkFyUP2rlPDxfkaWSoPikh3F5i RIywgV/ekz+gmWG1jVEjz3R+KcHFuobpgB/u4DFs4Cu5l50AOkgxkRLGNHZ6xsgHFaHeSz DuVJnAMammPLEYy23eRdvOuTnpHF6kA= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-KtQih3ppMhaY85gea4xqQQ-1; Fri, 15 May 2026 09:08:39 -0400 X-MC-Unique: KtQih3ppMhaY85gea4xqQQ-1 X-Mimecast-MFC-AGG-ID: KtQih3ppMhaY85gea4xqQQ_1778850518 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48fdca5c638so11999315e9.1 for ; Fri, 15 May 2026 06:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778850518; x=1779455318; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=DZRUwXImKlXe3MhgvWeIi4ZMiMl8dGgxIbSxw2YzVGs=; b=RsTfmlyzG/iQmjfg82igfbH8PduI3i3wLZGSQffTztfEmSRPawpLCaEBsKjG7RQ2D+ PwnyhrGH1z1x0+yn4QKZrfxRtHSaXmyn3ArEz+LIjEQ1o9MvBKDKEDNqFKsNp3r46EfJ 6iMLCvTDMmV6BXAt/jCUsHW2rmRGNw0j/+3HX8AhweXMhAde7sCPAk+OLiC151lcTy+9 lFU2tgIo5xyDrzPX2QWiFvKfxI7J/WBZNf3ovUQN0C+QfO2pfuqcVY0oWOumfFpiTSsN ceCCtaI8Cfm2o7JbNNsH0Br4aHOb2UjOQj8T2h1iPbq8lFJ+vSGHVNoxr5zWYaE/sZg3 64yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778850518; x=1779455318; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DZRUwXImKlXe3MhgvWeIi4ZMiMl8dGgxIbSxw2YzVGs=; b=RCMkiYJT+D9EtFnOOrhbh/8EbEHxhXrfqrWfiG6cngAzu/EtK3bWqXg/NOGqApaoMi 695tbbqdswL7vvjRBqhimSjio4efCsNo5WrEOdLJw/lH4xJZM3r+bN3ygUuACbfIkytd CTmtgcpIVOm7fEOjENl9MQH5GeheGDA06jXJGeQ0y3NTTapH6G7V9/AjNQr75ICU9dY8 +/XZK76F4VNc+DQU+MhR6fnnpJbyiTBeeFO4wlSspbl5LIunAVZgf7s60MEMd6WdXD27 /kJjxkx5VQAdtKoTLccDmCLt+PcWziU7mAsVUkyKUZMA24TeeYfmDAtszU0cG/Y2WAMW B8dA== X-Forwarded-Encrypted: i=1; AFNElJ+r9fyRy0xDN23ZOfC3uHZBd0yZ1RDRNx9bbDcGjGQPef5QjmJiKNP07qc0f/uTOgzsMrZ0y5yoHojfuCk=@vger.kernel.org X-Gm-Message-State: AOJu0YwGbgYr1ZXJYZhCy0Ap4ipEyiOGbjOQRS7fIgq0bV14CMRaKHGm 5EjfpxT1OrX3JnozBvSokrKeqRQu8qjAUQPFzXcCavAiRijMTq3jqVECvA+UbBFKDJ6Fh58tnF9 Ld5Hi5tTrSSyOIXC1lK3ek/Q6BhxUIUF94H0FDlTXKHNS+290ZFPXhSsuJxG1d5yIZw== X-Gm-Gg: Acq92OGkbsuixVvP7qy8KjAFRaHdydLkmB4JVsoBJ0vxmorjuxCLZYF+MkOqAyaIDwO bt7vTdZBHYY1uEkEUmZOz7nSmXwqkYRufd0U67OJx3eOrb/z9VxE8tqsZNld2P3yabSbsETUf3h jU8wjRT/OqQ9BAzfCkpePdySicwPYNOHVdPYKQmc1rNH8Oseo8ZjHcM0GYtQexJTr4h9G8BRojo BB9Uoi/y9WrbGhzs7IKz+BqDZw2dt7R3XGa5i2PK48bjBQ/SatK1F9ij9winPcB3a9PvRUcD8li RjLgBvLBeSIOTh081dVnCNmQk2PQ4N1WCgVlLTV9zT0KaeEimJQr8m76rEWXyKKKoUOfoohh+F3 1B4f5ln3OHsQhSDYAyRuF7ykUqyVemNNLCcPQBAyMLDXnVMjO/quvodzEK3K52teAibgcK+tEQn FJP9C2jg2i9wm62MmbRkR6TWPj6g== X-Received: by 2002:a05:600c:37ca:b0:489:1b10:d896 with SMTP id 5b1f17b1804b1-48fe59af198mr59725005e9.0.1778850517823; Fri, 15 May 2026 06:08:37 -0700 (PDT) X-Received: by 2002:a05:600c:37ca:b0:489:1b10:d896 with SMTP id 5b1f17b1804b1-48fe59af198mr59724095e9.0.1778850517152; Fri, 15 May 2026 06:08:37 -0700 (PDT) Received: from gmonaco-thinkpadt14gen3.rmtit.csb (212-8-243-115.hosted-by-worldstream.net. [212.8.243.115]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45d9ed2ffdfsm13109391f8f.15.2026.05.15.06.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 06:08:36 -0700 (PDT) Message-ID: <9afb6ae43ebde1308eab97a8e8025d4ab5d6da45.camel@redhat.com> Subject: Re: [RFC PATCH v2 08/10] rv/tlob: add tlob hybrid automaton monitor From: Gabriele Monaco To: wen.yang@linux.dev, Steven Rostedt Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 15 May 2026 15:08:35 +0200 In-Reply-To: References: Autocrypt: addr=gmonaco@redhat.com; prefer-encrypt=mutual; keydata=mDMEZuK5YxYJKwYBBAHaRw8BAQdAmJ3dM9Sz6/Hodu33Qrf8QH2bNeNbOikqYtxWFLVm0 1a0JEdhYnJpZWxlIE1vbmFjbyA8Z21vbmFjb0BrZXJuZWwub3JnPoiZBBMWCgBBFiEEysoR+AuB3R Zwp6j270psSVh4TfIFAmjKX2MCGwMFCQWjmoAFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgk Q70psSVh4TfIQuAD+JulczTN6l7oJjyroySU55Fbjdvo52xiYYlMjPG7dCTsBAMFI7dSL5zg98I+8 cXY1J7kyNsY6/dcipqBM4RMaxXsOtCRHYWJyaWVsZSBNb25hY28gPGdtb25hY29AcmVkaGF0LmNvb T6InAQTFgoARAIbAwUJBaOagAULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIXgBYhBMrKEfgLgd0WcK eo9u9KbElYeE3yBQJoymCyAhkBAAoJEO9KbElYeE3yjX4BAJ/ETNnlHn8OjZPT77xGmal9kbT1bC1 7DfrYVISWV2Y1AP9HdAMhWNAvtCtN2S1beYjNybuK6IzWYcFfeOV+OBWRDQ== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.1 (3.60.1-1.fc44) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2026-05-12 at 02:24 +0800, wen.yang@linux.dev wrote: > From: Wen Yang >=20 > diff --git a/Documentation/trace/rv/monitor_tlob.rst > b/Documentation/trace/rv/monitor_tlob.rst > new file mode 100644 > index 000000000000..91b592630b3f > --- /dev/null > +++ b/Documentation/trace/rv/monitor_tlob.rst > +Usage > +----- > + > +tracefs interface (uprobe-based external monitoring) > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > + > +The ``monitor`` tracefs file instruments an unmodified binary via uprobe= s. > +The format follows the ftrace ``uprobe_events`` convention (``PATH:OFFSE= T`` > +for the probe location, ``key=3Dvalue`` for configuration parameters):: > + > +=C2=A0 p PATH:OFFSET_START OFFSET_STOP threshold=3DUS > + > +The uprobe at ``OFFSET_START`` fires ``tlob_start_task()``; the uprobe a= t > +``OFFSET_STOP`` fires ``tlob_stop_task()``.=C2=A0 Both offsets are ELF f= ile > +offsets of entry points in ``PATH``.=C2=A0 ``PATH`` may contain ``:``; t= he last > +``:`` in the ``PATH:OFFSET_START`` token is the separator. > + > +To remove a binding, use ``-PATH:OFFSET_START``:: > + > +=C2=A0 echo 1 > /sys/kernel/tracing/rv/monitors/tlob/enable > + > +=C2=A0 echo "p /usr/bin/myapp:0x12a0 0x12f0 threshold=3D5000" \ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 > /sys/kernel/tracing/rv/monitors/tlob/mo= nitor > + > +=C2=A0 # Remove a binding > +=C2=A0 echo "-/usr/bin/myapp:0x12a0" > > /sys/kernel/tracing/rv/monitors/tlob/monitor > + > +=C2=A0 # List registered bindings > +=C2=A0 cat /sys/kernel/tracing/rv/monitors/tlob/monitor > + > +=C2=A0 # Read violations from the trace buffer > +=C2=A0 cat /sys/kernel/tracing/trace > + > +ioctl self-instrumentation (/dev/rv) > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I'm not particularly fond of ioctls, they aren't that flexible and in this way I don't really see an added value. In short, you're adding this so a program could instrument itself using ioctls instead of using uprobes, cannot the same thing be achieved using uprobes alone, e.g. by registering a function address or the current instruction pointer? If you really cannot do it with uprobes alone, wouldn't a sysfs/tracefs fil= e achieve a similar purpose without much of the boilerplate code? > + > +``/dev/rv`` is a shared RV character device.=C2=A0 Before using any moni= tor- > specific > +ioctl, the fd must be bound to a monitor via ``RV_IOCTL_BIND_MONITOR``.= =C2=A0 Each > +open fd has independent per-fd monitoring state:: > + > +=C2=A0 int fd =3D open("/dev/rv", O_RDWR); > + > +=C2=A0 /* Bind this fd to the tlob monitor. */ > +=C2=A0 struct rv_bind_args bind =3D { .monitor_name =3D "tlob" }; > +=C2=A0 ioctl(fd, RV_IOCTL_BIND_MONITOR, &bind); > + > +=C2=A0 struct tlob_start_args args =3D { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .threshold_us =3D 50000,=C2=A0=C2=A0 /* 5= 0 ms in microseconds */ > +=C2=A0 }; > +=C2=A0 ioctl(fd, TLOB_IOCTL_TRACE_START, &args); > + > +=C2=A0 /* ... code path under observation ... */ > + > +=C2=A0 int ret =3D ioctl(fd, TLOB_IOCTL_TRACE_STOP, NULL); > +=C2=A0 /* ret =3D=3D 0:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 within budget=C2=A0 */ > +=C2=A0 /* ret =3D=3D -EOVERFLOW: budget exceeded */ > + > +=C2=A0 close(fd); > + > +``TRACE_STOP`` returns ``-EOVERFLOW`` whenever the budget was exceeded. > +The HA timer calls ``da_monitor_reset()`` (storage remains); the > +synchronous ``ha_cancel_timer_sync()`` in ``tlob_stop_task()`` ensures t= he > +callback has completed before checking ``da_monitoring()``. > + > +Violation events > +~~~~~~~~~~~~~~~~ Since you are not documenting the detail_env_tlob tracepoint, is it something really required? It's deviating from the original RV purpose (run a model and spot violations) by adding further accounting, I'm fine with that if there is a documented need. In such case I would at the very least document its usage (thought I'd really like to be rid of it and let the curious user implement the accounting themselves). > + > +Budget violations are always reported via the ``error_env_tlob`` RV > +tracepoint (HA clock-invariant violation), regardless of which interface > +triggered them:: > + > +=C2=A0 cat /sys/kernel/tracing/trace > + > +To capture violations in a file:: > + > +=C2=A0 trace-cmd record -e error_env_tlob & > +=C2=A0 # ... run workload ... > +=C2=A0 trace-cmd report > + This is standard tracepoints usage, there's nothing about tlob we should document here. If you feel the existing RV documentation should expand this subject, feel free to contribute there. > +tracefs files > +------------- > + > +The following files are created under > +``/sys/kernel/tracing/rv/monitors/tlob/``: > + > +``enable`` (rw) > +=C2=A0 Write ``1`` to enable the monitor; write ``0`` to disable it. > + > +``desc`` (ro) > +=C2=A0 Human-readable description of the monitor. Same here, standard RV. > + > +``monitor`` (rw) > +=C2=A0 Write ``p PATH:OFFSET_START OFFSET_STOP threshold=3DUS`` > +=C2=A0 to bind two entry uprobes.=C2=A0 Write ``-PATH:OFFSET_START`` to = remove a > +=C2=A0 binding.=C2=A0 Read to list registered bindings in the same forma= t. And this is duplicating what mentioned above about uprobes, isn't it? > + > +Kernel API > +---------- > + > +.. kernel-doc:: kernel/trace/rv/monitors/tlob/tlob.c > +=C2=A0=C2=A0 :functions: tlob_start_task tlob_stop_task > + > +``tlob_start_task(task, threshold_us)`` > +=C2=A0 Begin monitoring *task* with a total latency budget of *threshold= _us* > +=C2=A0 microseconds.=C2=A0 Allocates per-task state, sets initial DA sta= te to > +=C2=A0 ``running``, resets ``clk_elapsed``, and arms the HA budget timer= . > +=C2=A0 Returns 0, -ENODEV (monitor disabled), -ERANGE (zero threshold), > +=C2=A0 -EALREADY (already monitoring), -ENOSPC (at capacity), or -ENOMEM= . > + > +``tlob_stop_task(task)`` > +=C2=A0 Stop monitoring *task*.=C2=A0 Synchronously cancels the HA timer = via > +=C2=A0 ``ha_cancel_timer_sync()``, checks ``da_monitoring()`` to determi= ne > outcome. > +=C2=A0 Returns 0 (clean stop, within budget), -EOVERFLOW (budget was exc= eeded), > +=C2=A0 -ESRCH (not monitored), or -EAGAIN (concurrent stop racing). > + Is kernel code going to use this API? RV monitors are meant to be enabled by userspace. What's the use-case here? > +Design notes > +------------ > + > +State transitions are driven by two tracepoints: > + > +- ``sched_switch``: ``prev_state =3D=3D 0`` (``TASK_RUNNING``, preempted= , > +=C2=A0 stays on runqueue) =E2=86=92 running=E2=86=92waiting; ``prev_stat= e !=3D 0`` (voluntarily > +=C2=A0 blocked, leaves runqueue) =E2=86=92 running=E2=86=92sleeping; ``n= ext`` pointer =E2=86=92 > +=C2=A0 waiting=E2=86=92running. > +- ``sched_wakeup``: task moves back onto the runqueue =E2=86=92 sleeping= =E2=86=92waiting. > + > +No ``waiting =E2=86=92 sleeping`` edge exists because a task can only bl= ock > +itself while executing on CPU.=C2=A0 ``try_to_wake_up()`` is also a no-o= p > +when ``__state =3D=3D TASK_RUNNING``, so ``sched_wakeup`` never fires wh= ile > +the task is in ``waiting`` state. That's probably a bit too detailed for this page. If you really want this information somewhere couldn't it stay in the code? Thanks, Gabriele