From patchwork Wed Mar 29 19:45:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 76784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp649330vqo; Wed, 29 Mar 2023 12:52:21 -0700 (PDT) X-Google-Smtp-Source: AKy350bSLubh0grzipJ5/sGsIscSejdeVyll6chbjUDvSJgWgX5tCoQr1P1O/KJrICvbRUHsN0Ud X-Received: by 2002:a17:902:d492:b0:1a2:8866:e8b2 with SMTP id c18-20020a170902d49200b001a28866e8b2mr59582plg.1.1680119541284; Wed, 29 Mar 2023 12:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680119541; cv=none; d=google.com; s=arc-20160816; b=wxKCganiwCIvR6rW7+0dsBAcjjvNZXiILtdo9cF30l7AB6BIMq9+PM58I8borkswzm k5l7/X2f0NiqRu6LJ8qqKg+AQ2uIkW97H4YbgQZifPDP5VMURg9w4DvoJ0tw3LoVa51L ED75rFhsCChl0fFUw/EjQBxux6y37dvBK00B4h3S7xk67oqeOFBmhdVUTF8sBA5/d/cc FH9EpTYrAV5R+qdDIgNF5t/0zD5N0SGC4T8ATLP5XdZnhNaYPG+0S45VcFb5hoepXHKM 5Q5s/9WEL6OKaQFGiOXuy+4JMKCrz8TTKqxDJ+XoT6xQo2ffOgZ7/bvLau0foX7SZQoO RQoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=02d7TFgJzLRkkG5zB+NkdUfduz3lCjl4V3vD+kU8pvs=; b=JFKXl9vEA6VRYXHBY/i6ZEzk0YeFCmKfF4vA6kFtVkYFynqwOKUORMhNdqUn9mwNtN eT9KHPx7IWQEyospMTMyLtnvo3jcm1yD/9l9KmujwWCCwxajiMUZ5Ri+v+o6wR56EXUS oK3gfD5CjLFNYbqHC4kJ5Oi+vshtcYPJV/AaZXqMFBhfI4IBJ6N0TbygckDz3MxJn7UN /SNzwaKCVF03V0K1XBV3R0yvtcE6yS/u9TLuTB9Pkhg1cn11sGg+3uczSx/gQU4Qvzio H99WnZ8zHTghm6I9UCFVDU86KJYK9lPu0FrwfTZRmqAIj53pNB2jPim7o2VSiu04gMc/ JndA== 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 h6-20020a170902ac8600b001a1a83b02a4si31013669plr.258.2023.03.29.12.52.08; Wed, 29 Mar 2023 12:52:21 -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 S230173AbjC2TrD (ORCPT + 99 others); Wed, 29 Mar 2023 15:47:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230131AbjC2Tp6 (ORCPT ); Wed, 29 Mar 2023 15:45:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D540065B7 for ; Wed, 29 Mar 2023 12:45:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 22B7BB82371 for ; Wed, 29 Mar 2023 19:45:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA0C5C4339E; Wed, 29 Mar 2023 19:45:53 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1phbk1-002Rop-0E; Wed, 29 Mar 2023 15:45:53 -0400 Message-ID: <20230329194552.889121252@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 29 Mar 2023 15:45:35 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-next][PATCH 19/25] tracing/user_events: Use write ABI in example References: <20230329194516.146147554@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761733028337806898?= X-GMAIL-MSGID: =?utf-8?q?1761733028337806898?= From: Beau Belgrave The ABI has changed to use a remote write approach. Update the example to show the expected use of this new ABI. Also remove debugfs path and use tracefs to ensure example works in more environments. Link: https://lkml.kernel.org/r/20230328235219.203-9-beaub@linux.microsoft.com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- samples/user_events/example.c | 45 +++++++---------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/samples/user_events/example.c b/samples/user_events/example.c index 18e34c9d708e..28165a096697 100644 --- a/samples/user_events/example.c +++ b/samples/user_events/example.c @@ -9,51 +9,28 @@ #include #include #include +#include #include #include #include -#include -#include #include -#if __BITS_PER_LONG == 64 -#define endian_swap(x) htole64(x) -#else -#define endian_swap(x) htole32(x) -#endif - -/* Assumes debugfs is mounted */ const char *data_file = "/sys/kernel/tracing/user_events_data"; -const char *status_file = "/sys/kernel/tracing/user_events_status"; +int enabled = 0; -static int event_status(long **status) -{ - int fd = open(status_file, O_RDONLY); - - *status = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ, - MAP_SHARED, fd, 0); - - close(fd); - - if (*status == MAP_FAILED) - return -1; - - return 0; -} - -static int event_reg(int fd, const char *command, long *index, long *mask, - int *write) +static int event_reg(int fd, const char *command, int *write, int *enabled) { struct user_reg reg = {0}; reg.size = sizeof(reg); + reg.enable_bit = 31; + reg.enable_size = sizeof(*enabled); + reg.enable_addr = (__u64)enabled; reg.name_args = (__u64)command; if (ioctl(fd, DIAG_IOCSREG, ®) == -1) return -1; - *index = reg.status_bit / __BITS_PER_LONG; - *mask = endian_swap(1L << (reg.status_bit % __BITS_PER_LONG)); *write = reg.write_index; return 0; @@ -62,17 +39,12 @@ static int event_reg(int fd, const char *command, long *index, long *mask, int main(int argc, char **argv) { int data_fd, write; - long index, mask; - long *status_page; struct iovec io[2]; __u32 count = 0; - if (event_status(&status_page) == -1) - return errno; - data_fd = open(data_file, O_RDWR); - if (event_reg(data_fd, "test u32 count", &index, &mask, &write) == -1) + if (event_reg(data_fd, "test u32 count", &write, &enabled) == -1) return errno; /* Setup iovec */ @@ -80,13 +52,12 @@ int main(int argc, char **argv) io[0].iov_len = sizeof(write); io[1].iov_base = &count; io[1].iov_len = sizeof(count); - ask: printf("Press enter to check status...\n"); getchar(); /* Check if anyone is listening */ - if (status_page[index] & mask) { + if (enabled) { /* Yep, trace out our data */ writev(data_fd, (const struct iovec *)io, 2);