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: 13187430 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 7A149C76195 for ; Fri, 24 Mar 2023 22:30:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3FEA900003; Fri, 24 Mar 2023 18:30:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB9496B007B; Fri, 24 Mar 2023 18:30:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86BB3900004; Fri, 24 Mar 2023 18:30:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 67FF96B007D for ; Fri, 24 Mar 2023 18:30:43 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 47DB21208E5 for ; Fri, 24 Mar 2023 22:30:43 +0000 (UTC) X-FDA: 80605237566.25.4A00800 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf08.hostedemail.com (Postfix) with ESMTP id 89D7C160019 for ; Fri, 24 Mar 2023 22:30:41 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=eGbWIZ+r; spf=pass (imf08.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=1679697041; a=rsa-sha256; cv=none; b=qKZ7JG1kmE+ZkCp1bXMFIQ7EuuWSgMSZFie+qx6SaN2ZA4qok7zN0Sf8DADZ8UvN4yvUIe Mv1Xmc/Pq+Xfctg+B8AK5i9+7EiV6dZwDHqy+zy7F5AQ1ui4xno7ukYSJl5dET46YwqB55 /GUmgFvKiT7XxZKZ4UwyMMBSAXGMbUg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=eGbWIZ+r; spf=pass (imf08.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=1679697041; 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=F72q7Zk+5i306e6sH8DShjyKyvhtXAAuaqF6zQqyTz8Oo3ua5aR49GhbtIGTpDlIjQ5Z2P RBNPDJT8Almdt2+J8VRer9jFF5VCO1gd6NOmtC0RAqO+2/pIT36MUHqaj+V7v0a1SilzHj zmVus8avQlcjoaEgm9Co6zudZvaDSOM= 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-Rspam-User: X-Rspamd-Queue-Id: 89D7C160019 X-Rspamd-Server: rspam01 X-Stat-Signature: ez6a8gzg6bsco5b7akadnjba55gbxxn1 X-HE-Tag: 1679697041-570025 X-HE-Meta: U2FsdGVkX18GxwPGrEBssj6HYGqo3nsjqmghH6Oq2lWX1gfCmKe3VbBUGELEVE1p16CQEtcq/UVp3ybninwXVLSX5s4USkoEBD5C9lqD2Ycx/gVIPkaU1MwUF5lnm5CujdYHvSAPQswD5DvKd4WJm1rgwCBQKGULM2w/Wio2m46JOiqO7h7ek+VHeAYu02Uc6RgQs37iDPdaruNHfQE+zG/lPNO5ToR1wdfiBN8dFa/OkqgyKz2nnRGdIT06UWhi95DSACEpRpQZcXn08BIYxTxloABszuWNqktuLAHRxEx3tkJ2SP2Fg+8JzLdLUyxPluGOktiWkXGD5K38rTSP6PhmYfY2O7pk0n7nzPz/mwRTXSZv+bptM91ppWv1DrV4F3I+Drd7QFHv1b7qCS9dzn1QhptXs6mvJhE54jbhug6L8iEt1P9m0UL3fMejQIJ21BpPIRTaPhwSbny206LZh0R+3aC2Ib1noMTS/SavB63I5ioYbJG/0EiCJqLlHcypWncCNZCW14qLa+s48m/olLasc3dxcm8e8fbD+t0z/O9gyKTgX/pNwO50hndLX6/ttAL5zVq/rnq4pk0zvUuGP+Fy+xY+qvt0sg0rNYH7Q5TxNQ6uaaItHFa4B7X8zUEGpyMC5Cvldnmswj/4Z9kn2qVdwoAVEPVyO55SlToYjneIlHCoK14+wKwVDPQfZlCUdb+gEUQBra0wpi4bKia9yLTPHeXpEqEd/X4ngRbYPTLdyTS1wFd4Ytd2bw8uuTZebmxj9IoYUaejQyahIW1WLRWhXJszJYoBZX21dygGbPAFYcBKBC4etNanCsbdAgFCBrLgXsWqFqROYs116UPYOKUXo6SDo63quSsffqeF0dJjFfQAIKnRC4AU72x4HuuNBzDI0TsLJq/T71G5Qo7MB6f1ZKjuOZl0EKj/3K9u+6f/l808AnhE1hrqiT5t12KPZ8nzT3oGOypPdsdH3Ot 8E3yPfot 0ZtzviqUVwGgjggDsmbTPZz7WJmAKi/XUGY+GwfMBcGgTRaF4qyChkzHjrCRO6owbZB8SuSwZnP1GRvSqhRVDMiUvjLjEvcbtu/EWA+x0wOZH6TTdcOe6oFq3CEUoWTdHq69jB5UxKuC226FORe908ZyDyJ9DVPKDerGWQo96mTMqrfH2T9W3gTB8tNuWn7RWCunrO2qxqLnf/Tl7C1d+NRMpzfs0NOFV0GhIg+aGEhHRiZJ2BfitShbJJmbFhK1QxKqjw0SmNh569tVluzFdm/xUVLWey+FkWGFXz0mSao9lAEk= 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);