First USB sketch.
[cascardo/kernel/slides/.git] / 03types / types
1 %Data Types
2 %Thadeu Cascardo
3
4 # Macros
5
6 * include/linux/kernel.h
7 * ARRAY\\_SIZE
8 * FIELD\\_SIZEOF
9 * ALIGN
10 * PTR\\_ALIGN
11 * IS\\_ALIGNED
12
13 # More macros
14
15 * container\\_of
16 * offsetof
17
18 # krefs
19
20 Reference:
21
22 * Documentation/kref.txt
23
24 # API
25
26 * struct kref
27 * kref\\_init - struct kref pointer
28 * kref\\_get - struct kref pointer
29 * kref\\_put - struct kref pointer and release function
30
31 # Usage
32
33 * Embed struct kref into your own structure
34 * Do not forget to call kref\\_init when initializing your structure
35 * Pass a release function as parameter to kref\\_put, where you release your
36   structure
37 * Follow the rules for calling kref\\_get and kref\\_put
38
39 # Rules
40
41 * Must increment count if passing a non-temporary copy
42 * May increment count without a lock if already has a valid pointer
43 * Must decrement when done with the pointer
44 * If code never tries to get a ref without a valid pointer, may be done without
45   a lock
46 * Must serialize getting a ref without a valid pointer with putting a ref
47
48 # Basic Types
49
50 * include linux/types.h
51 * sXX, where XX is 8, 16, 32 or 64
52 * uXX
53
54 # Endianness
55
56 # Little endian and Big endian
57
58 * Little endian machines
59         - Alpha
60         - x86
61 * Big endian machines
62         - PowerPC
63         - SPARC
64 * Multi-endian machines
65         - ARM
66         - MIPS
67         - SH
68
69 # Headers
70
71 * include asm/byteorder.h
72 * include/linux/byteorder/generic.h
73
74 # Macros
75
76 * cpu\\_to\\_beXX
77 * cpu\\_to\\_leXX
78 * beXX\\_to\\_cpu
79 * leXX\\_to\\_cpu
80 * All those with suffix p - use a pointer
81 * All those with suffix s - change in situ
82
83 # Lists
84
85 # Declaration
86
87 * include linux/list.h
88 * LIST\\_HEAD(head);
89 * Embed a struct list\\_head in your structure
90 * Use a struct list\\_head pointer to iterate
91
92 # Initialization
93
94 * INIT\\_LIST\\_HEAD - receives a pointer to the embedded list head
95
96 # Operations
97
98 * list\\_add - receives a pointer to the element and a head
99 * list\\_add\\_tail
100 * list\\_del - receives only the pointer to the element
101 * list\\_empty
102
103 # Access
104
105 * list\\_entry(entry, type, member); -- uses container\\_of
106 * list\\_first\\_entry(head, type, member);
107
108 # Iteration macros
109
110 * list\\_for\\_each(lhptr, head);
111 * list\\_for\\_each\\_entry(iptr, head, member)
112 * list\\_for\\_each\\_safe(lhptr, head);
113
114 # Bitmaps
115
116 # Declaration
117
118 * include linux/types.h
119 * include linux/bitops.h
120 * DECLARE\\_BITMAP
121
122 # API
123
124 * All atomic, prefix \\_ to use non-atomic
125 * set\\_bit
126 * clear\\_bit
127 * change\\_bit
128 * test\\_and\\_set\\_bit
129 * test\\_and\\_clear\\_bit
130 * test\\_and\\_change\\_bit
131
132 # Lookup
133
134 * find\\_first\\_bit
135 * find\\_first\\_zero\\_bit
136 * find\\_last\\_bit
137 * find\\_next\\_bit
138 * find\\_next\\_zero\\_bit
139 * for\\_each\\_set\\_bit
140
141 # Reb-black tree
142
143 # Files
144
145 * Documentation/rbtree.txt
146 * lib/rbtree.c
147 * include linux/rbtree.h
148
149 # Usage
150
151 * Embed struct rb\\_node into your data structure
152 * There's no callback for comparison, write your own lookup and insertion
153   functions
154 * Locking is up to the user
155
156 # API
157
158 * rb\\_entry is the same as container\\_of
159 * Create the root with struct rb\\_root name = RB\\_ROOT;
160 * Lookup function (see example) uses rb\\_left and rb\\_right members
161 * Insertion: lookup insertion point, save the parent and use the functions
162   rb\\_link\\_node and rb\\_insert\\_color (example in Documentation)
163 * Erase with rb\\_erase
164 * Iterate with functions rb\\_first, rb\\_last, rb\\_next and rb\\_prev
165
166 # Hashes
167
168 * No hash table
169 * There are hash functions found at
170         - include linux/hash.h
171         - include linux/jhash.h
172 * Users usually do chaining to resolve collisions
173
174 # Other data types
175
176 * IDR
177 * Flexible Array
178 * Plist
179 * Radix tree
180 * Btree