Monday, August 29, 2005

Learning(s) from a different land - I

Imagine my surprise when I went to a vendors office to help him out with some issues. The office had two rooms and a hall, a restroom and a small kitchen. The rooms were used for residential purposes. I was wondering if this is any kind of place to do business.

The hall had three phones (two cordless), a laptop for each person, one wireless and one wired router with a broadband connection. The engineers had all the stationary and used an oscilloscope for debugging. They also had soldering capability.

In the time to follow I began to love the work environment, no meeting, no interruptions, everyone has lunch together, the atmosphere was very informal almost like working from home. The kitchen had everything we needed to eat, we could walk around freely or rest on the sofa set. The environment made us feel so agile, we could solder up any hardware changes we needed, discuss any changes we wanted. I was glad to see that the Phone was not ringing, I had no chat interruptions, I did not have to wait for people for lunch. I had no fixed process to follow, no timesheet to fill, no status report to update, no meeting to attend.

I felt empowered to work the way things work for me. I got to define any workflow I wanted to follow to reach success. I realized that I was treated as per my capability and could decide what I needed to do. I was treated on Merit. We did not have any manager, just a stake holder.

I learnt that the ideal team size is probably 3 to 4 with no managers, just stake holders in the success of the team. This is probably what Agile Programming is all about, but to see it work is something else. I think organizations should ensure that like software, people should also have high cohesion and low coupling. I understand how the open source community works now.

Saturday, August 27, 2005

I'm back

Having spent a week in China/Hong Kong, I am back. I have some pictures, but I'll post them soon. I had a fun time in China and Hong Kong. Lots of learning(s), I hope to post them here as soon as I find free time.

Friday, August 19, 2005

Off for a while

I am off on an official visit for a week. I hope to be able to take my camera along and post some good pictures.

If you find the blog is not updated for a while, you know the reason. I will try to keep the blog up to date depending on the time I am able to find.

Wednesday, August 17, 2005

A new machine in my room

NewMachine

I hope I am able to use it well!

Late Night Help for a desperate photographer

I had taken some cool photographs using my digital camera. My previous installation of Windows 2000 had gone bad, so I reinstalled it. One of things that happened was that I misplaced my Cammedia software that comes with my camera. Olympus would not supply the software online. They asked me to contact an Olympus dealer.

Linux came in very handy, I was able to read my photographs using Digikam. See the screen shot below

snapshot1

I guess this is just one of the many good things about open source.

Check out digikam. Also check out the screen shots at Digikam ScreenShots

Tuesday, August 16, 2005

Searching with A9

Bored with the results returned by google. I decided to try out Amazon's search engine A9. I like the column based display of the search and the variety for selecting the source for searching.

One can dynamically select the source and select preferences. Books can be searched as well!

The screen shots below show the main page and a sample search for Discrete Cosine Transform. I found the search interesting. Many links were common between google and A9, but I think I am going to use A9 more often.

A9Home

Home Page of A9.com


A9DCT

Search for discrete cosine transform

Monday, August 15, 2005

Real Time Preemption changes being planned for 2.6

Paul McKenney with whom I had a good time interacting in Sequent, has written a great article on Real Time Preemption at A Real Time preemption Overview

These changes obsolete many things that have been said about Locking in Linux. As they say in the open source world

"If there is a book on it, the topic is obsolete"

I would highly recommend reading this article


Friday, August 12, 2005

Opera 8 now

I use Opera once in a while. Some of the stuff is really good.

  1. Mouse Gestures
  2. Unix Like Browsing
  3. Voice Support
  4. Many more

but what I found very useful for my blogging is image scaling. Scaling down of images is much much better than IE or Firefox.



Image rendered by Opera 8




Image rendered by Firefox




Image rendered by Internet Explorer

Thursday, August 11, 2005

Compile Time Assertions

A friend and I got into a discussion in coffee day last night about a review he was busy with. The code he was reviewing converts an integer to string. The author was taking the value of the integer, calculating log10 of the number and adding 2 to it to calculate the length of the array for storing the converted string.

This array would then be malloc'ed to store the string.

There are obvious deficiencies in this code

It is slow (due to the log10 calculation and malloc)

on the other hand

This code would scale better than any other code, for example if the integer size of the platform changed.

I suggested that the author do the following

1. Calculate the maximum array size for an int of 4 bytes (remember to include space for a possible "-"). Currently (11+1(possible "-")+1 ('\0' character)) bytes for a 4 byte integer.
2. Use compile time assertion to assert the size of the integer being converted.

If you are wondering what compile time assertions do, look at the code below

1 #define CT_ASSERT(cond, msg) \
2 typedef char msg[(cond) ? 1 : -1]
3
4 int
5 main(void)
6 {
7 int i = 10;
8
9 CT_ASSERT(sizeof(i) == 4, size_must_be_4);
10
11 }

Compile time assertions try to use the preprocessor and create situations that are illegal. The "C" compiler cannot compile the preprocessed code, if the assertion fails. See the example above.

On a platform where this condition fails, the output would be

cassert.c: In function `main':
cassert.c:9: size of array `size_must_be_4' is negative

This ensures that there is no runtime overhead of catching assertions and yet the code is fast and will break if the size of the integer changes.

Other sources of information
  1. Catching errors early with compile-time assertions
  2. Compile Time Assertions in C

Monday, August 08, 2005

Netscape 8 is such a joy

After all the controversy surrounding Netscape 8. I decided to install an upgraded/fixed version of Netscape 8. I found it amazing, you can switch between the IE and Firefox rendering engines so easily. I think this a big boon for web developers who are faced with the difficult task of testing pages with both browsers.

In the screen shots below look at the icon at the bottom left of the screen, they show the icon with which the page has been rendered. I think this a giant step for web developers and a good move by Netscape.


Netscape rendering using Firefox Posted by Picasa

Netscape rendering using IE Posted by Picasa

Netscape used to be the only browser for Linux, but unfortunately they have decided not to release Netscape 8 for Linux. I would be happy even if they released with a firefox engine, atleast I would use the same browser across platforms.

Sunday, August 07, 2005

Celebopedia

Do you enjoy wikipedia? Well there is a good celebopedia web site now. Each celebrity is listed with news, biography, stats, media and some extras. So will celebopedia become a standard like imdb.

I still love imdb and I think its much ahead of celebopedia.

Friday, August 05, 2005

An unexpected visit

On one of my posts, I found a post from two people who decided to visit other blogs and leave behind a visit me message. I think that's cool, but where does one draw the line?

Well, to be fair, I visited their web site from home and found out something about them. Blog's are multi-dimensional (people might not be willing to show all aspects of themselves completely). Some blogs are personal, some are political, some are technical, etc. Some blogs have mixed content.

I use the blog's I read column to link to my friends, but I might start indicating what kind of blogs I would like my blog to be linked with. The blogosphere is similar to a biological system. Wikipedia's definition of Blogosphere is very interesting.

Wikipedia states

Blogosphere (alternate: blogsphere) is the collective term encompassing all weblogs or blogs as a community or social network. Many weblogs are densely interconnected; bloggers read others' blogs, link to them, reference them in their own writing, and post comments on each others' blogs. Because of this, the interconnected blogs have grown their own culture.

Blogosphere is an essential concept for blogs. Blogs themselves are just web formats, whereas the blogosphere is a social phenomenon. What really differentiates blogs from webpages, forums, or chatrooms is that blogs can be part of that shifting Internet-wide social network.

Like biological systems, the blogosphere demonstrates all the classic ecological patterns: predators and prey, evolution and emergence, natural selection and adaptation. The number of links obtained by a blog, is frequently related to the quality and quantity of information presented by that blog. That means, the most popular blogs have the highest link level, the worst blogs have the lowest link level. The blog ecosystem has its own selection and adaptation mechanism. The good tends to become better, the bad tends to disappear.

Through links and commentaries, the blogosphere with its self-perfecting mechanism, converts itself from a personal publishing system into a collaborative publishing system.


I don't want to disappear, please help me survive :-)

Thursday, August 04, 2005

Can you recognize this person? -- Answered



Here is the answer to Can you recognize this person?. The name of the person is Lena.

See this expert from an email response

Subject: Lena (parting words) (longish)
Date: 21 Feb 1996 13:33:20 GMT
From: dobelman@dfw.dfw.net (John Dobelman)
Organization: DFW Internet Services - DFWNet: 800-2-DFWNet
Newsgroups: sci.image.processing

If Dr. Munson and the Transactions can forgive the copyright infringment, the departing Editor-in-chief's comments on the Lena deal are too good not to share with the group.

IEEE TRANSACTIONS ON IMAGE PROCESSING. VOL. 5. NO. 1. JANUARY 1996

A Note on Lena

During my term as Editor-in-Chief, I was approached a number of times with the suggestion that the IEEE TRANSACTIONS ON IMAGE PROCESSING should consider banning the use of the image of Lena. For those of you who are uninitiated in this brouhaha, let me provide a few facts. The original Lena image was a photograph of a Swedish woman named Lena Sjooblom, which appeared in the November 1972 issue of Playboy Magazine. (In English, Lena is sometimes spelled Lenna, to encourage proper pronunciation.) The image was later digitized at the University of Southern California as one of many possible images for use by the research community. I think it is safe to assume that the Lena image became a standard in our "industry" for two reasons. First, the image contains a nice mixture of detail, flat regions, shading, and texture that do a good job of testing various image processing algorithms. It is a good test image! Second, the Lena image is a picture of an attractive woman. It is not surprising that the (mostly male) image processing research community gravitated toward an image that they found attractive

An interesting link is http://www.lenna.org/

Wednesday, August 03, 2005

Rock star INXS

Do you guys watch the show on Star World! Well, I love the show.

  1. http://rockstar.msn.com/
  2. http://www.cbs.com/primetime/rock_star/




I love Jessica's attitude and singing. But my picks for the top three are

The photographs have been taken from rockstar.msn.com

What to Lock (Locking Design part IV)

To discuss this, we first need to look at what kind of system architecture is being used. There are two special types of locking primitives, they are described below.

  • Semaphore

    A semaphore is used to denote a locking primitive in which we relinquish the CPU if we do not get the lock. In the examples used in the previous article, down, down_write and down_interruptible are semaphores. The pseudo code for a typical semaphore implementation is given below.


    \begin{algorithm} % latex2html id marker 53\caption{Psuedo code for a semaphor... ... queue} \STATE return with the lock held \ENDIF \end{algorithmic}\end{algorithm}


  • Spinlock

    A spinlock is used in a multiprocessor environment. There might be cases when one cannot go to sleep waiting for a lock. Consider for example an interrupt handler in a Symmetric Multi Processing environment (here after referred to as SMP). All the CPUs may receive an interrupt from any device. If a device interrupted the system twice, lets say one interrupt goes to CPU 1 and the other to CPU 2. Both of them execute the same interrupt handler for the device. They will need mutual exclusion to avoid the kind of races or unexpected results. It would be very bad for a CPU to go to sleep in an interrupt handler, because an interrupt handler is running at a very high priority, preempting everything else, we should deal with it quickly or the system will perform very badly. So what do we do, we spin on the lock being held by the other CPU (assuming that the other CPU will not hold the lock for long). Once we get it, we finish with the interrupt handler and continue (NOTE: The assumption here is that interrupt handlers run fast, otherwise the spinlock will spin for a long time).


    \begin{algorithm} % latex2html id marker 63\caption{Psuedo code for a spinlock... ...TATE return with the lock held \ENDIF \ENDWHILE \end{algorithmic}\end{algorithm}


Now that we have looked at kinds of locking primitives, let us discuss when we need to lock data. First of all remember that we need to lock only global variables and structures, since only they are prone to races. Local variables reside on the stack and since each process on each processor has its own stack, there are no race conditions with local variables. We will consider the following cases


Rules Of Locking (locking design part III)

The rules are listed below

  • Lock only data, not code.
  • Lock only what you want to protect, not everything around it. Use locking optimally.

Surprisingly enough, there are only two small rules for locking. These rules are definitely not exhaustive, they are rules of thumb and form the basis of this article. From these rules we will draw more and try to use real world examples to illustrate the various rules. Lets now see what each rule means.

     /* Find the cache in the chain of caches. */
down(&cache_chain_sem);
/* the chain is never empty, cache_cache
is never destroyed */
if (clock_searchp == cachep)
clock_searchp =
list_entry(cachep->next.next,
kmem_cache_t, next);
list_del(&cachep->next);
up(&cache_chain_sem);

if (__kmem_cache_shrink(cachep)) {
printk(KERN_ERR "kmem_cache_destroy:
Can't free all objects %p\n", cachep);
down(&cache_chain_sem);
list_add(&cachep->next,&cache_chain);
up(&cache_chain_sem);
return 1;
}

In the example above, we grab the cache_chain_sem lock twice. We release the lock before calling __kmem_cache_shrink() and grab it again if necessary i.e, if __kmem_cache_shrink() returns a value greater than zero. We could have held the lock for the entire duration and freed it at the end, but it would conflict with the rules we stated above.

We would be protecting code and not data, we need to protect the cachep list, so we use the lock only to protect the contents of that list from changing. What if we held the lock and __kmem_cache_shrink() turned out to be an extremely long function? Other routines waiting for that lock would really starve, especially if __kmem_cache_shrink() does not change the cachep list. It would even be unfair to hold the lock and make merry while others are waiting for the lock.

This brings us to some important questions

  1. When do I need to implement locking into my code?
  2. How do I design my code to in corporate locking into it?

These questions are answered in the articles to follow.

Monday, August 01, 2005

Pages related to OSX86

Apple has decided to move to the intel platform. Here are some links related to their effort

  1. http://www.osx86.classicbeta.com/wiki/index.php/Main_Page
  2. http://maconintel.com/
  3. http://www.appleinsider.com/article.php?id=1175
  4. http://www.macsimumnews.com/index.php/archive/
    possible_mactel_chips_part_1_a_look_at_yonah
  5. http://buildyourownmac.com/
  6. http://www.jbnahan.net/en/
They are all unofficial, but they are fun to read. I can't wait for my own copy of MAC-OS-X on Intel or to buy one of those cool boxes. I hope they use a processor with 64 bit extensions and hyper-threading support

Saturday, July 30, 2005

Foveon X3 Technology

If you are interested in digital photography, please read the Digital Camera FAQ. One very interesting feature is the Foveon X3 Technology.

Here are some images to show you the distinction, they have been taken from the Foveon site.





Mosaic Capture
Foveon X3 Capture


Sharpness

Mosaic

[Larger View]

Foveon X3


Color Detail

Mosaic

[Larger View]

Foveon X3


Artifacts

Mosaic

[Larger View]

Foveon X3

Can you recognize this person?



She is very popular and you will find her in a lot of image processing books. There is a very interesting story and background about this person and her photograph. Can you figure it out? If you can't, please wait for the answer or ask for it

Migrate apps from Internet Explorer to Mozilla

IBM is running an article on Migrating Internet applications to Mozilla.


Figure 3. Mozilla's JavaScript debugger

I found it very interesting as I try to learn more about where the web has gone since the CGI days. I love XML, its a big relief from SGML.

Wednesday, July 27, 2005

Open Solaris



I am very excited about open Solaris. With the Apple folks also deciding to move to an Intel platform, Intel users would have access to

  1. Linux
  2. FreeBSD/NetBSD/(other BSD clones)
  3. Solaris
  4. MAC-OS X (derived from darwin - open darwin)
  5. Windows
The exciting thing is that sources for the first four can be easily obtained. Its fun to see gcc ported to all these platforms. All these are encouraging trends, the base support software is getting free, so will the other support tools in time to come. What will the software industry pay for then?

Lets see where the future takes us.

Monday, July 25, 2005

Conspiracy Theory - Did we land on the Moon?

Star world ran this program on Saturday 9:00 PM. It almost made me believe we did not land on the moon. Then I saw the http://www.braeunig.us/space/hoax.htm and I am a bit confused now by both claims.

NASA also has an interesting site http://science.nasa.gov/headlines/y2001/ast23feb_2.htm?list45245. I think I am going to believe again that we landed on the Moon until the next space vehicle to orbit the moon finds/proves that we did not go to the moon.

What I have found so far is that people believe strongly. A believer is not open to changing his mind and vice-versa.

Friday, July 22, 2005

Deterministic problem solving

Have you come across a problem that makes you want to wonder as to how long it will be before the problem will be solved. There are many good books out there on debugging and many many interesting discussions on weird problems and their solutions.

The question for today is

  1. Can we come up with techniques to convert the solution time non-deterministic to deterministic?
  2. How would be verify that these techniques do that effectively?

Tuesday, July 19, 2005

1970 and 1979 Editions of "How it works, the computer"



Interesting book and its online now. I like the size of the computers. Slashdot also has this story here

The Image Drawing Dilemma

Good posts demand good illustration. That is true for all topics but especially true for technical content (I know I promised more non-technical content, I have quite a bit of it, but it needs to be organized and reviewed).

I have been evaluating the following options for illustrating

  1. Hand drawn (I have a scanner)
  2. Using a tool like VISIO (openoffice has a decent tool too)
  3. Using my favourite MetaPost/LaTeX/pdfLaTeX/MetaFun
  4. Using PIC
  5. Using Graphviz

In this post, lets look at hand drawn images. Here are two hand drawn and scanned images - what do you make of them?


Monday, July 18, 2005

Are you a computer engineer?

Do you recognize these symbols?


If you don't, I suggest you refresh your knowlegde again.

Sunday, July 17, 2005

The latest review


I just got an email from William Stallings telling me that the book is published. Since I am one of the technical reviewers of the book (single chapter), I am expecting my free copy soon.

I like books by Stallings, they are well written and well illustrated. This is one of my last reviews this year.

Experiments with syntax highlighting

I have been posting code for a while now, I want to try and post good looking code - which is syntax highlighted.

Here is the first attempt


/*
* Simple program to parse regular expressions
* (C) Balbir Singh
* Permission to copy the program if and only if the (C) is
* maintained.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <bitset>
#include <iostream>
#include <queue>
using namespace std;

static bool status = true;

#ifdef DEBUG
#define debug(x...) {\
printf("%s:%d ", __FUNCTION__, __LINE__); \
printf(x); \
}
#else
#define debug(x...)
#endif

#define pcr debug("current token is %c\n", s[idx]);
#define perr {\
fprintf(stderr, "%s:%d parse error at token is %c\n", \
__PRETTY_FUNCTION__, __LINE__, s[idx-1]); \
status = false; \
};

Saturday, July 16, 2005

Thursday, July 14, 2005

Locking Design in many parts

A paper I wrote on locking several years ago. I reproduce it here in parts.

Elements of locking

Abstract:
In this paper we discuss the various aspects of locking, including designing code which would be considered safe. By safe, we mean free of unexpected side effects. These side effects are commonly known as race conditions in the literature of operating systems and computer architecture. Although a lot has been written on this subject, we will look at it from a different angle. Several examples have been used to illustrate the contents of this paper, the reader is not expected to understand the code listings and what the code does. The code should be viewed from the point of view of locking. The term locking has been used here to mean methods of protecting critical section of the code. It is assumed that the reader is familiar to some extent with the concept of critical section. Most of the examples and treatment of this subject is with respect to a operating system kernel concept, but the principles discussed here even apply to a multi-process or a multi-threaded user application. All the discussion applies to non-preemptive kernels only.

The Need For Locking

The need for locking is simple and a lot has been written about it. We will use a pratical example of a race condition often seen in an operating system environment. We will take an example from fork.c in Linux, it is a small and good example.

down_write(&oldmm->mmap_sem);
retval = dup_mmap(mm);
up_write(&oldmm->mmap_sem);


The fork system call in Linux and other Unix variants does the following

img1


img2
Figure 1: The fork() system call



Now consider what could happen if we did not lock the address space of the parent using down_write(&oldmm->mmap_sem), the address space (see figure 1) of the parent could change and what we set out to do i.e, Ensure that parent and child have the same address space at the end of fork, would never be accomplished. The dup_mmap(mm) function duplicates the address space. The deletion of a single page could affect the system call if proper locking is not used. We call the data and code protected by the locks as critical section. In our case the data used by dup_mmap(mm) that is mm is our critical section.

A fundamental assumption of locking is - once we get the lock it is ok for us to go ahead and modify/use the data protected by the lock.

NOTE: Most of the new hardware and software developments demand more concurrency, as we head towards concurrency at various levels of hardware and software, the need for locking and sound locking design principles become more accute.

Saturday, July 09, 2005

First Letter to Stroustrup

Hello, Bjarne,

I have been reading "The C++ Programming language, third edition (special edition)". Reading through section 11.3.2 made me realize that user defined types could use another feature like "type promotion" to get closer to types supported by the language. To support Mixed mode arithmetic the number of operators defined is 5 in section 11.3.2.

I was wondering if we have a promotion operator.

For example, lets say we have a reserved keyword promotion and we could do the following

Complex& operator promotion(double d)
{
this->im = 0;
this->re = d;
return *this;
}

The promotion operator could be invoked whenever we encounter a type in an operator that is not of the same class as the operator.

For example

2 + c // where c is complex

Could invoke a promotion operator with a new temporary created by the compiler

In effect, it would be equal to

t = new Complex();
c.operator+(t.operator promotion(2), c)

I think this would simpifly the permutations, combinations needed to develop a good usable user defined type.

Comments?

Balbir

Friday, July 08, 2005

Compilers - where are they going?

Reading through some of my books, I came across two concepts that I think are the biggest things that compilers support today

  1. Templates or Generics
  2. Reflection



The diagram below depicts the following facts

  1. Reflection is getting us closer to the compiler internals. They help us with how types are organized and to help us probe for more compiler details. Reflection is helping the user get more information about compiler internals.
  2. Templates are taking us towards implementing our own primitives. We are so close to doing code generation using techniques like meta template programming.

The day is not far when templates and reflection techniques will merge at some point giving the user full control from compiler internals to using the compiler interface.

Thursday, July 07, 2005

Effective C++, Second Edition


If you have read Effective C++, Second Edition, I hope you enjoyed reading it. I have started reading it and found some interesting things, I reported them to Scott Meyers. He updated them at Effective C++, Second Edition, Errata Web site. My code name is bxs.

You can find what I said and some really interesting stuff that others have said at the above web site.

Tuesday, July 05, 2005

Whom should we encourage to become our next generation leaders?

I have been thinking about this issue for a while. Who would make a good leader in the Indian democracy? What background should they come from? Well, here are my thoughts so far

Lal Bahadur Shastry ji used the following slogan (Jai is a praise, kisan is a farmer, jawan is a soldier and vigyan is science)

Jai Jawan, Jai Kisan

to which Atal Bihari Vajpayee added

Jai Vigyan

I feel we need people from the defense in our parliament. America has had the tradition of having people serving in the military become their presidents. I feel we should have

  1. Kisans (farmers) at the grass root level of politics
  2. Vigyanis (Scientists) be involved as Members of Rajya Sabha (as already dictated by our constitution)
  3. Jawans (Soldiers) at the top most level of leading the country with pride and loyalty.

privacy

Some of the policy from the app automation refers to https://rclone.org/privacy/ if you are a general blog reader, follow Google's polic...