Slow disk access and overall speed issues in newer ubuntu and linux mint

April 10, 2017 Leave a comment

I have the subjective feeling that the newer versions of ubuntu and its derivatives including linux mint has slowed up a bit compared to pre unity ubuntus(11.04) or linux mint 17. I had been looking for the reason for some time. This probably won’t apply to you unless you are using a slow ‘hard disk’. The symptom is that subjectively the disk access latencies are larger (eg. applications take longer to start).

Linux has a software component called the IO scheduler. This takes care of scheduling requests to the permanent storage devices. There are a few choices for the algorithm to be used for this purpose. The choices and current selection can be seen by issuing

cat /sys/block/sda/queue/scheduler

(For me the sda is the drive containing all linux partitions. It may change for you ie. sda, sdb, sdc.. or hda, hdb, hdc…)

The default in modern ubuntu and linux mint is the ‘deadline‘ scheduler; probably a decision based on benchmark performance results on modern hardware. I changed this to ‘cfq‘, and subjectively the system became a lot more responsive. You can temporarily tryout the setting by writing the new scheduler name to the above file using command

sudo sh -c 'echo cfq > /sys/block/sda/queue/scheduler'

If you find think system responsiveness is better than before, you can make the changes permanent by writing following settings to /etc/default/grub and running update-grub2

sudo vim /etc/default/grub

Type the setting


Exit editor.


From next reboot onwards the setting should now takeplace at boot itself.


Area vs Time: A look at algorithmic complexity in Hardware and Software

Many of us would have studied in our college that implementing something in hardware will be faster than implementing the same in software. What i see from this situation is a time complexity being converted into area complexity. And the benefits provided by pipelining, and reduced control overhead resulting from special purpose control implementation (As opposed to more generic&bulky control logic required by a general purpose CPU).

My own recent expeditions in this area suggest something that is not so obvious. The inverse proportion between Logic Area and Time starts after a discontinuity. Some algorithms will benefit substantially if a very minimal part of the algorithm is implemented in hardware. Beyond that point the Area vs Time relation will be an inverse proportional relation.

I would call these minimal logic that brings in huge value add as a ‘primitive function’. Now a little bit of theory. A general purpose processor does some sort of data manipulation function (eg. add, subract, multiply, divide, compare shift etc..) between two registers. Basically for a simple RISC 32 bit processor, whose instruction set is capable of taking 2 32 bit register operands and producing 1 32 bit register output, there is some combinational logic between the 64bit input and 32 bit output, depending on the current instruction. The typical instruction set of a RISC is <256 instruction. Is this enough to do all the possible function mapping from a 64 bit input to a 32 bit output domain?. No certainly not. You can always have one function that mirrors one of the 32 bit input to the output.

So for any of the general purpose processors, it is not possible to implement all the possible function mapping from a 2 word space to a 1 word symbol space. Instead it just implements the most commonly used function mappings like add, subtract, boolean operators, shifts etc. If you take the case of mirroring of bits in a 32 bit word, it will sure take at-least 32 cycles to do it in a general purpose CPU. But implementing a mirroring in hardware doesn’t consume much logic. But instantly reduces the time required for computation of the mirror by a large amount.

So if you are tasked with implementing custom hardware constrained by area, the first thing to ask is: is my CPU capable of supporting all the primitive logic function, relevant for the algorithms in use.

TODO: To be updated with some rough sketches indicating my idea

Categories: Philosophy, Tech, Viewpoints Tags:

Building gcc as cross-compiler


A cross-compiler is a compiler that runs on your PC and reads source code in your PC and converts that into binary suitable for some other CPU. Sometimes the precise cross compile tool may not be available as a binary package. For example, in my case i wanted to use bare-metal x86 tools(To build BIOS or similar low level system software). It was not available as binary package. Hence only option is to build it.


The packages and libraries needed to build gcc are well documented along with gcc. If you usually build softwares on your linux build PC, there are not much extra dependencies on the PC. One important dependency to build cross gcc is you should already have cross binutils for the same platform. And the binaries especially linker(ld) and assembler(as) should be available in the path. Eg. to build i686-elf-gcc, i686-elf-ld and i686-elf-as should be available in the system path. So

  1. Step 1 is to build binutis
  2. Step 2 is to build gcc

Further I will list the steps needed to build the cross gcc; specifically the i686-elf variant

Step 1: Build binutils as cross-tool

Download binutils. Extract, configure from a separate build directory, build and install it using following commands.

tar -xvf binutils-2.26.tar.bz2
mkdir build_binutils
cd build_binutils
../binutils-2.26/configure --target=i686-elf --prefix=<path-to-bin> --disable-nls --with-sysroot
make install
cd ..

All binaries will be available in the path specified in <path-to-bin>

Step 2: Build gcc as cross-tool

First set the path to binutils executables that got generated in the previous step.


Download, extract, configure from a separate build directory, build and install it using following commands

tar -xvf
mkdir build_gcccd build_gcc
../gcc-gcc-4_9_3-release/configure --target=i686-elf --prefix=<path-to-bin> --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

All binaries and libraries generated will be available in path specified in <path-to-bin>


OSDev: GCC Cross-Compiler

OSDev: GCC tool naming/prefix convention

Categories: Log, Tech Tags: , , ,


February 12, 2015 Leave a comment

If you go sit beneath a coconut tree to escape from the hot sun, and then you fall asleep in the shades of the tree; and then if by chance a ripe coconut falls on your head, killing you, will that be called your fate?

But there exists a certain wisdom that allows you to choose a tree with a lower chance of fatal accidents. Of-course, I don’t believe you can always make the probability zero. There exists a non-zero chance that a rock from Mars or an aeroplane engine falls on this particular tree taking away your life or perhaps wiping away all life forms from earth. You can further reduce the chance, if you actively track all the inter planetary objects heading to earth :-D.

Moral is that though life is full of chance events, there exists a certain wisdom in each case to bend the chance to your favour. But remember that however you reduce the probability of the worse; as long as it is non-zero, there is a chance!

Categories: Philosophy

Xilinx ISE on Ubuntu

January 26, 2015 Leave a comment

This post shall contain the issue I faced and solutions, when trying to use Xilinx ISE on Ubuntu(11.04). Shall keep updating as and when I encounter problems.

ISim Simulator – Link issue

The installation and the synthesis were trouble free. Had a bit issue with simulation. The simulation was not getting compiled. It was reporting “FATAL_ERROR:Simulator:Fuse.cpp:500:1.133 – Failed to compile generated C file isim/testbench_isim_beh.exe.sim/work/<filename>”. First step was to enable the more detailed error report by adding the “-v 1” option to the simulation build command. From the detailed log it turns out that the ‘fuse simulator’ was picking up the wrong from /opt/Xilinx/14.7/ISE_DS/ISE/lib/lin instead of /usr/lib/i386-linux-gnu. Issued the following commands as suggested by the 4th post at this archlinux forum.

From /opt/Xilinx/14.7/ISE_DS/ISE/lib/lin,

mkdir backup
mv backup
ln -s /usr/lib/i386-linux-gnu/ /opt/Xilinx/14.7/ISE_DS/ISE/lib/lin/

That solved the simulation issue.

Categories: Log Tags: ,

On the human need for happiness

January 4, 2015 Leave a comment

Life seems like a never-ending pursuit for happiness. Modern man never finds it happy in a steady state no matter how good the state is. Seems it is very important for the existence that there is always something that worries him. He always want something to be pursued, something to worry about..

Let me make myself clear what I mean by happiness. I am not referring to the short lived bliss that you get when you listen to a great piece of music, or enjoying a great piece of art. Rather I am considering the overall state of mind over a longer period of time, – say a month. Such overall feelings will surely be the result of thought that are persistent.

May be everyone ‘happy’ must be worrying about something. And I don;t think the unhappy mind doesn’t have any worry either. So everyone has something to worry. The things that keeps one worrying about should be the ones that determine greatness from mediocrity. (Greatness and mediocrity when measured by the contributions to the society.)

Other animals should be happy once their fundamental physical needs and emotional needs are satisfied. So what makes us go beyond the others. Is it something social? Is it something to do with our ability to think with language? Is it the unique identity, and a need to be unique; that the society instills in us through the many examples in history, and of own lineage that makes us want to be unique? What exactly is the fuel for the pursuit for happiness?

Is there a difference in the attitudes of various cultures in this regard? Is there a difference in terms of age? Is it really necessary to have a purpose in life?

How to use an old multimedia mobile phone as an music player – The signal integrity issues

November 17, 2014 Leave a comment

It is quite easy to convert a mobile phone into a music player, just connect your amplifier to the audio connector on the phone. Just that simple. However, problems start creeping up, when you want to power up both the phone and the amplifier out of the same supply. That means the phone doesn’t have a battery and is getting power form a 4.2V(Assuming original battery was Li-ion) regulator that you have built, and connected to the battery terminals. The problem is that in this case there is a lot of noise in the audio compared to the case with battery.

The Problem Statement

The reason is that the phone’s audio ground is no longer same as the amplifier ground. There are two cases. Case 1 is that the output stage of the phone has a bridge configuration. Case 2 is that the battery circuit uses low side current measurement. Case 1 is less probable because both the Left and Right channels share the common connector on the jack. For case 2, I have no clue why so many engineers prefer low side current measurement for the battery (connecting a resistor in series with the phone ground and battery negative terminal).

Phone audio electrical ground difference

In the figure, based on activity in the ‘Noisy Digital Circuit’ I1, the current through R1 changes and hence the voltage across it. This causes a varying voltage between the amplifier ground and the phone ground. The no-load voltage between Out+ and amplifier ground shall be V(R1) + V1. V(R1) is the noise introduced.

My case was only case 2. I could hear a lot of noise from the voltage converters on the phone. Because, based on their current consumption my phone’s ground was changing, and as a result the audio signal was also changing. The problem is illustrated in the figure above. The problem below shows the equivalent circuit used for simulation (Along with the solution circuit).

The LT-Spice circuit used for simulation of ground noise.

The LT-Spice circuit used for simulation of ground noise.

Here is a simulation output form the circuit above

Red is the op-amp's output voltage and green is the voltage at Out+

Red is the op-amp’s output voltage and green is the voltage at Out+

What is the solution?

The tough part is understanding the problem. Solution is simple – just use a difference amplifier with high common mode rejection ratio(CMRR).

Solution is to use a difference amplifier. Here is the one I used.

Solution is to use a difference amplifier. Here is the one I used.

The high CMRR is a catch here. As you can see from the problem statement diagram, the impedance on the two lines (Out+ and Out-) are in most cases, not matched. R2 shall add-up with R5 of the difference amplifier. R2 is typically a low resistance 10-33 ohms to protect the audio generator circuit in case of a short circuit, at the audio jack. A high CMRR can be achieved by increasing R5 and all the other resistors accordingly. 150k for R5 was a reasonable choice between CMRR and the op-amp bias current.

Still I have a bit of noise coupled from power supply remains. Already have the phone and amplifier grounds in a ‘star ground’ configuration. Hence very unlikely that noise is coupled through ground. Probably I have to add a voltage regulator for the amplifier.