Wallace
Wallace

Reputation: 651

What Kernel Threads are Responsible For Sending Network Packets in the Linux Kernel

I am reading the source code of Linux kernel trying to figure out how the Linux kernel sends the network packets, after many hours, I can only see the flow of network packets walking through TCP Layer, IP Layer and finally Datalink Layer, I can't find out which threads are doing these jobs.

My question is which kernel threads are responsible for sending network packets and where are they? (Since we can set a socket as non-blocking and let a user application to send network packets as fast as possible, so when the network is busy there must be some queues to buffer these packets, and there must be some kernel threads running someplace sending these packets. )

Upvotes: 2

Views: 2436

Answers (2)

Xuesen Liang
Xuesen Liang

Reputation: 11

The recv procedure:

  1. network chip recv data from wire

  2. network chip put data into kernel's RingBuffer memory by DMA

  3. network chip send hardware IRQ to cpu

  4. cpu handle the top half of the IRQ, which is very fast, then generate a soft IRQ to ksoftirqd

  5. kernel thread ksoftirqd close the hardware IRQ, then handle the bottom half of the soft IRQ

    5.1 ksoftirqd thread execute network driver's igb_poll() function, which take data from RingBuffer, then transfer through the tcp/ip stack. i.e., ip_rcv() -> tcp_rcv()..., finally put the data to socket buffer.

    5.2 ksoftirqd's work is done

  6. user thread take data from the its socket buffer.

The send procedure:

Most work is handled by user thread in kernel state. If user thread is resched, then the ksoftirqd thread do the remain work.

Upvotes: 1

CL.
CL.

Reputation: 180060

By default, the kernel does not use threads to send network packets.

Good network chips manage a packet queue in hardware. Cheaper chips have a fixed-length queue or no queue at all, and raise an interrupt when a packet has been transmitted; the kernel then enqueues or submits the next packet from its own queue from the interrupt handler.

The softirq for this is called NET_TX_SOFTIRQ (see net/core/dev.c). If the kernel is under heavy load or configured to move work out of interrupts, the ksoftirq/* threads handle softirqs.

Upvotes: 3

Related Questions