From patchwork Fri Feb 23 15:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Yang X-Patchwork-Id: 205467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp656690dyb; Fri, 23 Feb 2024 07:28:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV0aI+slfOYiuw4DgIq4DU9E95m7j5H+pDl/BL5z1F00MHQVyA/egGJlhDzI6A8qsFymchCOoThdrqWJEE5nduyj2kK8w== X-Google-Smtp-Source: AGHT+IEc86Nd2FbhUoCZ7pHXGiFnqw94R1a6ZeJm7eSA0Vl5CVk3AqcjiljtzXqksw5gbmISzcSA X-Received: by 2002:a67:f65a:0:b0:470:4f15:d9d5 with SMTP id u26-20020a67f65a000000b004704f15d9d5mr38415vso.32.1708702089321; Fri, 23 Feb 2024 07:28:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708702089; cv=pass; d=google.com; s=arc-20160816; b=F1aEUPJavVqJYJSohodYGlzapgV+XEmtZNtVrNVg3tA3wr8aNhXlNyD1JogWS3r+Iv VwPrCnlaHRFQa4SfU8AQ0Ag+gwqAOl5C3CrQsr01FInJ2scXghjxiMwk8MEGOw2dfX86 kytqv+Wok5Jgx0q+yY5JJKu3r5WOG1E2DkSneuiYg+jCpFtlgkq5HugqtjjCoEFC6PUB 7s66xHMJCW+9Q/Fpf4dW2Yz9p/U7NVzpSq9CuQTncR9j0CXjqD7twVRvSl5JqAStdFPM FWGC6UTyxKQjzdXxbImu+OTcltdiZEBUIogmVGpPXpXSGo11M1UWMHE1SAQM/6aYu5XA Qlew== 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=1WtJEn9rrkVa/bjSgot6IPYIwTbNxSH5b4RJzV2SbPE=; fh=E+fjSkszu/3wtcymzZVrQck5XVLw8YkYnkF0SUB03B0=; b=Je4m3WFT9zDYnLS2Kj6WSPH0SixMhkWw5hiOWtsd32Zb0NkCXiA//hN2R2PMcrHdjr kI4uKGdJP4JEelz6XTjtNSF3PkUOPSOvLNQTiU6VHo8Fy4CtMFb0GtUXkA/kVQq71b0f ySAMWG08ZtDFsFsmE6ofD6+UXgmyZKQ7Cht+s+WIpnJaJSnyUjJLrWr4CpU6jMRogUmP W/aYIyL1dwIdZlRSGyRocryTMo1VH2CD3CyTJ6dfvizJ0DXNC9ofDdH15IEMsa6qIb0Y WOY+qvAyZiqfb7K5h2QHKFhYCPjPYsDR+g113xOE3MyfWWXf/e3dtRsa1OhjHSArzVBs SJtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=PbWbSYuq; 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-78605-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78605-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d20-20020a67c494000000b0046ed6d01618si2330053vsk.583.2024.02.23.07.28.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 07:28:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78605-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=PbWbSYuq; 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-78605-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78605-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E47421C244D4 for ; Fri, 23 Feb 2024 15:27:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0475684A35; Fri, 23 Feb 2024 15:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="PbWbSYuq" Received: from out203-205-251-85.mail.qq.com (out203-205-251-85.mail.qq.com [203.205.251.85]) (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 9CB4281ADA for ; Fri, 23 Feb 2024 15:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.251.85 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708701913; cv=none; b=DdIxahrmw/h0uQP7Hdic9buCah1eKXaBnjzfyR1yzGGMrwiZKhX/ObsKbcehvtE6dh7YjTULs9GnnUBVacY4N43cUlt3cf4dGM0bXcMPGEUeg4+W7rutK9StVZ0TgzWvQfB1YIMbe+Ry2tD/TMkQDPgMDkPPYPHgUJ+qVksau5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708701913; c=relaxed/simple; bh=3mPRgvG/sxlIoXBUhas58x8E5T3hKihVno9gegRRSsY=; h=Message-ID:From:To:Cc:Subject:Date:MIME-Version; b=qBwDMWL4jYRf8ATBA/wVToGOrLELIJnsn8rLf76jH2o4LY+jAvY+zqQ3aqpcTI6c3aMa0CfTFBKHqENaUmazA4PG/ASG8xMcyxA24QjFRySK5/tEa7XEzCK9c2e0OlXqqyZTHqoFf1cqY9ZjfF740oa0UR1gIFj0/P2xP3Lg63g= 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=PbWbSYuq; arc=none smtp.client-ip=203.205.251.85 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=1708701601; bh=1WtJEn9rrkVa/bjSgot6IPYIwTbNxSH5b4RJzV2SbPE=; h=From:To:Cc:Subject:Date; b=PbWbSYuqlkBXsfDanbDbc6IW/dpS96uAXWpwOnj5uSCygcD+0HJU9Eg+P6SSpf4Mm XjEAY8H2vGKBJS/kzhkleXYP+aglgcXbdLFz5z6ccUMbzyoPjEMfRaxKF0nPmOdBW/ 0pRLpoFaICWFVX7IkUUAzXVC/Pf+H7MYKYx2tmNs= Received: from localhost.localdomain ([2409:8a60:2a61:ef40:a0ce:972d:4d86:c925]) by newxmesmtplogicsvrszc5-1.qq.com (NewEsmtp) with SMTP id 364A3425; Fri, 23 Feb 2024 23:13:36 +0800 X-QQ-mid: xmsmtpt1708701216t4yxx0qhx Message-ID: X-QQ-XMAILINFO: OVFdYp27KdlJsKXaiJczxah/ErLlkAIfv+v45KbXjJkbrauQ89wGaYTDPJQt3B CpQa3hygeMYYxieIkL4Z/5vgF9iqqu0HZ2DIHlJ3jJz0jcCaaxq19SJXdkwNPOJgSAVbnle13oHa pMNJC10cwDm8VpNI/OXyG9PhMgC55uj2kw9PyxkO0t/C/f7EC0agMB7lQSVKWXQuHkiAtVmYTS9D SF40Dls/ZG3wY0jHKwGgsRyu7b77GHPAF8QJ3BMMtqdYVgMMhufnwHN1OYvMigUMcHyBIgo22vSr 729Va2mCC1Uy+VIZm4h38zCAiynnKJUQMjatXVGwHhU6yChX6twMNUBHowDakBMnDiwigbihW6Rx BPQGfA9N28vF30GsGWe1DWL8/iHqfnMwjQVSKFwnYa0f0MhQAFGe4b5mg0zCHYtFOZ+8HNqjO5mp 2vpXEorj65a5KhCvmpGdVBtQRTliuMk1gFVBskeEQBMAi6ItF/WXQi6ymspWxrr+TODUMRf1g99T OREBcqTSbPoz1c9CiPvY630CfUqRxWXJbW9deEmKSpQzRY+YwCUwnbM449s6Y1uNV/DkIHBkxGN7 MEL+eaExaCV/uNbJ02T8OVO3YAWLollHF0seqDw37WQvkII5zssIeIeTbwsgO1IcUuUr9/ci8aII RAraSRc8pw9XI9xWHto1Bg2gQ4y03LReWYLyUKf6fnQIlnzRKl68sp4MFIb0gdpipKbkR/3smbs/ RXOOUFBTQg7GFVeBWL0s0j/ll6h3lYYlB00qfov8y/Y37wzHtAEfG9brY29DeALVklaM34ie/APg zS96DAVbQFVQHDnM38ycKL4iRv0oJN9WAcDO4UOyoVNTRptcEN0emLpoRZSBt+YRXvT7e6/hPx6h ATttHaGbqpSWfi700fuJppiOfG387Z70aPQkNpSLe7GEmg18ZNbLiyGxxdNlMOXvxbFquk83U6cT CQE6McgfjpWN0lzeBx56ad/8KxHMPBWqipY5VTBGqfXbebcb+KK/W3cXKdAiVFN6DktdMVU3QA0t 5lmH1936FTJ7//App/xI7I9oSl3msAYRvhaVC3iw== X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: wenyang.linux@foxmail.com To: Steven Rostedt , Masami Hiramatsu , Ingo Molnar Cc: Wen Yang , Oleg Nesterov , Mathieu Desnoyers , Mel Gorman , Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH v2] exit: add exit_code to trace_sched_process_exit and move it earlier in do_exit() Date: Fri, 23 Feb 2024 23:13:32 +0800 X-OQ-MSGID: <20240223151332.388253-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791704002232495030 X-GMAIL-MSGID: 1791704002232495030 From: Wen Yang 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. Add exit_code to the TP trace_sched_process_exit() and move it earlier in do_exit(). This way a user-space monitor could detect the exits and potentially make some preparations in advance. Suggested-by: Steven Rostedt Signed-off-by: Wen Yang Cc: Steven Rostedt Cc: Oleg Nesterov Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Ingo Molnar Cc: Mel Gorman Cc: Peter Zijlstra Cc: linux-kernel@vger.kernel.org --- include/trace/events/sched.h | 28 +++++++++++++++++++++++++--- kernel/exit.c | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index dbb01b4b7451..c2e8655fd453 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -330,9 +330,31 @@ DEFINE_EVENT(sched_process_template, sched_process_free, /* * Tracepoint for a task exiting: */ -DEFINE_EVENT(sched_process_template, sched_process_exit, - TP_PROTO(struct task_struct *p), - TP_ARGS(p)); +TRACE_EVENT(sched_process_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 waiting on task to unschedule: diff --git a/kernel/exit.c b/kernel/exit.c index 493647fd7c07..48b6ed7f7760 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_process_exit(tsk, code); kcov_task_exit(tsk); kmsan_task_exit(tsk); @@ -866,7 +867,6 @@ void __noreturn do_exit(long code) if (group_dead) acct_process(); - trace_sched_process_exit(tsk); exit_sem(tsk); exit_shm(tsk);