Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp112686lqo; Wed, 27 Mar 2024 08:15:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUDkIpACbIxYPrvvnG7bJLU08yEN6+BaPiL3iIdb92EayTfDivrDsv4uTxzQrxw1cVECqNRBr3zeQbgV9zcRiQM0lJK6YvjeATcoff3/A== X-Google-Smtp-Source: AGHT+IHpvexj+pW16Myg6OUpUA+4QLoKj5RYx3zdooE2+/1LwYlZCWheaw46egshzC+yYglog3Qs X-Received: by 2002:a05:6358:938c:b0:17f:4936:39ec with SMTP id h12-20020a056358938c00b0017f493639ecmr3932331rwb.10.1711552547936; Wed, 27 Mar 2024 08:15:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711552547; cv=pass; d=google.com; s=arc-20160816; b=FlMBiamGKBWlbvlLxq4HxmZIPoZ/Xm5Du3i/N7FZvEPsYl/xZSXBsatN4XsMODwvFb gI+7ToMttjgu5Hyj08kwVR8Mep+8Vfdx/xiCFqnis913IvMliWQ5wJxgyISSQgOWQled EKQkyc61wZCigjvlLpNDhIywVwpAOJQo+5HyW/CBOXZFWOLp+y55ANcUH0LHh4U+nxiT BEiWIAzugiLf+A9ZpwAPKFVL4VOkr85zbqq6HwpkAPKn6hvZrFLW7jysnIM2bqsB9rk0 THE+5F3kLhpCAauqQ1YtotMG1UPyMA/GbBTNDk94H2GobTFDQ7XVw3KTXHQ45fbZsBh5 uAeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=Vc1xA+qNHfX/+3M2nRAJyMXBCQhMZpS8kjFeKkkuy8g=; fh=clGNA+tedvB5MV/1cgdbbnpJZ1sf4uaGHoOUfF5stPk=; b=fqGuuLr/rl/P9jLvpBaUzbYmArP992oCmNmOl0fq8n9diqThg0PkQ0tf7R7gLI5lpi iPpMPX0emZcq1awp9hNYNQRWCYRyB9ToXBpe8v9usS48T1GAUWPaUE83bGWUHf5sbUCD gqMgYo1IjoGf/EVe33ZSC7DnmqffW1DHOnm7yXTwxgpneHC3JwNKQE8kGGCrWJuy1jTN Own7W8qK3UXv8Ms9eELrTSyRxRhrks1lwuOpBHNrByrd3XRrMwCdOB2ohd8xryqYBnOO XHDNVvlTfDyNDddSQ0GH9SZI6yMRbpnOmnGUJr8P6KCjhqj3vgZEFXU2hG/uHqBWobYj xUsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-121427-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121427-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y33-20020a631821000000b005d9252c9d05si11808676pgl.103.2024.03.27.08.15.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:15:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121427-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-121427-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121427-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 228842C5B99 for ; Wed, 27 Mar 2024 15:04:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58C2A1474B1; Wed, 27 Mar 2024 14:23:55 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D1D0614535D; Wed, 27 Mar 2024 14:23:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711549434; cv=none; b=ngNwIiSdRROELj3XeEw5m0RtVeMsR+MWkrI/7alHmjRIm8NQ6aAFnhkrcr4FoZGnMutbKHq4+K4EkuqLg1ayf56IOQl4ZBf7qmt3gOu89aR8ELn/AR/U7vIy3h7ZLiL3YmUbT9ki0nDNoqLzElGxTB2pGM9tzrMmW4sHRDeNcQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711549434; c=relaxed/simple; bh=BmZ4SjxSQBnkpuUFtgR3wQXxh1obJ6n5r0ucuS+Wj4k=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YMilRaZRvlDVdNTUS4PBRb6kVK9YaZJw7FU98e/AntXHg7mp3CHt+isYZ1vPsZSTf20bZ776bpLK4BuozlIvKzM5nXYTNQP00LLfsHlbzSPTrzjkOrhH0uG3jloOo3M9GZJwMOa5Fu4mOw9gpKIMhlCuQdpFHHtpjJ3liFc5prM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8748DC433F1; Wed, 27 Mar 2024 14:23:53 +0000 (UTC) Date: Wed, 27 Mar 2024 10:26:34 -0400 From: Steven Rostedt To: Tio Zhang Cc: Masami Hiramatsu , Mathieu Desnoyers , Ingo Molnar , Peter Zijlstra , , , , Subject: Re: [PATCH] trace/sched: add tgid for sched_wakeup_template Message-ID: <20240327102634.17013392@gandalf.local.home> In-Reply-To: <20240327084948.GA28114@didi-ThinkCentre-M930t-N000> References: <20240327084948.GA28114@didi-ThinkCentre-M930t-N000> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 27 Mar 2024 16:50:57 +0800 Tio Zhang wrote: > By doing this, we are able to filter tasks by tgid while we are > tracing wakeup events by ebpf or other methods. > > For example, when we care about tracing a user space process (which has > uncertain number of LWPs, i.e, pids) to monitor its wakeup latency, > without tgid available in sched_wakeup tracepoints, we would struggle > finding out all pids to trace, or we could use kprobe to achieve tgid > tracing, which is less accurate and much less efficient than using > tracepoint. This is a very common trace event, and I really do not want to add more data than necessary to it, as it increases the size of the event which means less events can be recorded on a fixed size trace ring buffer. Note, you are not modifying the "tracepoint", but you are actually modifying a "trace event". "tracepoint" is the hook in the kernel code: trace_sched_wakeup() "trace event" is defined by TRACE_EVENT() macro (and friends) that defines what is exposed in the tracefs file system. I thought ebpf could hook directly to the tracepoint which is: trace_sched_wakeup(p); I believe you can have direct access to the 'p' before it is processed from ebpf. There's also "trace probes" (I think we are lacking documentation on this, as well as event probes :-p): $ gdb vmlinux (gdb) p &((struct task_struct *)0)->tgid $1 = (pid_t *) 0x56c (gdb) p &((struct task_struct *)0)->pid $2 = (pid_t *) 0x568 # echo 't:wakeup sched_waking pid=+0x568($arg1):u32 tgid=+0x56c($arg1):u32' > /sys/kernel/tracing/dynamic_events # trace-cmd start -e wakeup # trace-cmd show trace-cmd-7307 [003] d..6. 599486.485762: wakeup: (__probestub_sched_waking+0x4/0x10) pid=845 tgid=845 bash-845 [001] d.s4. 599486.486136: wakeup: (__probestub_sched_waking+0x4/0x10) pid=17 tgid=17 bash-845 [001] d..4. 599486.486336: wakeup: (__probestub_sched_waking+0x4/0x10) pid=5516 tgid=5516 kworker/u18:2-5516 [001] d..4. 599486.486445: wakeup: (__probestub_sched_waking+0x4/0x10) pid=818 tgid=818 -0 [001] d.s4. 599486.491206: wakeup: (__probestub_sched_waking+0x4/0x10) pid=17 tgid=17 -0 [001] d.s5. 599486.493218: wakeup: (__probestub_sched_waking+0x4/0x10) pid=17 tgid=17 -0 [001] d.s4. 599486.497200: wakeup: (__probestub_sched_waking+0x4/0x10) pid=17 tgid=17 -0 [003] d.s4. 599486.829209: wakeup: (__probestub_sched_waking+0x4/0x10) pid=70 tgid=70 The above attaches to the tracepoint and $arg1 is the 'struct task_struct *p'. -- Steve > > Signed-off-by: Tio Zhang > Signed-off-by: Dylane Chen > --- > include/trace/events/sched.h | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h > index dbb01b4b7451..ea7e525649e5 100644 > --- a/include/trace/events/sched.h > +++ b/include/trace/events/sched.h > @@ -149,6 +149,7 @@ DECLARE_EVENT_CLASS(sched_wakeup_template, > __field( pid_t, pid ) > __field( int, prio ) > __field( int, target_cpu ) > + __field( pid_t, tgid ) > ), > > TP_fast_assign( > @@ -156,11 +157,12 @@ DECLARE_EVENT_CLASS(sched_wakeup_template, > __entry->pid = p->pid; > __entry->prio = p->prio; /* XXX SCHED_DEADLINE */ > __entry->target_cpu = task_cpu(p); > + __entry->tgid = p->tgid; > ), > > - TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d", > + TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d tgid=%d", > __entry->comm, __entry->pid, __entry->prio, > - __entry->target_cpu) > + __entry->target_cpu, __entry->tgid) > ); > > /*