From patchwork Thu Aug 3 08:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 130467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1064982vqx; Thu, 3 Aug 2023 04:03:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHES7asmzrV9amT5T1eHUHg6ufycrn2MYatpSkksZFHNwdMuY9g624/6tWII3dJFUI3I8dT X-Received: by 2002:a05:6808:1802:b0:3a7:4fff:6483 with SMTP id bh2-20020a056808180200b003a74fff6483mr7813350oib.15.1691060634431; Thu, 03 Aug 2023 04:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691060634; cv=none; d=google.com; s=arc-20160816; b=kxXHdgqdvuB3aku3A1zQ+de3gtIJy+lPj6U7ro/+BSv9hYFOyh6zm/+AXvHcpixY0C keKQElFF4o7Dji7u991Oiu+7FXD3563nlc06y1q7uZzk0DlH1+F65m9Y0ljqMjD1RPk+ IIxpQVY2ZkV2XFL3Z7TdzPqbtngsJQCyKZWW3bVBW9CIJrCroKv6xbh/ZEkiYuBYKqjp +BE4rCaOzRNzwzarz+e9WI4diS9HDHRK9hFgwUXe399s6QP6uyKC2NVgTWhzp1nLEMJ+ 7b7qZsZaq1dgEXg5xDLclIlRAvoBtWnx+cwt6kK95IxWNDOm+u3yiMAvRT2sqvv/cTGb jg2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6kMReHmvqASQi9h76AGb1J6S3mur9uz2u2XL40ZYDh4=; fh=TgT5K4Z1kLXalrYfkT8XvOWNi122otFfxWyimjdT30Y=; b=B3rUGhYaDOns9SCONl0wetSthQnBEuWA1YDHD9c7UUqGYBHRZ1kg6bsnsra7yb9i0T 89mn+UVNiX1FVP1QEevDlulohvI+bhZUzCjLsoM+X6Mw/8vd+G9IK7DmJpWoWLhHW10+ iaH9PgfydKsn2wNIYubeNO9rC0Uw1Xns67DTV6yDV308jWtBelwqEM7FJDpkqQ1ewx4O IBZujYg5yTXGlGbHZNGel6wuKrjUVNrxslwZgjNRFVpVmlsctJQeyF2iF3A3BU6wynvg jMd/HBz3pSlerdxJ2kMpN09lZ7fhO0hAx9e6fhc1Zwx1A8nKOzhWbrDhi/eqqCGfTFXQ IBoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VVB9J5Tl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oa1-20020a17090b1bc100b0025ebac2314asi2976480pjb.180.2023.08.03.04.03.29; Thu, 03 Aug 2023 04:03:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VVB9J5Tl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234493AbjHCIgx (ORCPT + 99 others); Thu, 3 Aug 2023 04:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjHCIgV (ORCPT ); Thu, 3 Aug 2023 04:36:21 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83E4F122; Thu, 3 Aug 2023 01:34:54 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686efb9ee0cso605435b3a.3; Thu, 03 Aug 2023 01:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691051694; x=1691656494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6kMReHmvqASQi9h76AGb1J6S3mur9uz2u2XL40ZYDh4=; b=VVB9J5TldtSc15eRKvxQumCP3QnvCdg5a0fl1cB1K5zggdkWOSGh+96PqR4SxqFVDe fvpzIOyv+Aa0WQJopul54plI5TGP97siH5RvMXAvtyzBBvcDZK32toG7bW87qsX9gV/5 KIuT3KcCAM/FsAQAuTM9baJlPYdC/e7Ym6OJFfpCmHmi8Cd2ltHhlSct8YsXBZeVR7C2 WsiMZmdl3z1CZTB/lkX5/tdMv/ZrOOH+mj8ED3ObcOSF8qvDDrHk1lOoKcX/EX3nGX6d hdbLtKztMLiELfN1j+HlBgXinMVb/QcBf+8h91qGpPzu9qTpfv2RA47cRjWmpkMR5bK+ awEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691051694; x=1691656494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6kMReHmvqASQi9h76AGb1J6S3mur9uz2u2XL40ZYDh4=; b=J9M68V7Wt1nlXCBhE7/7I4lvsoQkUZTXNp82PGWEw2d15o3P4qzZvxWyv+5E+PYOoQ UMmDXR5wjoCfglTXkLiIfLvPYOccakiO3/mh5wx/wqNh5uPyCjmIeTVUgBntF6WxJ+9P U2c3kjgQw2Y9d0HE0R2NXp5jVfIukslLWUSek7hlFW23iBtrDxKz1GIGiKFQEjSjMZAs euSBTTjeLql1DzAFgU3RL2B1SjNXPgdWqnnV+93CuBJut3I7/p4Fjhec0t5LtvZyA+o4 9DwsEdHltpBzajbPzYc7VIYnmHpAzCsYV+YimgfnZN1GHCIJ2QUmWCDhEmoaJn5GSJd8 hTLg== X-Gm-Message-State: ABy/qLZqRiq/i+Vo40otJQCpyo9++ZZy3RiDCiuCSWYZw41jSzlIcVBq X1r837KWMrVn52N51x9W+Z8= X-Received: by 2002:a05:6a20:2c98:b0:134:1011:8582 with SMTP id g24-20020a056a202c9800b0013410118582mr15334413pzj.47.1691051693857; Thu, 03 Aug 2023 01:34:53 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.83]) by smtp.googlemail.com with ESMTPSA id r6-20020a63b106000000b00563feb7113dsm12541876pgf.91.2023.08.03.01.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 01:34:53 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Adrian Hunter , Alexander Shishkin , Arnaldo Carvalho de Melo , Ian Rogers , Ingo Molnar , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra , Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v6 4/5] sched, tracing: add to report task state in symbolic chars Date: Thu, 3 Aug 2023 04:33:51 -0400 Message-ID: <20230803083352.1585-5-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803083352.1585-1-zegao@tencent.com> References: <20230803083352.1585-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773201235618821530 X-GMAIL-MSGID: 1773205595707166358 Internal representations of task state are likely to be changed or ordered, and reporting them to userspace without exporting them as part of API is basically wrong, which can easily break a userspace observability tool as kernel evolves. For example, perf suffers from this and still reports wrong states as of this writing. OTOH, some masqueraded states like TASK_REPORT_IDLE and TASK_REPORT_MAX are also reported inadvertently, which confuses things even more and most userspace tools do not even take them into consideration. So add a new variable in company with the old raw value to report task state in symbolic chars, which are self-explaining and no further translation is needed. Of course this does not break any userspace tool. Note for PREEMPT_ACTIVE, we introduce 'p' to report it and use the old conventions for the rest. Signed-off-by: Ze Gao Reviewed-by: Masami Hiramatsu (Google) Acked-by: Ian Rogers --- include/trace/events/sched.h | 44 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 43492daefa6f..ae5b486cc969 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -6,6 +6,7 @@ #define _TRACE_SCHED_H #include +#include #include #include #include @@ -214,6 +215,27 @@ static inline short __trace_sched_switch_state(bool preempt, return state ? (1 << (state - 1)) : state; } + +static inline char __trace_sched_switch_state_char(bool preempt, + unsigned int prev_state, + struct task_struct *p) +{ + long state; + +#ifdef CONFIG_SCHED_DEBUG + WARN_ON_ONCE(p != current); +#endif /* CONFIG_SCHED_DEBUG */ + + /* + * For PREEMPT_ACTIVE, we introduce 'p' to report it and use the old + * conventions for the rest. + */ + if (preempt) + return 'p'; + + state = __task_state_index(prev_state, p->exit_state); + return task_index_to_char(state); +} #endif /* CREATE_TRACE_POINTS */ /* @@ -236,6 +258,7 @@ TRACE_EVENT(sched_switch, __array( char, prev_comm, TASK_COMM_LEN ) __array( char, next_comm, TASK_COMM_LEN ) __field( short, prev_state ) + __field( char, prev_state_char ) ), TP_fast_assign( @@ -246,26 +269,13 @@ TRACE_EVENT(sched_switch, memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); + __entry->prev_state_char = __trace_sched_switch_state_char(preempt, prev_state, prev); /* XXX SCHED_DEADLINE */ ), - TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d", - __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, - - (__entry->prev_state & (TASK_REPORT_MAX - 1)) ? - __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|", - { TASK_INTERRUPTIBLE, "S" }, - { TASK_UNINTERRUPTIBLE, "D" }, - { __TASK_STOPPED, "T" }, - { __TASK_TRACED, "t" }, - { EXIT_DEAD, "X" }, - { EXIT_ZOMBIE, "Z" }, - { TASK_PARKED, "P" }, - { TASK_DEAD, "I" }) : - "R", - - __entry->prev_state & TASK_REPORT_MAX ? "+" : "", - __entry->next_comm, __entry->next_pid, __entry->next_prio) + TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%c ==> next_comm=%s next_pid=%d next_prio=%d", + __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, __entry->prev_state_char, __entry->next_comm, + __entry->next_pid, __entry->next_prio) ); /*