From patchwork Tue Jul 25 07:22:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 125440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2341881vqg; Tue, 25 Jul 2023 02:20:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGxxVwId2wcke8zisiBM564q+4AyuHE3IGoY00/4NikimT1OwZahWo7TIXqHfh21Ol6lFjI X-Received: by 2002:a17:907:272a:b0:993:6382:6e34 with SMTP id d10-20020a170907272a00b0099363826e34mr11186218ejl.72.1690276847583; Tue, 25 Jul 2023 02:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690276847; cv=none; d=google.com; s=arc-20160816; b=JVQKKQ3kDuNuBQ3ZDUXO+TUsufpRFUkmym/awqUXcAjuNTk7y8NeykMwEw5ACau7Pl pWEO18IfTmLgR+8r3p+ExIiGc4NrzllhvAYrP/BIYGeztAaY+lId3BGxJh+299rFkYh3 F88/DNRoXzGdxtJFnIECV5d6i1gNrcS+PqpgEUDMfyTR2zDKeHgfbfvU98vLHvlcXdyv POjbFhjwDpTOvlz/ffZFIdNqwMgMrB1TT1BI9am9wq5ZBlwqW/h+dZMYHR0VZSevrejk EmqbggL71C4UQc/4xrIqVjMLit6MuG8scaD/N75zaetE1CLUNHq4Ke1k/ViP/yaICThM M+Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8jOqL9nsN3X2QdJmIGhs0fEScdnThT1mzgrts+M8u0c=; fh=A8InIXaUJCDiCU1PTNfzcNZ+u4dmNDGcONSlyuU68T4=; b=qlCFKSDJ6o5NiFiBs7Hrq9RXxj7Rldq8tFfNhSTveHw0PUeH0LIvnXAhRrmjpU56ct /tRiHoluyNHIarTRRejwAJfO2u4yNBEa5GQv8GhX0DMD6TkRTqPXUtqthQ9llAQ+pcd2 seKnRrFsR1AYCOHilX5FfWmfGxToGWl26Kd80LRlr+6NEkIDep+u2IDv1midI4f9UjZi 9Qbui9eoSkxcPQF6lUZjI9Uj63XjVBuCj3RM9RTO/V6WevYMO8LptV1BZJSoQ44xe0s0 sg6qp2Xj2Ftqh7QlJuUT3AdEaAdMTFavcOsXnuYHZSFtHGq5Hu81/g6rh6Nl6m2GhZ60 sL4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=P3uSFiU1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a3-20020a170906368300b00978779cfc97si8311206ejc.795.2023.07.25.02.20.23; Tue, 25 Jul 2023 02:20:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=P3uSFiU1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232611AbjGYH1C (ORCPT + 99 others); Tue, 25 Jul 2023 03:27:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232507AbjGYH00 (ORCPT ); Tue, 25 Jul 2023 03:26:26 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE78810F8; Tue, 25 Jul 2023 00:23:09 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-66767d628e2so2945005b3a.2; Tue, 25 Jul 2023 00:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690269789; x=1690874589; 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=8jOqL9nsN3X2QdJmIGhs0fEScdnThT1mzgrts+M8u0c=; b=P3uSFiU1A85ZSJW+KDb9oGfLXAkcmTl8KJIjIHI34hO7DMh5CQ8xjVOvFCjugBnao5 YoeoJgqCFcrBpF4FPxEi9hY5p9j/Ih56nHnaMAYwHzFYN/UCT9PC/DPY2D2jFYembcJh Xl0AyJgZa/ji6U2z/EpGxkZ3iOMTsH2YsGVfd/DKUlE1G0DLQJ2B1rsMvHZi2gW7ZmIY UfLBfyTZF7h6Md2IZcbw3hu95oeKNqp/9OOVqqEOt2e7urSSFg0wHqzmskEgijgSgTPh +0dH0y109s6pCjy0eJcNgBb7u1kxRi2TU05xSiVMn/sqDvIQBMiwdjlMp/3OKqI2v98d jMFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690269789; x=1690874589; 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=8jOqL9nsN3X2QdJmIGhs0fEScdnThT1mzgrts+M8u0c=; b=ER6JJHr1sed9NOcDtF4zuZ20RzLmiO8HeEEnF3SDXEQVnbbDg7CV4ctbWBj69m2f3i lvE6Ne9kmFgmpgiMsyPAaqdLcmXGRkIP+r7rPVvKfjgvb5IrCVHNDjaDuQsx/f7kpoB2 5VTY4twQh1ccpS3bFQ02vdfgg8IkvHAetbHjneR3mbdFUMAwhpuOcRO13uiHi0OQykPw O1ljzWGDpx7lpxeiEYZKlhEXoXiEAT/dMApaafws4FB6tLWO/SqVQ9CxjlHs9/OXTbD7 R9F0B4c9YJ5TvYwZYGheq9H+xAk1LQquxUz79Ast0n8j8RamIscQL13WnTPrTmrDMZky 6kig== X-Gm-Message-State: ABy/qLacNpjrY4myBTnVgDuahanKkPcWpmUNDZtHaZfD/kgpQKz+h19s NhP3nsLuNjSEhenjrNbhkzM= X-Received: by 2002:a05:6a00:194c:b0:668:711a:7d93 with SMTP id s12-20020a056a00194c00b00668711a7d93mr7317580pfk.19.1690269789133; Tue, 25 Jul 2023 00:23:09 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.82]) by smtp.googlemail.com with ESMTPSA id d12-20020a63734c000000b0055acfd94c20sm9863908pgn.35.2023.07.25.00.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 00:23:08 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Ingo Molnar , Peter Zijlstra , Steven Rostedt , Namhyung Kim , Ian Rogers , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Adrian Hunter , Alexander Shishkin Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Subject: [RFC PATCH 1/3] sched, tracing: report task state in symbolic chars instead Date: Tue, 25 Jul 2023 15:22:52 +0800 Message-Id: <20230725072254.32045-2-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725072254.32045-1-zegao@tencent.com> References: <20230725072254.32045-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772383735681701554 X-GMAIL-MSGID: 1772383735681701554 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 not a good choice, which can easily break a userspace observability tool as kernel evolves. For example, perf suffers from this and still reports wrong states by this patch. OTOH, some masqueraded state like TASK_REPORT_IDLE and TASK_REPORT_MAX are also reported inadvertently, which confuses things even more. So report task state in symbolic char instead, which is self-explaining and no further translation is needed. Note for PREEMPT_ACTIVE, we introduce 'p' to report it and use the old conventions for the rest. Signed-off-by: Ze Gao --- include/trace/events/sched.h | 41 +++++++++++++----------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index fbb99a61f714..51102a7c0c2d 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 @@ -187,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 const char __trace_sched_switch_state(bool preempt, unsigned int prev_state, struct task_struct *p) { @@ -197,13 +198,6 @@ static inline long __trace_sched_switch_state(bool preempt, BUG_ON(p != current); #endif /* CONFIG_SCHED_DEBUG */ - /* - * Preemption ignores task state, therefore preempted tasks are always - * RUNNING (we will not have dequeued if state != RUNNING). - */ - if (preempt) - return TASK_REPORT_MAX; - /* * task_state_index() uses fls() and returns a value from 0-8 range. * Decrement it by 1 (except TASK_RUNNING state i.e 0) before using @@ -212,7 +206,16 @@ static inline long __trace_sched_switch_state(bool preempt, */ state = __task_state_index(prev_state, p->exit_state); - return state ? (1 << (state - 1)) : state; + /* + * Preemption ignores task state, therefore preempted tasks are always + * RUNNING (we will not have dequeued if state != RUNNING). + * Here, we use 'p' to denote this case and only for this case. + */ + if (preempt) + return 'p'; + + + return task_index_to_char(state); } #endif /* CREATE_TRACE_POINTS */ @@ -232,7 +235,7 @@ TRACE_EVENT(sched_switch, __array( char, prev_comm, TASK_COMM_LEN ) __field( pid_t, prev_pid ) __field( int, prev_prio ) - __field( long, prev_state ) + __field( char, prev_state ) __array( char, next_comm, TASK_COMM_LEN ) __field( pid_t, next_pid ) __field( int, next_prio ) @@ -249,22 +252,8 @@ TRACE_EVENT(sched_switch, /* 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 ? "+" : "", + 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, __entry->next_comm, __entry->next_pid, __entry->next_prio) ); From patchwork Tue Jul 25 07:22:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 125396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2310047vqg; Tue, 25 Jul 2023 01:02:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlETjagMHpdimPY6Tlx7InGY4O6jQBazcF5oTqIJ/oyABCDZ3uJu8fNDxSV5dctwld/G1ZvU X-Received: by 2002:a17:906:217:b0:992:7594:e6b2 with SMTP id 23-20020a170906021700b009927594e6b2mr10595978ejd.77.1690272176605; Tue, 25 Jul 2023 01:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690272176; cv=none; d=google.com; s=arc-20160816; b=UEaYnvZhw0Rt42hu4slrOJ2Wm6i6qC9q4TEV3pzk3ngvjjfM02V0mN3u5n/R85hGep LxAFayEmGeixrIqvOuZD2vcWaHFe+QnroEMIrr9We5CPNZEe+GN2P2lF8jtVbSmdD9Ko LfPKgbFIYLqj4sjHJUrzClr9aGDe8yDmgOSK8xLyfaRNIfS1w5iQlEPipIIBniKktZLF 1/M2Uv+HVPtXmaaSYL4iTH2hC1lvVVLS5a3TXDry9ZeLfY1anm/tH2M1flOmIrAovoxU LEQu8lbfzdfrCwzbBI3+QwaI+M9VR7HqhKMIDj4qgefj2EcwBDPQ2AynbieKerNduFcY km/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FmUBsd+tZoS42f/xnaNOMHrSi2QJyg5RglNDqx3WC8U=; fh=A8InIXaUJCDiCU1PTNfzcNZ+u4dmNDGcONSlyuU68T4=; b=GK/7mW0ijXhwijIXzemiTc8zq/8HkkNLHkn4F1M3UrFp/HWHbM3jaXJlZx1MKPQYMN S+LjaqZ6OrNnT+Xv1u6d446MkfZUNlYSBN77fa37/ZjsCnGZwMEFQJxcJR+M4c4apYwD H/FkKtbZXOrh20tEKPyBbJeE0IuiCkLZUkjqpEw3OQAazhY0nddQDnSrPYTWkAvfomTy SJPar/gClqrZ8Az0Rtd0awU9r86QNg9zUdEQA9lP1pxMPf+rs7/udHxxOtrR5Ng3ohHa E8N0MS2El1gjdXwlErDiq+Zhn7mALVOj59cGWjn1Edrvu2NjR4CobI8yFKXPQO4XolAR KR2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=b+FqgXu3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a170906828600b00988c64dd7acsi7212503ejx.620.2023.07.25.01.02.32; Tue, 25 Jul 2023 01:02:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=b+FqgXu3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232627AbjGYH1N (ORCPT + 99 others); Tue, 25 Jul 2023 03:27:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbjGYH02 (ORCPT ); Tue, 25 Jul 2023 03:26:28 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE3AC1BCD; Tue, 25 Jul 2023 00:23:13 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-345d3c10bdfso20959025ab.2; Tue, 25 Jul 2023 00:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690269793; x=1690874593; 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=FmUBsd+tZoS42f/xnaNOMHrSi2QJyg5RglNDqx3WC8U=; b=b+FqgXu3l472HbqYYF78SuQCousvxZV9bEimo83Y49v2vCNc6f77H0cbp6sp01GFSj FNUL/KAHGErJyWk0tJFIZXGsPJ4v4Wj4Yr/rpeygp3Igsq+vCEvVvQ22usgVLm6GGW7S vU0rgPdrPJHbxBn+RLmT/kPIHC/YcfLan681ZovoTyYTwefSQVIQySOVQT5Wc70wIdGM Rhj0H5HU4JARsulx9/QQFrwfOwfUxDzwB4Ay3yg9K7I5FELdilsKkdvvPt1FIaMDJNh6 0SVnru76z8/pyUFUQunET5WbloIDngd5Qy4d5GerjgTzs7AYvCA0XIrf7U6rc8d8Op/Z VXrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690269793; x=1690874593; 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=FmUBsd+tZoS42f/xnaNOMHrSi2QJyg5RglNDqx3WC8U=; b=Vuwipw2NxKSqd/MIKmXmOS+ZpIHwis6Kxy6BJ69TdCegZyP121lBtZPj/OBkJqry3V dF0xJUaPZEudfVF6Y9zACJ55lUhvZ27jM6Rl90eOHUN3deFGz0QGcp/+/BUKlCu8DJjl 34zpsm8GZSBl7MmTMM62ims80M1F+iA5OzrG5q/1lHaVcQMh1oaM3IxT3536ZDi8x8vJ 461gkeMme9BLDhC8dQu0fPAJKvbiPl0I8tJv5bTUXytnIyrMNEZPbxUWhYzYBxntrtW8 3r/LUcqkcUts02xgWI+dYMYoARg8cgqgqqiZkGe/2fPH2bBLL7WroeuXozWmOqU13R6c 4seQ== X-Gm-Message-State: ABy/qLYZXnsDTxFJbXC/5A0DDw7kr6bIdb7bmTvGlU8haoBmd/Tjvanm GEeJKZP43qLeCUUSnZ9HS4A= X-Received: by 2002:a05:6e02:12cf:b0:345:d58d:9ade with SMTP id i15-20020a056e0212cf00b00345d58d9ademr2766206ilm.3.1690269793087; Tue, 25 Jul 2023 00:23:13 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.82]) by smtp.googlemail.com with ESMTPSA id d12-20020a63734c000000b0055acfd94c20sm9863908pgn.35.2023.07.25.00.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 00:23:12 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Ingo Molnar , Peter Zijlstra , Steven Rostedt , Namhyung Kim , Ian Rogers , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Adrian Hunter , Alexander Shishkin Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Subject: [RFC PATCH 2/3] perf sched: sync with latest sched_switch tracepoint definition Date: Tue, 25 Jul 2023 15:22:53 +0800 Message-Id: <20230725072254.32045-3-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725072254.32045-1-zegao@tencent.com> References: <20230725072254.32045-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772378837792376776 X-GMAIL-MSGID: 1772378837792376776 Since tracepoint sched_switch changes its reported task state type, update the parsing logic accordingly. Signed-off-by: Ze Gao --- tools/perf/builtin-sched.c | 55 +++++++------------------------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index cc4ba506e119..b92f376fdd9a 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -92,24 +92,6 @@ struct sched_atom { struct task_desc *wakee; }; -#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP" - -/* 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, THREAD_WAIT_CPU, @@ -266,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; @@ -860,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__intval(evsel, sample, "prev_state"); struct task_desc *prev, __maybe_unused *next; u64 timestamp0, timestamp = sample->time; int cpu = sample->cpu; @@ -1050,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, @@ -1132,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__intval(evsel, sample, "prev_state"); struct work_atoms *out_events, *in_events; struct thread *sched_out, *sched_in; u64 timestamp0, timestamp = sample->time; @@ -1168,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); @@ -2026,24 +2001,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"); @@ -2084,7 +2047,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); @@ -2156,9 +2119,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; @@ -2575,7 +2538,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 = evsel__intval(evsel, sample, "prev_state"); if (machine__resolve(machine, &al, sample) < 0) { pr_err("problem processing %d event. skipping it\n", From patchwork Tue Jul 25 07:22:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 125393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2305387vqg; Tue, 25 Jul 2023 00:52:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlEWtQtci464G/2onPZrH7tbMzBQgcbXQLvVnF3Zf7lFkVde3zkguMK8r5C1nIVepVT6lwP/ X-Received: by 2002:a17:906:9bf6:b0:993:ec93:a5ef with SMTP id de54-20020a1709069bf600b00993ec93a5efmr11287841ejc.47.1690271568812; Tue, 25 Jul 2023 00:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690271568; cv=none; d=google.com; s=arc-20160816; b=KZ76lRWwSG3HygDQYHFPbBYdaQu6XrEF/TQCpZ79SuELmJsJrYgjZYkRaOwLMl4e3E rX2EnB/67GYICzZP+vGFu3dk7qammNNF898DB79+RaXFRlRP9wx6eJNl7op0dMajnhtX pWIk9jWbN4KZ32Acj5ABjuxxRe54fmj5oXopPfBj6aKvDJ74D5iRmpEWaNPuEw+vGB7j gSuxI7lAlSdLIDeluQdkpB6auWayygtBm5cRDFbNXhTQf/yHmtfJK1WCLJixMH/Ppqla lMUjhuxjtCvxw2+0L2eVhu/RnPZKLngMHvDYDuchkq5GEo8NlSNh0zJpFCVUksWcpYSi kv5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MBwG97iRZO4tN6Fiy1txLbQFfSCq1pL4Ni9ia1DF4dY=; fh=A8InIXaUJCDiCU1PTNfzcNZ+u4dmNDGcONSlyuU68T4=; b=KoXuCoh+NB+1jzrEs9SO7pgY7WbvCvN+7MGEBLw0xiBAblXzZPBRSGAXBIhP8BN/LE IK6JDj/San/9RGfwWq2J9VqCphog4WVvPzLkudzz6IGqGLHqC3lBPMZQz9W3O0P3KUKn CNnb3jATQjDzzYMfO2Re9LjBTJocq+UW/wimplNkUxeAmwawxjvFUR04q/2Lf/kIdM// xLOl5ka3wQ2JepOw7W62JYiVgp9I/L5z5RiSxCaJQCcVxm+wAbfaL7EpTXDY5AgZQ1ja 0pItnJplNYbif6yAo0W7zGpqLA8+dhu/0HjYn3oCN4gRzohtmEC0gbAWFpgivVZlJoLv A95A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fDWP8pJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a170906374400b00992bf8cc68csi7933923ejc.973.2023.07.25.00.52.24; Tue, 25 Jul 2023 00:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fDWP8pJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbjGYH1Y (ORCPT + 99 others); Tue, 25 Jul 2023 03:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232528AbjGYH03 (ORCPT ); Tue, 25 Jul 2023 03:26:29 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A0519A2; Tue, 25 Jul 2023 00:23:17 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3a04e5baffcso3613766b6e.3; Tue, 25 Jul 2023 00:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690269797; x=1690874597; 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=MBwG97iRZO4tN6Fiy1txLbQFfSCq1pL4Ni9ia1DF4dY=; b=fDWP8pJgo8CFkH9+IiKqXOh4RtqqEqQ/6GGY3V8azRSvvGfKhpE6KDe1fbUdl7Zpy9 dBPsirxsiAz3pCvshqbdZtlUoRX8zx94wFRpw/Rdz6WXWg55bEmRlH1nzm5WhMFxW3yK +Ke1E46i/28HQOvfoSUM9Px7LQmVoho9ggOfEY9VRGW4uJtXYJ/Y6kSPVcjhprdkyzRt npvN/d2+2vqMXt8ZrsBjvErj8cwmHSdq7trsZcyu3egVacU7Iapvo7nlSx2ktw5EK53N r3uUvOnVlQ4Cgqf663FAU4bcLckT8RLyDkN48g/uoNFZqfoL31bgX7TbV9sgpVfJkzEO 32uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690269797; x=1690874597; 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=MBwG97iRZO4tN6Fiy1txLbQFfSCq1pL4Ni9ia1DF4dY=; b=FyHoHqt1sDm4gQk8u9Q+OaYQrMurSMuPKKp+1SE2uKH7q5+xG912NU/j/W5mach9wt PedHAP1US8h4P30JvCGwG0TM3sjnOomw7jilozumbLeBbhUYbqkxIOzmtZq19ZU3gcCR KyHONoMWXqS3GB9ZfEW6aqD6Czy2APn01KJrOn6duCV+KgqTTXdlMAMUDJ6rONsWTMY0 LIOBRspRYmH0N7t9VMqxNmxR40EBvRKtPi0vz9vVH0a9ETjXCRW28NwVMIpm8YxxEeCd kMlvPZiKn/5ogoaQsJ/0Jcec/CxqAiiZ3iPBGlwcm8uXcuiIWxrf/4891lNrlE4IKr6j 9yTg== X-Gm-Message-State: ABy/qLYrTNZ6eKfSGTmg+Pqgop9gcWhuGOEeKIHyeLSuSBkGGKYQWFuP ZWCJ6w3YRdzoDCLrQijK/LMU7HtEO4zDww== X-Received: by 2002:a54:4703:0:b0:3a1:eb15:5ec4 with SMTP id k3-20020a544703000000b003a1eb155ec4mr9832357oik.42.1690269796838; Tue, 25 Jul 2023 00:23:16 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.82]) by smtp.googlemail.com with ESMTPSA id d12-20020a63734c000000b0055acfd94c20sm9863908pgn.35.2023.07.25.00.23.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 00:23:16 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Ingo Molnar , Peter Zijlstra , Steven Rostedt , Namhyung Kim , Ian Rogers , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Adrian Hunter , Alexander Shishkin Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Subject: [RFC PATCH 3/3] libtraceevent: sync with latest sched_switch tracepoint definition Date: Tue, 25 Jul 2023 15:22:54 +0800 Message-Id: <20230725072254.32045-4-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725072254.32045-1-zegao@tencent.com> References: <20230725072254.32045-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772378200487722943 X-GMAIL-MSGID: 1772378200487722943 Since tracepoint sched_switch changes its reported task state type, update the parsing logic accordingly. Signed-off-by: Ze Gao --- plugins/plugin_sched_switch.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/plugins/plugin_sched_switch.c b/plugins/plugin_sched_switch.c index 8752cae..37c1be2 100644 --- a/plugins/plugin_sched_switch.c +++ b/plugins/plugin_sched_switch.c @@ -9,27 +9,6 @@ #include "event-parse.h" #include "trace-seq.h" -static void write_state(struct trace_seq *s, int val) -{ - const char states[] = "SDTtZXxW"; - int found = 0; - int i; - - for (i = 0; i < (sizeof(states) - 1); i++) { - if (!(val & (1 << i))) - continue; - - if (found) - trace_seq_putc(s, '|'); - - found = 1; - trace_seq_putc(s, states[i]); - } - - if (!found) - trace_seq_putc(s, 'R'); -} - static void write_and_save_comm(struct tep_format_field *field, struct tep_record *record, struct trace_seq *s, int pid) @@ -100,7 +79,7 @@ static int sched_switch_handler(struct trace_seq *s, trace_seq_printf(s, "[%d] ", (int) val); if (tep_get_field_val(s, event, "prev_state", record, &val, 1) == 0) - write_state(s, val); + trace_seq_putc(s, (char) val); trace_seq_puts(s, " ==> ");