Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1972095rwo; Thu, 3 Aug 2023 02:49:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGKVJYvCDSBZHTqRGiV9s/asKKY25VFWcQ7Lr3q/lMh6PeGMeReUSW9TmgY71BPCme/wAE X-Received: by 2002:a17:906:5354:b0:98d:cd3e:c193 with SMTP id j20-20020a170906535400b0098dcd3ec193mr6967304ejo.46.1691056173763; Thu, 03 Aug 2023 02:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691056173; cv=none; d=google.com; s=arc-20160816; b=m/W5/l7Z0z7a1j8J25agLcFm8B6iqkWbp1g5G+A8hT36BISO5M9MkqRaim+bGvULlo zA8zgKSLCcuBgORXMhT+i0EJGyaReQcKB1DNuFTZ9hou1vWY8Duh0hsRd3Jfi3geXZxT oh07IBP8NdUqCq8wOtGBO2S701Oj+w/3fqcUQkq5MazxvrEA3ybpvDJmfMI3dGOMv5BJ /2a6u7WNPt2qzE1nJ2tjO+PxS0F3eUPUD15RGfoUyrsCzptscCnyJIvkMzkjYhZrp25a 0t3v9f6NyYiTRnQy+/PcsFyRx0srqgL1CpDe50xeFfY9WuNRL7Lp9/1XaeGzER+6cHvH B4uw== 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=udeCv5Eb6WVvc42CBfcTLqT1WQOD5nOEZCJGPiMa+0o=; fh=UpFtFCzii5ykkGoXq8QCM+IXKNgpf9xKHjNRjBS9wMU=; b=pihAmktCXSWxXx3k8qudbxaKgzKInFpYcc1GoUUTrWhm23AmdT6Qx79nxqqd9rxNWy SOXEYJSvAAmsYr3G87FD33R8spp8aBj1zr/R4puluHMPdNePb1HVoYzp8EQcPaSVKGS6 KLYjyCLUVTuLsoh11sObgPEM8zEwtNoJwiUQvDSCr/uswbgTcbkEI4Z9bJpnMf5asS3S qzLwcK/cYyIqU23Tdd5ouTfbKVCAHz1hBfvOIMSX+syiEt7yx4NU5BOuJeeVZ8xawdlV /NpDIkXgmI1ugU63a8NxYeH4eve+gc1BU1FtSu84MKnG2Fog0al5gqpJKcPbjT7SHzo4 qp2g== 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 um9-20020a170906cf8900b00992d6fa3b33si11440701ejb.440.2023.08.03.02.49.09; Thu, 03 Aug 2023 02:49:33 -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 S234624AbjHCJTF (ORCPT + 99 others); Thu, 3 Aug 2023 05:19:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbjHCJSc (ORCPT ); Thu, 3 Aug 2023 05:18:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6BE2684; Thu, 3 Aug 2023 02:18:31 -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 EE9BE61CFB; Thu, 3 Aug 2023 09:18:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D84B6C433C7; Thu, 3 Aug 2023 09:18:28 +0000 (UTC) Date: Thu, 3 Aug 2023 05:18:26 -0400 From: Steven Rostedt To: Ze Gao Cc: Adrian Hunter , Alexander Shishkin , Arnaldo Carvalho de Melo , Ian Rogers , Ingo Molnar , Jiri Olsa , Mark Rutland , Masami Hiramatsu , Namhyung Kim , Peter Zijlstra , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Ze Gao Subject: Re: [RFC PATCH v6 3/5] sched, tracing: reorganize fields of switch event struct Message-ID: <20230803051826.25ba7973@gandalf.local.home> In-Reply-To: <20230803083352.1585-4-zegao@tencent.com> References: <20230803083352.1585-1-zegao@tencent.com> <20230803083352.1585-4-zegao@tencent.com> X-Mailer: Claws Mail 3.19.1 (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=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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 Thu, 3 Aug 2023 04:33:50 -0400 Ze Gao wrote: > Report prioritiy and prev_state in 'short' to save some buffer > space. And also reorder the fields so that we take struct > alignment into consideration to make the record compact. If I were to write this, I would have wrote: The prev_state field in the sched_switch event is assigned by __trace_sched_switch_state(). The largest number that function will return is TASK_REPORT_MAX which is just 0x100. There's no reason that the prev_state field is a full 32 bits when it is using just 9 bits max. In order to save space on the ring buffer, shrink the prev_state to 16 bits (short). Also, change the positions of the other fields to accommodate the short value of prev_state to eliminate any holes that were created in the structure. See the difference? > > #ifdef CREATE_TRACE_POINTS > -static inline long __trace_sched_switch_state(bool preempt, > +static inline short __trace_sched_switch_state(bool preempt, > unsigned int prev_state, > struct task_struct *p) > { > unsigned int state; > > #ifdef CONFIG_SCHED_DEBUG > - BUG_ON(p != current); > + WARN_ON_ONCE(p != current); > #endif /* CONFIG_SCHED_DEBUG */ The above needs to be a separate patch. -- Steve > > /* > @@ -229,23 +229,23 @@ TRACE_EVENT(sched_switch, > TP_ARGS(preempt, prev, next, prev_state), > > TP_STRUCT__entry( > - __array( char, prev_comm, TASK_COMM_LEN ) > __field( pid_t, prev_pid ) > - __field( int, prev_prio ) > - __field( long, prev_state ) > - __array( char, next_comm, TASK_COMM_LEN ) > __field( pid_t, next_pid ) > - __field( int, next_prio ) > + __field( short, prev_prio ) > + __field( short, next_prio ) > + __array( char, prev_comm, TASK_COMM_LEN ) > + __array( char, next_comm, TASK_COMM_LEN ) > + __field( short, prev_state ) > ), > > TP_fast_assign( > - memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); > - __entry->prev_pid = prev->pid; > - __entry->prev_prio = prev->prio; > - __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); > + __entry->prev_pid = prev->pid; > + __entry->next_pid = next->pid; > + __entry->prev_prio = (short) prev->prio; > + __entry->next_prio = (short) next->prio; > memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); > - __entry->next_pid = next->pid; > - __entry->next_prio = next->prio; > + memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); > + __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); > /* XXX SCHED_DEADLINE */ > ), >