From patchwork Wed Aug 2 12:47: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: 13338138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0063C04FDF for ; Wed, 2 Aug 2023 12:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234869AbjHBMtO (ORCPT ); Wed, 2 Aug 2023 08:49:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234818AbjHBMtB (ORCPT ); Wed, 2 Aug 2023 08:49:01 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6057830C6; Wed, 2 Aug 2023 05:48:52 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2683add3662so4705778a91.1; Wed, 02 Aug 2023 05:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980532; x=1691585332; 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=u8lpjzm6rHULKX3RnedYfP137m4qvGL5uKJaH+JzOyE=; b=dsOEdkUxZ1tD0QOsLdlp1zsXXHcieudYGt0U2fn/8f2w/6NdSK5Nom90sLaMCS79VO LzqM7DSiv3m8Hwx1t07Zp19pmLFJJP2zZ9CmQCc0FSGxAQYwSJ2UM2Wz7IX8t5y7cvht /VJGkDkDYaZ1Z/vu0FhjBcDt6WKWLEY26NZ83tqM5JGm3h8Z0GleINZTIljljgp/xkGM WPxbr793xnvOXWGTd3A+7KkbCjd0N94kwA5ZIW7s8roJg6Z+Es0YwTH4qsn9JpljLHUv 9t126fNkmkPiX8RijOxRbPQAI1E+2Pwmza6sfmocbKLSsYEILpRw/DSffy3zvmN0xLcc kZBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980532; x=1691585332; 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=u8lpjzm6rHULKX3RnedYfP137m4qvGL5uKJaH+JzOyE=; b=EEU4+lsvkd7NInan/4M5KbL5Hxqiehvl+xqT0PvTqLf4xmKeUNtGIf0KhgD6lfH8w1 qHXlL7As0k2B5XxObHjDqzFZPgWVzsClGIQG1EwiqMc07f4WjxgTCp3hi0+4U5YUDV6J FMM3R8p8obuXaJa7xsudoab1kOdjZj63zZhF2hmATzLkBJz1GqAOip3Bs5tsibN9Z8Qe SEE6qSUmiHrT5WUTv7TQydtvjnuwWD4egwf5r8phMOXrRRNveBa0Ot8qP/w16Q+Svdv3 MB+fuHN7qE4Gt472HJEJSKOfgYJId0zalJ+bBiE7gq88jDGxsds878V41yn23GjWaO6N PDZA== X-Gm-Message-State: ABy/qLaAzkBBBuxFJhMR52rfCxoVNcDKuL3yi1C/QGP7ocgJgBHnGyFm DL+nm07c7jKrhSty44qUTTc= X-Google-Smtp-Source: APBJJlFZT7ZCW9/VkjiP1bSpFOyccekrrKdSn3AqKrrXWF9WWcXCPkdd1pDWteK/UbKlAYG8BxBNog== X-Received: by 2002:a17:90b:4a8d:b0:268:1217:46bc with SMTP id lp13-20020a17090b4a8d00b00268121746bcmr14634627pjb.11.1690980531731; Wed, 02 Aug 2023 05:48:51 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:48: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 v4 1/7] libtraceevent: sync state char array with the kernel Date: Wed, 2 Aug 2023 08:47:24 -0400 Message-ID: <20230802124840.335638-2-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Update state char array to match the latest kernel definitions. Signed-off-by: Ze Gao --- plugins/plugin_sched_switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/plugin_sched_switch.c b/plugins/plugin_sched_switch.c index 8752cae..e0986ac 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[] = "SDTtXZPI"; int found = 0; int i; From patchwork Wed Aug 2 12:47:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 13338139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52C42C00528 for ; Wed, 2 Aug 2023 12:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234836AbjHBMtU (ORCPT ); Wed, 2 Aug 2023 08:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234777AbjHBMtI (ORCPT ); Wed, 2 Aug 2023 08:49:08 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D46C73581; Wed, 2 Aug 2023 05:48:56 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-56433b1b12dso2361239a12.1; Wed, 02 Aug 2023 05:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980536; x=1691585336; 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=affZwz5TEk3WIR+PRuKQAQZIq234JaxujRitv/TmpCwQ1HiXjIUtfisiW6PsYsy2WJ z6H0HlNkN6qsdwiaIFnFaobjoGoPPbfnfQa2cqi9nAquKLz0X0Sd+ooFwFMDR1WwHPpE pegy5hefVZ0Zy/SPcKkxFZb9N2evvh0O/0r1N+JlU7TJwXsjTtL+sVl1K6fuiX37ABsg Jgs1lA22+oPPSEB0BqL9BVhE8KM78m2A56G8LPKum4AWTZOoDp719Fh5p5bCK/6k9ELP 613jSrxGDKHtBBvNGOGuQDN3uPGTJ2feM9YRuwotVBxZi1Bd3MS5qJCQcwOaaohs5hEp T1Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980536; x=1691585336; 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=BxG/avEX7AVvNaQZAd7x8iP02euQbX1nFijnWPPU4brc9/lwOJIk2zbntdApGWPljg eYVTQ2KfPETpIvuCgDQnZXzzx1KCdS/FjwpXK7UJL9d6g7aXO2+cDwy/vicdSL1w76eF aO0pafMKk6rinmDGBq8w9/j8grDr3Do7HUbDyLueAFg3ZLM2zsn1OUFAcJYDasKvtAWp z1i+9Sk0Rs9h/Yknus641hbCEKEC8OWWCIPUKv8ORmzjvIZF6xShap6E52HzyrAbqwTJ ZuD1IGEAmUnu4Q9ZDcx5DD8i6edLyclsH5BatP5p8abGyFmHYlSEuMZAj0TjPyyGABcI XzoA== X-Gm-Message-State: ABy/qLbjDzTKRrSNXXgkY4BM4IF0p7tWJ4Dr3NjTOUyCdlvhMuuzc66w 7FEkUhS2Tlu46RRrTf0ZMN8= X-Google-Smtp-Source: APBJJlGbwBrjxZSrIH+627bumLqD2mkRT9eSI5Q1xKxgYAsKG9qVBYCJYrIlLLDaF3pnUVITFpbiTw== X-Received: by 2002:a17:90b:1954:b0:256:8dbd:74fa with SMTP id nk20-20020a17090b195400b002568dbd74famr12027905pjb.22.1690980535749; Wed, 02 Aug 2023 05:48:55 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:48: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 v5 2/7] perf sched: sync state char array with the kernel Date: Wed, 2 Aug 2023 08:47:25 -0400 Message-ID: <20230802124840.335638-3-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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" /* 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 Wed Aug 2 12:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 13338140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC432C04FDF for ; Wed, 2 Aug 2023 12:49:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234751AbjHBMt0 (ORCPT ); Wed, 2 Aug 2023 08:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234788AbjHBMtJ (ORCPT ); Wed, 2 Aug 2023 08:49:09 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFE0212B; Wed, 2 Aug 2023 05:49:00 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-56487a5401bso131267a12.3; Wed, 02 Aug 2023 05:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980540; x=1691585340; 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=ZqGWXQUnHEGIAJjlk8NVej2IuOd14tKht3c5V5V3ivI=; b=mtOsLo07GMllEngNvb9+BqwcT7KAe81fbqwVPSDxezQtx9R2AIdEPawGkHCXKfy6EU rM8VkRK4Rxt7kcHvnT1IyKrCQMUISW2CKsEevszJxDVwBDTgFZBF6mry0a+5o/N1LQDN uC0DKs/PuonpeBIAaFtiX0zSCnljcsy/40Q2fszofzPbTmxwjwFH2ORITr3zwkVMmU2m OUJzeFQ0cUqFY2pEMVwouQZCUerqOs4jwfX5n8x+6ABL/ZyYnPsjMnDtJOKiv1hJ7ya1 wVRggbfxbLJsxFeGYbwuvFM0fjKTdKVQ0ANtzU5dDDsJCuhED4seqnTXBQpU3j3lAw7N UPpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980540; x=1691585340; 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=ZqGWXQUnHEGIAJjlk8NVej2IuOd14tKht3c5V5V3ivI=; b=hjHQI9iG6o1wEvkEJOOmK08ae+N52drb8k/pjP5wXf/6cS7vYaQHIjvH4HMp4VFptJ c6L4veXHEV8Fn4wVoD30msPz1z0k1vJzcaGinSuvvY4cN06r7zrFW/c9oCDGDfqyQzoK FbefpNv5BozHqsPz2SJ4HCqFdVsHjgwJZ07yjy+niB7zN2G0Ldx6hdX0mObSX8gRHWc3 H9EYN1UcPw2KAocAD9b1gjs5uXU1i46VIMWNbNWHddQAAQJ5D6QF7wDRuNx6IZMnna6V oY4FYRBHXsEzoTpPzaqxOur8V3thB9XFBdUd77QWmU/qg9BmDo3bmf/ROAI3pPtQxW/M d8BA== X-Gm-Message-State: ABy/qLYXBIoD/TJgGWMdj85Cu8Xexr2A/CqQyGaJS636wUeSDbSLs0+R lkt/k1XRfM7SkGs22nq8ey4= X-Google-Smtp-Source: APBJJlFjShZACk6pta2NRgdxfZ8vgVCM/fK1MmgGzGUheTbPNnbnvBCBDQuO9gxgsq8OvyrNiy31ag== X-Received: by 2002:a17:90a:2a48:b0:263:ac11:c6d2 with SMTP id d8-20020a17090a2a4800b00263ac11c6d2mr13717420pjg.25.1690980539783; Wed, 02 Aug 2023 05:48:59 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:48:59 -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 v5 3/7] perf sched: reorganize sched-out task state report code Date: Wed, 2 Aug 2023 08:47:26 -0400 Message-ID: <20230802124840.335638-4-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 8dc8f071721c..eb310d1a7625 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); @@ -2022,24 +2025,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(thread) == 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"); @@ -2080,7 +2071,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); @@ -2152,9 +2143,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->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; @@ -2579,7 +2570,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"); + const char state = get_task_prev_state(evsel, sample); addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) { From patchwork Wed Aug 2 12:47:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 13338141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DB6FC04E69 for ; Wed, 2 Aug 2023 12:49:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234854AbjHBMtj (ORCPT ); Wed, 2 Aug 2023 08:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234737AbjHBMtK (ORCPT ); Wed, 2 Aug 2023 08:49:10 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65FDB2D78; Wed, 2 Aug 2023 05:49:04 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-26830595676so4780327a91.2; Wed, 02 Aug 2023 05:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980544; x=1691585344; 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=DEZCAX1WlrsUv3nMNvtTambxp2M6PKeC7k4D0cytuU4=; b=lPf1TobbUrw1GTawCUCLEnAAjBp8pdwI/dfI2qxVqSsOzmaDY1I+0giZV4UOon5Bwx aaQF4Ez1LU7MqaKaQztnoUUnCEOS3Eo9ITZInVOl3qTGyypRbi/2ozpnE5g9DTNgvFDR x4gMWe1eSGUT5rT+cmAb9/RzoegOd+IagpZUOpNOvR1AP1oyn7kGFJiuAVsO5611TxVZ 0Qc1Ey/L3IONZ+w8KjzFyGeDwiU9z/JfUJmzka7SXLJFWahWxjGZBoIEnuI506kn4zoc UOIyu73yPY4qu+P4tWN2r0kNbC+L+GnMCrnAJNhvdYENrTKBF0XRIFiJEvenJCK2iEeU hJ+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980544; x=1691585344; 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=DEZCAX1WlrsUv3nMNvtTambxp2M6PKeC7k4D0cytuU4=; b=Pj0b3DTgqw67I7VUbLwPIRSOaDMesxzjgztKph26jTS07v7fXyxpxLH+p+9H+3V2sl bRVSPnqFOFN7SsWtUMvGJQyEMWDUPcpZPFkEFSYRNkmpzlLFrl5w1ivV57ina8/avrTD XuiuNCBG2g73w8oVyHmNsozH9MrENKkXIqikhAzuoaZSX+t39trq8079akrxo8xAIz5x er9BVzC/nZe+cQnzusnsxxRnY8Ap17OX/orEQ2MNdaYPpxx5AvKos73rOPWCaNBweLIl MRJt+umsaGmwmASIOj4RbZ+VFPTOgA6OFdY1cWZPs9te+sEEfF/VIj3XHeigtUFTNgTy 2JLg== X-Gm-Message-State: ABy/qLaPzKukVWihMC7q7QpC4wSgWTitabpugKDopXq1chY4KGwbF1HP yShPyyzeNNs+BmOiZffaW8I= X-Google-Smtp-Source: APBJJlGftl2PkKq0eq43TPyeopbrmeE6yjbx1dGMvYwvR4LfmIUg0CnVtmtReUApbmQhzTFdPXV2pQ== X-Received: by 2002:a17:90b:350b:b0:268:634f:61f2 with SMTP id ls11-20020a17090b350b00b00268634f61f2mr15998891pjb.17.1690980543891; Wed, 02 Aug 2023 05:49:03 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:49:03 -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 v5 4/7] sched, tracing: reorganize fields of switch event struct Date: Wed, 2 Aug 2023 08:47:27 -0400 Message-ID: <20230802124840.335638-5-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index fbb99a61f714..7d34db20b2c6 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -187,7 +187,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) { @@ -229,23 +229,23 @@ 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 ) - __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 ) ), 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->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); 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 Wed Aug 2 12:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 13338142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BDA9C41513 for ; Wed, 2 Aug 2023 12:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234905AbjHBMtw (ORCPT ); Wed, 2 Aug 2023 08:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234866AbjHBMtO (ORCPT ); Wed, 2 Aug 2023 08:49:14 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2A4726B0; Wed, 2 Aug 2023 05:49:08 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bbd2761f1bso56941595ad.2; Wed, 02 Aug 2023 05:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980548; x=1691585348; 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=g/qteU2mNw/BBJfHNte7O9hoGmnD/YD+enA+yhOHga4=; b=OP/jxunnVEjIALdrKgklqzA4TO2+S7yZyoB1vbzcHPo2X6iSraTju6MNy/9+cLsb0I taQTHYoyq2w90sy33wYlAJ3mIV/itOpiNrHrs8ni5c/sxk9SwynCw+cMAkmx5/3XaO23 uJSstfIzoSZPaoSyDGEbhJoGIP+LnCLdWcvbNVAOZHI77pnQhyMrAI1moxomYA2BNZJQ KEGFxlUuaUpR+ot+U0zWAn2nNBi4288T02gfxTbIZsiyQb8R2sqC4SkhLv4DoMzQKMLa 1Sr8TCBwWEMtoFHmJ1CJzneu/JOAvkXbjmm1+wpAelgMux60eLIaTMMqTgpF/hrXJDtV Zv0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980548; x=1691585348; 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=g/qteU2mNw/BBJfHNte7O9hoGmnD/YD+enA+yhOHga4=; b=HuZjXGx9xMf6ygdAChCGhZOlf95spDLPOIU79YBTM7Mhj9o0TMnMT5jUWNXNQBJ8Ie 9c4cYOqXhddL82LgfYpaxJpk1MxQs4m0vG//pHpVsb91rV4FsXnA4eEIEvGTemgd1nQ2 +AMsTEQTBxaGp6IQQGGnUn29ykVea4e27DzrJqh9XfUSJL9HpHhdBaeKnQfffmggBRMX sNf4twc//qGt4tnBMeFAGFOX6RwLUV1fUOskAXA2kzAkS5KTEQi0GmDE7LrwM6Nh4DZI wMp8pZmlN4JEC5wrhYlTqTuIaEG2Mig0dgLuTyGCyXtHPk8b+0baDhgOgAUMN0/8uMRm KXGA== X-Gm-Message-State: ABy/qLYa2kc1JvUWi7QX4cMe9H+F6Ts99fr20agiuPtmiRNH64Huz4ti lvZIXTcR9W/EUS83BZI8Ri4= X-Google-Smtp-Source: APBJJlHA7AJrJkY/XmvFc7K43FnZWwxGk3ty+ElpOYp1l0MN4z7lr7JxaCvjQdtuVGYHvkLSxSWktQ== X-Received: by 2002:a17:902:dac4:b0:1b8:8dbd:e1a0 with SMTP id q4-20020a170902dac400b001b88dbde1a0mr18050733plx.13.1690980548101; Wed, 02 Aug 2023 05:49:08 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:49:07 -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 v5 5/7] sched, tracing: add to report task state in symbolic chars Date: Wed, 2 Aug 2023 08:47:28 -0400 Message-ID: <20230802124840.335638-6-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 7d34db20b2c6..1c7b94793495 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 int __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 */ /* @@ -236,6 +258,7 @@ TRACE_EVENT(sched_switch, __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( @@ -246,26 +269,13 @@ TRACE_EVENT(sched_switch, __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); + __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) ); /* From patchwork Wed Aug 2 12:47:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 13338143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E59A2C04FE0 for ; Wed, 2 Aug 2023 12:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234876AbjHBMty (ORCPT ); Wed, 2 Aug 2023 08:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234822AbjHBMtP (ORCPT ); Wed, 2 Aug 2023 08:49:15 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E92271F; Wed, 2 Aug 2023 05:49:12 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-790ab117bd5so120086739f.0; Wed, 02 Aug 2023 05:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980552; x=1691585352; 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=GPn/mgTWKV+oBePvxacidtJnH5NXaYh0/ilB9/OG6C4=; b=BsmjiHo5WQQKClP5ASFtdsx0MlRD8yQSsvBGCM+NZ5GvwEDKFO8y8x02RduX1Q6Hm6 CPuaI/jLsxd9z57uutSrPQ/rPOttOx01/WFA9pyta/NEqdzAgQCF1ZTBA9m8iM1/kpH3 z65NBjwVeazO0Q8Fc2/yZui8mj2KvOcJTGPVddZxrfMPGHLddhmkwsjCZrSvoWbOl6PY KSP2aAZQBr9d9BufbCAvdlad/j3ulGI8JGqpcRfoX87o1QRM+qO8z7oYSjF6YKA4Gx+u A+tw5BJaWOYgThrR+7cZsLAHUHDjeb4pxkr0vdUxgfJoZvAA9VhrD0lJwG1rFh/ISIwO DPWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980552; x=1691585352; 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=GPn/mgTWKV+oBePvxacidtJnH5NXaYh0/ilB9/OG6C4=; b=AmyxQjQpYDADpRvLQrE0r2Ib59A3+9pmM4Au7H/AvglyvXT8ZxNeoleArPhD3aOxfA ewsAVtazXP1xPUBmJ3H4Dzs3vrfjjlLYEBAvhGJspvg3f8nX1HBJTfw9j4BNcwEXVdDO mx9NSNF289GaauZfB/lKj0j1T2egU7inW2HlljBOnWdMTohto0L/y/6m9qDIHe5UAt/A V+Vk3KBs8ms9tJWJa+ZFtFPS5WwCm8joCZGF+yKvkOD9XbWAPD8xUtfHIBIK2ih9z+V2 15ZFOmngC7j/7ZzAxz67HIq2X7LDZD8ESXzyfuTz6VouGYEb+tbBeZE688ZY4owfW3w5 /Sgg== X-Gm-Message-State: ABy/qLbSNwiNFPEGTRpqjLcLUg/pg1snIpU5KMAR4Lb6EiBDtTABIezF sBiuGV77I0ziFmCezai5LUg= X-Google-Smtp-Source: APBJJlErD1wHdBCAteMiisn+oi7DyRmull0LoxCEYSB3RmEGXwBJDpTihPy1OWjYPqu/tWZPejeyiQ== X-Received: by 2002:a05:6e02:1521:b0:346:f30:ad58 with SMTP id i1-20020a056e02152100b003460f30ad58mr16967213ilu.24.1690980552110; Wed, 02 Aug 2023 05:49:12 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:49:11 -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 v4 6/7] libtraceevent: prefer to use prev_state_char introduced in sched_switch Date: Wed, 2 Aug 2023 08:47:29 -0400 Message-ID: <20230802124840.335638-7-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 e0986ac..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[] = "SDTtXZPI"; + 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, " ==> "); From patchwork Wed Aug 2 12:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 13338144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D393C001E0 for ; Wed, 2 Aug 2023 12:49:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234924AbjHBMt5 (ORCPT ); Wed, 2 Aug 2023 08:49:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234818AbjHBMtT (ORCPT ); Wed, 2 Aug 2023 08:49:19 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDEDA2D4A; Wed, 2 Aug 2023 05:49:16 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bbc64f9a91so57190995ad.0; Wed, 02 Aug 2023 05:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690980556; x=1691585356; 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=KWetw+9fo7xpR+/Y1RDX5IOHvVHf8sfB8Rgzd3Bsv2A=; b=GIHzjFSzPcLYW4yJrPyLa5ImpMP+/3NnozdLXPCWfIEItaUDWT708653DBDRF9JDF1 7KJP2GCIClBAH9TSQ1KVLatrwc9yTBnkpzhENvv4RrL7sEfnb7UiXjrEyIlloYFhdoPb kV1D/qaJGKouufSXYhMmCQ6s3RuM7Snwrzt8TCemadIkH1WZ+Bjv5jWhtNkd1ZyZsdBX V9GoTGqzCtbsRZqsjZNFncaj+eA6BDJ5scmBkGEoP4jvts/pO08/1t3W/xVXwEtFegRb mzsuOG7V5o6E5TBzDQ56qCiReA6n102vgs9RiJ+P/P0i3axrYk1X/byHeLt3snHWyPwR aBRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690980556; x=1691585356; 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=KWetw+9fo7xpR+/Y1RDX5IOHvVHf8sfB8Rgzd3Bsv2A=; b=RMSoKbTxu3CpfqqqlJ8ThXzPCJWfgfEffOJ+UcwW8a6y1beW0RG+b/SnFhC7ISv7J6 klf1g5KJosImE4XA5lCwxTdElzxzIzEKRC0anRqfTGYZHTVq8E9nMA1Y+cABTICiWdRP OHmV6+J8uJE9ck4nuSaKbeL6ikmaHwioqzGVwbM75G4EfS7TuTVPUGwD+vMBipJ9CoFJ gm4BhbZQmuCudJuwOKc/M9CrGWR/WtIRyToMm4D4+1u7gP5ml1CdIZcUVMiVscAheDag gb9ROKYR/7ZZ7mXxZ+GF6Ro/JyERrMXvaxUr00+8PvzN3zMaR8rEvsrP6ROALB8f1g1A O51g== X-Gm-Message-State: ABy/qLZuDCHWBNqKL7p9vDfX2eQe2sthYRGpbuwsAicoEU7GhDk9tWvK TlQSUNChgeVRSVxMwds3nks= X-Google-Smtp-Source: APBJJlHw4hmPYrgetk+3UmXtsG7PL5InI9GFCxvW4F0oTwPBOrp7ldLy1FZuk2Y69spe/Xv1ftUHXA== X-Received: by 2002:a17:902:f551:b0:1ae:8892:7d27 with SMTP id h17-20020a170902f55100b001ae88927d27mr17956049plf.42.1690980556116; Wed, 02 Aug 2023 05:49:16 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.17]) by smtp.googlemail.com with ESMTPSA id x34-20020a17090a6c2500b00264044cca0fsm4811993pjj.1.2023.08.02.05.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 05:49:15 -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 v5 7/7] perf sched: prefer to use prev_state_char introduced in sched_switch Date: Wed, 2 Aug 2023 08:47:30 -0400 Message-ID: <20230802124840.335638-8-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802124840.335638-1-zegao@tencent.com> References: <20230802124840.335638-1-zegao@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index eb310d1a7625..7f76ba51e36d 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, @@ -2143,7 +2155,7 @@ 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 == 'R') + if (r->last_state == 'R' || r->last_state == 'p') r->dt_preempt = dt_wait; else if (r->last_state == 'D') r->dt_iowait = dt_wait;