2008-09-19 06:56:32 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 04:31:15 +08:00
|
|
|
* sched/irq/irq_dispatch.c
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 23:33:58 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2008-09-19 06:56:32 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2008-09-19 06:56:32 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2008-09-19 06:56:32 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-12-15 02:39:29 +08:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2008-09-19 06:56:32 +08:00
|
|
|
#include <debug.h>
|
2007-02-18 07:21:28 +08:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
2021-04-25 22:57:55 +08:00
|
|
|
#include <nuttx/mm/mm.h>
|
2017-03-30 21:38:37 +08:00
|
|
|
#include <nuttx/random.h>
|
2020-06-16 21:57:49 +08:00
|
|
|
#include <nuttx/sched_note.h>
|
2008-09-19 06:56:32 +08:00
|
|
|
|
2014-08-09 04:31:15 +08:00
|
|
|
#include "irq/irq.h"
|
2018-08-25 21:10:11 +08:00
|
|
|
#include "clock/clock.h"
|
2018-11-15 21:11:51 +08:00
|
|
|
#include "sched/sched.h"
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2018-01-13 07:41:09 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-05 14:57:47 +08:00
|
|
|
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
|
|
|
|
# define NUSER_IRQS CONFIG_ARCH_NUSER_INTERRUPTS
|
|
|
|
#else
|
|
|
|
# define NUSER_IRQS NR_IRQS
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 22:15:10 +08:00
|
|
|
/* CALL_VECTOR - Call the interrupt service routine attached to this
|
|
|
|
* interrupt request
|
2018-08-25 21:10:11 +08:00
|
|
|
*/
|
|
|
|
|
2021-04-29 19:41:27 +08:00
|
|
|
#ifndef CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ
|
|
|
|
# define CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ 0
|
|
|
|
#endif
|
|
|
|
|
2022-04-05 14:50:23 +08:00
|
|
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
2018-08-25 21:10:11 +08:00
|
|
|
# define CALL_VECTOR(ndx, vector, irq, context, arg) \
|
|
|
|
do \
|
|
|
|
{ \
|
2023-09-28 16:37:27 +08:00
|
|
|
clock_t start; \
|
|
|
|
clock_t elapsed; \
|
|
|
|
start = perf_gettime(); \
|
2018-08-25 21:10:11 +08:00
|
|
|
vector(irq, context, arg); \
|
2023-09-28 16:37:27 +08:00
|
|
|
elapsed = perf_gettime() - start; \
|
2022-04-05 14:57:47 +08:00
|
|
|
if (ndx < NUSER_IRQS) \
|
2018-08-25 21:10:11 +08:00
|
|
|
{ \
|
2023-09-28 16:37:27 +08:00
|
|
|
g_irqvector[ndx].count++; \
|
2023-04-23 10:35:13 +08:00
|
|
|
if (elapsed > g_irqvector[ndx].time) \
|
2022-04-05 14:57:47 +08:00
|
|
|
{ \
|
2023-04-23 10:35:13 +08:00
|
|
|
g_irqvector[ndx].time = elapsed; \
|
2022-04-05 14:57:47 +08:00
|
|
|
} \
|
2018-08-25 21:10:11 +08:00
|
|
|
} \
|
2021-04-29 19:41:27 +08:00
|
|
|
if (CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ > 0 && \
|
|
|
|
elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_IRQ) \
|
|
|
|
{ \
|
2023-09-28 16:37:27 +08:00
|
|
|
CRITMONITOR_PANIC("IRQ %d(%p), execute time too long %ju\n", \
|
|
|
|
irq, vector, (uintmax_t)elapsed); \
|
2021-04-29 19:41:27 +08:00
|
|
|
} \
|
2018-08-25 21:10:11 +08:00
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
#else
|
2018-11-27 01:29:20 +08:00
|
|
|
# define CALL_VECTOR(ndx, vector, irq, context, arg) \
|
2022-04-05 14:50:23 +08:00
|
|
|
vector(irq, context, arg)
|
2018-11-27 01:29:20 +08:00
|
|
|
#endif /* CONFIG_SCHED_IRQMONITOR */
|
|
|
|
|
2008-09-19 06:56:32 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Public Functions
|
2008-09-19 06:56:32 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2008-09-19 06:56:32 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Name: irq_dispatch
|
|
|
|
*
|
|
|
|
* Description:
|
2017-03-30 21:38:37 +08:00
|
|
|
* This function must be called from the architecture-specific logic in
|
2012-07-15 03:30:31 +08:00
|
|
|
* order to dispatch an interrupt to the appropriate, registered handling
|
|
|
|
* logic.
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2015-10-03 07:43:18 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-02-28 05:17:21 +08:00
|
|
|
void irq_dispatch(int irq, FAR void *context)
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
2022-09-08 22:38:45 +08:00
|
|
|
#ifdef CONFIG_DEBUG_MM
|
|
|
|
struct tcb_s *rtcb = this_task();
|
|
|
|
#endif
|
2018-08-25 05:01:32 +08:00
|
|
|
xcpt_t vector = irq_unexpected_isr;
|
|
|
|
FAR void *arg = NULL;
|
2018-08-29 21:13:21 +08:00
|
|
|
unsigned int ndx = irq;
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-02-28 05:17:21 +08:00
|
|
|
#if NR_IRQS > 0
|
2018-08-25 05:01:32 +08:00
|
|
|
if ((unsigned)irq < NR_IRQS)
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
2017-03-03 22:55:16 +08:00
|
|
|
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
|
2018-08-29 19:44:05 +08:00
|
|
|
ndx = g_irqmap[irq];
|
2018-08-25 05:01:32 +08:00
|
|
|
if (ndx < CONFIG_ARCH_NUSER_INTERRUPTS)
|
2017-03-03 22:55:16 +08:00
|
|
|
{
|
2018-08-25 05:01:32 +08:00
|
|
|
if (g_irqvector[ndx].handler)
|
|
|
|
{
|
|
|
|
vector = g_irqvector[ndx].handler;
|
|
|
|
arg = g_irqvector[ndx].arg;
|
|
|
|
}
|
2017-03-03 22:55:16 +08:00
|
|
|
}
|
2018-08-25 05:01:32 +08:00
|
|
|
#else
|
2018-08-29 19:44:05 +08:00
|
|
|
if (g_irqvector[ndx].handler)
|
2017-03-03 22:55:16 +08:00
|
|
|
{
|
2018-08-29 19:44:05 +08:00
|
|
|
vector = g_irqvector[ndx].handler;
|
|
|
|
arg = g_irqvector[ndx].arg;
|
2017-03-03 22:55:16 +08:00
|
|
|
}
|
|
|
|
#endif
|
2007-02-18 07:21:28 +08:00
|
|
|
}
|
2007-02-28 05:17:21 +08:00
|
|
|
#endif
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2017-03-30 21:38:37 +08:00
|
|
|
#ifdef CONFIG_CRYPTO_RANDOM_POOL_COLLECT_IRQ_RANDOMNESS
|
|
|
|
/* Add interrupt timing randomness to entropy pool */
|
|
|
|
|
|
|
|
add_irq_randomness(irq);
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 21:57:49 +08:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
/* Notify that we are entering into the interrupt handler */
|
|
|
|
|
|
|
|
sched_note_irqhandler(irq, vector, true);
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 07:21:28 +08:00
|
|
|
/* Then dispatch to the interrupt handler */
|
|
|
|
|
2018-08-25 21:10:11 +08:00
|
|
|
CALL_VECTOR(ndx, vector, irq, context, arg);
|
2018-08-31 00:27:18 +08:00
|
|
|
UNUSED(ndx);
|
2018-11-15 21:11:51 +08:00
|
|
|
|
2020-06-16 21:57:49 +08:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
/* Notify that we are leaving from the interrupt handler */
|
|
|
|
|
|
|
|
sched_note_irqhandler(irq, vector, false);
|
|
|
|
#endif
|
|
|
|
|
2021-04-25 22:57:55 +08:00
|
|
|
#ifdef CONFIG_DEBUG_MM
|
2022-11-12 14:18:25 +08:00
|
|
|
if ((rtcb->flags & TCB_FLAG_HEAP_CHECK) ||
|
|
|
|
(this_task()->flags & TCB_FLAG_HEAP_CHECK))
|
2021-04-25 22:57:55 +08:00
|
|
|
{
|
|
|
|
kmm_checkcorruption();
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-18 07:21:28 +08:00
|
|
|
}
|