Multi-threaded applications and floating point registers
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
======================================================================
#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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 6 lines · Ingo van Lil
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 had a similar problem between processes a few months ago, I also posted an example, unfortunately with no resolution nor further inquiries from the developers. I suspect the skas3 patch does not get much attention now...
Try to run the guest with mode=skas0 - in my case it eliminated the problem and the guest is running for months without a hiccup. If your problem is the same, it will probably help as well.
Quoted 3 lines
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.
In my case it was reproducible with 2.6.23.17 as well.
Regards
Signature · 11 lines
Stano ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 11 lines · Stanislav Meduna
Quoted 6 lines
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 had a similar problem between processes a few months ago, I also posted an example, unfortunately with no resolution nor further inquiries from the developers. I suspect the skas3 patch does not get much attention now...
Yes, I remember the thread. I don't think we're hitting the same problem, though: I'm not using the SKAS3 patch, and I did not notice any kind of cross-process influence. The effect is limited to threads sharing a single process context.
Regards,
Ingo
------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel