| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| From: Jin Qian <jinqian@google.com> |
| Date: Thu, 2 Mar 2017 13:32:59 -0800 |
| Subject: 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. |
| |
| [CPNOTE: 01/07/21] Lee: Requested status on the bug |
| |
| Bug: 120442023 |
| Change-Id: I6c138de5b2332eea70f57e098134d1d141247b3f |
| Signed-off-by: Jin Qian <jinqian@google.com> |
| [AmitP: Refactored changes to align with changes from upstream commit |
| 9a07000400c8 ("sched/headers: Move CONFIG_TASK_XACCT bits from <linux/sched.h> to <linux/sched/xacct.h>")] |
| Signed-off-by: Amit Pundir <amit.pundir@linaro.org> |
| [tkjos: Needed for storaged fsync accounting ("storaged --uid" and |
| "storaged --task").] |
| [adelva: This is modifying a userspace interface and should probably |
| be reworked] |
| Signed-off-by: Alistair Delva <adelva@google.com> |
| --- |
| 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 |
| --- a/drivers/misc/Kconfig |
| +++ b/drivers/misc/Kconfig |
| @@ -462,7 +462,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 |
| --- 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) |
| @@ -459,6 +460,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 |
| --- a/fs/sync.c |
| +++ b/fs/sync.c |
| @@ -10,7 +10,7 @@ |
| #include <linux/slab.h> |
| #include <linux/export.h> |
| #include <linux/namei.h> |
| -#include <linux/sched.h> |
| +#include <linux/sched/xacct.h> |
| #include <linux/writeback.h> |
| #include <linux/syscalls.h> |
| #include <linux/linkage.h> |
| @@ -205,6 +205,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 |
| --- 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 |
| --- 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 |
| --- 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, |