系统相关
首页 > 系统相关> > linux内核 —— 读写信号量实验

linux内核 —— 读写信号量实验

作者:互联网

内核版本:5.14
代码路径:

概述

读写信号量具有如下特点:

数据结构

struct rw_semaphore {
	atomic_long_t count;
	atomic_long_t owner;
#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
	struct optimistic_spin_queue osq; /* spinner MCS lock */
#endif
	raw_spinlock_t wait_lock;
	struct list_head wait_list;
};

实验

实现一个申请和释放读写信号量rwsem_test的内核模块,然后通过应用来控制申请或者释放,期间使用crash工具查看rwsem_test信号量的内部状态。

root@ubuntu-vm:~# crash /mnt/linux-5.14/vmlinux
      KERNEL: /mnt/linux-5.14/vmlinux
    DUMPFILE: /dev/mem
        CPUS: 12
        DATE: Sat Mar 26 09:34:29 CST 2022
      UPTIME: 00:29:52
LOAD AVERAGE: 0.72, 0.23, 0.08
       TASKS: 176
    NODENAME: ubuntu-vm
     RELEASE: 5.14.0+
     VERSION: #3 SMP Fri Mar 25 08:57:39 PDT 2022
     MACHINE: x86_64  (3599 Mhz)
      MEMORY: 16 GB
         PID: 578
     COMMAND: "crash"
        TASK: ffff8de0c595ec80  [THREAD_INFO: ffff8de0c595ec80]
         CPU: 2
       STATE: TASK_RUNNING (ACTIVE)

crash> sym rwsem_test
ffffffffa5645b00 (d) rwsem_test
crash> rw_semaphore.count,owner,wait_list -x ffffffffa5645b00
  count = {
    counter = 0x0
  },
  owner = {
    counter = 0x0
  },
  wait_list = {
    next = 0xffffffffa5645b18 <rwsem_test+24>,
    prev = 0xffffffffa5645b18 <rwsem_test+24>
  }

标签:write,crash,读写,linux,list,信号量,rwsem,进程
来源: https://www.cnblogs.com/pengdonglin137/p/16057702.html