Message ID | 20230525054032.29392-1-sunliming@kylinos.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp136010vqr; Wed, 24 May 2023 22:54:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hxIyuT4LzVcM1e2ndhbJDwq/fgfztgdgaGWOC3J0+tLMT7QnlNrF+BRJnhE2xxQXixLWP X-Received: by 2002:a17:90b:314d:b0:253:3f25:3d99 with SMTP id ip13-20020a17090b314d00b002533f253d99mr476552pjb.45.1684994093354; Wed, 24 May 2023 22:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684994093; cv=none; d=google.com; s=arc-20160816; b=biCGSAvgJl+OO75HiSc9Ezj6BfWi4T5+GVZfmLN0rI1QVRddem7ZRCqe5pqGV0+TwQ PpaILzyoArqJy/UfgiRBVV7lSIMsa0EfR2Nov6jolhmkce9YJerA2izRjDZ0kk65qUCp IiXu8fHiuYFZhMRJkWObsO1XwXbJv9G5Zlz7u3jZXZ6Xeof+8dNUIMbiBX4AAq3IJMbY 9Y+PlxvjO5f0emkn13Q8dR13isqjvxrRYyn6RfdPNdp+JGX3bcu6bwvXXH3s65j7anZo 9894irrBLa80gvDs9vWfYxDJTDMucFK3ZbWt9oI5AYLLGuGXvaEF5bXggO6UqSvTWPzx 8zlA== 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 :message-id:date:subject:cc:to:from; bh=DUK+1sZwH5x1POWo13nOYhiz5YcV3CrJGvFKdHODSKo=; b=xTQaeS9U6TxKCt83Bf0DQGd5eQkQqbs/r5tuIr5hhtKYKLKQ7/FfJsfpQi1qWBLLn+ cLa5lELsX23TnwNHY7QYsgBTsSu76T7nrC/yx2SLj40WGSUW3RzasKRQRFs+mwMNMPGf c749K9W6owIPlHDU4rFWQZOETz5NmWO443ozQ1k9oi9W1uv0G9bjQ5mUrY2LxZy0lheb P67girt+bLbjDkOyWTHj5I1s4X2ghETJ5p9qsvihYiVizuD3gEQP6e+QBAwbUMdOAsXn f59aepnsXGtlkcKJ9XuzSHTE0kGDqC8kc02huRJ/bxjH7D9wzdzlIl/6p1Bmblqla/Zk 6o6A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d24-20020a17090ab31800b00255d819b632si782745pjr.43.2023.05.24.22.54.38; Wed, 24 May 2023 22:54:53 -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 S231578AbjEYFkm (ORCPT <rfc822;ahmedalshaiji.dev@gmail.com> + 99 others); Thu, 25 May 2023 01:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjEYFkl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 25 May 2023 01:40:41 -0400 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54F9BA1; Wed, 24 May 2023 22:40:39 -0700 (PDT) Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-64f47448aeaso1353972b3a.0; Wed, 24 May 2023 22:40:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684993239; x=1687585239; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DUK+1sZwH5x1POWo13nOYhiz5YcV3CrJGvFKdHODSKo=; b=P5aPmgayiHAnMuvWbYhQE0mpZpyB81ISHO6aQPuDxUeQWKGsmzcHF9zzHTaGz9Ba6l OmZQ4Tb3LSxaFKFFNrfQPR/gBddy3EPcPLk14iBLtbpLa00Iejm1iU851FGMbEeuFf+2 nU63CN2WgLbu1IVgB8k2lkkWv2CvD7ueWSJrbuSIuEcfOrqT4dkmonxFej32AlRF40u5 l5JnwUtv1qAzhKSnvFfrtUn3rO9YXg9ySz3JwmrXUZ4HRS3/6SVyDMkMvy6uQIyMvmXG Xx2mwYR7fmEOb1TsEsue4JVqwS26wAmoAIS4wP2VSI8jvQNCI6tcf7gmgBDEZQy0U58O a9Sg== X-Gm-Message-State: AC+VfDxc1pG8Yluish1XQ4QpvUuWxNHi60PNzKpsO8HafHwi4P2cI4xI yO6cwqen2T+xjxqqh9jcDg== X-Received: by 2002:aa7:88d0:0:b0:63b:854e:8459 with SMTP id k16-20020aa788d0000000b0063b854e8459mr6626319pff.31.1684993238570; Wed, 24 May 2023 22:40:38 -0700 (PDT) Received: from localhost.localdomain ([116.128.244.169]) by smtp.gmail.com with ESMTPSA id l11-20020a62be0b000000b0064dbf805ff7sm364200pff.72.2023.05.24.22.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 22:40:38 -0700 (PDT) From: sunliming <sunliming@kylinos.cn> To: mhiramat@kernel.org, rostedt@goodmis.org, beaub@linux.microsoft.com Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, kelulanainsley@gmail.com, sunliming <sunliming@kylinos.cn> Subject: [PATCH] tracing/user_events: Fix the order of the fields in the trace output Date: Thu, 25 May 2023 13:40:32 +0800 Message-Id: <20230525054032.29392-1-sunliming@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766844366261400494?= X-GMAIL-MSGID: =?utf-8?q?1766844366261400494?= |
Series |
tracing/user_events: Fix the order of the fields in the trace output
|
|
Commit Message
sunliming
May 25, 2023, 5:40 a.m. UTC
Commit 4bec284cc0b9 ("tracing/user_events: Use print_format_fields() for
trace output") use print_event_fields() as safe and gives user readable
output. However, due to the insertion of the struct ftrace_event_field
structure into the field linked list from the header, the trace output
oder of fields of user events is reversed. Fix the problem by insertint
to the tail of field linked list.
Signed-off-by: sunliming <sunliming@kylinos.cn>
---
kernel/trace/trace_events_user.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, May 25, 2023 at 01:40:32PM +0800, sunliming wrote: > Commit 4bec284cc0b9 ("tracing/user_events: Use print_format_fields() for > trace output") use print_event_fields() as safe and gives user readable > output. However, due to the insertion of the struct ftrace_event_field > structure into the field linked list from the header, the trace output > oder of fields of user events is reversed. Fix the problem by insertint > to the tail of field linked list. > > Signed-off-by: sunliming <sunliming@kylinos.cn> > --- > kernel/trace/trace_events_user.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c > index aacd22c1e9f8..e9e2ec3c7613 100644 > --- a/kernel/trace/trace_events_user.c > +++ b/kernel/trace/trace_events_user.c > @@ -972,7 +972,7 @@ static int user_event_add_field(struct user_event *user, const char *type, > if (filter_type == FILTER_OTHER) > field->filter_type = filter_assign_type(type); > > - list_add(&field->link, &user->fields); > + list_add_tail(&field->link, &user->fields); > > /* > * Min size from user writes that are required, this does not include > -- > 2.25.1 Thanks for the patch, however, this breaks the tracefs format file. The fields are required to be put in backwards since it walks them backwards. Example using this: echo 'u:test u32 a; u32 b;' > dynamic_events cat /sys/kernel/tracing/events/user_events/test/format Before this change: name: test ... format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:u32 a; offset:8; size:4; signed:0; field:u32 b; offset:12; size:4; signed:0; print fmt: "a=%u b=%u", REC->a, REC->b After this change: name: test ... format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:u32 b; offset:12; size:4; signed:0; field:u32 a; offset:8; size:4; signed:0; print fmt: "b=%u a=%u", REC->b, REC->a I do agree though, that print_fields() is doing it backwards. Can you please fix the print_fields() function instead? (It should walk the list of fields backwards like tracefs format file does). Steven can then Ack that work, since it's isolated there. Thanks, -Beau
OK,I got it. Beau Belgrave <beaub@linux.microsoft.com> 于2023年5月26日周五 00:53写道: > > On Thu, May 25, 2023 at 01:40:32PM +0800, sunliming wrote: > > Commit 4bec284cc0b9 ("tracing/user_events: Use print_format_fields() for > > trace output") use print_event_fields() as safe and gives user readable > > output. However, due to the insertion of the struct ftrace_event_field > > structure into the field linked list from the header, the trace output > > oder of fields of user events is reversed. Fix the problem by insertint > > to the tail of field linked list. > > > > Signed-off-by: sunliming <sunliming@kylinos.cn> > > --- > > kernel/trace/trace_events_user.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c > > index aacd22c1e9f8..e9e2ec3c7613 100644 > > --- a/kernel/trace/trace_events_user.c > > +++ b/kernel/trace/trace_events_user.c > > @@ -972,7 +972,7 @@ static int user_event_add_field(struct user_event *user, const char *type, > > if (filter_type == FILTER_OTHER) > > field->filter_type = filter_assign_type(type); > > > > - list_add(&field->link, &user->fields); > > + list_add_tail(&field->link, &user->fields); > > > > /* > > * Min size from user writes that are required, this does not include > > -- > > 2.25.1 > > Thanks for the patch, however, this breaks the tracefs format file. The > fields are required to be put in backwards since it walks them > backwards. > > Example using this: > echo 'u:test u32 a; u32 b;' > dynamic_events > cat /sys/kernel/tracing/events/user_events/test/format > > Before this change: > name: test > ... > format: > field:unsigned short common_type; offset:0; size:2; signed:0; > field:unsigned char common_flags; offset:2; size:1; signed:0; > field:unsigned char common_preempt_count; offset:3; size:1; signed:0; > field:int common_pid; offset:4; size:4; signed:1; > > field:u32 a; offset:8; size:4; signed:0; > field:u32 b; offset:12; size:4; signed:0; > > print fmt: "a=%u b=%u", REC->a, REC->b > > After this change: > name: test > ... > format: > field:unsigned short common_type; offset:0; size:2; signed:0; > field:unsigned char common_flags; offset:2; size:1; signed:0; > field:unsigned char common_preempt_count; offset:3; size:1; signed:0; > field:int common_pid; offset:4; size:4; signed:1; > > field:u32 b; offset:12; size:4; signed:0; > field:u32 a; offset:8; size:4; signed:0; > > print fmt: "b=%u a=%u", REC->b, REC->a > > I do agree though, that print_fields() is doing it backwards. Can you > please fix the print_fields() function instead? (It should walk the list > of fields backwards like tracefs format file does). > > Steven can then Ack that work, since it's isolated there. > > Thanks, > -Beau
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c index aacd22c1e9f8..e9e2ec3c7613 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -972,7 +972,7 @@ static int user_event_add_field(struct user_event *user, const char *type, if (filter_type == FILTER_OTHER) field->filter_type = filter_assign_type(type); - list_add(&field->link, &user->fields); + list_add_tail(&field->link, &user->fields); /* * Min size from user writes that are required, this does not include