Message ID | tencent_09CF49556CD442411A93D0E92ACC2B7E5D08@qq.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-76860-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp43164dyb; Thu, 22 Feb 2024 08:11:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVsSZ9facghpdAakBn1LnihsBANxxY297tcfO2L2GN1U6dvcgyCliD2nlcxO1PAT+aZgdPYrsHbTCHQ7uiaZ+l0it+D/w== X-Google-Smtp-Source: AGHT+IGOgqHw9AdYWXW5dZjgXvW6qZzvI/hBOGzvrCl74siYss9p8BRlAtKfKVKOyn7pcPyMpoHl X-Received: by 2002:a05:6a00:1a8b:b0:6e2:853e:3d60 with SMTP id e11-20020a056a001a8b00b006e2853e3d60mr4737213pfv.13.1708618284512; Thu, 22 Feb 2024 08:11:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708618284; cv=pass; d=google.com; s=arc-20160816; b=H1NTYWFNTeGLCb6OJwzELHPQHjxVY/lHHvsnG2GGFRpU/Y2MjNKvci8XSI6nBe/9Fb CI+Ct5y8Dfqm35iPqEYVdZ1NjQsPh2kZjKxQcmI2G6bZmjSQ8ldjBDmz14QxY5E/k5m9 k3vMgvI5zFwIK6+xKRSMLQp2PiLAOd9QX67Ik2JK6gEWsd3rHvoheJLBPvjFIAS05MVr L2W7O/i2OC/Nmugc6cg7xbYwNvuk+zyeRyTSM7tYzPw4QFRUmbx/6cQBqpCKXhesynFl 0MgTGC7VxnlCdH43PoqFu5qvvu82PyClv+BZocnd+4PRifnxzXt6lSBuW4pLjKxn7yoS SHwA== 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:date:subject:cc:to:from :message-id:dkim-signature; bh=vjLg0TSWsTe0chZQ3fuBODGo/vzvbbkVGlo25W/YgL8=; fh=E+fjSkszu/3wtcymzZVrQck5XVLw8YkYnkF0SUB03B0=; b=e65mYiZY5NmmrmTUhIGCtMEBRS3nfy9359P4yOn3zum1KJUkIwzIkIrQFOKaYf9AAo MrMOwmocdAU5VAbfhJp7l/KYm62uEeqrDmZd4hxO3bJ40vr7sca2PkkQ4ei0j1SQDw78 c7zuIsqAmuR6CK5xwSoLqVhzpd15UsZKHJIAz94uq5Gr0Zd1D4AvnKRO4bhGsfDgOGC1 CgF26b/Yzw2H81lQ0rWm3nNtZRRRRF9tPjGMhXG1twTlaacuS3n9sMajvV4y5VPsdSD4 jb0RTqZQq5WZkAH/eyY0G2xi+NAoFxhuwDBd45s50mX3glEwaZVdHeZw5MI4waecwC6Z YHPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=owEkeYMT; arc=pass (i=1 spf=pass spfdomain=foxmail.com dkim=pass dkdomain=foxmail.com dmarc=pass fromdomain=foxmail.com); spf=pass (google.com: domain of linux-kernel+bounces-76860-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76860-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ca27-20020a056a02069b00b005dc500d9af0si10819118pgb.450.2024.02.22.08.11.24 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 08:11:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76860-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=owEkeYMT; arc=pass (i=1 spf=pass spfdomain=foxmail.com dkim=pass dkdomain=foxmail.com dmarc=pass fromdomain=foxmail.com); spf=pass (google.com: domain of linux-kernel+bounces-76860-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76860-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com 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 5E68F288773 for <ouuuleilei@gmail.com>; Thu, 22 Feb 2024 16:11:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEEEA153BD4; Thu, 22 Feb 2024 16:10:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="owEkeYMT" Received: from out203-205-221-231.mail.qq.com (out203-205-221-231.mail.qq.com [203.205.221.231]) (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 74B57151CC5 for <linux-kernel@vger.kernel.org>; Thu, 22 Feb 2024 16:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708618204; cv=none; b=UIzJtW1nKXHmUGBi18QxXP0DMAiBmQer2ziGTQGBOlQNMPUYL8UeULJZNuWyxhngTxY2e8QU+U+idQ5EElxC+TO4GYERAjjqAmt0F4c5ezSgWxG8j0UUesmYiP7FcvJAIgIV+j0zMwhLiTsPTdCfiUWFEx3f3uIz3rgAkTZviWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708618204; c=relaxed/simple; bh=VAARJbyByjfYUowrYEBvOr5VJx+E5jEyLas79aJZyFg=; h=Message-ID:From:To:Cc:Subject:Date:MIME-Version; b=C17Q3nYcCW0mmmk78pFzC2IivKdkx3+psPGUX7UaSM4ssqj9Yohc6fJWmjtj1STyVfpfpGWSc7rYC9w9btWwydrXWbabvojjC9kE+H3yhuDx6OkPzSyaEC0QeABq3QR+ZHgfGXn4KYKj1YCaViO1jgaqsQzvRUNj1TWjrq4GmEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com; spf=pass smtp.mailfrom=foxmail.com; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b=owEkeYMT; arc=none smtp.client-ip=203.205.221.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1708617892; bh=vjLg0TSWsTe0chZQ3fuBODGo/vzvbbkVGlo25W/YgL8=; h=From:To:Cc:Subject:Date; b=owEkeYMTlWA81AQ2Ov455FK/7iNjh3ILUq4B2dPH3HRoJf5LdJFLczkRRS9en/olx V1l7rmOQSm6MKe0huQbmJFv8QQHSMcA8++jfp36OfWTsEqdQS+OXdtiLQe2/31pKhO G+8RayQWbZZMYPPcvwptgNogfcWQKFmVbo2OLluM= Received: from localhost.localdomain ([2409:8a60:2a61:ef40:7404:388f:486a:7747]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id 131B565A; Fri, 23 Feb 2024 00:04:49 +0800 X-QQ-mid: xmsmtpt1708617889t56zrz7dp Message-ID: <tencent_09CF49556CD442411A93D0E92ACC2B7E5D08@qq.com> X-QQ-XMAILINFO: N3l5ASPewLWqAyF+hdEE/ByG4KGYO1CseUekN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PUhxQsoeAVDbp3OJHYyFg= From: wenyang.linux@foxmail.com To: Steven Rostedt <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org>, Ingo Molnar <mingo@kernel.org> Cc: Wen Yang <wenyang.linux@foxmail.com>, Oleg Nesterov <oleg@redhat.com>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, Mel Gorman <mgorman@techsingularity.net>, Peter Zijlstra <peterz@infradead.org>, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] exit: add a tracepoint for profiling a task that is starting to exit Date: Fri, 23 Feb 2024 00:04:34 +0800 X-OQ-MSGID: <20240222160434.350595-1-wenyang.linux@foxmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791616125927791346 X-GMAIL-MSGID: 1791616125927791346 |
Series |
[1/2] exit: add a tracepoint for profiling a task that is starting to exit
|
|
Commit Message
Wen Yang
Feb. 22, 2024, 4:04 p.m. UTC
From: Wen Yang <wenyang.linux@foxmail.com> Currently coredump_task_exit() takes some time to wait for the generation of the dump file. But if the user-space wants to receive a notification as soon as possible it maybe inconvenient. Commit 2d4bcf886e42 ("exit: Remove profile_task_exit & profile_munmap") simplified the code, but also removed profile_task_exit(), which may prevent third-party kernel modules from detecting process exits timely. Add the new trace_sched_profile_task_exit() this way a user-space monitor could detect the exits and potentially make some preparations in advance. Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Peter Zijlstra <peterz@infradead.org> Cc: linux-kernel@vger.kernel.org --- include/trace/events/sched.h | 28 ++++++++++++++++++++++++++++ kernel/exit.c | 1 + 2 files changed, 29 insertions(+)
Comments
On 2024-02-22 11:04, wenyang.linux@foxmail.com wrote: > From: Wen Yang <wenyang.linux@foxmail.com> > > Currently coredump_task_exit() takes some time to wait for the generation > of the dump file. But if the user-space wants to receive a notification > as soon as possible it maybe inconvenient. > > Commit 2d4bcf886e42 ("exit: Remove profile_task_exit & profile_munmap") > simplified the code, but also removed profile_task_exit(), which may > prevent third-party kernel modules from detecting process exits timely. > > Add the new trace_sched_profile_task_exit() this way a user-space monitor > could detect the exits and potentially make some preparations in advance. I don't see any explanation justifying adding an extra tracepoint rather than just moving trace_sched_process_exit() earlier in do_exit(). Why is moving trace_sched_process_exit() earlier in do_exit() an issue, considering that any tracer interested in knowing the point where a task is really reclaimed (from zombie state) is trace_sched_process_free() called from delayed_put_task_struct() ? Thanks, Mathieu > > Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> > Cc: Oleg Nesterov <oleg@redhat.com> > Cc: Steven Rostedt <rostedt@goodmis.org> > Cc: Masami Hiramatsu <mhiramat@kernel.org> > Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> > Cc: Ingo Molnar <mingo@kernel.org> > Cc: Mel Gorman <mgorman@techsingularity.net> > Cc: Peter Zijlstra <peterz@infradead.org> > Cc: linux-kernel@vger.kernel.org > --- > include/trace/events/sched.h | 28 ++++++++++++++++++++++++++++ > kernel/exit.c | 1 + > 2 files changed, 29 insertions(+) > > diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h > index dbb01b4b7451..750b2f0bdf69 100644 > --- a/include/trace/events/sched.h > +++ b/include/trace/events/sched.h > @@ -341,6 +341,34 @@ DEFINE_EVENT(sched_process_template, sched_wait_task, > TP_PROTO(struct task_struct *p), > TP_ARGS(p)); > > +/* > + * Tracepoint for profiling a task that is starting to exit: > + */ > +TRACE_EVENT(sched_profile_task_exit, > + > + TP_PROTO(struct task_struct *task, long code), > + > + TP_ARGS(task, code), > + > + TP_STRUCT__entry( > + __array( char, comm, TASK_COMM_LEN ) > + __field( pid_t, pid ) > + __field( int, prio ) > + __field( long, code ) > + ), > + > + TP_fast_assign( > + memcpy(__entry->comm, task->comm, TASK_COMM_LEN); > + __entry->pid = task->pid; > + __entry->prio = task->prio; > + __entry->code = code; > + ), > + > + TP_printk("comm=%s pid=%d prio=%d exit_code=0x%lx", > + __entry->comm, __entry->pid, __entry->prio, > + __entry->code) > +); > + > /* > * Tracepoint for a waiting task: > */ > diff --git a/kernel/exit.c b/kernel/exit.c > index 493647fd7c07..f675f879a1b2 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -826,6 +826,7 @@ void __noreturn do_exit(long code) > > WARN_ON(tsk->plug); > > + trace_sched_profile_task_exit(tsk, code); > kcov_task_exit(tsk); > kmsan_task_exit(tsk); >
On 2024/2/23 00:25, Mathieu Desnoyers wrote: > On 2024-02-22 11:04, wenyang.linux@foxmail.com wrote: >> From: Wen Yang <wenyang.linux@foxmail.com> >> >> Currently coredump_task_exit() takes some time to wait for the generation >> of the dump file. But if the user-space wants to receive a notification >> as soon as possible it maybe inconvenient. >> >> Commit 2d4bcf886e42 ("exit: Remove profile_task_exit & profile_munmap") >> simplified the code, but also removed profile_task_exit(), which may >> prevent third-party kernel modules from detecting process exits timely. >> >> Add the new trace_sched_profile_task_exit() this way a user-space monitor >> could detect the exits and potentially make some preparations in advance. > > I don't see any explanation justifying adding an extra tracepoint > rather than just moving trace_sched_process_exit() earlier in do_exit(). > > Why is moving trace_sched_process_exit() earlier in do_exit() an issue, > considering that any tracer interested in knowing the point where a task > is really reclaimed (from zombie state) is trace_sched_process_free() > called from delayed_put_task_struct() ? > > Thanks, > > Mathieu > Thanks. We will make the modifications according to your suggestions. -- Best wishes, Wen >> >> Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> >> Cc: Oleg Nesterov <oleg@redhat.com> >> Cc: Steven Rostedt <rostedt@goodmis.org> >> Cc: Masami Hiramatsu <mhiramat@kernel.org> >> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> >> Cc: Ingo Molnar <mingo@kernel.org> >> Cc: Mel Gorman <mgorman@techsingularity.net> >> Cc: Peter Zijlstra <peterz@infradead.org> >> Cc: linux-kernel@vger.kernel.org >> --- >> include/trace/events/sched.h | 28 ++++++++++++++++++++++++++++ >> kernel/exit.c | 1 + >> 2 files changed, 29 insertions(+) >> >> diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h >> index dbb01b4b7451..750b2f0bdf69 100644 >> --- a/include/trace/events/sched.h >> +++ b/include/trace/events/sched.h >> @@ -341,6 +341,34 @@ DEFINE_EVENT(sched_process_template, >> sched_wait_task, >> TP_PROTO(struct task_struct *p), >> TP_ARGS(p)); >> +/* >> + * Tracepoint for profiling a task that is starting to exit: >> + */ >> +TRACE_EVENT(sched_profile_task_exit, >> + >> + TP_PROTO(struct task_struct *task, long code), >> + >> + TP_ARGS(task, code), >> + >> + TP_STRUCT__entry( >> + __array( char, comm, TASK_COMM_LEN ) >> + __field( pid_t, pid ) >> + __field( int, prio ) >> + __field( long, code ) >> + ), >> + >> + TP_fast_assign( >> + memcpy(__entry->comm, task->comm, TASK_COMM_LEN); >> + __entry->pid = task->pid; >> + __entry->prio = task->prio; >> + __entry->code = code; >> + ), >> + >> + TP_printk("comm=%s pid=%d prio=%d exit_code=0x%lx", >> + __entry->comm, __entry->pid, __entry->prio, >> + __entry->code) >> +); >> + >> /* >> * Tracepoint for a waiting task: >> */ >> diff --git a/kernel/exit.c b/kernel/exit.c >> index 493647fd7c07..f675f879a1b2 100644 >> --- a/kernel/exit.c >> +++ b/kernel/exit.c >> @@ -826,6 +826,7 @@ void __noreturn do_exit(long code) >> WARN_ON(tsk->plug); >> + trace_sched_profile_task_exit(tsk, code); >> kcov_task_exit(tsk); >> kmsan_task_exit(tsk); >
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index dbb01b4b7451..750b2f0bdf69 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -341,6 +341,34 @@ DEFINE_EVENT(sched_process_template, sched_wait_task, TP_PROTO(struct task_struct *p), TP_ARGS(p)); +/* + * Tracepoint for profiling a task that is starting to exit: + */ +TRACE_EVENT(sched_profile_task_exit, + + TP_PROTO(struct task_struct *task, long code), + + TP_ARGS(task, code), + + TP_STRUCT__entry( + __array( char, comm, TASK_COMM_LEN ) + __field( pid_t, pid ) + __field( int, prio ) + __field( long, code ) + ), + + TP_fast_assign( + memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __entry->pid = task->pid; + __entry->prio = task->prio; + __entry->code = code; + ), + + TP_printk("comm=%s pid=%d prio=%d exit_code=0x%lx", + __entry->comm, __entry->pid, __entry->prio, + __entry->code) +); + /* * Tracepoint for a waiting task: */ diff --git a/kernel/exit.c b/kernel/exit.c index 493647fd7c07..f675f879a1b2 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -826,6 +826,7 @@ void __noreturn do_exit(long code) WARN_ON(tsk->plug); + trace_sched_profile_task_exit(tsk, code); kcov_task_exit(tsk); kmsan_task_exit(tsk);