From 3fd220679ce235f0e222978ed5f1244d8f64963a Mon Sep 17 00:00:00 2001 From: Jin Qian Date: Thu, 2 Mar 2017 13:32:59 -0800 Subject: [PATCH] ANDROID: taskstats: track fsync syscalls This adds a counter to the taskstats extended accounting fields, which tracks the number of times fsync is called, and then plumbs it through to the uid_sys_stats driver. Bug: 120442023 Change-Id: I6c138de5b2332eea70f57e098134d1d141247b3f Signed-off-by: Jin Qian [AmitP: Refactored changes to align with changes from upstream commit 9a07000400c8 ("sched/headers: Move CONFIG_TASK_XACCT bits from to ")] Signed-off-by: Amit Pundir [tkjos: Needed for storaged fsync accounting ("storaged --uid" and "storaged --task").] [astrachan: This is modifying a userspace interface and should probably be reworked] Signed-off-by: Alistair Strachan --- drivers/misc/Kconfig | 2 +- drivers/misc/uid_sys_stats.c | 2 ++ fs/sync.c | 3 ++- include/linux/sched/xacct.h | 9 +++++++++ include/linux/task_io_accounting.h | 2 ++ include/linux/task_io_accounting_ops.h | 1 + 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index ba9d624472a2..241e3d9ee7aa 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -515,7 +515,7 @@ config MISC_RTSX config UID_SYS_STATS bool "Per-UID statistics" - depends on PROFILING && TASK_IO_ACCOUNTING + depends on PROFILING && TASK_XACCT && TASK_IO_ACCOUNTING help Per UID based cpu time statistics exported to /proc/uid_cputime Per UID based io statistics exported to /proc/uid_io diff --git a/drivers/misc/uid_sys_stats.c b/drivers/misc/uid_sys_stats.c index ea23f5d0af43..36b5f37fca2f 100644 --- a/drivers/misc/uid_sys_stats.c +++ b/drivers/misc/uid_sys_stats.c @@ -249,6 +249,7 @@ static void add_uid_tasks_io_stats(struct uid_entry *uid_entry, task_io_slot->write_bytes += compute_write_bytes(task); task_io_slot->rchar += task->ioac.rchar; task_io_slot->wchar += task->ioac.wchar; + task_io_slot->fsync += task->ioac.syscfs; } static void compute_io_uid_tasks(struct uid_entry *uid_entry) @@ -452,6 +453,7 @@ static void add_uid_io_stats(struct uid_entry *uid_entry, io_slot->write_bytes += compute_write_bytes(task); io_slot->rchar += task->ioac.rchar; io_slot->wchar += task->ioac.wchar; + io_slot->fsync += task->ioac.syscfs; add_uid_tasks_io_stats(uid_entry, task, slot); } diff --git a/fs/sync.c b/fs/sync.c index b54e0541ad89..055daab8652a 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -220,6 +220,7 @@ static int do_fsync(unsigned int fd, int datasync) if (f.file) { ret = vfs_fsync(f.file, datasync); fdput(f); + inc_syscfs(current); } return ret; } diff --git a/include/linux/sched/xacct.h b/include/linux/sched/xacct.h index c078f0a94cec..9544c9d9d534 100644 --- a/include/linux/sched/xacct.h +++ b/include/linux/sched/xacct.h @@ -28,6 +28,11 @@ static inline void inc_syscw(struct task_struct *tsk) { tsk->ioac.syscw++; } + +static inline void inc_syscfs(struct task_struct *tsk) +{ + tsk->ioac.syscfs++; +} #else static inline void add_rchar(struct task_struct *tsk, ssize_t amt) { @@ -44,6 +49,10 @@ static inline void inc_syscr(struct task_struct *tsk) static inline void inc_syscw(struct task_struct *tsk) { } + +static inline void inc_syscfs(struct task_struct *tsk) +{ +} #endif #endif /* _LINUX_SCHED_XACCT_H */ diff --git a/include/linux/task_io_accounting.h b/include/linux/task_io_accounting.h index 6f6acce064de..bb26108ca23c 100644 --- a/include/linux/task_io_accounting.h +++ b/include/linux/task_io_accounting.h @@ -19,6 +19,8 @@ struct task_io_accounting { u64 syscr; /* # of write syscalls */ u64 syscw; + /* # of fsync syscalls */ + u64 syscfs; #endif /* CONFIG_TASK_XACCT */ #ifdef CONFIG_TASK_IO_ACCOUNTING diff --git a/include/linux/task_io_accounting_ops.h b/include/linux/task_io_accounting_ops.h index bb5498bcdd96..733ab62ae141 100644 --- a/include/linux/task_io_accounting_ops.h +++ b/include/linux/task_io_accounting_ops.h @@ -97,6 +97,7 @@ static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, dst->wchar += src->wchar; dst->syscr += src->syscr; dst->syscw += src->syscw; + dst->syscfs += src->syscfs; } #else static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,