1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-14 14:55:41 +00:00

Stage-2 commit of the critical*() code. This re-inlines cpu_critical_enter()

and cpu_critical_exit() and moves associated critical prototypes into their
own header file, <arch>/<arch>/critical.h, which is only included by the
three MI source files that need it.

Backout and re-apply improperly comitted syntactical cleanups made to files
that were still under active development.  Backout improperly comitted program
structure changes that moved localized declarations to the top of two
procedures.  Partially re-apply one of the program structure changes to
move 'mask' into an intermediate block rather then in three separate
sub-blocks to make the code more readable.  Re-integrate bug fixes that Jake
made to the sparc64 code.

Note: In general, developers should not gratuitously move declarations out
of sub-blocks.  They are where they are for reasons of structure, grouping,
readability, compiler-localizability, and to avoid developer-introduced bugs
similar to several found in recent years in the VFS and VM code.

Reviewed by:	jake
This commit is contained in:
Matthew Dillon 2002-04-01 23:51:23 +00:00
parent ad68ab89e2
commit 182da8209d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=93607
29 changed files with 577 additions and 270 deletions

View File

@ -18,24 +18,7 @@
#include <sys/mutex.h>
#include <sys/sysctl.h>
#include <sys/ucontext.h>
void
cpu_critical_enter(void)
{
struct thread *td;
td = curthread;
td->td_md.md_savecrit = intr_disable();
}
void
cpu_critical_exit(void)
{
struct thread *td;
td = curthread;
intr_restore(td->td_md.md_savecrit);
}
#include <machine/critical.h>
/*
* cpu_critical_fork_exit() - cleanup after fork

View File

@ -59,11 +59,6 @@ intr_restore(register_t ipl)
alpha_pal_swpipl(ipl);
}
void cpu_critical_enter(void);
void cpu_critical_exit(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#endif /* _KERNEL */
#endif /* !_MACHINE_CPUFUNC_H_ */

View File

@ -0,0 +1,72 @@
/*-
* Copyright (c) 2002 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* This file contains prototypes and high-level inlines related to
* machine-level critical function support:
*
* cpu_critical_enter() - inlined
* cpu_critical_exit() - inlined
* cpu_critical_fork_exit() - prototyped
* cpu_thread_link() - prototyped
* related support functions residing
* in <arch>/<arch>/critical.c - prototyped
*
* $FreeBSD$
*/
#ifndef _MACHINE_CRITICAL_H_
#define _MACHINE_CRITICAL_H_
__BEGIN_DECLS
/*
* Prototypes - see <arch>/<arch>/critical.c
*/
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#ifdef __GNUC__
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*/
static __inline void
cpu_critical_enter(void)
{
struct thread *td;
td = curthread;
td->td_md.md_savecrit = intr_disable();
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*/
static __inline void
cpu_critical_exit(void)
{
struct thread *td;
td = curthread;
intr_restore(td->td_md.md_savecrit);
}
#else /* !__GNUC__ */
void cpu_critical_enter(void)
void cpu_critical_exit(void)
#endif /* __GNUC__ */
__END_DECLS
#endif /* !_MACHINE_CRITICAL_H_ */

View File

@ -155,7 +155,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -232,7 +232,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX avoid dbl cnt */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -15,6 +15,7 @@
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/ucontext.h>
#include <machine/critical.h>
#ifdef SMP
#include <machine/privatespace.h>
@ -30,7 +31,7 @@
#include <i386/isa/intr_machdep.h>
#endif
void unpend(void); /* note: not static (called from assembly) */
void i386_unpend(void); /* NOTE: not static, called from assembly */
/*
* Instrument our ability to run critical sections with interrupts
@ -43,81 +44,23 @@ SYSCTL_INT(_debug, OID_AUTO, critical_mode,
CTLFLAG_RW, &critical_mode, 0, "");
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*
* If old-style critical section handling (critical_mode == 0), we
* disable interrupts.
*
* If new-style critical section handling (criticla_mode != 0), we
* do not have to do anything. However, as a side effect any
* interrupts occuring while td_critnest is non-zero will be
* deferred.
* cpu_unpend() - called from critical_exit() inline after quick
* interrupt-pending check.
*/
void
cpu_critical_enter(void)
{
struct thread *td;
if (critical_mode == 0) {
td = curthread;
td->td_md.md_savecrit = intr_disable();
}
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*
* If td_critnest is -1 this is the 'new' critical_enter()/exit()
* code (the default critical_mode=1) and we do not have to do
* anything unless PCPU_GET(int_pending) is non-zero.
*
* Note that the td->critnest (1->0) transition interrupt race against
* our int_pending/unpend() check below is handled by the interrupt
* code for us, so we do not have to do anything fancy.
*
* Otherwise td_critnest contains the saved hardware interrupt state
* and will be restored. Since interrupts were hard-disabled there
* will be no pending interrupts to dispatch (the 'original' code).
*/
void
cpu_critical_exit(void)
cpu_unpend(void)
{
register_t eflags;
struct thread *td;
td = curthread;
if (td->td_md.md_savecrit != (register_t)-1) {
intr_restore(td->td_md.md_savecrit);
td->td_md.md_savecrit = (register_t)-1;
} else {
/*
* We may have to schedule pending interrupts. Create
* conditions similar to an interrupt context and call
* unpend().
*
* note: we do this even if we are in an interrupt
* nesting level. Deep nesting is protected by
* critical_*() and if we conditionalized it then we
* would have to check int_pending again whenever
* we decrement td_intr_nesting_level to 0.
*/
if (PCPU_GET(int_pending)) {
eflags = intr_disable();
if (PCPU_GET(int_pending)) {
++td->td_intr_nesting_level;
unpend();
--td->td_intr_nesting_level;
}
intr_restore(eflags);
}
eflags = intr_disable();
if (PCPU_GET(int_pending)) {
++td->td_intr_nesting_level;
i386_unpend();
--td->td_intr_nesting_level;
}
intr_restore(eflags);
}
/*
@ -147,24 +90,26 @@ cpu_thread_link(struct thread *td)
}
/*
* Called from cpu_critical_exit() or called from the assembly vector code
* Called from cpu_unpend or called from the assembly vector code
* to process any interrupts which may have occured while we were in
* a critical section.
*
* - interrupts must be disabled
* - td_critnest must be 0
* - td_intr_nesting_level must be incremented by the caller
*
* NOT STATIC (called from assembly)
*/
void
unpend(void)
i386_unpend(void)
{
int irq;
u_int32_t mask;
KASSERT(curthread->td_critnest == 0, ("unpend critnest != 0"));
KASSERT((read_eflags() & PSL_I) == 0, ("unpend interrupts enabled1"));
curthread->td_critnest = 1;
for (;;) {
u_int32_t mask;
int irq;
/*
* Fast interrupts have priority
*/
@ -207,7 +152,7 @@ unpend(void)
case 1: /* bit 1 - statclock */
mtx_lock_spin(&sched_lock);
statclock_process(curthread->td_kse,
(register_t)unpend, 0);
(register_t)i386_unpend, 0);
mtx_unlock_spin(&sched_lock);
break;
}

View File

@ -624,10 +624,6 @@ u_int rcr0(void);
u_int rcr3(void);
u_int rcr4(void);
void reset_dbregs(void);
void cpu_critical_enter(void);
void cpu_critical_exit(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
__END_DECLS

View File

@ -0,0 +1,111 @@
/*-
* Copyright (c) 2002 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* This file contains prototypes and high-level inlines related to
* machine-level critical function support:
*
* cpu_critical_enter() - inlined
* cpu_critical_exit() - inlined
* cpu_critical_fork_exit() - prototyped
* cpu_thread_link() - prototyped
* related support functions residing
* in <arch>/<arch>/critical.c - prototyped
*
* $FreeBSD$
*/
#ifndef _MACHINE_CRITICAL_H_
#define _MACHINE_CRITICAL_H_
__BEGIN_DECLS
extern int critical_mode;
/*
* Prototypes - see <arch>/<arch>/critical.c
*/
void cpu_unpend(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#ifdef __GNUC__
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*
* If old-style critical section handling (critical_mode == 0), we
* disable interrupts.
*
* If new-style critical section handling (criticla_mode != 0), we
* do not have to do anything. However, as a side effect any
* interrupts occuring while td_critnest is non-zero will be
* deferred.
*/
static __inline void
cpu_critical_enter(void)
{
if (critical_mode == 0) {
struct thread *td = curthread;
td->td_md.md_savecrit = intr_disable();
}
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*
* If td_critnest is -1 this is the 'new' critical_enter()/exit()
* code (the default critical_mode=1) and we do not have to do
* anything unless PCPU_GET(int_pending) is non-zero.
*
* Note that the td->critnest (1->0) transition interrupt race against
* our int_pending/unpend() check below is handled by the interrupt
* code for us, so we do not have to do anything fancy.
*
* Otherwise td_critnest contains the saved hardware interrupt state
* and will be restored. Since interrupts were hard-disabled there
* will be no pending interrupts to dispatch (the 'original' code).
*/
static __inline void
cpu_critical_exit(void)
{
struct thread *td = curthread;
if (td->td_md.md_savecrit != (register_t)-1) {
intr_restore(td->td_md.md_savecrit);
td->td_md.md_savecrit = (register_t)-1;
} else {
/*
* We may have to schedule pending interrupts. Create
* conditions similar to an interrupt context and call
* unpend().
*
* note: we do this even if we are in an interrupt
* nesting level. Deep nesting is protected by
* critical_*() and if we conditionalized it then we
* would have to check int_pending again whenever
* we decrement td_intr_nesting_level to 0.
*/
if (PCPU_GET(int_pending))
cpu_unpend();
}
}
#else /* !__GNUC__ */
void cpu_critical_enter(void)
void cpu_critical_exit(void)
#endif /* __GNUC__ */
__END_DECLS
#endif /* !_MACHINE_CRITICAL_H_ */

View File

@ -125,7 +125,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -197,7 +197,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -125,7 +125,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -197,7 +197,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -125,7 +125,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -197,7 +197,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -155,7 +155,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -232,7 +232,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX avoid dbl cnt */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -15,6 +15,7 @@
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/ucontext.h>
#include <machine/critical.h>
#ifdef SMP
#include <machine/privatespace.h>
@ -30,7 +31,7 @@
#include <i386/isa/intr_machdep.h>
#endif
void unpend(void); /* note: not static (called from assembly) */
void i386_unpend(void); /* NOTE: not static, called from assembly */
/*
* Instrument our ability to run critical sections with interrupts
@ -43,81 +44,23 @@ SYSCTL_INT(_debug, OID_AUTO, critical_mode,
CTLFLAG_RW, &critical_mode, 0, "");
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*
* If old-style critical section handling (critical_mode == 0), we
* disable interrupts.
*
* If new-style critical section handling (criticla_mode != 0), we
* do not have to do anything. However, as a side effect any
* interrupts occuring while td_critnest is non-zero will be
* deferred.
* cpu_unpend() - called from critical_exit() inline after quick
* interrupt-pending check.
*/
void
cpu_critical_enter(void)
{
struct thread *td;
if (critical_mode == 0) {
td = curthread;
td->td_md.md_savecrit = intr_disable();
}
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*
* If td_critnest is -1 this is the 'new' critical_enter()/exit()
* code (the default critical_mode=1) and we do not have to do
* anything unless PCPU_GET(int_pending) is non-zero.
*
* Note that the td->critnest (1->0) transition interrupt race against
* our int_pending/unpend() check below is handled by the interrupt
* code for us, so we do not have to do anything fancy.
*
* Otherwise td_critnest contains the saved hardware interrupt state
* and will be restored. Since interrupts were hard-disabled there
* will be no pending interrupts to dispatch (the 'original' code).
*/
void
cpu_critical_exit(void)
cpu_unpend(void)
{
register_t eflags;
struct thread *td;
td = curthread;
if (td->td_md.md_savecrit != (register_t)-1) {
intr_restore(td->td_md.md_savecrit);
td->td_md.md_savecrit = (register_t)-1;
} else {
/*
* We may have to schedule pending interrupts. Create
* conditions similar to an interrupt context and call
* unpend().
*
* note: we do this even if we are in an interrupt
* nesting level. Deep nesting is protected by
* critical_*() and if we conditionalized it then we
* would have to check int_pending again whenever
* we decrement td_intr_nesting_level to 0.
*/
if (PCPU_GET(int_pending)) {
eflags = intr_disable();
if (PCPU_GET(int_pending)) {
++td->td_intr_nesting_level;
unpend();
--td->td_intr_nesting_level;
}
intr_restore(eflags);
}
eflags = intr_disable();
if (PCPU_GET(int_pending)) {
++td->td_intr_nesting_level;
i386_unpend();
--td->td_intr_nesting_level;
}
intr_restore(eflags);
}
/*
@ -147,24 +90,26 @@ cpu_thread_link(struct thread *td)
}
/*
* Called from cpu_critical_exit() or called from the assembly vector code
* Called from cpu_unpend or called from the assembly vector code
* to process any interrupts which may have occured while we were in
* a critical section.
*
* - interrupts must be disabled
* - td_critnest must be 0
* - td_intr_nesting_level must be incremented by the caller
*
* NOT STATIC (called from assembly)
*/
void
unpend(void)
i386_unpend(void)
{
int irq;
u_int32_t mask;
KASSERT(curthread->td_critnest == 0, ("unpend critnest != 0"));
KASSERT((read_eflags() & PSL_I) == 0, ("unpend interrupts enabled1"));
curthread->td_critnest = 1;
for (;;) {
u_int32_t mask;
int irq;
/*
* Fast interrupts have priority
*/
@ -207,7 +152,7 @@ unpend(void)
case 1: /* bit 1 - statclock */
mtx_lock_spin(&sched_lock);
statclock_process(curthread->td_kse,
(register_t)unpend, 0);
(register_t)i386_unpend, 0);
mtx_unlock_spin(&sched_lock);
break;
}

View File

@ -624,10 +624,6 @@ u_int rcr0(void);
u_int rcr3(void);
u_int rcr4(void);
void reset_dbregs(void);
void cpu_critical_enter(void);
void cpu_critical_exit(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
__END_DECLS

111
sys/i386/include/critical.h Normal file
View File

@ -0,0 +1,111 @@
/*-
* Copyright (c) 2002 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* This file contains prototypes and high-level inlines related to
* machine-level critical function support:
*
* cpu_critical_enter() - inlined
* cpu_critical_exit() - inlined
* cpu_critical_fork_exit() - prototyped
* cpu_thread_link() - prototyped
* related support functions residing
* in <arch>/<arch>/critical.c - prototyped
*
* $FreeBSD$
*/
#ifndef _MACHINE_CRITICAL_H_
#define _MACHINE_CRITICAL_H_
__BEGIN_DECLS
extern int critical_mode;
/*
* Prototypes - see <arch>/<arch>/critical.c
*/
void cpu_unpend(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#ifdef __GNUC__
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*
* If old-style critical section handling (critical_mode == 0), we
* disable interrupts.
*
* If new-style critical section handling (criticla_mode != 0), we
* do not have to do anything. However, as a side effect any
* interrupts occuring while td_critnest is non-zero will be
* deferred.
*/
static __inline void
cpu_critical_enter(void)
{
if (critical_mode == 0) {
struct thread *td = curthread;
td->td_md.md_savecrit = intr_disable();
}
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*
* If td_critnest is -1 this is the 'new' critical_enter()/exit()
* code (the default critical_mode=1) and we do not have to do
* anything unless PCPU_GET(int_pending) is non-zero.
*
* Note that the td->critnest (1->0) transition interrupt race against
* our int_pending/unpend() check below is handled by the interrupt
* code for us, so we do not have to do anything fancy.
*
* Otherwise td_critnest contains the saved hardware interrupt state
* and will be restored. Since interrupts were hard-disabled there
* will be no pending interrupts to dispatch (the 'original' code).
*/
static __inline void
cpu_critical_exit(void)
{
struct thread *td = curthread;
if (td->td_md.md_savecrit != (register_t)-1) {
intr_restore(td->td_md.md_savecrit);
td->td_md.md_savecrit = (register_t)-1;
} else {
/*
* We may have to schedule pending interrupts. Create
* conditions similar to an interrupt context and call
* unpend().
*
* note: we do this even if we are in an interrupt
* nesting level. Deep nesting is protected by
* critical_*() and if we conditionalized it then we
* would have to check int_pending again whenever
* we decrement td_intr_nesting_level to 0.
*/
if (PCPU_GET(int_pending))
cpu_unpend();
}
}
#else /* !__GNUC__ */
void cpu_critical_enter(void)
void cpu_critical_exit(void)
#endif /* __GNUC__ */
__END_DECLS
#endif /* !_MACHINE_CRITICAL_H_ */

View File

@ -155,7 +155,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -232,7 +232,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX avoid dbl cnt */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -125,7 +125,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -197,7 +197,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -125,7 +125,7 @@ IDTVEC(vec_name) ; \
cmpl $0,PCPU(INT_PENDING) ; \
je 2f ; \
; \
call unpend ; \
call i386_unpend ; \
2: ; \
decl TD_INTR_NESTING_LEVEL(%ebx) ; \
10: ; \
@ -197,7 +197,7 @@ IDTVEC(vec_name) ; \
FAKE_MCOUNT(13*4(%esp)) ; /* XXX late to avoid double count */ \
cmpl $0,PCPU(INT_PENDING) ; \
je 9f ; \
call unpend ; \
call i386_unpend ; \
9: ; \
pushl $irq_num; /* pass the IRQ */ \
call sched_ithd ; \

View File

@ -18,24 +18,7 @@
#include <sys/mutex.h>
#include <sys/sysctl.h>
#include <sys/ucontext.h>
void
cpu_critical_enter(void)
{
struct thread *td;
td = curthread;
td->td_md.md_savecrit = intr_disable();
}
void
cpu_critical_exit(void)
{
struct thread *td;
td = curthread;
intr_restore(td->td_md.md_savecrit);
}
#include <machine/critical.h>
/*
* cpu_critical_fork_exit() - cleanup after fork

View File

@ -300,11 +300,6 @@ intr_restore(critical_t psr)
__asm __volatile ("mov psr.l=%0;; srlz.d" :: "r" (psr));
}
void cpu_critical_enter(void);
void cpu_critical_exit(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#endif /* _KERNEL */
#endif /* !_MACHINE_CPUFUNC_H_ */

View File

@ -0,0 +1,73 @@
/*-
* Copyright (c) 2002 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* This file contains prototypes and high-level inlines related to
* machine-level critical function support:
*
* cpu_critical_enter() - inlined
* cpu_critical_exit() - inlined
* cpu_critical_fork_exit() - prototyped
* cpu_thread_link() - prototyped
* related support functions residing
* in <arch>/<arch>/critical.c - prototyped
*
* $FreeBSD$
*/
#ifndef _MACHINE_CRITICAL_H_
#define _MACHINE_CRITICAL_H_
__BEGIN_DECLS
/*
* Prototypes - see <arch>/<arch>/critical.c
*/
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#ifdef __GNUC__
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*/
static __inline void
cpu_critical_enter(void)
{
struct thread *td;
td = curthread;
td->td_md.md_savecrit = intr_disable();
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*/
static __inline void
cpu_critical_exit(void)
{
struct thread *td;
td = curthread;
intr_restore(td->td_md.md_savecrit);
}
#else /* !__GNUC__ */
void cpu_critical_enter(void)
void cpu_critical_exit(void)
#endif /* __GNUC__ */
__END_DECLS
#endif /* !_MACHINE_CRITICAL_H_ */

View File

@ -70,6 +70,7 @@
#include <sys/vmmeter.h>
#include <sys/user.h>
#include <machine/critical.h>
static MALLOC_DEFINE(M_ATFORK, "atfork", "atfork callback");

View File

@ -54,6 +54,7 @@
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/uma.h>
#include <machine/critical.h>
MALLOC_DEFINE(M_PGRP, "pgrp", "process group header");
MALLOC_DEFINE(M_SESSION, "session", "session header");

View File

@ -34,6 +34,7 @@
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <machine/critical.h>
/*
* Global run queue.

View File

@ -132,12 +132,6 @@ powerpc_get_pcpup(void)
return(ret);
}
void cpu_critical_enter(void);
void cpu_critical_exit(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#endif /* _KERNEL */
#endif /* !_MACHINE_CPUFUNC_H_ */

View File

@ -0,0 +1,76 @@
/*-
* Copyright (c) 2002 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* This file contains prototypes and high-level inlines related to
* machine-level critical function support:
*
* cpu_critical_enter() - inlined
* cpu_critical_exit() - inlined
* cpu_critical_fork_exit() - prototyped
* cpu_thread_link() - prototyped
* related support functions residing
* in <arch>/<arch>/critical.c - prototyped
*
* $FreeBSD$
*/
#ifndef _MACHINE_CRITICAL_H_
#define _MACHINE_CRITICAL_H_
__BEGIN_DECLS
/*
* Prototypes - see <arch>/<arch>/critical.c
*/
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#ifdef __GNUC__
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*/
static __inline void
cpu_critical_enter(void)
{
u_int msr;
struct thread *td = curthread;
msr = mfmsr();
td->td_md.md_savecrit = msr;
msr &= ~(PSL_EE | PSL_RI);
mtmsr(msr);
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*/
static __inline void
cpu_critical_exit(void)
{
struct thread *td = curthread;
mtmsr(td->td_md.md_savecrit);
}
#else /* !__GNUC__ */
void cpu_critical_enter(void)
void cpu_critical_exit(void)
#endif /* __GNUC__ */
__END_DECLS
#endif /* !_MACHINE_CRITICAL_H_ */

View File

@ -19,26 +19,6 @@
#include <sys/sysctl.h>
#include <sys/ucontext.h>
void
cpu_critical_enter(void)
{
u_int msr;
struct thread *td = curthread;
msr = mfmsr();
td->td_md.md_savecrit = msr;
msr &= ~(PSL_EE | PSL_RI);
mtmsr(msr);
}
void
cpu_critical_exit(void)
{
struct thread *td = curthread;
mtmsr(td->td_md.md_savecrit);
}
/*
* cpu_critical_fork_exit() - cleanup after fork
*/

View File

@ -224,9 +224,4 @@ ffs(int mask)
#undef LDNC_GEN
#undef STNC_GEN
void cpu_critical_enter(void);
void cpu_critical_exit(void);
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#endif /* !_MACHINE_CPUFUNC_H_ */

View File

@ -0,0 +1,75 @@
/*-
* Copyright (c) 2002 Matthew Dillon. This code is distributed under
* the BSD copyright, /usr/src/COPYRIGHT.
*
* This file contains prototypes and high-level inlines related to
* machine-level critical function support:
*
* cpu_critical_enter() - inlined
* cpu_critical_exit() - inlined
* cpu_critical_fork_exit() - prototyped
* cpu_thread_link() - prototyped
* related support functions residing
* in <arch>/<arch>/critical.c - prototyped
*
* $FreeBSD$
*/
#ifndef _MACHINE_CRITICAL_H_
#define _MACHINE_CRITICAL_H_
__BEGIN_DECLS
/*
* Prototypes - see <arch>/<arch>/critical.c
*/
void cpu_critical_fork_exit(void);
void cpu_thread_link(struct thread *td);
#ifdef __GNUC__
/*
* cpu_critical_enter:
*
* This routine is called from critical_enter() on the 0->1 transition
* of td_critnest, prior to it being incremented to 1.
*/
static __inline void
cpu_critical_enter(void)
{
struct thread *td;
critical_t pil;
td = curthread;
pil = rdpr(pil);
wrpr(pil, 0, 14);
td->td_md.md_savecrit = pil;
}
/*
* cpu_critical_exit:
*
* This routine is called from critical_exit() on a 1->0 transition
* of td_critnest, after it has been decremented to 0. We are
* exiting the last critical section.
*/
static __inline void
cpu_critical_exit(void)
{
struct thread *td;
td = curthread;
wrpr(pil, td->td_md.md_savecrit, 0);
}
#else /* !__GNUC__ */
void cpu_critical_enter(void)
void cpu_critical_exit(void)
#endif /* __GNUC__ */
__END_DECLS
#endif /* !_MACHINE_CRITICAL_H_ */

View File

@ -19,27 +19,6 @@
#include <sys/sysctl.h>
#include <sys/ucontext.h>
void
cpu_critical_enter(void)
{
struct thread *td;
critical_t pil;
td = curthread;
pil = rdpr(pil);
wrpr(pil, 0, 14);
td->td_md.md_savecrit = pil;
}
void
cpu_critical_exit(void)
{
struct thread *td;
td = curthread;
wrpr(pil, td->td_md.md_savecrit, 0);
}
/*
* cpu_critical_fork_exit() - cleanup after fork
*/