From patchwork Tue Nov 22 22:52:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 24624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2484620wrr; Tue, 22 Nov 2022 15:10:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf5iOcRHiSSD7A1uxHLwB0NA7av5dRbzg2kx6tk4m10r/m17H8A0zR4pDVWo7+LYUJD8IGnC X-Received: by 2002:a17:906:ce4a:b0:7ae:5ad1:e834 with SMTP id se10-20020a170906ce4a00b007ae5ad1e834mr21430711ejb.312.1669158624299; Tue, 22 Nov 2022 15:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669158624; cv=none; d=google.com; s=arc-20160816; b=kYL2ylXp33M+iA1WiYffclDfF3BQ86dy0j6+8n5BnAuwnxhi187sOv3zxcoyjw452X XGAzSsJ3meQLUPWDH/ak67u5bE7bW/S732Eo3gSe51FFeHCIrMhq2pDTKLxynZ7ZP+0j Sx5najRfv+vwxEbnsjnudA86HJA8Xvr2gHzG6M7h1Rv2zXGFmnF99XdHMOWDjcV518Lx m/3viotA8tS4VndaptLlsjSKAea11F5Tlp8j3BW+OC7DD00exDpju1eHa9p8KWFHPJo8 kb2Fq1m/Cdqi304ZaVQNPRqxWxEhorsrJx8YkwwH/RGfOnzEHUdh798Vqfovi6/MC6s4 3sbg== 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:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; b=G5GfAVjxbsHWFxrTcDXYwSwCJXUNmG8omNk710XTzW8YmJLvp5ggaNp+6aMgvOWTgF SDZdtkQkemMy/53VuRlLnee7LohJPcwQKYWgN4irkEcY9RDwFTcb4Bsg0qeuAChbWb2b kWpWhZpEv0ALNBvVNda+qA6HeyFyQsRfjNS8qveVrdfVUq+4gRd1uDvnz6Q1QwSyN3eh Gi+1d6wDP7Zww/SFg5O9kYtborRLXx9E5Urn9K9Sjl7A2ZIE2aewh5o11CzojPBXebEa jkTxXbeIN6ZC8d1wniI6E0O1vEAkb1kOeN3kNs+TveZsJD1AaZPwBt2XJWngOe9wBys2 xgKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Zzw/+Vh/"; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c16-20020a05640227d000b0045a16f47a9fsi13641510ede.624.2022.11.22.15.09.58; Tue, 22 Nov 2022 15:10:24 -0800 (PST) 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=@linux.microsoft.com header.s=default header.b="Zzw/+Vh/"; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235260AbiKVWwx (ORCPT + 99 others); Tue, 22 Nov 2022 17:52:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235119AbiKVWwU (ORCPT ); Tue, 22 Nov 2022 17:52:20 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4844FC9A81; Tue, 22 Nov 2022 14:52:20 -0800 (PST) Received: from W11-BEAU-MD.localdomain (unknown [76.135.50.127]) by linux.microsoft.com (Postfix) with ESMTPSA id DDD2520B83EE; Tue, 22 Nov 2022 14:52:19 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DDD2520B83EE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1669157540; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zzw/+Vh/KnR1kr4o0v11o16pFOTkVvQG2EQhAOcbenBY5U+Q446331qHxBe0lpYLy fp4HQemKG0rHQwv3Y9bwLeTu4sxfvTGhJK+Duy5YeLQy39dkOIkj6649aoDDL3oytA KOKI+iegodiQJX6kr2wr4cAY6cJ3+BNHNbYqLbaU= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dcook@linux.microsoft.com, alanau@linux.microsoft.com, brauner@kernel.org, akpm@linux-foundation.org Cc: linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 8/9] tracing/user_events: Use write ABI in example Date: Tue, 22 Nov 2022 14:52:12 -0800 Message-Id: <20221122225213.2317-9-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122225213.2317-1-beaub@linux.microsoft.com> References: <20221122225213.2317-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750239673692578122?= X-GMAIL-MSGID: =?utf-8?q?1750239673692578122?= 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. Signed-off-by: Beau Belgrave --- samples/user_events/example.c | 47 +++++++---------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/samples/user_events/example.c b/samples/user_events/example.c index d06dc24156ec..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 +const char *data_file = "/sys/kernel/tracing/user_events_data"; +int enabled = 0; -/* Assumes debugfs is mounted */ -const char *data_file = "/sys/kernel/debug/tracing/user_events_data"; -const char *status_file = "/sys/kernel/debug/tracing/user_events_status"; - -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);