On Fri, 30 Oct 2026 22:34:35 +0000
David Laight <[email protected]> wrote:

> I suspect the trace code would be faster it is just copied the (first)
> 16 characters and worried about whether it was terminated later on.
> It does far more 'saves' than trace reads and their performance is
> much more important.

I'm assuming that the compiler would optimize:

+/*
+ * Copy task name to a buffer. Final result is always a NUL-terminated string.
+ */
+static __always_inline void copy_task_comm(char *dst, struct task_struct *tsk, 
size_t len)
+{
+       const char *_src = tsk->comm;
+       size_t _len = min(len, TASK_COMM_LEN);
+
+       if (!_len)
+               return;
+
+       memcpy(dst, _src, _len);
+       dst[_len - 1] = '\0';
+}
+

to basically:

        memcpy(dst, src, _len);
        dst[_len - 1] = '\0';

Where it already figured out _len at build time. Adding a single write of
the nul byte without any branches would likely be a couple of cycles at
max. It's all hot cache (from the memcpy) and writing a immediate.

I'm not worried that one line will cause any measurable overhead to the
tracing.

-- Steve

Reply via email to