日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

內(nèi)核操作 Linux2.6內(nèi)核驅(qū)動移植參考( 二 )


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結(jié)構(gòu),和fops連接,將設(shè)備加入到系統(tǒng)中!好復(fù)雜?。。?br /> d)void cdev_del(struct cdev *cdev);
只有在cdev_add執(zhí)行成功才可運(yùn)行 。
e)輔助函數(shù)
kobject_put(&cdev->kobj);
struct kobject *cdev_get(struct cdev *cdev);
void cdev_put(struct cdev *cdev);
這一部分變化和新增的/sys/dev有一定的關(guān)聯(lián) 。
14、新增對/proc的訪問操作
<linux/seq_file.h>
以前的/proc中只能得到string, seq_file操作能得到如long等多種數(shù)據(jù) 。
相關(guān)函數(shù):
static struct seq_operations 必須實(shí)現(xiàn)這個類似file_operations得數(shù)據(jù)中得各個成
員函數(shù) 。
seq_printf();
int seq_putc(struct seq_file *m, char 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、底層內(nèi)存分配
1、<linux/malloc.h>頭文件改為<linux/slab.h>
2、分配標(biāo)志GFP_BUFFER被取消,取而代之的是GFP_NOIO 和 GFP_NOFS
3、新增__GFP_REPEAT,__GFP_NOFAIL,__GFP_NORETRY分配標(biāo)志
4、頁面分配函數(shù)alloc_pages(),get_free_page()被包含在<linux/gfp.h>中
5、對NUMA系統(tǒng)新增了幾個函數(shù):
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
<linux/mempool.h>
mempool_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變量
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, mypcint);
2.6內(nèi)核采用了可剝奪得調(diào)度方式這些宏都不安全 。
17、內(nèi)核時間變化
1、現(xiàn)在的各個平臺的HZ為
Alpha: 1024/1200; ARM: 100/128/200/1000; CRIS: 100; i386: 1000; IA-64:
1024; M68K: 100; M68K-nommu: 50-1000; MIPS: 100/128/1000; MIPS64: 100;
PA-RISC: 100/1000; PowerPC32: 100; PowerPC64: 1000; S/390: 100; SPARC32:
100; SPARC64: 100; SuperH: 100/1000; UML: 100; v850: 24-100; x86-64: 1000.
2、由于HZ的變化,原來的jiffies計數(shù)器很快就溢出了,引入了新的計數(shù)器jiffies_64
3、#include <linux/jiffies.h>
u64 my_time = get_jiffies_64();
4、新的時間結(jié)構(gòu)增加了納秒成員變量
struct timespec current_kernel_time(void);
5、他的timer函數(shù)沒變,新增
void add_timer_on(struct timer_list *timer, int cpu);
6、新增納秒級延時函數(shù)
ndelay();
7、POSIX clocks 參考kernel/posix-timers.c
18、工作隊列(workqueue)
1、任務(wù)隊列(task queue )接口函數(shù)都被取消,新增了workqueue接口函數(shù)
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,
void (*function)(void *), void *data);

推薦閱讀