xv6可以运行多cpu的计算机上,这个os使用mycpu函数来标识初当前的cpu,使用struct cpu结构体来记录当前的CPU状态。使用cpus这些状态存放于cpus数组中,使用ncpu来标志cpu的个数。

  1 // Per-CPU state
2 struct cpu {
3 uchar apicid; // Local APIC ID 每个cpu都有一个唯一硬件ID,这个ID可以lapicid()函数进行获取,然后存放于这个字段中。
4 struct context *scheduler; // swtch() here to enter scheduler
5 struct taskstate ts; // Used by x86 to find stack for interrupt
6 struct segdesc gdt[NSEGS]; // x86 global descriptor table
7 volatile uint started; // Has the CPU started?
8 int ncli; // Depth of pushcli nesting.
9 int intena; // Were interrupts enabled before pushcli?
10 struct proc *proc; // The process running on this cpu or null
11 };
12
13 extern struct cpu cpus[NCPU]; //当前系统中存在的CPU
14 extern int ncpu;

以下函数主要功能是获取 运行当前代码的cpu对应的ID,然后通过这个ID在cpus数组中进行匹配,得到当前CPU信息(这个cpu信息是已经事先通过程序获取的)

 35 // Must be called with interrupts disabled to avoid the caller being
36 // rescheduled between reading lapicid and running through the loop.
37 struct cpu*
38 mycpu(void)
39 {
40 int apicid, i;
41
42 if(readeflags()&FL_IF)
43 panic("mycpu called with interrupts enabled\n");
44
45 apicid = lapicid();
46 // APIC IDs are not guaranteed to be contiguous. Maybe we should have
47 // a reverse map, or reserve a register to store &cpus[i].
48 for (i = 0; i < ncpu; ++i) {
49 if (cpus[i].apicid == apicid)
50 return &cpus[i];
51 }
52 panic("unknown apicid\n");
53 }

xv6解析-- 多处理器操作的更多相关文章

  1. 通过pull解析器操作安卓的xml

    通过pull解析器操作安卓的xml 例子定义了一个javabean用于存放上面解析出来的xml内容, 这个javabean为Person,代码请见本页下面备注: =================== ...

  2. 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)

    1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...

  3. jQuery2.x源码解析(DOM操作篇)

    jQuery2.x源码解析(构建篇) jQuery2.x源码解析(设计篇) jQuery2.x源码解析(回调篇) jQuery2.x源码解析(缓存篇) jQuery这个类库最为核心重要的功能就是DOM ...

  4. 解析Redis操作五大数据类型常用命令

    摘要:分享经常用到一些命令和使用场景总结,以及对Redis中五大数据类型如何使用cmd命令行的形式进行操作的方法. 本文分享自华为云社区<Redis操作五大数据类型常用命令解析>,作者:灰 ...

  5. 使用 jsoup 对 HTML 文档进行解析和操作

    jsoup 简介 Java 程序在解析 HTML 文档时,相信大家都接触过 htmlparser 这个开源项目,我曾经在 IBM DW 上发表过两篇关于 htmlparser 的文章,分别是:从 HT ...

  6. ansible-playbook组件解析及操作全解

    转载于http://www.178linux.com/7001 一.ansible-playbook介绍: playbook是由一个或多个”play”组成的列表.play的主要功能在于将事先归为一组的 ...

  7. jsoup对 HTML 文档的解析和操作

    本文手动转载自http://www.cnblogs.com/chenying99/archive/2013/01/04/2844615.html,仅根据个人需要对实用部分进行转载,详细请阅读原文. j ...

  8. C#的颜色解析及操作和相关Brush

    一.颜色表示方式 // // Summary: // Creates a System.Drawing.Color structure from a 32-bit ARGB value. // // ...

  9. 解析和操作XML文件

    Dom4j工具 使用步骤: 1)导入dom4j的核心包. dom4j-1.6.1.jar 2)编写Dom4j读取xml文件代码 1,Domj4读取xml文件 ,准备工作:读取整个文档并获取根节点 // ...

随机推荐

  1. Hadoop优化 操作系统优化

    1.优化文件系统,修改/etc/fstab 在defaults后面添加noatime,表示不记录文件的访问时间. 修改为: 如果不想重新启动操作系统使配置生效,那么应该执行: # mount -o r ...

  2. ubuntu中编译安装gcc 9.2.0

    一切都和其他源码安装软件是一样的: 一.下载源代码: http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz 二.解压文件 tar xvf gcc- ...

  3. indexOf的用法

    A.indexOf(B)="-1"表示的是不存在 不等于-1就表示存在 http://www.w3school.com.cn/jsref/jsref_indexOf.asp 没有出 ...

  4. java创建数组几种方式

    最近得多学学基础了,基础还是很重要的- int[] temp=new int[6]; int[] temp={1,2,3,4}; int[] temp= new int[]{1,2,3,4,5};  ...

  5. 【原】Python基础-函数

    #不定长参数,这里prams是一个元组集合def print_params(*prams): for e in prams: print(e) print(prams) #输出('xxx', (1, ...

  6. 2018-2019-2 20165234 《网络对抗技术》 Exp9 Web安全基础

    Exp9 Web安全基础 一. 实践内容 1. 安装JDK.Webgoat 2. SQL注入攻击 数字型注入(Numeric SQL Injection) 日志欺骗(Log Spoofing) 字符串 ...

  7. 近似最近邻算法-annoy解析

    转自https://www.cnblogs.com/futurehau/p/6524396.html Annoy是高维空间求近似最近邻的一个开源库. Annoy构建一棵二叉树,查询时间为O(logn) ...

  8. case设计及验证:入口+页面+展示

    测试个性CB问题, 功能整体结构为:入口+页面+展示 总结: 1. 产品文档为主,其次是服务端接口返回.数据结构及字段值确认.结合实际场景检查是否有遗漏或不合理. 2. 以字段为维度,每个字段的检查点 ...

  9. webpack——Modules && Hot Module Replacement

    blog:JavaScript Module Systems Showdown: CommonJS vs AMD vs ES2015 官网链接: Modules 官网链接:Hot Module Rep ...

  10. Jmeter响应断言--正则表达式判断纯数字

    如图所示,这样是匹配14位数字,如果响应是纯数字可以直接用上