Multi Threading
Multi Threading
nic device-driver
write()
my_write()
packet buffer
user data-buffer copy_from_user()
hardware
We want to eliminate this copying-operation
Our driver’s packet-layout
TYPE/
destn-address source-address LENGTH
count
-- data --
-- data --
-- data –
packet-buffer in kernel-space
16 bytes
Packet-
base-address (64-bits) length
CSO cmd status CSS special
I V I E
R I F
D L 0 0 C O
S C
E E S P
Key question: What will the NIC do if we don’t set the EOP-bit in a TX Descriptor?
Splitting our packet-layout
TYPE/
destn-address source-address LENGTH
count HDR
-- data --
-- data -- LEN
-- data –
packet-buffer in kernel-space
Packet-
base-address (64-bits) Length CSO cmd status CSS special
EOP=0
(=HDR)
Packet-
base-address (64-bits) Length CSO cmd status CSS special
EOP=1
(=LEN)
packet-buffer in kernel-space
-- data --
-- data --
LEN
-- data –
packet-buffer in user-space
Packet-
base-address (64-bits) Length CSO cmd status CSS special
EOP=0
(=HDR)
Packet-
base-address (64-bits) Length CSO cmd status CSS special
EOP=1
(=LEN)
User-space
Kernel-space
packet-header buffer
DMA
NIC hardware
The ‘virt_to_phys()’ macro
• Linux provides a convenient macro which
kernel-module code can employ to obtain
the physical-address for a memory-region
from its virtual-address – but it only works
for addresses that aren’t in ‘high’ memory
• For ‘normal’ memory-regions, conversion
between ‘virtual’ and ‘physical’ addresses
amounts to a simple addition/subtraction
Linux memory-mapping
= persistent mapping
= transient mappings
HMA
kernel
space
896-MB
user
physical RAM space
CR3
Linear to Physical
linear address
dir-index physical address-space
table-index offset
page
table
page frame
page
directory
CR3
Address-translation
• The CPU examines any virtual address it
encounters, subdividing it into three fields
31 22 21 12 11 0
LEGEND
P = Present (1=yes, 0=no)
W = Writable (1 = yes, 0 = no)
U = User (1 = yes, 0 = no)
A = Accessed (1 = yes, 0 = no)
D = Dirty (1 = yes, 0 = no)
offset len
buf