This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Knowing current context
- From: David Brennan <eCos at brennanhome dot com>
- To: ecos-patches at sources dot redhat dot com
- Date: Sat, 23 Oct 2004 08:32:33 -0700
- Subject: Knowing current context
For our application, it is desirable to know if a section of code is
running in interrupt context. (Specifically we have a custom assert
function, and our arrays are protected, so if the interrupt routine goes
out of bounds on the array, the assert will fire. We are in the process
of writing a custom "print" function that can be used in interrupt
context, but we only want it to work in interrupt context, otherwise we
will use our normal messaging system.) This code performs that function.
(Although it requires platform specific implementation in vectors.S,
which I provided for i386.) I went ahead and put DSR tracking in also,
although it is not as necessary for our application.
David Brennan
Index: hal/i386/arch/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/i386/arch/current/ChangeLog,v
retrieving revision 1.41
diff -u -5 -w -r1.41 ChangeLog
--- hal/i386/arch/current/ChangeLog 22 Apr 2004 15:26:37 -0000 1.41
+++ hal/i386/arch/current/ChangeLog 23 Oct 2004 15:22:44 -0000
@@ -1,5 +1,10 @@
+2004-10-22 David Brennan <eCos@brennanhome.com.com>
+
+ * src/vectors.S: Added configurable feature to allow user code to
+ determine if it is running in ISR context.
+
2004-04-22 Jani Monoses <jani@iv.ro>
* cdl/hal_i386.cdl :
Invoke tail with stricter syntax that works in latest coreutils.
Index: hal/i386/arch/current/src/vectors.S
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/i386/arch/current/src/vectors.S,v
retrieving revision 1.16
diff -u -5 -w -r1.16 vectors.S
--- hal/i386/arch/current/src/vectors.S 1 Dec 2002 15:50:14 -0000 1.16
+++ hal/i386/arch/current/src/vectors.S 23 Oct 2004 15:05:41 -0000
@@ -506,10 +506,16 @@
# Increment scheduler lock
.extern cyg_scheduler_sched_lock
incl cyg_scheduler_sched_lock
#endif
+#if defined(CYGIMP_KERNEL_INTERRUPTS_TRACK_ISR_CONTEXT)
+ # Increment ISR level
+ .extern _cyg_kernel_interrupt_isr_level
+ incl _cyg_kernel_interrupt_isr_level
+#endif
+
movl %esp,%ebp # EBP = copy of ESP
# adjust ESP by 16 for the state stored before the pusha
add $16,i386reg_esp(%esp)
Index: kernel/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/ChangeLog,v
retrieving revision 1.121
diff -u -5 -w -r1.121 ChangeLog
--- kernel/current/ChangeLog 24 Sep 2004 16:57:12 -0000 1.121
+++ kernel/current/ChangeLog 23 Oct 2004 15:18:25 -0000
@@ -1,5 +1,13 @@
+2004-10-22 David Brennan <eCos@brennanhome.com.com>
+
+ * include/kapi.h:
+ * cdl/kernel.cdl:
+ * src/intr/intr.cxx: Added configurable feature to allow user code to
+ determine if it is running in ISR/DSR context. (ISR requires a mode
+ to vectors.S, see i386 for example)
+
2004-09-24 Nick Garnett <nickg@ecoscentric.com>
* src/sched/mlqueue.cxx (enqueue): Fix bug in sorted queue
insertion: priority test was inverted. Spotted by TomChen.
Index: kernel/current/cdl/kernel.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/cdl/kernel.cdl,v
retrieving revision 1.20
diff -u -5 -w -r1.20 kernel.cdl
--- kernel/current/cdl/kernel.cdl 1 Jul 2003 17:34:53 -0000 1.20
+++ kernel/current/cdl/kernel.cdl 23 Oct 2004 15:06:08 -0000
@@ -86,10 +86,28 @@
concepts, for example Delayed Service Routines."
script interrupts.cdl
}
+ cdl_option CYGIMP_KERNEL_INTERRUPTS_TRACK_ISR_CONTEXT {
+ display "Track whether or not currently in interrupt context"
+ default_value 0
+ description "
+ In some (user) functions it may be desireable to know if the
+ current context is interrupt context, and possibly perform
+ some functions differently. This option provides that feature"
+ }
+
+ cdl_option CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT {
+ display "Track whether or not currently in DSR context"
+ default_value 0
+ description "
+ In some (user) functions it may be desireable to know if the
+ current context is DSR context, and possibly perform
+ some functions differently. This option provides that feature"
+ }
+
# ---------------------------------------------------------------------
# Exceptions. Currently there are only two options. The first
# determines whether or not exceptions are enabled at all. The
# second controls whether they apply globally or on a per-thread
# basis. There should probably be more options, but the boundary
Index: kernel/current/include/kapi.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/include/kapi.h,v
retrieving revision 1.20
diff -u -5 -w -r1.20 kapi.h
--- kernel/current/include/kapi.h 15 Mar 2004 15:20:53 -0000 1.20
+++ kernel/current/include/kapi.h 23 Oct 2004 15:17:24 -0000
@@ -361,10 +361,17 @@
cyg_cpu_t cyg_interrupt_get_cpu(
cyg_vector_t vector /* vector to control */
) __THROW;
+/* ISR/DSR context access */
+/* if return value > 0 in ISR context */
+cyg_atomic cyg_interrupt_isr_level(void) __THROW;
+
+/* if return value > 0 in DSR context */
+cyg_atomic cyg_interrupt_dsr_level(void) __THROW;
+
/*---------------------------------------------------------------------------*/
/* Counters, Clocks and Alarms */
void cyg_counter_create(
cyg_handle_t *handle, /* returned counter handle */
sIndex: kernel/current/src/intr/intr.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/intr/intr.cxx,v
retrieving revision 1.17
diff -u -5 -w -r1.17 intr.cxx
--- kernel/current/src/intr/intr.cxx 23 May 2002 23:06:54 -0000 1.17
+++ kernel/current/src/intr/intr.cxx 23 Oct 2004 15:06:10 -0000
@@ -137,17 +137,31 @@
Cyg_Interrupt* volatile Cyg_Interrupt::dsr_list[CYGNUM_KERNEL_CPU_MAX];
#endif
+#ifdef CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT
+static cyg_atomic current_dsr_level = 0;
+
+externC cyg_atomic
+cyg_interrupt_dsr_level()
+{
+ return current_dsr_level;
+}
+
+#endif // CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT
+
// -------------------------------------------------------------------------
// Call any pending DSRs
void
Cyg_Interrupt::call_pending_DSRs_inner(void)
{
// CYG_REPORT_FUNCTION();
+#ifdef CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT
+ current_dsr_level++;
+#endif // CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT
HAL_SMP_CPU_TYPE cpu = CYG_KERNEL_CPU_THIS();
#ifdef CYGIMP_KERNEL_INTERRUPTS_DSRS_TABLE
@@ -191,10 +205,14 @@
}
#endif
+#ifdef CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT
+ current_dsr_level--;
+#endif // CYGIMP_KERNEL_INTERRUPTS_TRACK_DSR_CONTEXT
+
};
externC void
cyg_interrupt_call_pending_DSRs(void)
{
@@ -270,10 +288,21 @@
Cyg_Interrupt* intr = (Cyg_Interrupt*) intr_obj;
intr->post_dsr ();
}
// -------------------------------------------------------------------------
+#ifdef CYGIMP_KERNEL_INTERRUPTS_TRACK_ISR_CONTEXT
+volatile cyg_atomic current_isr_level
+ CYGBLD_ATTRIB_ASM_ALIAS( _cyg_kernel_interrupt_isr_level ) = 0;
+
+externC cyg_atomic
+cyg_interrupt_isr_level()
+{
+ return current_isr_level;
+}
+
+#endif // CYGIMP_KERNEL_INTERRUPTS_TRACK_ISR_CONTEXT
// FIXME: should have better name - Jifl
externC void
interrupt_end(
cyg_uint32 isr_ret,
@@ -314,10 +343,15 @@
Cyg_Scheduler::get_current_thread()->set_saved_context(regs);
#endif
+#ifdef CYGIMP_KERNEL_INTERRUPTS_TRACK_ISR_CONTEXT
+ // This isr is now complete
+ current_isr_level--;
+#endif // CYGIMP_KERNEL_INTERRUPTS_TRACK_ISR_CONTEXT
+
// Now unlock the scheduler, which may also call DSRs
// and cause a thread switch to happen.
Cyg_Scheduler::unlock();