6.1 Races 6.2 Code: Locks Xv6 有两种锁,spinlocks 和 sleep-locks. struct spinlock { uint locked; // 0 表示可以获取锁,1 表示锁被占用 char *name; // 锁的名称 struct cpu *cpu; // 持有锁的 CPU }; void acquire(struct spinlock *lk) { push_off(); // disable interrupts to avoid deadlock. if (holding(lk)) // 如果当前进程已经持有锁,则 panic,不可重入 panic("acquire"); while (__sync_lock_test_and_set(&lk->locked, 1) != 0) ; __sync_synchronize(); lk->cpu = mycpu(); } __sync_lock_test_and_set 是 C 库的一个原子操作,在 risc-v 上,它会被编译成 amoswap 原子指令。 __sync_lock_test_and_set(&lk->locked, 1) 的工作原理: 原子性地读取 lk->locked 的当前值 将 lk->locked 设置为 1(表示锁被占用) 返回 lk->locked 的原始值 如果返回 0:说明锁之前是空闲的(0),现在成功获取了锁,跳出循环 如果返回 1:说明锁之前就被占用(1),继续自旋等待 void release(struct spinlock *lk) { if (!...

1 min

File System 8.1 Overview File system 架构: disk layer: 读写磁盘 block buffer cache layer: 缓存和同步磁盘数据 logging layer: 把多个 blocks 打包到一个 transaction. inode layer: 包括 individual files, 每个都被表示为一个 inode. directory layer: 包括 directories, 每个都被表示为一个特殊的 inode. path name layer: 提供像/xv6/fs.c 这样的层级路径名。 file descriptor layer: 使用 file descriptor 抽象一些 unix 资源 (pipes, devices, files) disk hardware 一般以 block(或者叫 sector) 为单位,一个 block 通常是 512 bytes. 操作系统使用的 block size 可能与 disk 的 block size 不同,一般是 disk 的 block size 的整数倍。...

3 min

Q1 Uthread 为 users-level threading system 设计 context switch mechanism. Q2 Using threads 利用 threads 和 locks 来实现 parallel programming. 使用 UNIX pthread 库。 Q3 Barrier 实现 barrier, 即应用程序中的一个点,在这个点上,所有参与的线程都必须等待,直到所有其他参与的线程也到达这个点。 可以使用 pthread condition variables.

1 min

回顾 gdb 的用法. lab code lab util 的 Q3 primes 还没做. 把 lab util 每个 question 的 git commit 分开. 笔记

1 min

第一篇 新学习路线、视频介绍、资料下载、开发板基础操作 第三篇 环境搭建与开发板操作 2.6 下载 bsp 和配置交叉编译工具链 $ git clone https://e.coding.net/codebug8/repo.git # download reop $ mkdir -p 100ask_imx6ull-sdk && cd 100ask_imx6ull-sdk $ ../repo/repo init -u https://gitee.com/weidongshan /manifests.git -b linux-sdk -m imx6ull/100ask_imx6ull_linux4.9.88_release.xml --no-repo-verify $ ../repo/repo sync -j4 在.bashrc 中添加 export ARCH=arm export CROSS_COMPILE=arm-buildroot-linux-gnueabihf- export PATH=$PATH:/home/book/100ask_imx6ull-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin 3.3 启动方式 EMMC: 1.2.4 low, 3 high。 SD/TF 卡:1.2.3 high, 4 low。 USB: 3 low, 4 high。 3.4 串口连接 看图如何连接。 3.4.4 串口登录 输入 root 即可登录。...

3 min