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: 13336024 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 315C4C04E69 for ; Tue, 1 Aug 2023 09:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231743AbjHAJBk (ORCPT ); Tue, 1 Aug 2023 05:01:40 -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-Google-Smtp-Source: APBJJlHq2Lm3+F6k9MivoIGydF/yhZu/S3lgtq1fxoPlsdCFWRgrMkABOwQpROpeXd/v4xKjcex5xg== 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 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. 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: 13336025 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 2D614C001E0 for ; Tue, 1 Aug 2023 09:01:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231919AbjHAJBn (ORCPT ); Tue, 1 Aug 2023 05:01:43 -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-Google-Smtp-Source: APBJJlEowuQrpkipas305RJSKP6JUFe4LdY1CxvA62HmjQx6UH0kvPkuzKFb9fVhdUX7Pt4bCWBxcw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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: 13336026 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 A057DC001E0 for ; Tue, 1 Aug 2023 09:01:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232173AbjHAJB5 (ORCPT ); Tue, 1 Aug 2023 05:01:57 -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-Google-Smtp-Source: APBJJlGNAFkldW0pFDmQA6SMOwnw+zJDxri1fsp82e+tU2NsdUEA7z8xoSGFUv31M8l9BiIiYyOqBQ== 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 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 | 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: 13336027 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 25208C001DF for ; Tue, 1 Aug 2023 09:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232105AbjHAJCB (ORCPT ); Tue, 1 Aug 2023 05:02:01 -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-Google-Smtp-Source: APBJJlGAMx9FctmI958cHsKiDCC6mhfuY35vspd5N962LCOAh9RlZF919nW0hnNKEMk/HXwUfpXrhQ== 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 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 | 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: 13336028 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 340EFC04E69 for ; Tue, 1 Aug 2023 09:02:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232335AbjHAJCS (ORCPT ); Tue, 1 Aug 2023 05:02:18 -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-Google-Smtp-Source: APBJJlFPmEwgJhL3yR0VN9ChGXsHvr+G++Y7pVp45DkKxQeeCKMl6D9N82WEZwxntTt3X2C2DMHq7Q== 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 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 | 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: 13336029 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 5D883C001E0 for ; Tue, 1 Aug 2023 09:02:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjHAJCX (ORCPT ); Tue, 1 Aug 2023 05:02:23 -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-Google-Smtp-Source: APBJJlEgEGfL/Sa0Hc20kBqI0KCpcup53YVIjfJ2cJlZF3NxpUjHae3cj6zpEWs3NbpHX6xjWwFvxw== 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 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 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, " ==> ");