int L1lookup(u_int32_t address) { ///// IMPLEMENT THIS ///// return 0; } int L2lookup(u_int32_t address) { ///// IMPLEMENT THIS ///// return 0; }
int L1lookup(u_int32_t address) { ///// IMPLEMENT THIS ///// return 0; } int L2lookup(u_int32_t address) { ///// IMPLEMENT THIS ///// return 0; }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Topic Video
Question
instruction is in the first picture
please give me only implementation of int L1lookup(u_int32_t address) and int L2lookup(u_int32_t address)
cacheSim.h
#include<stdlib.h>
#include<stdio.h>
#define DRAM_SIZE 1048576
typedef struct cb_struct {
unsigned char data[16]; // One cache block is 16 bytes.
u_int32_t tag;
u_int32_t timeStamp; /// This is used to determine what to evict. You can update the timestamp using cycles.
}cacheBlock;
typedef struct access {
int readWrite; // 0 for read, 1 for write
u_int32_t address;
u_int32_t data; // If this is a read access, value here is 0
}cacheAccess;
// This is our dummy DRAM. You can initialize this in anyway you want to test.
unsigned char * DRAM;
cacheBlock L1_cache[2][2]; // Our 2-way, 64 byte cache
cacheBlock L2_cache[4][4]; // Our 4-way, 256 byte cache
// Trace points to a series of cache accesses.
FILE *trace;
long cycles;
void init_DRAM();
// This function print the content of the cache in the following format for an N-way cache with M Sets
// Set 0 : CB1 | CB2 | CB 3 | ... | CB N
// Set 1 : CB1 | CB2 | CB 3 | ... | CB N
// ...
// Set M-1 : CB1 | CB2 | CB 3 | ... | CB N
void printCache();
////// Part 1: Checking if the address is in the cache /////
// These functions perform a cache lookup to the associated cache levels. Return 0 if the address is not in the cache (cache miss) and 1 if the address is in the cache (cache hit)
int L1lookup(u_int32_t address);
int L2lookup(u_int32_t address);
// This function returns a setID given an address
unsigned int getL1SetID(u_int32_t address);
unsigned int getL2SetID(u_int32_t address);
// This function returns a tag given an address
unsigned int getL1Tag(u_int32_t address);
unsigned int getL2Tag(u_int32_t address);
////// Part 2: FIFO cache //////
// This function performs a read to a cache content. Return the 4-byte data content given by the address. Please note that the read access MUST evict existing cache block correctly based on the FIFO policy and insert the new cache block correctly into the cache.
u_int32_t read_fifo(u_int32_t address);
// EPart 3: handle write. Assuming a write-through cache. This is the only place you actually modify the data in the cache and DRAM
void write(u_int32_t address, u_int32_t data);
#include<stdio.h>
#define DRAM_SIZE 1048576
typedef struct cb_struct {
unsigned char data[16]; // One cache block is 16 bytes.
u_int32_t tag;
u_int32_t timeStamp; /// This is used to determine what to evict. You can update the timestamp using cycles.
}cacheBlock;
typedef struct access {
int readWrite; // 0 for read, 1 for write
u_int32_t address;
u_int32_t data; // If this is a read access, value here is 0
}cacheAccess;
// This is our dummy DRAM. You can initialize this in anyway you want to test.
unsigned char * DRAM;
cacheBlock L1_cache[2][2]; // Our 2-way, 64 byte cache
cacheBlock L2_cache[4][4]; // Our 4-way, 256 byte cache
// Trace points to a series of cache accesses.
FILE *trace;
long cycles;
void init_DRAM();
// This function print the content of the cache in the following format for an N-way cache with M Sets
// Set 0 : CB1 | CB2 | CB 3 | ... | CB N
// Set 1 : CB1 | CB2 | CB 3 | ... | CB N
// ...
// Set M-1 : CB1 | CB2 | CB 3 | ... | CB N
void printCache();
////// Part 1: Checking if the address is in the cache /////
// These functions perform a cache lookup to the associated cache levels. Return 0 if the address is not in the cache (cache miss) and 1 if the address is in the cache (cache hit)
int L1lookup(u_int32_t address);
int L2lookup(u_int32_t address);
// This function returns a setID given an address
unsigned int getL1SetID(u_int32_t address);
unsigned int getL2SetID(u_int32_t address);
// This function returns a tag given an address
unsigned int getL1Tag(u_int32_t address);
unsigned int getL2Tag(u_int32_t address);
////// Part 2: FIFO cache //////
// This function performs a read to a cache content. Return the 4-byte data content given by the address. Please note that the read access MUST evict existing cache block correctly based on the FIFO policy and insert the new cache block correctly into the cache.
u_int32_t read_fifo(u_int32_t address);
// EPart 3: handle write. Assuming a write-through cache. This is the only place you actually modify the data in the cache and DRAM
void write(u_int32_t address, u_int32_t data);
cacheSim.C
#include "cacheSim.h"
// In this question, we will assume DRAM will take a 4-byte values starting from 0 to
void init_DRAM()
{
unsigned int i=0;
DRAM = malloc(sizeof(char) * DRAM_SIZE);
for(i=0;i<DRAM_SIZE/4;i++)
{
*((unsigned int*)DRAM+i) = i;
}
}
void printCache()
{
int i,j,k;
printf("===== L1 Cache Content =====\n");
for(i=0;i<2;i++)
{
printf("Set %d :", i);
for(j=0;j<2;j++)
{
printf(" {(TAG: 0x%x)", (unsigned int)(L1_cache[i][j].tag));
for(k=0;k<16;k++)
printf(" 0x%x,", (unsigned int)(L1_cache[i][j].data[k]));
printf(" |");
}
printf("\n");
}
printf("===== L2 Cache Content =====\n");
for(i=0;i<4;i++)
{
printf("Set %d :", i);
for(j=0;j<4;j++)
{
printf(" {(TAG: 0x%x)", (unsigned int)(L2_cache[i][j].tag));
for(k=0;k<16;k++)
printf(" 0x%x,", (unsigned int)(L2_cache[i][j].data[k]));
printf(" |");
}
printf("\n");
}
}
u_int32_t read_fifo(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
int L1lookup(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
int L2lookup(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL1SetID(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL2SetID(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL1Tag(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL2Tag(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
void write(u_int32_t address, u_int32_t data)
{
///// REPLACE THIS /////
read_fifo(address);
return;
}
int main()
{
init_DRAM();
cacheAccess buffer;
int timeTaken=0;
FILE *trace = fopen("input.trace","r");
int L1hit = 0;
int L2hit = 0;
cycles = 0;
while(!feof(trace))
{
fscanf(trace,"%d %x %x", &buffer.readWrite, &buffer.address, &buffer.data);
printf("Processing the request for [R/W] = %d, Address = %x, data = %x\n", buffer.readWrite, buffer.address, buffer.data);
// Checking whether the current access is a hit or miss so that we can advance time correctly
if(L1lookup(buffer.address))// Cache hit
{
timeTaken = 1;
L1hit++;
}
else if(L2lookup(buffer.address))// L2 Cache Hit
{
L2hit++;
timeTaken = 5;
}
else timeTaken = 50;
if (buffer.readWrite) write(buffer.address, buffer.data);
else read_fifo(buffer.address);
cycles+=timeTaken;
}
printCache();
printf("Total cycles used = %ld\nL1 hits = %d, L2 hits = %d", cycles, L1hit, L2hit);
fclose(trace);
free(DRAM);
return 0;
}
// In this question, we will assume DRAM will take a 4-byte values starting from 0 to
void init_DRAM()
{
unsigned int i=0;
DRAM = malloc(sizeof(char) * DRAM_SIZE);
for(i=0;i<DRAM_SIZE/4;i++)
{
*((unsigned int*)DRAM+i) = i;
}
}
void printCache()
{
int i,j,k;
printf("===== L1 Cache Content =====\n");
for(i=0;i<2;i++)
{
printf("Set %d :", i);
for(j=0;j<2;j++)
{
printf(" {(TAG: 0x%x)", (unsigned int)(L1_cache[i][j].tag));
for(k=0;k<16;k++)
printf(" 0x%x,", (unsigned int)(L1_cache[i][j].data[k]));
printf(" |");
}
printf("\n");
}
printf("===== L2 Cache Content =====\n");
for(i=0;i<4;i++)
{
printf("Set %d :", i);
for(j=0;j<4;j++)
{
printf(" {(TAG: 0x%x)", (unsigned int)(L2_cache[i][j].tag));
for(k=0;k<16;k++)
printf(" 0x%x,", (unsigned int)(L2_cache[i][j].data[k]));
printf(" |");
}
printf("\n");
}
}
u_int32_t read_fifo(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
int L1lookup(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
int L2lookup(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL1SetID(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL2SetID(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL1Tag(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL2Tag(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
void write(u_int32_t address, u_int32_t data)
{
///// REPLACE THIS /////
read_fifo(address);
return;
}
int main()
{
init_DRAM();
cacheAccess buffer;
int timeTaken=0;
FILE *trace = fopen("input.trace","r");
int L1hit = 0;
int L2hit = 0;
cycles = 0;
while(!feof(trace))
{
fscanf(trace,"%d %x %x", &buffer.readWrite, &buffer.address, &buffer.data);
printf("Processing the request for [R/W] = %d, Address = %x, data = %x\n", buffer.readWrite, buffer.address, buffer.data);
// Checking whether the current access is a hit or miss so that we can advance time correctly
if(L1lookup(buffer.address))// Cache hit
{
timeTaken = 1;
L1hit++;
}
else if(L2lookup(buffer.address))// L2 Cache Hit
{
L2hit++;
timeTaken = 5;
}
else timeTaken = 50;
if (buffer.readWrite) write(buffer.address, buffer.data);
else read_fifo(buffer.address);
cycles+=timeTaken;
}
printCache();
printf("Total cycles used = %ld\nL1 hits = %d, L2 hits = %d", cycles, L1hit, L2hit);
fclose(trace);
free(DRAM);
return 0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
please give implementation of
unsigned int getL1SetID(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL2SetID(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL1Tag(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
unsigned int getL2Tag(u_int32_t address)
{
///// IMPLEMENT THIS /////
return 0;
}
Solution
by Bartleby Expert
Follow-up Question
please give implementation of
void write(u_int32_t address, u_int32_t data)
{
///// REPLACE THIS /////
read_fifo(address);
return;
}
Solution
by Bartleby Expert
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education