CSAPP 六個重要實驗 lab4

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   java   ar   for   

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 10000int 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 HERECSE 351 - Winter 2013Lab 4 - Mystery CachesMystery Cache Geometries:mystery0:    block size = 64 bytes    cache size = 262144 bytes    associativity = 1mystery1:    block size = 8 bytes    cache size = 16384 bytes    associativity = 4mystery2:    block size = 16 bytes    cache size = 65536 bytes    associativity = 16mystery3:    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厘米 
    這幅作品正是格威德擅長描繪的古典美人著古典服裝,依靠在大理石上的女性形象。觀眾透過薄如蟬翼的服飾,看到了少女的美麗。少女楚楚動人的容貌讓人浮想聯翩。觀看這幅作品,有一種仰視紀念碑似的感覺,這是畫家的有意安排。








 

CSAPP 六個重要實驗 lab4

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.