Explain recent advancements better.
[cascardo/kernel/slides/.git] / 15net / net
1 %Network Subsystem
2 %Thadeu Cascardo
3
4 # Socket Buffers
5
6 * include linux/skbuff.h
7 * struct sk\\_buff
8         - struct net\\_device *dev
9 * alloc\\_skb(len, gfp)
10 * dev\\_alloc\\_skb(len) - uses ATOMIC, reserves PAD
11 * netdev\\_alloc\\_skb(netdev, len) - uses ATOMIC, since 2.6.18
12 * kfree\\_skb, dev\\_kfree\\_skb
13
14 # Diagram
15
16 * head - start of allocated buffer
17 * end - end of allocated buffer
18 * data - start of data, giving space after headroom
19 * tail - end of used space
20 * headroom - space between head and data
21 * tailroom - space between tail and end
22
23 # Socket Buffers operations
24
25 * skb\\_put(skb, len) - adds data to end of skb
26 * skb\\_push(skb, len) - adds data to start of skb
27 * skb\\_pull(skb, len) - allocates headroom
28 * skb\\_headroom and skb\\_tailroom
29 * skb\\_reserve - only allowed for empty buffer, reserves headroom
30 * skb\\_orphan - release it from its socket holder
31
32 # Network Device
33
34 * include linux/netdevice.h
35 * struct net\\_device
36         - char name[]
37         - features
38         - stats
39         - netdev\\_ops
40         - ethtool\\_ops
41         - header\\_ops
42         - flags
43         - mtu
44         - type
45         - hard\\_header\\_len
46
47 # Network Device Setup
48
49 * alloc\\_netdev(szpriv, name, setup)
50 * setup function
51 * include linux/etherdevice.h
52 * ether\\_setup
53 * alloc\\_etherdev
54 * register\\_netdev
55 * unregister\\_netdev
56 * free\\_netdev
57
58 # Network Device Operations
59
60 * struct net\\_device\\_ops
61 * ndo\\_init
62 * ndo\\_open
63         - should call netif\\_start\\_queue
64 * ndo\\_stop
65         - should call netif\\_stop\\_queue
66
67 # Network Device Address
68
69 * struct net\\_device
70         - dev\\_addr
71 * random\\_ether\\_addr
72 * struct net\\_device\\_ops
73         - ndo\\_set\\_mac\\_address
74 * eth\\_mac\\_addr
75
76 # Transmission
77
78 * ndo\\_start\\_xmit
79 * Called with softirqs disabled or in softirq context
80 * Called with a held lock
81
82 # Limits on transmission
83
84 * When TX buffers are full, xmit may call netif\\_stop\\_queue
85 * Should arrange to get netif\\_wake\\_queue called after TX buffers are free
86   again
87
88 # Transmission timeout
89
90 * Transmission may timeout after queue has been stopped
91 * Current code already updates last time packet was transmitted
92 * Driver should set watchdog\\_timeo and ndo\\_tx\\_timeout
93
94 # Reception
95
96 * Usually happens in an interrupt handler
97 * Driver allocates skb: some drivers allocate it when setting up and arrange the
98   device to write into the buffers directly
99 * Must set skb field protocol: easily done for ethernet drivers with
100   eth\\_type\\_trans
101 * Finally, call netif\\_rx
102
103 # NAPI
104
105 * To allow more performance, NAPI introduces polling, avoiding too much
106   interrupts when load is high
107 * Driver disables interrupts and enables polling in its interrupt handler
108   when RX happens
109 * Network subsystem uses a softirq to do the polling
110 * The driver poll function disables polling and reenabled interrupts when it's
111   done with its hardware queue
112
113 # NAPI
114
115 * struct napi\\_struct
116 * netif\\_napi\\_add(dev, napi, poll\\_func, weight)
117 * napi\\_enable: called in open
118 * napi\\_disable: called in stop - awaits completion
119 * napi\\_schedule
120         - napi\\_schedule\\_prep
121         - \\_\\_napi\\_schedule
122 * napi\\_complete: called in poll when all is done
123 * Use netif\\_receive\\_skb instead of netif\\_rx
124
125 # NAPI step by step
126
127 * In the interrupt handler:
128         - Checks that the interrupt received is RX
129         - Call napi\\_schedule\\_prep to check that napi isn't already scheduled
130         - Disable RX
131         - Call \\_\\_napi\\_schedule
132
133 # Weight and Budget
134
135 * The weight is the start budget for the interface, usually 16
136 * The poll function must not dequeue more frames than the budget
137 * It must call napi\\_complete if and only if it has exhausted the hardware
138   queues with less than the budget
139 * It must return the number of entries in the queue processed
140
141 # Changes in net device
142
143 * Use netdev\\_priv, no priv anymore
144 * struct net\\_device\\_ops introduced in 2.6.29, with compatibility provided
145   for drivers
146 * Compatibility removed in 2.6.31
147 * netdev\\_tx\\_t: NETDEV\\_TX\\_OK, NETDEV\\_TX\\_BUSY, NETDEV\\_TX\\_LOCKED
148
149 # Other recent changes
150
151 * Some members moved to netdev\\_queue to increase cache-line usage
152 * GRO/GSO - Handle hardware checksum acceleration
153 * Multi-queue support, for devices with multiple queues, so they can be handled
154   in different CPUs
155 * RPS - Receive Packet Steering, which distributes protocol processing amongst
156   multiple CPUs in case of a single device, single queue system
157 * RFS - Receive Flow Steering, which tries to handle the packet in the CPU where
158   the application is running