2010년 5월 6일 목요일

Helllo Guys ,
I am bringing in one of the most unknown issue (few among us may know this) called False Cache Sharing.

Have u ever noticed when u create object in any object oriented programming language, how it is allocated in the memory? Even if it is allocated how processor reacts to it? How its is fed into pipelines and what will happen if u have ur cpu which is SMP with hyper threading enabled?

CLR(Common Language Runtime ) : To make it simpler i must say , its task is to just keep all the object allocated by User into as near as possible into assigned HEAP(So that further locality of refrence can be used)

lets take an example

public class Demo
{
public int status1;
public int status2;
}

When Demo object is instansiated , and loaded into Memory..SMP processor which has HyperThreading Enabled,reads the data from RAM through Cache-Line via System Bus into its fast cache(L2 cache) and now able to be fed into superscalar architacture.

consider there are two execution streams (two thread) for one CPU(concept of Hyper-Technology).One Thread(T1) is accessing status1 and another(T2) is using status2. Lets Suppose T1 has to read status1 and T2 has to write status=10. As both addresses belong to same cache-line, One among them has to wait for other to get its task completed , and during that time other thread's execution gets stalled.Situation would be evn worse when dual processor is used as 4 Logical CPU may demand the data from same cache line .


Trivial Solution To this problem :

As a programmer i can add some padding objects/variable in my above code snippet as follows:


{
public int status1;
public int pad1;
...
..
..
public int status2;

}

Now thread concering data may not fall into same cache line (depends up on again cache-line size again, need to know your proceesor uses how much size for cache-line).
But this intoduces bad programming habbit as code will be unruly if u effective lines are few thousands n padding lines are multiple of them.



Limitation of this solution:

Suppose you are adding few padding objects in betwn , again it depends up on your compiler whether it reorders the code or not..even if it is not reordered , bt sometimes if there are
some unused objects , and unfortunatly if it is garbage collected even before two threads can use it..then situation will be same as now there is no padded data (Becouse of the grace of our garbage collector and compilers)



2.Most unfeasible solution will be to not pick sequential addressess out of RAM , so that at least we will not be able to find cache-line-sharing.but it causes change in the modern processors design.



3.A solution may be to add some logic so that predict the locality of data (which is being used by multiple threads ) without wasting much cpu clock ticks , and if two instructions/data belong to same cache-line ,copy it to some other location in cache from where it could be fetched by needed thread .But surely this is much costlier approach than waiting for thread of line to be vacted.


In my view first solution is feasible if you have knowledge about processor cache line and also compiler characterstics too.

Read it out above article and if you guys find any solution , then let me know also so that we can check its feasiblity too....

2010년 1월 29일 금요일

For You...

fir ek baar shard hawaon ne rukh moda
fir ek baar in ghataon ne vadiyon ko apne rang me ooda
fir ek baar suraj ki kirno ne munder par apni chamak bikheri
fir ek baar baagon me wo kaliya muskurayi
fir ek baar koyal ke kookne se dil me daudi armaano ki ashayein
fir ek baar ons ki bundon ne dharti ke daman ko ghera
fir ek baar ye poorwayi ne apni mahak bikheri
fir ek baar sarso khet me lahlahayi
fir ek baar jharne ki kalkal ne jindgi ki jhalak dikhayi
fir ek baar nadiyo ka lahrana man me halchal paida kar gaya
fir ek baar wo aamrayi ki khusboo ki yaad ayi
fir ek baar wo galyiyan wo chaurahon ne pookara
fir ek baar dil ke kisi kone me stabdh bhavanaon ne li angadayi
fir ek baar sinduri suraj ne apni lalima bikheri
fir bhi na jane ye dil kyon bechain hai


na jane kyon najuk honto ne muskurana bhula diya hai..
na jane kyon dil ki dhadkane maddham hai
na jane kyon ye palke nam hai
na jane kyon kise ke hone ka ehsas hai
na jane kyon koi door hai par door sa nahi
na jane kyon ye dil un anjaani rahon ko dekhta hai
na jane kyon is dil ko kisi ke aane ka intzaar hai
na jane kyon ye asq sahaj hi ache lagne lage
na jane apna hi saye se hum kyon hum darne lage
na jane kisi ki jhukti huyi nigahein fir yaad aayi
na jane kisi ki wo komal muskaan fir khusiya bikher gayi

Vaise to kahne ko duniya me mahfilon ki koi kami nahi
fir bhi is dil ke kisi kone me tanhayi basti hai
Vaise to aas-paas rangeen nazare hain
fir bhi dil me kisi ki yaadon ki suli gad jati hai

Vaise to is dil me hazaron armano ke mele hai
fir bhi ek choti si kasak kyon chubhti hai

Vaise to na to ye galyian or na hi ye manzar andekhe hai
fir bhi na jane ye kyon apne se lagte hai

Kyon is dil me kisi ki dundhli si tasveer hai
Jo paas hokar bhi paas naho aur door hoker bhi door nahi

Vaise to dil ki dhadkane chalti hai
par na jane kyon ye sasein madhaam hai.

Kyon ab doston ke tanein bhi nahi chubhte

Kyon ye gulshan ke fool bhi raas nahi ate

Sayad ye tum hi ho....
Jo har pal apne hone ka ehsaas dilati ho
Har ek gulshan har ek kali me tum hi nazar aati ho.

Apni muskaan ko apne hoto se juda na hone dena
Apne chehre par khushi ki lali hamesha barqarar rakhna
Har pal ko aise jina ki hum sath hai......