From patchwork Tue Aug 1 09:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 129159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2574240vqg; Tue, 1 Aug 2023 03:32:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlG8Q1DTk5jaN9BlKRb/3qb+XM88umWyBqUhYR3tF5AwpebCYwrsxV72B5PgRaLmvpgxgj7x X-Received: by 2002:a17:906:108f:b0:993:e752:1a6d with SMTP id u15-20020a170906108f00b00993e7521a6dmr2243937eju.18.1690885963096; Tue, 01 Aug 2023 03:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690885963; cv=none; d=google.com; s=arc-20160816; b=Aib/v//YDp7rQ7PaF2om5qCyO0e21HiIf65cckjAaY2Rh6St+YHVfImwgMZHmBKsFZ N2gV4PJkEXO5ydTyNCKkgDPK6GXfpIhqn7gUIqYvgNyd0C86UTOjLAG/Ksc5PZPHVBeC myEL51i2EpG3lZP7fcTePpRB2B5uZbppRkbv31/83we6KivUdgZpJP1kmBxMmC6Yee/s A2TYvWEXMsROn/c+4gmNzX+XhHPrTuyKIu8gcwQUHIsFW2TYcO1ph/82mBstiW/WRLjw pCKRgJpTICjKfJ1zDVXPpW7uGqRCJTm03h8pNclzcNcBESeMPwmfMG8jq6ZjRzvBkBfO P37A== 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=ANQBcIlYslUfyuFpH0ut8ZVNsDjb/eKVIKT4N9OJfTI=; fh=4S4dukURCUlSsjzSa0Ofy3qHSrrdu/uT1HnGBPj5BK4=; b=l1NoX5MncHDm+4o45+LAiyVRiL/IeXnsmuakYru9+U72LjbQfJR5DjCittzT7ax+z+ eTg5AQdbk4HHxq7Hgds66F1rCdlHTsF8GIYl4IpEcLXPJr/8/DMaNaQOnyvdXJPQeMOX aeU7+gRV6OpZbSSqY/qsXIykaGEqJ3QtvxuF2veQjQoPlMOa1cAuYl1TIwEPyhPloczY 23jpb+72QKWDe0XvaYezdnGN3XvBbEjBAh/ct8JR0mcbi1y0ZUShhTpB6I7Um0JaVbvO LX9eF+TayOkxccVHt21nkUon0O+mZArYkApgBSEvxFC5MI/jQJbGUTz8dTMJXbL91N1x Iesw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="SU1K5qS/"; 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 ay21-20020a170906d29500b00988357b5f3fsi5159745ejb.758.2023.08.01.03.32.19; Tue, 01 Aug 2023 03:32:43 -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="SU1K5qS/"; 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 S231990AbjHAJBp (ORCPT + 99 others); Tue, 1 Aug 2023 05:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjHAJBi (ORCPT ); Tue, 1 Aug 2023 05:01:38 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24114173A; Tue, 1 Aug 2023 02:01:37 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-267fc19280bso4318535a91.1; Tue, 01 Aug 2023 02:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690880496; x=1691485296; 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=ANQBcIlYslUfyuFpH0ut8ZVNsDjb/eKVIKT4N9OJfTI=; b=SU1K5qS/8yCfPyxZKXlBwc104Wvn8wfdVsSfRcB96eVcbDwHfzY00tKeboUstqxq0T BRMJCfKfzXhVyj8rxZm6f44pcyyQXe+i9GXjHz8RHOeQeg21eAQudXLshb/HC3aGMUZW /WRCupIyCLHEiuD7QM/WI6mK5RqoPEZyTsM6su19ihphcVZtidulyL5iUys7qTDiBq3V 0ZZj5pgtauhC/533lkLJ5yhvVvZV3ret185irdYlO7uU/ViV24rS/vR75BSx2+6TAv0f 14JA/Itc5uu/JdH26Rth4KabmTUms6+bVuJldzQgdB4d+UoSsi5ujVrypsOR1UIgxMiP E51g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880496; x=1691485296; 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=ANQBcIlYslUfyuFpH0ut8ZVNsDjb/eKVIKT4N9OJfTI=; b=YXPD8FrcOBikmCF8FfUOlrWSF2oai0JvBe1xEJj8GH2zrhO87ia89SC5Fn38K6Kc1Q nanoHIfpmD2I3NtwQ1rfr6JMR10PUhqQS5FfM1C4XdkhCeqmRg9MvLGzh26ZK6VwZW8u j87o/AXTUxIsx3vaTfsg5TQHYRDLuLIhjgb4p60gw0yF7rNO1Qt8N1UoitghCu7ZSx5P M49E6uKTxZveqbaqbDfZOgDYpe29t46m29CbE7VwjcPawbpgbmwmJ/DU6VmhpyeBctmS onO4+v3cVxaDIqc9P+ONGdT1G6eXZ8RozDCYti8oNP0o6mgSgTmCKpAma7Gg23O+4Wwg ONeQ== X-Gm-Message-State: ABy/qLZe8SBmUd1FlEbjGn8wQGCi86/tkKE5f8xUwsoMuNTQBT0wSW+N JZH1kgeKiecMhOv63p6denM= X-Received: by 2002:a17:90b:3c3:b0:268:94b:8d0 with SMTP id go3-20020a17090b03c300b00268094b08d0mr14673309pjb.11.1690880496543; Tue, 01 Aug 2023 02:01:36 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm1592523pjj.1.2023.08.01.02.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 02:01:36 -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, linux-trace-devel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v3 1/6] perf sched: sync state char array with the kernel Date: Tue, 1 Aug 2023 17:01:19 +0800 Message-Id: <20230801090124.8050-2-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230801090124.8050-1-zegao@tencent.com> References: <20230801090124.8050-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: 1773022439597848786 X-GMAIL-MSGID: 1773022439597848786 update state char array and then remove unused and stale macros, which are kernel internal representations and not encouraged to use anymore. this fix is for old kernels, and we will steer to newly added symbolic char to report task state but also maintain compatibility to not break anything. 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 cc4ba506e119..c0d0ad18fc76 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, From patchwork Tue Aug 1 09:01:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 129239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2616444vqg; Tue, 1 Aug 2023 05:01:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQhtUDcDf2+zdRpKdEflv+T1frSrGB3JrgkdkC71uUjtooJgs0zbrzmXa6Z1UQFsxpby3C X-Received: by 2002:a05:6a20:7493:b0:132:d029:ed3d with SMTP id p19-20020a056a20749300b00132d029ed3dmr12815357pzd.29.1690891297084; Tue, 01 Aug 2023 05:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690891297; cv=none; d=google.com; s=arc-20160816; b=HIaI7RIwTBO24TGIhpu5gRQGgtfgxHZdbCBrFFprNeMEKAh7gSD+P2Fvbdtq+d/4W8 +J4z6lhsH6ZUHSc8WY3Ez2tIg03zCOkSVlJPYiTMd3YXTqwUTbFmG+jctRtvEDbvzrNm B/8FcMZLxoR6qmFQqWhUxrydGFZfzjvPtjtEANZza0nIlLtfz3hvW38cO2gYQP5PQVPp aMqqLUwaKwBC1oOfE8tHlQAPAtcZgpyyRpQCMQZoXRVc8t7BlXNTwMaW9TZabYa02IlZ pTiE1MTGZMlro3IJ7Hw07QvZbOLx/IxCKjFyXkqDNu3kIkTUjl+Ng+GIHAFeEEjgJQv+ /8Cg== 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=FyqGyivSWJ8U4X+4ZXNDsrpYxWDLRcGdfTgj5jmwqPU=; fh=4S4dukURCUlSsjzSa0Ofy3qHSrrdu/uT1HnGBPj5BK4=; b=rtsbhqETPNMvDJ0YpNiq+kaJ2F+dvo5omapXUJ+gQnVzeMoDrlZELXzp7x68I6lbXc AKqpdd8VLHCa7Ig4eYlF2vNG6l5Ls1hUpgWS+T9fEmz1EjeSkpAIEzqAqTMJNxPCRWNK f480XehLo8b60/jWpBRD1jWy/wuERTn3++CXBUi34Xfwe6O3j7TCyAjpb59PtTBVWZS0 Gc7bpgKyIG7V+odotUHsZHL51zxV//Wk4AZiz6HQZMw32Rwp5mhx/qViNPhf092zdknk SicrRTBkQyap3AgBT/qS+TURPl6cPGpI6miyrIG9pduxQHsX4CY8w3CUYJmUhTd9Gnfv Cqiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=D0xqo6gP; 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 bv127-20020a632e85000000b00543a89c95c2si8745842pgb.207.2023.08.01.05.01.23; Tue, 01 Aug 2023 05:01:37 -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=D0xqo6gP; 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 S231915AbjHAJBu (ORCPT + 99 others); Tue, 1 Aug 2023 05:01:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbjHAJBm (ORCPT ); Tue, 1 Aug 2023 05:01:42 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2138DE7; Tue, 1 Aug 2023 02:01:41 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-268299d5d9fso3006915a91.1; Tue, 01 Aug 2023 02:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690880500; x=1691485300; 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=FyqGyivSWJ8U4X+4ZXNDsrpYxWDLRcGdfTgj5jmwqPU=; b=D0xqo6gPUT4pSeEn7VvOYFV5VgXyJV2kvn6SKN1gvF1cV1d8Hr5DTWd59ZmyZxdImf F5VgBKMQloXeM/8EYkQVhG/AXGbyZ1X4238jLHC+ZlNF/uRdTus8i1loTTCtTZg21fOF u3RVSzW01Q2wfLfjAU09/+QejdCvxXr/KmhO87efJM5L1uQu/jdjgCTFfsOmw4HGI9J0 ObiZPg3ZRRzs7xWt3lgXtOLQ5WeEDOTxBTuYVEwInXub8c2rmQmqmNiKXYg7OYq5LG03 nhdad3jJELvzabPCP7blSV7WWnVjnvfnb6PUQ5gcCy7T06VQtOAO+icX3f8N++pFqYQW rkrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880500; x=1691485300; 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=FyqGyivSWJ8U4X+4ZXNDsrpYxWDLRcGdfTgj5jmwqPU=; b=ZmH2f6MPtOM+MvN8pVfPTTuxXmJQt6H6wLSf/wByIyLnZWeQQSJ3YK45za5HYxxYSB Wndv2MkMfBd7GFjUAf8gHdLPAFB1a+0NLpPwzRz+IY94PpxcDwfw4x+1cg+r3UcUVKEj 95hW/7o5h167gaRIAi7GPWtciYYDt3Gq+PzaO/M+yfYUfcQOAGNVLUiPPrtDbIIWKiqE ChkbF2alBmzy7gPdNZM/zVcT77UXDCOLepP457sVI7kmwW5qSIqez0rMRf7rdUl3NTHe KLdvJralXLJ4tm5kdeeW1sI3udTvkNTcTRAPq+UPL05I01cxTDgwbB5OhXwUk+84cgdp tp4A== X-Gm-Message-State: ABy/qLYlhESQEZZEG3pF4ZMXnmVc7KBikqboHOxRJHcrKsmLnKAIZ4Q7 q9lS20UU7H5/QllVaw/3Py0= X-Received: by 2002:a17:90a:2fcf:b0:268:5fd8:d8ff with SMTP id n15-20020a17090a2fcf00b002685fd8d8ffmr9942593pjm.0.1690880500502; Tue, 01 Aug 2023 02:01:40 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm1592523pjj.1.2023.08.01.02.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 02:01:40 -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, linux-trace-devel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v3 2/6] perf sched: reorganize sched-out task state report code Date: Tue, 1 Aug 2023 17:01:20 +0800 Message-Id: <20230801090124.8050-3-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230801090124.8050-1-zegao@tencent.com> References: <20230801090124.8050-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: 1773028032583517131 X-GMAIL-MSGID: 1773028032583517131 this patch mainly does housekeeping work and not introduce any functional change. Signed-off-by: Ze Gao --- tools/perf/builtin-sched.c | 57 ++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index c0d0ad18fc76..275da655b67a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -94,11 +94,6 @@ struct sched_atom { #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 - enum thread_state { THREAD_SLEEPING = 0, THREAD_WAIT_CPU, @@ -255,7 +250,7 @@ struct thread_runtime { u64 total_preempt_time; u64 total_delay_time; - int last_state; + char last_state; char shortname[3]; bool comm_changed; @@ -425,7 +420,7 @@ static void add_sched_event_wakeup(struct perf_sched *sched, struct task_desc *t } static void add_sched_event_sleep(struct perf_sched *sched, struct task_desc *task, - u64 timestamp, u64 task_state __maybe_unused) + u64 timestamp, char task_state __maybe_unused) { struct sched_atom *event = get_new_event(task, timestamp); @@ -840,6 +835,20 @@ replay_wakeup_event(struct perf_sched *sched, return 0; } +static inline char task_state_char(int state) +{ + static const char state_to_char[] = "RSDTtXZPI"; + unsigned bit = state ? ffs(state) : 0; + return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; +} + +static inline char get_task_prev_state(struct evsel *evsel, + struct perf_sample *sample) +{ + const int prev_state = evsel__intval(evsel, sample, "prev_state"); + return task_state_char(prev_state); +} + static int replay_switch_event(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, @@ -849,7 +858,7 @@ static int replay_switch_event(struct perf_sched *sched, *next_comm = evsel__strval(evsel, sample, "next_comm"); const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), next_pid = evsel__intval(evsel, sample, "next_pid"); - const u64 prev_state = evsel__intval(evsel, sample, "prev_state"); + const char prev_state = get_task_prev_state(evsel, sample); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1039,12 +1048,6 @@ static int thread_atoms_insert(struct perf_sched *sched, struct thread *thread) return 0; } -static char sched_out_state(u64 prev_state) -{ - const char *str = TASK_STATE_TO_CHAR_STR; - - return str[prev_state]; -} static int add_sched_out_event(struct work_atoms *atoms, @@ -1121,7 +1124,7 @@ static int latency_switch_event(struct perf_sched *sched, { const u32 prev_pid = evsel__intval(evsel, sample, "prev_pid"), next_pid = evsel__intval(evsel, sample, "next_pid"); - const u64 prev_state = evsel__intval(evsel, sample, "prev_state"); + const char prev_state = get_task_prev_state(evsel, sample); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1157,7 +1160,7 @@ static int latency_switch_event(struct perf_sched *sched, goto out_put; } } - if (add_sched_out_event(out_events, sched_out_state(prev_state), timestamp)) + if (add_sched_out_event(out_events, prev_state, timestamp)) return -1; in_events = thread_atoms_search(&sched->atom_root, sched_in, &sched->cmp_pid); @@ -2015,24 +2018,12 @@ static void timehist_header(struct perf_sched *sched) printf("\n"); } -static char task_state_char(struct thread *thread, int state) -{ - static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; - unsigned bit = state ? ffs(state) : 0; - - /* 'I' for idle */ - if (thread->tid == 0) - return 'I'; - - return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; -} - static void timehist_print_sample(struct perf_sched *sched, struct evsel *evsel, struct perf_sample *sample, struct addr_location *al, struct thread *thread, - u64 t, int state) + u64 t, char state) { struct thread_runtime *tr = thread__priv(thread); const char *next_comm = evsel__strval(evsel, sample, "next_comm"); @@ -2073,7 +2064,7 @@ static void timehist_print_sample(struct perf_sched *sched, print_sched_time(tr->dt_run, 6); if (sched->show_state) - printf(" %5c ", task_state_char(thread, state)); + printf(" %5c ", thread->tid == 0 ? 'I' : state); if (sched->show_next) { snprintf(nstr, sizeof(nstr), "next: %s[%d]", next_comm, next_pid); @@ -2145,9 +2136,9 @@ static void timehist_update_runtime_stats(struct thread_runtime *r, else if (r->last_time) { u64 dt_wait = tprev - r->last_time; - if (r->last_state == TASK_RUNNING) + if (r->last_state == 'R' || r->last_state == 'p') r->dt_preempt = dt_wait; - else if (r->last_state == TASK_UNINTERRUPTIBLE) + else if (r->last_state == 'D') r->dt_iowait = dt_wait; else r->dt_sleep = dt_wait; @@ -2564,7 +2555,7 @@ static int timehist_sched_change_event(struct perf_tool *tool, struct thread_runtime *tr = NULL; u64 tprev, t = sample->time; int rc = 0; - int state = evsel__intval(evsel, sample, "prev_state"); + char state = get_task_prev_state(evsel, sample); if (machine__resolve(machine, &al, sample) < 0) { pr_err("problem processing %d event. skipping it\n", From patchwork Tue Aug 1 09:01:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 129100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2545974vqg; Tue, 1 Aug 2023 02:25:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFi2eAFpPiGsMb/u/oSzUurZaRH87QJXq6oDJyjtc27MeJ/6ba3A2nCP13quJefBrZHjHI9 X-Received: by 2002:a05:6402:1299:b0:522:2af1:1ffe with SMTP id w25-20020a056402129900b005222af11ffemr1761934edv.9.1690881928294; Tue, 01 Aug 2023 02:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690881928; cv=none; d=google.com; s=arc-20160816; b=NsEfs5d+u8/cdggXt6NiW9Ert1ip5aWuOzbOZyKfVjrV6ZKAjevDToxiMcqnr7TvNV EaqFW4YFDrHZlih4N0jkbGqoiSZ5TYzcZHbiNNzQePfvbTEo16jzzHfbS8IIL8WGRpC/ 360/Xscy4ztiQzPlrV/2o/+VfoEOSa8OWX+xmv+gsYnoNsrWoPpPcRMqIQ9pPKPIhY8Q 5U6AsB/XmB4GftY1mQ/iuy2t36NDWF2+nbUCETgGsQg1voPeNC50QMvlUDVjat0amDcg JBdSVJ4BEbNl1pVGJHMPRJsNu7zcyMR6jyV6/93WAThTrnICDvQ+hfCcV8es2sIoB1Ii Ny8Q== 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=PBxCbacsLX6m7o32e5QWwMlB/3bI1PwM+xCI9ISuc6o=; fh=4S4dukURCUlSsjzSa0Ofy3qHSrrdu/uT1HnGBPj5BK4=; b=gViXXG5PvkybomDu6nVHqc/z3CkgWRGuhX70p01HHvNV3F5YBc6UGu1h1rTZoOcGOk 1dxvGZNgkbgHEvhM+QJdJfuGBRhFtqN27aMhR69uW2gclMqu698qOnVEBz+7UN4z6Wdv fwTHJjGDsO91MvlN/irzfQV+wyELhbIx6kJms7NxdPuFGisDcNnOP+8piB/7I3oWsCv3 TAKcNk4qMyxtG9K5vzvMjybBY8pGPJkPuLKhb8i2osVLoECDKkgTWRnmBBO/yqUNFikt JGzmC+vGeAMNOu2BJg6eDI5cYgfq8yN2O9AfRirRff0m1nec5NOAgxtrRo8XSSPTR4Yc 4ukA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=eZn7HUGd; 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 n17-20020a056402061100b0052229b7a96asi7839209edv.684.2023.08.01.02.25.04; Tue, 01 Aug 2023 02:25:28 -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=eZn7HUGd; 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 S232272AbjHAJB6 (ORCPT + 99 others); Tue, 1 Aug 2023 05:01:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbjHAJBt (ORCPT ); Tue, 1 Aug 2023 05:01:49 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1425E1996; Tue, 1 Aug 2023 02:01:45 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bbdc05a93bso33066885ad.0; Tue, 01 Aug 2023 02:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690880504; x=1691485304; 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=PBxCbacsLX6m7o32e5QWwMlB/3bI1PwM+xCI9ISuc6o=; b=eZn7HUGdRY0o+oSO7rF5Pch85mgNf4Y/292AsG/gybfExewTsCGLCO3KLIeVP3cDn3 wkKZ1f3YHvWHzpdzWJXNmRqahVWImESo2wNDUDvjUVmHYvtarL2Y6b9qB5KRzOcwVZvc mpiLj/BFpjrOBNA41rHxf8YSE7ACPQzxyIPu+g5s4/jK+vX1cp1p3ZwhhUg1VfFOnPgE UzhHsqB3a1WYWpJOfq4o3HPa1tL3tmpuLHO5jkWZN+nrEOizwlk6MNVydcHPGi4ZgYAl xootA5r0isHTNLsL5E9/XNIC93uG6VArfY/ZA1/v2RCpcvFO2NWu7XCXHItMEfvWQSm7 eobg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880504; x=1691485304; 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=PBxCbacsLX6m7o32e5QWwMlB/3bI1PwM+xCI9ISuc6o=; b=lXgYiRCrTKJieo5FvvUAhba5byX7V7wHE2IrBtkVci9nKoopYPqwt/ZYetipXweL+P 85jC690noIPOLrzjhFecxSCC4XelByuLSftdTmhoElsp68+Rt8LWhrbs1Yyw0Da19OLw 9BQRJO2+aiKFxh6pcJV9kf74A4bidCzTKtmNPzQJ4pqRdMOxWSn+j7Hb1A6M5D+3XBC8 /r1ht36ZdxanxzPn9n/+RK9r/O2B/+WMiEUvy0P1zv5cpJwcDPsKpewZTHJJXUuKSyWj cPZYoapQiL1/30Xl2KXi+1taaNB7h4MX/m3F5LXONlE+8U6BbMbPKOP3IolO5/sd/6jE S9LA== X-Gm-Message-State: ABy/qLaaT0dIIrutKmifz5yCjjxXUDgr/1GkZfGpbmzPaYc3WCxVb5p2 tySPXAJyB0cyPaDOm1BJMTQ= X-Received: by 2002:a17:90b:4b4c:b0:268:31f3:79d6 with SMTP id mi12-20020a17090b4b4c00b0026831f379d6mr9635389pjb.36.1690880504352; Tue, 01 Aug 2023 02:01:44 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm1592523pjj.1.2023.08.01.02.01.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 02:01:44 -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, linux-trace-devel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v3 3/6] sched, tracing: add to report task state in symbolic chars Date: Tue, 1 Aug 2023 17:01:21 +0800 Message-Id: <20230801090124.8050-4-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230801090124.8050-1-zegao@tencent.com> References: <20230801090124.8050-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: 1773018209054004586 X-GMAIL-MSGID: 1773018209054004586 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 | 54 +++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index fbb99a61f714..e507901bcab8 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 long __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 + BUG_ON(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 */ /* @@ -233,6 +255,7 @@ TRACE_EVENT(sched_switch, __field( pid_t, prev_pid ) __field( int, prev_prio ) __field( long, prev_state ) + __field( char, prev_state_char ) __array( char, next_comm, TASK_COMM_LEN ) __field( pid_t, next_pid ) __field( int, next_prio ) @@ -240,32 +263,19 @@ TRACE_EVENT(sched_switch, TP_fast_assign( memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); - __entry->prev_pid = prev->pid; - __entry->prev_prio = prev->prio; - __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); + __entry->prev_pid = prev->pid; + __entry->prev_prio = prev->prio; + __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); + __entry->prev_state_char = __trace_sched_switch_state_char(preempt, prev_state, prev); memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); - __entry->next_pid = next->pid; - __entry->next_prio = next->prio; + __entry->next_pid = next->pid; + __entry->next_prio = next->prio; /* 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) ); /* From patchwork Tue Aug 1 09:01:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 129203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2597432vqg; Tue, 1 Aug 2023 04:21:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlF6IaTT9AO7TXMHkYtBvsOtRfyO6gf7ipmHg9lMotxxddba8XhiV3AbiKIpXFSKvofl4WFZ X-Received: by 2002:a2e:8613:0:b0:2b9:cddc:adeb with SMTP id a19-20020a2e8613000000b002b9cddcadebmr2259648lji.29.1690888875855; Tue, 01 Aug 2023 04:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690888875; cv=none; d=google.com; s=arc-20160816; b=rOLJ9uqA8+G7nUOOVx+fm0rUWEUjROQWbbgPohezabs0CETaODStcj+MTvVbvKpa3E PaSpV5m7GMjG/rP+hjE27BQbHDo2GbF8YxC9Jb7E62mYY1uszrXHmO9BL7xuLnoCm4rm 8a8RyT8b3XxhPPII0AZvWeUScMyPQ3FrSyjpq9wp4QNUZlK1uDdwJE17p3S1hvHhzBjw NMWE5W0YOig6ZzalS/0nBfP1q7IoD/lgtwZidXaSGAKlZpIPk7UoqdvJllmhx3p5v3+K Z/mHulEoOH5mzWR4FcnaZRNF/euPo7Y4xZe99a82taz9h6jAOws6TXwQpBZ7eM4Psoji i1YQ== 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=jwyto1QFsZ2jeAqiVCVI7asIYgAtksL73lrshA0wpgo=; fh=4S4dukURCUlSsjzSa0Ofy3qHSrrdu/uT1HnGBPj5BK4=; b=R/jud+S2TkLbbopqYEEgypsCbSoyB/mp+F78DRQ4tJ64rxKBUUArEkcpH8BG9jptDO Zi+EOT+v07CHLmHkUE80dQAg6OkrJqYuubHpwM3TMlEeBiEtpCl+Dg5wnAkRjp6X4y89 7taUua0CcOwLM6hMTu8GyZBuQ1C23h8ZS7CBVd0B9PfCmBBuahLIZWIa58R5IFlX5Hms kvWbB0WiKXO0aVMz3S0VIsTSsfHudN0n2WQLVvbKrfjJ3VJwee/3Xy102pLfXJDH3RqB RAPIfbqVXHYv5GDOK2DSJEsVCJ0+gJV7ShO+Qo98KiWh7LqnjZmRGDBGdeon5wSSOhrG Jo4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=lIDBHFBL; 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 gl23-20020a170906e0d700b0099bc038eb2esi8600501ejb.201.2023.08.01.04.20.51; Tue, 01 Aug 2023 04:21:15 -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=lIDBHFBL; 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 S232236AbjHAJCC (ORCPT + 99 others); Tue, 1 Aug 2023 05:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232071AbjHAJB5 (ORCPT ); Tue, 1 Aug 2023 05:01:57 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F26301FC9; Tue, 1 Aug 2023 02:01:48 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-563c7aabf38so4324597a12.0; Tue, 01 Aug 2023 02:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690880508; x=1691485308; 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=jwyto1QFsZ2jeAqiVCVI7asIYgAtksL73lrshA0wpgo=; b=lIDBHFBLzSxp1aUAT4vFf2WIcvdBYXVTEUQJ5LuTg/1cEK7w0XPksFUvTLzZ0BwuSX 4h3FgP9Jctoibtc1e6GfTumd9W+2zRF91sFdIu9SINOI7T3Z2gwLbKKxUT5D9y1Blm86 kXuzE/BnL9/uLTShVTMOUcAQw61QV3yOvwPjs0nBxda2ciNLpXsYdRHaI9n5hnqOUraL HEchqUicHKhBBwCOGgxv5+b52EJHdyHqAEfrz/39CNJMAocXWISxjqAjmj/Ab/r5HGuB bpfUmBRGjAzeGK8cgZrj8QcLLu1Cnh42GCwNO8+eAxSDhBUaPMJGyTa0G0c0VUXLYaLQ amqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880508; x=1691485308; 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=jwyto1QFsZ2jeAqiVCVI7asIYgAtksL73lrshA0wpgo=; b=H/RWsp2XBN1nh9gpOtYLU4n5+TPh9cSscBwoJAXumS2TNPFXr9QDrT8lo8pDa6mnOx nnRJJM+VF2Bb2ezV0jlfDnU+c1u7Wmaps1kX67DeZMUNHF3A3oig56/VkHDWtXWmNuP3 sSHJSOegmZFmpBgFVojthRkfnthbzJyKzJbBMb5LAdDcj9xrakc9im0qtpJ+7OfAvPrN 5Po3Dto4jZhUyduJpReekWvGPVQyxyTdwebORXOsYmcK0lHCjK3FWyvFYGCtu3s9D9PJ EK2R66E76tcI8Ai35sPADVW7jrgVOjthbjRz6we3XtqQb2wMl6UtuDJ22QBPA9K4y90w 6s6w== X-Gm-Message-State: ABy/qLYgZPS3dRTh8gAhdnWUWqnwJadztwNRcHppp+lrRzVjRW4WS/kf 2vccLPLxDcZQkYhJn2CPhvbCSz/dughxcA== X-Received: by 2002:a17:90a:a085:b0:268:535f:7c15 with SMTP id r5-20020a17090aa08500b00268535f7c15mr14611417pjp.0.1690880508158; Tue, 01 Aug 2023 02:01:48 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm1592523pjj.1.2023.08.01.02.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 02:01:47 -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, linux-trace-devel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v3 4/6] sched, tracing: reorganize fields of switch event struct Date: Tue, 1 Aug 2023 17:01:22 +0800 Message-Id: <20230801090124.8050-5-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230801090124.8050-1-zegao@tencent.com> References: <20230801090124.8050-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: 1773025493821964623 X-GMAIL-MSGID: 1773025493821964623 Report priorities in 'short' and prev_state in 'int' to save some buffer space. And also reorder the fields so that we take struct alignment into consideration to make the record compact. Suggested-by: Steven Rostedt (Google) Signed-off-by: Ze Gao --- include/trace/events/sched.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index e507901bcab8..36863ffb00c6 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -188,7 +188,7 @@ DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new, TP_ARGS(p)); #ifdef CREATE_TRACE_POINTS -static inline long __trace_sched_switch_state(bool preempt, +static inline int __trace_sched_switch_state(bool preempt, unsigned int prev_state, struct task_struct *p) { @@ -251,25 +251,25 @@ TRACE_EVENT(sched_switch, TP_ARGS(preempt, prev, next, prev_state), TP_STRUCT__entry( - __array( char, prev_comm, TASK_COMM_LEN ) __field( pid_t, prev_pid ) - __field( int, prev_prio ) - __field( long, prev_state ) - __field( char, prev_state_char ) - __array( char, next_comm, TASK_COMM_LEN ) __field( pid_t, next_pid ) - __field( int, next_prio ) + __field( short, prev_prio ) + __field( short, next_prio ) + __field( int, prev_state ) + __array( char, prev_comm, TASK_COMM_LEN ) + __array( char, next_comm, TASK_COMM_LEN ) + __field( char, prev_state_char ) ), TP_fast_assign( - memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); __entry->prev_pid = prev->pid; - __entry->prev_prio = prev->prio; + __entry->next_pid = next->pid; + __entry->prev_prio = (short) prev->prio; + __entry->next_prio = (short) next->prio; __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); __entry->prev_state_char = __trace_sched_switch_state_char(preempt, prev_state, prev); memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); - __entry->next_pid = next->pid; - __entry->next_prio = next->prio; + memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); /* XXX SCHED_DEADLINE */ ), From patchwork Tue Aug 1 09:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 129098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2545527vqg; Tue, 1 Aug 2023 02:24:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlHJqhAMNtSfBTxXYkz6CehiYQ5KpSns/NpZfmgrYZ1B6ecHxEQW16Ew5Z6D6Us0hQwoRJ62 X-Received: by 2002:a17:907:2c47:b0:974:183a:54b6 with SMTP id hf7-20020a1709072c4700b00974183a54b6mr1620468ejc.33.1690881855653; Tue, 01 Aug 2023 02:24:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690881855; cv=none; d=google.com; s=arc-20160816; b=ucQSiMKhuPWVIfLOn8VY44I7HKML2vu+90pP4tbts+Y6G3M09DCxe0am9gAZH+L4bE XXFfZ9ieDoSkxEOvTwZfrwRr301VQiEVB0DsCdaqmDnM9Ms9bECF4+EJJ7SAZrYE78D7 GqEfL5Lsipy2AVPCjMHTyP9zDjpEOC2NGumlrH1eQKLVw4rm/YqHXgMKZH9up4HMWzJk aeg4dcHXvjnOdUILfSgiAkS8ybwxcmHFfsUHziUTtTOKVl/32X4kPNjs5P+MxM3m8It5 1EkkeY74tf7xgiJlskOJ6H9hosuFMI2Cr9OlQ9J2Y4i+SvggmCHIrrtHC4/2Z7pH80rf bF+w== 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=6ly2QJNLAEtTlKSCo6d7xttDO2/tTmofDJcjQHz0sLg=; fh=4S4dukURCUlSsjzSa0Ofy3qHSrrdu/uT1HnGBPj5BK4=; b=AWiglscvgoOCfQJWZlyrlPkiXLMWrOAuh5JMDUG3u8m4NNMtvVRk4lrSoebQbGa6VP VJeFYVzPYwKyHUgCcJpop829QcazUpID2XSPpQD1OXde9T51uJpFtvSwWsrtPu6tagR3 8lIqU747R/kiTCuLRGmEo4QX3S2CmoB5ZR2qQfBrLqEYsfLDtdy1LUzjjYVi13nQMXEU FpNMLBqtfeOKX+yvufes+LQbyD+ud0fLQmW7HUgwQhf/kwbWujuJ53MzccKPan9ySeyW 4sKO98IjsixRiK5UH93C5iZg+nbjkaUcegYLYzdFF9qkotQewyggsZP3hgKmmTRiBDxN wrkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hyyuAqCy; 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 ha5-20020a170906a88500b0098e41199c5dsi8315965ejb.417.2023.08.01.02.23.52; Tue, 01 Aug 2023 02:24:15 -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=hyyuAqCy; 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 S232366AbjHAJCU (ORCPT + 99 others); Tue, 1 Aug 2023 05:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbjHAJB7 (ORCPT ); Tue, 1 Aug 2023 05:01:59 -0400 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7B462101; Tue, 1 Aug 2023 02:01:52 -0700 (PDT) Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-78363cc070aso284289239f.1; Tue, 01 Aug 2023 02:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690880512; x=1691485312; 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=6ly2QJNLAEtTlKSCo6d7xttDO2/tTmofDJcjQHz0sLg=; b=hyyuAqCyfKq1hI6vDQjj50c2JrrsShWN1524EFNYdqnUb3k2Z3Lq03ZYIw/Vu0QpSF FggL5X4qgFMTuBFVyeo3QeYhDnwtB+Nr28nZGZFtCJ28OtgWw4DgPM2Qt3s+MzJNSpjO TGrlSoCFQfnkn0UdeKr7MLQQAlFEF1TlPYf9WPiF8EOGCia0PMFqjoAAFiPDYeewPYYL K+pm/rxv9AhT2UH42Jj6qbiDvmuUky+Fz6a4DiIJxcvv/+rtn/rYNYvLNgAkBUAfMilQ X7/PWqfASAaDv0BvRkBWQ3WDSkWgJAsJkRN4ML9xLTaI5vFmRikDQU6t2B/YwFkSjIh0 C5cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880512; x=1691485312; 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=6ly2QJNLAEtTlKSCo6d7xttDO2/tTmofDJcjQHz0sLg=; b=RWCT7Sx5Zi9p9GmVxfLZup5VoCt6GWKxsr4DLwInG5BBtDVwlj7xtrnP7ASrVz4QTe JN9IvZK6CSBguVJ1ptEXJjFE0rN3LHNRw++GSwtCgIupz6FOGMyG8gJIEeFJRrC9ny/l E84JWGfdBWznR7GtFzZxkxM83wS1bqN4wNxpCGYfphBXTGCMhnh+BlISkuR3c44exmXu 4yEKvim/HyUCeweKxFqTvGGpBWH3TIVBEX1lyJp3+UsSR6n319eqvBOnbcxyYLwDv7nl Cr+CzlewJINfolP+K07kjPeGpxTQlKuWWq/Op5ZQcviUCizXQd9E4wIR5orFXQpATF01 eT8Q== X-Gm-Message-State: ABy/qLbN86XNHs77O/d6nN3nCus6q8axvwVNTGMOLDQb/1ytkwYr9UXe qdxlr7AvJHIFlLSV13MKRVM= X-Received: by 2002:a05:6e02:218d:b0:346:d51:9922 with SMTP id j13-20020a056e02218d00b003460d519922mr14239768ila.13.1690880511998; Tue, 01 Aug 2023 02:01:51 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm1592523pjj.1.2023.08.01.02.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 02:01:51 -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, linux-trace-devel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v3 5/6] perf sched: prefer to use prev_state_char introduced in sched_switch Date: Tue, 1 Aug 2023 17:01:23 +0800 Message-Id: <20230801090124.8050-6-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230801090124.8050-1-zegao@tencent.com> References: <20230801090124.8050-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: 1773018133035810966 X-GMAIL-MSGID: 1773018133035810966 Since the sched_switch tracepoint introduces a new variable to report sched-out task state in symbolic char, we prefer to use it to spare from knowing internal implementations in kernel. Also we keep the old parsing logic intact but sync the state char array with the latest kernel. Signed-off-by: Ze Gao --- tools/perf/builtin-sched.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 275da655b67a..6ca60d4773d3 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -837,7 +837,7 @@ replay_wakeup_event(struct perf_sched *sched, static inline char task_state_char(int state) { - static const char state_to_char[] = "RSDTtXZPI"; + static const char state_to_char[] = "RSDTtXZPIp"; unsigned bit = state ? ffs(state) : 0; return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; } @@ -845,8 +845,20 @@ static inline char task_state_char(int state) static inline char get_task_prev_state(struct evsel *evsel, struct perf_sample *sample) { - const int prev_state = evsel__intval(evsel, sample, "prev_state"); - return task_state_char(prev_state); + char prev_state_char; + int prev_state; + + //prefer to use prev_state_char + if (evsel__field(evsel, "prev_state_char")) + prev_state_char = (char) evsel__intval(evsel, + sample, "prev_state_char"); + else { + prev_state = (int) evsel__intval(evsel, + sample, "prev_state"); + prev_state_char = task_state_char(prev_state); + } + + return prev_state_char; } static int replay_switch_event(struct perf_sched *sched, From patchwork Tue Aug 1 09:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 129150 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2567965vqg; Tue, 1 Aug 2023 03:18:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlGli7K99G79THi8qAnCuJ0eOt7QcCOshrFCC8kbpIUC3i2+yNfWZoMJcAIe8PmxTTZURefs X-Received: by 2002:a05:6808:3093:b0:3a4:894a:9f3d with SMTP id bl19-20020a056808309300b003a4894a9f3dmr15182736oib.41.1690885083935; Tue, 01 Aug 2023 03:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690885083; cv=none; d=google.com; s=arc-20160816; b=l5lZrymL3ZDKonqctUTOhRkExuAa4o6RVq/rz0Yxptu7QEOeGW0jl/hmvhmmlWB97m fU1wGCZuoX1y2u44mK1b890pNGXSdKtLudQmfcZScjUyrZgSxjzKgz4HMnjD7F8CNplP fP888IybUgaJDxKARO2SN2JOfXj+kt+LGebpBEyOl7L+SVl+1i1AJTJD6dEtfiA5qnDM e7Ot9Oot0+AgOGAt6+OYVK64kChHHHGC1XJAPIZk32LZo63PTnpaYiUKYKnkxr6aPZP6 2VyhurV3Xk+KXf1W2YxC/t1khm5HfzCond6wC2fDnJ4mOgcwP5LQ122k8kPd1qVQsMt/ FdVA== 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=w1czaeXwKPoW79DQXCoJFC1V8bFxJyQ215iwxz8lUyU=; fh=4S4dukURCUlSsjzSa0Ofy3qHSrrdu/uT1HnGBPj5BK4=; b=BSse506fX3l8AMKdZYnHhSZCFLt5MAyw3pJh8bEKisU9kRn6wLWKxdrO6hF23HPoGk z5bDifhMRt+1EB6iWpW/7y86dvJgz9CBn/Mh5g82qGK6jVf2owOrHmBsRggCwdENkiU/ Qyys0Z7Paaypgg/eg6nAo6QazodsM4ywW6RBbN/Prr5TLFh4iXqZmZea8vnC0GKtpYYh aI9K4wobMOtbqYZEMEKWtGHB1AfPlKYr8/aRwnUTrtOHOYe26Gs2lMr00EPloHTeZHq3 HajFvuY0W3F9admtxyDr4+Q0OJunuCbtAFGxmt9YfW725pzFb/eKpV+VZwfCi8jgVM1e YgHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ms8c2ZbB; 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 z125-20020a633383000000b0056401aefc55si1360122pgz.240.2023.08.01.03.17.51; Tue, 01 Aug 2023 03:18:03 -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=ms8c2ZbB; 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 S232430AbjHAJCf (ORCPT + 99 others); Tue, 1 Aug 2023 05:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231949AbjHAJCO (ORCPT ); Tue, 1 Aug 2023 05:02:14 -0400 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DEFB2121; Tue, 1 Aug 2023 02:01:56 -0700 (PDT) Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3a3efebcc24so4104504b6e.1; Tue, 01 Aug 2023 02:01:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690880516; x=1691485316; 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=w1czaeXwKPoW79DQXCoJFC1V8bFxJyQ215iwxz8lUyU=; b=ms8c2ZbB4R4fcbOy+mUJuwgXu4e0yufWtAlHMDXY2WnBmnyeTwE7ArkyOg6QsjA2bF SFuuk5Az0zk8szoQauYILOraZ47zU/hlFz++Kexz1kHY7bRL5ni1Q7n2u0vma1bhrKcx 9is5gEAYNI8Q7DXpoPBNDolyn3ifDb+Cswg7wY6ws96ts/SHMg7sXLMaBIx6NHz8eA4x IiW+VBQfO6KbRqBTLiKIqqnLAa+MoQil/+hq8vda8g3cCzy8U0SgyUK+PfNSBjd1m68g PZnJjsRC6jhWQm29Eo9oSg0WFrasNY1uIsqDwVxjf/q75cC/ICsVPyEhobGM1jBNjrCH MOcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690880516; x=1691485316; 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=w1czaeXwKPoW79DQXCoJFC1V8bFxJyQ215iwxz8lUyU=; b=aWBV2NJ9WTJ7m5VPHRi50sDgRREdhC84t+HJQoKN6hegMFAGhL13iGVHt/AqtOibhd segJb3lyOYaoXDi0S2NbMf2ZkudZyupzvsXO5mImsYz5eewNUlhS6Q9+9fnmDwbXzict zlIQ17lPTHWgiZzGihJQ+dJxV51PKMkv+510CEMopK0IV3lMoSzBIlDGX7PocvYp/nEd JZBB31t6K5fnnrkdnlQNjRt0t56Ua/y714yFrPYFo4By20r68C8byH+OB1Y/ILOP3Y/L /bveExIat7XcD+X+4NFS3mOmVSHEpYXh9vfjbnHodoZU5Noo8nu0OKceN1+oQK3COib+ 05Wg== X-Gm-Message-State: ABy/qLa3M5vnEp1eNchkDI/3EVhj7Gwwp2eRXojbqhxQ1kB7F4Cv0rrO Jo8IfQND0hbaA1MChE6P1mA= X-Received: by 2002:a05:6808:1595:b0:3a7:4e0c:faa9 with SMTP id t21-20020a056808159500b003a74e0cfaa9mr910611oiw.29.1690880515818; Tue, 01 Aug 2023 02:01:55 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm1592523pjj.1.2023.08.01.02.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 02:01:55 -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, linux-trace-devel@vger.kernel.org, Ze Gao Subject: [RFC PATCH v3 6/6] libtraceevent: prefer to use prev_state_char introduced in sched_switch Date: Tue, 1 Aug 2023 17:01:24 +0800 Message-Id: <20230801090124.8050-7-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230801090124.8050-1-zegao@tencent.com> References: <20230801090124.8050-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: 1773021517555064078 X-GMAIL-MSGID: 1773021517555064078 Since the sched_switch tracepoint introduces a new variable to report sched-out task state in symbolic char, we prefer to use it to spare from knowing internal implementations in kernel. Also we keep the old parsing logic intact but sync the state char array with the latest kernel. Signed-off-by: Ze Gao --- plugins/plugin_sched_switch.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/plugin_sched_switch.c b/plugins/plugin_sched_switch.c index 8752cae..4c57322 100644 --- a/plugins/plugin_sched_switch.c +++ b/plugins/plugin_sched_switch.c @@ -11,7 +11,7 @@ static void write_state(struct trace_seq *s, int val) { - const char states[] = "SDTtZXxW"; + const char states[] = "SDTtXZPIp"; int found = 0; int i; @@ -99,7 +99,12 @@ static int sched_switch_handler(struct trace_seq *s, if (tep_get_field_val(s, event, "prev_prio", record, &val, 1) == 0) trace_seq_printf(s, "[%d] ", (int) val); - if (tep_get_field_val(s, event, "prev_state", record, &val, 1) == 0) + //find if has prev_state_char, otherwise fallback to prev_state + if (tep_find_field(event, "prev_state_char")) { + if (tep_get_field_val(s, event, "prev_state_char", record, &val, 1) == 0) + trace_seq_putc(s, (char) val); + } + else if (tep_get_field_val(s, event, "prev_state", record, &val, 1) == 0) write_state(s, val); trace_seq_puts(s, " ==> ");