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. OpenJudge计算概论-骑车与走路

    /*============================================================ 骑车与走路 总时间限制: 1000ms 内存限制: 65536kB 描述 ...

  2. sklearn里计算roc_auc_score,报错ValueError: bad input shape

    用sklearn的DecisionTreeClassifer训练模型,然后用roc_auc_score计算模型的auc.代码如下 clf = DecisionTreeClassifier(criter ...

  3. Java并发包线程池之ForkJoinPool即ForkJoin框架(一)

    前言 这是Java并发包提供的最后一个线程池实现,也是最复杂的一个线程池.针对这一部分的代码太复杂,由于目前理解有限,只做简单介绍.通常大家说的Fork/Join框架其实就是指由ForkJoinPoo ...

  4. 001-http-总览、文件配置、常用http client、http连接池

    一.概述 http请求项目搭建:地址:https://github.com/bjlhx15/common-study.git 中的common-http 主要针对post请求中的,form表单[app ...

  5. 002-创建型-01-工厂方法模式(Factory Method)

    一.概述 定义一个创建对象的接口,但让实现这个接口的类来决定实例化那个类,工厂方法让类的实例化推迟到子类中进行. 工厂方法模式(FACTORY METHOD)同样属于一种常用的对象创建型设计模式,又称 ...

  6. 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_08-用户认证-认证服务查询数据库-用户登录前端

    点击登陆注册链接 跳转到登陆的页面 门户的前端代码 当前路径base64编码 登陆的表单,在学习中心的前端. 这就是登陆的表单 这是表单的校验 请求服务端的接口 登陆请求的方法 请求的地址nginx上 ...

  7. LeetCode_191. Number of 1 Bits

    191. Number of 1 Bits Easy Write a function that takes an unsigned integer and return the number of ...

  8. LeetCode_121. Best Time to Buy and Sell Stock

    121. Best Time to Buy and Sell Stock Easy Say you have an array for which the ith element is the pri ...

  9. spark在windows的配置

    在spark-env.cmd添加一行 FOR /F %%i IN ('hadoop classpath') DO @set SPARK_DIST_CLASSPATH=%%i 修改:log4j.prop ...

  10. vmware安装密钥

    VMware虚拟机已升级至14版本,之前的12版本的秘钥已经无法使用,在此分享一下VMware Workstation 14永久激活密钥: CG54H-D8D0H-H8DHY-C6X7X-N2KG6 ...