Wednesday, June 19, 2013

Vim Editor : Some very common and useful shortcuts

As a programmer I think we use some tools to make our work easier. Most of the time it will be some hi-fi IDE, but I saw many good programmer using Vim Editor very efficiently.  And I must say it has equal capability if you use it properly.

So here I will try to cover few basic shortcuts which could make your life easier.

Shortcut                   Use

yy                        copy the current line in the buffer.

3yy                      copy multiple line (here 3) in the buffer.

p                          paste the buffer content after cursor position line.

P                          paste the buffer content before cursor position line.

D                         delete line at cursor position.

dd                        delete current line.

3dd                      delete multiple line(here 3).

/text                     search “text” in the current file.

:number                go to this line number

u                          undo the last change.

dw                       delete entire word

:%s/fff/rrrrr/g        find all instance of “fff” and replace it with “rrrrr”


And for more tutorial, refer following tutorial.
Hope it will help.

Sancheoneo Ice Festival, Hwacheon, Korea

This weekend I was able to go to any ice festival, Sancheoneo Ice festival and as per CNN it is world’s 4th largest Ice festival.

So here I will give you all the details in my style :

When It is held : probably month of January everywhere.

Where : It is situated in a city called Hwacheon, Korea.

How to reach there : It depends on from where you want to start.  I was staying in Suwon. So from there I took a express bus to Chuncheon, if you are staying in Seoul also, you have to do the same. you can also use Subway, but I will suggest use bus, that way you don’t need to change many metro to reach there.  Then from Chuncheon, there is very frequent bus service to Hwacheon( every 15-20 mins). Ice festival venue is some half a kilometer away from bus terminal, so you can walk down the road.

Activities you can try : Mostly it is popular for Ice fishing. So you can dig a hole in the frozen river and enjoy fishing, there is also bar hand fishing available if you want to try. Worth to mention, there is a foreigner help desk where you can purchase all the fishing equipment and they speak English so you can get any help if you want. To use the Ice Fishing ring you have to purchase ticket of 8000 won, out of which you will get some 3000-5000 won back as food coupon.

Apart from that you can try other things too, like Ice Sliding for that also you have to purchase 5000 won ticket, but I must say it was fun. There are a lot of activities, but I think others are for Children only, the other activities are :  Go Karting on Ice( or I say Go Icing  ), Ice Bicycle, small bungee jumping, Fake Para gliding through the crane(:P).

We were lucky that, it was Special Winter Olympics held in South Korea, so there was a team of Figure Skating, who performed on the very famous “Gangnam Style” song. And I must say, it was awesome performance and must watch too.

Also you can make your snow man there as lots of ice, and volunteer will help you to form shape.  And always watch your step, as it is very slippery. But overall it was good experience.

Food : You will find many food stalls. As for non-vegetarian you will have lots of option with traditional korean food items, but for vegetarian can also survive. In veg food, you will have Tofu(soya-paneer), some indian utppam kinda stuff(tasty though) and some fruits.

Etc: If you are planning to stay in the night, then I will suggest you visit the market as they have really nice Lightning in the night.

I hope it will help you plan your trip to Sancheoneo Ice Festival.

Korean Folk Village

Finally I came out of Dan pretty much after one and half month of no trip at all. So it was refreshing to have a feel of chilly korean weather.

Let me share the experience of Korean Folk Village Trip in my usual way:

Where it is : Yongin-si, Gyeonggi-do( Near to Suwon)

How to reach there : I will suggest you to use subway to reach Suwon Station. As from there you will find 2 buses (37 and 10-5). But I prefer 37, as it is better frequency. Also Tourism department provides free shuttle from Suwon station, but it has limited frequency, although I didn’t use it(may be my timing didn’t match).

What it is : It basically gives you the glimpse of the traditional korean village. you can say it is a musuem of an Korean Folk Village. You will find everything, like traditional home, their village council, items they used to use, shops etc.

What to do : Apart from vising all the places mentioned above. Management has made sure you dont get bored easily. As they have managed to have some 2 hours performance. First the traditional marriage ceremony, Folk music performance (awesome), rope performance (not that interesting) and performance by horse riders. It starts around 10:30 and they will repeat all performances from 2 PM.

After covering all these performance you can proceed to food court where you will find traditional korean folk food(veggies take your foods with you, no good option for you). Then you can go for the museum about korean culture.

Next is Amusement park, which covers haunted house, 4D movie Theater, many rides for children as well as adults.

Further, they have sculpture garden(good for you if you are art fan).

Finally there are few more museums related to other countries culture, you can check it out if you want.

how much it costs : Fee for adult is 15000 won(Admission ticket) and 20000 won(Admission + Amusement Ticket). I will suggest go for second option, as if you pay for rides individually it will cost you more.

Hope it helps you to plan.

Android SurfaceFlinger : Few useful links

Hi All,

If you guys are interested in understanding the flow of Android SurfaceFlinger, here are few links. I must say these are quite detailed and nicely written, although it is in Chinese. So Here are the links
1. http://www.360doc.com/content/10/0221/08/155970_16303293.shtml
2. http://www.360doc.com/content/10/1120/11/3700464_70888667.shtml
4. http://blog.csdn.net/luoshengyang/article/details/7747932
5. http://blog.csdn.net/sure00/article/category/781178

If you will go through it, I can assure you, it would be more than enough to know about Surfaceflinger.

How To Enable debugfs in kernel dynamically.

Kernel developer has provided a functionality known as “debugfs” to debug the kernel, enabling the log at the run time. It is very useful for the modules which have a lots of logs, and enabling the log statically will make the system very slow. So Kernel developers came up with this idea to enabling the logs only for the time when user wants to check a particular scenario.
So here is the process to enable it :
Step 1. Enable the debugfs, which can be done by following command :
mount -o rw,remount -t debugfs none /sys/kernel/debug
Step 2. Now if you want to see what are the logs defined you can do the same using following command :
cat /sys/kernel/debug/dynamic_debug/control [Here /sys/kernel/debug/ is the directory we mounted in previous command,                    u can change it if you want]
Step 3. Now enable the debug log for the files or paricular function you want to see in the logs:
echo ‘file mdp.c +p’ > /sys/kernel/debug/dynamic_debug/control [It will enable all debugfs logs in mdp.c]
echo ’file mdp.c line 2921 +p’ > /sys/kernel/debug/dynamic_debug/control [It will only enabled the log at 2921 line in mdp.c file]
# (
> echo ’file svcsock.c line 1603 +p’ ;\
> echo ’file svcsock.c line 1563 +p’ ;\
> ) > /sys/kernel/debug/dynamic_debug/control [for enabling to multiple debug logs]
Step 4. Now you can check the logs in demsg or cat /proc/kmsg.
Here I want to mention the logs which used under pr_debug()/dev_dbg() method will be enabled by this feature.So whatever logs you want to enable put those using pr_debug or dev_dbg().
you can find more details for pattern to enable logs @ https://www.kernel.org/doc/ols/2009/ols2009-pages-39-46.pdf

Device driver diary : my notes

Virtual device are devices which does not have real hardware, these are used to provide certain functionality.
Character devices are used to provide interface to platform to access hardware through certain file operations.
Platform devices are used to put certain functionality inside the device, so that other devices(virtual or physical) can use its functionality.
How init function of each driver is getting called ?
Ans : When we compile the module code, it puts the function pointer of that module init in a file called init.txt. So at the running time, in main.c file a function
reads all of these function pointer and call those one by one.
- device_create() is used to create device, but we need to tell whether it is platform device or character device. Character device do that using cdev_add or cdev_init.
platform device use platform_device_register().
- Major and Minor combination is used identify the device driver by device file.so whenever we create the device as well as add the device to device hierarchy we use this number.
Character Device:
Refere this link : http://www.linuxforu.com/2011/02/linux-character-drivers/

Device Driver Diary : Uevent and Netlink Socket for Kernel-Platform Communication

uevent is a kernel state change notification method. So whenever there is any change in hardware, which needs to be conveyed to platform,platform uses uevent to send those. There will be a daemon from platform side which will monitors these events and respond accordingly.
So uevent is nothing but a notification which consists detailed information about this event. For example :
add@/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/host6 ACTION=add DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/host6 SUBSYSTEM=scsi DEVTYPE=scsi_host SEQNUM=1165
This tells many things like what is the device name, device id, subsystem, device type, action(add,remove).
so lets see how it adds the variable info:
to do the same it needs a method add_uevent_var().Here we put the information. for example :
env = kzalloc (sizeof (struct kobj_uevent_env), GFP_KERNEL);
retval = add_uevent_var (env, “ACTION =% s”, action_string);
retval = add_uevent_var (env, “DEVPATH =% s”, devpath);
retval = add_uevent_var (env, “SUBSYSTEM =% s”, subsystem);
now as string is ready, we will call
kobject_uevent_env(struct kobject *kobj, enum kobject_action action, char *envp_ext[]);
/*for usb specific*/
kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE,disconnected);
So if you want to send any event to platform, you have to use this method ultimately.
Now lets understand a little bit insight of how kobject_event_env() works. Basically this method uses the netlink socket inside.Netlink sockets are the socket which is used to intiate connection from kernel side. It works like this.
1. We create a socket at kernel side, and associate a buffer with this buffer.
2. It calls netlink_broadcast_filtered()
3. It calls do_one_braodcast()
4. It calls netlink_broadcast_deliver() which puts socket into a socket buffer queue. Also it calls sk->dk_data_ready()
5. finally it calls sock_def_readable, it signals the user side socket that the data at kernel side is ready to be read.
At Platform side we have a file at hardware/libhardware_legacy/uevent/ named as uevent.c. This have a function, uvent_init(), it creates the netlink socket at platform side using socket(), and associate the local buffer to it using bind() function. Then in uevent_next_event() function,it will keep on checking the socket for new data. uevent_next_event() function will be called by application.
Important Files :
1. hardware/libhardware_legacy/uevent/uevent.c
2. kernel/lib/kobject_uevent.c
3. kernel/net/netlink/af_netlink.c
4. kernel/drivers/usb/gadget/android.c [for usb related uevents]
5. frameworks/base/core/java/android/os/UEventObserver.java
6. frameworks/base/services/java/com/android/server/usb/UsbService.java
References :
1. http://blog.csdn.net/dfysy/article/details/7330919 [translate it, it will help you a lot about how uevent flow]
2. http://www.linuxjournal.com/article/7356 [complete tutorial on netlink socket, with example]
3. Man page of socket(), bind() and netlink() @ http://linux.die.net
I hope this will help you. Still I have one doubt that how netlink socket is different from normall polling, if you have clue, please comment below.
EDIT : Mr. Rami Rosen told me that its the generic kernel implementation that when a write operation is done on the queue of the socket, a flag which says that the socket can be awakened is set. So until then poll is in blocking state.