From patchwork Tue Mar 28 23:52:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13191673 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 38DE0C76196 for ; Tue, 28 Mar 2023 23:52:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05BDF6B0087; Tue, 28 Mar 2023 19:52:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E33A36B0083; Tue, 28 Mar 2023 19:52:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAE446B0081; Tue, 28 Mar 2023 19:52:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B614C900003 for ; Tue, 28 Mar 2023 19:52:30 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 706B1ABDA8 for ; Tue, 28 Mar 2023 23:52:30 +0000 (UTC) X-FDA: 80619958860.07.70A9DAA Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf05.hostedemail.com (Postfix) with ESMTP id B221D100006 for ; Tue, 28 Mar 2023 23:52:28 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=fw5Hu2PH; spf=pass (imf05.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=1680047548; 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=IRZk7BFbyL7dULje+pVU8mjA+p0JDRZDJRSE/k81nqCTqP66iMAn4La4MqTje0E/W6bxVX rVAhfhZL8l0TgqdKBXXHc+kfT9lEhsN4+p8ZeXhmukfDSWOv5+mFHG6rU5YDvpuxdHaEDs T35S+U4+IvG/hT95/FEUzKGbLJCBBq4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=fw5Hu2PH; spf=pass (imf05.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=1680047548; a=rsa-sha256; cv=none; b=bwz2QpspM0u1lw1Norz0BwCio8Vo5Xct4SRyA8DGPsJgtaP/toySWD+tWlwJzZapGZHeCJ H8XWLN+XisUMlJDztbqFxsO4U3MCYK+adIGzIAKX7bPKUmb2T+qSEtn2jNykCLzfZ/FL2o qn7WKXPIgptxsZ2Y11MauIfFNAnUTKY= Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 840C020FDC26; Tue, 28 Mar 2023 16:52:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 840C020FDC26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680047547; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fw5Hu2PHEUphs88pUUTVc1A++7+3aYnR0xPiH7iapsn3ImWO0zjYiFI1POXN/rGK+ IyFSibY7nreLfH+9/gTtweT0J02Xe+1Dazlnwne3kXXuxztr3jowfd0h8ZKAovdhhk sJzvvVFl1u2gHKPj8svpyDZsVB9/Un6iIlU0Mae4= 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 v10 08/12] tracing/user_events: Use write ABI in example Date: Tue, 28 Mar 2023 16:52:15 -0700 Message-Id: <20230328235219.203-9-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328235219.203-1-beaub@linux.microsoft.com> References: <20230328235219.203-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B221D100006 X-Rspam-User: X-Stat-Signature: hm77im5r4ct9ahtrw8sw8eykkad3nr7h X-HE-Tag: 1680047548-615069 X-HE-Meta: U2FsdGVkX1/86Oj/mxsrSAdcMB5g596Fra3M+W6YuFpYpKG4CSMszIYMtyUbLqBjsW9S8Ozj3aOWxH8QRIkaRUFnJYdOpRpJGfSpXL5zXoEtlr5i7DVodBa1tXoG3KEFt4O6hkPbDHghxNk5I0YduQO1qNgNvBy2eIk+F78ZlTGiQwl9Xc1prmY7t6blP/ZxnJThYxRurcWYUejh7CAUW/vwOAOYpnawA7+4PWQ8d5jZsj/9AIQrEpyXtOqWil+6Df2bWyPkSzMPyaKcwxmAv2dntRmaj1SiGZfaE6jNiEutdHrVdLiy9OaLwzuJp9y+WiId0o3VlTo0y7u0bTE8t7mksguWOb6CiaRUu2HHfsJUoGyFRDdsmCpl6j6d5dPRGsCQR5G74tBCzYalG0mDiBfjsSa9R7JyONbuF3ivqOsCK8UaxwNHEDlRt6dJSL4gU9e0lIi8rnZDDvZSgW6u79OND/pBb2ORT7sOMHCBtMjGaOs5FKQM5ZajcZrBK06xCZOKOS0FhRxXLwjeuxZY+lpxuRa2rtNadj5YNg7CvIv62t1Xu2MZ4KGKRHmkAkpnUnCZlvQmoVNO30yPxWoHofRnZMYlFlNI5+D/HoiQ5ojCLusBXNUKdlDckLcZVCY2LEesgNwX862/mOi3Bc4pMOPjh6kQp+ESMB3tNhMCKi9i/bGxNHsAmiSp9AGGFwhWAUnmtuxiCUyVksrYR0asgY/qqpJ7m3LkFCxjZ+nK0VJkS6bJFGA2tlMV5eIDEiYIoCU6YXruSxddcHAxhBBdsn6sV5MNl03OIJSBxqt3XX6IAZRt+3nMGwQwuKjWpIp3RxIhVH/UfaMSSRkZpPL7NqhwkiznkUr/ltkSAMLX9c/RwGIMzKKXo64oK5eDOUGp14AbCWt03n2ZXl9Eegxv3m51OH28cO5zwR8jvAGhAz53/6zvxz6zOe8fNcnkFwDgwl40vUDNZoN4THxqu+n r7/LNqsR 1zdcbXoySYjzXwDek+rBpZaXPIzvDGYoyOoeTuAvKnmpR9LLrYAJMbIt20OlLHjpmHhNBGlg/T1kjHbfSgTA4/z61Fo4rFfXn1eX3yq+CDGf1Pbz3nQXwnD2dKAkSAdP0cSvEE62j5xDzKbOvZLMQmK+Fve7x8/VqjzbpnJ8ZxI2Ilx1iRbAFpX+jTuZ/h0VGgGOYBPtRG9zVXKXI2xWUQkzfG0ilITQs33hMVY3m8YzXQrONfB25p/eX/3f9a3pU5jrDFGcl13sY+kW+id6CDO0ZrRjfOO6NqDqivdqxUiypvNZsikvUDquCThesL9Tiz5dNnoNAqU+kPjbvJbg6Zs/Zjn38+3gJ3ihjBRFRVY9Z+k38ytiUMYX8SA== 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);