Linux驅動知識:內核中經常使用的數據類型

#include <linux/types.h> typedef u8; typedef u16; typedef u32; typedef u64;

The equivalent signed types exist as well. In user space, you can refer to the types as __u8, _ _u16, and so forth.linux

 

#include <asm/page.h>性能

PAGE_SIZE    //未必是4K
PAGE_SHIFT

Symbols that define the number of bytes per page for the current architecture and the number of bits in the page offset (12 for 4-KB pages and 13 for 8-KB pages).ui

 

#include <asm/byteorder.h> __LITTLE_ENDIAN __BIG_ENDIAN

Only one of the two symbols is defined, depending on the architecture.spa

 

#include <asm/byteorder.h> u32 __cpu_to_le32 (u32); u32 __le32_to_cpu (u32);

Functions that convert between known byte orders and that of the processor. There are more than 60 such functions; see the various files ininclude/linux/byteorder/ for a full list and the ways in which they are defined.code

 

#include <asm/unaligned.h> get_unaligned(ptr); put_unaligned(val, ptr);

Some architectures need to protect unaligned data access using these macros. The macros expand to normal pointer dereferencing for architectures that permit you to access unaligned data.orm

有的平臺上在非對齊的位置存取相應數據(好比在4的非整數倍地址上訪問u32)會有問題,有的平臺是經過產生異常並在異常處理中進行讀寫,極大下降了性能。blog

 

#include <linux/err.h>
void *ERR_PTR(long error); long PTR_ERR(const void *ptr); long IS_ERR(const void *ptr);

Functions allow error codes to be returned by functions that return a pointer value.ip

 

#include <linux/list.h> list_add(struct list_head *new, struct list_head *head); list_add_tail(struct list_head *new, struct list_head *head); list_del(struct list_head *entry); list_del_init(struct list_head *entry); list_empty(struct list_head *head); list_entry(entry, type, member); list_move(struct list_head *entry, struct list_head *head); list_move_tail(struct list_head *entry, struct list_head *head); list_splice(struct list_head *list, struct list_head *head);

Functions that manipulate circular, doubly linked lists.ci

 

list_for_each(struct list_head *cursor, struct list_head *list) list_for_each_prev(struct list_head *cursor, struct list_head *list) list_for_each_safe(struct list_head *cursor, struct list_head *next, struct list_head *list) list_for_each_entry(type *cursor, struct list_head *list, member) list_for_each_entry_safe(type *cursor, type *next struct list_head *list, member)

Convenience macros for iterating through linked lists.get

相關文章
相關標籤/搜索