sched/irq: Add a configuration option to show interrupt information via a procfs file.
This commit is contained in:
parent
335d1e0030
commit
0080225473
@ -77,6 +77,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
extern const struct procfs_operations proc_operations;
|
extern const struct procfs_operations proc_operations;
|
||||||
|
extern const struct procfs_operations irq_operations;
|
||||||
extern const struct procfs_operations cpuload_operations;
|
extern const struct procfs_operations cpuload_operations;
|
||||||
extern const struct procfs_operations meminfo_operations;
|
extern const struct procfs_operations meminfo_operations;
|
||||||
extern const struct procfs_operations module_operations;
|
extern const struct procfs_operations module_operations;
|
||||||
@ -124,8 +125,12 @@ static const struct procfs_entry_s g_procfs_entries[] =
|
|||||||
{ "cpuload", &cpuload_operations, PROCFS_FILE_TYPE },
|
{ "cpuload", &cpuload_operations, PROCFS_FILE_TYPE },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
{ "irqs", &irq_operations, PROCFS_FILE_TYPE },
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MEMINFO
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MEMINFO
|
||||||
{ "meminfo", &meminfo_operations, PROCFS_FILE_TYPE },
|
{ "meminfo", &meminfo_operations, PROCFS_FILE_TYPE },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_MODULE) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
#if defined(CONFIG_MODULE) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
||||||
@ -133,15 +138,15 @@ static const struct procfs_entry_s g_procfs_entries[] =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_BLOCKS
|
||||||
{ "fs/blocks", &mount_procfsoperations, PROCFS_FILE_TYPE },
|
{ "fs/blocks", &mount_procfsoperations, PROCFS_FILE_TYPE },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_MOUNT
|
||||||
{ "fs/mount", &mount_procfsoperations, PROCFS_FILE_TYPE },
|
{ "fs/mount", &mount_procfsoperations, PROCFS_FILE_TYPE },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
|
#ifndef CONFIG_FS_PROCFS_EXCLUDE_USAGE
|
||||||
{ "fs/usage", &mount_procfsoperations, PROCFS_FILE_TYPE },
|
{ "fs/usage", &mount_procfsoperations, PROCFS_FILE_TYPE },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_FS_SMARTFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
|
#if defined(CONFIG_FS_SMARTFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
|
||||||
|
@ -114,8 +114,8 @@ typedef uint32_t irq_mapped_t;
|
|||||||
|
|
||||||
/* This struct defines the form of an interrupt service routine */
|
/* This struct defines the form of an interrupt service routine */
|
||||||
|
|
||||||
typedef int (*xcpt_t)(int irq, FAR void *context, FAR void *arg);
|
typedef CODE int (*xcpt_t)(int irq, FAR void *context, FAR void *arg);
|
||||||
#endif
|
#endif /* __ASSEMBLY__ */
|
||||||
|
|
||||||
/* Now include architecture-specific types */
|
/* Now include architecture-specific types */
|
||||||
|
|
||||||
|
@ -623,6 +623,15 @@ endmenu # Pthread Options
|
|||||||
|
|
||||||
menu "Performance Monitoring"
|
menu "Performance Monitoring"
|
||||||
|
|
||||||
|
config SCHED_IRQMONITOR
|
||||||
|
bool "Enable IRQ monitoring"
|
||||||
|
default n
|
||||||
|
depends on FS_PROCFS
|
||||||
|
---help---
|
||||||
|
Enabling counting of interrupts from all interrupt sources. These
|
||||||
|
counts will be available in the mounted procfs file systems at the
|
||||||
|
top-level file, "irqs".
|
||||||
|
|
||||||
config SCHED_CPULOAD
|
config SCHED_CPULOAD
|
||||||
bool "Enable CPU load monitoring"
|
bool "Enable CPU load monitoring"
|
||||||
default n
|
default n
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
# sched/irq/Make.defs
|
# sched/irq/Make.defs
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
# Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved.
|
||||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -44,6 +44,13 @@ else ifeq ($(CONFIG_SCHED_INSTRUMENTATION_CSECTION),y)
|
|||||||
CSRCS += irq_csection.c
|
CSRCS += irq_csection.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SCHED_IRQMONITOR),y)
|
||||||
|
CSRCS += irq_foreach.c
|
||||||
|
ifeq ($(CONFIG_FS_PROCFS),y)
|
||||||
|
CSRCS += irq_procfs.c
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
# Include irq build support
|
# Include irq build support
|
||||||
|
|
||||||
DEPPATH += --dep-path irq
|
DEPPATH += --dep-path irq
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/irq/irq.h
|
* sched/irq/irq.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2013-2014, 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2013-2014, 2017-2018 Gregory Nutt. All rights
|
||||||
|
* reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -71,10 +72,26 @@
|
|||||||
|
|
||||||
struct irq_info_s
|
struct irq_info_s
|
||||||
{
|
{
|
||||||
xcpt_t handler; /* Address of the interrupt handler */
|
xcpt_t handler; /* Address of the interrupt handler */
|
||||||
FAR void *arg; /* The argument provided to the interrupt handler. */
|
FAR void *arg; /* The argument provided to the interrupt handler. */
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
systime_t start; /* Time interrupt attached */
|
||||||
|
#ifdef CONFIG_HAVE_LONG_LONG
|
||||||
|
uint64_t count; /* Number of interrupts on this IRQ */
|
||||||
|
#else
|
||||||
|
uint32_t mscount; /* Number of interrupts on this IRQ (MS) */
|
||||||
|
uint32_t lscount; /* Number of interrupts on this IRQ (LS) */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
/* This is the type of the callback from irq_foreach(). */
|
||||||
|
|
||||||
|
typedef CODE int (*irq_foreach_t)(int irq, FAR struct irq_info_s *info,
|
||||||
|
FAR void *arg);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -180,6 +197,36 @@ int irq_unexpected_isr(int irq, FAR void *context, FAR void *arg);
|
|||||||
bool irq_cpu_locked(int cpu);
|
bool irq_cpu_locked(int cpu);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_foreach
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function traverses the internal list of interrupts and provides
|
||||||
|
* information about each attached interrupt.
|
||||||
|
*
|
||||||
|
* Some caution may be necessary: If interrupts are disabled then the
|
||||||
|
* counts may change during the traversal. If pre-emption is enabled, then
|
||||||
|
* the traversed sequence may be widely separated in time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* callback - This function will be called for each attached interrupt
|
||||||
|
* along with the IRQ number, an instance of struct irq_info_s,
|
||||||
|
* and the caller provided argument
|
||||||
|
* args - This is an opaque argument provided with each call to the
|
||||||
|
* callback function.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned after callback has been invoked for all of
|
||||||
|
* the attached interrupts. The callback function may terminate the
|
||||||
|
* traversal at any time by returning a non-zero value. In that case,
|
||||||
|
* irq_foreach will return that non-zero value.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
int irq_foreach(irq_foreach_t callback, FAR void *arg);
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/irq/irq_attach.c
|
* sched/irq/irq_attach.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2008, 2010, 2012, 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2008, 2010, 2012, 2017-2018 Gregory Nutt. All rights
|
||||||
|
* reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -115,6 +116,15 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg)
|
|||||||
|
|
||||||
g_irqvector[ndx].handler = isr;
|
g_irqvector[ndx].handler = isr;
|
||||||
g_irqvector[ndx].arg = arg;
|
g_irqvector[ndx].arg = arg;
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
g_irqvector[ndx].start = clock_systimer();
|
||||||
|
#ifdef CONFIG_HAVE_LONG_LONG
|
||||||
|
g_irqvector[ndx].count = 0;
|
||||||
|
#else
|
||||||
|
g_irqvector[ndx].mscount = 0;
|
||||||
|
g_irqvector[ndx].lscount = 0;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
leave_critical_section(flags);
|
leave_critical_section(flags);
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/irq/irq_dispatch.c
|
* sched/irq/irq_dispatch.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2017-2018 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -46,6 +46,33 @@
|
|||||||
|
|
||||||
#include "irq/irq.h"
|
#include "irq/irq.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
# ifdef CONFIG_HAVE_LONG_LONG
|
||||||
|
# define INCR_COUNT(ndx) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
g_irqvector[ndx].count++; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
# else
|
||||||
|
# define INCR_COUNT(ndx) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if (++g_irqvector[ndx].lscount == 0) \
|
||||||
|
{ \
|
||||||
|
g_irqvector[ndx].mscount++; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define INCR_COUNT(ndx)
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -86,13 +113,14 @@ void irq_dispatch(int irq, FAR void *context)
|
|||||||
{
|
{
|
||||||
vector = g_irqvector[ndx].handler;
|
vector = g_irqvector[ndx].handler;
|
||||||
arg = g_irqvector[ndx].arg;
|
arg = g_irqvector[ndx].arg;
|
||||||
|
INCR_COUNT(ndx);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
vector = g_irqvector[irq].handler;
|
vector = g_irqvector[irq].handler;
|
||||||
arg = g_irqvector[irq].arg;
|
arg = g_irqvector[irq].arg;
|
||||||
|
INCR_COUNT(irq);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
vector = irq_unexpected_isr;
|
vector = irq_unexpected_isr;
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
|
118
sched/irq/irq_foreach.c
Normal file
118
sched/irq/irq_foreach.c
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* sched/irq/irq_foreach.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/irq.h>
|
||||||
|
|
||||||
|
#include "irq/irq.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* This is the number of entries in the interrupt vector table */
|
||||||
|
|
||||||
|
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
|
||||||
|
# define TAB_SIZE CONFIG_ARCH_NUSER_INTERRUPTS
|
||||||
|
#else
|
||||||
|
# define TAB_SIZE NR_IRQS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_foreach
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function traverses the internal list of interrupts and provides
|
||||||
|
* information about each attached interrupt.
|
||||||
|
*
|
||||||
|
* Some caution may be necessary: If interrupts are disabled then the
|
||||||
|
* counts may change during the traversal. If pre-emption is enabled, then
|
||||||
|
* the traversed sequence may be widely separated in time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* callback - This function will be called for each attached interrupt
|
||||||
|
* along with the IRQ number, an instance of struct irq_info_s,
|
||||||
|
* and the caller provided argument
|
||||||
|
* args - This is an opaque argument provided with each call to the
|
||||||
|
* callback function.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned after callback has been invoked for all of
|
||||||
|
* the attached interrupts. The callback function may terminate the
|
||||||
|
* traversal at any time by returning a non-zero value. In that case,
|
||||||
|
* irq_foreach will return that non-zero value.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int irq_foreach(irq_foreach_t callback, FAR void *arg)
|
||||||
|
{
|
||||||
|
int irq;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
DEBUGASSERT(callback != NULL);
|
||||||
|
|
||||||
|
/* Visit each interrupt in the interrupt table */
|
||||||
|
|
||||||
|
for (irq = 0; irq < TAB_SIZE; irq++)
|
||||||
|
{
|
||||||
|
if (g_irqvector[irq].handler != NULL &&
|
||||||
|
g_irqvector[irq].handler != irq_unexpected_isr)
|
||||||
|
{
|
||||||
|
ret = callback(irq, &g_irqvector[irq], arg);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_SCHED_IRQMONITOR */
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* sched/irq/irq_initialize.c
|
* sched/irq/irq_initialize.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2008, 2010, 2018 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -89,5 +89,14 @@ void irq_initialize(void)
|
|||||||
{
|
{
|
||||||
g_irqvector[i].handler = irq_unexpected_isr;
|
g_irqvector[i].handler = irq_unexpected_isr;
|
||||||
g_irqvector[i].arg = NULL;
|
g_irqvector[i].arg = NULL;
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
g_irqvector[i].start = 0;
|
||||||
|
#ifdef CONFIG_HAVE_LONG_LONG
|
||||||
|
g_irqvector[i].count = 0;
|
||||||
|
#else
|
||||||
|
g_irqvector[i].mscount = 0;
|
||||||
|
g_irqvector[i].lscount = 0;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
443
sched/irq/irq_procfs.c
Normal file
443
sched/irq/irq_procfs.c
Normal file
@ -0,0 +1,443 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* sched/irq/irq_procfs.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/fs/fs.h>
|
||||||
|
#include <nuttx/fs/procfs.h>
|
||||||
|
|
||||||
|
#include "irq/irq.h"
|
||||||
|
|
||||||
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS)
|
||||||
|
#ifdef CONFIG_SCHED_IRQMONITOR
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
/* Output format:
|
||||||
|
*
|
||||||
|
* 11111111112222222222333333333344
|
||||||
|
* 12345678901234567890123456789012345678901
|
||||||
|
*
|
||||||
|
* IRQ HANDLER ARGUMENT COUNT RATE
|
||||||
|
* DDD XXXXXXXX XXXXXXXX DDDDDDDDDD DDDD.DDD
|
||||||
|
*
|
||||||
|
* NOTE: This assumes that an address can be represented in 32-bits. In
|
||||||
|
* the typical configuration where CONFIG_HAVE_LONG_LONG=y, the COUNT field
|
||||||
|
* may not be wide enough.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define HDR_FMT "IRQ HANDLER ARGUMENT COUNT RATE\n"
|
||||||
|
#define IRQ_FMT "%3u %08lx %08lx %10lu %4lu.%03lu\n"
|
||||||
|
|
||||||
|
/* Determines the size of an intermediate buffer that must be large enough
|
||||||
|
* to handle the longest line generated by this logic (plus a couple of
|
||||||
|
* bytes).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define IRQ_LINELEN 44
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* This structure describes one open "file" */
|
||||||
|
|
||||||
|
struct irq_file_s
|
||||||
|
{
|
||||||
|
struct procfs_file_s base; /* Base open file structure */
|
||||||
|
FAR char *buffer; /* User provided buffer */
|
||||||
|
size_t remaining; /* Number of available characters in buffer */
|
||||||
|
size_t ncopied; /* Number of characters in buffer */
|
||||||
|
off_t offset; /* Current file offset */
|
||||||
|
char line[IRQ_LINELEN]; /* Pre-allocated buffer for formatted lines */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* irq_foreach() callback function */
|
||||||
|
|
||||||
|
static int irq_callback(int irq, FAR struct irq_info_s *info,
|
||||||
|
FAR void *arg);
|
||||||
|
|
||||||
|
/* File system methods */
|
||||||
|
|
||||||
|
static int irq_open(FAR struct file *filep, FAR const char *relpath,
|
||||||
|
int oflags, mode_t mode);
|
||||||
|
static int irq_close(FAR struct file *filep);
|
||||||
|
static ssize_t irq_read(FAR struct file *filep, FAR char *buffer,
|
||||||
|
size_t buflen);
|
||||||
|
static int irq_dup(FAR const struct file *oldp,
|
||||||
|
FAR struct file *newp);
|
||||||
|
static int irq_stat(FAR const char *relpath, FAR struct stat *buf);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* See fs_mount.c -- this structure is explicitly extern'ed there.
|
||||||
|
* We use the old-fashioned kind of initializers so that this will compile
|
||||||
|
* with any compiler.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const struct procfs_operations irq_operations =
|
||||||
|
{
|
||||||
|
irq_open, /* open */
|
||||||
|
irq_close, /* close */
|
||||||
|
irq_read, /* read */
|
||||||
|
NULL, /* write */
|
||||||
|
|
||||||
|
irq_dup, /* dup */
|
||||||
|
|
||||||
|
NULL, /* opendir */
|
||||||
|
NULL, /* closedir */
|
||||||
|
NULL, /* readdir */
|
||||||
|
NULL, /* rewinddir */
|
||||||
|
|
||||||
|
irq_stat /* stat */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_callback
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int irq_callback(int irq, FAR struct irq_info_s *info,
|
||||||
|
FAR void *arg)
|
||||||
|
{
|
||||||
|
FAR struct irq_file_s *irqfile = (FAR struct irq_file_s *)arg;
|
||||||
|
struct irq_info_s copy;
|
||||||
|
irqstate_t flags;
|
||||||
|
systime_t elapsed;
|
||||||
|
systime_t now;
|
||||||
|
size_t linesize;
|
||||||
|
size_t copysize;
|
||||||
|
unsigned long intpart;
|
||||||
|
unsigned long fracpart;
|
||||||
|
unsigned long count;
|
||||||
|
|
||||||
|
DEBUGASSERT(irqfile != NULL);
|
||||||
|
|
||||||
|
/* Take a snapshot and reset the counts */
|
||||||
|
|
||||||
|
flags = enter_critical_section();
|
||||||
|
memcpy(©, info, sizeof(struct irq_info_s));
|
||||||
|
now = clock_systimer();
|
||||||
|
info->start = now;
|
||||||
|
#ifdef CONFIG_HAVE_LONG_LONG
|
||||||
|
info->count = 0;
|
||||||
|
#else
|
||||||
|
info->mscount = 0;
|
||||||
|
info->lscount = 0;
|
||||||
|
#endif
|
||||||
|
leave_critical_section(flags);
|
||||||
|
|
||||||
|
/* Don't bother if count == 0 */
|
||||||
|
|
||||||
|
if (copy.count == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the interrupt rate from the interrupt count and the elapsed
|
||||||
|
* time.
|
||||||
|
*
|
||||||
|
* REVISIT: If these counts have not been samples and reset in a long time
|
||||||
|
* then the following will likely overflow.
|
||||||
|
*/
|
||||||
|
|
||||||
|
elapsed = now - copy.start;
|
||||||
|
|
||||||
|
#ifdef CONFIG_HAVE_LONG_LONG
|
||||||
|
/* elapsed = <current-time> - <start-time>, units=clock ticks
|
||||||
|
* rate = <interrupt-count> * TICKS_PER_SEC / elapsed
|
||||||
|
*/
|
||||||
|
|
||||||
|
intpart = (unsigned int)((copy.count * TICK_PER_SEC) / elapsed);
|
||||||
|
if (intpart >= 10000)
|
||||||
|
{
|
||||||
|
intpart = 9999;
|
||||||
|
fracpart = 999;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint64_t intcount = (uint64_t)intpart * elapsed / TICK_PER_SEC;
|
||||||
|
fracpart = (unsigned int)
|
||||||
|
(((copy.count - intcount) * TICK_PER_SEC * 1000) / elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure that the count is representable with snprintf format */
|
||||||
|
|
||||||
|
if (copy.count > ULONG_MAX)
|
||||||
|
{
|
||||||
|
count = ULONG_MAX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = (unsigned long)copy.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
# error Missing logic
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Output information about this interrupt */
|
||||||
|
|
||||||
|
linesize = snprintf(irqfile->line, IRQ_LINELEN, IRQ_FMT,
|
||||||
|
(unsigned int)irq,
|
||||||
|
(unsigned long)((uintptr_t)copy.handler),
|
||||||
|
(unsigned long)((uintptr_t)copy.arg),
|
||||||
|
count, intpart, fracpart);
|
||||||
|
|
||||||
|
copysize = procfs_memcpy(irqfile->line, linesize, irqfile->buffer,
|
||||||
|
irqfile->remaining, &irqfile->offset);
|
||||||
|
|
||||||
|
irqfile->ncopied += copysize;
|
||||||
|
irqfile->buffer += copysize;
|
||||||
|
irqfile->remaining -= copysize;
|
||||||
|
|
||||||
|
/* Return a non-zero value to stop the traversal if the user-provided
|
||||||
|
* buffer is full.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (irqfile->remaining > 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_open
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int irq_open(FAR struct file *filep, FAR const char *relpath,
|
||||||
|
int oflags, mode_t mode)
|
||||||
|
{
|
||||||
|
FAR struct irq_file_s *irqfile;
|
||||||
|
|
||||||
|
finfo("Open '%s'\n", relpath);
|
||||||
|
|
||||||
|
/* PROCFS is read-only. Any attempt to open with any kind of write
|
||||||
|
* access is not permitted.
|
||||||
|
*
|
||||||
|
* REVISIT: Write-able proc files could be quite useful.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((oflags & O_WRONLY) != 0 || (oflags & O_RDONLY) == 0)
|
||||||
|
{
|
||||||
|
ferr("ERROR: Only O_RDONLY supported\n");
|
||||||
|
return -EACCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "irqs" is the only acceptable value for the relpath */
|
||||||
|
|
||||||
|
if (strcmp(relpath, "irqs") != 0)
|
||||||
|
{
|
||||||
|
ferr("ERROR: relpath is '%s'\n", relpath);
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate a container to hold the file attributes */
|
||||||
|
|
||||||
|
irqfile = (FAR struct irq_file_s *)kmm_zalloc(sizeof(struct irq_file_s));
|
||||||
|
if (!irqfile)
|
||||||
|
{
|
||||||
|
ferr("ERROR: Failed to allocate file attributes\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the attributes as the open-specific state in filep->f_priv */
|
||||||
|
|
||||||
|
filep->f_priv = (FAR void *)irqfile;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_close
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int irq_close(FAR struct file *filep)
|
||||||
|
{
|
||||||
|
FAR struct irq_file_s *irqfile;
|
||||||
|
|
||||||
|
/* Recover our private data from the struct file instance */
|
||||||
|
|
||||||
|
irqfile = (FAR struct irq_file_s *)filep->f_priv;
|
||||||
|
DEBUGASSERT(irqfile);
|
||||||
|
|
||||||
|
/* Release the file attributes structure */
|
||||||
|
|
||||||
|
kmm_free(irqfile);
|
||||||
|
filep->f_priv = NULL;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_read
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static ssize_t irq_read(FAR struct file *filep, FAR char *buffer,
|
||||||
|
size_t buflen)
|
||||||
|
{
|
||||||
|
FAR struct irq_file_s *irqfile;
|
||||||
|
size_t linesize;
|
||||||
|
size_t copysize;
|
||||||
|
|
||||||
|
finfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
|
||||||
|
|
||||||
|
/* Recover our private data from the struct file instance */
|
||||||
|
|
||||||
|
irqfile = (FAR struct irq_file_s *)filep->f_priv;
|
||||||
|
DEBUGASSERT(irqfile);
|
||||||
|
|
||||||
|
/* Save the file offset and the user buffer information */
|
||||||
|
|
||||||
|
irqfile->offset = filep->f_pos;
|
||||||
|
irqfile->buffer = buffer;
|
||||||
|
irqfile->remaining = buflen;
|
||||||
|
|
||||||
|
/* The first line to output is the header */
|
||||||
|
|
||||||
|
linesize = snprintf(irqfile->line, IRQ_LINELEN, HDR_FMT);
|
||||||
|
|
||||||
|
copysize = procfs_memcpy(irqfile->line, linesize, irqfile->buffer,
|
||||||
|
irqfile->remaining, &irqfile->offset);
|
||||||
|
|
||||||
|
irqfile->ncopied = copysize;
|
||||||
|
irqfile->buffer += copysize;
|
||||||
|
irqfile->remaining -= copysize;
|
||||||
|
|
||||||
|
/* Now traverse the list of attached interrupts, generating output for
|
||||||
|
* each.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(void)irq_foreach(irq_callback, (FAR void *)irqfile);
|
||||||
|
|
||||||
|
/* Update the file position */
|
||||||
|
|
||||||
|
filep->f_pos += irqfile->ncopied;
|
||||||
|
return irqfile->ncopied;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_dup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Duplicate open file data in the new file structure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int irq_dup(FAR const struct file *oldp, FAR struct file *newp)
|
||||||
|
{
|
||||||
|
FAR struct irq_file_s *oldattr;
|
||||||
|
FAR struct irq_file_s *newattr;
|
||||||
|
|
||||||
|
finfo("Dup %p->%p\n", oldp, newp);
|
||||||
|
|
||||||
|
/* Recover our private data from the old struct file instance */
|
||||||
|
|
||||||
|
oldattr = (FAR struct irq_file_s *)oldp->f_priv;
|
||||||
|
DEBUGASSERT(oldattr);
|
||||||
|
|
||||||
|
/* Allocate a new container to hold the task and attribute selection */
|
||||||
|
|
||||||
|
newattr = (FAR struct irq_file_s *)kmm_malloc(sizeof(struct irq_file_s));
|
||||||
|
if (!newattr)
|
||||||
|
{
|
||||||
|
ferr("ERROR: Failed to allocate file attributes\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The copy the file attributes from the old attributes to the new */
|
||||||
|
|
||||||
|
memcpy(newattr, oldattr, sizeof(struct irq_file_s));
|
||||||
|
|
||||||
|
/* Save the new attributes in the new file structure */
|
||||||
|
|
||||||
|
newp->f_priv = (FAR void *)newattr;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: irq_stat
|
||||||
|
*
|
||||||
|
* Description: Return information about a file or directory
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int irq_stat(const char *relpath, struct stat *buf)
|
||||||
|
{
|
||||||
|
/* "irqs" is the only acceptable value for the relpath */
|
||||||
|
|
||||||
|
if (strcmp(relpath, "irqs") != 0)
|
||||||
|
{
|
||||||
|
ferr("ERROR: relpath is '%s'\n", relpath);
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "irqs" is the name for a read-only file */
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(struct stat));
|
||||||
|
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#endif /* CONFIG_SCHED_IRQMONITOR */
|
||||||
|
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS */
|
Loading…
Reference in New Issue
Block a user