From patchwork Mon Jan 15 07:23:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 188042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1547772dyc; Sun, 14 Jan 2024 23:23:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBj78K8RSQtsjiunlh9/2L1hE7PVVnYZpRYc3au7mAcFnvOUvOsa61ukLZSs1dueItCew7 X-Received: by 2002:a2e:9b8d:0:b0:2cc:3f95:a9d7 with SMTP id z13-20020a2e9b8d000000b002cc3f95a9d7mr1067677lji.124.1705303425721; Sun, 14 Jan 2024 23:23:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705303425; cv=none; d=google.com; s=arc-20160816; b=bWkTBi5fFmy2Qn6gXZbZJMSB/nxFvlEOyiDkMTWAm/R4Ds+2uIM3dIACdP1UG8VKup 082pIeoCtvhfY/TBKMcY64UtOIcteXZGmRYsWgPsNPg3skx4XG76WebnAdr3T2cRRnK1 7fYJ8OxXlmQCJH0/Gs76b2udkv7C0UP3oQR9h67J0xZbd/SnyPFGhYvh9IQwQGIa3w+H T8W6h4j/m3fsSwLaLsCvqJ7NoZkN9/EdpaFOD1fwPcDid0XPJW+hFpW3+UE+W9fEuxZf VJ1buUfUr3aIMOoZn98hus+eFqP5Q5QTVpteuijnbB6VH68GClIYLPEZ4ieqyygy3RTY L5Rg== 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=8DlrDFe5Y9kinmI2EZideUfaxC8SBA39wYnKFZevMC4=; fh=BA7X0Fh+nH6aOBOR/HncHKQUGXeIUOSOgeWoVcIZnUI=; b=bYbcRI+kbi/TydDTfkGXZwuISjLSrq19FEZOT/CtAU0eUYXazWKipCaylhIILoGbqm p0iJTi8NesOqi6AKoH7/11j496y2SB4NrZVyn07J/uli7Zxb15THl6kHop64VKhe8/eT zdt7g+F6WitvlvyJTxinKxKiBBWMiHQQvgXy90fvUlor3N6xcmFrTsRkEyLrKN5VzUUw 9Z2LIdgEclunXPikMkk5+6CXcy08o1QVm7U4O1d5W6H234B+l6pUQm26jtocuMvcEFee WmpNyTHKTX9tO1AZ5qx45sZAV5F3jlnVX52h4taqZpxPYM6zVgc9D3CwPW1isu46o7oC HkSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zq4GRdCj; spf=pass (google.com: domain of linux-kernel+bounces-25677-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25677-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.23.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:23:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25677-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=Zq4GRdCj; spf=pass (google.com: domain of linux-kernel+bounces-25677-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25677-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 5509B1F21734 for ; Mon, 15 Jan 2024 07:23:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 461A56FC3; Mon, 15 Jan 2024 07:23:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zq4GRdCj" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 63D765689; Mon, 15 Jan 2024 07:23:18 +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-pf1-f175.google.com with SMTP id d2e1a72fcca58-6db82a57c50so139084b3a.2; Sun, 14 Jan 2024 23:23:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705303397; x=1705908197; 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=8DlrDFe5Y9kinmI2EZideUfaxC8SBA39wYnKFZevMC4=; b=Zq4GRdCjLOm7sEchNmh0mcQHOS4A9aiqwbcgYazxifGMNe4YsFs8Y7J8SCqhpqhgSM FzLy7A1xWQw+Lh6WkH33B+eLZnUJ2O+buGTKOgCHsyMNaDYyc3pwxim8vv37rRGc4tRW nBZZuWrOqD/Bt6eOD5FjxpSWEeI45sPscSdOwh/U5BQ/HEAx3J+rDYOyZUu510gWNkqC BcwPhxSaZ3acYj/M7O6chnkWzntMPD70Zj6adZqGxjGR9W8JhgxO7br7rOyY3N3wYb/1 JsBpgim7mwjVCj7IZvAWby3H/FuJRtrnjjFPhnjIjBwCO+Voqg5ttahIVCzvyDBHltxb 2n9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705303397; x=1705908197; 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=8DlrDFe5Y9kinmI2EZideUfaxC8SBA39wYnKFZevMC4=; b=XzHWUavCF26rToFBWs2WIfU5BlRPNk4C3biMj+Gh8D2otj9Otx3rQS0tjxUArLpWpX Y12PjUHaWolZYrpr0c5v7ME2kXoYdz4oP2YPTIB+NLO2+RfM1DhkNy2SHc35zau65BAL 6ismycnN6GrHXeIO6Z3JHHBR595zJgDbcnMpPyXiDjpKjMS5V9tWlC+qr9dkZV2BRQme xw48ig84MibxbKdNla5GtbTxylmfjUzei0tghqBIQZJOGv97glcqYrc0AVfXy7eaqoaL 8c6ehxMTExgaEsna7SaKE6BKraSNn9DmrIQyxmvxomb+j9O9GzpD48WMQfDKWzCXnB5A HfHw== X-Gm-Message-State: AOJu0YxZoCVVTQli7JnKqyPK9Ayp69SfnU3dcLzZwzdjr/F2r7ocxVbM m28f0zTmxstM1orBpyeILxE= X-Received: by 2002:a05:6a21:1a4:b0:19a:757f:2db5 with SMTP id le36-20020a056a2101a400b0019a757f2db5mr2012329pzb.8.1705303397599; Sun, 14 Jan 2024 23:23:17 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:23:17 -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 1/4] perf sched: Sync state char array with the kernel Date: Mon, 15 Jan 2024 02:23:03 -0500 Message-ID: <20240115072306.303993-2-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: 1788140245246982474 X-GMAIL-MSGID: 1788140245246982474 Update state char array to match the latest kernel definitions and remove unused state mapping macros. Note this is the preparing patch for get rid of the way to parse process state from raw bitmask value. Instead we are going to parse it from the recorded tracepoint print format, and this change marks why we're doing it. 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 dd6065afbbaf..ced6fffe8110 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 Mon Jan 15 07:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 188043 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1547832dyc; Sun, 14 Jan 2024 23:24:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGd9A3hMMux0tlZC/a5BJs0SsWnUt2smoSrft7mgfjr3+L5WU++FSywU0EzweBlkelCaYdJ X-Received: by 2002:a92:6b0b:0:b0:35f:f4ae:955e with SMTP id g11-20020a926b0b000000b0035ff4ae955emr1030216ilc.35.1705303440062; Sun, 14 Jan 2024 23:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705303440; cv=none; d=google.com; s=arc-20160816; b=F8rAocQj19xdKXjxclwH3oM2zqkpgw40PikS2HpifZtXeLMbsncSfn8FJp/+t8K3K9 0TqJXWlDmCRcepIi+8ZfgYNO2W8cRzglNBVlbf1vZljWXflyD4bFCVZIzmUtAqUv6v/T N71RtiCM7zRd/R3RWcY+Rfn9cMj7gisO5gNeHd0exc85J3MWFsj0xOpFqCb1h3O8I50d o2hP15Q9BxrHb6Snqoz28LDSD3MHbxWQg/5RD3P0cTT1evx9JbB1g2wCre/cECFehPAe Jn5lDESihx73RrwQ05V+LRG/hevqqWh6xvUQPB9Hrqxryw1XErf3Ef57vzvRGT1J41/2 4a8Q== 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=C/dKJoVMA2YV+Bmb+1jLCdgMm+0uodJZZ6nPFfWpQiA=; fh=BA7X0Fh+nH6aOBOR/HncHKQUGXeIUOSOgeWoVcIZnUI=; b=cYm8AoNuTll5I5ItSrnORs1IL4cNqDqEUfaU1OU+sFwQlLOQCSmPqQAxzRExcqrZe2 1dKFRi9va7w8TORGy1xdiF+KyRpl/3d7m0LIme4DypED0HPrZFQGJYqeuGN2uGnScAo+ oCN+rSfkswXsZBRNgYrdGx2RB5TGhYAeQPMIxO1L1n3/5SiIsLXjo8Lz40C0Pd4Ez4jM agyCCQeL65Nz8K1t+sVlF6A1jnghYdZT1v0Vx+aUfGf4ge3GZjrMhC/x1IUlG7fz2MeU AU3NVulVZ8CdkkGo8pE0y655yByJp2PDAn0rXVSRZe9rxsyo3gF5skf07gBLM9DD0tdZ DUbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="kygU50m/"; spf=pass (google.com: domain of linux-kernel+bounces-25678-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w13-20020a63d74d000000b005cdbeb97153si8054610pgi.86.2024.01.14.23.23.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:24:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25678-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="kygU50m/"; spf=pass (google.com: domain of linux-kernel+bounces-25678-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25678-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C7F1F28184D for ; Mon, 15 Jan 2024 07:23:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2156F79CB; Mon, 15 Jan 2024 07:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kygU50m/" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 D23556FB6; Mon, 15 Jan 2024 07:23:21 +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-f175.google.com with SMTP id d9443c01a7336-1d3e2972f65so33125475ad.3; Sun, 14 Jan 2024 23:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705303401; x=1705908201; 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=C/dKJoVMA2YV+Bmb+1jLCdgMm+0uodJZZ6nPFfWpQiA=; b=kygU50m/O/oVO6N4SF1cr6cQFBSP5ctQEVKQxO6pvU8y+4xe/V3vCsB0guEyUX2m2c IYGjqiQGDvymsXD6kXsXcV/SnWRCx5Zry0BfwAkY1glqpHYSG+Em0Lki0KseVg8bGwmE NLXi0Ks+f/pFB7QsfZFR/P3iopfJdrb4RwVip4vOrOjEg7Mz0WejadaE4GbM3eF//7Eb qqpNZnuYNsYa9Jj9mgAXtLE1fov9y4IYTGYtZFwNqtrF4yiL+q4PtFMqk2wALI4vhntM qhPa24hO5qDbl6Mwz23g4LsT9qGmNq+7FLorfRA6BXWij0QopuPMioFbTNAxpjljX5DJ iNXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705303401; x=1705908201; 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=C/dKJoVMA2YV+Bmb+1jLCdgMm+0uodJZZ6nPFfWpQiA=; b=n8JAu7c06IUiA97cPKxQhlR3Ye7qkNH2n0SfSoPLonrB95XKPnvNJsfsz9P0bRDVuY Zjgasa92zIQ957A+RLOwYegboYqh8U+jou++dOW5ShvZXdDxLxzOXzXVxem5RMIt0kh9 moHbRJINkXbIZZ/xgDKYyCv9KOdhgtmq9LRIxSpkfXGOLfMp7p7OL9dVsCzTAV1qiSdT twam5F/LtwS3ZN4HZBVinxOqWiMsI9qSPYlusWqAXNTsknhXJSFI4RNWEUkfC1/JDEc2 iJltcuCp9h20x3umnhqlUdn8e77yrZIchYchNIJZrUFY7uQvrC0r9JJ1RlghCvxXIhIX hPlg== X-Gm-Message-State: AOJu0YwKZoFMFpQV0DHU6w10K9jL4xR+TWYaBEsP7kZys5hhfuJQGJHc SijI+/tS/y/6kUjjFliBjc8= X-Received: by 2002:a17:902:654a:b0:1d5:693a:8904 with SMTP id d10-20020a170902654a00b001d5693a8904mr2296318pln.5.1705303401048; Sun, 14 Jan 2024 23:23:21 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:23:20 -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 2/4] perf util: Add helpers to parse task state string from libtraceevent Date: Mon, 15 Jan 2024 02:23:04 -0500 Message-ID: <20240115072306.303993-3-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: 1788140259973305996 X-GMAIL-MSGID: 1788140259973305996 Perf uses a hard coded string "RSDTtXZPI" to index the sched_switch prev_state field raw bitmask value. This works well except for when the kernel changes this string, in which case this will break again. Instead we add a new way to parse task state string from tracepoint print format already recorded by perf, which eliminates the further dependencies with this hardcode and unmaintainable macro, and this is exactly what libtraceevent[1] does for now. So we borrow the print flags parsing logic from libtraceevent[1]. And in get_states(), we walk the print arguments until the __print_flags() for the target state field is found, and use that to build the states string for future parsing. [1]: https://lore.kernel.org/linux-trace-devel/20231224140732.7d41698d@rorschach.local.home/ Cc: Steven Rostedt (Google) Signed-off-by: Steven Rostedt (Google) Signed-off-by: Ze Gao --- tools/perf/util/evsel.c | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 72a5dfc38d38..98edf42fcf80 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2818,6 +2818,118 @@ u64 evsel__intval_common(struct evsel *evsel, struct perf_sample *sample, const return field ? format_field__intval(field, sample, evsel->needs_swap) : 0; } +/* + * prev_state is of size long, which is 32 bits on 32 bit architectures. + * As it needs to have the same bits for both 32 bit and 64 bit architectures + * we can just assume that the flags we care about will all be within + * the 32 bits. + */ +#define MAX_STATE_BITS 32 + +static const char *convert_sym(struct tep_print_flag_sym *sym) +{ + static char save_states[MAX_STATE_BITS + 1]; + + memset(save_states, 0, sizeof(save_states)); + + /* This is the flags for the prev_state_field, now make them into a string */ + for (; sym; sym = sym->next) { + long bitmask = strtoul(sym->value, NULL, 0); + int i; + + for (i = 0; !(bitmask & 1); i++) + bitmask >>= 1; + + if (i >= MAX_STATE_BITS) + continue; + + save_states[i] = sym->str[0]; + } + + return save_states; +} + +static struct tep_print_arg_field * +find_arg_field(struct tep_format_field *prev_state_field, struct tep_print_arg *arg) +{ + struct tep_print_arg_field *field; + + if (!arg) + return NULL; + + if (arg->type == TEP_PRINT_FIELD) + return &arg->field; + + if (arg->type == TEP_PRINT_OP) { + field = find_arg_field(prev_state_field, arg->op.left); + if (field && field->field == prev_state_field) + return field; + field = find_arg_field(prev_state_field, arg->op.right); + if (field && field->field == prev_state_field) + return field; + } + return NULL; +} + +static struct tep_print_flag_sym * +test_flags(struct tep_format_field *prev_state_field, struct tep_print_arg *arg) +{ + struct tep_print_arg_field *field; + + field = find_arg_field(prev_state_field, arg->flags.field); + if (!field) + return NULL; + + return arg->flags.flags; +} + +static struct tep_print_flag_sym * +search_op(struct tep_format_field *prev_state_field, struct tep_print_arg *arg) +{ + struct tep_print_flag_sym *sym = NULL; + + if (!arg) + return NULL; + + if (arg->type == TEP_PRINT_OP) { + sym = search_op(prev_state_field, arg->op.left); + if (sym) + return sym; + + sym = search_op(prev_state_field, arg->op.right); + if (sym) + return sym; + } else if (arg->type == TEP_PRINT_FLAGS) { + sym = test_flags(prev_state_field, arg); + } + + return sym; +} + +static __maybe_unused const char *get_states(struct tep_format_field *prev_state_field) +{ + struct tep_print_flag_sym *sym; + struct tep_print_arg *arg; + struct tep_event *event; + + event = prev_state_field->event; + + /* + * Look at the event format fields, and search for where + * the prev_state is parsed via the format flags. + */ + for (arg = event->print_fmt.args; arg; arg = arg->next) { + /* + * Currently, the __print_flags() for the prev_state + * is embedded in operations, so they too must be + * searched. + */ + sym = search_op(prev_state_field, arg); + if (sym) + return convert_sym(sym); + } + return NULL; +} #endif bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize) 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) { From patchwork Mon Jan 15 07:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 188045 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1548134dyc; Sun, 14 Jan 2024 23:24:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjkg6kvmh7kuiXf4ZVf72pdOo0SdK0lSb/GE7k1XME7L1ZKyHAammidDmr/wzcaRDdT1cQ X-Received: by 2002:a05:6a20:6f90:b0:19b:1da3:b9bf with SMTP id gv16-20020a056a206f9000b0019b1da3b9bfmr5241pzb.57.1705303496157; Sun, 14 Jan 2024 23:24:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705303496; cv=none; d=google.com; s=arc-20160816; b=fTIWuPM8NR+SMw8zbAGKoUaXdy+405I9r2BMnZkbw/WR8qFufM5bjTF+E4Cs+STXqM bn2FWy9dWqgSQXmelmWdAQ2pk4MyMUGHvA5IFwtz86Fz4Ej4yvOXOfKZcclbjnHrbMug DOJkW33aZuQvZKz2RM2tfsQGyzRogSz+aJsw+JRfJzrxqbXJ1C+0goMP2BEDzt+UqeHs U0SOp+PU/wNSHi4Wk0y3se6OXSfH/nqyu4xbnvJ/lgrTlzF0jI3SX6b8w8k9XvpTFtfp R5R0U0TvgmMPpkYBc9HsUWGxXR6iUu5P+HQBaaxGcW4/VkcXYp8bJE8P+CHl7WS+XkTO kNgA== 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=kZ5LQrtGOef2RhCQexh0DzGghwnp1zT6hJb7zIaDJYU=; fh=BA7X0Fh+nH6aOBOR/HncHKQUGXeIUOSOgeWoVcIZnUI=; b=A4mEeVaz0j6H7CVK4T2D5ptJ8rF2d9l7TQc2+TuglP6s/SbFMCM2jCWUaJ6F2s6bx3 6xdWkmq3T3G4sVqJ7c50vOseEJOErXtZcKLfhm3dvkyWamyRXlbaiXIp5ykjev1BTa5W VKREBuFZb5Oh2eanTHVB/mmBD+svEhGF7Ufqv1VC7VJZGbLLU0sD0CW0gm6+C+ImOs6H ooJP+YnA7HVmCQjlUyzJl9S0utTNb37tmQzhltMsgRFzcEquGvHihDxx7Ufq1fU68k9t /Dbsok7AmefxI4MoAVlCgeVSugh+JKun/KAOMDyQ9htm39cNsUqOnv26mwulW4YMXOOS ijTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="a0Min/Bp"; spf=pass (google.com: domain of linux-kernel+bounces-25680-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25680-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u14-20020a17090a4bce00b002869d1b1921si8396028pjl.31.2024.01.14.23.24.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:24:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25680-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="a0Min/Bp"; spf=pass (google.com: domain of linux-kernel+bounces-25680-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25680-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1318BB20F5B for ; Mon, 15 Jan 2024 07:24:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0611B5C97; Mon, 15 Jan 2024 07:23:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a0Min/Bp" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 858C88814; Mon, 15 Jan 2024 07:23:28 +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-f173.google.com with SMTP id d9443c01a7336-1d51ba18e1bso71735725ad.0; Sun, 14 Jan 2024 23:23:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705303408; x=1705908208; 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=kZ5LQrtGOef2RhCQexh0DzGghwnp1zT6hJb7zIaDJYU=; b=a0Min/BpgERqnBz4GkjZawDm1Tmtq7QwVUZqZp9TbVGFiLQ46BxC5h6oqGn4HxfC+x Pqz1yhNI6uptsKTplg10oBlA1rJPMnJpf9Y6eGThSxgdoADrC4v0JDgMmCDiHAatzpZI iIfo+wm0vSfR9J+Jx4G465RiVx4ToJ7OF1zyaJ3AWc+R282Oh8orfRBbXWddF/3tncJK e84eZfw4dttpMMbCQ72YB6SS85wipxc37dABfuEJ7EAIuFtLR/oi+cVdi/2YLw3h8eqQ A720EKQT7jfOPSIles8MBeYQpts+o/9Suq0GYBjTALuTbr8B65mPIa4bkav43ifVwFzK dIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705303408; x=1705908208; 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=kZ5LQrtGOef2RhCQexh0DzGghwnp1zT6hJb7zIaDJYU=; b=lMb9/GC/tp8/xMvYLlBBGaQkc1w1RSa5mfmP72oVESn7g+LmqiuJWRH+mBeiclZB4g zreJvnu0z2I5VGPxBX1mHFLFOn+4iajAsff9ePOtZhoZDa7uiV1TPDAgZrRDdAYcN6+9 Mg6xgY8LNOlIJxqRWfh2zIEkJelNN5yi4hy/g/HsJxcCR45kRAKeRUjad1b33lRmjUv2 PuF5RoXm8J0RE4ba56KEAOk3evO6ZQ+h+UmMi+zsGgEW1cW3//fvXlPUeHfnq1RLVVRO o2qcsWysKEQutGYeh5IyiTkxOqg+IOrBbDVfgcEUhOX5tEcLnKBK+B/c9inhsFenPpuJ PdPg== X-Gm-Message-State: AOJu0YzOcqDClTzG9m8+aCuCMw6y0q0g9KUIgMrUQIe/nOgSMzYX88Or 82HxkSYCtliB8ptqVnzkdFY= X-Received: by 2002:a17:902:e78a:b0:1d3:ee1f:ce54 with SMTP id cp10-20020a170902e78a00b001d3ee1fce54mr6201200plb.89.1705303407872; Sun, 14 Jan 2024 23:23:27 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 23:23:27 -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 4/4] perf sched: Commit to evsel__taskstate() to parse task state info Date: Mon, 15 Jan 2024 02:23:06 -0500 Message-ID: <20240115072306.303993-5-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: 1788140318308266065 X-GMAIL-MSGID: 1788140318308266065 Now that we have evsel__taskstate() which no longer relies on the hardcoded task state string and has good backward compatibility, we have a good reason to use it. Note TASK_STATE_TO_CHAR_STR and task bitmasks are useless now so we remove them for good. And now we pass the state info back and forth in a symbolic char which explains itself well instead. Signed-off-by: Ze Gao --- tools/perf/builtin-sched.c | 46 +++++++++----------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index ced6fffe8110..f1d62f6b6cab 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -92,13 +92,6 @@ struct sched_atom { struct task_desc *wakee; }; -#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 +248,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 +418,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, const char task_state __maybe_unused) { struct sched_atom *event = get_new_event(task, timestamp); @@ -849,7 +842,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 = evsel__taskstate(evsel, sample, "prev_state"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1039,13 +1032,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, char run_state, @@ -1121,7 +1107,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 = evsel__taskstate(evsel, sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1157,7 +1143,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 +2008,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, const char state) { struct thread_runtime *tr = thread__priv(thread); const char *next_comm = evsel__strval(evsel, sample, "next_comm"); @@ -2080,7 +2054,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 +2126,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 +2553,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 = evsel__taskstate(evsel, sample, "prev_state"); addr_location__init(&al); if (machine__resolve(machine, &al, sample) < 0) {