Skip to contentSkip to conversation

Floating point problems on UML - help needed

DISCUSSION Richard Weinberger 3 participants 4 messages Aug 17, 2011 – Aug 18, 2011 User-mode Linux (UML)

lore
Share & tools
lore

Richard Weinberger

author maintainer
#0 lore raw

Hi,

Gunnar reported that some Java program does not work proper within UserModeLinux.
After looking closer at the problem I was able to reduce it to a small C program. (Program is attached.)

It looks like FPU registers get sometimes lost after switching between two or more threads.
It also happens not always, that's why my test program contains a infinite loop. After a few million iterations the program abort()s.

I can reproduce the issue on both x86 and x86_64, the host's or UML's kernel version does not matter. I've tested 2.6.18 to 3.1-rc2.

Interestingly the problem occurs not on my old Pentium 4 machines. One P4 has HT the other not.
Only "newer" CPUs are affected.

First I thought it's a race in _switch_to(), but adding unblock/block_signals() did not help. Currently I'm running out of ideas.
I'm not an expert in this area of UML. :-(

Any idea what goes wrong here?

Thanks,
//richard

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

static int xxx(float f)

{
	if(f <= 0.0){
		printf("wrong f!: %f\n", f);
		return -1;
	}

	return 0;
}

static void *fun(void *arg)

{
	float f = 5.0;

	for(;;){
		if(xxx(f) < 0)
			abort();
	}

	return NULL;
}

int main()

{
	pthread_t t1, t2;

	pthread_create(&t1, NULL, fun, NULL);
	pthread_create(&t2, NULL, fun, NULL);

	pthread_join(t1, NULL);
	pthread_join(t2, NULL);

	return 0;
}
#1 lore raw
Quoted 2 lines · Richard Weinberger

It looks like FPU registers get sometimes lost after switching between two or more threads.

This is probably a bug in UML I reported nearly three years ago. For me mode=skas0 worked aruond the issue.

http://thread.gmane.org/gmane.linux.uml.devel/11824/focus=11840

You might try the patch posted in
http://thread.gmane.org/gmane.linux.uml.devel/12158
(I don't have the environment to test it anymore)

Regards

Signature · 1 line
                                     Stano
author maintainer
#2 lore raw

Am 18.08.2011 08:29, schrieb Stanislav Meduna:

Quoted 5 lines · Richard Weinberger
Quoted 3 lines

It looks like FPU registers get sometimes lost after switching between two or more threads.

Quoted 8 lines

This is probably a bug in UML I reported nearly three years ago. For me mode=skas0 worked aruond the issue.

http://thread.gmane.org/gmane.linux.uml.devel/11824/focus=11840

You might try the patch posted in
http://thread.gmane.org/gmane.linux.uml.devel/12158
(I don't have the environment to test it anymore)

Cool, saving the FP registers explicitly on each task switch solves the issue. Do you know why Ingo's patch was never applied?
Ingo?

Thanks,
//richard

#3 lore raw
Quoted 8 lines · Richard Weinberger
Quoted 3 lines

You might try the patch posted in
http://thread.gmane.org/gmane.linux.uml.devel/12158
(I don't have the environment to test it anymore)

Cool, saving the FP registers explicitly on each task switch solves the issue.
Do you know why Ingo's patch was never applied?
Ingo?

I don't know why it was never applied, I guess it just slipped between the cracks. I've been using the patch for several months back in 2009, and it reliably fixed the observed problems.

My employer switched from UML to QEMU/KVM since then, so I eventually lost interest.

Cheers,
Ingo