From patchwork Fri Mar 24 22:30:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 74769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp64196vqo; Fri, 24 Mar 2023 15:34:50 -0700 (PDT) X-Google-Smtp-Source: AKy350aWAzl7yDxfn4uVd+MKAn8qmXmQKxN+hkfUqmB9jMtGZp9o77Lpw1daurYcdZTfUHj1S92N X-Received: by 2002:aa7:960c:0:b0:62a:9d4f:91f5 with SMTP id q12-20020aa7960c000000b0062a9d4f91f5mr4081004pfg.15.1679697290005; Fri, 24 Mar 2023 15:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679697289; cv=none; d=google.com; s=arc-20160816; b=UN0BaR04w8BqXIZoOtn744FDjkurQt4lzWmCLPDvSaARR/H01l0ePyoK05GicepbBt OcfRfgQYvIrzccqA7ReOamMcEGPxkLTdfv2TvD8k+u4B2fCJc31z3Cq56W3+Rm9/MTj4 K+yAwpb4XPigBvUanvr61fAOzXMHaC74QNQTfBvQMxkGeRrjl7lo9/TekoMjJ/hAi2iL 1A/MQUg9R4NPnB8/SpjQWkf3whf93Nphc6GG8xWq3yzmwHEcDmsjVWBePU95C9PkSuO4 FsE+1aTtFMUT0uTF80ArEKaEw+Pd/77Vp0krvJuDdbck1ycVGX1S7lFil+iFyfT5cHfp DSIA== 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=hfqIudwulcjdKwsTaKXMqS52vOstU/jUC4/dZgmErqZNR+ANbZ3s5iWTOcYo/tXYgP OT4PhQEyEOsyOV2Z2AmOYpHTSNeomzXNTQjL4vh9zsKRu+8i9KeSPY7ozu1Qd5lr188S YXpIshB7n9uFOxY5nL9kivpH7sD+O/CdW8RiLOsPPExOvrKs87uRkjUjDjLjMVPijaYt LL3j/dXwE9bgjge5nZDhVGTkcyxqVB6goi1QowamwXAz6VvSEzL+9hCfYYYA+7sQjkIs fAUvEtcMyqjj93DM9truxUyFCDK2fmKOSiekjGwlpvgcLG+rMp5r9E8W34+pv+PemFEd TPBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=eGbWIZ+r; 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 d134-20020a621d8c000000b006257a8b0d69si20864670pfd.100.2023.03.24.15.34.36; Fri, 24 Mar 2023 15:34:49 -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; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=eGbWIZ+r; 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 S232405AbjCXWbD (ORCPT + 99 others); Fri, 24 Mar 2023 18:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbjCXWan (ORCPT ); Fri, 24 Mar 2023 18:30:43 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 39D9917152; Fri, 24 Mar 2023 15:30:41 -0700 (PDT) Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 7D5A920FC4EC; Fri, 24 Mar 2023 15:30:40 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7D5A920FC4EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679697040; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eGbWIZ+r+NMvwDlV7XV+fCUEiVJiQbMzovpYLN/E3H38bh/7YBwM0+1hJuMB4rsfB jJVsETEGjoRj8UKVYM4pBFS5ASkm/fA6tWAGr35SDqDY5I78WDoAXrtQG4hHsz/05i UPzzlNG3HxCT4Sr4nBjRwpdhvvsCOMndyRzJPfvE= 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, ebiederm@xmission.com, keescook@chromium.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v9 08/11] tracing/user_events: Use write ABI in example Date: Fri, 24 Mar 2023 15:30:25 -0700 Message-Id: <20230324223028.172-9-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230324223028.172-1-beaub@linux.microsoft.com> References: <20230324223028.172-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-17.9 required=5.0 tests=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=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?1761290265763951661?= X-GMAIL-MSGID: =?utf-8?q?1761290265763951661?= 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);