All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] Multi-threaded applications and floating point registers
@ 2009-04-07 17:47 Ingo van Lil
  2009-04-07 18:27 ` Stanislav Meduna
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo van Lil @ 2009-04-07 17:47 UTC (permalink / raw)
  To: user-mode-linux-devel

Hello there,

I'm experiencing some weird problems with a multi-threaded application 
I'm working on: A function which uses nothing but a single input value, 
a few constants and a couple of floating point operations returns wrong 
results from time to time. The application uses multiple threads, and 
we're suspecting that the FPU state isn't properly saved and restored 
when switching between threads within a process.

I've written a trivial test program which can be used to reproduce the 
issue (see below). In theory the program should run forever, but in UML 
it aborts after just a few seconds.

I have observed the issue both with kernel 2.6.28.8 and Busybox/uclibc 
and with the demo kernel 2.6.24-rc7 and the Fedora10 image from the UML 
home page. The problem does not happen with kernel 2.6.23.1. We're 
suspecting that the problem has been introduced by the patch [1] to stop 
saving the process FP state which has been applied just before 2.6.24-rc1.

Regards,
Ingo

[1] 
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=42daba316557e597a90a730f61c762602b7f0e0c

======================================================================

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

static double my_abs(double d)
{
     return (d >= 0) ? d : -d;
}

static void *fp_test_thread_func(void *arg)
{
     volatile double value1 = *(double *)arg;
     volatile double value2 = *(double *)arg;
     while (1) {
         if (my_abs(value1 - value2) > 0.0001) {
             fprintf(stderr, "Inconsistent values: %lf, %lf\n", value1, 
value2);
             abort();
         }
     }
     return NULL;
}

#define NUM_THREADS 2

int main(void)
{
     pthread_t threads[NUM_THREADS];

     int i;
     for (i = 0; i < NUM_THREADS; i++) {
         double startval = i;
         pthread_create(&threads[i], NULL, fp_test_thread_func, &startval);
     }

     while (1) pause();
     return 0;
}

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


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

end of thread, other threads:[~2009-04-07 21:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-07 17:47 [uml-devel] Multi-threaded applications and floating point registers Ingo van Lil
2009-04-07 18:27 ` Stanislav Meduna
2009-04-07 21:23   ` Ingo van Lil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.