Lines Matching defs:thread
21 * 3) proc->inner_lock : protects the thread and node lists
24 * (proc->todo, thread->todo, proc->delivered_death and
25 * node->async_todo), as well as thread->transaction_stack
247 * There are separate work lists for proc, thread, and node (async).
528 * struct binder_thread - binder thread bookkeeping
529 * @proc: binder process for this thread
535 * @pid: PID for this thread
538 * (only accessed by this thread)
539 * @looper_needs_return: looping thread needs to exit driver
541 * @transaction_stack: stack of in-progress transactions for this thread
543 * @todo: list of work to do for this thread
547 * @return_error: transaction errors reported by this thread
548 * (only accessed by this thread)
549 * @reply_error: transaction errors reported by target thread
551 * @wait: wait queue for thread work
552 * @stats: per-thread statistics
554 * @tmp_ref: temporary reference to indicate thread is in use
557 * @is_dead: thread is dead and awaiting free
568 int looper; /* only modified by this thread */
569 bool looper_need_return; /* can be written by other thread */
632 * during thread teardown
846 * binder_enqueue_deferred_thread_work_ilocked() - Add deferred thread work
847 * @thread: thread to queue work to
850 * Adds the work to the todo list of the thread. Doesn't set the process_todo
851 * flag, which means that (if it wasn't already set) the thread will go to
857 binder_enqueue_deferred_thread_work_ilocked(struct binder_thread *thread,
860 WARN_ON(!list_empty(&thread->waiting_thread_node));
861 binder_enqueue_work_ilocked(work, &thread->todo);
865 * binder_enqueue_thread_work_ilocked() - Add an item to the thread work list
866 * @thread: thread to queue work to
869 * Adds the work to the todo list of the thread, and enables processing
875 binder_enqueue_thread_work_ilocked(struct binder_thread *thread,
878 WARN_ON(!list_empty(&thread->waiting_thread_node));
879 binder_enqueue_work_ilocked(work, &thread->todo);
886 if (thread->looper & BINDER_LOOPER_STATE_POLL &&
887 thread->pid == current->pid && !thread->process_todo)
888 wake_up_interruptible_sync(&thread->wait);
890 thread->process_todo = true;
894 * binder_enqueue_thread_work() - Add an item to the thread work list
895 * @thread: thread to queue work to
898 * Adds the work to the todo list of the thread, and enables processing
902 binder_enqueue_thread_work(struct binder_thread *thread,
905 binder_inner_proc_lock(thread->proc);
906 binder_enqueue_thread_work_ilocked(thread, work);
907 binder_inner_proc_unlock(thread->proc);
945 static void binder_free_thread(struct binder_thread *thread);
959 static bool binder_has_work_ilocked(struct binder_thread *thread,
962 return thread->process_todo ||
963 thread->looper_need_return ||
965 !binder_worklist_empty_ilocked(&thread->proc->todo));
968 static bool binder_has_work(struct binder_thread *thread, bool do_proc_work)
972 binder_inner_proc_lock(thread->proc);
973 has_work = binder_has_work_ilocked(thread, do_proc_work);
974 binder_inner_proc_unlock(thread->proc);
979 static bool binder_available_for_proc_work_ilocked(struct binder_thread *thread)
981 return !thread->transaction_stack &&
982 binder_worklist_empty_ilocked(&thread->todo) &&
983 (thread->looper & (BINDER_LOOPER_STATE_ENTERED |
991 struct binder_thread *thread;
994 thread = rb_entry(n, struct binder_thread, rb_node);
995 if (thread->looper & BINDER_LOOPER_STATE_POLL &&
996 binder_available_for_proc_work_ilocked(thread)) {
998 wake_up_interruptible_sync(&thread->wait);
1000 wake_up_interruptible(&thread->wait);
1006 * binder_select_thread_ilocked() - selects a thread for doing proc work.
1007 * @proc: process to select a thread from
1009 * Note that calling this function moves the thread off the waiting_threads
1011 * signal. Therefore, callers *should* always wake up the thread this function
1014 * Return: If there's a thread currently waiting for process work,
1015 * returns that thread. Otherwise returns NULL.
1020 struct binder_thread *thread;
1023 thread = list_first_entry_or_null(&proc->waiting_threads,
1027 if (thread)
1028 list_del_init(&thread->waiting_thread_node);
1030 return thread;
1034 * binder_wakeup_thread_ilocked() - wakes up a thread for doing proc work.
1035 * @proc: process to wake up a thread in
1036 * @thread: specific thread to wake-up (may be NULL)
1039 * This function wakes up a thread in the @proc process.
1040 * The caller may provide a specific thread to wake-up in
1041 * the @thread parameter. If @thread is NULL, this function
1045 * should first call binder_select_thread() to find a thread
1046 * to handle the work (if they don't have a thread already),
1047 * and pass the result into the @thread parameter.
1050 struct binder_thread *thread,
1055 if (thread) {
1057 wake_up_interruptible_sync(&thread->wait);
1059 wake_up_interruptible(&thread->wait);
1063 /* Didn't find a thread waiting for proc work; this can happen
1073 * a thread that called into (e)poll is handling non-binder
1081 struct binder_thread *thread = binder_select_thread_ilocked(proc);
1083 binder_wakeup_thread_ilocked(proc, thread, /* sync = */false);
1213 * The node was already added by another thread
1250 struct binder_thread *thread = container_of(target_list,
1253 BUG_ON(&thread->todo != target_list);
1254 binder_enqueue_deferred_thread_work_ilocked(thread,
1469 * Return: the ref for node. It is possible that another thread
1823 * Another thread created the ref first so
1843 * binder_thread_dec_tmpref() - decrement thread->tmp_ref
1844 * @thread: thread to decrement
1846 * A thread needs to be kept alive while being used to create or
1848 * extract t->from from a binder_transaction and keep the thread
1851 * tmp_ref and free if appropriate (thread has been released
1854 static void binder_thread_dec_tmpref(struct binder_thread *thread)
1858 * it cannot reach zero or thread->is_dead is false
1860 binder_inner_proc_lock(thread->proc);
1861 atomic_dec(&thread->tmp_ref);
1862 if (thread->is_dead && !atomic_read(&thread->tmp_ref)) {
1863 binder_inner_proc_unlock(thread->proc);
1864 binder_free_thread(thread);
1867 binder_inner_proc_unlock(thread->proc);
1896 * binder_get_txn_from() - safely extract the "from" thread in transaction
1899 * Atomically return the "from" thread and increment the tmp_ref
1900 * count for the thread to ensure it stays alive until
1923 * to guarantee that the thread cannot be released while operating on it.
2039 "reply failed, no target thread at root\n");
2044 "reply failed, no target thread -- retry %d\n",
2331 struct binder_thread *thread,
2492 * Need to make sure the thread goes
2496 if (thread)
2497 thread->looper_need_return = true;
2511 struct binder_thread *thread,
2520 binder_transaction_buffer_release(proc, thread, buffer,
2526 struct binder_thread *thread)
2529 struct binder_proc *proc = thread->proc;
2542 proc->pid, thread->pid, (u64)fp->binder,
2555 &thread->todo, &rdata);
2579 struct binder_thread *thread)
2581 struct binder_proc *proc = thread->proc;
2591 proc->pid, thread->pid, fp->handle);
2652 struct binder_thread *thread,
2655 struct binder_proc *proc = thread->proc;
2668 proc->pid, thread->pid,
2678 proc->pid, thread->pid, fd);
2691 * target thread.
2962 struct binder_thread *thread,
2968 struct binder_proc *proc = thread->proc;
2977 proc->pid, thread->pid, (u64)fda->num_fds);
2984 proc->pid, thread->pid, (u64)fda->num_fds);
3002 proc->pid, thread->pid);
3016 ret = binder_translate_fd(fd, offset, t, thread,
3026 struct binder_thread *thread,
3035 struct binder_proc *proc = thread->proc;
3049 proc->pid, thread->pid);
3058 proc->pid, thread->pid);
3066 proc->pid, thread->pid);
3078 * @thread: thread in @proc to send the transaction to (may be NULL)
3081 * to find a thread in the target process to handle the transaction and
3082 * wake it up. If no thread is found, the work is queued to the proc
3085 * If the @thread parameter is not NULL, the transaction is always queued
3086 * to the waitlist of that specific thread.
3089 * false if the target process or thread is dead
3093 struct binder_thread *thread)
3102 BUG_ON(thread);
3111 if (proc->is_dead || (thread && thread->is_dead)) {
3117 if (!thread && !pending_async)
3118 thread = binder_select_thread_ilocked(proc);
3120 if (thread)
3121 binder_enqueue_thread_work_ilocked(thread, &t->work);
3128 binder_wakeup_thread_ilocked(proc, thread, !oneway /* sync */);
3179 struct binder_thread *thread,
3217 e->from_thread = thread->pid;
3225 in_reply_to = thread->transaction_stack;
3229 proc->pid, thread->pid);
3235 if (in_reply_to->to_thread != thread) {
3238 proc->pid, thread->pid, in_reply_to->debug_id,
3251 thread->transaction_stack = in_reply_to->to_parent;
3264 proc->pid, thread->pid,
3299 proc->pid, thread->pid);
3315 proc->pid, thread->pid);
3346 w = list_first_entry_or_null(&thread->todo,
3352 * thread that has a transaction at the head of
3355 * thread from proc->waiting_threads to enqueue
3357 * todo list while the thread is on waiting_threads.
3359 binder_user_error("%d:%d new transaction not allowed when there is a transaction on thread todo\n",
3360 proc->pid, thread->pid);
3368 if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) {
3371 tmp = thread->transaction_stack;
3372 if (tmp->to_thread != thread) {
3375 proc->pid, thread->pid, tmp->debug_id,
3433 proc->pid, thread->pid, t->debug_id,
3442 proc->pid, thread->pid, t->debug_id,
3450 t->from = thread;
3458 t->async_from_pid = thread->proc->pid;
3459 t->async_from_tid = thread->pid;
3544 proc->pid, thread->pid);
3552 proc->pid, thread->pid, (u64)tr->offsets_size);
3560 proc->pid, thread->pid,
3606 proc->pid, thread->pid);
3616 proc->pid, thread->pid,
3639 ret = binder_translate_binder(fp, t, thread);
3657 ret = binder_translate_handle(fp, t, thread);
3675 thread, in_reply_to);
3706 proc->pid, thread->pid);
3719 proc->pid, thread->pid);
3734 proc->pid, thread->pid,
3745 thread, in_reply_to);
3769 proc->pid, thread->pid);
3792 thread, bp,
3812 proc->pid, thread->pid, hdr->type);
3826 proc->pid, thread->pid);
3837 proc->pid, thread->pid);
3847 binder_enqueue_thread_work(thread, tcomplete);
3872 binder_enqueue_deferred_thread_work_ilocked(thread, tcomplete);
3874 t->from_parent = thread->transaction_stack;
3875 thread->transaction_stack = t;
3882 binder_pop_transaction_ilocked(thread, t);
3889 binder_enqueue_thread_work(thread, tcomplete);
3955 proc->pid, thread->pid, return_error, return_error_param,
3976 BUG_ON(thread->return_error.cmd != BR_OK);
3978 thread->return_error.cmd = BR_TRANSACTION_COMPLETE;
3979 binder_enqueue_thread_work(thread, &thread->return_error.work);
3982 thread->return_error.cmd = return_error;
3983 binder_enqueue_thread_work(thread, &thread->return_error.work);
4000 struct binder_thread *thread,
4029 binder_release_entire_buffer(proc, thread, buffer, is_failure);
4034 struct binder_thread *thread,
4044 while (ptr < end && thread->return_error.cmd == BR_OK) {
4054 atomic_inc(&thread->stats.bc[_IOC_NR(cmd)]);
4079 proc->pid, thread->pid);
4095 proc->pid, thread->pid,
4115 proc->pid, thread->pid, debug_string,
4121 proc->pid, thread->pid, debug_string,
4142 proc->pid, thread->pid,
4151 proc->pid, thread->pid,
4163 proc->pid, thread->pid,
4173 proc->pid, thread->pid,
4186 proc->pid, thread->pid,
4215 proc->pid, thread->pid,
4220 proc->pid, thread->pid,
4227 proc->pid, thread->pid, (u64)data_ptr,
4230 binder_free_buf(proc, thread, buffer, false);
4241 binder_transaction(proc, thread, &tr.transaction_data,
4252 binder_transaction(proc, thread, &tr,
4260 proc->pid, thread->pid);
4262 if (thread->looper & BINDER_LOOPER_STATE_ENTERED) {
4263 thread->looper |= BINDER_LOOPER_STATE_INVALID;
4265 proc->pid, thread->pid);
4267 thread->looper |= BINDER_LOOPER_STATE_INVALID;
4269 proc->pid, thread->pid);
4274 thread->looper |= BINDER_LOOPER_STATE_REGISTERED;
4280 proc->pid, thread->pid);
4281 if (thread->looper & BINDER_LOOPER_STATE_REGISTERED) {
4282 thread->looper |= BINDER_LOOPER_STATE_INVALID;
4284 proc->pid, thread->pid);
4286 thread->looper |= BINDER_LOOPER_STATE_ENTERED;
4291 proc->pid, thread->pid);
4292 thread->looper |= BINDER_LOOPER_STATE_EXITED;
4315 WARN_ON(thread->return_error.cmd !=
4317 thread->return_error.cmd = BR_ERROR;
4319 thread,
4320 &thread->return_error.work);
4324 proc->pid, thread->pid);
4332 proc->pid, thread->pid,
4344 proc->pid, thread->pid,
4356 proc->pid, thread->pid);
4378 proc->pid, thread->pid);
4386 proc->pid, thread->pid,
4397 if (thread->looper &
4401 thread,
4443 proc->pid, thread->pid, (u64)cookie,
4447 proc->pid, thread->pid, (u64)cookie);
4454 if (thread->looper &
4458 thread, &death->work);
4471 proc->pid, thread->pid, cmd);
4480 struct binder_thread *thread, uint32_t cmd)
4486 atomic_inc(&thread->stats.br[_IOC_NR(cmd)]);
4491 struct binder_thread *thread,
4512 binder_stat_br(proc, thread, cmd);
4514 proc->pid, thread->pid, cmd_name, node_debug_id,
4521 static int binder_wait_for_work(struct binder_thread *thread,
4525 struct binder_proc *proc = thread->proc;
4531 prepare_to_wait(&thread->wait, &wait, TASK_INTERRUPTIBLE);
4532 if (binder_has_work_ilocked(thread, do_proc_work))
4535 list_add(&thread->waiting_thread_node,
4540 list_del_init(&thread->waiting_thread_node);
4546 finish_wait(&thread->wait, &wait);
4619 struct binder_thread *thread,
4638 wait_for_proc_work = binder_available_for_proc_work_ilocked(thread);
4641 thread->looper |= BINDER_LOOPER_STATE_WAITING;
4644 !!thread->transaction_stack,
4645 !binder_worklist_empty(proc, &thread->todo));
4647 if (!(thread->looper & (BINDER_LOOPER_STATE_REGISTERED |
4650 proc->pid, thread->pid, thread->looper);
4658 if (!binder_has_work(thread, wait_for_proc_work))
4661 ret = binder_wait_for_work(thread, wait_for_proc_work);
4664 thread->looper &= ~BINDER_LOOPER_STATE_WAITING;
4680 if (!binder_worklist_empty_ilocked(&thread->todo))
4681 list = &thread->todo;
4689 if (ptr - buffer == 4 && !thread->looper_need_return)
4699 if (binder_worklist_empty_ilocked(&thread->todo))
4700 thread->process_todo = false;
4719 binder_stat_br(proc, thread, cmd);
4730 binder_stat_br(proc, thread, cmd);
4733 proc->pid, thread->pid);
4771 proc->pid, thread->pid,
4783 * this thread frees while the other thread
4794 proc, thread, &ptr, node_ptr,
4799 proc, thread, &ptr, node_ptr,
4804 proc, thread, &ptr, node_ptr,
4809 proc, thread, &ptr, node_ptr,
4815 proc->pid, thread->pid,
4838 proc->pid, thread->pid,
4859 binder_stat_br(proc, thread, cmd);
4866 proc->pid, thread->pid, w->type);
4904 binder_inner_proc_lock(thread->proc);
4905 thread->sender_pid_nr = task_tgid_nr(sender);
4906 binder_inner_proc_unlock(thread->proc);
4911 binder_inner_proc_lock(thread->proc);
4912 thread->sender_pid_nr = 0;
4913 binder_inner_proc_unlock(thread->proc);
4928 binder_free_buf(proc, thread, buffer, true);
4931 proc->pid, thread->pid,
4940 binder_stat_br(proc, thread, cmd);
4979 binder_stat_br(proc, thread, cmd);
4982 proc->pid, thread->pid,
4996 binder_inner_proc_lock(thread->proc);
4997 thread->tokens.sender_tokenid = t->sender_tokenid;
4998 thread->tokens.first_tokenid = t->first_tokenid;
4999 binder_inner_proc_unlock(thread->proc);
5002 binder_inner_proc_lock(thread->proc);
5003 t->to_parent = thread->transaction_stack;
5004 t->to_thread = thread;
5005 thread->transaction_stack = t;
5006 binder_inner_proc_unlock(thread->proc);
5018 list_empty(&thread->proc->waiting_threads) &&
5020 (thread->looper & (BINDER_LOOPER_STATE_REGISTERED |
5022 /*spawn a new thread if we leave this out */) {
5027 proc->pid, thread->pid);
5030 binder_stat_br(proc, thread, BR_SPAWN_LOOPER);
5098 struct binder_thread *thread = NULL;
5104 thread = rb_entry(parent, struct binder_thread, rb_node);
5106 if (current->pid < thread->pid)
5108 else if (current->pid > thread->pid)
5111 return thread;
5115 thread = new_thread;
5117 thread->proc = proc;
5118 thread->pid = current->pid;
5119 atomic_set(&thread->tmp_ref, 0);
5120 init_waitqueue_head(&thread->wait);
5121 INIT_LIST_HEAD(&thread->todo);
5122 rb_link_node(&thread->rb_node, parent, p);
5123 rb_insert_color(&thread->rb_node, &proc->threads);
5124 thread->looper_need_return = true;
5125 thread->return_error.work.type = BINDER_WORK_RETURN_ERROR;
5126 thread->return_error.cmd = BR_OK;
5127 thread->reply_error.work.type = BINDER_WORK_RETURN_ERROR;
5128 thread->reply_error.cmd = BR_OK;
5130 return thread;
5135 struct binder_thread *thread;
5139 thread = binder_get_thread_ilocked(proc, NULL);
5141 if (!thread) {
5142 new_thread = kzalloc(sizeof(*thread), GFP_KERNEL);
5146 thread = binder_get_thread_ilocked(proc, new_thread);
5148 if (thread != new_thread)
5151 return thread;
5172 static void binder_free_thread(struct binder_thread *thread)
5174 BUG_ON(!list_empty(&thread->todo));
5176 binder_proc_dec_tmpref(thread->proc);
5177 kfree(thread);
5181 struct binder_thread *thread)
5188 binder_inner_proc_lock(thread->proc);
5191 * after we remove this thread from proc->threads.
5193 * free the thread in binder_free_thread()
5197 * take a ref on this thread to ensure it
5200 atomic_inc(&thread->tmp_ref);
5201 rb_erase(&thread->rb_node, &proc->threads);
5202 t = thread->transaction_stack;
5205 if (t->to_thread == thread)
5210 thread->is_dead = true;
5217 proc->pid, thread->pid,
5219 (t->to_thread == thread) ? "in" : "out");
5221 if (t->to_thread == thread) {
5229 } else if (t->from == thread) {
5248 * If this thread used poll, make sure we remove the waitqueue from any
5251 if (thread->looper & BINDER_LOOPER_STATE_POLL)
5252 wake_up_pollfree(&thread->wait);
5254 binder_inner_proc_unlock(thread->proc);
5263 if (thread->looper & BINDER_LOOPER_STATE_POLL)
5268 binder_release_work(proc, &thread->todo);
5269 binder_thread_dec_tmpref(thread);
5277 struct binder_thread *thread = NULL;
5280 thread = binder_get_thread(proc);
5281 if (!thread)
5284 binder_inner_proc_lock(thread->proc);
5285 thread->looper |= BINDER_LOOPER_STATE_POLL;
5286 wait_for_proc_work = binder_available_for_proc_work_ilocked(thread);
5288 binder_inner_proc_unlock(thread->proc);
5290 poll_wait(filp, &thread->wait, wait);
5292 if (binder_has_work(thread, wait_for_proc_work))
5300 struct binder_thread *thread)
5318 proc->pid, thread->pid,
5323 ret = binder_thread_write(proc, thread,
5336 ret = binder_thread_read(proc, thread, bwr.read_buffer,
5353 proc->pid, thread->pid,
5477 struct binder_thread *thread;
5492 thread = binder_get_thread(proc);
5493 if (thread == NULL) {
5500 ret = binder_ioctl_write_read(filp, cmd, arg, thread);
5536 proc->pid, thread->pid);
5537 binder_thread_release(proc, thread);
5538 thread = NULL;
5614 token = thread->tokens.sender_tokenid;
5615 ftoken = thread->tokens.first_tokenid;
5639 token = thread->tokens.sender_tokenid;
5640 ftoken = thread->tokens.first_tokenid;
5642 sender_pid_nr = thread->sender_pid_nr;
5667 if (thread)
5668 thread->looper_need_return = false;
5847 struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
5849 thread->looper_need_return = true;
5850 if (thread->looper & BINDER_LOOPER_STATE_WAITING) {
5851 wake_up_interruptible(&thread->wait);
5973 struct binder_thread *thread;
5975 thread = rb_entry(n, struct binder_thread, rb_node);
5978 active_transactions += binder_thread_release(proc, thread);
6156 struct binder_thread *thread,
6164 seq_printf(m, " thread %d: l %02x need_return %d tr %d\n",
6165 thread->pid, thread->looper,
6166 thread->looper_need_return,
6167 atomic_read(&thread->tmp_ref));
6169 t = thread->transaction_stack;
6171 if (t->from == thread) {
6172 print_binder_transaction_ilocked(m, thread->proc,
6175 } else if (t->to_thread == thread) {
6176 print_binder_transaction_ilocked(m, thread->proc,
6180 print_binder_transaction_ilocked(m, thread->proc,
6185 list_for_each_entry(w, &thread->todo, entry) {
6186 print_binder_work_ilocked(m, thread->proc, " ",
6347 "thread",
6401 struct binder_thread *thread;
6415 list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node)
6667 struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
6668 struct binder_transaction *t = thread->transaction_stack;
6670 if (t->from == thread) {
6673 } else if (t->to_thread == thread) {
6713 struct binder_thread *thread = NULL;
6721 list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node)