Linux Device Drivers阅读笔记
Linux Device Drivers, 3rd Edition
2.3.1. User Space and Kernel Space
内核空间和用户空间
Unix transfers execution from user space to kernel space whenever an application issues a system call or is suspended by a hardware interrupt. Kernel code executing a system call is working in the context of a process—it operates on behalf of the calling process and is able to access data in the process's address space. Code that handles interrupts, on the other hand, is asynchronous with respect to processes and is not related to any particular process.
这是很关键的段落:
Unix可以通过系统调用和硬件中断实现从用户空间到内核空间的切换。对于系统调用,内核代码运行于调用进程的上下文中,内核代码可以访问调用进程的数据。对于硬件中断,内核代码运行于中断上下文,独立于当前被打断的进程,所以此时不能访问被中断的当前进程空间的数据。
从用户空间切换到内核空间时要使用内核空间堆栈,linux内核空间堆栈<8k, 写内核程序要相当注意栈的使用。
当系统从内核空间返回或者从中断上下文中返回用户空间时,如果有重新调度需求,系统会进行重新调度,即用户抢占。
系统处于中断上下文或者进程持有自旋锁时不允许内核抢占。
内核抢占一般发生在,
1 当系统在内核空间执行时,被某个中断打断,当从这个中断返回内核空间时。
2 内核空间释放自旋锁时。
3.7. read and write
unsigned long copy_to_user(void _ _user *to,
const void *from,
unsigned long count);
unsigned long copy_from_user(void *to,
const void _ _user *from,
unsigned long count);
Although these functions behave like normal memcpy functions, a little extra care must be used when accessing user space from kernel code. The user pages being addressed might not be currently present in memory, and the virtual memory subsystem can put the process to sleep while the page is being transferred into place. This happens, for example, when the page must be retrieved from swap space.
内核空间和用户空间拷贝数据时
相关文档:
其实这才应该是这一系列文章的第一节,因为这篇文章讲的是盘古开天地的事。话说Mr.
Process是一个现代人,但是,只要是人,总该有个祖先。人们总想知道自己从哪来,然后才可以估摸算一下自己将去向何方。所以咱也要了解一下
Linux的世界里人类的起源。
图1:从上电到BIOS
按下电源开关的那个真实的人就是Linux世界里的 ......
相信g r e p是U N I X和L I N U X中使用最广泛的命令之一。g r e p(全局正则表达式版本)允许对文本文件进行模式查找。如果找到匹配模式, g r e p打印包含模式的所有行。g r e p支持基本正则表达式,也支持其扩展集。g r e p有三种变形,即:
G r e p: 标准g r e p命令,本章大部分篇幅集中讨论此格式。
E g r e p: ......
文章来源:http://blog.chinaunix.net/u3/94284/showart_1982227.html
一:前言
接着前面的终端控制台分析,接下来分析serial的驱动.在linux中,serial也对应着终端,通常被称为串口终端.在shell上,我们看到的/dev/ttyS*就是串口终端所对应的设备节点.
在分析具体的serial驱动之前.有必要先分析uart驱动架构.uart是Universal ......
每个进程都有一个唯一的进程号。 每个进程都有一个父进程。 系统中的进程以树的形式组织,init进程(进程号为1)作为根。 进程0是调度进程,没有程序与之对应,是内核的一部分。 进程1是init进程,是在系统启动的阶段由内核启动的,对应/sbin/ini ......