Received: by 2002:ac8:4602:0:b0:405:464a:c27a with SMTP id p2csp2529196qtn; Tue, 25 Jul 2023 11:20:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYZVHF20vYWDRW1IKqil4yGe6+LtnvQykNDJVU7kCoch9T2yF6YdiYQrvve+WjvuQMzk7M X-Received: by 2002:a17:90a:dc13:b0:268:4485:c868 with SMTP id i19-20020a17090adc1300b002684485c868mr19181pjv.49.1690309199673; Tue, 25 Jul 2023 11:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690309199; cv=none; d=google.com; s=arc-20160816; b=TKwG6EUDquGekkbRb9xhXAmeDTUsQtiYQ+tDjLj/c0p4mS24jOCmpPctdCUK7V8Ea0 VhakCocqsNPNQFYqfEQ6nfXvLFaV2hx1+VlQo3S8NUytuuVPLnuU3Hwvaz7E6lyojhtl el/yvbRWy6UC8v4LxcNS/mDGgSKM7o6b1tQWXskfovS5kFRXQbUkWH47ZIqYkcEVaocj RitnHEE087NlSLGMoe+GW9FbSe1gc/envV0hfldZnU6AaFSzyr80sEFQXPwfPnlSxmd5 xgKEUic9H/gJL9dwL5IhV66iwOQJOnZBMelbzc1kmiY9aTReo8TJyuSDhvhM9zsEguEg UOWQ== 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:subject:cc:to:from:date; bh=n/Fbc3w1kI8s5twptc+xjKcC7BSwChEa6nH3kdannb8=; fh=ZGUgm1KrMRMUJ3+xl66VkzRCSX6smRT1X5pmJKTnT/g=; b=SRbtE3Y8ZnFOO3vkJILPjZoV82t3o0j9+FJ23UNR91y02RDsvbuiZWv3t7vQ23/ql9 koI/GhixjuZc+E0uXo7VUc7Ow2B37K4eMGB8OMFIgJ67RKOFyV6quz7sgd6/uwa0s2id 5r7ZmrbPK7+JL+mILMoxE8qsHliYYZ6y2M9a9LRouIYlPHFwTRg75wTjeZITqHoqj+nx WPBgKrDl08lKXnVcTqKhfaatJljkOFGl9JPmABS1TDf6rvhEcGvpreA4Ta/85cQsi3rH B9x7+cMWDz7etwPjMh7/lgXZVCzEtYi8xo0HcZdeV9SokWlxNPrqGbFfIM6jQNN5S8OY uw/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y24-20020a17090aa41800b0026838c7367esi1885598pjp.56.2023.07.25.11.19.46; Tue, 25 Jul 2023 11:19:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232128AbjGYR7p (ORCPT + 99 others); Tue, 25 Jul 2023 13:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231953AbjGYR7n (ORCPT ); Tue, 25 Jul 2023 13:59:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C44A9BB; Tue, 25 Jul 2023 10:59:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5976661851; Tue, 25 Jul 2023 17:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B66C2C433C7; Tue, 25 Jul 2023 17:59:40 +0000 (UTC) Date: Tue, 25 Jul 2023 13:59:38 -0400 From: Steven Rostedt To: Ze Gao Cc: Ingo Molnar , Peter Zijlstra , 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 Subject: Re: [RFC PATCH 1/3] sched, tracing: report task state in symbolic chars instead Message-ID: <20230725135938.1e056a02@rorschach.local.home> In-Reply-To: <20230725072254.32045-2-zegao@tencent.com> References: <20230725072254.32045-1-zegao@tencent.com> <20230725072254.32045-2-zegao@tencent.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,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, 25 Jul 2023 15:22:52 +0800 Ze Gao wrote: > #ifdef CREATE_TRACE_POINTS > -static inline long __trace_sched_switch_state(bool preempt, > +static inline const char __trace_sched_switch_state(bool preempt, Does it really need to be "const"? > 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 ) This will break userspace. Just because you update libtraceevent doesn't mean that it will get to all the users of it. There's still tools that have the old method hard coded and doesn't use the library. Now, because the old tools still do the parsing of this format, we can add a new field called prev_state_char that will give you this. Now to save space, we should change prev_state to int (can't make it short as there's that test for "+" which does sometimes happen). I believe we can make prev_prio and next prio into shorts (and possibly chars!). -- Steve > @@ -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)