Re: [patch 2/2] x86, fpu: lazy allocation of FPU area - v4

Previous thread: Taras Budenkevich додав у Ваших by Команда Коннекта on Tuesday, March 4, 2008 - 4:46 pm. (1 message)

Next thread: [patch 1/2] x86, fpu: split FPU state from task struct - v4 by Suresh Siddha on Tuesday, March 4, 2008 - 4:37 pm. (5 messages)
From: Suresh Siddha
Date: Tuesday, March 4, 2008 - 4:37 pm

Only allocate the FPU area when the application actually uses FPU, i.e., in the
first lazy FPU trap. This could save memory for non-fpu using apps.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
---
v4: Handles the kmem_cache_alloc() failures.
v3: Fixed the non-atomic calling sequence in atomic context.
v2: Ported to x86.git#testing with some name changes.
---

Index: linux-2.6-x86/arch/x86/kernel/i387.c
===================================================================
--- linux-2.6-x86.orig/arch/x86/kernel/i387.c	2008-03-04 15:31:56.000000000 -0800
+++ linux-2.6-x86/arch/x86/kernel/i387.c	2008-03-04 15:31:57.000000000 -0800
@@ -9,7 +9,6 @@
 #include <linux/sched.h>
 #include <linux/module.h>
 #include <linux/regset.h>
-#include <linux/bootmem.h>
 #include <asm/processor.h>
 #include <asm/i387.h>
 #include <asm/math_emu.h>
@@ -67,7 +66,6 @@
 	else
 		xstate_size = sizeof(struct i387_fsave_struct);
 #endif
-	init_task.thread.xstate = alloc_bootmem(xstate_size);
 }
 
 #ifdef CONFIG_X86_64
@@ -97,12 +95,22 @@
  * value at reset if we support XMM instructions and then
  * remeber the current task has used the FPU.
  */
-void init_fpu(struct task_struct *tsk)
+int init_fpu(struct task_struct *tsk)
 {
 	if (tsk_used_math(tsk)) {
 		if (tsk == current)
 			unlazy_fpu(tsk);
-		return;
+		return 0;
+	}
+
+	/*
+	 * Memory allocation at the first usage of the FPU and other state.
+	 */
+	if (!tsk->thread.xstate) {
+		tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
+						      GFP_KERNEL);
+		if (!tsk->thread.xstate)
+			return -ENOMEM;
 	}
 
 	if (cpu_has_fxsr) {
@@ -124,6 +132,7 @@
 	 * Only the device not available exception or ptrace can call init_fpu.
 	 */
 	set_stopped_child_used_math(tsk);
+	return 0;
 }
 
 int fpregs_active(struct task_struct *target, const struct user_regset *regset)
@@ -140,10 +149,14 @@
 		unsigned int pos, unsigned int count,
 		void *kbuf, void __user ...
From: Bastien ROUCARIES
Date: Thursday, March 6, 2008 - 5:40 am

Regards
-- 

"ROUCARIES Bastien"

--

Previous thread: Taras Budenkevich додав у Ваших by Команда Коннекта on Tuesday, March 4, 2008 - 4:46 pm. (1 message)

Next thread: [patch 1/2] x86, fpu: split FPU state from task struct - v4 by Suresh Siddha on Tuesday, March 4, 2008 - 4:37 pm. (5 messages)