From patchwork Thu Mar 23 19:06:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13186006 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 816B4C74A5B for ; Thu, 23 Mar 2023 19:06:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 882A76B0080; Thu, 23 Mar 2023 15:06:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79D396B0083; Thu, 23 Mar 2023 15:06:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DD3A6B0081; Thu, 23 Mar 2023 15:06:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 145526B0080 for ; Thu, 23 Mar 2023 15:06:21 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E3EB114078F for ; Thu, 23 Mar 2023 19:06:20 +0000 (UTC) X-FDA: 80601093720.01.EA59A4E Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf01.hostedemail.com (Postfix) with ESMTP id D33A540016 for ; Thu, 23 Mar 2023 19:06:18 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=P6MesIwO; spf=pass (imf01.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=1679598379; 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=YeArfzNmlzlmwx85t002ZAphXKNyZLO/t1fBMSB55q+0W/S4ugdFHu1VYEfNc69PmSDZkR CHYHnzVaBeb6Eje8DxzGY3A9nLEd5tUaFWtTZQhkF2FLK4dlGamRcnJP697RzP/yxkVSEn SjfrDPsHLnafoVqGxqeR8oH2mKq3n7U= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=P6MesIwO; spf=pass (imf01.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=1679598379; a=rsa-sha256; cv=none; b=u9inZoilBWhQtu1XLvwo+942mn/k71AS3s7A0clmqHjWIKh0ypTQcHryUNEvwpc084QPNX Z/+2+ogZFEBHioDw6E7ShO+r78BOvWhsSMPxkCZCaUU/YMxUk7EF7r+qqR1hCmw4YWwBtQ gsPdQe58jbib+140MqpUiOoFxHWAbnk= Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 7CFCE20FC3CF; Thu, 23 Mar 2023 12:06:17 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7CFCE20FC3CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679598377; bh=dmkEXknb1A0Qhw2AWPTXryudmpuAFo4IqxhDoe6dNiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P6MesIwOojUCuQ3GuY7LjicEPdHYhGGiJQ+CLacm4xFS3stHwHJQoJTlvELbhrp+o QhEPZcaTIQYaIwcGDCBf2ezN2TCYtIuMYH83fwOTCwPa3Mz8GowW+tWbMgGdCwaFrA WBvnVy6owmiFugDjS1/g/mkA32fYLpZvgBT8FRgQ= 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: [RESEND PATCH v8 08/11] tracing/user_events: Use write ABI in example Date: Thu, 23 Mar 2023 12:06:07 -0700 Message-Id: <20230323190610.251-9-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230323190610.251-1-beaub@linux.microsoft.com> References: <20230323190610.251-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: rysnxjsqxyh4dmcq5tdfoprng8oowcnx X-Rspamd-Queue-Id: D33A540016 X-HE-Tag: 1679598378-841845 X-HE-Meta: U2FsdGVkX1/QJfAoKGs2vhMzJjVxCH0Wdt87yrqrx0nFkIDmn1ehjnZsxKRuzSqSiA/+reUeZyiSp1rtmkQto3iT91jEOQ6mQoWpWpwp02K8AEoG7+mdmgnz9jieJDKJlkjYUQ3pKKrRluiT8Q8JrtBIXG4c928NZq4Fm2FThgNbFTAE7A4qUgtrX3imqAwGXqJovEX6GvXJ6Lg5gDeI6necuKiRsO+k1yuV12qtAKoGiIcQl+ULdjiEsPT+SVRN4r08R+kH1sq+vdLZ35zEGHXxUvIvcZgDvADPsft2tZPGgeK+3XwJ5Vpvq+GeOK2Sa0ctl2caj0s6cPJ2xSyJxhk2klQJ0aZi0NTgpJqLBbtrfM8x2w9SC6gfx1tLUEpc/nYbBBqL4KYXDoFdi3GwlZb7s+BXOmZKTowsPtwqGOiFfTMkZDH7F8ENj6/yAKlVRH48uxmZK01n7lh/TZElchx9JRX3G4/JyXegHjTeVJp8Ca8Iqy85cha+KRT9REL1BhmY+JpgR7yvSs+MGQjCBT60vW6eLVEnnwnj4HqvjkLVqSX/ht0sJnE9E7+sT2JOYaveLvV8z5EDs7OBZ/zt21/hrhHrj19FLvDF9jTgbhNxzGA00GNSOKMQA4NnWtM6WLTO409+VZFAyKAO8b+WxQbxofjMcbAVCO4GZj7OgOhbpz6TjVmnvEiFGQJxLqTQF5xN2TkH97dpXjhpGwNosEn3mSzg4ZAbgjblSc2tCV8xDBOSfOE+3EIRVPYyUwMincqwTj7Yi4azamgo8rOzkcq0a+AWWrDs2olM0JIZOEhuHGofkaCoycrwxiEyI6s3Qtz0/SZ2wzttyexNaV6Q2PqQ68K+KuS/TI0U4fz5LrqSNVMeEaXsJ9gpSme1W/bVx9/APxdM0ODgUP6fKGStlcu+FPOXRk+oRsitixUC1XZ6vrnvIgJx4MI6jXovezd5lDDD8nieU0q82K2xbSP LPSwfFls 6gMDqrI4CqS4PYfI7xoeKLXFgtI3gcUlHAdcl6cFL3+yw5ge3OVTdM8BmMJpQLTGuemdA372NROFtWCMy8gi57DJhjYXaXuizKqfzSnJZzQpqxm3r8CXMFvKDJIONR2VheZXKiFXygqbsF6NKdqeOwU09oKp2gBUG4mLTn+O98GQo7BF05gJeSuXYgk9kiLIAzdjTa716uCmdHbYE8EkEfjKouPmo56OXWRQYvOCmwnV3CYn9s1Xp+NzrBAaRIVqtoTd6Ts0oJyQ2Zh2fHvul9fbvsLeti5TyUZQkMt00H9yC7ts= 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);