From patchwork Tue Feb 21 21:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13148405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E53CC64EC4 for ; Tue, 21 Feb 2023 21:12:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 305466B007B; Tue, 21 Feb 2023 16:11:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FA3C6B0083; Tue, 21 Feb 2023 16:11:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD87D6B0082; Tue, 21 Feb 2023 16:11:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 905F76B0080 for ; Tue, 21 Feb 2023 16:11:54 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 67285AAE0A for ; Tue, 21 Feb 2023 21:11:54 +0000 (UTC) X-FDA: 80492546148.07.10C49A2 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 9BD63120005 for ; Tue, 21 Feb 2023 21:11:52 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=lx3feqfY; spf=pass (imf29.hostedemail.com: domain of beaub@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=beaub@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677013912; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; b=0a97e9tsWUiDKc90QUIArKYxbV6Wu5Lwtq7zec3igQwd8f10TD0VMiliWDSnI3S/8CSxAa JjXLOfNOouF9uKoar+bgGg4r/0qqJy4lvyBA9VmqkMgOBYws6bcQDseabk8MxC6vxbCcUR qJinPvvxxkGvwFGXAB9JEUY+WzJXlRs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=lx3feqfY; spf=pass (imf29.hostedemail.com: domain of beaub@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=beaub@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677013912; a=rsa-sha256; cv=none; b=kAWc++BbzBvmSvcOVCrhfdi6+L6uVnVgpHd7CN1OwE1vVFb3AUMEouxCR00LPqohvpqH93 o8IBaSqRyqcs+k0ETMBYfN6BotujHZcJq7WUKp+S2cNeeDHXfCDFnoZ2adcogjs1utqpUU g4ZBvjnzL4j6NolPNfoQy3TwVgOzG04= Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 8134B209A93F; Tue, 21 Feb 2023 13:11:51 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8134B209A93F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1677013911; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lx3feqfYF+aEhN1mP3tQCcQD1e60V/NolIzXLKvQb3OD0NFi/tqVHTvtuYYX9E39b Q3k7ob2SXXoxxt8Wf/FzpCxyAqgo0vutRwwN79bYJPy3AyBVTE4RhOpUOfXAddi0EH /hci1B8YQnPMz+s1a4T+A6LYfh2NggSBhkYNaUwg= 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-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v8 08/11] tracing/user_events: Use write ABI in example Date: Tue, 21 Feb 2023 13:11:40 -0800 Message-Id: <20230221211143.574-9-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230221211143.574-1-beaub@linux.microsoft.com> References: <20230221211143.574-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9BD63120005 X-Stat-Signature: 1t6uh15nr8hkrg8s1ibnbtmjq6xr97zw X-HE-Tag: 1677013912-582369 X-HE-Meta: U2FsdGVkX1+RjJ5ZFg8mK2UZfh59rlMjjnYq5K6he0989dKLscICG0J3jrA6eW5oqsi+97AzdvL4SzbkVraa1MQcB4Tk0Gs1PqlaC4RzPPsZPKqaLMhSmOOGmKQoKgo1utDrOnogVHyn/gMCE3h1lRY50dkTEF8DfAIkULLgNI993oV2WREAM4ljTtGxJo81rwr7copEcOeQzdNh1IjRVZoeRuwSBLc5kTavLBEN4U/h5Gs7HgruIWTJBHTzXL6GDngubRAimcJUdE/VZXShBwG8G4n/BfCH8V6f8K1kwyOk5in46ctaFOmLBlYye2F5egpimmXwEMjlNeNoZJZxrZJbQWL5RzX9BwVSe7s4F+/h1CDQ3BD0h5VGGwKl1iIU2HMBseK4NtDzDo0zikQ81mRxHaZLRijygfBXt5aJqWIZXNPjqe8djSKX1845AAb4HbUPnVdRJgDTVjrjnbQqHbOjU0cN3KxX57txLcZp1X4vgwGEwWzSNQflC8pw98YW5l6NflN21C3QJR6Xw3FqGksVKKF9qooJ9NdvFQZH9xy7IEYEDwVLx0j+6F70YZgC/3CI4hli7gTgWNfWZf24yHrcuE51q/0DRD5zV2nutO7qhL9ZvpkkzHaHoH1riPv32y2cp75tBpJT9fmvzEYKW83P+vRJW3M7rCxmj6WM071c5vsu0gDBVEuhixE7Ix2iMEpL7YEhJErKirdR8zHfDCAQbnrZaiO8bpKCw/d7qMQ8VLJ5UJlD8x93+drhTWv3gCMUPyJlpyHnJRB1JIkY3Ua33wJamCEUuTrAmA1D+FF/0TFV9rQDdgePrEXQedXzxQC85jJm5g/TiW3xJYG4QSQOfX2vZVwkS/gr9KM+FYykYZB6mo8R6Ad6AWj6ngxZQwQheswP4DqwG4Satw8h501XpVuBX77X3zehPFL9DHv1jFvywl2VAHH7PlScgjaJcxP9SKg7gFnYdRjyhTB PcQvoGcI F7y+XVpo51b5j6sh0quGiWgcwKfLm1MTv0Cefr2L+bmUkF7HXEmhXhCV6hTb4UZkcQ/DvEgMpZqDPPKBLB4BPWNX4N4X0nNdUEPyJidI/PH4C6sV/ke9beJ75EO0WC50oZkeLzn6Qx1dEPh7ftXYFo/PZAAzU4/Q2x/nED9VKjm2glf9XvnYVOJZ/VnOGbArDJZSk+US+1RQW7i8NZ3E9G+5RKfgGxtWCJqIU/wdOh+UGynCo6QjV3g2LBi6Dj7esY3X94krDSi4K5di73ZDjDBmCC8j7gNfJLsZLhbt0EBZWURg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);