Monday 16 July 2018

Cache Writing Schemes

I found this concept really hard to memorise during my preparation. Till date gate hasn't asked any specific question on this topic. But chances are pretty fair for this type of questions to come in near future. Don't get upset if you are not able to get it. Just skip it. I too skipped it. Go as relax as possible to gate exam. Even if question comes from this section just leave it. Don't spoil the entire paper for just 2 marks.

Lets get started:

1. WRITE THROUGH CACHE

READ HIT:- No memory access.

READ MISS:- Memory must send number of words required by the Cache.

WRITE HIT:- Cache must send a word to memory.

WRITE MISS:- Memory must send to cache equivalent number of words required and then Cache must send a word to memory.


2. WRITE BACK CACHE

READ HIT:- No memory access.

READ MISS:- If replaced line/block is modified then cache to memory first then memory to cache equivalent number of words required.

If replaced line/block is clean then memory to cache required number of words will be sent.

WRITE HIT:- No memory access

WRITE MISS:- If replaced line is modified then cache to memory first then memory to cache equivalent number of words required.

If replaced line/block is clean then memory to cache required number of words will be sent.


3. WRITE ALLOCATE ( FETCH ON WRITE)

Data at the missed write location is loaded to the Cache, followed by a write-hit operation.

Here write misses are similar to read miss.

Generally, write back caches use write allocate principle.

4. NO-WRITE ALLOCATE (WRITE NO-ALLOCATE OR WRITE AROUND)

Data at the missed write location is not loaded to cache and is written directly to the backing store.

Only the reads are cached.

Generally, write through cache uses no-write principle.



Example:
A 64 word Cache and Main Memory are divided into 16 word blocks...cache access time=10 ns ,,MM access time =50 ns. the hit ratio for read operation is =80% and write operation=90%.
Whenever a page fault occurs,the associated block must be brought from Main memory to cache for both read and write operation....read frequency=40%,write frequency =60%.

Assume CPU bus can transfer 1 word at a time.

1.what is avg access time if write through scheme is used?

Answer:

First write all the things you need for calculation.

Block size = 16 words
Cache access time = 10ns
Main Memory access time = 50ns

Cache Hit ratio:
Read hit = 80%
Read miss = 20%
Write hit = 90%
Write miss = 10%

Read operation frequency = 40%
Write operation frequency = 60%

------------------
1. If write through scheme is used:

First you should do this...

Avg access time = (40%)(Avg Read access time) + (60%) (Avg Write access time)

(We have just divided the total number of operations into read and write operations, as 40% are read operations and 60% are write operations)
.....................................
Now similarly divide the Avg read access time and Avg Write access time,

Avg Read access time = (80%)(Avg Read hit time) + (20%)(Avg Read miss time)

Avg Write access time = (90%)(Avg Write hit time) + (10%)(Avg Write miss time)
......................................
Now refer to the theory part i mentioned above for write through scheme.

Avg Read hit time = 0(Main memory) + 10(cache), since no memory access is required and 1 cache read is required.

Avg Read miss time = 16*50(Main memory) + (1+16+1)*10(cache),1st cache read is a miss, then memory must send 16 words(Block size ) to the cache {note: 16 memory access and 16 cache access are required for this transfer} and then 1 final cache read is required to get the data.

Avg Write hit time = 1*50(Main memory) + 10(cache), here cache must send the word written to the memory

Avg Write miss time = (16+1)*50(Main memory) + (1+16+1)*10(cache),  here Memory must send to cache 16 words (Block size) and then Cache must send a word to memory.
........................................

Now just wrap everything up and get the answer.

Avg access time = (40%){ (80%)(10) + 20%(260) } + (60%){ (90%)(60) + (10%)(1030) }

                           = (0.4) {8 + 52} + (0.6) {54 + 103}

                           = (0.4) {60} + (0.6) { 157 } = 118.2 ns

There is also another method using stall frequency which is a faster method. But in order to do that you need to be very thorough in applying all data. This method is slower but will always give you the exact accurate answer with no errors.

------------------------------------------------------------

Additional Task:

Do extend the above question for write back cache policy. Here you will need ratio of pages modified. Assume 20% of pages are modified.  Now just imagine how we solved it for write through cache and use it to solve for write back cache policy. Post your answers on comments. I will verify it when i get some time...

Friday 13 July 2018

How to deal with bad habits?

SHIFTING OF DESIRE IS EASIER THAN STOPPING THEM

Bad habits are quite common these days. It's really difficult to stop them instantly. Bad habits include smoking, chewing tobacco, drinks, excessive sexual desire, drug addicts etc etc. But no one ever talks about them openly. These things if not dealt well can spoil your future completely. A teenager under 16 might not control his/her urge but being matured definitely you can and you should.

So how to deal with them?

Instead of trying to stop them instantly you should try to shift the desire to something else.
For example:-
If you are smoking at Rs 20 per cigarette then shift that desire to chocolates or chicken items. Train your mind few times that i am addicted to chicken lolipop or dairymilk now. Utilise that money to buy these.

Try to figure out any other food item that you like the most. Many people like cakes, pastries, sweets, beverages etc etc.

Go near your dentist. He will say you exactly how much you have tarnished your teeth by smoking. So you won't be presentable and feel shy to talk to others because of those bad yellow colour tarnished front teeth.

If you are alcoholic then try the hardest alcohol and drink and eat till you vomit. Vomiting experience would leave a serious bad impression for alcohols in your mind. It is evident from studies that after severely vomiting for once even a serious alcohol addict thinks thrice before touching alcohol again.

Excessive sexual desire can only be eliminated by setting up a serious goal. For example: Research people are so obsessed with their research work that they forget everything. They are so focused in their work and desire to succeed that they don't have time to think about other pleasures. Similarly actors, musicians, politicians are obsessed with their work. So you need to set a goal and have the dedicated desire to achieve it.

Drug addicts are considered to be serious. You should visit a physician asap !!!

Some people are addicted towards study. Many would say that it's good then. But actually it's bad too. They don't realise the importance of study in practical world. They are just like the robots with no emotions. They are very sensitive in many cases. They can't withstand minor offending behaviour and very often attempt suicides and other serious issues cease to happen.

You must have your own life !!! The world is such a beautiful place. Try to explore it as much as possible before you close your eyes forever.

Have a good day !!! keep smiling and keep inspiring others...