HP Laptop SD card Driver to work in linux

After many trials from google and ubuntu forums.
I got the solution to work my SD card reader in Linux(I tried it in Ubuntu).

  • First of all Download the Linux Driver for ur SD card from here SD Card Driver Download
  • Extract them to your $HOME folder.
  • Now Install the Driver

    1. cd rts_pstor
    2. make
    3. sudo make install
    4. sudo depmod
    5. sudo modprobe rts_pstor

The Beautiful IISc

Getting Started with tinySTM (Ubuntu)

This post is a quick guide to go from nothing to writing small tinySTM based applications. For those that don’t know, tinySTM is a library for writing applications that use transactional memory for synchronization in lieu of traditional locks an semaphores. So this begs two questions now. What issynchronization and what is transactional memory?

Loosely speaking, synchronization is a term used to refer to any method to prevent processes or threads from trampling on one another. What do I mean trampling? There’s things like memory consistency errors which is a term for when threads have an inconsistent view of the same data. For example, if two threads check the value of an integer and see different values. This is typically caused when the integer is cached on the CPU. One core will load a cached version of the variable and the other thread (running on a different core) will go to RAM to read the value. And so different values are seen! Synchronization prevents problems like these.

Transactional Memory (TM) is a style of synchronization that was inspired heavily by databases. In a database requests are encapsulated as transactions. Databases ensure integrity through transactions. This is accomplished by rolling-back any changes that were made in a partially completed transaction. This means that failed transactions won’t break your database. The same is true of memory.

With a little back story, we’re ready to start

wget http://tinystm.org/sites/tinystm.org/files/tinySTM/tinySTM-0.9.9.tgz
tar -xvf tinySTM-0.9.9.tgz
cd tinySTM-0.9.9
sudo apt-get install libatomic-ops-dev
export LIBAO_HOME=/usr/include/atomic_ops
#sometimes we have to edit the make file
DEFINES += -DINTERNAL_STATS //uncomment it

Runing make compiles tinySTM and puts a static library file at ~/tinySTM-0.9.9/lib/libstm.a. Anything we write to use tinySTM will need to link to this lib file.

Let’s make sure that everything is working by compiling and running the example code that came with tinySTM.

cd test
cd bank
# To run these demos with multiple threads we use the "-n" option
./bank -n 3

If everything is working correctly you should get some pretty lengthy output that looks similar to this:

kris@cosmos:~/tinySTM-0.9.9/test/bank$ ./bank -n 3

Nb accounts : 1024
Duration : 10000
Nb threads : 3
Read-all rate : 20
Read threads : 0
Seed : 0
Write-all rate : 0
Write threads : 0
Type sizes : int=4/long=8/ptr=8/word=8
Initializing STM
Creating thread 0
Creating thread 1
Creating thread 2
Thread 0
#transfer : 1969727
#read-all : 492137
#write-all : 0
#aborts : 522377
#lock-r : 167012
#lock-w : 387
#val-r : 354978
#val-w : 0
#val-c : 0
#inv-mem : 0
#realloc : 0
#r-over : 0
#lr-ok : 0
#lr-failed : 0
Max retries : 35784
Thread 1
#transfer : 3517300
#read-all : 879229
#write-all : 0
#aborts : 986623
#lock-r : 288231
#lock-w : 691
#val-r : 697695
#val-w : 6
#val-c : 0
#inv-mem : 0
#realloc : 0
#r-over : 0
#lr-ok : 0
#lr-failed : 0
Max retries : 45082
Thread 2
#transfer : 1947009
#read-all : 486864
#write-all : 0
#aborts : 580381
#lock-r : 228081
#lock-w : 328
#val-r : 351970
#val-w : 2
#val-c : 0
#inv-mem : 0
#realloc : 0
#r-over : 0
#lr-ok : 0
#lr-failed : 0
Max retries : 57503
Bank total : 0 (expected: 0)
Duration : 10000 (ms)
#txs : 9292266 (929226.600000 / s)
#read txs : 1858230 (185823.000000 / s)
#write txs : 0 (0.000000 / s)
#update txs : 7434036 (743403.600000 / s)
#aborts : 2089381 (208938.100000 / s)
#lock-r : 683324 (68332.400000 / s)
#lock-w : 1406 (140.600000 / s)
#val-r : 1404643 (140464.300000 / s)
#val-w : 8 (0.800000 / s)
#val-c : 0 (0.000000 / s)
#inv-mem : 0 (0.000000 / s)
#realloc : 0 (0.000000 / s)
#r-over : 0 (0.000000 / s)
#lr-ok : 0 (0.000000 / s)
#lr-failed : 0 (0.000000 / s)
Max retries : 57503

It’s really no fun to run someone else’s code, so lets build something simple from the ground up. I’ll be using the Boost Thread library for threading instead of pthreads (which is what the tinySTM examples use).

I’m going to write a very contrived example, where I’ll have a Counter class and a MyRunnable class. The Counter class will be extremely simple. In fact, it will basically just be a wrapper around an integer. The only method of interest it will provide will be increment(), which will increment the integer some amount each time it is called. The other class, MyRunnable is basically just an encapsulation of a Boost thread, you can think of it as class the implements Runnable in Java.

The program will start a bunch of threads via Boost, which results in the the run() method of each MyRunnable object getting executed from a different thread of execution. The MyRunnables will try to call increment() on the same Counter object. If everything is done right, each call should be accounted for in the end.

I will synchronize the increment() method by enclosing its body in a transaction. That means that if another thread modifies any of the memory touched in the body of increment, the transaction will be canceled and rolled back to the original state.

Don’t forget to copy all of the tinySTM .h files (stm.h, mod_mem.h, etc) and the library file (libstm.a) into your current working directory. With all of that in mind, here’s the example:

//File: samplestm.cpp //Author: Kristopher Kalish #include #include #include #include "stm.h" // These following macros are from the tinySTM examples, and they truly // are useful. /* * Useful macros to work with transactions. Note that, to use nested * transactions, one should check the environment returned by * stm_get_env() and only call sigsetjmp() if it is not null. */ #define RO 1 #define RW 0 #define START(id, ro) { sigjmp_buf *_e = stm_get_env(); stm_tx_attr_t _a = {id, ro}; sigsetjmp(*_e, 0); stm_start(_e, &_a) #define LOAD(addr) stm_load((stm_word_t *)addr) #define STORE(addr, value) stm_store((stm_word_t *)addr, (stm_word_t)value) #define COMMIT stm_commit(); } using namespace std; static const int INCREMENT = 5; static const int NUM_RUNS = 100000; class Counter { public: Counter() { value = 0; } /** * Increment the counter by five by looping. A loop was picked to * make calls to increment() take more cpu time. */ void increment() { START(0, RW); for(int i = 0; i value); tmp = tmp + 1; STORE(&this->value, tmp); } COMMIT; } int getValue() { return value; } private: int value; }; class MyRunnable { public: MyRunnable(int id, boost::barrier* bar, Counter* count) { this->id = id; this->bar = bar; this->count = count; } void run() { for(int i = 0; i increment(); } // all done, wait at the barrier bar->wait(); } // The entry point for a thread void operator()() { // We must call stm_init_thread() at the beginning of each // thread's line of execution before using the tinySTM library stm_init_thread(); run(); // Call this at the end of each thread's execution to have // tinySTM clean up. stm_exit_thread(); } private: int id; boost::barrier* bar; Counter* count; }; int main() { int numThreads = 4; boost::barrier my_barrier(numThreads); Counter count; cout << "Intializing tinySTM." << endl; stm_init(); cout << "Counter is starting with value: " << count.getValue() << endl; cout << "Starting " << numThreads << " counting threads..." <= 1); // Make the first thread boost::thread thread1(MyRunnable(0, &my_barrier, &count)); // Then make the remaining threads for(int i = 1; i < numThreads; i++) boost::thread thread(MyRunnable(i, &my_barrier, &count)); // thread1 will terminate when all threads have reached the barrier thread1.join(); // Wait for thread1 to terminate cout << "Counter is ended with value: " << count.getValue() << endl; cout << "Counter should be: " << NUM_RUNS * numThreads * INCREMENT << endl; // Let tinySTM clean up after itself stm_exit(); return 0; }

Then to compile and run, we will need to link against the tinySTM library and Boost library: g++ samplestm.cpp -lboost_thread-mt libstm.a -o sample ./sample Example output:

Intializing tinySTM.
Counter is starting with value: 0 
Starting 4 counting threads... 
Counter is ended with value: 2000000
Counter should be: 2000000

reference : http://kris.kalish.net/2009/09/getting-started-with-tinystm-ubuntu-9-04/

Disabling the Authentication for changing Network proxy in Ubuntu

Network Proxy(System->Preferences->Network Proxy) in ubuntu changes the proxy settings for me.
We need to set Apply system wide so that whole system can use it including update manager but the problem here is (for me) every time i change the proxy it asks me to enter the password twice. I usually carry my laptop from home to college. So every time i switch i have to enter password twice, which is big hectic for me.

The first dialog asks access to com.ubuntu.systemservice.setProxy. This response is configured in the file /usr/share/polkit-1/actions/com.ubuntu.systemservice.policy. This is a very readable XML file which contains a section for the setProxy action.

<action id="com.ubuntu.systemservice.setproxy">
  <description>Set current global proxy</description>
  <message>System policy prevents setting proxy settings</message>
    <!-- Old settings

so one authentication dropped. second one can cause potential damage to the system. org.gnome.gconf.defaults.set-system this is stored in a file /usr/share/polkit-1/actions/org.gnome.gconf.defaults.policy.

<action id="org.gnome.gconf.defaults.set-system">
  <description gettext-domain="GConf2">Change GConf system values</description>
  <message gettext-domain="GConf2">Privileges are required to change GConf system values</message>
    <!-- Old setting

After the above changes have been made Now the password authentication has been dropped. Now I can change the Network Proxy without authentication.

The above changes can cause potential damage to your system if it is a multi-user system. Especially the second step of changing network proxy.

My Interview at Microsoft

So Microsoft came to our college as a Campus Placements.
Written test is over. Wow I got selected in written test.
Now I can post the written test questions :
1. Given a binary tree, print the path from a given node in the tree to the root.
2. In a sorted string, a substring is reversed. Write code for in-place reversal of that substring …. 19abcfedgh –> 19abcdefgh
3. Given a linked list in which each node has two pointers, one points to the next node and other to some random (valid) node in the list, make a copy of entire linked list

after that I had three interviews.

1st Interview
This is the first serious interview in my life.
Interviewer : Hi, are you Mr. Shanmuk?
me : yes sir.
Interviewer : okay, i am Mr.XYZ , before we start tell me abt urself and ur interests ?
me : I told what I am and I told i am doing ME in IISc and i am enjoying this.
interviewer : okay, so mr.Shanmuk u r given a tree whose structure is

struct tree{
   struct tree* left,*right;
   int data ;

now u have to implement an inorder iterator for this tree.
He means that every time we call that function it will give the next immediate in order successor of the previously returned value

In this picture first time we call the function it should return -4. next time we call it should return 2, next 3 and so on.
me : first stupid solution traverse the tree in in-order and store them in queue and pop them when the function is called.
Interviewer : nice, bt what is the complexity ?
Me : space : O(n) time : O(1)
Interviewer : Suppose this is a balanced tree can you do something with space complexity.
Me : Instead of pushing the whole in-order elements in stack push one by one till you reach the in-order successor.
space : O(logn) time : O(1) amortised.
interviewer : nice.
now he gave the second question given k sorted lists each of size n, merge them.
me: obvious solution is O(k*k*n).
interviewer : can u improve ? he gave an hint u can use extra memory.
me : i gave another algorithm with heap data structure o(k*logk*n) with space complexity of O(n)

Thats it.
I was little bit confident that i will be selected in this round.
and yeah i got selected.

2nd Interview
interviewer :
some formal questions like introduction , projects , interests…
after that he asked to give an algorithm for
string pattern matching with reg exp.

ex: str : abccdef pattern : bc*d*
should return true; because bccd is subset of str .

me : I couldn’t get it correctly, he gave some hints. i solved partially. then again he gave some hints, now I was able to give him the answer, but it was complicated. So he asked me to write the answer in paper. after struggling a lot i wrote some code with some bugs. then he asked about my written test questions.

that’s it.
Immediately after this i was asked to go for HR interview. well its not fully HR he asked technical questions.
I don’t remember all of them one of them is Give a solution to producer consumer problem without starvation for writers.
i gave one stupid answer which will do n times sema_down for writer and reader.
where n = no of readers.
interviewer : what if we don’t know no of readers ahead of time.
me : I was thinking, in the mean he gave a hint to use use variable writers and readers, instead of only reader. so i gave him the answer.

In this way all my interviews are over.
Some of my friends had four interviews, so i thought i am not going to be selected.
but Thanks to microsoft for selecting me along with my friends.

I prefer Debian over Ubuntu

Ubuntu 11.04 makes life horrible.
For those rare people who don’t know, Canonical’s Ubuntu distribution is basically Debian Sid (the unstable version) plus a few GUI apps and modifications. Debian is one of the most successful community-based distributions.

Till ubuntu 10.10, i was using ubuntu, but when this Ubuntu 11.04 came, i was attracted by its look after seeing a video in youtube, so i upgraded my system to 11.04. but after upgrading this i came to know that this is the worst OS i have seen in my life(sorry worse because windows is there). I have experienced lot of problems with ubuntu 11.04. the problem with ubuntu is that they have to release the new version after every six months. so even though they are not ready with this new version they will release there experimental version. which will have lot of bugs. so after a lot of troubles i thought i wont use ubuntu any more.

So i went for debian. In debian we have four versions(may be more) oldstable, stable, testing, unstable. So the users can decide which version they want. Debian adheres very strictly to free software philosophies, even to that extent, that they re-branded Firefox to Iceweasel. Debian comes with netInst CD which will install the base system only. the other parts u can download and install according to ur wish. I can decide which desktop environment i want. i don’t have to go for that stupid unity.

So no wonder that everything that runs in ubuntu also runs in debian.

Deleting old kernels in Debian/Ubuntu

The problem i used to face in Debian/ubuntu is that when ever i do update/upgrade/dist-upgrade
there will be some more new kernel will be installed. going to synaptic manager and uninstalling every kernel is a pretty heavy task.

the proper and suggested method to remove this kernels are

Step1: find the current kernel version
$: uname -r
output: 2.6.32-5-amd64
this is your kernel version

Step2: List all kernels in your system
$: dpkg –list ‘linux-image*’ /*for debian/ubuntu*/
output :

| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                              Version               Description
+++-=============================- ============      -   ======================
un  linux-image                                  (no description available)
un  linux-image-2.6                              (no description available)
un  linux-image-2.6-amd64                        (no description available)
un  linux-image-2.6-openvz-amd64                 (no description available)
un  linux-image-2.6-vserver-amd64                (no description available)
un  linux-image-2.6-xen-amd64                    (no description available)
ii  linux-image-2.6.32-5-amd64     2.6.32-35squeeze2   Linux 2.6.32 for 64-bit PCs
un  linux-image-2.6.38-10-generic                (no description available)
un  linux-image-                       (no description available)
un  linux-image-                   (no description available)
un  linux-image-3.0                              (no description available)
un  linux-image-3.0.4-1                          (no description available)
un  linux-image-3.0.4-1-dbg                      (no description available)
iU  linux-image-generic          Generic Linux kernel image

$: rpm -q kernel /*for centOS/RedHat/Fedora etc*/
output :

step 3: Remove all old kernels
Choose which kernel you want to uninstall from the list of those installed.
$: sudo apt-get remove linux-image-2.6.38-10-generic /*debian/ubuntu*/
$: rpm -e kernel-2.6.12-1.el5 /*for centOS/RedHat/Fedora etc*/