lockmeter
[Top] [All Lists]

Some notes on portability of lockmetering code to non-IA32 architectures

To: lockmeter@xxxxxxxxxxx
Subject: Some notes on portability of lockmetering code to non-IA32 architectures
From: Frank Hofmann - Sun Germany Technical Solution Center - Munich <Frank.Hofmann@xxxxxxxxxxxxxxx>
Date: Wed, 10 Nov 1999 18:18:07 +0100 (MET)
Reply-to: Frank Hofmann - Sun Germany Technical Solution Center - Munich <Frank.Hofmann@xxxxxxxxxxxxxxx>
Sender: owner-lockmeter@xxxxxxxxxxx
Hi,

have downloaded the lockmeter 1.1.1 code - this is great stuff !

Unfortunately I don't have an Intel-based SMP system to test this on,
but I've found that with very few modifications it also compiles on
sparc (only tried v8, i.e. 32bit). To accomplish this, apart from
adding to the config.in, Makefile, ... stuff I also had to change the
following code parts:


In lockmeter.c, there are several points which prevent that it
compiles on non-IA32:

1. the use of "cpucount". This variable is not an exported symbol resp.
   a global on sparc.
   Replacing this by the arch-independent global "smp_num_cpus" works.

2. Same for "cpu_hz". This is only used currently to fill in a field
   in the lockstat info struct. I don't know an arch-independent way
   to get this but it's not required for working lockstat and so I've
   just removed it for the moment.

3. The following assembler code:

#define local_irq_save(x) \
    __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ 
:"memory")

#define local_irq_restore(x) \
    __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory")

   looking at the #define's in asm-i386/system.h, one finds that this
   is identical to:

#define local_irq_save(x) __save_and_cli((x))
#define local_irq_restore(x) __restore_flags((x))

   This way it also should be more portable.
   __save_and_cli() is not available on all architectures but it is on
   IA32 and sparc.

4. The following assembler code:

static __inline__ int atomic_incr_and_test_nonneg(volatile atomic_t *v)
{
       unsigned char c;

       __asm__ __volatile__(
               LOCK "incl %0; setns %1"
               :"=m" (__atomic_fool_gcc(v)), "=qm" (c)
               :"m" (__atomic_fool_gcc(v)));
       return c != 0;
}

   There's tons of similar code in the includes asm-i386/atomic.h and
   the corresponding asm-includes for other platforms. I've not yet
   found a portable way of coding this using the macros from atomic.h
   but for sparc that reads:

#define atomic_incr_and_test_nonneg(x) (atomic_add_return(1,(x)) >= 0)


Modifications to other files:

        - smplock.h: minor, easy, but I don't see a way of getting this
          completely platform-independent.
        - spinlock.h: dito.
        - some mods to the $ARCH_ksyms.c file. This makes sense ;-)



I've not yet been able to test lockmetering on my SS10 because my kernel
codebase is a bit corrupted and therefore I did not get a working kernel
in the few hours I coded last night ;-)
This is not a fault of the lockmetering code - there were some code
problems with other patches I was using that prevented the kernel from
compiling.

I will be able to test my sparc-adapted code tonight. If it works, I'm
going to create diff's against a stock-2.2.13 source. It should be
pretty straightforward to port this to other non-IA32 architectures then.

Let's see - where could other arch-dependent pitfalls be located:

- lockmeter.h: I'm not sure about the LSTAT_RA macro.
- endianness issues: Have not yet been able to check for this.

Thanks for the code - it's fun !


Bye
Frank Hofmann


<Prev in Thread] Current Thread [Next in Thread>