qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Add support for atomic operations on sh user emulation
@ 2009-01-18 16:59 Lionel Landwerlin
  2009-01-18 17:03 ` Lionel Landwerlin
  0 siblings, 1 reply; 3+ messages in thread
From: Lionel Landwerlin @ 2009-01-18 16:59 UTC (permalink / raw)
  To: qemu-devel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-18 18:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-18 16:59 [Qemu-devel] [PATCH] Add support for atomic operations on sh user emulation Lionel Landwerlin
2009-01-18 17:03 ` Lionel Landwerlin
2009-01-18 18:21   ` Lionel Landwerlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).