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

Commit 308230b9 authored by Carlos Llamas's avatar Carlos Llamas Committed by Todd Kjos
Browse files

ANDROID: binder: switch task argument for binder_thread



Refactor binder priority functions to take in 'struct binder_thread *'
instead of just 'struct task_struct *'. This allows access to other
thread fields used in subsequent patches. In any case, the same task
reference is still available under thread->task.

There is no functional impact from this patch.

Bug: 148101660
Signed-off-by: default avatarCarlos Llamas <cmllamas@google.com>
Change-Id: I67b599884580d957d776500e467827e5035c99f6
(cherry picked from commit 759d98484b5b51932d3d11651fa83c6bb268ce03)
parent 807b6742
Loading
Loading
Loading
Loading
+14 −12
Original line number Original line Diff line number Diff line
@@ -650,10 +650,11 @@ static int to_kernel_prio(int policy, int user_priority)
		return MAX_USER_RT_PRIO - 1 - user_priority;
		return MAX_USER_RT_PRIO - 1 - user_priority;
}
}


static void binder_do_set_priority(struct task_struct *task,
static void binder_do_set_priority(struct binder_thread *thread,
				   const struct binder_priority *desired,
				   const struct binder_priority *desired,
				   bool verify)
				   bool verify)
{
{
	struct task_struct *task = thread->task;
	int priority; /* user-space prio value */
	int priority; /* user-space prio value */
	bool has_cap_nice;
	bool has_cap_nice;
	unsigned int policy = desired->sched_policy;
	unsigned int policy = desired->sched_policy;
@@ -713,22 +714,23 @@ static void binder_do_set_priority(struct task_struct *task,
		set_user_nice(task, priority);
		set_user_nice(task, priority);
}
}


static void binder_set_priority(struct task_struct *task,
static void binder_set_priority(struct binder_thread *thread,
				const struct binder_priority *desired)
				const struct binder_priority *desired)
{
{
	binder_do_set_priority(task, desired, /* verify = */ true);
	binder_do_set_priority(thread, desired, /* verify = */ true);
}
}


static void binder_restore_priority(struct task_struct *task,
static void binder_restore_priority(struct binder_thread *thread,
				    const struct binder_priority *desired)
				    const struct binder_priority *desired)
{
{
	binder_do_set_priority(task, desired, /* verify = */ false);
	binder_do_set_priority(thread, desired, /* verify = */ false);
}
}


static void binder_transaction_priority(struct task_struct *task,
static void binder_transaction_priority(struct binder_thread *thread,
					struct binder_transaction *t,
					struct binder_transaction *t,
					struct binder_node *node)
					struct binder_node *node)
{
{
	struct task_struct *task = thread->task;
	struct binder_priority desired = t->priority;
	struct binder_priority desired = t->priority;
	const struct binder_priority node_prio = {
	const struct binder_priority node_prio = {
		.sched_policy = node->sched_policy,
		.sched_policy = node->sched_policy,
@@ -760,7 +762,7 @@ static void binder_transaction_priority(struct task_struct *task,
		desired = node_prio;
		desired = node_prio;
	}
	}


	binder_set_priority(task, &desired);
	binder_set_priority(thread, &desired);
	trace_android_vh_binder_set_priority(t, task);
	trace_android_vh_binder_set_priority(t, task);
}
}


@@ -2523,7 +2525,7 @@ static int binder_proc_transaction(struct binder_transaction *t,
		thread = binder_select_thread_ilocked(proc);
		thread = binder_select_thread_ilocked(proc);


	if (thread) {
	if (thread) {
		binder_transaction_priority(thread->task, t, node);
		binder_transaction_priority(thread, t, node);
		binder_enqueue_thread_work_ilocked(thread, &t->work);
		binder_enqueue_thread_work_ilocked(thread, &t->work);
	} else if (!pending_async) {
	} else if (!pending_async) {
		binder_enqueue_work_ilocked(&t->work, &proc->todo);
		binder_enqueue_work_ilocked(&t->work, &proc->todo);
@@ -3189,7 +3191,7 @@ static void binder_transaction(struct binder_proc *proc,
		binder_inner_proc_unlock(target_proc);
		binder_inner_proc_unlock(target_proc);
		wake_up_interruptible_sync(&target_thread->wait);
		wake_up_interruptible_sync(&target_thread->wait);
		trace_android_vh_binder_restore_priority(in_reply_to, current);
		trace_android_vh_binder_restore_priority(in_reply_to, current);
		binder_restore_priority(current, &in_reply_to->saved_priority);
		binder_restore_priority(thread, &in_reply_to->saved_priority);
		binder_free_transaction(in_reply_to);
		binder_free_transaction(in_reply_to);
	} else if (!(t->flags & TF_ONE_WAY)) {
	} else if (!(t->flags & TF_ONE_WAY)) {
		BUG_ON(t->buffer->async_transaction != 0);
		BUG_ON(t->buffer->async_transaction != 0);
@@ -3303,7 +3305,7 @@ static void binder_transaction(struct binder_proc *proc,
	BUG_ON(thread->return_error.cmd != BR_OK);
	BUG_ON(thread->return_error.cmd != BR_OK);
	if (in_reply_to) {
	if (in_reply_to) {
		trace_android_vh_binder_restore_priority(in_reply_to, current);
		trace_android_vh_binder_restore_priority(in_reply_to, current);
		binder_restore_priority(current, &in_reply_to->saved_priority);
		binder_restore_priority(thread, &in_reply_to->saved_priority);
		thread->return_error.cmd = BR_TRANSACTION_COMPLETE;
		thread->return_error.cmd = BR_TRANSACTION_COMPLETE;
		binder_enqueue_thread_work(thread, &thread->return_error.work);
		binder_enqueue_thread_work(thread, &thread->return_error.work);
		binder_send_failed_reply(in_reply_to, return_error);
		binder_send_failed_reply(in_reply_to, return_error);
@@ -3974,7 +3976,7 @@ static int binder_thread_read(struct binder_proc *proc,
						 binder_stop_on_user_error < 2);
						 binder_stop_on_user_error < 2);
		}
		}
		trace_android_vh_binder_restore_priority(NULL, current);
		trace_android_vh_binder_restore_priority(NULL, current);
		binder_restore_priority(current, &proc->default_priority);
		binder_restore_priority(thread, &proc->default_priority);
	}
	}


	if (non_block) {
	if (non_block) {
@@ -4199,7 +4201,7 @@ static int binder_thread_read(struct binder_proc *proc,


			trd->target.ptr = target_node->ptr;
			trd->target.ptr = target_node->ptr;
			trd->cookie =  target_node->cookie;
			trd->cookie =  target_node->cookie;
			binder_transaction_priority(current, t, target_node);
			binder_transaction_priority(thread, t, target_node);
			cmd = BR_TRANSACTION;
			cmd = BR_TRANSACTION;
		} else {
		} else {
			trd->target.ptr = 0;
			trd->target.ptr = 0;