proc: uid: Changes the thread notifier to profile event notifier.

In order to keep the code consistent with all other platforms, the
thread notifier is changed to profile event notifier.

Change-Id: I5b996c789927b42dacba10af6fe81a21866e2c8f
This commit is contained in:
Ruchi Kandoi 2015-04-06 17:53:17 -07:00 committed by Ed Tam
parent 9580994141
commit 6684fc826e
2 changed files with 19 additions and 34 deletions

View file

@ -668,7 +668,7 @@ config BU52031NVX_POUCHDETECT
config UID_CPUTIME
tristate "Per-UID cpu time statistics"
default n
depends on PROFILING
help
Per UID based cpu time statistics exported to /proc/uid_cputime

View file

@ -13,8 +13,6 @@
*
*/
#include <asm/thread_notify.h>
#include <linux/atomic.h>
#include <linux/err.h>
#include <linux/hashtable.h>
@ -22,6 +20,7 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/proc_fs.h>
#include <linux/profile.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
@ -30,7 +29,7 @@
#define UID_HASH_BITS 10
DECLARE_HASHTABLE(hash_table, UID_HASH_BITS);
static DEFINE_SPINLOCK(uid_lock);
static DEFINE_MUTEX(uid_lock);
static struct proc_dir_entry *parent;
struct uid_entry {
@ -82,7 +81,7 @@ static int uid_stat_show(struct seq_file *m, void *v)
cputime_t stime;
unsigned long bkt;
spin_lock(&uid_lock);
mutex_lock(&uid_lock);
hash_for_each(hash_table, bkt, node, uid_entry, hash) {
uid_entry->active_stime = 0;
@ -94,7 +93,7 @@ static int uid_stat_show(struct seq_file *m, void *v)
uid_entry = find_or_register_uid(task_uid(task));
if (!uid_entry) {
read_unlock(&tasklist_lock);
spin_unlock(&uid_lock);
mutex_unlock(&uid_lock);
pr_err("%s: failed to find the uid_entry for uid %d\n",
__func__, task_uid(task));
return -ENOMEM;
@ -115,7 +114,7 @@ static int uid_stat_show(struct seq_file *m, void *v)
cputime_to_usecs(total_stime));
}
spin_unlock(&uid_lock);
mutex_unlock(&uid_lock);
return 0;
}
@ -163,7 +162,7 @@ static ssize_t uid_remove_write(struct file *file,
return -EINVAL;
}
spin_lock(&uid_lock);
mutex_lock(&uid_lock);
for (; uid_start <= uid_end; uid_start++) {
hash_for_each_possible_safe(hash_table, uid_entry, node, tmp,
@ -173,7 +172,7 @@ static ssize_t uid_remove_write(struct file *file,
}
}
spin_unlock(&uid_lock);
mutex_unlock(&uid_lock);
return count;
}
@ -183,14 +182,19 @@ static const struct file_operations uid_remove_fops = {
.write = uid_remove_write,
};
static void uid_task_exit(struct task_struct *task)
static int process_notifier(struct notifier_block *self,
unsigned long cmd, void *v)
{
struct task_struct *task = v;
struct uid_entry *uid_entry;
uid_t uid = task_uid(task);
cputime_t utime, stime;
uid_t uid;
spin_lock(&uid_lock);
if (!task)
return NOTIFY_OK;
mutex_lock(&uid_lock);
uid = task_uid(task);
uid_entry = find_or_register_uid(uid);
if (!uid_entry) {
pr_err("%s: failed to find uid %d\n", __func__, uid);
@ -202,27 +206,8 @@ static void uid_task_exit(struct task_struct *task)
uid_entry->stime += stime;
exit:
spin_unlock(&uid_lock);
}
static int process_notifier(struct notifier_block *self,
unsigned long cmd, void *v)
{
struct thread_info *thread = v;
struct task_struct *task = v ? thread->task : NULL;
if (!task)
return NOTIFY_DONE;
switch (cmd) {
case THREAD_NOTIFY_EXIT:
uid_task_exit(task);
break;
default:
break;
}
return NOTIFY_DONE;
mutex_unlock(&uid_lock);
return NOTIFY_OK;
}
static struct notifier_block process_notifier_block = {
@ -245,7 +230,7 @@ static int __init proc_uid_cputime_init(void)
proc_create_data("show_uid_stat", S_IRUGO, parent, &uid_stat_fops,
NULL);
thread_register_notifier(&process_notifier_block);
profile_event_register(PROFILE_TASK_EXIT, &process_notifier_block);
return 0;
}