io_thread.c (30df927b936b2ef21eb07dce9c141c7897609643) io_thread.c (f2cce89a074e6d2991dddc94f6b6ebe1576b8459)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* RxRPC packet reception
3 *
4 * Copyright (C) 2007, 2016, 2022 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

--- 407 unchanged lines hidden (view full) ---

416 return 0;
417}
418
419/*
420 * I/O and event handling thread.
421 */
422int rxrpc_io_thread(void *data)
423{
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* RxRPC packet reception
3 *
4 * Copyright (C) 2007, 2016, 2022 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

--- 407 unchanged lines hidden (view full) ---

416 return 0;
417}
418
419/*
420 * I/O and event handling thread.
421 */
422int rxrpc_io_thread(void *data)
423{
424 struct rxrpc_connection *conn;
424 struct sk_buff_head rx_queue;
425 struct rxrpc_local *local = data;
426 struct rxrpc_call *call;
427 struct sk_buff *skb;
428 bool should_stop;
429
430 complete(&local->io_thread_ready);
431
432 skb_queue_head_init(&rx_queue);
433
434 set_user_nice(current, MIN_NICE);
435
436 for (;;) {
437 rxrpc_inc_stat(local->rxnet, stat_io_loop);
438
425 struct sk_buff_head rx_queue;
426 struct rxrpc_local *local = data;
427 struct rxrpc_call *call;
428 struct sk_buff *skb;
429 bool should_stop;
430
431 complete(&local->io_thread_ready);
432
433 skb_queue_head_init(&rx_queue);
434
435 set_user_nice(current, MIN_NICE);
436
437 for (;;) {
438 rxrpc_inc_stat(local->rxnet, stat_io_loop);
439
440 /* Deal with connections that want immediate attention. */
441 conn = list_first_entry_or_null(&local->conn_attend_q,
442 struct rxrpc_connection,
443 attend_link);
444 if (conn) {
445 spin_lock_bh(&local->lock);
446 list_del_init(&conn->attend_link);
447 spin_unlock_bh(&local->lock);
448
449 rxrpc_input_conn_event(conn, NULL);
450 rxrpc_put_connection(conn, rxrpc_conn_put_poke);
451 continue;
452 }
453
439 /* Deal with calls that want immediate attention. */
440 if ((call = list_first_entry_or_null(&local->call_attend_q,
441 struct rxrpc_call,
442 attend_link))) {
443 spin_lock_bh(&local->lock);
444 list_del_init(&call->attend_link);
445 spin_unlock_bh(&local->lock);
446

--- 11 unchanged lines hidden (view full) ---

458 rxrpc_input_packet(local, &skb);
459 trace_rxrpc_rx_done(skb->mark, skb->priority);
460 rxrpc_free_skb(skb, rxrpc_skb_put_input);
461 break;
462 case RXRPC_SKB_MARK_ERROR:
463 rxrpc_input_error(local, skb);
464 rxrpc_free_skb(skb, rxrpc_skb_put_error_report);
465 break;
454 /* Deal with calls that want immediate attention. */
455 if ((call = list_first_entry_or_null(&local->call_attend_q,
456 struct rxrpc_call,
457 attend_link))) {
458 spin_lock_bh(&local->lock);
459 list_del_init(&call->attend_link);
460 spin_unlock_bh(&local->lock);
461

--- 11 unchanged lines hidden (view full) ---

473 rxrpc_input_packet(local, &skb);
474 trace_rxrpc_rx_done(skb->mark, skb->priority);
475 rxrpc_free_skb(skb, rxrpc_skb_put_input);
476 break;
477 case RXRPC_SKB_MARK_ERROR:
478 rxrpc_input_error(local, skb);
479 rxrpc_free_skb(skb, rxrpc_skb_put_error_report);
480 break;
481 break;
466 default:
467 WARN_ON_ONCE(1);
468 rxrpc_free_skb(skb, rxrpc_skb_put_unknown);
469 break;
470 }
471 continue;
472 }
473
474 if (!skb_queue_empty(&local->rx_queue)) {
475 spin_lock_irq(&local->rx_queue.lock);
476 skb_queue_splice_tail_init(&local->rx_queue, &rx_queue);
477 spin_unlock_irq(&local->rx_queue.lock);
478 continue;
479 }
480
481 set_current_state(TASK_INTERRUPTIBLE);
482 should_stop = kthread_should_stop();
483 if (!skb_queue_empty(&local->rx_queue) ||
482 default:
483 WARN_ON_ONCE(1);
484 rxrpc_free_skb(skb, rxrpc_skb_put_unknown);
485 break;
486 }
487 continue;
488 }
489
490 if (!skb_queue_empty(&local->rx_queue)) {
491 spin_lock_irq(&local->rx_queue.lock);
492 skb_queue_splice_tail_init(&local->rx_queue, &rx_queue);
493 spin_unlock_irq(&local->rx_queue.lock);
494 continue;
495 }
496
497 set_current_state(TASK_INTERRUPTIBLE);
498 should_stop = kthread_should_stop();
499 if (!skb_queue_empty(&local->rx_queue) ||
484 !list_empty(&local->call_attend_q)) {
500 !list_empty(&local->call_attend_q) ||
501 !list_empty(&local->conn_attend_q)) {
485 __set_current_state(TASK_RUNNING);
486 continue;
487 }
488
489 if (should_stop)
490 break;
491 schedule();
492 }
493
494 __set_current_state(TASK_RUNNING);
495 rxrpc_see_local(local, rxrpc_local_stop);
496 rxrpc_destroy_local(local);
497 local->io_thread = NULL;
498 rxrpc_see_local(local, rxrpc_local_stopped);
499 return 0;
500}
502 __set_current_state(TASK_RUNNING);
503 continue;
504 }
505
506 if (should_stop)
507 break;
508 schedule();
509 }
510
511 __set_current_state(TASK_RUNNING);
512 rxrpc_see_local(local, rxrpc_local_stop);
513 rxrpc_destroy_local(local);
514 local->io_thread = NULL;
515 rxrpc_see_local(local, rxrpc_local_stopped);
516 return 0;
517}