DSASȯԤ:xv6˥ͥåȥǽ
2020ǯ0403

xv6˥ͥåȥǽ

ϤƤʥ֥åޡϿ

̳˰ܹԤƤ1Ⱦۤɷвᤷޤ̶ФȤǰǤǸ椫ưǤ褦ˤʤä @pandax381 Ǥ

ե륹åǼ TCP/IP ץȥ륹å xv6 Ȥ߹ߡ̤εǽư褦ˤʤޤ

а

줳78ǯ餤ФĤǤɡ饤եȤƤٶѤTCP/IPץȥ륹åγȯۤܤ³Ƥޤ

Ūˡץȥ륹åOSεǽΰȤƥͥ¸ߤƤΤǤμץȥ륹åϡ䤹Ż뤷Թǥ桼֤ΥץꥱѤΥ饤֥ȤƼƤޤ

microps-01

Dzؤ˰֤󥯥٥Ϥ PF_PACKET / BPF / TAP Ѥ뤪ڻͤǡ˥ѥåȽǰǤ褦ˤʤäƤޤ

microps-02

꤬Ƥʬ⤢ޤEthernetե졼TCPȤΤޤƤǽƤޤ֥ץȥ륹åäƤɤʺˤʤäƤפȶ̣äͤФʷϵϤΤ٤餤Υܥ塼ˤʤäƤ󤸤ʤȻפޤ

ʪǥХ󥿥եݲȤʤ˺ǤΤạ̇̄ä饳ɸƤ

ǯ󥿡󥷥åפ˾Ƥơδĥˤä DHCP饤ȵǽѥåžǽˤDPDKݡȤȤäɤä줤ޤ12֤Ȥû֤̤ФƤޤ

ήǡƤˤ KLab Expert Camp Ȥɥ٥Ȥ򳫺Ťޤ

4֡Ҥץȥ륹åȯȤޥ˥åʹɥ٥Ȥˤ⤫餺񤫤餿γäƤ졢̤ƴŪʻȤߤؤꡢ̸ؤΰܿ䵡ǽɲä˼ȤǤޤ

üԤΥեɥХåɤƺŪ˳ŤʤȻפǡǶư򸫤ƤȡּCPUưƤ뼫ѥǥӥɤOS˼ץȥ륹åȤ߹ߤפȤХͤиǽ⽽ʬꤽʵƤޤ

ʤȤ⡢桼֤ǤưȤƤ饤֥ξ֤OSΥͥȤ߹⤦Ȥݤˤɤ櫤Ǥ뤫İƤʤȤˤϡʬ˥ݡȤƤʤȤܤ˸Ƥޤʤ櫓ǡ֤ޤϼʬǤäƤߤ뤫פȤΤμȤߤΤ⤽ưǤ

꺢OS

Ѥʤ顢ͤOSϤǤ餺ּʬOSפͭƤޤ30OSܤ֤Ĥɤ⤦פѤǤʤΤǡOSϤƤȻ֤ݤꤹƤޤޤȸä Linux BSD ȡ١ˤˤϵϤ礭ޤ

äӤˤϡѥȤ xv6 Ƥʵޤ

CPUϢǤˤо줷ƤޤޤޤǤʤȻפޤxv6 Version 6 UNIX (V6) x86ʥޥץåĶ˸˺ƼΤǤMITڥ졼ƥ󥰥ƥιֵѤ˳ȯMITʳˤ¿ζ鵡ؤȤƺѤƤޤ

̤10,000٤ǡOSμˤۤɾܤʤƤΤϤȤǤܥ塼Ǥ¤ɥȤͤƤƤ˭٤ˤΤ⿴Ǥ

Ƕ RISC-V μ˰ܹԤ褦ǡMITιֵǿΤΤ RISC-V Ǥ١ˤʤäƤޤx86 Ǥ 2018 ǯٰΥ֤򻲾Ȥޤ礦

ɤϤ뤫

xv6 ˤϥͥåȥǽڴޤޤƤʤᡢNICΥɥ饤Фɬפޤץȥ륹åǤϥ󥯥OSεǽPF_PACKET BPFˤѤƤƥɥ饤ФˤϥΡåäΤǡ⤦ʲعߤ뤳Ȥˤʤޤ

xv6 QEMU ưʤ鳫ȯʤ뤳ȤˤʤΤǡNIC QEMU ǻȤƾ˭٤ e1000 (Intel 8254x) 򥿡åȤˤΤɤǤ

ޤϡɥ饤ФΥȥݥȤΥߡѰդ Hello, World! ǤϤ褦ʥɤ񤭡PCI ǥХΥɥ饤ФΥꥹȤɲäƤȤϤ᤿ɤ ...ȻפäΤǤ õƤ⤽äݤɤޤ

Ϥxv6 PCI 򥵥ݡȤƤʤΤǤ

ä xv6 NIC 򰷤ˤ

  • PCIХ򥹥
  • ³ƤǥХ򸡽
  • бɥ饤ФƤӽФ

ȤϢνɬפꡢˤ⤦ʲعߤ뤳Ȥˤʤ櫓ǤȾ徺٤ʤꤽǤ͡

PCIν

PCIХΥ ȤȤʤ񤷤ʹޤI/OݡȤáƾɤࡢȤη֤ǤơդOSΤߤʤ餷ƤƤޤ

ե졼ΰäƤʤ󤾡Ȥ֤Ǥ uchan λɤ PCI 򤷤ޤʤƤޤˡ

ʲ Linux Kernel ⤷ɥȤ⻲ͤˤʤޤ

βɤߤʤ龯ŤĿʤƤ PCI Х򥹥󤷤ƥǥХ򸡽Ф륳ɤ񤯤ΤϤۤ񤷤ʤȻפޤʤxv6-net Ǥ PCI κǽŪʥɤ JOS Ȥ̤ OS Ҽڤ뤳Ȥˤޤ

  • https://pdos.csail.mit.edu/6.828/2018/jos.git

JOS ϡxv6 Ʊͤ MIT ڥ졼ƥ󥰥ƥιֵǻȤ˳ȯƤ OS ǤJOS ϰտŪ˺Ƥ̤OSǤꡢxv6 βʹȤˡJOS μʤƴȤΤ褦Ǥޤxv6 ΥꥷåʥͥǤΤФ JOS ϥޥͥȤ㤤⤢褦Ǥ

ɤ٤Ƥߤ JOS Ƥƥ쥤˽񤫤Ƥ뵤ΤΡΤʷϵϤʤƤޤơJOS ˤ PCI Υɤ e1000 ɥ饤ФΥȥʤۤܤʤˤ񤫤ƤʤäݤΥեˤѰդƤ뤿ᡢȤ碌Ƥ餦Ȥˤޤ

嵭 pci.c JOS ΥɤΤΤǤxv6 ˼ФͤϹΨ JOS ΥɤɤǤϤǡǤͤ񤭻餫ɤ JOS ΥɤȤ碌Ƥäۤɤͤ򤷤䤹ȹ̤ͤǤʥɤ򤽤ΤޤȤ߹िᡢ碌˾֤ݤƤꤷޤˡ

pciinit() main() 椫ƤǤȡư PCI Х򥹥󤷤³ƤǥХФޤ

PCI: 0:0.0: 8086:1237: class: 6.0 (Bridge device) irq: 0
PCI: 0:1.0: 8086:7000: class: 6.1 (Bridge device) irq: 0
PCI: 0:1.1: 8086:7010: class: 1.1 (Storage controller) irq: 0
PCI: 0:1.3: 8086:7113: class: 6.80 (Bridge device) irq: 9
PCI: 0:2.0: 1234:1111: class: 3.0 (Display controller) irq: 0
PCI: 0:3.0: 8086:100e: class: 2.0 (Network controller) irq: 11

٥IDȥǥХID򥭡˥ɥ饤ФΥȥݥȤƤȡǥХлˤáƤޤ

struct pci_driver pci_attach_vendor[] = {
	{ 0x8086, 0x100e, &e1000_init },
	{ 0, 0, 0 },
};

NICΥɥ饤

PCI ΥǥХ򸡽ФǤ褦ˤʤä顢 NIC Υɥ饤Ф񤭤ޤ

JOS Υˤ kernel/e1000.c kernel/e1000.h ޤޤƤޤɤäݤǡIntel ΥɥȤɤȤäƤޤ

ͤˤʤꤽʥɤʤõƤߤȡxv6 RISC-V ǤΥݥȥˤ NIC νޤǽ񤫤줿ɥ饤Фοޤ򻲹ͤˤĤġإåեϤΤޤѤƤ餤ޤ

ޤ Ƥܤ㤯狼䤹ƽޤPCIξܤ񤫤Ƥơʾ򥿥ɤޤƤäɤΤ...ȴưʤ e1000 򤷤ޤʤƤޤˡEPUBǤǤ㤤ޤ

OSDev.org ǾҲ𤵤ƤʲΥɤ⻲ͤˤޤ

¾ˤ⡢ˤ xv6 e1000 ɥ饤Ф񤤤ƤͤΤǡgithub Ǥ⤤ĤץȤ򸫤Ĥ뤳ȤǤޤɤݡ󥰤ǡߤư֤ΤΤϸĤޤǤ

ϢκȤǰֶ路Τѥåȼ˳ߤȯ뤳Ȥǡ1֤餤ϥޤäƤޤȽ񤤤ĤǤʤʤߤȯʤޤ줽ˤʤäƤΤǡưȤϤ㤯򤷤äǤ

ʤ֤ǻȤDMAѤΥХåե꤬ޤǤƤʤưƤʤä󤸤ʤȻפäƤޤ

դξܤȤϡޤ̤εܤǤ񤳤ʤȻפäƤޤ

ץȥ륹åΤΰܿ

NIC Υɥ饤ФưΤǡ褤Υץȥ륹åΤΰܿ˼ݤΤǤޤȤʤäܿǤƤޤޤäΤǡޤ񤯤Ȥʤäꤷޤ

pthread ȤäƤΤ mutex spinlock ֤ꡢcond 򥿥 sleep/wakeup ֤ꤷ餤ǤȡޡȤƤʤΤǡTCPκȤޡ˰¸ϤޤưƤޤ

ޤARP ˱Ǥ褦ˤʤä

ICMP ˱Ǥ褦ˤʤä

UDP ̿Ǥ褦ˤʤ

ǽŪ TCP ư褦ˤʤޤ

å

ͥǥץȥ륹åư褦ˤʤäƤ⥽åȤʤХ桼֤̿ץꥱ񤯤ȤǤޤ

ץȥ륹åˤϥåAPI⤢ΤǤñʤ饤֥ؿʤΤǥץȥ륹å򥫡ͥȤ߹֤Ǥϥ桼֤Υץꥱ󤫤ƤӤޤ

ʤ櫓ǡå ǤϤʤΥåȡʴϢΥƥॳˤޤ

ƥॳɲäˤäƤϡxv6 δ¸Υƥॳ椫褦ʥץȥפΤΤõƱ褦˼Ƥޤ

socket() ǺǥץϡȤ¸ߤƤեǥץȸߴĤ褦˺äƤΤǡåȤΥǥץ close() Ĥꡢrecv() / senc() read() / write() ȤȤޤ

ñʥå̿ΥץǤСLinux Ѥ˽񤤤ɤΤޤư٤ˤϤȺäƤޤ

ifconfig ޥ

뤫饤󥿥եξ֤ǧIPɥ쥹ꤹ뤿ˡŬʥޥɡifget / ifset / ifup / ifdownˤб륷ƥॳäơξ򤷤ΤǤޤ

ȤäȥΤǡǽŪ ifconfig ޥɤޤip ޥɤʤΤ NETLINK μϤ˸ȤͳǤ

ifconfig ioctl() ̤ƥ󥿥եξ/ꤷƤΤǡioctl ΥƥॳɲäSIOCGXXX SIOCSXXX ҤǤޤ

⤳ȺǤּץȥ륹å xv6 ˰ܿפȤϡxv6 ˥ͥåȥǽפȤˤʤäΤǡΤ褦ʥȥˤʤޤ

ȡ;ä reddit ǥӥ塼⤷ޤ

reddit ǥȤ줿μOSäƤƴưΤǾҲ𤷤Ƥޤ

ޤͽΩƤΤ񤷤Ǥ٥ȤŤǤ褦ʾˤʤä顢ޤ KLab Expert Camp ǥץȥ륹åιɤꤿȻפäƤޤκݤϼOSؤȤ߹ߤ⥵ݡȤǤ褦˽ƤޤΤdzڤߤˤƤƤ


@pandax381

pandax381 at 18:58Comments(0)network 

ε˥Ȥ

̾:
URL:
  򵭲: ɾ:    
 
 
 
Blog⸡
Archives
Υ֥ˤĤ
DSASȤϡKLab ۤѤƤ륳ƥĥӥѤLinux١ΥեǤ5Υǡ󥿤ˤƹۤѤƤޤ桹DSASȤ䤹ˡƤϤDZѤǤ뤳Ȥܻؤơɤ˶ФǤޤ
Υ֥Ǥϡ DSAS ǻȤäƤ뵻ѤξҲ䡢¸Ƥߤ̤𡢥ȥ֥˴ޤ줿ηи̤ʤɡ򿥤ޤƾҲ𤷤ƤȻפޤ
ǿ