随笔分类 -  kernel source

notes about kernel source
摘要:1. printk.c 中的重要变量 首先介绍一些 kernel/printk/printk.c 中定义的一些十分重要的变量。 /* console_sem用来保护对console_drivers列表的访问 */ static DEFINE_SEMAPHORE(console_sem); /* co 阅读全文
posted @ 2020-08-07 11:29 glob 阅读(1080) 评论(0) 推荐(1)
摘要:1. echo sdf > /dev/ttyS0 tty_cdev_add 给 tty driver 分配字符设备,设置字符设备的文件操作函数指针指向 tty_fops ,后者的写函数为 tty_write 。 static int tty_cdev_add(struct tty_driver *d 阅读全文
posted @ 2020-08-07 11:27 glob 阅读(572) 评论(0) 推荐(0)
摘要:1. workqueue tty 借助 workqueue 实现串口读写操作之间的同步。 tty_port 结构体中的 struct tty_bufhead buf 成员有一个 struct work_struct work 成员, drivers/tty/tty_buffer.c 中的 tty_b 阅读全文
posted @ 2020-08-07 11:25 glob 阅读(957) 评论(0) 推荐(0)
摘要:1. tty_init 作为字符设备的一员, tty 设备的初始化函数 tty_init 在 drivers/char/mem.c 中的 chr_dev_init 调用。后者声明为 fs_initcall(chr_dev_init); 。 tty_init 的详细说明如下: int __init t 阅读全文
posted @ 2020-08-07 11:23 glob 阅读(944) 评论(0) 推荐(0)
摘要:1. 设置 tty 参数 设置 tty 参数时会设置 tty_struct 内 disc_data 的一些成员变量: struct n_tty_data { ... /* must hold exclusive termios_rwsem to reset these */ unsigned cha 阅读全文
posted @ 2020-08-07 11:22 glob 阅读(1079) 评论(0) 推荐(0)
摘要:1. line discipline line discipline 介于 TTY 层和具体的串口驱动 ( 比如 serial8250 ) 之间。 发送数据时,应用程序通过系统调用向 TTY 设备文件写入数据,进而调用 TTY 层驱动程序执行写操作。 TTY 层驱动程序调用 line discipl 阅读全文
posted @ 2020-08-07 11:21 glob 阅读(1088) 评论(0) 推荐(0)
摘要:本文仍然以slab cache kmalloc_caches 为例,结合 函数的实现,说明slab对象的回收过程。 1. kfree 通过 函数释放 申请的内存时,对应的函数定义在 mm/slub.c 中。 2. slab_free( mm/slub.c ) 如果 的参数地址所在的页面属于slab分 阅读全文
posted @ 2019-10-22 11:26 glob 阅读(1468) 评论(0) 推荐(0)
摘要:slab cache建立后,就可以从中分配对象。以 kmalloc_caches 为例,执行 函数时会从中分配对象。 1. kmalloc 搞内核的肯定对 不会陌生,和 函数类似,这个函数用来分配内存,定义在 include/linux/slab.h 中: 虽然代码的注释说明 函数通常用于向内核的对 阅读全文
posted @ 2019-10-22 11:25 glob 阅读(966) 评论(0) 推荐(0)
摘要:SLAB用来响应较小的内存分配请求,事实上,现在的Linux内核使用的是SLUB——unqueued SLAB分配器。 Linux内核支持三种分配器,分别为SLAB,SLOB,SLUB。x86架构下,默认采用SLUB分配器。 因此,本文解析内核代码时,默认采用SLUB下的代码定义;同时,虽然三种分配 阅读全文
posted @ 2019-10-22 11:21 glob 阅读(838) 评论(0) 推荐(0)
摘要:本文主要分析Linux内核如何处理grub参数中的console=ttyS0,115200n8部分,中间还会穿插一些 include/linux/init.h 的内容。 grub参数中的console=有多种形式,根据 Documentation/kernel parameters.txt 文件, 阅读全文
posted @ 2019-07-05 15:30 glob 阅读(2893) 评论(0) 推荐(0)
摘要:1 /* 2 * Finalizes the stack vm_area_struct. The flags and permissions are updated, 3 * the stack is optionally relocated, and some extra space is added. 4 */ 5 6 /** The macro below ... 阅读全文
posted @ 2018-01-04 09:05 glob 阅读(871) 评论(0) 推荐(0)
摘要:The /var/log/wtmp file records all logins and logouts. The /var/log/lastlog file records when each user last logged in. The /var/log/faillog file reco 阅读全文
posted @ 2017-06-08 15:52 glob 阅读(136) 评论(0) 推荐(0)
摘要:1 unsigned long copy_from_user(void * to, const void __user * from, unsigned long n) 第一个参数to是内核空间的数据目标地址指针, 第二个参数from是用户空间的数据源地址指针, 第三个参数n是数据的长度。 如果数据 阅读全文
posted @ 2017-05-06 11:01 glob 阅读(148) 评论(0) 推荐(0)
摘要:control code page: Control pages are special, they are the intermediaries that are needed while we copy the rest of the pages to their final resting p 阅读全文
posted @ 2017-03-22 16:44 glob 阅读(241) 评论(0) 推荐(0)