1、linux/moduleparam.hmodule_param(name, type, perm);module_param_named(name, value, type, perm);参数定义 module_param_string(name, string, len, perm);module_param_array(name, type, num, perm);MODULE_PARM(variable,type);MODULE_PARM_DESC(variable,type);4、 模块别名 MODULE_ALIAS(alias-name这是新增的,在老版本中需在/etc/module
2、s.conf配置,现在在代码中就可以实现。5、 模块计数 int try_module_get(&module);module_put();MOD_INC_USE_COUNT 和 MOD_DEC_USE_COUNT http:/www.fsl.cs.sunysb.edu/sean/parser.cgi?modulesIn 2.4 modules, the MOD_INC_USE_COUNT macro is used to prevent unloading of the module while there is an open file. The 2.6 kernel, however,
3、knows not to unload a module that owns a character device thats currently open.However, this requires that the module be explicit in specifying ownership of character devices, using the THIS_MODULE macro. You also have to take out all calls to MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT. static struct f
4、ile_operations fops = .owner = THIS_MODULE, .read = device_read, .write = device_write, .open = device_open, .release = device_release The 2.6 kernel considers modules that use the deprecated facility to be unsafe, and does not permit their unloading, even with rmmod -f. 2.6,2.5的kbuild不需要到处加上MOD_INC
5、_USE_COUNT来消除模块卸载竞争(module unload race)6、 符号导出 只有显示的导出符号才能被其他模块使用,默认不导出所有的符号,不必使用EXPORT_NO _SYMBOLS 老板本:默认导出所有的符号,除非使用EXPORT_NO_SYMBOLS 7、 内核版本检查 需要在多个文件中包含时,不必定义_NO_VERSION_ 在多个文件中包含时,除在主文件外的其他文件中必须定义_ _NO_VERSION_,防止版本重复定义。8、 设备号 kdev_t被废除不可用,新的dev_t拓展到了32位,12位主设备号,20位次设备号。unsigned int iminor(stru
6、ct inode *inode);unsigned int imajor(struct inode *inode);8位主设备号,8位次设备号 int MAJOR(kdev_t dev);int MINOR(kdev_t dev);9、 内存分配头文件变更 所有的内存分配函数包含在头文件,而原来的不存在 内存分配函数包含在头文件10、 结构体的初试化 gcc开始采用ANSI C的struct结构体的初始化形式:static struct some_structure = .field1 = value, .field2 = value, . ;非标准的初试化形式 field1: value,
7、field2:11、 用户模式帮助器 int call_usermodehelper(char *path, char *argv, char *envp, int wait);新增wait参数 12、 request_module() request_module(foo-device-%d, number);char module_name32;printf(module_name, request_module(module_name);13、 dev_t引发的字符设备的变化 1、取主次设备号为 unsigned iminor(struct inode *inode);unsigned
8、imajor(struct inode *inode);2、老的register_chrdev()用法没变,保持向后兼容,但不能访问设备号大于256的设备 。3、新的接口为 a)注册字符设备范围 int register_chrdev_region(dev_t from, unsigned count, char *name);b)动态申请主设备号 int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, char *name);看了这两个函数郁闷吧_!怎么和file_operations结构联系起来啊?别急
9、!c)包含 ,利用struct cdev和file_operations连接 struct cdev *cdev_alloc(void);void cdev_init(struct cdev *cdev, struct file_operations *fops);int cdev_add(struct cdev *cdev, dev_t dev, unsigned count);(分别为,申请cdev结构,和fops连接,将设备加入到系统中!好复杂啊!) d)void cdev_del(struct cdev *cdev);只有在cdev_add执行成功才可运行。e)辅助函数 kobject
10、_put(&cdev-kobj);struct kobject *cdev_get(struct cdev *cdev);void cdev_put(struct cdev *cdev);这一部分变化和新增的/sys/dev有一定的关联。14、 新增对/proc的访问操作 以前的/proc中只能得到string, seq_file操作能得到如long等多种数据。相关函数:static struct seq_operations 必须实现这个类似file_operations得数据中得各个成 员函数。seq_printf();int seq_putc(struct seq_file *m, ch
11、ar c);int seq_puts(struct seq_file *m, const char *s);int seq_escape(struct seq_file *m, const char *s, const char *esc);int seq_path(struct seq_file *m, struct vfsmount *mnt, struct dentry *dentry, char *esc);seq_open(file, &ct_seq_ops);等等 15、 底层内存分配 1、头文件改为2、分配标志GFP_BUFFER被取消,取而代之的是GFP_NOIO 和 GFP_
12、NOFS 3、新增_GFP_REPEAT,_GFP_NOFAIL,_GFP_NORETRY分配标志 4、页面分配函数alloc_pages(),get_free_page()被包含在中 5、对NUMA系统新增了几个函数:a) struct page *alloc_pages_node(int node_id, unsigned int gfp_mask, unsigned int order);b) void free_hot_page(struct page *page);c) void free_cold_page(struct page *page);6、 新增Memory pools
13、linux/mempool.hmempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t *free_fn, void *pool_data);void *mempool_alloc(mempool_t *pool, int gfp_mask);void mempool_free(void *element, mempool_t *pool);int mempool_resize(mempool_t *pool, int new_min_nr, int gfp_mask);16、 per-CPU
14、变量 get_cpu_var();put_cpu_var();void *alloc_percpu(type);void free_percpu(const void *);per_cpu_ptr(void *ptr, int cpu) get_cpu_ptr(ptr) put_cpu_ptr(ptr) 老版本使用 DEFINE_PER_CPU(type, name);EXPORT_PER_CPU_SYMBOL(name);EXPORT_PER_CPU_SYMBOL_GPL(name);DECLARE_PER_CPU(type, name);DEFINE_PER_CPU(int, mypcin
15、t);2.6内核采用了可剥夺得调度方式这些宏都不安全。17、 内核时间变化 1、现在的各个平台的HZ为 Alpha: 1024/1200; ARM: 100/128/200/1000; CRIS: 100; i386: 1000; IA-64:1024; M68K: M68K-nommu: 50-1000; MIPS: 100/128/1000; MIPS64:PA-RISC: 100/1000; PowerPC32: PowerPC64: S/390: SPARC32:100; SPARC64: SuperH: UML: v850: 24-100; x86-64: 1000. 2、由于HZ的
16、变化,原来的jiffies计数器很快就溢出了,引入了新的计数器jiffies_64 3、#include u64 my_time = get_jiffies_64();4、新的时间结构增加了纳秒成员变量 struct timespec current_kernel_time(void);5、他的timer函数没变,新增 void add_timer_on(struct timer_list *timer, int cpu);6、新增纳秒级延时函数 ndelay();7、POSIX clocks 参考kernel/posix-timers.c 18、 工作队列(workqueue) 1、任务队列
17、(task queue )接口函数都被取消,新增了workqueue接口函数 struct workqueue_struct *create_workqueue(const char *name);DECLARE_WORK(name, void (*function)(void *), void *data);INIT_WORK(struct work_struct *work, void (*function)(void *), void *data);PREPARE_WORK(struct work_struct *work, 2、申明struct work_struct结构 int qu
18、eue_work(struct workqueue_struct *queue, struct work_struct *work);int queue_delayed_work(struct workqueue_struct *queue, struct work_struct *work, unsigned long delay);int cancel_delayed_work(struct work_struct *work);void flush_workqueue(struct workqueue_struct *queue);void destroy_workqueue(struc
19、t workqueue_struct *queue);int schedule_work(struct work_struct *work);int schedule_delayed_work(struct work_struct *work, unsigned long delay);19、 新增创建VFS的libfslibfs给创建一个新的文件系统提供了大量的API. 主要是对struct file_system_type的实现。参考源代码:drivers/hotplug/pci_hotplug_core.c drivers/usb/core/inode.c drivers/oprofil
20、e/oprofilefs.c fs/ramfs/inode.c fs/nfsd/nfsctl.c (simple_fill_super() example) 20、 DMA的变化 未变化的有:void *pci_alloc_consistent(struct pci_dev *dev, size_t size, dma_addr_t *dma_handle);void pci_free_consistent(struct pci_dev *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle);变化的有:1、 void *dma_all
21、oc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int flag);void dma_free_coherent(struct device *dev, size_t size, 2、列举了映射方向:enum dma_data_direction DMA_BIDIRECTIONAL = 0, DMA_TO_DEVICE = 1, DMA_FROM_DEVICE = 2, DMA_NONE = 3, 3、单映射 dma_addr_t dma_map_single(struct device *dev, vo
22、id *addr, size_t size, enum dma_data_direction direction);void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, 4、页面映射 dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, void dma_unmap_page(struct device *dev, dma_addr_t dma_addr, 5、有关scatter/g
23、ather的函数:int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction);void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries, enum dma_data_direction direction);6、非一致性映射(Noncoherent DMA mappings) void *dma_alloc_noncoherent(struct dev
24、ice *dev, size_t size, void dma_sync_single_range(struct device *dev, dma_addr_t dma_handle, void dma_free_noncoherent(struct device *dev, size_t size, 7、DAC (double address cycle) int pci_dac_set_dma_mask(struct pci_dev *dev, u64 mask);void pci_dac_dma_sync_single(struct pci_dev *dev, dma64_addr_t
25、dma_addr, size_t len, int direction);21、 互斥 新增seqlock主要用于:1、少量的数据保护 2、数据比较简单(没有指针),并且使用频率很高 3、对不产生任何副作用的数据的访问 4、访问时写者不被饿死 linux/seqlock.h初始化 seqlock_t lock1 = SEQLOCK_UNLOCKED;或seqlock_t lock2; seqlock_init(&lock2);void write_seqlock(seqlock_t *sl);void write_sequnlock(seqlock_t *sl);int write_tryse
26、qlock(seqlock_t *sl);void write_seqlock_irqsave(seqlock_t *sl, long flags);void write_sequnlock_irqrestore(seqlock_t *sl, long flags);void write_seqlock_irq(seqlock_t *sl);void write_sequnlock_irq(seqlock_t *sl);void write_seqlock_bh(seqlock_t *sl);void write_sequnlock_bh(seqlock_t *sl);unsigned int read_seqbegin(seqlock_t *sl);int read_seqretry(seqlock_t *sl, unsigned int iv);unsigned int read_seqbegin_irqsave(seqlock_t *sl, long flags);int read_seqretry_irqrestore(seqlock
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1