tag:blogger.com,1999:blog-32783998007663725312024-03-13T08:52:14.771+05:30Let's Share some thoughts.............Online Diary for trouble shooting of daily technology problems.It have mixture of different flavors of technologies like android, windows problems, linux as well as the good informative links related to online movies or music or travel.Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.comBlogger111125tag:blogger.com,1999:blog-3278399800766372531.post-76145890463316824922019-01-08T20:56:00.000+05:302019-01-08T20:56:30.629+05:30Google Colab setup for fast.ai Deep learning course <div dir="ltr" style="text-align: left;" trbidi="on">
For past few days I have been trying to setup Google Colab to run fast.ai lesson files.<br />
<div>
Found multiple post on the same but I was getting some or other error.</div>
<div>
<br /></div>
<div>
So here is the code which worked for me, I know there is latest version of fast.ai, but I wasn't able to make it work with that. </div>
<div>
Here the code is based on fastai version 0.7.</div>
<script src="https://gist.github.com/smartyrahul/82008a9cafae08a755cd970b209b4696.js"></script>
<div>
<br /></div>
<div>
<br />
I am unable to mention the author of the original post, as I was trying multiple combination at the time. If you are able to find, please comment, I will update my post with proper citation.<br />
<br />
<br />
<b>PS: sometimes Google colab throws random error, so I will suggest to reset all runtime and then run again</b>. </div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-27351572282962021942018-02-15T14:09:00.000+05:302018-02-15T14:12:18.335+05:30Rename Domain Computer using Powershell Script<div dir="ltr" style="text-align: left;" trbidi="on">
As name suggests, powershell is very powerful way to automate pretty much all the things in windows.<br />
<div>
<br /></div>
<div>
If you want to rename your computer using power shell script where your computer is part of domain. Here is the the simple set of commands to do it :</div>
<div>
<br /></div>
<div>
1. $user = '<domain-name>DOMAIN-NAME\USER-NAME<user-name>'</user-name></domain-name></div>
<div>
2. $password = '<your-domainuser-password>PASSWORD'|ConvertTo-SecureString -AsPlainText -force</your-domainuser-password></div>
<div>
3. $cred = New-Object System.Management.Automation.PSCredential $user,$password</div>
<div>
4. Rename-Computer -ComputerName CURRENT-COMPUTER-NAME <current-computer-name>-NewName NEW_COMPUTER-NAME <new-computer-name>-domaincredential $cred</new-computer-name></current-computer-name></div>
<div>
<br /></div>
<div>
After that you need to restart the computer for changes to take effect.</div>
<div>
<br /></div>
<div>
Hope it helps !!</div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-13629062698175235262016-02-06T21:13:00.001+05:302016-02-06T21:14:27.590+05:30C++ Graph class Implementation : Without any STL package<div dir="ltr" style="text-align: left;" trbidi="on">
Hi All,<br />
<br />
Please find the implementation for Graph class in C++ without using any STL reference.<br />
Let me know if you find any issues with it.<br />
<br />
Header file.<br />
<script src="https://gist.github.com/anonymous/544ab4fd8905dfaf52b3.js"></script><br />
<br />
Cpp file:<br />
<br />
<script src="https://gist.github.com/smartyrahul/7736b33e736669eb75e4.js"></script><br />
<br />
Happy Coding !!</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com1tag:blogger.com,1999:blog-3278399800766372531.post-40027550696330384472015-11-18T23:53:00.000+05:302015-11-22T16:03:33.959+05:30Parse.com Android : Common Issues faced<div dir="ltr" style="text-align: left;" trbidi="on">
If you have just started in the world of BASS service, you might have chosen Parse.com.<br />
Although it has good tutorial for explaining things, still I think community support is not very good.<br />
I also had hard time to try basic things. So let me share a complete tutorial for extracting some data from Parse.com. It will be more towards covering the known issues.<br />
<br />
<b>Step 1: Uploading Data</b><br />
In Tutorial provided by Parse, they talked how you can create a ParseObject, and upload the data by putting.You can follow the Guide provided by Parse to do that. I instead use Import Data option in Data Browser. So create a Json file and upload it there. If you are facing any issue with uploading, like it should be in that particular format, I will suggest to download any existing Table such as User, and open the JSON file. Similar way you can do it. Remember the first name should be "results" only, otherwise it wont let you upload.<br />
<br />
<b>Step 2: Creating a subclass of ParseObject</b><br />
Although you can use normal ParseObject class do that, I will suggest you to use your own customized subclass of ParseObject.<br />
a) Use @ParseClassName("YOUR_CLASS_NAME") annotation.<br />
b) Keep the file name, class name and Table Name same.<br />
c) There should be default constructor of your customized sub-class.<br />
d) Create set/get method for your fields in the table.<br />
<br />
<b>Step3: Registering the subclass</b><br />
In your Application class's onCreate() method: add this line before calling Parse.initialize() :<br />
ParseObject.registerSubclass(YOUR_CLASS_NAME.class);<br />
<br />
<b>Step4: Query using the subclass</b><br />
ParseQuery<alert> query = Alert.getQuery();</alert><br />
query.findInBackground(); //see the last link to get the full code.<br />
<br />
<b>Step5: Manifest changes</b><br />
a) Please make sure you have defined the name field in <application> tag in AndroidManifest.xml. Better use the complete path.</application><br />
b) Add android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE permission.<br />
<br />
I think this covers pretty much all the points. Let me know if you face any issues with it. Sorry for lousy writing.<br />
Here is link for all <a href="http://ideone.com/YlvVY3">code</a>.<br />
<br />
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-54428086773597727512015-11-04T08:27:00.000+05:302015-11-04T08:27:00.205+05:30Unable to add Google Play Service or Appcompat library project<div dir="ltr" style="text-align: left;" trbidi="on">
It has been very long since I wrote any post about Android. So I will try now to continue the writing.<br />
<br />
If you have left Android for some time and now starting over again. You might observe that Google is no longer providing ADT (Android Development Tool) bundle. Now the new tool is Android Studio. Although it has all the related tools at one place, but it is slow and little bit hard to start with.<br />
<br />
So here is the guide for using old ADT.<br />
Download the last ADT bundle. I am using adt-bundle-windows-x86_64-20140702.<br />
You will find that it doesnt have Google Play Services project. To install it:<br />
1. Go to Sdk Manager. Its there in the same zip file of adt bundle.<br />
2. Refresh the list, in last checkbox named Extras: you can see one sub-item Google Play Services.<br />
3. Check it and install it.<br />
4. You can see that now a folder has been created in the \sdk\extras\google\google_play_services.<br />
5. Now go to eclipse, Import Android project and give the location to this google_play_services folder. <b>Don't forget to Check the Copy Projects into workspace option.</b><br />
6. That's it.<br />
<br />
Now if you want to include this project in your App's Project. Just go to project settings. In Android Option, there is a option to Add, Click on it, it will be showing your play-service/appcompat project.<br />
choose whichever is relevant to you.<br />
<br />
The same process could be followed for Appcompat Project.<br />
<br />
If you face any other issue, comment here or mail me @ rahul.lnmiit@gmail.com</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-35914390532061199882014-09-26T10:48:00.000+05:302014-11-01T21:23:21.923+05:30Device Tree in Linux <div dir="ltr" style="text-align: left;" trbidi="on">In the series of short notes on kernel concepts. Here is my new post on Device Tree. Device Tree has become a important part of linux kernel now. So lets start with it in my usual way of writing :<br /><br /><b>What is Device Tree?</b><br />- Device Tree is a tree like structure, which is used to store hardware information.<br />- It is a description of machine's hardware that is readable by the OS, so that kernel code could separated from machine specific information.<br />- So using Device tree, you can get any information from it at any point of time by parsing it.<br /><br /><b>What is the benefit of Device Tree?</b><br />- It ensures a single board file for a chipset, rest of the device specific information can be moved to device tree.<br />- Platform devices are created at run-time by the kernel by parsing the device tree nodes.<br />- we can add the devices which are not present right now, but in future they will, so no need to write the code again at later stage.<br />- So overall it steps toward the single kernel binary for all variation of chipset, which can be clubbed with specific device tree blob to create different binaries for different variation. This will reduce the time to support new platform for the chipset.<br /><br /><b>How to enable DT support ?</b><br />- First thing is create an entry in board file, between DT_MACHINE_START & DT_MACHINE_END. you need to look into a board file to understand it better. Remember you must have dt_compat field with the appropriate dt_mach structure, which will be containing the chipset details.<br />- Add your device tree source(dts) file. It have the compatible , model and id field, so it should be filled with appropriate variable. [ check /arch/arm/boot/dts/ folder for .dts file]<br />- To enable building this tree, there are 2 ways :<br />a) Enable through menuconfig -> boot options -> flattened device tree<br />or<br />b) define 'select USE_OF ' in Kconfig entry in arch/arm/Kconfig<br /><br /><b>Structure of Device Tree:</b><br /> Device tree describes a machine's hardware with a combination of<br /><br />1) <b>Nodes:</b> It represents the device or bus. Contains properties and child nodes. It is defined as node_name@unit_address.<br /><br />2) <b>Properties:</b> provides information about a device. It consists of a name and a value. Properties can further be categorized as Standard or Non-Standard.<br /><br /><b>Standard Properties:</b><br />a) compatible : it is used to distinguish between different nodes. Recommended format for compatible property is "manufacturer, model". OS can use it for machine/device driver selection.<br /><br />b) phandle : specifies an unique numerical identifier for a node with the device tree. Used by other nodes that need to refer to the node associated with the property.<br /><br />c) status : Indicate the operational status of a device. Values for this could be "okay", "disabled", "fail".<br /><br />d) #address-cells,#size-cells : May be used in any device node that has children in the device tree hierarchy. Describes how the child nodes should be addressed. #address-cells tells no of cells to encode the address field in child's reg property. #size-cells tells no of cells to encode the size field in child's reg property.<br /><br />e)reg : Arbitrary number of pairs of address and size. It describes the address and the size od the device's resources. It tells no of cells to specify address and size are specified by the #address-cells and #size-cells properties in the parent of the device node.<br /><br /><br />These are the main things. If you want more details, I will suggest you to refer Documentation/devicetree in linux kernel.</div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-85558570159303192562014-09-25T12:15:00.000+05:302014-11-01T21:23:21.973+05:30Short Notes on System Call<div dir="ltr" style="text-align: left;" trbidi="on">This post covers pretty much all main points which you need to know about System Call in Linux. These points are my notes which I covered through many blogs/sites for my study. So lets start it :<br /><div><br /></div><div><b>What is System Call ?</b></div><div>- As Linux doesn't allow user process to directly modify anything in kernel space. It has provided a way to achieve it, which is known as System Call. So basically system call provide a layer between the kernel and user space process. Using this, kernel performs user space process's task inside the kernel space. This way kernel have control on, what a user process can do.</div><div><br /></div><div><b>Why you need a System Call ?</b></div><div>- As system call is the only legal entry point to kernel, sometimes you may need some information, which can only be provided with kernel space credentials, so Kernel developers give you some system call. Although user space doesn't use it directly(in general), they uses some API for the same. </div><div>So the flow will go like </div><div><br /></div><div><b>read() ----> read() wrapper ------> system_call() ------> sys_read()</b></div><div><br /></div><div>Here first two thing is in user space and last two is in kernel space.</div><div><br /></div><div><b>How do they work ?</b></div><div>- Application program calls the API.</div><div>- A system library routine is called first.</div><div>- It transforms the call to the system standard and traps to the kernel.</div><div>- Control is taken by the kernel running in the system mode.</div><div>- According to the code, the call dispatcher invokes the responsible handler.</div><div>- Interrupt is disable during this handler.</div><div>- After call is finished, mode is changed from system mode to user mode and calling process execution resumes.</div><div><br /></div><div><b>How it works at low level ?</b></div><div>- So whenever you call any system call, it is translated to SWI <syscall_number>.</syscall_number></div><div>- Whenever processor sees SWI, it interrupts whatever is running currently( except IRQ/FIQ), changes the mode to supervisor mode(SVC).</div><div>- Whatever parameters were there in the system call, are passed using registers. </div><div>- Also PC is stored in LR of svc mode and CPSR is saved in SPSR_svc, so that we can recover the previous state while returning from SWI.</div><div>- On execution of SWI, processor looks for SWI_handler address, which was already defined in the vector table. </div><div>- From this SWI handler, processor jumps to the specific system call handler. Here we use the system call number to get the corresponding handler.</div><div>- Once the system call handler finishes its execution. Processor change the mode to user, and recover PC from LR.</div><div><br /></div><div><b>Type of System Call :</b></div><div>- Process control and IPC : fork(), exec(), pipe()</div><div>- Memory Management : malloc(), free()</div><div>- File and File System management : open(), read(), write()</div><div>- Device Management : ioctl()</div><div>- Others : kill(), signal()</div><div><br /></div><div><b>Implementation of System Call :</b></div><div>For this you can refer my previous <a href="http://kernelblogwithrahul.blogspot.in/2014/09/add-custom-system-call-in-linux-kernel.html" target="_blank">blog </a>on creating system call.</div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com1tag:blogger.com,1999:blog-3278399800766372531.post-13144034810909372902014-09-19T12:43:00.000+05:302014-11-01T21:23:21.988+05:30Add a Custom System Call in Linux Kernel<div dir="ltr" style="text-align: left;" trbidi="on">Here I will be covering a small tutorial on creating new system call in Linux Kernel. I am using Latest Kernel version 3.16 ( It is latest at the time of blog written).<div>I added my call for 32 bit system only. </div><div><br /></div><div>So the whole process is divided in 5 step.</div><div><br /></div><div><b>Step 1</b>: Open arch/x86/syscalls/syscall_32.tbl . Here go to the last line in the file. It will be containing a number in first column, this number tells that it is the last number used by system for system call. So lets say the number is 356, so your new system call will have number 357. Now just duplicate the last line, and change the number and name of the sys call. Let say it is "hello". So the whole line will look like :</div><div><br /></div><div>357 i386 hello sys_hello</div><div><br /></div><div><b>Step 2</b>: Add the syntax of syscall in include/linux/syscalls.h. Suppose this sys call takes 2 int parameters. So for syscall "hello", your new line should be like this :</div><div><br /></div><div>asmlinkage long sys_hello(int a, int b);</div><div><br /></div><div><b>Step 3</b>: Now add the entry in /kernel/sys_ni.c. So entry will be like :</div><div><br /></div><div>cond_syscall(sys_hello);</div><div><br /></div><div><b>Step 4</b>: Add the function definition for sys call. Open kernel/sys.c. you can add it at different place too. Now as our sys call is having two parameters, so the function will look like this :</div><div><br /></div><div>SYSCALL_DEFINE2(hello /*name of syscall */, int /*type of first parameter */, a /*name of first parameter*/, int /*type of second parameter */, a /*name of second parameter*/)</div><div>{</div><div>int error = -EINVAL;</div><div>// code for whatever you want to do in syscall </div><div><br /></div><div>return 0;</div><div>}</div><div><br /></div><div>That's it, your system call is created, but to reflect it in your kernel, you have to build it. you can refer my <a href="http://kernelblogwithrahul.blogspot.in/2014/03/build-kernel-from-source-code.html" target="_blank">blog </a></div><div><br /></div><div><br /></div><div><b>Step 5</b>: Test the system call. create a userspace program. Don't forget to add sys/syscall.h header. </div><div><br /></div><div>Now to call our hello syscall. </div><div><br /></div><div>int call = syscall(357, 1,2); // here 357 is our system call number, 1 is val for a and 2 for b.</div><div><br /></div><div><br /></div><div>That will be all from my side. I hope it help you to understand syscall. </div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-62218675411377774732014-07-30T07:34:00.001+05:302014-07-30T07:34:59.602+05:30Insertion Sort : In non increasing format<div dir="ltr" style="text-align: left;" trbidi="on">
Here is the pseudo code for arranging number in non increasing format using Insertion sort. This is one of the exercise of Book Introduction to Algorithms by CLRS.<br />
<br />
//N is array's length<br />
for j = N-1 to 1<br />
key = A[j];<br />
i = j + 1;<br />
<br />
while i<=N && A[i] > key<br />
A[i-1] = A[i];<br />
i = i +1;<br />
A[i-1] = key;<br />
<br />
Input : 5 4 3 2 6<br />
Output : 5 4 3 6 2<br />
5 4 6 3 2<br />
5 6 4 3 2<br />
6 5 4 3 2 [Final]</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-62400659022553423682014-07-24T13:58:00.000+05:302014-11-01T21:23:22.053+05:30Short Notes on Memory in Linux<div dir="ltr" style="text-align: left;" trbidi="on">Most of part of this blog will be containing notes from Robert Love's Linux Kernel Development. But I will try to add the general questions also in this blog.<br /><br /><br />The most basic unit of memory is page. Kernel use page structure to keep track of all the pages in the system. Through this kernel can be informed that whether page is used or free, if used then who is using it etc.<br /><br />Zone : Because of hardware limitation the kernel can't treat all pages identical. So it is divided in 3 parts mostly : ZONE_DMA(upto 16 MB), ZONE_NORMAL(16 to 896 MB) and ZONE_HIGHMEM(896 & above).<br /><br />Main limitation to divide pages in Zone are:<br />1. Some hardware devices can perform DMA to only certain memory address.<br />2. Some memory can't be permanently mapped into kernel address space.(eg: HIGMEM)<br /><br /><b>Page allocation interface :</b><br /><br />1. struct page * alloc_pages(gfp_t gfp_mask, unsigned int order) : This returns 2 to the power order pages contiguous physical page. As this function returns a page pointer, to get the logical address of it, we use page_address(struct page * page) method.<br />2. unsigned long __get_free_pages(gft_t gfp_mask, unsigned int order) : it returns the logical address.<br />3. unsigned long get_zeroed_pages(gfp_mask) : it is useful for page allocated for user space, as it zeroes the content of allocated page, so that sensitive data doesn't pass to user space.<br />4. void * kmalloc(size_t size, gfp_t flags): this function returns a pointer to a region of memory that is atleast size bytes in length. This memory is physically contiguous.<br />5. vamlloc() : it allocates virtually contiguous memory. It does this by allocating potentially non contiguous chunks of physical memory and fixing the page table to map the memory into a contiguous chunk of virtual memory.<br /><br /><b>Deallocation interface :</b><br /><br />1. __free_pages(struct page *page, unsigned int order) : Always ensure you are deallocating only those page which you allocate.<br />2. kfree(const void *ptr)<br />3. vfree(const void *ptr)<br /><br /><b>Introduction to Slab Layer:</b><br />Allocation and deallocation memory is the most common operation in Kernel. Because of it, there is good chance of de-fragmentation. Which is complete waste of resources, as you are having the free memory but you cant use it as it is not contiguous.<br />To resolve this issue, Linux kernel came up with the slab layer concept. So most frequently used data structure is allocated through cache. At the start-up we create the caches for all major data structure. Cache is further divided in slab. And slab contains a page. Apart from that Cache also maintain 3 list, empty list, full list and partial list.<br />So whenever allocation request comes, Cache check whether any empty page is there on any of the list. It allocates there and then return the page. Once that structure is released, the corresponding page is also released and return back to the free list.<br /><br />This was the basics, now lets try with questions which I faced, these questions may not in order of relevance:<br /><br /><b>1. What is the return address of kmalloc() ? Physical or Virtual?</b><br />Ans : it always return the virtual address, and the allocated memory region will be physically as well as virtually contiguous.<br /><br /><b>2. How memory is allocated for program ?</b><br />Ans : When ever program compilation is done. At the time of loading, First program is loaded in memory, then mapped it to the Virtual memory. So it will be having page table with no association with physical memory. At the time of use, means when you want some memory for operation, it goes to page table, there MMU find that no physical memory is allocated, so it do the page_fault(). Then the physical memory is allocated and corresponding entry is created in the page table.<br /><br /><b>3. logical address and virtual address ?</b><br />Ans : Most important thing is logical address comes in picture if you have segmentation unit in your system. If it is not there then there is no logical address. So the address translation happens like this :<br /> logical address => [segmentation unit] => virtual address => [paging unit] => physical address<br /><div><br /></div><div><b>4. Why physically contiguous memory region is more efficient than virtually contiguous memory?</b></div><div>Ans : As memory allocated is physically contiguous can use a concept called huge pages. With this higher page size can be used, so correspondingly there will be lesser page entries in the table.<span style="background-color: white;">Huge pages can improve performance through reduced page faults (a single fault brings in a large chunk of memory at once) and by reducing the cost of virtual to physical address translation (fewer levels of page tables must be traversed to get to the physical address). </span><br /><span style="background-color: white;"><br /></span><span style="background-color: white;"><b>5. How Shared memory is used?</b></span><br /><span style="background-color: white;">Ans : For shared memory we use IPC like shmem. So whenever two process wants to share some memory. They use shmem IPC to get an id for the associated memory, further this shared memory is mapped to both processes's address space. So for those process it looks like local memory. Internally the vm_area_struct (virtual memory area) uses VM_SHARED flag to show this memory area as shared memory.</span><br /><span style="background-color: white;"> Also when we create a child process with CLONE_VM flag, at the time of creation it skips the allocate_mm() call (which is actually responsible for memory allocation) and assign it's mm structure to its parent's mm structure. </span><br /><span style="background-color: white;"><br /></span><span style="background-color: white;"><b>6. Where does the memory is allocated for kernel stack ?</b></span><br /><span style="background-color: white;">Ans : Kernel stack is allocated in the kernel space, remember not is user space memory. But it is mapped to that Process's address space, not only that but to all other process's address space. As apart from kernel no body will be using this, so it no process is able to recognize it and they don't have permission to access it.</span><br /><span style="background-color: white;"><br /></span><span style="background-color: white;"><b>7. Can a process use whole 4 GB address ?</b></span><br /><span style="background-color: white;">Ans : No, it can't. Remember, memory is divided in memory area. So a process can only access only those memory areas for which it has permission. Even to add or remove memory area, it has to request kernel.</span></div><div><br /></div><div><br /><div><br /><br /></div></div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com1tag:blogger.com,1999:blog-3278399800766372531.post-39592033859540978962014-06-29T18:32:00.000+05:302014-06-29T18:32:43.440+05:30How to Submit android app to Amazon app store<div dir="ltr" style="text-align: left;" trbidi="on">
If you are new to android development and specifically planning to launch your app to Amazon app store. Then you must be feeling a little bit left behind, because there you won't find much over net apart from Amazon's own material. <div>
<br /></div>
<div>
Although it is mentioned on their site clearly, I thought of repeating it, because it will just some one else to find the right thing :</div>
<div>
<br /></div>
<div>
So if you want to add the ad api so here is the way : </div>
<div>
<br /></div>
<div>
1. Download sdk from <a href="https://developer.amazon.com/public/resources/development-tools/sdk">here</a>.</div>
<div>
2. Now add the Jar in Eclipse using Install New Software. After that add this <a href="http://developer.amazon.com/eclipse">link</a> as name Amazon.</div>
<div>
3. Now Import your android project, remove all the google play service api from it, and add Amazon api. To do that right click on your project, and click on Properties. And then in that click on Amazon Mobile app SDK. </div>
<div>
4. There you can select whatever you want to use, Mobile Ads, ADM, In-App purchasing etc.</div>
<div>
5. Now it comes to the coding part. Wherever you want to use it, include the following code :</div>
<div>
<br /></div>
<div>
AdRegistration.setAppKey("37de83fd21234ed4811e241507876542F"); // put your Application id</div>
<div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> </div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> this.adView = (AdLayout) findViewById(R.id.adview);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> </div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> AdTargetingOptions adOptions = new AdTargetingOptions().enableGeoLocation(true);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Optional: Set ad targeting options here.</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> this.adView.loadAd(adOptions); // Retrieves an ad on background thread</div>
</div>
<div>
<br /></div>
<div>
And you have to create corresponding entry in xml :</div>
<div>
<br /></div>
<div>
<div>
<com .amazon.device.ads.adlayout="" div=""><div>
<span class="Apple-tab-span" style="white-space: pre;"> </span> android:id="@+id/adview"</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_width="match_parent" </div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>android:layout_height="wrap_content"/></div>
</com></div>
<div>
<br /></div>
<div>
6. And you are good to go. </div>
<div>
7. Use Test your app option on Amazon before uploading your apk to Amazon app store.</div>
<div>
<br /></div>
<div>
I hope this blog help you to publish your first App on Amazon app store.</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-21223483356403215292014-06-26T19:09:00.000+05:302014-06-26T19:09:36.069+05:30Android : How to Check whether device is rooted or not ?<div dir="ltr" style="text-align: left;" trbidi="on">
Many time user go for rooting their phone to break the constraints put by operator and OEMs. <div>
So Rooting your phone opens a door of new features which could be really useful. </div>
<div>
<br /></div>
<div>
To root your phone, I will suggest you to go to <a href="http://www.xda-developers.com/">Xda developers</a>. They have wide range of tutorial specifically for each devices. So once you have followed their steps, and just wanted to confirm whether your device has been rooted, Here is a simple app called <a href="https://play.google.com/store/apps/details?id=com.bitdroid.rootverifier">Root Verifier Pro</a> Launched by <a href="https://play.google.com/store/apps/developer?id=Bitdroid+Devz">Bitdroid Devz</a>. </div>
<div>
<br /></div>
<div>
I will suggest you to try it, it worked fine for me. </div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-17089672988159550962014-06-19T14:28:00.000+05:302014-06-19T14:28:54.008+05:30HWComposer : Android Surface Composition Logic Module<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif;">After my last post of SurfaceFlinger few people asked me to write on HWcomposer, which is tightly associated with SurfaceFlinger. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;">I here would like to mention that Google's Graphics Architecture <a href="http://source.android.com/devices/graphics/architecture.html">link</a> helped me a lot. So I will be mentioning many of those points here again.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">So here we go </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">HWComposer(HWC)'s primary purpose is to determing the most efficient way to composite buffers with the available hardware.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">You can easily recognize the value of HWC, when you consider "overlay planes". The purpose of overlay planes is to composite the multiple buffers together, but in the display hardware(MDP in case of QCom) rather than the GPU. You can refer this link for <a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvHBoWH91c7bED1A1lvcKCdhu-LOBn6WdcuhDnQyTshFpDfmcqBHaM7M5QKF7FaZNxOpf0DMt4yeVs5c0BKhH_jAi9sdxKg23DhFRXvCbjFdbxe055M9dPpTjrisw5hpSj_SP75dsVap0/s1600/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7+2014-02-15+%E4%B8%8B%E5%8D%889.44.58.png">diagram</a>.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">The mentioned link describes it very well, it goes like :</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">In General you have three buffers for Android screen at a time, one for Status bar, second for Navigation bar and third for Application. So instead of compositing all three buffers, SurfaceFlinger pass these buffers to Display Hardware to process. So HWC works like this :</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<li style="background-color: #f9f9f9; color: #222222; font-size: 14px; line-height: 19px; margin: 0px 0px 5px;"><span style="font-family: Trebuchet MS, sans-serif;">SurfaceFlinger provides the HWC with a full list of layers, and asks, "how do you want to handle this?"</span></li>
<li style="background-color: #f9f9f9; color: #222222; font-size: 14px; line-height: 19px; margin: 0px 0px 5px;"><span style="font-family: Trebuchet MS, sans-serif;">The HWC responds by marking each layer as "overlay" or "GLES composition."</span></li>
<li style="background-color: #f9f9f9; color: #222222; font-size: 14px; line-height: 19px; margin: 0px 0px 5px;"><span style="font-family: Trebuchet MS, sans-serif;">SurfaceFlinger takes care of any GLES composition, passing the output buffer to HWC, and lets HWC handle the rest.</span></li>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Now as mentioned in 3rd point, Surfaceflinger passes the output buffer to HWC. This is quite useful when there is no update in the screen. In this scenario, HWC can choose GLES composition for those buffer. Because of this, When Surfaceflinger comes up with the same set of buffers(as no screen is changed), HWC can just continue to show the previously composite buffer.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Code Flow:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Linking of hwc module :</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">SurfaceFlinger::init() -> HWComposer() -> loadHWCModule() -> hwc_open_1 -> (module->methods-->open) ->open() [defined in hwc.cpp]</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"> Now whenever Surfaceflinger have new buffers to update, it calls setupHWComposer(). This function is used to get all layers, using </span><br />
<span style="font-family: Trebuchet MS, sans-serif;">currentLayers = hw->getVisibleLayersSortedByZ();</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">after setting the data, it calls prepare() which in turns call prepare()[hwc.cpp][I will definde the details of this function later].</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">After all processing and composition is done, we call postFrameBuffer(), it calls commit() and finally hwc::set(). Which goes like this :</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">hwc::set() -> hwc_set_primary() -> (mFbUpdate->draw())* -> ov.queueBuffer() -> GenericPipe::queueBuffer() -> Data:queueBuffer()(OverlayCtrlData.h) -> MdpData:play()(overlaymdp.h) -> play()(MdpWrapper.h) ->ioctl(fd,MSMFB_OVERLAY_PLAY,offset)</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">this fd and offset it is getting from </span><br />
<span style="font-family: Trebuchet MS, sans-serif;">fbLayer = &list->hwLayers[last];</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">hnd = (private_handle_t *) fbLayer->handle;</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">after (mFbUpdate->draw()) calls finishes, flow goes like </span><br />
<span style="font-family: Trebuchet MS, sans-serif;">(Overlay->displayCommit()) -> displayCommit()(Overlay.cpp) -> displayCommit()(MdpWrapper.h) -> ioctl(fd, MSMFB_OVERLAY_COMMIT, info)</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">After this lcd driver starts doing the final task.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Now lets understand what prepare() function do. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">prepare is called for each frame before composition and is used by SurfaceFlinger to determine what composition steps the HWC can handle. </span><br />
<span style="font-family: Trebuchet MS, sans-serif;">The HWC responds by setting the compositionType field in each layer to either HWC_FRAMEBUFFER or HWC_OVERLAY.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">In case of HWC_FRAMEBUFFER, composition is handled by SurfaceFlinger using OpenGL ES, in later case HWC will have to handle the layer's composition.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Now other important function in hwc.cpp is set(). When this call returns the caller assumes that the display will be updated in the near future with the content of their work list.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br /></div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-30012141167983568652014-06-11T12:18:00.000+05:302014-11-01T21:23:22.067+05:30difference between Kernel Thread and User thread<div dir="ltr" style="text-align: left;" trbidi="on">1. Kernel threads run only in Kernel Mode, while regular processes run alternatively in Kernel Mode and in User Mode.<br /><br />2. Because kernel threads run only in Kernel Mode, they use only linear addresses greater than PAGE_OFFSET. Regular processes, on the other hand, use all four gigabytes of linear addresses, in either User Mode or Kernel Mode.<br /><br />Process 0 :<br />This is the ancestor of all processes, also known as the idle process. it is a kernel thread created from scratch during the intialization phase of linux. This ancestor proces uses the following statically allocated data structures.<br /><br />1. A process descriptor stored in the init_task variable, initialized by the INIT_TASK macro.<br />2. A thread_info descriptor and a Kernel Mode stack stored in the init_thread_union variable and initialized by the INIT_THREAD_INFO macro.<br />3. The following tables, which is the process descriptor points to:<br /><br />- init_mm ( initialized by INIT_MM)<br />- init_fs (initlialized by INIT_FS)<br />- init_files (initlialized by INIT_FILES)<br />- init_signals(initialized by INIT_SIGNALS)<br />- init_sighand(initialized by INIT_SIGHAND)<br /><br />4. The master kernel Page Global Directory stored in swapper_pg_dir.<br /><br />The start_kernel() function intializes all the data structures needed by the kernel enables interrupts, and creates another kernel thread, named process 1 (known as init process).<br /><br />After creating init process, Process 0 is selected by scheduler only when there are no other processes in the TASK_RUNNING state.<br /><br />For multiprocessor system, there is a process 0 for each CPU.<br /><br /></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-64413736999088813802014-06-02T23:29:00.000+05:302014-06-02T23:29:26.309+05:30Check if a character link list is palindrome or not.<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Hi Folks,<br />
<br />
Here is my implementation for checking whether link list is palindrome or not.<br />
<br />
#include <iostream><br />
#include <stack><br />
#include <cstdlib><br />
<br />
struct node<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>int data;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>struct node *next;<br />
};<br />
<br />
using namespace std;<br />
<br />
struct node *head;<br />
<br />
void addNode(int data)<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>struct node *temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>temp = (struct node *) malloc(sizeof(struct node));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>temp -> next = NULL;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>temp->data = data;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(head == NULL)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head = temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>struct node *head1;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head1 = head;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>while(head1 ->next != NULL)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head1 = head1->next;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head1->next = temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
int main()<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>int N;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>cin >> N;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>for(int i=0;i<N;i++)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>int temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>cin >> temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>addNode(temp);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>struct node *slow, *fast;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>stack<int> stk;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>slow = head;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>fast = head;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>while(fast->next != NULL)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>stk.push(slow->data);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>slow = slow->next;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>fast = fast->next;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(fast->next != NULL)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>fast = fast->next;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(N %2 != 0)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>slow = slow->next;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>while(!stk.empty())<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//<span class="Apple-tab-span" style="white-space: pre;"> </span>cout << (stk.top()) <<" " << (slow->data) <<endl;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(stk.top() == slow->data)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>slow = slow->next;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>stk.pop();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>cout <<"No Pallindrome" <<endl;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return false;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>cout <<"Pallindrome" <<endl;//return true;<br />
}</div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-48003617740003197552014-06-01T16:56:00.000+05:302014-06-01T16:56:27.462+05:30Generate all combination of elements of an array : Power Set Algorithm<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
#include <iostream></iostream></div>
<div>
#include <vector></vector></div>
<div>
#define MAX 100010</div>
<div>
using namespace std;</div>
<div>
<br /></div>
<div>
int arr[MAX];</div>
<div>
<br /></div>
<div>
void powerset(int arr[], vector<int> v, int start, int end)</int></div>
<div>
{</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>if(start > end)</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>v.push_back(arr[start]);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>vector<int>::iterator i;</int></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>for(i = v.begin(); i<v .end="" div="" i=""><div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>{</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cout << *i;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cout << "\n";</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>powerset(arr,v,start+1,end);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>v.pop_back();</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>powerset(arr,v,start+1,end);</div>
<div>
<br /></div>
<div>
}</div>
<div>
<br /></div>
<div>
int main()</div>
<div>
{</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>int T,N;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cin >> T;</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>while(T-- > 0)</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>{</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cin >> N;</div>
<div>
<br /></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>for(int i=0;i<n div="" i=""><div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>cin >> arr[i];</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>vector<int> v;</int></div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>powerset(arr,v,0,N-1);</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span>return 0;</div>
<div>
}</div>
<div>
<span class="Apple-tab-span" style="white-space: pre;"> </span></div>
</n></div>
</v></div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-11396991700613137082014-05-28T07:20:00.001+05:302014-05-28T07:20:12.146+05:30Notes on Insertion Sort<div dir="ltr" style="text-align: left;" trbidi="on">
Insertion Sort is a way of sorting elements. While using insertion sort, we traverse from right to left element.<br />
<br />
Steps :<br />
<br />
1. Assume 0th element is already sorted.<br />
2. Starting i from first element till last :<br />
- In a loop(j ), check if the previous element is greater than the comparing element( for example for first time, we will be comparing 1st element to 0th element.)<br />
- If previous element is greater than comparing element, we will replace the j+1th element with j.[Remember before doing this keep array[i] stored in some variable, as it will be compared to all elements].<br />
- when loops finished, just replace the last index element with array[i] stored value.<br />
<br />
<br />
Code :<br />
<br />
for(i =1; i<n i="" p="">{<br />
int val = arr[i];<br />
int j = i-1;<br />
<br />
while( j >=0 && A[j] > val)<br />
{<br />
A[j+1] = A[j];<br />
j--;<br />
}<br />
<br />
A[j] = val;<br />
}</n></div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-56609893088773974892014-04-23T18:04:00.000+05:302014-11-01T21:23:22.118+05:30kmalloc() V/S other page allocation methods<div dir="ltr" style="text-align: left;" trbidi="on">If you are developing anthing in Kernel, I hope you have used kmalloc() many times till now. But if you see there are other function also to allocate physical memory. Those are :<div><br /><div>__get_free_page(unsigned int gfp_mask)</div><div>__get_free_pages(unsinged int gfp_mask, int order)</div><div>get_zeroed_page(unsigned int gfp_mask)</div><div><br /></div><div>So when we use kmalloc() and when we use the above functions ?</div><div>Answer lies in your requirement, if you need very small memory to allocate, go for kmalloc, because there you define the minimum no of bytes(let say n) you need to allocate. But remember it just ensure that atleast n bytes will be allocated, but in reality, it allocates more than it, sometimes even double of the size. So in short there is no fine granuality with kmalloc().</div><div><br /></div><div>while get_free_page family is used when you want to allocate memory in terms of pages, as for kernel, page is the smallest memory unit. So you will pass the order x, and it will return you 2 power x pages. So here Kernel ensures that only requested no of pages will be allocated. So there will not be any memory waste.</div><div><br /></div><div>And if you want to allocate memory from high memory, then there is a seperate function : [Although these function can be used for normal zones too]</div><div><br /></div><div>alloc_pages(unsinged int gfp_mask, unsigned int order)</div><div>alloc_pages(unsinged int gfp_mask)</div><div><br /></div><div><br /></div></div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-12688672682839072872014-04-20T14:40:00.001+05:302014-04-20T14:41:12.457+05:30Short Note on Android App Signing<div dir="ltr" style="text-align: left;" trbidi="on">
I know you will find many articles for mentioned title. But I thought of summarizing it , So Here are the steps :<br />
<br />
1. You need Keytool and Jarsigner. If you have java installed in your system, then you have these utilities.<br />
<br />
2. Now generate a private key for your app, So here is the command :<br />
<b><i>keytool -genkey -v -keystore my-release-key.keystore -alias ANY_NAME -keyalg RSA -keysize 2048 -validity 10000</i></b><br />
<br />
This will ask you few basic question, answer those. finally it will ask the password, give it, this will encrypt your keystore file.<br />
<br />
3. I hope as you are an android developer, you must be having Eclipse with you. So Go to File -> export -> Android -> Export Android Application.<br />
<br />
4. Select the project from which you want to export the application.<br />
<br />
5. Select keystore, remember in step 2 you created my-release-key.keystore, give path to this file. And entered the password you have entered at the time of creation.<br />
<br />
6. Next it will ask key alias selection, So whatever ANY_NAME you given in step2, choose that and again give the password.<br />
<br />
7. Finally it will ask you the location, where the signed application will be exported. So just give the path and click finish.<br />
<br />
And you are done.<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-2643589784284797642014-04-14T07:29:00.001+05:302014-04-14T07:29:51.568+05:30Create a structure which can contain any type of data <div dir="ltr" style="text-align: left;" trbidi="on">
Generally whenever we create a structure, we define that what kind of data it will be storing. But think it this way, what if you don't know what kind of data structure it can use in future, to avoid that situation. Here is the way :<br />
<br />
#include <stdio .h=""></stdio><br />
#include <stdlib .h=""></stdlib><br />
struct node<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>void *ptr;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>struct node *link;<br />
};<br />
int main(void) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// your code goes here<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>struct node *head,*temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>float var = 10.5f;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head = (struct node *)malloc(sizeof(struct node));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>*(int *)(head->ptr) =10;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head->link = NULL;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>temp = (struct node *)malloc(sizeof(struct node));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>*(float *)(temp->ptr) = var;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>temp->link = NULL;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>head->link = temp;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>printf("Value = %d",*(int *)(head->ptr));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>printf("Value = %f",*(float *)(temp->ptr));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return 0;<br />
}<br />
<br />
Hope it helps you in your next interview :)<br />
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-52642828379317542972014-03-21T14:51:00.000+05:302014-11-01T21:23:22.188+05:30Mutex Vs Binary Semaphore<div dir="ltr" style="text-align: left;" trbidi="on">Most of the time people get confused with these two. So here I will try to explain the difference using this <a href="http://stackoverflow.com/a/86021/769260" target="_blank">answer </a>at Stack Overflow.<br /><br />So Mutex is a lock which have the owner association, So it means whoever holds the mutex lock will only be able to unlock this mutex. So Mutex is used when you want to lock the resources.<br /><br />While Binary Semaphore is used for signalling mechanism, It doesn't lock the resource. So any other thread can also unlock the semaphore held by your thread. In other words it signals your thread to do something.</div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-8752366486764723362014-03-20T15:47:00.000+05:302014-11-01T21:23:22.200+05:30GDB : Debugger for simple c file<div dir="ltr" style="text-align: left;" trbidi="on">Hi,<br /><br />It may be out of track article for kernel, but it could be good if you have single file.<br />So GDB is a debugger utility in linux for debugging C/ C++ program.<br /><br />Step 1 : So first how you will enable your program to do so :<br />In your compilation command, use -g option, for example :<br />gcc -g program.c -o program<br /><br />Step 2 : Now to run the utility, just type gdb on the shell. It will give you something like (gdb) shell<br /><br />Step 3: Load the file which you want to debug,<br /> (gdb) file filename.c<br /><br />Step 4 : Put break points at lines<br /> (gdb) break filename.c : Line number<br /> Put break points at function<br /> (gdb) break func_name<br /><br />Step 5 : type run. It will run till it reaches your first break point.<br /><br />Step 6 : Now suppose you want to check the value of some variable use print<br /> (gdb) print x<br /><br />Step 7 : If you want to just go to next break point, just type<br /> (gdb) continue<br /><br />Step 8 : If you want to go step by step, use either next/step command.<br /> (gdb) next<br /> or<br /> (gdb) step<br /> Only difference is, next will treat any sub-routine call as a single instruction.<br /><br />Now apart from break point there is one more concept as Watch point, it works on variable instead of function or line number. It will stop code execution when the value of variable on which watchpoint is set, has been changed. Syntax is<br />(gdb) watch variable_name <br /><br />There are other command also<br /><br />1. backtrace - produces a stack trace of the function calls that lead to a seg fault (should remind you of Java exceptions)<br />2. where - same as backtrace; you can think of this version as working even when you’re still in the middle of the program<br />3. finish - runs until the current function is finished<br />4. delete - deletes a specified breakpoint<br />5. info breakpoints - shows information about all declared<br />breakpoints<br /><br />Also we can use condition in breakpoints, for example you want to break only when i < 1,so do like this :<br />(gdb) break program.c : 7 if i < 1.<br /><div><br /></div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-40315129932783006232014-03-18T21:20:00.000+05:302014-11-01T21:23:22.254+05:30Build kernel from source code<div dir="ltr" style="text-align: left;" trbidi="on">If you are newbie to the kernel, It is a matter of time when you have to download kernel source and build it. Although working in Linux kernel domain for 2 years, I never did it earlier, so finally today I did it because of <span style="background-color: white; color: #555555; font-family: arial, sans-serif; font-size: 13px; white-space: nowrap;"><a href="http://eudyptula-challenge.org/">eudyptula-challenge.org</a>.</span><div><span style="background-color: white; color: #555555; font-family: arial, sans-serif; font-size: 13px; white-space: nowrap;"><br /></span></div><div>So here are the steps, you should do to build your kernel. </div><div><br /></div><div>Step 1 : Download the source code from git.</div><div><br /></div><div>Step 2 : Set up the config file. It is the file which tells at the time of booting what all configuration needed to be enabled. So easiest way to create config file <span style="background-color: white; font-family: arial, sans-serif; font-size: 13px;">sudo make localmodconfig</span></div><div><span style="background-color: white; font-family: arial, sans-serif; font-size: 13px;"><br /></span></div><div>Step 3 : Further if you want to modify any change in config file, use <span style="background-color: white; font-family: arial, sans-serif; font-size: 13px;">sudo make menuconfig.</span><span style="background-color: white; color: #500050; font-family: arial, sans-serif; font-size: 13px;"> </span>Now change any configuration you want, you can select y/n/m.</div><div><br /></div><div style="text-align: left;">Step 4 : Now its time to build your kernel, you can use either make or you can use <span style="background-color: white;"><span style="font-family: inherit;">make deb-pkg</span></span></div><div><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><br /></span></div><div>Step 5 : To install the image, </div><div>- If you used make earlier, then call make install.</div><div>- If you used make deb-pkg, then <span style="background-color: white; font-family: inherit;">install the image first:</span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;">sudo dpkg -i linux-image-3.14.0-rc6-00145-</span><wbr style="background-color: white;"></wbr><span style="background-color: white;">ga4ecdf8_3.14.0-rc6-00145-</span><wbr style="background-color: white;"></wbr><span style="background-color: white;">ga4ecdf8-8_i386.deb</span><br style="background-color: white;" /><span style="background-color: white;">Then install the headers :</span><span style="background-color: white;">sudo dpkg -i linux-headers-3.14.0-rc6-</span><wbr style="background-color: white;"></wbr><span style="background-color: white;">00145-ga4ecdf8_3.14.0-rc6-</span><wbr style="background-color: white;"></wbr><span style="background-color: white;">00145-ga4ecdf8-8_i386.deb</span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;"><br /></span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;">you can replace the version accordingly in above commands.</span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;"><br /></span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;">After reboot, you will be able to see the new linux kernel in your grub list.</span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;"><br /></span></span></div><div style="text-align: left;"><span style="font-family: inherit;"><span style="background-color: white;"><br /></span></span></div><div style="text-align: left;"><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><br /></span></div><div><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 13px;"><br /></span></div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0tag:blogger.com,1999:blog-3278399800766372531.post-24443074397463099102014-03-18T12:32:00.000+05:302014-11-01T21:23:22.268+05:30ARM 3-Stage Pipeline<div dir="ltr" style="text-align: left;" trbidi="on"><b>What is Pipeline?</b><br />Pipeline is used to improve the perforamnce of the overall system by allowing multiple instructions(which are in different stage) parallely. So first understand the 3 stages of pipeline :<br /><br /><div style="text-align: center;"><b>Fetch--------> Decode -----------> Execute</b></div><br />As per their names, In Fetch, we fetch the instructions, in Decode we decode the instruction and finally execure in Execute stage.<br /><br />So keeping these 3 stages in mind, Whenever instuction 1 is in Executing stage(as it started first), instruction 2 will be in Decoding stage and instruction 3 will be in Fetching stage.<br /><br />So if you see this, then there will not be any improvement for a single instruction, as every instruction will be taking the same 3 cycles to execute. But the overall performance will be improved.<br /><br /><b>Problem with pipeline: </b><br />As like all other good things in the world, pipeline also have it share of cons. Pipeline creates problem when there is a branch instruction, because whenever branch instruction is in executing stage, It has to go to some other instruction instead of the instruction which processor had taken in fetch/decode stage while branch instruction was in fetch/decoding stage. I know it may be confusing, so lets understand this with an example:<br /><br />[As I dont know assembly language, instruction syntax can be different what you expect]<br />1. ADD R1,R2,R3 [Add R2, R3 and keep it in R1]<br />2. ADD R2,R3,R4<br />3. SUB R3, R4,R5<br />4. JMP X<br />5. ADD R2,R3,R4<br />6. SUB R3, R4,R5<br />7. X:<br />8. ADD R1,R2,R3<br /><br /><br />So you can see when instruction 4(JMP) will be in execution stage, instruction 5 will be in decode stage and instruction 6 in fetch stage. But as isntruction 4 is a jump statement, thee is no use of executing instruction 5 and 6.<br /> In that case pipeline will be flush, and next 2 cycle will be waste. As for instruction 7 to execute, you will need 2 cycle, and as there is no eligible instruction to execute in pipeline, there will not be any output during this cycle.<br /><br />So it is not necessary that pipeline will always improve performance.<br /><br /><b>Branch Prediction:</b><br />To overcome this problem caused by pipeline, Architecture came up with branch prediction. It tries to predict which could be executed next, . There are different ways to achieve this, I am not covering those here. you can refer wikipedia or ARM information center.</div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com2tag:blogger.com,1999:blog-3278399800766372531.post-11610622108541953182014-03-16T10:55:00.000+05:302014-11-01T21:23:22.329+05:30Cache Management in ARM<div dir="ltr" style="text-align: left;" trbidi="on"><b>What is Cache?</b><br /><div>Cache is a place where a processor can put data and instruction. </div><div><br /></div><div><b>Why we need Cache?</b></div><div>As we know accessing memory to fetch instructions and data is way slower than processor clock, so fetching any instruction from the memory can take multiple clock cycle. To improve this scenario, ARM provides the concept of Cache, it is a small, fast block of memory which sits between processor core and memory. <b>It holds copies of items in main memory.</b> That way we have kept one intermediate small memory which is faster than main memory.</div><div><br /></div><div><b>How it works?</b></div><div>If we have cache in our system, there must be a cahce controller. Cache controller is a hardware which manages cache without the knowledge of programmer. So whenever processor wants to read or write anything, first it will check it in the cache, this is called cache lookup. If it is there it will return the result to processor. If required instruction/data is not there, it is known as cache miss. And request will be forwarded to main memory.<br /> Apart from checking whether data/instruction existence in the cache, there is one more thing in core, which is a write buffer. Write buffer is used to save further time for processor. So suppose processor wants to execute a store instruction, what it can do is, it can put the relevant information such as which location to write, which buffer needs to copy, and what is the size of buffer which is getting copied into this write buffer, after that processor is free to do take next instruction, Write buffer will then put this data into the memory.<br /><br /><b>Level of Cache:</b><br />There are generally two caches(L1 and L2), some architecture have only one cahce(L1) too.<br />L1 caches are typically connected directly to the core logic that fetches instructions and handles load and store instructions. These are Harvard caches, that is, there are separate caches for instructions and for data that effectively appear as part of the core. Generally these have very small size 16KB or 32KB. This size depends on the capability of providing single cycle access at a core speed of 1GHz or<br />more.<br /> Other is L2 cache, these are larger in size, but slower and unified in nature. Unified because it uses single cahce for instructions and data. L2 cache could be part of core or be a external block.<br /><br /><b>Cache Coherency:</b><br />As every core has its own L1 cache, It needs a mechanism to maintain the coherency between all the caches, because if one cache is updated and other is not, This will create data inconsistency.<br />There are 2 ways to solve this scenario:<br /><br />1. <b>Hardware manage coherency</b> : It is the most efficient solution. So the data which is shared among caches will always be updated. Everything in that sharing domain will always contain the same exact value for that share data.<br />2. <b>Software manager coherency</b> : Here the software, usually device drivers, must clean or flush dirty data from caches, and invalidate old data to enable sharing with other processors or masters in the system. This takes processor cycles, bus bandwidth, and power.</div></div>Anonymoushttp://www.blogger.com/profile/03456236290590717915noreply@blogger.com0