Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4354757rwo; Tue, 25 Jul 2023 05:04:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlFuRud9PqrZyb9psQ4iXDVwqXdwIzm+tIjpSnEFG3CiUsWSXoQIPx4sLNu1TwvMeSbAB+Dx X-Received: by 2002:a17:902:d512:b0:1bb:9675:8c06 with SMTP id b18-20020a170902d51200b001bb96758c06mr6463509plg.35.1690286651493; Tue, 25 Jul 2023 05:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690286651; cv=none; d=google.com; s=arc-20160816; b=0wEaxBfMB/uOw/Zx6GbJ/4szFiGpmFGQYFflAa5vB6/NMKM80PhnSCHIeFI4wbZifU woNLKAwS4BytlG8Elu+S9bbRp9NLiKelViSS9UkjANExRCpEAmh8W1NtY9wbqNHNC8Jk yTfhwPF+TFL3v7ME7Jrbsv9Hd/ziQjn5VnX8tSjKhSfZItSOsnDP7Wgm1XmgovDSHnVa ZuLaCzoejRmz5ijd0KiVVwIBTHefUOJbiqRxp874GsPZgvI00u5vxas+x5tZigHWUJiK DJ30Q4rbLmZUvFOe1/TlRtr4HqiUXsazsZcpjqiYgrCKN3L0KqhhzR3+AXVCTVmoKcHf 94fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dwGjez98+Z7DYerWtpEnUz/QCZ+ae99CXaeubhq+lCo=; fh=sE9IZF3CAzobV6XMBWHzGWrSVmADumexpJV3iYzs+pc=; b=G/vW2Nq3NcsWeZ16Yh2Lo2aKH/g3FMeO+pyZHi+JzKF5vqEJA+58xVpwOe0ylA38z3 ngVJOemeh8Ixyw5vUOlgLKcHpL3XIZJ74PCE815N7DLdxlVaNXyxGwL35cV50Y/83yuC ifQwZ+ic67dPWelMOPOxESJkOuTzMOiwQWrxp52/iN9Et7vT58QYhvw55l6sQOAkpeMU qbPZGouOubuREVGYpqPYK7iIlmfIV9mLh/MtaaAmFBgcka9a9mUnicw6Di27hkw7OiYA O9akNx2CCZ8ue/TClatXQYJ9i1Lin1T2/BopZ9rC8bNviphZCpZVytKcv5vBkc08l86c opWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mlSsZSHs; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a170902d2c200b001b8ae69289dsi12287654plc.539.2023.07.25.05.03.51; Tue, 25 Jul 2023 05:04:11 -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=mlSsZSHs; 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 S232072AbjGYKzx (ORCPT + 99 others); Tue, 25 Jul 2023 06:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231605AbjGYKzc (ORCPT ); Tue, 25 Jul 2023 06:55:32 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01FF12689; Tue, 25 Jul 2023 03:53:26 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-5222bc916acso2738213a12.3; Tue, 25 Jul 2023 03:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690282399; x=1690887199; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dwGjez98+Z7DYerWtpEnUz/QCZ+ae99CXaeubhq+lCo=; b=mlSsZSHswqcByPTwbuUwAjc/BiDmV8alwigpLyjDiXkr2naBn6+a1HZzUbRU4uTF/t wqHWi/o3OBlSLBO3sduuT8vGsvn3O5kv8/1ZOuf/ofWgdsa4j5HewPQqgX5BI1s/FswI //QmEsDN+IYCxbkPSe+UHTesOimIDGDxQzoWU2tyDXEnup3ogcWyNtnAPPuvaGUhz8jX +CstZmpDAhBHorkYtLEAIfmq8mm9QloyePHrg7B0hVfk2ccwWi0b1RRlBzFg1x3hWxy4 CsNB5AEAqhdTyxwe805gHiCPJIM6b9YbHbw9FGa0SRBl7KAMA5DhIOCJyqVnDo0HfDoy JmiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690282399; x=1690887199; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dwGjez98+Z7DYerWtpEnUz/QCZ+ae99CXaeubhq+lCo=; b=LvDhHikfj/y1VAY9rSP7glrHFKYc3W8DafFAfhqK6HZ49GwrFd/QiEFBP8IcZeJgWd +h5QNP5F3HeWW6dfcRVnnJgzYTOFTAzupkLWadBtqijQB/q5r4sxdRUxI55pHqMk9Ckv Z9GL3Hqx9Ojq9Nt5k4qdVGLqLDZtwWYJS/kpsT/GUIIAgN+67078zhn5TJ5MAfiWpfMB 69RzsCqyS9hPicB+x2QKkWuVsa1fEH/eIDf7il+5vrg2XgiViljhPxBhT5cizZ+NLoyK T2DiBqHog0spiH5fB5tNakW0Gm7BBXyN+vvm6hB1ur+Ht3XNA0U/qkI65v2C9e7IX4AH haHw== X-Gm-Message-State: ABy/qLamytpqv+UrgOSxNHz10kWKQRg2ErUFb2kHIRS5I0Ibvt6PKUIt rtUhp2OxLYMZdLkct+wepx9aAF3MUscZFqw7DjA= X-Received: by 2002:a05:6402:1295:b0:51e:4e77:3347 with SMTP id w21-20020a056402129500b0051e4e773347mr8959757edv.41.1690282398609; Tue, 25 Jul 2023 03:53:18 -0700 (PDT) MIME-Version: 1.0 References: <20230725072254.32045-1-zegao@tencent.com> <20230725072254.32045-2-zegao@tencent.com> <20230725083357.GA3765278@hirez.programming.kicks-ass.net> In-Reply-To: <20230725083357.GA3765278@hirez.programming.kicks-ass.net> From: Ze Gao Date: Tue, 25 Jul 2023 18:53:07 +0800 Message-ID: Subject: Re: [RFC PATCH 1/3] sched, tracing: report task state in symbolic chars instead To: Peter Zijlstra Cc: Ingo Molnar , Steven Rostedt , Namhyung Kim , Ian Rogers , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Adrian Hunter , Alexander Shishkin , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Tue, Jul 25, 2023 at 4:34=E2=80=AFPM Peter Zijlstra wrote: > > On Tue, Jul 25, 2023 at 03:22:52PM +0800, Ze Gao wrote: > > > @@ -197,13 +198,6 @@ static inline long __trace_sched_switch_state(bool= preempt, > > BUG_ON(p !=3D current); > > #endif /* CONFIG_SCHED_DEBUG */ > > > > - /* > > - * Preemption ignores task state, therefore preempted tasks are a= lways > > - * RUNNING (we will not have dequeued if state !=3D RUNNING). > > - */ > > - if (preempt) > > - return TASK_REPORT_MAX; > > - > > /* > > * task_state_index() uses fls() and returns a value from 0-8 ran= ge. > > * Decrement it by 1 (except TASK_RUNNING state i.e 0) before usi= ng > > @@ -212,7 +206,16 @@ static inline long __trace_sched_switch_state(bool= preempt, > > */ > > state =3D __task_state_index(prev_state, p->exit_state); > > > > - return state ? (1 << (state - 1)) : state; > > + /* > > + * Preemption ignores task state, therefore preempted tasks are a= lways > > + * RUNNING (we will not have dequeued if state !=3D RUNNING). > > + * Here, we use 'p' to denote this case and only for this case. > > + */ > > + if (preempt) > > + return 'p'; > > + > > I don't get this move, why compute state before this return? Oops, I was going to ignore the PREEMP_ACTIVE in the first attempt and changed it to 'state =3D 0' which I decided to introduce 'p' to denote this after second thoughts. Will fix it and revert this move. > > + > > + 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 ) > > This is a format change and will likely break a ton of programs :/ Yeah, I admit that. And I believe this kind of break happens each time the internal task state constant mapping is rearranged, it's of no big difference here, since the most renowned perf itself is still broken at this time after. And IMHO it's time to fix this and do things correctly. That is why I propose this and mark it as RF= C. BTW, could you help to point to any possible tools/programs that would break other than perf/libtraceevent, because these two are the only users I run into so far. Regards, Ze