qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] SEV and WFE instructions on ARM
@ 2013-06-06 14:34 Sebastian Huber
  2013-06-06 18:17 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Huber @ 2013-06-06 14:34 UTC (permalink / raw)
  To: qemu-devel

Hello,

I want to use Qemu to test some SMP code.  For this I set up Qemu to fire up 
two Cortex-A9 MPCore CPUs.  I have the following ticket lock implementation:

static inline void _ARM_Data_memory_barrier( void )
{
   __asm__ volatile ( "dmb" : : : "memory" );
}

static inline void _ARM_Data_synchronization_barrier( void )
{
   __asm__ volatile ( "dsb" : : : "memory" );
}

static inline void _ARM_Send_event( void )
{
   __asm__ volatile ( "sev" : : : "memory" );
}

static inline void _ARM_Wait_for_event( void )
{
   __asm__ volatile ( "wfe" : : : "memory" );
}

typedef struct {
   uint32_t next_ticket;
   uint32_t now_serving;
} CPU_SMP_lock_Control;

#define CPU_SMP_LOCK_INITIALIZER { 0, 0 }

static inline void _CPU_SMP_lock_Acquire( CPU_SMP_lock_Control *lock )
{
   uint32_t my_ticket;
   uint32_t next_ticket;
   uint32_t status;

   __asm__ volatile (
     "1: ldrex %[my_ticket], [%[next_ticket_addr]]\n"
     "add %[next_ticket], %[my_ticket], #1\n"
     "strex %[status], %[next_ticket], [%[next_ticket_addr]]\n"
     "teq %[status], #0\n"
     "bne 1b"
     : [my_ticket] "=&r" (my_ticket),
       [next_ticket] "=&r" (next_ticket),
       [status] "=&r" (status)
     : [next_ticket_addr] "r" (&lock->next_ticket)
     : "cc", "memory"
   );

   while ( my_ticket != lock->now_serving ) {
     _ARM_Wait_for_event();
   }

   _ARM_Data_memory_barrier();
}

static inline void _CPU_SMP_lock_Release( CPU_SMP_lock_Control *lock )
{
   _ARM_Data_memory_barrier();
   ++lock->now_serving;
   _ARM_Data_synchronization_barrier();
   _ARM_Send_event();
}

I run the following code on both CPUs:

while (1) {
   _CPU_SMP_lock_Acquire(&lock);
   ++global_counter;
   _CPU_SMP_lock_Release(&lock);
}

It seems that the SEV/WFE instructions are implemented as a nop on Qemu (see in 
file "target-arm/translate.c" function gen_nop_hint()).  So the simulator 
executes the busy wait loop most of the time.  Is it possible to trigger a 
schedule event in Qemu which stops the simulation on one CPU and selects 
another CPU instead?

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Qemu-devel] SEV and WFE instructions on ARM
@ 2013-11-26 12:51 Walsh, Benjamin
  2013-11-26 20:28 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Walsh, Benjamin @ 2013-11-26 12:51 UTC (permalink / raw)
  To: sebastian.huber@embedded-brains.de; +Cc: qemu-devel@nongnu.org

Hello Sebastian,

I was looking at using WFE on QEMU, found that it is implemented as a NOP, googled and I found this thread.

I am not using this for SMP, simply to implement sleep, so the busy loop is conceptually OK. Except, of course, that QEMU floors the host CPU at 100% in the idle loop.

You mentioned that you might send some patches for WFE/SEV, but I haven't seen anything in the current QEMU repo. Did you get anywhere with this ?

Thanks,
Ben

---
Benjamin Walsh, MTS
VxMicro
Desk : (613)270-2261
Fax  : (613)592-2283
www.windriver.com


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

end of thread, other threads:[~2013-11-26 20:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06 14:34 [Qemu-devel] SEV and WFE instructions on ARM Sebastian Huber
2013-06-06 18:17 ` Peter Maydell
2013-06-07  8:24   ` Sebastian Huber
  -- strict thread matches above, loose matches on Subject: below --
2013-11-26 12:51 Walsh, Benjamin
2013-11-26 20:28 ` Peter Maydell

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).