fpswa patch(es)
The following patch is really 3 patches rolled into one. I've found all 3 useful during application porting and debugging.
1. /proc/fpemu
A proc file that tools can monitor to identify when applications are running that are requiring lots of assists. Configured with CONFIG_PROC_FPEMU
% cat /proc/fpemu
CPU0f4859
CPU135141
Total00000
2. Log total number of assists to messages
Configured with CONFIG_PRINT_FPEMU, causes messages like
Dec 6 10:04:41 nospam kernel: assist(1151): 1000000 floating-point assist faults
when a process exits having taken a nonzero number of assist faults
3. signal for successful assist
Allows the process to request a specified signal to be sent when an assist succeeds. Currently the process receives SIGFPE when the assist fails (and nothing when it succeeds).
The application requests this with, e.g.
prctl(PR_FPEMU_SIGNAL, SIGUSR1);
Configured with CONFIG_SIGNAL_FPEMU.
The following applies cleanly to 2.4.16 + 011128 diff.
Thanks,
Brian Sumner
---------- patch follows ----------------------------------------------------------
arch/ia64/config.in Wed Nov 28 06:11:03 2001 renamed from arch/ia64/config.in Tue Nov 27 12:10:18 2001 +3 -0
@@ -96,6 +96,9 @@ bool 'SMP support' CONFIG_SMP tristate 'Support running of Linux/x86 binaries' CONFIG_IA32_SUPPORT bool 'Performance monitor support' CONFIG_PERFMON +bool '/proc/fpemu support' CONFIG_PROC_FPEMU +bool 'Log FPEMU activity per process' CONFIG_PRINT_FPEMU +bool 'Generate signal for successful FPEMU invocation' CONFIG_SIGNAL_FPEMU tristate '/proc/pal support' CONFIG_IA64_PALINFO tristate '/proc/efi/vars support' CONFIG_EFI_VARS
arch/ia64/kernel/process.c Wed Nov 28 06:11:03 2001 renamed from arch/ia64/kernel/process.c Tue Nov 27 12:10:18 2001 +5 -0
@@ -517,6 +517,11 @@ current->thread.flags &= ~IA64_THREAD_PM_VALID; } #endif +#ifdef CONFIG_PRINT_FPEMU + if (current->thread.fpemu_count) + printk(KERN_WARNING "%s(%d): %lu floating-point assist faults\n", + current->comm, current->pid, current->thread.fpemu_count); +#endif } unsigned long
arch/ia64/kernel/traps.c Wed Nov 28 06:56:56 2001 renamed from arch/ia64/kernel/traps.c Fri Nov 9 16:26:17 2001 +71 -0
119 lines not on this page · raw message
include/asm-ia64/processor.h Wed Nov 28 06:11:03 2001 renamed from include/asm-ia64/processor.h Tue Nov 27 12:10:19 2001 +23 -0
@@ -345,6 +345,15 @@ (int *) (addr)); \ }) +#ifdef CONFIG_SIGNAL_FPEMU +#define SET_FPEMU_SIG(task,value) \ +({ \ + (task)->thread.fpemu_sig = value; \ + 0; \ +}) +#endif + + struct siginfo; struct thread_struct {
@@ -378,6 +387,18 @@ #else # define INIT_THREAD_PM #endif +#ifdef CONFIG_PRINT_FPEMU + __u64 fpemu_count; +# define INIT_FPEMU_COUNT 0, +#else +# define INIT_FPEMU_COUNT +#endif +#ifdef CONFIG_SIGNAL_FPEMU + __u64 fpemu_sig; +# define INIT_FPEMU_SIG 0, +#else +# define INIT_FPEMU_SIG +#endif __u64 dbr[IA64_NUM_DBG_REGS]; __u64 ibr[IA64_NUM_DBG_REGS]; struct ia64_fpreg fph[96]; /* saved/loaded on demand */
@@ -391,6 +412,8 @@ 0, /* siginfo */ \ INIT_THREAD_IA32 \ INIT_THREAD_PM \ + INIT_FPEMU_COUNT \ + INIT_FPEMU_SIG \ {0, }, /* dbr */ \ {0, }, /* ibr */ \ {{{{0}}}, } /* fph */ \
include/linux/prctl.h Wed Nov 28 06:19:16 2001 renamed from include/linux/prctl.h Tue Nov 27 12:10:20 2001 +2 -0
@@ -26,4 +26,6 @@ # define PR_FPEMU_NOPRINT 1 /* silently emulate fp operations accesses */ # define PR_FPEMU_SIGFPE 2 /* don't emulate fp operations, send SIGFPE instead */ +#define PR_FPEMU_SIGNAL 11 /* generate signal on successful FPEMU invocation */ + #endif /* _LINUX_PRCTL_H */
init/main.c Wed Nov 28 06:11:03 2001 renamed from init/main.c Tue Nov 27 12:10:20 2001 +6 -0
@@ -109,6 +109,9 @@ #ifdef CONFIG_PERFMON extern void perfmon_init(void); #endif +#ifdef CONFIG_PROC_FPEMU +extern void trap_proc_init(void); +#endif /* * Boot command-line arguments
@@ -597,6 +600,9 @@ #ifdef CONFIG_PERFMON perfmon_init(); #endif +#ifdef CONFIG_PROC_FPEMU + trap_proc_init(); +#endif mempages = num_physpages; fork_init(mempages);
kernel/sys.c Wed Nov 28 06:11:03 2001 renamed from kernel/sys.c Tue Nov 27 12:10:20 2001 +8 -0
@@ -1272,6 +1272,14 @@ } current->keep_capabilities = arg2; break; + case PR_FPEMU_SIGNAL: +#ifdef SET_FPEMU_SIG + error = arg2 < 1 || arg2 >= _NSIG + ? -EINVAL : SET_FPEMU_SIG(current, arg2); +#else + error = -EINVAL; +#endif + break; default: error = -EINVAL; break;
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Brian Sumner
Brian> The following patch is really 3 patches rolled into one. Brian> I've found all 3 useful during application porting and debugging.
I see that this could be useful for certain debugging/hacking activities, but I don't think it's generally useful enough to warrant more kernel bloat. I'd rather keep this patch separate from the official tree. On a side note, it seems to there are some race conditions in incrementing the counters.
We could include more info in /proc/cpuinfo. E.g., we could include a count of the total number of fpswa and unaligned faults (on a per CPU basis). (Alpha Linux does this, if you want to look for an example). If someone sent me a patch to do that, I'd be much more inclined to apply it.
--david