mutexks - true mutual exclusion in kernel space in linux


quick links
the simple paper on mutexks
the kernel patch
    This patch contains:
  1. slight addition to show_trace in traps.c so that it prints the distance between the functions in the stack interms of words.
  2. addition of mutexks.c and mutexks.h files which provide the mutexks logic
  3. a small patch to sched.c so that it doesn't ignore the preempt_count unless the mutualExclusionOnlyFlag is set. a hack or BAD FIX to scsi_error.c so that the current problem in it is solved TEMPORARILY. The actual fix would involve moving the code to use mutexks or similar where ever required.

The story ;-)
The way linux implements spinlocks in UniProcessor configuration, the semantic of spinlocks changes from a mechanism which provides Mutual Exclusion (ME) to one which provides Exclusive Execution (EE). So I have wondered wouldn't it affect code which expects ME. But in 2.4 I didn't find any issue related to this on my machine. However with the latest 2.6.0 kernel I had some surprises.

When I tried 2.6.0 kernel I found that when querying my ide cdrom drives, for one of the drives in test3 it used to dump few stack traces and later crash. However with test4 it dumps few stack traces

trace 1 - captured using dmesg . I have identified the contents of the call trace dumped in the log file, which correspond to function pointers in the stack of other functions.
trace 2 - captured using dmesg (has one part of my fix)
and then continues with its job.

So one analysing the call trace from test4 with the source and binary code, I realized that the reason this is happening is because of the spinlock no longer being a ME logic but having become a EE logic in uniprocessor configurations.

So I have come up with a solution to this problem by implementing what I call MUTEXKS for mutual exclusion in kernelspace. Which is nothing but integration of existing spinlock and semaphore logics in the kernel into a single entity which behaves like a spinlock in SMP configurations and a semaphore in UniProcessor configurations.
You can read about it in the link provided above.

Here is a dmesg log after my fix (this is a temporary hack, as the proper implementation will involve changing to many locations in the scsci layer to use mutexks where appropriate rather than spinlocks, and its better left to the people who maintain it, as they know the flow there better).


Last updated on 26 aug 2003 - 1800, India
Created using Vim :-)