qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] Add support for atomic operations on sh user emulat


From: Lionel Landwerlin
Subject: [Qemu-devel] [PATCH] Add support for atomic operations on sh user emulation
Date: Sun, 18 Jan 2009 17:59:45 +0100

Hi all,

I've got some problem with threads and sh4 user emulation. Let's take a
little example :

------------------------------------------------------

#include <stdlib.h>
#include <stdio.h>

#include <pthread.h>

static pthread_mutex_t mutex;

static void *
thread_task (int id)
{
        while (1)
        {
                pthread_mutex_lock (&mutex);

                printf ("%i Got it !\n", id);

                pthread_mutex_unlock (&mutex);
        }
}

int
main (int argc, char *argv[])
{
        int i, n = 42;
        pthread_t th;

        pthread_mutex_init (&mutex, NULL);

        for (i = 0 ; i < n ; i++)
        {
                pthread_create (&th, NULL, thread_task, (void *) i);
        }
        
        thread_task (n);

        return EXIT_SUCCESS;
}

------------------------------------------------------

For those who would like to test, here is a stripped rootfs
http://djdeath.atr.free.fr/rootfs_sh4.tar.gz (from stlinux.com) with
everything to execute this like test (you will find the previous example
compiled in /tmp).

So when starting this program with the current qemu, you will probably
got an assertion (after a random amonth of time) from the libc :
mutex->__data.__owner == 0

The problem is that on SH4 (and probably others) uniprocessor
architectures, there is no atomic instructions (or very few). Atomic
operations related to locking etc... are provided by a kernel emulation
(gUSA). In user mode emulation qemu has to provide this emulation
instead of the kernel that is unaware of the state of the emulated
program (register, stack, etc...) and is probably everytime from a
different architecture.

The following patch provide a way to emulate gUSA, maybe not the best.
This patch is a rewrite of the previous patch I sent on tas.b atomic
operation.

Regards,

-- 
Lione Landwerlin                                         

O p e n W i d e                    14, rue Gaillon 75002 Paris





reply via email to

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