Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10d5f7ef authored by Andres Oportus's avatar Andres Oportus Committed by Vincent Zvikaramba
Browse files

ANDROID: cpufreq: stats: add uid removal for uid_time_in_state



Bug: 62295304
Bug: 34133340
Test: Boot and test uid removal by writing to remove_uid_range

Signed-off-by: default avatarAndres Oportus <andresoportus@google.com>
Change-Id: Ic51fc9480716a8aad88fb55549c2b69021038a11
parent 1e5a73ed
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -884,6 +884,27 @@ static void cpufreq_stats_create_table(unsigned int cpu)
	cpufreq_cpu_put(policy);
}

void cpufreq_task_stats_remove_uids(uid_t uid_start, uid_t uid_end)
{
	struct uid_entry *uid_entry;
	struct hlist_node *tmp;

	rt_mutex_lock(&uid_lock);

	for (; uid_start <= uid_end; uid_start++) {
		hash_for_each_possible_safe(uid_hash_table, uid_entry, tmp,
			hash, uid_start) {
			if (uid_start == uid_entry->uid) {
				hash_del(&uid_entry->hash);
				kfree(uid_entry->dead_time_in_state);
				kfree(uid_entry);
			}
		}
	}

	rt_mutex_unlock(&uid_lock);
}

static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
		unsigned long val, void *data)
{
+24 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/cpufreq.h>

#define UID_HASH_BITS	10
static DECLARE_HASHTABLE(hash_table, UID_HASH_BITS);
@@ -413,7 +414,8 @@ static ssize_t uid_remove_write(struct file *file,
	struct hlist_node *tmp;
	char uids[128];
	char *start_uid, *end_uid = NULL;
	long int uid_start = 0, uid_end = 0;
	long int start = 0, end = 0;
	uid_t uid_start, uid_end;

	if (count >= sizeof(uids))
		count = sizeof(uids) - 1;
@@ -428,15 +430,32 @@ static ssize_t uid_remove_write(struct file *file,
	if (!start_uid || !end_uid)
		return -EINVAL;

	if (kstrtol(start_uid, 10, &uid_start) != 0 ||
		kstrtol(end_uid, 10, &uid_end) != 0) {
	if (kstrtol(start_uid, 10, &start) != 0 ||
		kstrtol(end_uid, 10, &end) != 0) {
		return -EINVAL;
	}

#define UID_T_MAX (((uid_t)~0U)-1)
	if ((start < 0) || (end < 0) ||
		(start > UID_T_MAX) || (end > UID_T_MAX)) {
		return -EINVAL;
	}

	uid_start = start;
	uid_end = end;

	/* TODO need to unify uid_sys_stats interface with uid_time_in_state.
	 * Here we are reusing remove_uid_range to reduce the number of
	 * sys calls made by userspace clients, remove_uid_range removes uids
	 * from both here as well as from cpufreq uid_time_in_state
	 */
	cpufreq_task_stats_remove_uids(uid_start, uid_end);

	rt_mutex_lock(&uid_lock);

	for (; uid_start <= uid_end; uid_start++) {
		hash_for_each_possible_safe(hash_table, uid_entry, tmp,
							hash, (uid_t)uid_start) {
							hash, uid_start) {
			if (uid_start == uid_entry->uid) {
				remove_uid_tasks(uid_entry);
				hash_del(&uid_entry->hash);
@@ -446,6 +465,7 @@ static ssize_t uid_remove_write(struct file *file,
	}

	rt_mutex_unlock(&uid_lock);

	return count;
}

+2 −1
Original line number Diff line number Diff line
@@ -501,6 +501,7 @@ static inline void acct_update_power(struct task_struct *p, cputime_t cputime) {

void cpufreq_task_stats_init(struct task_struct *p);
void cpufreq_task_stats_exit(struct task_struct *p);
void cpufreq_task_stats_remove_uids(uid_t uid_start, uid_t uid_end);
int  proc_time_in_state_show(struct seq_file *m, struct pid_namespace *ns,
	struct pid *pid, struct task_struct *p);