资源简介
CSAPP(深入理解操作系统)的倒数第二个实验源代码,总共有三种方法
代码片段和文件信息
/*
* clock.c - Routines for using the cycle counters on x86
* Alpha and Sparc boxes.
*
* Copyright (c) 2002 R. Bryant and D. O‘Hallaron All rights reserved.
* May not be used modified or copied without permission.
*/
#include
#include
#include
#include
#include “clock.h“
/*******************************************************
* Machine dependent functions
*
* Note: the constants __i386__ and __alpha
* are set by GCC when it calls the C preprocessor
* You can verify this for yourself using gcc -v.
*******************************************************/
#if defined(__i386__)
/*******************************************************
* Pentium versions of start_counter() and get_counter()
*******************************************************/
/* $begin x86cyclecounter */
/* Initialize the cycle counter */
static unsigned cyc_hi = 0;
static unsigned cyc_lo = 0;
/* Set *hi and *lo to the high and low order bits of the cycle counter.
Implementation requires assembly code to use the rdtsc instruction. */
void access_counter(unsigned *hi unsigned *lo)
{
asm(“rdtsc; movl %%edx%0; movl %%eax%1“ /* Read cycle counter */
: “=r“ (*hi) “=r“ (*lo) /* and move results to */
: /* No input */ /* the two outputs */
: “%edx“ “%eax“);
}
/* Record the current value of the cycle counter. */
void start_counter()
{
access_counter(&cyc_hi &cyc_lo);
}
/* Return the number of cycles since the last call to start_counter. */
double get_counter()
{
unsigned ncyc_hi ncyc_lo;
unsigned hi lo borrow;
double result;
/* Get cycle counter */
access_counter(&ncyc_hi &ncyc_lo);
/* Do double precision subtraction */
lo = ncyc_lo - cyc_lo;
borrow = lo > ncyc_lo;
hi = ncyc_hi - cyc_hi - borrow;
result = (double) hi * (1 << 30) * 4 + lo;
if (result < 0) {
fprintf(stderr “Error: counter returns neg value: %.0f\n“ result);
}
return result;
}
/* $end x86cyclecounter */
#elif defined(__alpha)
/****************************************************
* Alpha versions of start_counter() and get_counter()
***************************************************/
/* Initialize the cycle counter */
static unsigned cyc_hi = 0;
static unsigned cyc_lo = 0;
/* Use Alpha cycle timer to compute cycles. Then use
measured clock speed to compute seconds
*/
/*
* counterRoutine is an array of Alpha instructions to access
* the Alpha‘s processor cycle counter. It uses the rpcc
* instruction to access the counter. This 64 bit register is
* divided into two parts. The lower 32 bits are the cycles
* used by the current process. The upper 32 bits are wall
* clock cycles. These instructions read the counter and
* convert the lower 32 bits into an unsigned int - this is the
* user space counter value.
* NOTE: The counter has a very limited time span. With a
* 450MhZ clock the c
- 上一篇:IAR各个版本的破解器
- 下一篇:山东大学数据库期末考试7套复习题
相关资源
- 跟老男孩学linux三剑客命令V1.5
- 宋宝华源码《Linux设备驱动开发详解
- 基于嵌入式Linux的RFID读卡器的驱动程
- vgg_generated_48,vgg_generated_64,vgg_gene
- 2711_1p0- 树莓派4B 芯片手册.pdf
- Linux编程手册-多线程-详细资料.rar
- 西农Linux实习含详细实习报告
- CRF++ toolkit 0.58
- Linux餐厅点菜系统基于Linux 下QT数据库
- redis-3.0.0.tar.gz
- linux usb core driver源码分析
- 嵌入式linux下QT开发的wifi源码
- 鸟哥私房菜PPT-经典的linux学习资料
- 黑马_Linux网络编程-网络基础-socket编程
- Linux大作业
- 智能家居实训项目 所使用的第三方库
- [课件] linux入门基础ppt
- 鸟哥的Linux私房菜——基础学习篇第四
- Linux下的BT软件源码,包含详细讲解
- geckodriver-v0.18.0-linux32
- 基于ARM_linux多媒体播放器的Qt源码
- 深度Linux 15.8下安装RTL8192EU驱动,亲测
- Serial IO Card-华塑PCMCIA转串口RS232-ox
- busybox-1.24.1.tar.bz2
- BCM4352 无线网卡驱动 适用kalilinux2018
- linux内核分析实验 模拟宾馆房间预订
- 宇视相机linux32位SDK
- 基于嵌入式Linux与S3C2410平台的视频采
- mibbrowser for linux
- linux(centos)系统安全snort——搭建入
评论
共有 条评论