Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3024577rwo; Thu, 3 Aug 2023 20:32:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXTtSkKWyUKI39eLPp7faulTiZAxIt+4x9Twh0wgAQ8hVkUZBs4hKPvGwUYDSj5aNhkVd6 X-Received: by 2002:a05:6512:2216:b0:4f8:d385:41bd with SMTP id h22-20020a056512221600b004f8d38541bdmr415904lfu.8.1691119922119; Thu, 03 Aug 2023 20:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691119922; cv=none; d=google.com; s=arc-20160816; b=uIjtfw+vV++68R0UNv/54YJGvthpZZIgkhzwhWxVjY363c9w8eyLHxW4lTTMnIHe0V nG8btKgbGDt8QXQu0FIXfmhrQ3EqewSeGVr3LnLLzQZEDFX3pW2B4KRrjZxsMLbm2ybh PNDQ/havaNf7LTGkvKnYSQ/BtFCiO2NrT3u0v0nTIEoQc0bXAQazbMtyCqVDQzTFa0EJ NYqoPCz1y3fARtJfcPMZqmBPwwodFiosbiWQtqHAqNedeHVzSYa2NhluVigYX5tmLV8T Yo2iO0Dz1ZH+mVBEb3PLtK4yDZOZaWD/EIZAYiTqfdcfuGl4s5DiZSG5h22Nh9cPZJX9 o+Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=H0h7iWjuLjZV6ZF1NMpCJ/oaSh2XQCJuifsadDe4GTE=; fh=i11EqTbJhvgTBLJrKYn2dhvv75Alx1G7BCLiW+AR2Jc=; b=OuXU4nEkZIWXXzG52ZU6I2GfSJw1Rrukwblg6o+3kh3SlX12DvsQtjqLF/xwh+Xr6P E1BiWl7o86s9ptUD16ieGe/ExHqg33tiAM1dTOv+z97N/SjVCrIiGTRfzPscWBF0nxFJ 9EkF0el4OVfFs+dAe6XuyYzSxeij+3NmiwNLsI5gy2tCrDpgg0YLc9nWyRFyy99ZUcXH nalv95cwkxFpheO4/LCradLedHZW3q0GKIWv8PgpORV9tE7ETVRWvuWEj+HN26a12vzb Kw+K7xkmeeMAmjKSKcjws72zB9yIQcRSFZbUlRgtzITI7tsmd0C4laSzGlWIR0QT/gqf spYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="s1pX/luM"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a05640207d000b005231053301bsi845974edy.427.2023.08.03.20.31.37; Thu, 03 Aug 2023 20:32: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="s1pX/luM"; 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 S231379AbjHDCXY (ORCPT + 99 others); Thu, 3 Aug 2023 22:23:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233983AbjHDCXB (ORCPT ); Thu, 3 Aug 2023 22:23:01 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB3B4680; Thu, 3 Aug 2023 19:22:11 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4fe3b86cec1so2706532e87.2; Thu, 03 Aug 2023 19:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691115729; x=1691720529; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=H0h7iWjuLjZV6ZF1NMpCJ/oaSh2XQCJuifsadDe4GTE=; b=s1pX/luML5i2+Fpub3Q04CqfkbB5vuhnkmWYBA/aE2wAwUDhbUdq/5CLybe80t3Adu VGEVqdREBinjCMbVSKVWDgQZR+gUCBEVdLO3CStBaV2WUXEV1eZA0NxZBhZ0OamKQAW9 qOuLe02QeiMNLMcDQj/3r9m3QIkHJ/c4x/18A9IEMxdM8al2AryaphJ+tu/kmqlFpqI1 bNZaTgF8Th7mu5ORoCP78E4z1vMiKpiCN+r23EW0GuEDNmSs8OQxEGgDLmGrQldZ1WtK 8PIK2E+DOoibFQ+XRYuBoG7GWjVz8Fowuiso+2yzFWQNGPDQ1t+YUs1XyRgKBS5nFrQz 9eHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691115729; x=1691720529; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H0h7iWjuLjZV6ZF1NMpCJ/oaSh2XQCJuifsadDe4GTE=; b=gMpsxkGPnzcb7BPPLjXlaQqBXC7enYLSMmXsb10HlE34cTdxYSSh9On8u5bRA+/Qgy w1gFvdM3xvdnKlObPTgLCZHb+Md8DSTCGiyTL5XKMKjEChhyEmCb2i25l0pxI7xlPPzV bBcx1E4w06dGrvKENahMhQzC3uVd4RK1hZ2diZwbSYmhI3oflZknPagpkl+RN8mjxJU7 DZBVLkahohhTfEQHakZGA/TyjiBk0ASHoBkAGUKq9pSgINBO3Xgv7AOh/MhGYKXZgbmn nB/d8mRLNieHUjDxxfOudK9PbtF87USWcZv7NRSTL8xoFdBzYO/sKQtkyFiU3Qz5Yx60 S3jA== X-Gm-Message-State: AOJu0Yy3Q9FEpKU7fxn+QMbGKqTPxK/TBj9kAEtv6TeCyohArg+5TwL/ LfyuDtHJPD98o/1pfdLUqbxa/fBXGLKsAKLgB8E= X-Received: by 2002:a05:6512:324d:b0:4f8:6833:b13c with SMTP id c13-20020a056512324d00b004f86833b13cmr235780lfr.14.1691115729043; Thu, 03 Aug 2023 19:22:09 -0700 (PDT) MIME-Version: 1.0 References: <20230803083352.1585-1-zegao@tencent.com> <20230803083352.1585-2-zegao@tencent.com> <20230803111031.056b3446@gandalf.local.home> In-Reply-To: <20230803111031.056b3446@gandalf.local.home> From: Ze Gao Date: Fri, 4 Aug 2023 10:21:57 +0800 Message-ID: Subject: Re: [RFC PATCH v6 1/5] perf sched: sync state char array with the kernel To: Steven Rostedt Cc: Adrian Hunter , Alexander Shishkin , Arnaldo Carvalho de Melo , Ian Rogers , Ingo Molnar , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Thu, Aug 3, 2023 at 11:10=E2=80=AFPM Steven Rostedt wrote: > > On Thu, 3 Aug 2023 04:33:48 -0400 > Ze Gao 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 > > --- > > 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 wor= ks > for the kernel you made the change for, but if it is run on another kerne= l, > 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 suff= er 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=3D%s ", to find the state characte= r. > > 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 t= o avoid interpreting task state out of 'prev_state'. Because the awkward thin= g 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 =3D 0, >