From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: xenomai@xenomai.org
Subject: [Xenomai-core] x86 FPU switches routines.
Date: Mon, 23 Oct 2006 10:24:40 +0200 [thread overview]
Message-ID: <453C7C48.30602@domain.hid> (raw)
[-- Attachment #1: Type: text/plain, Size: 536 bytes --]
Hi,
As once discussed with Heikki, and after a first missed attempt, here
is a patch for x86 which attempts to cope correctly with Linux (non
real-time) drivers using FPU in kernel-space.
I tested it on my laptop without drivers using FPU, and it appears to
work correctly, but it would be nice if people that had problems with
the previous attempt (if I remember correctly, on old pentiums and on
AMD processors) could test this patch.
Thanks in advance.
--
Gilles Chanteperdrix
[-- Attachment #2: xeno-i386-fpu-switch-use-cr0-ts.diff --]
[-- Type: text/x-patch, Size: 2067 bytes --]
Index: include/asm-i386/system.h
===================================================================
--- include/asm-i386/system.h (revision 1704)
+++ include/asm-i386/system.h (working copy)
@@ -69,6 +69,7 @@
/* FPU context bits for root thread. */
unsigned is_root: 1;
unsigned ts_usedfpu: 1;
+ unsigned cr0_ts: 1;
} xnarchtcb_t;
Index: include/asm-i386/bits/pod.h
===================================================================
--- include/asm-i386/bits/pod.h (revision 1704)
+++ include/asm-i386/bits/pod.h (working copy)
@@ -44,6 +44,7 @@
/* Remember the preempted Linux task pointer. */
rootcb->user_task = rootcb->active_task = current;
rootcb->ts_usedfpu = wrap_test_fpu_used(current) != 0;
+ rootcb->cr0_ts = (read_cr0() & 8) != 0;
/* So that xnarch_save_fpu() will operate on the right FPU area. */
rootcb->fpup = &rootcb->user_task->thread.i387;
}
@@ -265,12 +266,21 @@
{
struct task_struct *task = tcb->user_task;
- if (task) {
- if (!wrap_test_fpu_used(task))
+ if (!tcb->is_root) {
+ if (task) {
+ /* fpu not used or already saved by __switch_to. */
+ if (!wrap_test_fpu_used(task))
+ return;
+
+ /* Tell Linux that we already saved the state of the FPU
+ hardware of this task. */
+ wrap_clear_fpu_used(task);
+ }
+ } else {
+ if (tcb->cr0_ts ||
+ (tcb->ts_usedfpu && !wrap_test_fpu_used(task)))
return;
- /* Tell Linux that we already saved the state of the FPU
- hardware of this task. */
wrap_clear_fpu_used(task);
}
@@ -298,13 +308,14 @@
wrap_set_fpu_used(task);
}
} else {
- /* Restore state of FPU if TS_USEFPU bit was armed. */
- if (!tcb->ts_usedfpu) {
+ /* Restore state of FPU only if TS bit in cr0 was clear. */
+ if (tcb->cr0_ts) {
stts();
return;
}
- wrap_set_fpu_used(task);
+ if (tcb->ts_usedfpu)
+ wrap_set_fpu_used(task);
}
/* Restore the FPU hardware with valid fp registers from a
@@ -336,7 +347,7 @@
}
}
} else {
- if (!tcb->ts_usedfpu)
+ if (tcb->cr0_ts)
return;
xnarch_restore_fpu(tcb);
next reply other threads:[~2006-10-23 8:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-23 8:24 Gilles Chanteperdrix [this message]
2006-10-23 9:01 ` [Xenomai-core] x86 FPU switches routines Jan Kiszka
2006-10-23 9:12 ` Gilles Chanteperdrix
2006-11-11 22:40 ` Philippe Gerum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=453C7C48.30602@domain.hid \
--to=gilles.chanteperdrix@xenomai.org \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.