From patchwork Mon Jan 15 07:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 188044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1547901dyc; Sun, 14 Jan 2024 23:24:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFY0N2ugnWvzMcbOq+4ESmb2PDd+U/J2kaitGmJK9aeFugtDvt3oF4zeo8xLBd/LzkbP+Uj X-Received: by 2002:a05:6402:2024:b0:558:858a:2cb with SMTP id ay4-20020a056402202400b00558858a02cbmr1146075edb.136.1705303456505; Sun, 14 Jan 2024 23:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705303456; cv=none; d=google.com; s=arc-20160816; b=WOb/e95kfEZU9oTWjRw98rGfkCN7eDeOqGteCnx1mPq1W+IpGiy30mYO4+eP/BiWwa +R4z7frfEIRlNX6g5dNMmKNoekfUNv/FbBzknntgKlJwpUU7Paz1fMPeijEietpA1oUD XJbki0ZNXi4BLbuweW21xjAmnQg17dRkh8tCQisLmVo1FqnE7BVmYu+6BSS1a+HHRtch dMsf0dpD9/yKZeLYprjUSV5Eb0U2ESTATQhlAeZ82zypG1NLrFUL5am+4TluMs/QYco3 cHOnFBVAkNZNvH5HJVmtHyr+G4JbSyqTn45XBicrP3am+bA/bIa//gVzbWjY0fbe9q9w LzJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YO7169RMuikSZ+p+ScnKGybrX+FP44pJIaHfIqNNpC4=; fh=BA7X0Fh+nH6aOBOR/HncHKQUGXeIUOSOgeWoVcIZnUI=; b=yng08tITmY19u2Vx/mbE9VeQslfmsjnrsMe4t33LTGfVlK/ZedKNB6GXZcIox7xLQL sgwBXD4aDjPNocHIinHO/WrJ9MUTwFAwZnAlHRFznWjESpq+gq3pn5+txrUaweIsw/YA yq/AXBHBLK5M74/bz9d2nT9En4+TJg3+BRiKxYrXO1IniQoiM2czIZv3j9XC7Fw0aWYQ /gl+UPoa0Excfg7sjsWlljZYimVewbFMcA2nE/cM0ucBxQ0+i/ETD1jyz4GYO4bz1yYC L6/B9Q+5vwQKQXugWWdiC87gtYIrLkpnvOFwZe70NWYz8d/MTO4AzAZAtrZZHXQSuiaW 0btw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NPT6SAj7; spf=pass (google.com: domain of linux-kernel+bounces-25679-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bl5-20020a056402210500b00558611c29f4si3700168edb.246.2024.01.14.23.24.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:24:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25679-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NPT6SAj7; spf=pass (google.com: domain of linux-kernel+bounces-25679-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E24B31F21446 for ; Mon, 15 Jan 2024 07:24:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF40B882E; Mon, 15 Jan 2024 07:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NPT6SAj7" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 142257494; Mon, 15 Jan 2024 07:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d4ab4e65aeso58280325ad.0; Sun, 14 Jan 2024 23:23:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705303404; x=1705908204; darn=vger.kernel.org; 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=YO7169RMuikSZ+p+ScnKGybrX+FP44pJIaHfIqNNpC4=; b=NPT6SAj7tFpW8DVZt5J7KX1PzlFXZxp4eEOG7PfZno4D/xTDkw32prpj6fkypbEz6q W0EDED7VeYOH9+9VKk4pVCO4d5KNT5fVlsQkWqw1Syie95r0L/6WrzZofh9fJNJltqu7 2UCcSfN9RYkbAlhaRA7vpboPGBwnEI4CU8Vf/TGfuk8qbQbY3x62dM2lNRTzY0QHadu5 0AHqw7UG4ki2LS6J4HR3xZXr+h4AUT5spTEJqYH/B4qJr448mmqfS60gpbYpprHF8rwe RSyn5HwTTIYyjhSRvykZVGCYdoxXkvS8iF62SnLCVsEHEM9KmBZOnTYG8Am138PwyV32 WgUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705303404; x=1705908204; 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=YO7169RMuikSZ+p+ScnKGybrX+FP44pJIaHfIqNNpC4=; b=OI48LYIzIVpe0FSQ8c9ciFR/HpQ0mE5/UTWLbmp/s/3h6hpyBJSkv/svaRBdnJyCvQ CKomc0rNrtWxHMeeLE1ZIQBVJBoqI8CJOeLGIglVgWJieLPWzvYasnJKuUjtMTIkqbLU 3dj2zls7ymEX1JvB8cXyBWFQy7hArRfwgaSihAnUT42thLrDZFIv802eCs7y9N2fsDv2 xWJfQu6upfURuql65dTVWxSulIdoOtQreQ0S8y4+fbFQ62djSidWz9ex/9TYmeRwrKBR OoMmJZ1Hz+01kEjKGtqNU7cva2WldvKf3XMJKdLFBOJjWJXKKqdo2hO9jb/FBB5OpB0/ xeIA== X-Gm-Message-State: AOJu0YwSpvFjVhohkKDO6WLSGtFd+AN5ewHP8TLFZfK5JtCzQ7y8JzP1 KfKcE2cuHWl3ROqz0ZZeK98= X-Received: by 2002:a17:902:db0c:b0:1d4:2bae:49f with SMTP id m12-20020a170902db0c00b001d42bae049fmr8005525plx.26.1705303404449; Sun, 14 Jan 2024 23:23:24 -0800 (PST) Received: from localhost.localdomain ([203.205.141.87]) by smtp.googlemail.com with ESMTPSA id mp13-20020a170902fd0d00b001d4ac8ac969sm6990545plb.275.2024.01.14.23.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:23:24 -0800 (PST) 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 , Namhyung Kim , Peter Zijlstra , Steven Rostedt Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Ze Gao Subject: [PATCH 3/4] perf util: Add evsel__taskstate() to parse the task state info instead Date: Mon, 15 Jan 2024 02:23:05 -0500 Message-ID: <20240115072306.303993-4-zegao@tencent.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240115072306.303993-1-zegao@tencent.com> References: <20240115072306.303993-1-zegao@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788140276976918864 X-GMAIL-MSGID: 1788140276976918864 Now that we have the __prinf_flags() parsing routines, we add a new helper evsel__taskstate() to extract the task state info from the recorded data. Signed-off-by: Ze Gao --- tools/perf/util/evsel.c | 36 +++++++++++++++++++++++++++++++++++- tools/perf/util/evsel.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 98edf42fcf80..bc256bdc58d9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2906,7 +2906,7 @@ search_op(struct tep_format_field *prev_state_field, struct tep_print_arg *arg) return sym; } -static __maybe_unused const char *get_states(struct tep_format_field *prev_state_field) +static const char *get_states(struct tep_format_field *prev_state_field) { struct tep_print_flag_sym *sym; struct tep_print_arg *arg; @@ -2930,6 +2930,40 @@ static __maybe_unused const char *get_states(struct tep_format_field *prev_state } return NULL; } + +char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name) +{ + static struct tep_format_field *prev_state_field; + static const char *states; + struct tep_format_field *field; + unsigned long long val; + unsigned int bit; + char state = '?'; /* '?' denotes unknown task state */ + + field = evsel__field(evsel, name); + + if (!field) + return state; + + if (!states || field != prev_state_field) { + states = get_states(field); + if (!states) + return state; + prev_state_field = field; + } + + /* + * Note since the kernel exposes TASK_REPORT_MAX to userspace + * to denote the 'preempted' state, we might as welll report + * 'R' for this case, which make senses to users as well. + * + * We can change this if we have a good reason in the future. + */ + val = evsel__intval(evsel, sample, name); + bit = val ? ffs(val) : 0; + state = (!bit || bit > strlen(states)) ? 'R' : states[bit-1]; + return state; +} #endif bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index d791316a1792..55a7a6210513 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -338,6 +338,7 @@ struct perf_sample; void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const char *name); +char evsel__taskstate(struct evsel *evsel, struct perf_sample *sample, const char *name); static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) {