Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The objective of this lab programming assignment is to explore the impact of tem

ID: 669978 • Letter: T

Question

The objective of this lab programming assignment is to explore the impact of temporal locality, spatial locality, the replacement block policy, the cache size, and the block size on the miss rate and the effective memory access ema. We assume that 1) the hit access time is 1 clock cycle (cc) and 2) the cache miss penalty (time to upload the block from main memory to cache) is equal to Sb cc, where Sb is the size in words of a block. For example, if the block size is 64 bytes, then the miss penalty is 16 clock cycles (64 bytes is equal to 16 words). For Parts A and B, we consider a CPU with a 32 bit address bus. You must simulate a system with 32 bit words where data are aligned: this means that memory references are always multiple of 4. The cache sizes to consider are 16 KB, 64 KB, 256 KB, and 512 KB. The block size is 64, 128, 256, 1 KB (1024) and 4 KB. Write in your language of choice (that can run on an engineering Tux machine) a simulator of a one level cache system. We assume that we start with an empty cache and that all code and data are in the main memory(no page faults). Generate 1,000,000 random memory references and populate the cache to measure the miss rate and the effective memory access ema. Part A: First Come First Out (FIFO) Replacement Policy 1) Direct mapping Set the cache size to 16 KB. For each block size 64, 128, 256, and 1 KB, measure the miss rate and the effective memory access ema. Compare the measured effective access time with the computed effective access time as a function of the measured miss rate. Repeat for cache sizes 64 KB, 256 KB, and 512 KB. Collect your results and plot them on 1) a graph with the miss rate on the y-axis and the block size on the x-axis, and 2) a graph with the effective access time on the y-axis and the block size on the x-axis. For each of the above two graphs, plot the four curves corresponding 16 KB, 64 KB, 256 KB, and 512 KB cache sizes. 2) Fully associative Repeat the experiment in A.1 using a fully associative cache. 3) Compare and comment on the difference between Direct mapping and fully associative. Discuss the impact of the block size and cache size. Compare the measured effective access time with the computed access time. Part B: Least Recently Used (LRU) Repeat Part A using LRU. Conclusion: Compare and comment the performance of FIFO and LRU. Are the results expected? If not, explain why. PLEASE GIVE ME A C PROGRAMMING CODE OR ANY ASAP!!

Explanation / Answer

CODE :

#include<stdio.h>
void FIFO();
void LRU();

int main()
{
    int ch;
    do
    {
        printf(" 1.FIFO 2.LRU 3.Exit Enter Choice : ");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
            FIFO();
            break;
            case 2:
            LRU();
            break;
       }
    }while(ch!=3);
}
void FIFO()
{
    int frame[3]={-1,-1,-1},ref[20],cnt=0,i,j,no,flag;
    float ratio,hitcnt=0.00;
    printf(" Enter length of reference string : ");
    scanf("%d",&no);
    printf(" Enter reference String with giving space .... ");
    for(i=0;i<no;i++)
    scanf("%d",&ref[i]);
    //printf(" Execution is started here .....");
    for(i=0;i<no;i++)
    {
        flag=0;
        for(j=0;j<3;j++)
        if(frame[j]==ref[i])
        {
            printf(" Page Hit ");
            hitcnt++;
            flag=1;
            break;
        }

        if(flag==0)
        {
            printf(" Page Miss");
            printf(" Before : ");
            for(j=0;j<3;j++)
            printf(" %d",frame[j]);
            frame[cnt]=ref[i];
            cnt++;
            if(cnt>=3)
            cnt=0;
            printf(" After : ");
            for(j=0;j<3;j++)
            printf(" %d",frame[j]);
        }
    }
ratio=hitcnt/no;
printf(" Hit ratio = %f ",ratio);
}
void LRU()
{
    int frame[3]={-1,-1,-1},used[3]={-1,-1,-1},cnt=0,ref[20],i,j,flag,no,index,value;
    float ratio,hitcnt=0;
    printf(" Enter length of reference string : ");
    scanf("%d",&no);
    printf(" Enter reference String with giving space ");
    for(i=0;i<no;i++)
    scanf("%d",&ref[i]);
    //printf(" Execution is started here ");
    for(i=0;i<no;i++)
    {
        flag=0;
        for(j=0;j<3;j++)
        if(frame[j]==ref[i])
        {
            printf(" Page Hit ");
            hitcnt++;
            flag=1;
            used[j]=cnt;
            break;
        }
        if(flag==0)
        {
            printf(" Page Miss");
            printf(" Before :");
            for(j=0;j<3;j++)
            printf(" %d",frame[j]);
            //selection of victim for replacement
            index=0;
            value=used[0];
            if(cnt!=0) {
            for(j=0;j<3;j++)
            if(value>used[j]&&value!=used[j])
            {
                index=j;
                value=used[j];
            }
        }
        //printf(" Victim is %d ",index);
        frame[index]=ref[i];
        used[index]=cnt;
        printf(" After :");
        for(j=0;j<3;j++)
        printf(" %d",frame[j]);
    }
cnt++;
}
ratio=hitcnt/no;
printf(" Hit ratio = %f ",ratio);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote