Book Note: Linux Device Driver Dos and Don'ts
Book Note: Linux Device Driver Dos and Don'ts
http://janitor.kernelnewbies.org/docs/driver-howto.html
what a hardened (robust) device
driver should mean and how it should be implemented and measured.
1.3 Robust device drivers
-Follows the Linux CodingStyle.
-Efficient in managing faults and handling, reporting and recovering from errors.
(Also not panic() happy.)
-Complies with latest Linux kernel APIs and interfaces.
(Uses the new device driver model, kobjects and sysfs.)
-Properly manages resources (memory, semaphores, interrupts, etc.).
-Uses kernel-provided "C" I/O functions instead of assembly code.
2.0 Where do I start?
3.0 OK, I'm ready...
3.1 Efficient error handling, reporting and recovery:
1)<printk()>
you should always check printk() calls to include appropriate KERN_* constant.
2)<goto>
3) <Enumerated return codes> <return EWHATEVER should be return -EWHATEVER>
4) <No need to panic()>
Rather, the device driver should try to recover, re-initialize, or finally simply
return an appropriate error code, release allocated resources, log a message and
exit gracefully.
3.2.1 Module interface changes
<Initialization and cleanup>
<Module Reference Count macros>
You no longer need to adjust your own module reference count
-Reference counting from other modules:
;A Golden Rule: if you are calling through a function pointer into a (different) module,
you must hold a reference to that module.
Otherwise you risk sleeping in the module while it is unloaded.
You can get a reference to a module by using:
try_module_get(owner);
and you don't have to check if OWNER != NULL, this is done by try_module_g
Ïà¹ØÎĵµ£º
Fedora 8.0(linux)ÓÃRPM°²×°gcc
ǰһÕó×°ÁËÒ»¸öFedora 8.0£¬¾ÓÈ»½«gccÑ¡Ïîûѡ£¬ÏÖÔÚÏëÔÚLinux»·¾³Ïµ÷ÊÔc³ÌÐò£¬Ö»ÓÐÔÙ°²×°gcc±àÒëÆ÷¡£ÔÚFedora 8.0°²×°µÄÔ´ÎļþÖУ¬ÕÒµ½PackageÎļþ¼Ð£¬ÀïÃæ°²×°gcc±àÒëÆ÷µÄÎļþ£¬Fedora 8.0µÄgcc ÊÇversion 4.12 £¨20070925£©¡£
°²×°Ë³Ðò:
£¨1£©rpm -ivh kernheaders-2.6 ......
1¡¢LinuxϵͳÏÂ.koÎļþÊÇʲôÎļþ£¿.soÎļþÊÇʲôÎļþ£¿
.ko ££ kernel object£¬ÄÚºËÄ£¿é£¬¿ÉÒÔÔÚLinuxÄÚºËÆðÀ´Ö®ºó¶¯Ì¬µÄ¼ÓÔØºÍÐ¶ÔØ¡£
.so ££ shared object£¬Óû§²ãµÄ¶¯Ì¬¿â £¨ÓÚ.a ¶ÔÓ¦£©£¬Ê¹ÓÃͬһ¸ö.soµÄ³ÌÐòÔÚÔËÐÐʱ
Ö»ÐèÒª¸Ã.soµÄͬһ·Ý¿½±´ ......
vmstat 5 10 ºÍ vmstat -d
r-->;ÔÚÔËÐжÓÁÐÖеȴýµÄ½ø³ÌÊý
b-->;ÔڵȴýioµÄ½ø³ÌÊý
w-->;¿ÉÒÔ½øÈëÔËÐжÓÁе«±»Ìæ»»µÄ½ø³Ì
memoy
swap-->;ÏÖʱ¿ÉÓõĽ»»»Äڴ棨k±íʾ£©
free-->;¿ÕÏеÄÄڴ棨k±íʾ£©
pages
re££¡·»ØÊÕµÄÒ³Ãæ
mf££¡··ÇÑÏÖØ´íÎóµÄÒ³Ãæ
pi££¡·½øÈëÒ³ÃæÊý£¨k±íʾ£©
po£ ......
Linux²Ù×÷ÏµÍ³ÍøÂç±à³Ì--ÔʼÌ×½Ó×Ö £¨1£©
http://soft.zdnet.com.cn/software_zone/2007/1020/568223.shtml
ÎÒÃÇÔÚÇ°ÃæÒѾѧϰ¹ýÁËÍøÂç³ÌÐòµÄÁ½ÖÖÌ×½Ó×Ö(SOCK_STREAM,SOCK_DRAGM).ÔÚÕâÒ»Õ ÀïÃæÎÒÃÇÒ»ÆðÀ´Ñ§Ï°ÁíÍâÒ»ÖÖÌ×½Ó×Ö--ÔʼÌ×½Ó×Ö(SOCK_RAW)¡£Ó¦ÓÃÔʼÌ×½Ó×Ö,ÎÒÃÇ¿ÉÒÔ±àд³öÓÉTCPºÍUDPÌ×½Ó×Ö²»Äܹ»ÊµÏֵŦÄÜ. × ......
linux limits.conf ÅäÖÃ
¡¡¡¡limits.conf Îļþʵ¼ÊÊÇ Linux PAM£¨²åÈëʽÈÏ֤ģ¿é£¬Pluggable Authentication Modules£©ÖÐ pam_limits.so µÄÅäÖÃÎļþ£¬¶øÇÒÖ»Õë¶ÔÓÚµ¥¸ö»á»°¡£
¡¡¡¡limits.confµÄ¸ñʽÈçÏ£º
¡¡¡¡username|@groupname type resource limit
¡¡¡¡username|@groupname£ºÉèÖÃÐèÒª±»ÏÞÖÆµÄÓû§Ãû£¬×éÃûÇ°Ãæ¼Ó@º ......