From 956a0d3998cdc9bfc3608bc358d0fab974bf4905 Mon Sep 17 00:00:00 2001 From: Manish Varma Date: Mon, 15 Mar 2021 21:40:24 -0700 Subject: [PATCH] ANDROID: fs: Add vendor hooks for ep_create_wakeup_source & timerfd_create timerfd doesn't create any wakelocks, but eventpoll can. When it does, it names them after the underlying file descriptor, and since all timerfd file descriptors are named "[timerfd]" (which saves memory on systems like desktops with potentially many timerfd instances), all wakesources created as a result of using the eventpoll-on-timerfd idiom are called... "[timerfd]". However, it becomes impossible to tell which "[timerfd]" wakesource is affliated with which process and hence troubleshooting is difficult. Adding vendor hooks to allow vendor to assign appropriate names to timerfd descriptors and eventoll wakesource. Bug: 155142106 Signed-off-by: Manish Varma Change-Id: I330a42ab48bed4b26d5eb2f636925c66061165ec (cherry picked from commit 0ff110fbb309be385126a42ac9f7004ba9b0644e) --- drivers/android/vendor_hooks.c | 3 +++ fs/eventpoll.c | 11 +++++++++-- fs/timerfd.c | 9 +++++++-- include/trace/hooks/fs.h | 23 +++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 include/trace/hooks/fs.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 789fa7beea83..43eb748c1103 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -365,3 +366,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sd_update_bus_speed_mode); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_slab_folio_alloced); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_kmalloc_large_alloced); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_netlink_poll); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ep_create_wakeup_source); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_timerfd_create); diff --git a/fs/eventpoll.c b/fs/eventpoll.c index eccecd3fac90..30217f0fed81 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -39,6 +39,8 @@ #include #include +#include + /* * LOCKING: * There are three level of locking required by epoll : @@ -1373,15 +1375,20 @@ static int ep_create_wakeup_source(struct epitem *epi) { struct name_snapshot n; struct wakeup_source *ws; + char ws_name[64]; + strlcpy(ws_name, "eventpoll", sizeof(ws_name)); + trace_android_vh_ep_create_wakeup_source(ws_name, sizeof(ws_name)); if (!epi->ep->ws) { - epi->ep->ws = wakeup_source_register(NULL, "eventpoll"); + epi->ep->ws = wakeup_source_register(NULL, ws_name); if (!epi->ep->ws) return -ENOMEM; } take_dentry_name_snapshot(&n, epi->ffd.file->f_path.dentry); - ws = wakeup_source_register(NULL, n.name.name); + strlcpy(ws_name, n.name.name, sizeof(ws_name)); + trace_android_vh_ep_create_wakeup_source(ws_name, sizeof(ws_name)); + ws = wakeup_source_register(NULL, ws_name); release_dentry_name_snapshot(&n); if (!ws) diff --git a/fs/timerfd.c b/fs/timerfd.c index e9c96a0c79f1..de8e736bbf7b 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -28,6 +28,8 @@ #include #include +#include + struct timerfd_ctx { union { struct hrtimer tmr; @@ -407,6 +409,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) { int ufd; struct timerfd_ctx *ctx; + char file_name_buf[32]; /* Check the TFD_* constants for consistency. */ BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC); @@ -443,7 +446,9 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) ctx->moffs = ktime_mono_to_real(0); - ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx, + strlcpy(file_name_buf, "[timerfd]", sizeof(file_name_buf)); + trace_android_vh_timerfd_create(file_name_buf, sizeof(file_name_buf)); + ufd = anon_inode_getfd(file_name_buf, &timerfd_fops, ctx, O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS)); if (ufd < 0) kfree(ctx); @@ -451,7 +456,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) return ufd; } -static int do_timerfd_settime(int ufd, int flags, +static int do_timerfd_settime(int ufd, int flags, const struct itimerspec64 *new, struct itimerspec64 *old) { diff --git a/include/trace/hooks/fs.h b/include/trace/hooks/fs.h new file mode 100644 index 000000000000..bb8f177db5c1 --- /dev/null +++ b/include/trace/hooks/fs.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM fs + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH trace/hooks + +#if !defined(_TRACE_HOOK_FS_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_FS_H + +#include + +DECLARE_HOOK(android_vh_ep_create_wakeup_source, + TP_PROTO(char *name, int len), + TP_ARGS(name, len)); + +DECLARE_HOOK(android_vh_timerfd_create, + TP_PROTO(char *name, int len), + TP_ARGS(name, len)); +#endif /* _TRACE_HOOK_FS_H */ + +/* This part must be outside protection */ +#include \ No newline at end of file