qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] atomic-test: Add spinlock test case


From: Alexander Spyridakis
Subject: Re: [Qemu-devel] [PATCH 2/2] atomic-test: Add spinlock test case
Date: Mon, 11 May 2015 12:41:51 +0200

Hi Andrew,

On 11 May 2015 at 12:17, Andrew Jones <address@hidden> wrote:
> > +
> > +void atomic_lock(int *lock_var)
> > +{
> > +    while (__sync_lock_test_and_set(lock_var, 1));
> > +}
> > +
> > +void atomic_unlock(int *lock_var)
> > +{
> > +    __sync_lock_release(lock_var);
> > +}
>
> Do these builtins actually do anything without enabling the
> MMU first?

>From my experience while testing on ARM, without the builtins
atomicity will fail, with our without enabling the MMU.

> > +
> > +void test_spinlock()
> > +{
> > +    int i, errors = 0;
> > +    int cpu = get_cpuid();
> > +
> > +    for (i = 0; i < LOOP_SIZE; i++) {
> > +        LOCK(&global_lock);
> > +
> > +        if (global_a == (cpu + 1) % 2) {
> > +            global_a = 1;
> > +            global_b = 0;
> > +        } else {
> > +            global_a = 0;
> > +            global_b = 1;
> > +        }
> > +
> > +        if (global_a == global_b) {
> > +            errors++;
> > +        }
> > +        UNLOCK(&global_lock);
> > +    }
> > +
> > +    printf("CPU%d: Done - Errors: %d\n", cpu, errors);
> > +}
> > +
> >  void main(void)
> >  {
> > -    printf("CPU %d on\n", get_cpuid());
> > +    if (!get_cpuid()) {
> > +            printf("Starting test\n");
> > +    }
> > +
> > +    test_spinlock();
> >      power_off();
> >  }
>
> You could have saved a ton of time by just putting these 50
> lines into a new kvm-unit-tests test. If you need the mmu
> disabled for some reason, then we can add an mmu_disable()
> to the API.
>
> drew

The main idea is to start with something very minimal and
straightforward for a standalone test similar to the QEMU's multiboot,
since the target is to mainly trigger race conditions and test
multithreaded TCG.

Thanks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]