Presentation is loading. Please wait.

Presentation is loading. Please wait.

Drivers and the Kernel. Computer Center, CS, NCTU 2 Roles of the Kernel – (1)  Components of a UNIX System User-level programs Kernel Hardware  Kernel.

Similar presentations


Presentation on theme: "Drivers and the Kernel. Computer Center, CS, NCTU 2 Roles of the Kernel – (1)  Components of a UNIX System User-level programs Kernel Hardware  Kernel."— Presentation transcript:

1 Drivers and the Kernel

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

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

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

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

6 Computer Center, CS, NCTU 6 Finding the System Hardware  Before venturing into kernel configuration Get an inventory of the machine’s hardware Microsoft's Device Manager  dmesg cat /var/run/dmesg.boot  pciconf -lv man 4 ath man -k Atheros psm0: irq 12 on atkbdc0 psm0: [GIANT-LOCKED] psm0: [ITHREAD] psm0: model Generic PS/2 mouse, device ID 0 ath0@pci0:3:0:0: class=0x020000 card=0x058a1014 chip=0x1014168c vendor = 'Atheros Communications Inc.' device = 'AR5212 Atheros AR5212 802.11abg wireless' class = network subclass = ethernet

7 Computer Center, CS, NCTU 7 Kernel Drivers and Modules  Before building a custom kernel Load kernel modules to get the specific hardware support  Kernel modules kldstat kldload  /boot/kernel/*.ko  Modify /boot/loader.conf to load modules in boot time automatically –if_ath_load="YES" kldunload zfs [/home/liuyh] -liuyh- kldstat Id Refs Address Size Name 1 62 0xffffffff80100000 6a2dc8 kernel 2 1 0xffffffff807a3000 1abd08 zfs.ko 3 2 0xffffffff8094f000 3a68 opensolaris.ko 4 4 0xffffffff80953000 1f348 krpc.ko 5 1 0xffffffff80973000 bc28 geom_label.ko

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

9 Computer Center, CS, NCTU 9 Building and Installing a Custom Kernel – (2)  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  Kernel locations /boot/kernel/kernel /boot/kernel  /boot/kernel.old make.conf(5)

10 Computer Center, CS, NCTU 10 The Configuration File  Each line contains a keyword and one or more arguments http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html KeywordFunctionExample machineSets the machine typei386 or amd64 cpuSets the CPU type I686_CPU or HAMMER identSets the name of the kernelMYKERNEL optionsSets various comiple-time optionsINET or INET6 deviceDeclares devicesfxp includeInclude another kernel config fileGENERIC nooptionsUnset optionsMD_ROOT nodeviceUnset devicesfdc

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

12 Computer Center, CS, NCTU 12 Ok mode

13 Computer Center, CS, NCTU 13 Tuning the FreeBSD Kernel  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.maxfilesprint the description of the variable % sysctl kern.maxfilesprint the value of the variable % sudo sysctl kern.maxfiles=2048

14 Computer Center, CS, NCTU 14 Reference  References http://www.freebsd.org/doc/en/books/handbook/kernelconfig- config.htmlhttp://www.freebsd.org/doc/en/books/handbook/kernelconfig- config.html /usr/src/sys/ /conf  NOTES  LINT  GENERIC  Further reading http://www.freebsd.org/doc/handbook/configtuning-kernel- limits.htmlhttp://www.freebsd.org/doc/handbook/configtuning-kernel- limits.html http://www.freebsd.org/doc/en/books/developers- handbook/kerneldebug.htmlhttp://www.freebsd.org/doc/en/books/developers- handbook/kerneldebug.html


Download ppt "Drivers and the Kernel. Computer Center, CS, NCTU 2 Roles of the Kernel – (1)  Components of a UNIX System User-level programs Kernel Hardware  Kernel."

Similar presentations


Ads by Google