From 7a9cbd82c8b5f839a256b5b24b9775b2b09c7cf5 Mon Sep 17 00:00:00 2001 From: yipeng xiang Date: Tue, 21 Jan 2025 16:54:49 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add hooks for f2fs down read Add hook to solve the priority inversion, In CPU high load scenarios, once the f2fs rwsem was hold by thread as the writer with low priority, then the key thread will be blocked here. So a prio scheme in the hook is needed to optimize this. Bug: 369935682 Change-Id: Ie7f85900169348c961aacda9ccdb7f74e6e77889 Signed-off-by: yipeng xiang --- drivers/android/vendor_hooks.c | 2 ++ fs/f2fs/checkpoint.c | 8 ++++++++ fs/f2fs/f2fs.h | 7 +++++++ include/trace/hooks/fs.h | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 include/trace/hooks/fs.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 73fa22c3ea84..dce2d7e95005 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -111,6 +112,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_uic_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_send_tm_command); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_check_int_errors); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_update_sdev); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_f2fs_down_read); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_io_statistics); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cgroup_attach); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_iommu_setup_dma_ops); diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index efda9a022981..6b3113958f6b 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -20,12 +20,20 @@ #include "segment.h" #include "iostat.h" #include +#include #define DEFAULT_CHECKPOINT_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3)) static struct kmem_cache *ino_entry_slab; struct kmem_cache *f2fs_inode_entry_slab; +void _trace_android_rvh_f2fs_down_read(wait_queue_head_t *read_waiters, + struct rw_semaphore *rwsem, bool *skip) +{ + trace_android_rvh_f2fs_down_read(read_waiters, rwsem, skip); +} +EXPORT_SYMBOL_GPL(_trace_android_rvh_f2fs_down_read); + void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io, unsigned char reason) { diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6f2cbf4c5740..9ab4522c7ae9 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2180,8 +2180,15 @@ static inline int f2fs_rwsem_is_contended(struct f2fs_rwsem *sem) return rwsem_is_contended(&sem->internal_rwsem); } +void _trace_android_rvh_f2fs_down_read(wait_queue_head_t *read_waiters, + struct rw_semaphore *rwsem, bool *skip); + static inline void f2fs_down_read(struct f2fs_rwsem *sem) { + bool skip = false; + _trace_android_rvh_f2fs_down_read(&sem->read_waiters, &sem->internal_rwsem, &skip); + if (skip) + return; #ifdef CONFIG_F2FS_UNFAIR_RWSEM wait_event(sem->read_waiters, down_read_trylock(&sem->internal_rwsem)); #else diff --git a/include/trace/hooks/fs.h b/include/trace/hooks/fs.h new file mode 100644 index 000000000000..93132d98c846 --- /dev/null +++ b/include/trace/hooks/fs.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM fs + +#define TRACE_INCLUDE_PATH trace/hooks + +#if !defined(_TRACE_HOOK_FS_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_FS_H + +#include + +DECLARE_RESTRICTED_HOOK(android_rvh_f2fs_down_read, + TP_PROTO(wait_queue_head_t *read_waiters, struct rw_semaphore *rwsem, bool *skip), + TP_ARGS(read_waiters, rwsem, skip), 1); + +#endif /* _TRACE_HOOK_FS_H */ + +/* This part must be outside protection */ +#include