minix/kernel/system/do_clear.c
Tomas Hruby cbc9586c13 Lazy FPU
- FPU context is stored only if conflict between 2 FPU users or while
  exporting context of a process to userspace while it is the active
  user of FPU

- FPU has its owner (fpu_owner) which points to the process whose
  state is currently loaded in FPU

- the FPU exception is only turned on when scheduling a process which
  is not the owner of FPU

- FPU state is restored for the process that generated the FPU
  exception. This process runs immediately without letting scheduler
  to pick a new process to resolve the FPU conflict asap, to minimize
  the FPU thrashing and FPU exception hadler execution

- faster all non-FPU-exception kernel entries as FPU state is not
  checked nor saved

- removed MF_USED_FPU flag, only MF_FPU_INITIALIZED remains to signal
  that a process has used FPU in the past
2010-06-07 07:43:17 +00:00

81 lines
2.3 KiB
C

/* The kernel call implemented in this file:
* m_type: SYS_CLEAR
*
* The parameters for this kernel call are:
* m1_i1: PR_ENDPT (endpoint of process to clean up)
*/
#include "kernel/system.h"
#include <minix/endpoint.h>
#if USE_CLEAR
/*===========================================================================*
* do_clear *
*===========================================================================*/
PUBLIC int do_clear(struct proc * caller, message * m_ptr)
{
/* Handle sys_clear. Only the PM can request other process slots to be cleared
* when a process has exited.
* The routine to clean up a process table slot cancels outstanding timers,
* possibly removes the process from the message queues, and resets certain
* process table fields to the default values.
*/
struct proc *rc;
int exit_p;
int i;
if(!isokendpt(m_ptr->PR_ENDPT, &exit_p)) { /* get exiting process */
return EINVAL;
}
rc = proc_addr(exit_p); /* clean up */
release_address_space(rc);
/* Don't clear if already cleared. */
if(isemptyp(rc)) return OK;
/* Check the table with IRQ hooks to see if hooks should be released. */
for (i=0; i < NR_IRQ_HOOKS; i++) {
if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
}
}
/* Remove the process' ability to send and receive messages */
clear_endpoint(rc);
/* Turn off any alarm timers at the clock. */
reset_timer(&priv(rc)->s_alarm_timer);
/* Make sure that the exiting process is no longer scheduled,
* and mark slot as FREE. Also mark saved fpu contents as not significant.
*/
RTS_SETFLAGS(rc, RTS_SLOT_FREE);
rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
/* Release the process table slot. If this is a system process, also
* release its privilege structure. Further cleanup is not needed at
* this point. All important fields are reinitialized when the
* slots are assigned to another, new process.
*/
if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
#if 0
/* Clean up virtual memory */
if (rc->p_misc_flags & MF_VM) {
vm_map_default(rc);
}
#endif
/* release FPU */
if (fpu_owner == rc)
release_fpu();
return OK;
}
#endif /* USE_CLEAR */