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 <jinqian@google.com>
[AmitP: Refactored changes to align with changes from upstream commit
        9a07000400 ("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").]
[astrachan: This is modifying a userspace interface and should probably
            be reworked]
Signed-off-by: Alistair Strachan <astrachan@google.com>
This commit is contained in:
Jin Qian 2017-03-02 13:32:59 -08:00 committed by Alistair Strachan
parent f4eeb5d6c6
commit 3fd220679c
6 changed files with 17 additions and 2 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -9,7 +9,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>
@ -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;
}

View file

@ -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 */

View file

@ -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

View file

@ -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,