The role of the 1,__ATTRUBTE__ keyword
Click to open link
The role of
__attrubte__ (packed) is to tell the compiler to undo the optimization alignment of the structure during compilation and to align it by the actual number of bytes consumed.
struct str_struct{
__u8 A;
__u8 B;
__u8 C;
__u16 D;
} __attribute__ ((packed));
the size of the struct above is 5
/* when using a TypeDef, pay special attention to where __attribute__ ((packed)) is placed, equivalent to:
* typedef struct STR_ Stuct str;
* and the struct str_struct is the structure above.
*/
typedef struct {
__u8 A;
__u8 B;
__u8 C;
__u16 D;
} __attribute__ ((packed)) Str;
the size of the struct above is 5
/* In the following typedef structure, __ATTRIBUTE__ ((packed)) is placed after the structure name Str_temp, its function is ignored, notice the difference from the structure str. */
typedef struct {
__u8 A;
__u8 b;
__u8 C;
__u16 D;
}str_temp __attribute__ ((packed));
The size of the above structure is 6
There are two underscores before and after attribute, followed by a pair of original brackets, and the corresponding __attribute__ parameters in parentheses.
The syntax format is: __attribute__ ((attribute-list))
Attribute sections are used for functions and variables, and typically the compiler places functions in the. Text section, where variables are placed in the. data or. BSS sections, and the section property allows the compiler to place functions or variables in the specified section.
2, meaning of Is_err () in driver
All drivers are running in kernel space, although the kernel space is large, but always limited, and in this limited space, its last page is reserved specifically.
All in the kernel pointer if the last page is referred to, then this is an error pointer, kernel space is 3g-4g, so oxfffff000-0xffffffff is invalid pointer.
[CPP]View Plaincopy
- /*static Inline long is_err (const void *PTR)
- {
- return (unsigned long) ptr > (unsigned long) -1000l;
- }*/
- static inline void * __must_check err_ptr (long error)
- {
- return (void *) error;
- }
Ptr_err () Converts the pointer to an error code.
Likely () and unlikely functions of the 3,linux kernel
Click to open link
Likely and unlikely are only used to change the performance of the system and do not change the values that have been previously
Does not often occur with unlikely, often occurring with likly
Differences between the 4,mdelay and Msleep () functions
Click to open link
Mdelay accuracy is higher, but will always occupy the CPU resources, msleep the current process into the waiting queue according to personal experience, the time delay of 10ms or less is better than the time delay of the time series is best or use the mdelay,100ms or more than the Msleep, Delay of 100ms or more
There is a certain impact on the operation of the multi-tasking system of Linux.
[Linux kernel]linux kernel programming specification