CSAPP 六个重要实验 lab4

CSAPP && lab4


实验材料:

http://download.csdn.net/detail/u011368821/7926305


实验指导书:

http://download.csdn.net/detail/u011368821/7926323


实验环境:

Linux 3.13.11

Ubuntu 14.0










Part I: An Experiment in C and Java


Q&A Answer these questions:

1.  What are the source code differences among the two Java implementations?

两者src dst的数据类型不同.一个是int 另一个时Integer

(摸着良心说,目前为止,我仅钟爱于C,java仅仅写过hello world... 对于这个问题不能给出很漂亮的回答.)


2.  Pick a single pair of results that most surprised you. What is it about the results that surprised you? (That is,
from the 32 pairs of measurement results, pick one pair whose relationship is least like what you would have
guessed.)


经过多次对比发现,Integer类型的程序比int类型的程序耗时要长!


3.  [Optional extra credit] None of these programs appear to actually do anything, so one is tempted to optimize
them by simply eliminating all code (resulting in an empty main()). Is that a correct optimization? Related to
that, try compiling this C program, with and without optimization, and then time running it:


我认为省略main的参数不会对程序有所优化(个人观点) 

这里需要根据实验指导书去copy书上的一段代码,自己编译运行测试

#include <stdio.h>

#define SIZE 10000

int main()
{
	int i,j,k;

	int sum = 1;

	for(i = 0;i < SIZE; i++)
	{
		for(j = 0;j < SIZE;j++)
		{
			for(k = 0;k < SIZE;k++)
			{
				sum = -sum;
			}
		}
	}

//	printf("Hello world!\n");
	printf("Sum is %d\n",sum);

	return 0;
}


感觉intel i5 8G RAM 的配置都跑不动

反正我等了好久都出不来结果, 追究这东东意义不大了 , next station





Part II: Inferring Mystery Cache Geometries


这个实验是以CSAPP第六章第五节的cache为基础的,没搞清楚cache玩不转的


Instructions


                  Specifically, each of these "processors" is provided as an object file (.o file) against which you will link your code. See the file mystery-cache.h for documentation of the function interface that these object files export.       


                 Your job is to fill in the function stubs in cache-test-skel.c which, when linked with one of these cache object files, will determine and then output the cache size, associativity, and block size. Some of the provided object files are named with this information (e.g. cache_64c_2a_16b.o is a 64 KB capacity, 2­ way set ­associative cache with 16B blocks) to help you check your work.There are also 4 mystery cache object files, whose parameters you must discover on your own.


                  You can assume that the mystery caches have sizes that are powers of 2 and use a least recently used replacement policy.


                   You cannot assume anything else about the cache parameters except what you can infer from the cache size. Finally, the mystery caches are all pretty realistic in their geometries, so use this fact to sanity check your results.




Your Tasks


                Complete the 3 functions in cache-test-skel.c which have /* YOUR CODE GOES HERE */ comments in them.


                Additionally, determine the geometry of each of the four mystery caches and list these in a comment, along with your name, at the top of your modified cache-test-skel.c.


我在做第三个的时候卡了很久,在这里特别要感谢Chenbo Li,是看了他的github 我才得以解脱...

先释出题解,过段时间再给出分析 : )


/*
   YOUR NAME HERE
CSE 351 - Winter 2013
Lab 4 - Mystery Caches

Mystery Cache Geometries:
mystery0:
    block size = 64 bytes
    cache size = 262144 bytes
    associativity = 1
mystery1:
    block size = 8 bytes
    cache size = 16384 bytes
    associativity = 4
mystery2:
    block size = 16 bytes
    cache size = 65536 bytes
    associativity = 16
mystery3:
    block size = 2 bytes
    cache size = 131072 bytes
    associativity = 2
*/

#include <stdlib.h>
#include <stdio.h>

#include "mystery-cache.h"

/*
 * NOTE: When using access_cache() you do not need to provide a "real" memory
 * addresses. You can use any convenient integer value as a memory address,
 * you should not be able to cause a segmentation fault by providing a memory
 * address out of your programs address space as the argument to access_cache.
 */

/*
   Returns the size (in B) of each block in the cache.
*/
int get_block_size(void) {
	int block_counter = 0;
	flush_cache();
	access_cache(0);

	for(block_counter = 0; access_cache(block_counter);block_counter++)
	{
	}

  	return block_counter;
}

/*
   Returns the size (in B) of the cache.
*/
int get_cache_size(int block_size) {

	int possible_cache_size;
	int tmp = 0;
	flush_cache();

	for(possible_cache_size = 1; 1 ;possible_cache_size<<=1)
	{
		for(tmp = 0;tmp <= possible_cache_size;tmp += block_size)
		{
			access_cache(tmp);
		}

		if(!access_cache(0))
		{
			break;
		}
	}

	return possible_cache_size;
}

/*
   Returns the associativity of the cache.
*/
int get_cache_assoc(int cache_size) {

	int tmp = cache_size;
	int addr = 0;
	
	flush_cache();

	for(addr = 0; 1; addr += cache_size)
	{
		access_cache(addr);
		for(tmp = 0;tmp <= addr;tmp += cache_size)
		{
			if(!access_cache(tmp))
			{
				return addr/cache_size;
			}
		}
	}
	return -1;
}

int main(void) {
  int size;
  int assoc;
  int block_size;

  /* The cache needs to be initialized, but the parameters will be
     ignored by the mystery caches, as they are hard coded.
     You can test your geometry paramter discovery routines by
     calling cache_init() w/ your own size and block size values. */
  cache_init(0,0);

  block_size=get_block_size();
  size=get_cache_size(block_size);
  assoc=get_cache_assoc(size);

  printf("Cache block size: %d bytes\n", block_size);
  printf("Cache size: %d bytes\n", size);
  printf("Cache associativity: %d\n", assoc);

  return EXIT_SUCCESS;
}



古典美 格威德(又译格维得) 英国 1906年 画布油画 40.60×30.50厘米 
    这幅作品正是格威德擅长描绘的古典美人着古典服装,依靠在大理石上的女性形象。观众透过薄如蝉翼的服饰,看到了少女的美丽。少女楚楚动人的容貌让人浮想联翩。观看这幅作品,有一种仰视纪念碑似的感觉,这是画家的有意安排。








 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Y86 Tools (Student Distribution) Copyright (c) 2002, R. Bryant and D. O Hallaron, All rights reserved. May not be used, modified, or copied without permission. This directory contains the student distribution of the Y86 tools. It is a proper subset of the master distribution, minus the solution files found in the master distribution. yas Y86 assembler yis Y86 instruction (ISA) simulator hcl2c HCL to C translator ssim SEQ simulator ssim+ SEQ+ simulator psim PIPE simulator y86-code/ Examples programs and and benchmark testing scripts ptest/ Scripts for detailed automated regression testing 1. Building the Y86 tools The Y86 simulators can be configured to support TTY and GUI interfaces. A simulator running in TTY mode prints all information about its run-time behavior on the terminal. Hard to understand what s going on, but useful for automated testing, and doesn t require any special installation features. A simulator running in GUI mode uses a fancy graphical user interface. Nice for visualizing and debugging, but requires installation of Tcl/Tk on your system. To build the Y86 tools, perform the following steps: NOTE: If your instructor prepared this distribution for you, then you can skip Step 1 and proceed directly to Step 2. The Makefile will already have the proper values for GUIMODE, TKLIBS, and TKINC for your system. Step 1. Decide whether you want the TTY or GUI form of the simulators, and then modify ./Makefile in this directory accordingly. (The changes you make to the variables in this Makefile will override the values already assigned in the Makefiles in the seq and pipe directories.) Building the GUI simulators: If you have Tcl/Tk installed on your system, then you can build the GUI form by initializing the GUIMODE, TKLIBS, and TKINC variables, as appropriate for your system. (The default values work for Linux systems.) Assigning GUIMODE=-DHAS_GUI causes the necessary GUI support code in the simulator sources to be included. The TKLIBS variable tells gcc where to look for the libtcl.so and libtk.so libraries. And the TKINC variable tells gcc where to find the tcl.h and tk.h header files. Building the TTY simulators: If you don t have Tcl/Tk installed on your system, then build the TTY form by commenting out all three of these variables (GUIMODE, TKLIBS, and TKINC) in the Makefile. Step 2: Once you ve modified the Makefile to build either the GUI or TTY form, then you can construct the entire set of Y86 tools by typing unix> make clean; make 2. Files Makefile Builds the Y86 tools README This file misc/ Source files for the Y86 assembler yas, the Y86 instruction simulator yis, and the isa.c file that is used by the -t option of the processor simulators to check the results against the ISA simulation. seq/ Code for the SEQ and SEQ+ simulators. Contains HCL files for labs and homework problems that involve modifying SEQ. pipe/ Code for the PIPE simulator. Contains HCL files for labs and homework problems that involve modifying PIPE. y86-code/ Example .ys files from CS:APP and scripts for conducting automated benchmark teseting of the new processor designs. ptest/ Automated regression testing scripts for testing processor designs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值