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
473 * binder_enqueue_deferred_thread_work_ilocked() - Add deferred thread work
474 * @thread: thread to queue work to
477 * Adds the work to the todo list of the thread. Doesn't set the process_todo
478 * flag, which means that (if it wasn't already set) the thread will go to
484 binder_enqueue_deferred_thread_work_ilocked(struct binder_thread *thread,
487 WARN_ON(!list_empty(&thread->waiting_thread_node));
488 binder_enqueue_work_ilocked(work, &thread->todo);
492 * binder_enqueue_thread_work_ilocked() - Add an item to the thread work list
493 * @thread: thread to queue work to
496 * Adds the work to the todo list of the thread, and enables processing
502 binder_enqueue_thread_work_ilocked(struct binder_thread *thread,
505 WARN_ON(!list_empty(&thread->waiting_thread_node));
506 binder_enqueue_work_ilocked(work, &thread->todo);
513 if (thread->looper & BINDER_LOOPER_STATE_POLL &&
514 thread->pid == current->pid && !thread->process_todo)
515 wake_up_interruptible_sync(&thread->wait);
517 thread->process_todo = true;
521 * binder_enqueue_thread_work() - Add an item to the thread work list
522 * @thread: thread to queue work to
525 * Adds the work to the todo list of the thread, and enables processing
529 binder_enqueue_thread_work(struct binder_thread *thread,
532 binder_inner_proc_lock(thread->proc);
533 binder_enqueue_thread_work_ilocked(thread, work);
534 binder_inner_proc_unlock(thread->proc);
572 static void binder_free_thread(struct binder_thread *thread);
586 static bool binder_has_work_ilocked(struct binder_thread *thread,
589 return thread->process_todo ||
590 thread->looper_need_return ||
592 !binder_worklist_empty_ilocked(&thread->proc->todo));
595 static bool binder_has_work(struct binder_thread *thread, bool do_proc_work)
599 binder_inner_proc_lock(thread->proc);
600 has_work = binder_has_work_ilocked(thread, do_proc_work);
601 binder_inner_proc_unlock(thread->proc);
606 static bool binder_available_for_proc_work_ilocked(struct binder_thread *thread)
608 return !thread->transaction_stack &&
609 binder_worklist_empty_ilocked(&thread->todo) &&
610 (thread->looper & (BINDER_LOOPER_STATE_ENTERED |
618 struct binder_thread *thread;
621 thread = rb_entry(n, struct binder_thread, rb_node);
622 if (thread->looper & BINDER_LOOPER_STATE_POLL &&
623 binder_available_for_proc_work_ilocked(thread)) {
625 wake_up_interruptible_sync(&thread->wait);
627 wake_up_interruptible(&thread->wait);
633 * binder_select_thread_ilocked() - selects a thread for doing proc work.
634 * @proc: process to select a thread from
636 * Note that calling this function moves the thread off the waiting_threads
638 * signal. Therefore, callers *should* always wake up the thread this function
641 * Return: If there's a thread currently waiting for process work,
642 * returns that thread. Otherwise returns NULL.
647 struct binder_thread *thread;
650 thread = list_first_entry_or_null(&proc->waiting_threads,
654 if (thread)
655 list_del_init(&thread->waiting_thread_node);
657 return thread;
661 * binder_wakeup_thread_ilocked() - wakes up a thread for doing proc work.
662 * @proc: process to wake up a thread in
663 * @thread: specific thread to wake-up (may be NULL)
666 * This function wakes up a thread in the @proc process.
667 * The caller may provide a specific thread to wake-up in
668 * the @thread parameter. If @thread is NULL, this function
672 * should first call binder_select_thread() to find a thread
673 * to handle the work (if they don't have a thread already),
674 * and pass the result into the @thread parameter.
677 struct binder_thread *thread,
682 if (thread) {
684 wake_up_interruptible_sync(&thread->wait);
686 wake_up_interruptible(&thread->wait);
690 /* Didn't find a thread waiting for proc work; this can happen
700 * a thread that called into (e)poll is handling non-binder
708 struct binder_thread *thread = binder_select_thread_ilocked(proc);
710 binder_wakeup_thread_ilocked(proc, thread, /* sync = */false);
840 * The node was already added by another thread
877 struct binder_thread *thread = container_of(target_list,
880 BUG_ON(&thread->todo != target_list);
881 binder_enqueue_deferred_thread_work_ilocked(thread,
1096 * Return: the ref for node. It is possible that another thread
1450 * Another thread created the ref first so
1470 * binder_thread_dec_tmpref() - decrement thread->tmp_ref
1471 * @thread: thread to decrement
1473 * A thread needs to be kept alive while being used to create or
1475 * extract t->from from a binder_transaction and keep the thread
1478 * tmp_ref and free if appropriate (thread has been released
1481 static void binder_thread_dec_tmpref(struct binder_thread *thread)
1485 * it cannot reach zero or thread->is_dead is false
1487 binder_inner_proc_lock(thread->proc);
1488 atomic_dec(&thread->tmp_ref);
1489 if (thread->is_dead && !atomic_read(&thread->tmp_ref)) {
1490 binder_inner_proc_unlock(thread->proc);
1491 binder_free_thread(thread);
1494 binder_inner_proc_unlock(thread->proc);
1523 * binder_get_txn_from() - safely extract the "from" thread in transaction
1526 * Atomically return the "from" thread and increment the tmp_ref
1527 * count for the thread to ensure it stays alive until
1550 * to guarantee that the thread cannot be released while operating on it.
1690 "reply failed, no target thread at root\n");
1695 "reply failed, no target thread -- retry %d\n",
1982 struct binder_thread *thread,
2143 * Need to make sure the thread goes
2147 if (thread)
2148 thread->looper_need_return = true;
2162 struct binder_thread *thread,
2171 binder_transaction_buffer_release(proc, thread, buffer,
2177 struct binder_thread *thread)
2180 struct binder_proc *proc = thread->proc;
2193 proc->pid, thread->pid, (u64)fp->binder,
2206 &thread->todo, &rdata);
2230 struct binder_thread *thread)
2232 struct binder_proc *proc = thread->proc;
2242 proc->pid, thread->pid, fp->handle);
2303 struct binder_thread *thread,
2306 struct binder_proc *proc = thread->proc;
2319 proc->pid, thread->pid,
2329 proc->pid, thread->pid, fd);
2342 * target thread.
2614 struct binder_thread *thread,
2620 struct binder_proc *proc = thread->proc;
2629 proc->pid, thread->pid, (u64)fda->num_fds);
2636 proc->pid, thread->pid, (u64)fda->num_fds);
2654 proc->pid, thread->pid);
2668 ret = binder_translate_fd(fd, offset, t, thread,
2678 struct binder_thread *thread,
2687 struct binder_proc *proc = thread->proc;
2701 proc->pid, thread->pid);
2710 proc->pid, thread->pid);
2718 proc->pid, thread->pid);
2780 * @thread: thread in @proc to send the transaction to (may be NULL)
2783 * to find a thread in the target process to handle the transaction and
2784 * wake it up. If no thread is found, the work is queued to the proc
2787 * If the @thread parameter is not NULL, the transaction is always queued
2788 * to the waitlist of that specific thread.
2791 * BR_DEAD_REPLY if the target process or thread is dead
2792 * BR_FROZEN_REPLY if the target process or thread is frozen and
2799 struct binder_thread *thread)
2810 BUG_ON(thread);
2825 (thread && thread->is_dead)) {
2831 if (!thread && !pending_async)
2832 thread = binder_select_thread_ilocked(proc);
2834 if (thread) {
2835 binder_enqueue_thread_work_ilocked(thread, &t->work);
2854 binder_wakeup_thread_ilocked(proc, thread, !oneway /* sync */);
2943 struct binder_thread *thread,
2982 e->from_thread = thread->pid;
2989 binder_set_extended_error(&thread->ee, t_debug_id, BR_OK, 0);
2994 in_reply_to = thread->transaction_stack;
2998 proc->pid, thread->pid);
3004 if (in_reply_to->to_thread != thread) {
3007 proc->pid, thread->pid, in_reply_to->debug_id,
3020 thread->transaction_stack = in_reply_to->to_parent;
3028 thread->pid, proc->pid);
3035 proc->pid, thread->pid,
3070 proc->pid, thread->pid, tr->target.handle);
3086 proc->pid, thread->pid);
3095 thread->pid, proc->pid);
3106 thread->pid, proc->pid);
3115 thread->pid, proc->pid);
3123 w = list_first_entry_or_null(&thread->todo,
3129 * thread that has a transaction at the head of
3132 * thread from proc->waiting_threads to enqueue
3134 * todo list while the thread is on waiting_threads.
3136 binder_user_error("%d:%d new transaction not allowed when there is a transaction on thread todo\n",
3137 proc->pid, thread->pid);
3145 if (!(tr->flags & TF_ONE_WAY) && thread->transaction_stack) {
3148 tmp = thread->transaction_stack;
3149 if (tmp->to_thread != thread) {
3152 proc->pid, thread->pid, tmp->debug_id,
3188 thread->pid, proc->pid);
3201 thread->pid, proc->pid);
3215 proc->pid, thread->pid, t->debug_id,
3224 proc->pid, thread->pid, t->debug_id,
3232 t->from = thread;
3240 t->from_pid = thread->proc->pid;
3241 t->from_tid = thread->pid;
3264 thread->pid, proc->pid);
3274 thread->pid, proc->pid);
3336 proc->pid, thread->pid);
3344 proc->pid, thread->pid, (u64)tr->offsets_size);
3352 proc->pid, thread->pid,
3380 thread->pid, proc->pid);
3399 proc->pid, thread->pid);
3409 proc->pid, thread->pid,
3432 ret = binder_translate_binder(fp, t, thread);
3440 thread->pid, proc->pid);
3452 ret = binder_translate_handle(fp, t, thread);
3459 thread->pid, proc->pid);
3472 thread, in_reply_to);
3481 thread->pid, proc->pid);
3505 proc->pid, thread->pid);
3518 proc->pid, thread->pid);
3533 proc->pid, thread->pid,
3544 thread, in_reply_to);
3552 thread->pid, proc->pid);
3570 proc->pid, thread->pid);
3581 thread->pid, proc->pid);
3595 thread, bp,
3606 thread->pid, proc->pid);
3617 proc->pid, thread->pid, hdr->type);
3631 proc->pid, thread->pid);
3642 proc->pid, thread->pid);
3655 binder_enqueue_thread_work(thread, tcomplete);
3682 binder_enqueue_deferred_thread_work_ilocked(thread, tcomplete);
3684 t->from_parent = thread->transaction_stack;
3685 thread->transaction_stack = t;
3694 binder_pop_transaction_ilocked(thread, t);
3712 binder_enqueue_thread_work(thread, tcomplete);
3731 binder_txn_error("%d:%d dead process or thread\n",
3732 thread->pid, proc->pid);
3775 proc->pid, thread->pid, reply ? "reply" :
3805 BUG_ON(thread->return_error.cmd != BR_OK);
3809 thread->return_error.cmd = BR_TRANSACTION_COMPLETE;
3810 binder_enqueue_thread_work(thread, &thread->return_error.work);
3814 binder_set_extended_error(&thread->ee, t_debug_id,
3817 thread->return_error.cmd = return_error;
3818 binder_enqueue_thread_work(thread, &thread->return_error.work);
3835 struct binder_thread *thread,
3864 binder_release_entire_buffer(proc, thread, buffer, is_failure);
3869 struct binder_thread *thread,
3879 while (ptr < end && thread->return_error.cmd == BR_OK) {
3889 atomic_inc(&thread->stats.bc[_IOC_NR(cmd)]);
3915 proc->pid, thread->pid);
3931 proc->pid, thread->pid,
3951 proc->pid, thread->pid, debug_string,
3957 proc->pid, thread->pid, debug_string,
3978 proc->pid, thread->pid,
3987 proc->pid, thread->pid,
3999 proc->pid, thread->pid,
4009 proc->pid, thread->pid,
4022 proc->pid, thread->pid,
4051 proc->pid, thread->pid,
4056 proc->pid, thread->pid,
4063 proc->pid, thread->pid, (u64)data_ptr,
4066 binder_free_buf(proc, thread, buffer, false);
4077 binder_transaction(proc, thread, &tr.transaction_data,
4088 binder_transaction(proc, thread, &tr,
4096 proc->pid, thread->pid);
4098 if (thread->looper & BINDER_LOOPER_STATE_ENTERED) {
4099 thread->looper |= BINDER_LOOPER_STATE_INVALID;
4101 proc->pid, thread->pid);
4103 thread->looper |= BINDER_LOOPER_STATE_INVALID;
4105 proc->pid, thread->pid);
4110 thread->looper |= BINDER_LOOPER_STATE_REGISTERED;
4116 proc->pid, thread->pid);
4117 if (thread->looper & BINDER_LOOPER_STATE_REGISTERED) {
4118 thread->looper |= BINDER_LOOPER_STATE_INVALID;
4120 proc->pid, thread->pid);
4122 thread->looper |= BINDER_LOOPER_STATE_ENTERED;
4127 proc->pid, thread->pid);
4128 thread->looper |= BINDER_LOOPER_STATE_EXITED;
4151 WARN_ON(thread->return_error.cmd !=
4153 thread->return_error.cmd = BR_ERROR;
4155 thread,
4156 &thread->return_error.work);
4160 proc->pid, thread->pid);
4168 proc->pid, thread->pid,
4180 proc->pid, thread->pid,
4192 proc->pid, thread->pid);
4214 proc->pid, thread->pid);
4222 proc->pid, thread->pid,
4233 if (thread->looper &
4237 thread,
4279 proc->pid, thread->pid, (u64)cookie,
4283 proc->pid, thread->pid, (u64)cookie);
4290 if (thread->looper &
4294 thread, &death->work);
4307 proc->pid, thread->pid, cmd);
4316 struct binder_thread *thread, uint32_t cmd)
4322 atomic_inc(&thread->stats.br[_IOC_NR(cmd)]);
4327 struct binder_thread *thread,
4348 binder_stat_br(proc, thread, cmd);
4350 proc->pid, thread->pid, cmd_name, node_debug_id,
4357 static int binder_wait_for_work(struct binder_thread *thread,
4361 struct binder_proc *proc = thread->proc;
4366 prepare_to_wait(&thread->wait, &wait, TASK_INTERRUPTIBLE|TASK_FREEZABLE);
4367 if (binder_has_work_ilocked(thread, do_proc_work))
4370 list_add(&thread->waiting_thread_node,
4375 list_del_init(&thread->waiting_thread_node);
4381 finish_wait(&thread->wait, &wait);
4442 struct binder_thread *thread,
4461 wait_for_proc_work = binder_available_for_proc_work_ilocked(thread);
4464 thread->looper |= BINDER_LOOPER_STATE_WAITING;
4467 !!thread->transaction_stack,
4468 !binder_worklist_empty(proc, &thread->todo));
4470 if (!(thread->looper & (BINDER_LOOPER_STATE_REGISTERED |
4473 proc->pid, thread->pid, thread->looper);
4481 if (!binder_has_work(thread, wait_for_proc_work))
4484 ret = binder_wait_for_work(thread, wait_for_proc_work);
4487 thread->looper &= ~BINDER_LOOPER_STATE_WAITING;
4503 if (!binder_worklist_empty_ilocked(&thread->todo))
4504 list = &thread->todo;
4512 if (ptr - buffer == 4 && !thread->looper_need_return)
4522 if (binder_worklist_empty_ilocked(&thread->todo))
4523 thread->process_todo = false;
4542 binder_stat_br(proc, thread, cmd);
4561 binder_stat_br(proc, thread, cmd);
4564 proc->pid, thread->pid);
4602 proc->pid, thread->pid,
4614 * this thread frees while the other thread
4625 proc, thread, &ptr, node_ptr,
4630 proc, thread, &ptr, node_ptr,
4635 proc, thread, &ptr, node_ptr,
4640 proc, thread, &ptr, node_ptr,
4646 proc->pid, thread->pid,
4669 proc->pid, thread->pid,
4690 binder_stat_br(proc, thread, cmd);
4697 proc->pid, thread->pid, w->type);
4735 binder_inner_proc_lock(thread->proc);
4736 thread->sender_pid_nr = task_tgid_nr(sender);
4737 binder_inner_proc_unlock(thread->proc);
4742 binder_inner_proc_lock(thread->proc);
4743 thread->sender_pid_nr = 0;
4744 binder_inner_proc_unlock(thread->proc);
4759 binder_free_buf(proc, thread, buffer, true);
4762 proc->pid, thread->pid,
4771 binder_stat_br(proc, thread, cmd);
4810 binder_stat_br(proc, thread, cmd);
4813 proc->pid, thread->pid,
4827 binder_inner_proc_lock(thread->proc);
4828 thread->tokens.sender_tokenid = t->sender_tokenid;
4829 thread->tokens.first_tokenid = t->first_tokenid;
4830 binder_inner_proc_unlock(thread->proc);
4833 binder_inner_proc_lock(thread->proc);
4834 t->to_parent = thread->transaction_stack;
4835 t->to_thread = thread;
4836 thread->transaction_stack = t;
4837 binder_inner_proc_unlock(thread->proc);
4849 list_empty(&thread->proc->waiting_threads) &&
4851 (thread->looper & (BINDER_LOOPER_STATE_REGISTERED |
4853 /*spawn a new thread if we leave this out */) {
4858 proc->pid, thread->pid);
4861 binder_stat_br(proc, thread, BR_SPAWN_LOOPER);
4931 struct binder_thread *thread = NULL;
4937 thread = rb_entry(parent, struct binder_thread, rb_node);
4939 if (current->pid < thread->pid)
4941 else if (current->pid > thread->pid)
4944 return thread;
4948 thread = new_thread;
4950 thread->proc = proc;
4951 thread->pid = current->pid;
4952 atomic_set(&thread->tmp_ref, 0);
4953 init_waitqueue_head(&thread->wait);
4954 INIT_LIST_HEAD(&thread->todo);
4955 rb_link_node(&thread->rb_node, parent, p);
4956 rb_insert_color(&thread->rb_node, &proc->threads);
4957 thread->looper_need_return = true;
4958 thread->return_error.work.type = BINDER_WORK_RETURN_ERROR;
4959 thread->return_error.cmd = BR_OK;
4960 thread->reply_error.work.type = BINDER_WORK_RETURN_ERROR;
4961 thread->reply_error.cmd = BR_OK;
4962 thread->ee.command = BR_OK;
4964 return thread;
4969 struct binder_thread *thread;
4973 thread = binder_get_thread_ilocked(proc, NULL);
4975 if (!thread) {
4976 new_thread = kzalloc(sizeof(*thread), GFP_KERNEL);
4980 thread = binder_get_thread_ilocked(proc, new_thread);
4982 if (thread != new_thread)
4985 return thread;
5009 static void binder_free_thread(struct binder_thread *thread)
5011 BUG_ON(!list_empty(&thread->todo));
5013 binder_proc_dec_tmpref(thread->proc);
5014 kfree(thread);
5018 struct binder_thread *thread)
5025 binder_inner_proc_lock(thread->proc);
5028 * after we remove this thread from proc->threads.
5030 * free the thread in binder_free_thread()
5034 * take a ref on this thread to ensure it
5037 atomic_inc(&thread->tmp_ref);
5038 rb_erase(&thread->rb_node, &proc->threads);
5039 t = thread->transaction_stack;
5042 if (t->to_thread == thread)
5047 thread->is_dead = true;
5054 proc->pid, thread->pid,
5056 (t->to_thread == thread) ? "in" : "out");
5058 if (t->to_thread == thread) {
5059 thread->proc->outstanding_txns--;
5067 } else if (t->from == thread) {
5086 * If this thread used poll, make sure we remove the waitqueue from any
5089 if (thread->looper & BINDER_LOOPER_STATE_POLL)
5090 wake_up_pollfree(&thread->wait);
5092 binder_inner_proc_unlock(thread->proc);
5101 if (thread->looper & BINDER_LOOPER_STATE_POLL)
5106 binder_release_work(proc, &thread->todo);
5107 binder_thread_dec_tmpref(thread);
5115 struct binder_thread *thread = NULL;
5118 thread = binder_get_thread(proc);
5119 if (!thread)
5122 binder_inner_proc_lock(thread->proc);
5123 thread->looper |= BINDER_LOOPER_STATE_POLL;
5124 wait_for_proc_work = binder_available_for_proc_work_ilocked(thread);
5126 binder_inner_proc_unlock(thread->proc);
5128 poll_wait(filp, &thread->wait, wait);
5130 if (binder_has_work(thread, wait_for_proc_work))
5138 struct binder_thread *thread)
5157 proc->pid, thread->pid,
5162 ret = binder_thread_write(proc, thread,
5175 ret = binder_thread_read(proc, thread, bwr.read_buffer,
5192 proc->pid, thread->pid,
5315 struct binder_thread *thread;
5321 thread = rb_entry(n, struct binder_thread, rb_node);
5322 if (thread->transaction_stack)
5406 static int binder_ioctl_get_extended_error(struct binder_thread *thread,
5411 binder_inner_proc_lock(thread->proc);
5412 ee = thread->ee;
5413 binder_set_extended_error(&thread->ee, 0, BR_OK, 0);
5414 binder_inner_proc_unlock(thread->proc);
5426 struct binder_thread *thread;
5441 thread = binder_get_thread(proc);
5442 if (thread == NULL) {
5449 ret = binder_ioctl_write_read(filp, cmd, arg, thread);
5485 proc->pid, thread->pid);
5486 binder_thread_release(proc, thread);
5487 thread = NULL;
5631 ret = binder_ioctl_get_extended_error(thread, ubuf);
5658 token = thread->tokens.sender_tokenid;
5659 ftoken = thread->tokens.first_tokenid;
5683 token = thread->tokens.sender_tokenid;
5684 ftoken = thread->tokens.first_tokenid;
5686 sender_pid_nr = thread->sender_pid_nr;
5711 if (thread)
5712 thread->looper_need_return = false;
5891 struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
5893 thread->looper_need_return = true;
5894 if (thread->looper & BINDER_LOOPER_STATE_WAITING) {
5895 wake_up_interruptible(&thread->wait);
6020 struct binder_thread *thread;
6022 thread = rb_entry(n, struct binder_thread, rb_node);
6025 active_transactions += binder_thread_release(proc, thread);
6205 struct binder_thread *thread,
6213 seq_printf(m, " thread %d: l %02x need_return %d tr %d\n",
6214 thread->pid, thread->looper,
6215 thread->looper_need_return,
6216 atomic_read(&thread->tmp_ref));
6218 t = thread->transaction_stack;
6220 if (t->from == thread) {
6221 print_binder_transaction_ilocked(m, thread->proc,
6224 } else if (t->to_thread == thread) {
6225 print_binder_transaction_ilocked(m, thread->proc,
6229 print_binder_transaction_ilocked(m, thread->proc,
6234 list_for_each_entry(w, &thread->todo, entry) {
6235 print_binder_work_ilocked(m, thread->proc, " ",
6399 "thread",
6453 struct binder_thread *thread;
6467 list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node)
6756 struct binder_thread *thread = rb_entry(n, struct binder_thread, rb_node);
6757 struct binder_transaction *t = thread->transaction_stack;
6759 if (t->from == thread) {
6762 } else if (t->to_thread == thread) {
6802 struct binder_thread *thread = NULL;
6810 list_for_each_entry(thread, &proc->waiting_threads, waiting_thread_node)