Drivers and the Kernel Computer Center CS NCTU

  • Slides: 14
Download presentation
Drivers and the Kernel

Drivers and the Kernel

Computer Center, CS, NCTU Roles of the Kernel – (1) q Components of a

Computer Center, CS, NCTU Roles of the Kernel – (1) q Components of a UNIX System • User-level programs • Kernel • Hardware q Kernel manages the resources • CPU – process management • Memory – memory management • I/O devices – device management q Kernel provides method for • Inter-process communication (IPC) Ø Synchronization, communication • Processes to request resources Ø System calls 2

Computer Center, CS, NCTU 3 Roles of the Kernel – (2)

Computer Center, CS, NCTU 3 Roles of the Kernel – (2)

Computer Center, CS, NCTU Kernel-wide Design Approaches q Monolithic kernels • Kernel space, shared

Computer Center, CS, NCTU Kernel-wide Design Approaches q Monolithic kernels • Kernel space, shared memory, fast, …, need reboot • Eg. Linux, *BSD, MS-DOS, MS Windows 9 x series… q Microkernels • User space, message passing, slow, …, as services • Eg. Mac OS X, Be. OS, … q Hybrid • Monolithic + Micro • Eg. MS Windows NT series, Dragon. Fly BSD, … q Nanokernels q Exokernels 4

Computer Center, CS, NCTU 5 Why Build a Custom Kernel q Free. BSD kernel

Computer Center, CS, NCTU 5 Why Build a Custom Kernel q Free. BSD kernel • • Monolithic modular The functionality cannot be dynamically loadable q Building a custom kernel • • To be an advanced BSD user Time-consuming task q Customized kernel vs. GENERIC • • Fast boot time Lower memory usage Additional hardware support Fine-tune system performance Ø Such as adjusting important system parameters

Computer Center, CS, NCTU Finding the System Hardware q Before venturing into kernel configuration

Computer Center, CS, NCTU Finding the System Hardware q Before venturing into kernel configuration • Get an inventory of the machine’s hardware • Microsoft's Device Manager q dmesg • cat /var/run/dmesg. boot psm 0: <PS/2 Mouse> irq 12 on atkbdc 0 psm 0: [GIANT-LOCKED] psm 0: [ITHREAD] psm 0: model Generic PS/2 mouse, device ID 0 q pciconf -lv • man 4 ath • man -k Atheros ath 0@pci 0: 3: 0: 0: class=0 x 020000 card=0 x 058 a 1014 chip=0 x 1014168 c vendor = 'Atheros Communications Inc. ' device = 'AR 5212 Atheros AR 5212 802. 11 abg wireless' class = network subclass = ethernet 6

Computer Center, CS, NCTU Kernel Drivers and Modules q Before building a custom kernel

Computer Center, CS, NCTU Kernel Drivers and Modules q Before building a custom kernel • Load kernel modules to get the specific hardware support q Kernel modules • kldstat zfs [/home/liuyh] -liuyh- kldstat Id Refs Address Size 1 62 0 xffff 80100000 6 a 2 dc 8 2 1 0 xffff 807 a 3000 1 abd 08 3 2 0 xffff 8094 f 000 3 a 68 4 4 0 xffff 80953000 1 f 348 5 1 0 xffff 80973000 bc 28 • Name kernel zfs. ko opensolaris. ko krpc. ko geom_label. ko kldload Ø /boot/kernel/*. ko Ø Modify /boot/loader. conf to load modules in boot time automatically – if_ath_load="YES" 7 • kldunload

Computer Center, CS, NCTU Building and Installing a Custom Kernel – (1) q Obtain

Computer Center, CS, NCTU Building and Installing a Custom Kernel – (1) q Obtain full Free. BSD source tree • sysinstall Ø Configure Distributions src All • csup Ø csup -h cvsup. tw. freebsd. org /usr/share/examples/cvsup/standard-supfile q Customized kernel configuration file • Sample files Ø /usr/src/sys/<ARCH>/conf – GENERIC, NOTES, LINT (generated by “make LINT”) – /usr/src/sys/conf/NOTES for architecture independent options • Customized file Ø cp GENERIC /usr/local/etc/MYKERNEL Ø ln -s /usr/local/etc/MYKERNEL /usr/src/sys/<ARCH>/conf/ 8

Computer Center, CS, NCTU Building and Installing a Custom Kernel – (2) q Building

Computer Center, CS, NCTU Building and Installing a Custom Kernel – (2) q Building a kernel • cd /usr/src • make buildkernel KERNCONF=MYKERNEL • make installkernel KERNCONF=MYKERNEL Ø kernel = buildkernel + installkernel • MODULES_OVERRIDE Ø Set to a list of modules to build instead of all of them • NO_MODULES Ø Set to not build modules with the kernel • WITHOUT_MODULES Ø Set to a list of modules to exclude from the build q Kernel locations • • 9 /boot/kernel /boot/kernel. old make. conf(5)

Computer Center, CS, NCTU 10 The Configuration File q Each line contains a keyword

Computer Center, CS, NCTU 10 The Configuration File q Each line contains a keyword and one or more arguments • http: //www. freebsd. org/doc/en_US. ISO 8859 -1/books/handbook/kernelconfig-config. html Keyword Function Example machine Sets the machine type i 386 or amd 64 cpu Sets the CPU type I 686_CPU or HAMMER ident Sets the name of the kernel MYKERNEL options Sets various comiple-time options INET or INET 6 device Declares devices fxp include Include another kernel config file GENERIC nooptions Unset options MD_ROOT nodevice Unset devices fdc

Computer Center, CS, NCTU If Something Goes Wrong q Config failed • Make sure

Computer Center, CS, NCTU If Something Goes Wrong q Config failed • Make sure the keyword is typed correctly q Make failed • • Look over your configuration Send mail to the Free. BSD general questions mailing list with kernel configuration q Boot failed • ok mode Ø boot kernel. old Ø unload kernel && load /boot/kernel. old/kernel && boot • nextboot(8) q ps(1) failed • 11 Recompile and install a world

Computer Center, CS, NCTU 12 Ok mode

Computer Center, CS, NCTU 12 Ok mode

Computer Center, CS, NCTU 13 Tuning the Free. BSD Kernel q sysctl command •

Computer Center, CS, NCTU 13 Tuning the Free. BSD Kernel q sysctl command • Dynamically set or get kernel parameters • All changes made by sysctl will be lost across reboot • Use sysctl to tune the kernel and test it, then recompile the kernel • Format: % sysctl [options] name[=value] … Ex: % sysctl –a list all kernel variables % sysctl –d kern. maxfiles print the description of the variable % sysctl kern. maxfiles print the value of the variable % sudo sysctl kern. maxfiles=2048

Computer Center, CS, NCTU Reference q References • http: //www. freebsd. org/doc/en/books/handbook/kernelconfig. html •

Computer Center, CS, NCTU Reference q References • http: //www. freebsd. org/doc/en/books/handbook/kernelconfig. html • /usr/src/sys/<ARCH>/conf Ø NOTES Ø LINT Ø GENERIC q Further reading • http: //www. freebsd. org/doc/handbook/configtuning-kernellimits. html • http: //www. freebsd. org/doc/en/books/developershandbook/kerneldebug. html 14