Message ID | 20230803083352.1585-2-zegao@tencent.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1022743vqx; Thu, 3 Aug 2023 02:34:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFoF0dm6/yD/lZXaLU7/4xTxE7MS1OQkbRndTx5DJiHhWvohpSrEpJyU24J6e6kOpdM5/zH X-Received: by 2002:a05:620a:3729:b0:76c:c450:b987 with SMTP id de41-20020a05620a372900b0076cc450b987mr9388865qkb.62.1691055242349; Thu, 03 Aug 2023 02:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691055242; cv=none; d=google.com; s=arc-20160816; b=Bjaj1ZwtZo/TA7vg79XjSGE1UK48I8RJwErfXUjhhAP9iTIcZ+plrNjdnL3Bj8RPqW CR/Ag+CJchWIPp0yCegXdVaf0S9xl2ebfrfM39cMBGwu0cxsUXU772b4UwZXuZ0t70HD twRlW+2XwhhpsmGrcpUIAte1p0LlWsqY1pZLV69tL+zULa00Ki2Ynri3eb7jvu3KYDvS i2BCdsCcoUz5wRo3oAKKhefkoGidqfRXsu7m+nunRcmOqzAZCrdsKKSySuOKYkKxmStF AfTpHDL/ZjJE3Eol9arVypvg3Et18zalKulY2BfSKVjLBu/lkIS1QfSc3UW2ox4j76ML jVcQ== 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=CzdBr4YE6+e2aCPihxyG1VP6AlkYIgUBNXtEC6jGkqA=; fh=TgT5K4Z1kLXalrYfkT8XvOWNi122otFfxWyimjdT30Y=; b=a0uHgUVwXj5kG7GLB4dQpPN3Vex5N1Dx37D16b8oBUViOzI4c6AOImrwf8zuJjR8hz ZSAkAlvXy/z//O7m+IrhK2nK7KP0XYfEsb6p/XqVcVFAOqBmDbh0GOhKivOqtTjDpUMd na3h1Ua09lilgmlUcgBe6p4nKBRXVJOpMPOI11l7r3BNQ1+vyA9e2tIRNPSJxekkBl7C SGEuqmO6Yi80lCJ+gZqXa14UxaPxvlnf0hKNEopIHyVSFKW0ZDzb1p9F7jwsVFr6WadF H286/NRUwXA5ZEzCbpKNM6oNQ9effcivLJzD1mH3Oyn10U7wlakYMu3MVL4fRs9j2E8f mo7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Y/9r8JJK"; 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 z16-20020a634c10000000b005639fa45a28si1673538pga.630.2023.08.03.02.33.48; Thu, 03 Aug 2023 02:34:02 -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="Y/9r8JJK"; 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 S233593AbjHCIgj (ORCPT <rfc822;jeff.pang.chn@gmail.com> + 99 others); Thu, 3 Aug 2023 04:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234389AbjHCIgC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Aug 2023 04:36:02 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248723C31; Thu, 3 Aug 2023 01:34:36 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686b91c2744so481121b3a.0; Thu, 03 Aug 2023 01:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691051675; x=1691656475; 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=CzdBr4YE6+e2aCPihxyG1VP6AlkYIgUBNXtEC6jGkqA=; b=Y/9r8JJKfyClJG9K8FJm7KPjugSxpks8rCNhdwQOcJ/bv6c8+pq3lK1IGeChGXO2LC pi3sH0DN49vBEdT3Qsn6L3k7bSFjv45LF32+NLCeRjTucTTcel6FNw6g4Jf1HIPX/Byh CFPwads8yzANusFzRsqrcp27YQlhFSCVP5tt1F7ywMOWKqRZA3T1GHLOuCt/Vodga/mc +OGFmPsQHN+3DHmzldqn5nYkzEAv4BpH2ReuCijEBmP7XjPi3iEwm3SSh7uEDwWSvO3Z gMRmxZJVK+ePNtOwjYugvmX3+8FoHs7WFHenPW/eFPImn5eDtu4qcJN3QTr6B0nuxHvF bYzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691051675; x=1691656475; 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=CzdBr4YE6+e2aCPihxyG1VP6AlkYIgUBNXtEC6jGkqA=; b=QN+XxRPsEHEipReA3y+RX6zVTq2/ihrkm0k65yztcS5nZIdmijhdTjMTaQM6It9Lw1 E1W0UUe/pO3RfhoEbVCqdtxRqWWjVGy7mGDjChveeSHICtOdacRbwLHil5JBmbZtASdO NWR3tvL4W7cUthaYQ66uL2VckgTTNAaYEsbxnol2sm/D28nE8j/skJcmp6JXJ3pwIdDp u2C3RiuLe+BfcXGEznLgmDp+BcSPf0yXjNy4OtUjuf1SvF762MjGql+XbE6mCTDyAt/P ZEBKi7Ii+kxPy6v7Cu5Bs2ul4mYQUwExUQa9Xhg0qGHr+yiia9JGmfemYfawNuMiotzS kSAg== X-Gm-Message-State: ABy/qLZ81Il02Zfit6KrJC2RY7F9Q7duPWA2s2ixeVS/bp1P0Pm1Xs0l SI/lce4vYpJ+aHIR7GekimI= X-Received: by 2002:a05:6a00:15d6:b0:682:a62a:ec36 with SMTP id o22-20020a056a0015d600b00682a62aec36mr22266054pfu.15.1691051675648; Thu, 03 Aug 2023 01:34:35 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 01:34:35 -0700 (PDT) From: Ze Gao <zegao2021@gmail.com> X-Google-Original-From: Ze Gao <zegao@tencent.com> To: Adrian Hunter <adrian.hunter@intel.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Ian Rogers <irogers@google.com>, Ingo Molnar <mingo@redhat.com>, Jiri Olsa <jolsa@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Masami Hiramatsu <mhiramat@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Steven Rostedt <rostedt@goodmis.org> Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao <zegao@tencent.com> Subject: [RFC PATCH v6 1/5] perf sched: sync state char array with the kernel Date: Thu, 3 Aug 2023 04:33:48 -0400 Message-ID: <20230803083352.1585-2-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 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773199941800187329 X-GMAIL-MSGID: 1773199941800187329 |
Series |
fix task state report from sched tracepoint
|
|
Commit Message
Ze Gao
Aug. 3, 2023, 8:33 a.m. UTC
Update state char array and then remove unused and stale
macros, which are kernel internal representations and not
encouraged to use anymore.
Signed-off-by: Ze Gao <zegao@tencent.com>
---
tools/perf/builtin-sched.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
Comments
On Thu, 3 Aug 2023 04:33:48 -0400 Ze Gao <zegao2021@gmail.com> wrote: Hi Ze, > Update state char array and then remove unused and stale > macros, which are kernel internal representations and not > encouraged to use anymore. > A couple of things. First, the change logs of every commit need to specify the "why". The subject can say "what", but the change log really needs to explain why this patch is important. For example, this patch is really two changes (and thus should actually be two patches). (I'll also comment on the other patches) 1. The update of the state char array. You should explain why it's being updated. If it was wrong, it needs to state the commit that changed to make that happen. 2. For the removing the stale macros, the change log can simply state that the macros are unused in the code and are being removed. Finally, I know you're eager to get this patch set in, but please hold off sending a new version immediately after a comment or two. Some maintainers prefer submitters to wait a week or so, otherwise you will tend to "spam" their inboxes. There's more than one maintainer Cc'd on this series, and you need to be courteous not to send too many emails in a short period of time. -- Steve > Signed-off-by: Ze Gao <zegao@tencent.com> > --- > tools/perf/builtin-sched.c | 13 +------------ > 1 file changed, 1 insertion(+), 12 deletions(-) > > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c > index 9ab300b6f131..8dc8f071721c 100644 > --- a/tools/perf/builtin-sched.c > +++ b/tools/perf/builtin-sched.c > @@ -92,23 +92,12 @@ struct sched_atom { > struct task_desc *wakee; > }; > > -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" > +#define TASK_STATE_TO_CHAR_STR "RSDTtXZPI" > > /* task state bitmask, copied from include/linux/sched.h */ > #define TASK_RUNNING 0 > #define TASK_INTERRUPTIBLE 1 > #define TASK_UNINTERRUPTIBLE 2 > -#define __TASK_STOPPED 4 > -#define __TASK_TRACED 8 > -/* in tsk->exit_state */ > -#define EXIT_DEAD 16 > -#define EXIT_ZOMBIE 32 > -#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) > -/* in tsk->state again */ > -#define TASK_DEAD 64 > -#define TASK_WAKEKILL 128 > -#define TASK_WAKING 256 > -#define TASK_PARKED 512 > > enum thread_state { > THREAD_SLEEPING = 0,
On Thu, Aug 3, 2023 at 5:09 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Thu, 3 Aug 2023 04:33:48 -0400 > Ze Gao <zegao2021@gmail.com> wrote: > > Hi Ze, > > > Update state char array and then remove unused and stale > > macros, which are kernel internal representations and not > > encouraged to use anymore. > > > > A couple of things. > > First, the change logs of every commit need to specify the "why". The > subject can say "what", but the change log really needs to explain why this > patch is important. For example, this patch is really two changes (and thus > should actually be two patches). (I'll also comment on the other patches) Thanks for the feedback! Will elaborate the changes in each changelog. > 1. The update of the state char array. You should explain why it's being > updated. If it was wrong, it needs to state the commit that changed to make > that happen. > > 2. For the removing the stale macros, the change log can simply state that > the macros are unused in the code and are being removed. > > Finally, I know you're eager to get this patch set in, but please hold off > sending a new version immediately after a comment or two. Some maintainers > prefer submitters to wait a week or so, otherwise you will tend to "spam" > their inboxes. There's more than one maintainer Cc'd on this series, and you > need to be courteous not to send too many emails in a short period of time. Noted! Actually I'm in no rush and just to make sure people see the latest patches so they do not have to waste time on the old series. Will hold off to resolve all the comments in this thread. And thanks for pointing this out. Regards, Ze
Hi, THIS IS THE NEW CHANGELOG FOR THIS PATCH: perf sched: sync state char array with the kernel Since commit e936e8e459e14 ("perf tools: Adapt the TASK_STATE_TO_CHAR_STR to new value in kernel space."), the state char array that is used to interpret the states of tasks being switched out have not synced once with kernel definitions. Whereas the task report logic is evolving over this time and the definition of this state char array has been changed multiple times. And this leads to inconsistency. As of this writing, perf timehist --state still reports the wrong states because TASK_STATE_TO_CHAR_STR is too outdated to use. So sync TASK_STATE_TO_CHAR_STR to match the latest kernel definitions to fix it. Signed-off-by: Ze Gao <zegao@tencent.com> Regards, Ze On Thu, Aug 3, 2023 at 6:29 PM Ze Gao <zegao2021@gmail.com> wrote: > > On Thu, Aug 3, 2023 at 5:09 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > > > On Thu, 3 Aug 2023 04:33:48 -0400 > > Ze Gao <zegao2021@gmail.com> wrote: > > > > Hi Ze, > > > > > Update state char array and then remove unused and stale > > > macros, which are kernel internal representations and not > > > encouraged to use anymore. > > > > > > > A couple of things. > > > > First, the change logs of every commit need to specify the "why". The > > subject can say "what", but the change log really needs to explain why this > > patch is important. For example, this patch is really two changes (and thus > > should actually be two patches). (I'll also comment on the other patches) > > Thanks for the feedback! Will elaborate the changes in each changelog. > > > 1. The update of the state char array. You should explain why it's being > > updated. If it was wrong, it needs to state the commit that changed to make > > that happen. > > > > 2. For the removing the stale macros, the change log can simply state that > > the macros are unused in the code and are being removed. > > > > Finally, I know you're eager to get this patch set in, but please hold off > > sending a new version immediately after a comment or two. Some maintainers > > prefer submitters to wait a week or so, otherwise you will tend to "spam" > > their inboxes. There's more than one maintainer Cc'd on this series, and you > > need to be courteous not to send too many emails in a short period of time. > > Noted! Actually I'm in no rush and just to make sure people see the > latest patches so they do not have to waste time on the old series. > > Will hold off to resolve all the comments in this thread. > > And thanks for pointing this out. > > Regards, > Ze
> 2. For the removing the stale macros, the change log can simply state that > the macros are unused in the code and are being removed. I've split this part into a separate patch, and here is the changelog: perf sched: cleanup to remove unused macros The macros copied from kernel headers are unused and stale in the code and are being removed to avoid confusions. Signed-off-by: Ze Gao <zegao@tencent.com> Regards, Ze
On Thu, 3 Aug 2023 04:33:48 -0400 Ze Gao <zegao2021@gmail.com> wrote: > Update state char array and then remove unused and stale > macros, which are kernel internal representations and not > encouraged to use anymore. > > Signed-off-by: Ze Gao <zegao@tencent.com> > --- > tools/perf/builtin-sched.c | 13 +------------ > 1 file changed, 1 insertion(+), 12 deletions(-) > > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c > index 9ab300b6f131..8dc8f071721c 100644 > --- a/tools/perf/builtin-sched.c > +++ b/tools/perf/builtin-sched.c > @@ -92,23 +92,12 @@ struct sched_atom { > struct task_desc *wakee; > }; > > -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" > +#define TASK_STATE_TO_CHAR_STR "RSDTtXZPI" Thinking about this more, this will always be wrong. Changing it just works for the kernel you made the change for, but if it is run on another kernel, it's broken again. I actually wrote code once that basically just did a: struct trace_seq s; trace_seq_init(&s); tep_print_event(tep, &s, record, "%s", TEP_PRINT_INFO); then searched s.buffer for "prev_state=%s ", to find the state character. That's because the kernel should always be up to date (and why I said I needed that string in the print_fmt). As perf has a tep handle, this could be a helper function to extract the state if needed, and get rind of relying on the above character array. -- Steve > > /* task state bitmask, copied from include/linux/sched.h */ > #define TASK_RUNNING 0 > #define TASK_INTERRUPTIBLE 1 > #define TASK_UNINTERRUPTIBLE 2 > -#define __TASK_STOPPED 4 > -#define __TASK_TRACED 8 > -/* in tsk->exit_state */ > -#define EXIT_DEAD 16 > -#define EXIT_ZOMBIE 32 > -#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) > -/* in tsk->state again */ > -#define TASK_DEAD 64 > -#define TASK_WAKEKILL 128 > -#define TASK_WAKING 256 > -#define TASK_PARKED 512 > > enum thread_state { > THREAD_SLEEPING = 0,
On Thu, Aug 3, 2023 at 11:10 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Thu, 3 Aug 2023 04:33:48 -0400 > Ze Gao <zegao2021@gmail.com> wrote: > > > Update state char array and then remove unused and stale > > macros, which are kernel internal representations and not > > encouraged to use anymore. > > > > Signed-off-by: Ze Gao <zegao@tencent.com> > > --- > > tools/perf/builtin-sched.c | 13 +------------ > > 1 file changed, 1 insertion(+), 12 deletions(-) > > > > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c > > index 9ab300b6f131..8dc8f071721c 100644 > > --- a/tools/perf/builtin-sched.c > > +++ b/tools/perf/builtin-sched.c > > @@ -92,23 +92,12 @@ struct sched_atom { > > struct task_desc *wakee; > > }; > > > > -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" > > +#define TASK_STATE_TO_CHAR_STR "RSDTtXZPI" > > Thinking about this more, this will always be wrong. Changing it just works > for the kernel you made the change for, but if it is run on another kernel, > it's broken again. Indeed. There is no easy way to maintain backward compatibility unless we stop using this bizarre 'prev_state' field. Basically all its users suffer from this. That's why I believe this needs a fix to alert people does not use 'prev_state' anymore. > I actually wrote code once that basically just did a: > > struct trace_seq s; > > trace_seq_init(&s); > tep_print_event(tep, &s, record, "%s", TEP_PRINT_INFO); > > then searched s.buffer for "prev_state=%s ", to find the state character. > > That's because the kernel should always be up to date (and why I said I > needed that string in the print_fmt). Turing to building the state char array from print fmt string dynamically is a great idea. :) > As perf has a tep handle, this could be a helper function to extract the > state if needed, and get rind of relying on the above character array. I'll figure out how to make it happen. BTW, my last concern is that is there any better way to notice userspace to avoid interpreting task state out of 'prev_state'. Because the awkward thing happens again. Thanks, Ze > -- Steve > > > > > > /* task state bitmask, copied from include/linux/sched.h */ > > #define TASK_RUNNING 0 > > #define TASK_INTERRUPTIBLE 1 > > #define TASK_UNINTERRUPTIBLE 2 > > -#define __TASK_STOPPED 4 > > -#define __TASK_TRACED 8 > > -/* in tsk->exit_state */ > > -#define EXIT_DEAD 16 > > -#define EXIT_ZOMBIE 32 > > -#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) > > -/* in tsk->state again */ > > -#define TASK_DEAD 64 > > -#define TASK_WAKEKILL 128 > > -#define TASK_WAKING 256 > > -#define TASK_PARKED 512 > > > > enum thread_state { > > THREAD_SLEEPING = 0, >
On Fri, Aug 4, 2023 at 10:21 AM Ze Gao <zegao2021@gmail.com> wrote: > > On Thu, Aug 3, 2023 at 11:10 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > > > On Thu, 3 Aug 2023 04:33:48 -0400 > > Ze Gao <zegao2021@gmail.com> wrote: > > > > > Update state char array and then remove unused and stale > > > macros, which are kernel internal representations and not > > > encouraged to use anymore. > > > > > > Signed-off-by: Ze Gao <zegao@tencent.com> > > > --- > > > tools/perf/builtin-sched.c | 13 +------------ > > > 1 file changed, 1 insertion(+), 12 deletions(-) > > > > > > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c > > > index 9ab300b6f131..8dc8f071721c 100644 > > > --- a/tools/perf/builtin-sched.c > > > +++ b/tools/perf/builtin-sched.c > > > @@ -92,23 +92,12 @@ struct sched_atom { > > > struct task_desc *wakee; > > > }; > > > > > > -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" > > > +#define TASK_STATE_TO_CHAR_STR "RSDTtXZPI" > > > > Thinking about this more, this will always be wrong. Changing it just works > > for the kernel you made the change for, but if it is run on another kernel, > > it's broken again. > > Indeed. There is no easy way to maintain backward compatibility unless > we stop using this bizarre 'prev_state' field. Basically all its users suffer > from this. That's why I believe this needs a fix to alert people does not > use 'prev_state' anymore. > > > I actually wrote code once that basically just did a: > > > > struct trace_seq s; > > > > trace_seq_init(&s); > > tep_print_event(tep, &s, record, "%s", TEP_PRINT_INFO); > > > > then searched s.buffer for "prev_state=%s ", to find the state character. > > > > That's because the kernel should always be up to date (and why I said I > > needed that string in the print_fmt). > > Turing to building the state char array from print fmt string dynamically > is a great idea. :) > > > As perf has a tep handle, this could be a helper function to extract the > > state if needed, and get rind of relying on the above character array. > > I'll figure out how to make it happen. > > BTW, my last concern is that is there any better way to notice userspace to > avoid interpreting task state out of 'prev_state'. Because the awkward thing > happens again. By userspace, I mean all tools consume 'prev_state' but don't have print fmt available, taking bpf tracepoint for example. Regards, Ze > Thanks, > Ze > > > -- Steve > > > > > > > > > > /* task state bitmask, copied from include/linux/sched.h */ > > > #define TASK_RUNNING 0 > > > #define TASK_INTERRUPTIBLE 1 > > > #define TASK_UNINTERRUPTIBLE 2 > > > -#define __TASK_STOPPED 4 > > > -#define __TASK_TRACED 8 > > > -/* in tsk->exit_state */ > > > -#define EXIT_DEAD 16 > > > -#define EXIT_ZOMBIE 32 > > > -#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) > > > -/* in tsk->state again */ > > > -#define TASK_DEAD 64 > > > -#define TASK_WAKEKILL 128 > > > -#define TASK_WAKING 256 > > > -#define TASK_PARKED 512 > > > > > > enum thread_state { > > > THREAD_SLEEPING = 0, > >
On Fri, Aug 4, 2023 at 10:38 AM Ze Gao <zegao2021@gmail.com> wrote: > > On Fri, Aug 4, 2023 at 10:21 AM Ze Gao <zegao2021@gmail.com> wrote: > > > > On Thu, Aug 3, 2023 at 11:10 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > > > > > On Thu, 3 Aug 2023 04:33:48 -0400 > > > Ze Gao <zegao2021@gmail.com> wrote: > > > > > > > Update state char array and then remove unused and stale > > > > macros, which are kernel internal representations and not > > > > encouraged to use anymore. > > > > > > > > Signed-off-by: Ze Gao <zegao@tencent.com> > > > > --- > > > > tools/perf/builtin-sched.c | 13 +------------ > > > > 1 file changed, 1 insertion(+), 12 deletions(-) > > > > > > > > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c > > > > index 9ab300b6f131..8dc8f071721c 100644 > > > > --- a/tools/perf/builtin-sched.c > > > > +++ b/tools/perf/builtin-sched.c > > > > @@ -92,23 +92,12 @@ struct sched_atom { > > > > struct task_desc *wakee; > > > > }; > > > > > > > > -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" > > > > +#define TASK_STATE_TO_CHAR_STR "RSDTtXZPI" > > > > > > Thinking about this more, this will always be wrong. Changing it just works > > > for the kernel you made the change for, but if it is run on another kernel, > > > it's broken again. > > > > Indeed. There is no easy way to maintain backward compatibility unless > > we stop using this bizarre 'prev_state' field. Basically all its users suffer > > from this. That's why I believe this needs a fix to alert people does not > > use 'prev_state' anymore. > > > > > I actually wrote code once that basically just did a: > > > > > > struct trace_seq s; > > > > > > trace_seq_init(&s); > > > tep_print_event(tep, &s, record, "%s", TEP_PRINT_INFO); > > > > > > then searched s.buffer for "prev_state=%s ", to find the state character. > > > > > > That's because the kernel should always be up to date (and why I said I > > > needed that string in the print_fmt). > > > > Turing to building the state char array from print fmt string dynamically > > is a great idea. :) I realize this is not perfect as well after second thoughts, since this does not take offline use of perf into consideration. People might run perf on different machines than where the perf.data gets recorded, in which way what we get from /sys/kernel/debug/tracing/events/sched/sched_switch/format is likely different from the perf.data. So let's parse it from TEP_PRINT_INFO of each record instead of building the state char array and rely on 'prev_state' again. At least this fix all tools that have TEP_PRINT_INFO available. Thanks, Ze > > > As perf has a tep handle, this could be a helper function to extract the > > > state if needed, and get rind of relying on the above character array. > > > > I'll figure out how to make it happen. > > > > BTW, my last concern is that is there any better way to notice userspace to > > avoid interpreting task state out of 'prev_state'. Because the awkward thing > > happens again. > > By userspace, I mean all tools consume 'prev_state' but don't have print fmt > available, taking bpf tracepoint for example. > > Regards, > Ze > > > Thanks, > > Ze > > > > > -- Steve > > > > > > > > > > > > > > /* task state bitmask, copied from include/linux/sched.h */ > > > > #define TASK_RUNNING 0 > > > > #define TASK_INTERRUPTIBLE 1 > > > > #define TASK_UNINTERRUPTIBLE 2 > > > > -#define __TASK_STOPPED 4 > > > > -#define __TASK_TRACED 8 > > > > -/* in tsk->exit_state */ > > > > -#define EXIT_DEAD 16 > > > > -#define EXIT_ZOMBIE 32 > > > > -#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) > > > > -/* in tsk->state again */ > > > > -#define TASK_DEAD 64 > > > > -#define TASK_WAKEKILL 128 > > > > -#define TASK_WAKING 256 > > > > -#define TASK_PARKED 512 > > > > > > > > enum thread_state { > > > > THREAD_SLEEPING = 0, > > >
On Fri, 4 Aug 2023 11:19:06 +0800 Ze Gao <zegao2021@gmail.com> wrote: > I realize this is not perfect as well after second thoughts, since this does not > take offline use of perf into consideration. People might run perf on different > machines than where the perf.data gets recorded, in which way what we get > from /sys/kernel/debug/tracing/events/sched/sched_switch/format is likely > different from the perf.data. If perf data files does what trace.dat files do, it should save the file formats in the data files. It should not be reading the kernel when reading the data file. With trace-cmd, you can do: trace-cmd dump --events And it will show you all the formats of the events that it saved in the file. -- Steve
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 9ab300b6f131..8dc8f071721c 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -92,23 +92,12 @@ struct sched_atom { struct task_desc *wakee; }; -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" +#define TASK_STATE_TO_CHAR_STR "RSDTtXZPI" /* task state bitmask, copied from include/linux/sched.h */ #define TASK_RUNNING 0 #define TASK_INTERRUPTIBLE 1 #define TASK_UNINTERRUPTIBLE 2 -#define __TASK_STOPPED 4 -#define __TASK_TRACED 8 -/* in tsk->exit_state */ -#define EXIT_DEAD 16 -#define EXIT_ZOMBIE 32 -#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD) -/* in tsk->state again */ -#define TASK_DEAD 64 -#define TASK_WAKEKILL 128 -#define TASK_WAKING 256 -#define TASK_PARKED 512 enum thread_state { THREAD_SLEEPING = 0,