* Worklist routines **********************************************************************/ * Pick a node off the list of nodes with work, * try get an item to process off it. Remove the node from the list. */
| 3425 | * try get an item to process off it. Remove the node from the list. |
| 3426 | */ |
| 3427 | static void |
| 3428 | ngthread(void *arg) |
| 3429 | { |
| 3430 | for (;;) { |
| 3431 | struct epoch_tracker et; |
| 3432 | node_p node; |
| 3433 | |
| 3434 | /* Get node from the worklist. */ |
| 3435 | NG_WORKLIST_LOCK(); |
| 3436 | while ((node = STAILQ_FIRST(&ng_worklist)) == NULL) |
| 3437 | NG_WORKLIST_SLEEP(); |
| 3438 | STAILQ_REMOVE_HEAD(&ng_worklist, nd_input_queue.q_work); |
| 3439 | NG_WORKLIST_UNLOCK(); |
| 3440 | CURVNET_SET(node->nd_vnet); |
| 3441 | CTR3(KTR_NET, "%20s: node [%x] (%p) taken off worklist", |
| 3442 | __func__, node->nd_ID, node); |
| 3443 | /* |
| 3444 | * We have the node. We also take over the reference |
| 3445 | * that the list had on it. |
| 3446 | * Now process as much as you can, until it won't |
| 3447 | * let you have another item off the queue. |
| 3448 | * All this time, keep the reference |
| 3449 | * that lets us be sure that the node still exists. |
| 3450 | * Let the reference go at the last minute. |
| 3451 | */ |
| 3452 | NET_EPOCH_ENTER(et); |
| 3453 | for (;;) { |
| 3454 | item_p item; |
| 3455 | int rw; |
| 3456 | |
| 3457 | NG_QUEUE_LOCK(&node->nd_input_queue); |
| 3458 | item = ng_dequeue(node, &rw); |
| 3459 | if (item == NULL) { |
| 3460 | node->nd_input_queue.q_flags2 &= ~NGQ2_WORKQ; |
| 3461 | NG_QUEUE_UNLOCK(&node->nd_input_queue); |
| 3462 | break; /* go look for another node */ |
| 3463 | } else { |
| 3464 | NG_QUEUE_UNLOCK(&node->nd_input_queue); |
| 3465 | NGI_GET_NODE(item, node); /* zaps stored node */ |
| 3466 | ng_apply_item(node, item, rw); |
| 3467 | NG_NODE_UNREF(node); |
| 3468 | } |
| 3469 | } |
| 3470 | NET_EPOCH_EXIT(et); |
| 3471 | NG_NODE_UNREF(node); |
| 3472 | CURVNET_RESTORE(); |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | /* |
| 3477 | * XXX |
nothing calls this directly
no test coverage detected