sched/note: Move the circle buffer code to driver

so the format code can be shared by different transport

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2020-08-07 02:57:30 +08:00
committed by liuguo09
parent f99719e260
commit 952af92690
20 changed files with 540 additions and 456 deletions
@@ -26,6 +26,7 @@ CONFIG_CXD56_SPI5=y
CONFIG_CXD56_SPI=y CONFIG_CXD56_SPI=y
CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DRIVER_NOTE=y
CONFIG_EXAMPLES_HELLO=y CONFIG_EXAMPLES_HELLO=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y CONFIG_FS_PROCFS_REGISTER=y
@@ -45,7 +46,6 @@ CONFIG_RR_INTERVAL=200
CONFIG_RTC=y CONFIG_RTC=y
CONFIG_RTC_DRIVER=y CONFIG_RTC_DRIVER=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SDCLONE_DISABLE=y CONFIG_SDCLONE_DISABLE=y
CONFIG_SMP=y CONFIG_SMP=y
CONFIG_SMP_NCPUS=2 CONFIG_SMP_NCPUS=2
@@ -23,6 +23,7 @@ CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DRIVER_NOTE=y
CONFIG_EXAMPLES_HELLO=y CONFIG_EXAMPLES_HELLO=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y CONFIG_HAVE_CXX=y
@@ -49,7 +50,6 @@ CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SMP=y CONFIG_SMP=y
CONFIG_SPINLOCK_IRQ=y CONFIG_SPINLOCK_IRQ=y
CONFIG_START_MONTH=3 CONFIG_START_MONTH=3
@@ -36,6 +36,7 @@ CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_AUDIO=y CONFIG_DRIVERS_AUDIO=y
CONFIG_DRIVER_NOTE=y
CONFIG_DVFS=y CONFIG_DVFS=y
CONFIG_EXAMPLES_HELLO=y CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_I2SLOOP=y CONFIG_EXAMPLES_I2SLOOP=y
@@ -146,7 +147,6 @@ CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_INSTRUMENTATION_PREEMPTION=y CONFIG_SCHED_INSTRUMENTATION_PREEMPTION=y
CONFIG_SCHED_LPWORK=y CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=60 CONFIG_SCHED_LPWORKPRIORITY=60
@@ -22,6 +22,7 @@ CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVER_NOTE=y
CONFIG_ELF=y CONFIG_ELF=y
CONFIG_EXAMPLES_ELF=y CONFIG_EXAMPLES_ELF=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
@@ -54,7 +55,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=32 CONFIG_SCHED_ONEXIT_MAX=32
CONFIG_SCHED_STARTHOOK=y CONFIG_SCHED_STARTHOOK=y
@@ -21,6 +21,7 @@ CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_MQUEUE=y CONFIG_DISABLE_MQUEUE=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVER_NOTE=y
CONFIG_FAT_LCNAMES=y CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y CONFIG_FS_FAT=y
@@ -54,7 +55,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=32 CONFIG_SCHED_ONEXIT_MAX=32
CONFIG_SCHED_STARTHOOK=y CONFIG_SCHED_STARTHOOK=y
@@ -29,6 +29,7 @@ CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVER_NOTE=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
CONFIG_HRT_TIMER=y CONFIG_HRT_TIMER=y
CONFIG_I2C=y CONFIG_I2C=y
@@ -99,7 +100,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=32 CONFIG_SCHED_ONEXIT_MAX=32
CONFIG_SCHED_STARTHOOK=y CONFIG_SCHED_STARTHOOK=y
@@ -37,6 +37,7 @@ CONFIG_DEV_URANDOM=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_AUDIO=y CONFIG_DRIVERS_AUDIO=y
CONFIG_DRIVER_NOTE=y
CONFIG_DVFS=y CONFIG_DVFS=y
CONFIG_ELF=y CONFIG_ELF=y
CONFIG_EXAMPLES_HELLO=m CONFIG_EXAMPLES_HELLO=m
@@ -154,7 +155,6 @@ CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_INSTRUMENTATION_PREEMPTION=y CONFIG_SCHED_INSTRUMENTATION_PREEMPTION=y
CONFIG_SCHED_LPWORK=y CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=60 CONFIG_SCHED_LPWORKPRIORITY=60
@@ -28,6 +28,7 @@ CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVER_NOTE=y
CONFIG_EXAMPLES_ADC=y CONFIG_EXAMPLES_ADC=y
CONFIG_EXAMPLES_ADC_GROUPSIZE=6 CONFIG_EXAMPLES_ADC_GROUPSIZE=6
CONFIG_EXAMPLES_ADC_SWTRIG=y CONFIG_EXAMPLES_ADC_SWTRIG=y
@@ -104,7 +105,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=32 CONFIG_SCHED_ONEXIT_MAX=32
CONFIG_SCHED_STARTHOOK=y CONFIG_SCHED_STARTHOOK=y
@@ -21,6 +21,7 @@ CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVER_NOTE=y
CONFIG_ELF=y CONFIG_ELF=y
CONFIG_EXAMPLES_POSIXSPAWN=y CONFIG_EXAMPLES_POSIXSPAWN=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
@@ -53,7 +54,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=32 CONFIG_SCHED_ONEXIT_MAX=32
CONFIG_SCHED_STARTHOOK=y CONFIG_SCHED_STARTHOOK=y
@@ -35,6 +35,7 @@ CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVERS_AUDIO=y CONFIG_DRIVERS_AUDIO=y
CONFIG_DRIVER_NOTE=y
CONFIG_DVFS=y CONFIG_DVFS=y
CONFIG_ELF=y CONFIG_ELF=y
CONFIG_EXAMPLES_HELLO=m CONFIG_EXAMPLES_HELLO=m
@@ -154,7 +155,6 @@ CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_INSTRUMENTATION_PREEMPTION=y CONFIG_SCHED_INSTRUMENTATION_PREEMPTION=y
CONFIG_SCHED_LPWORK=y CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIORITY=60 CONFIG_SCHED_LPWORKPRIORITY=60
@@ -27,6 +27,7 @@ CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DISABLE_POSIX_TIMERS=y CONFIG_DISABLE_POSIX_TIMERS=y
CONFIG_DRIVER_NOTE=y
CONFIG_ELF=y CONFIG_ELF=y
CONFIG_ELF_BUFFERSIZE=512 CONFIG_ELF_BUFFERSIZE=512
CONFIG_EXAMPLES_ADC=y CONFIG_EXAMPLES_ADC=y
@@ -107,7 +108,6 @@ CONFIG_SCHED_ATEXIT=y
CONFIG_SCHED_CHILD_STATUS=y CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=32 CONFIG_SCHED_ONEXIT_MAX=32
CONFIG_SCHED_STARTHOOK=y CONFIG_SCHED_STARTHOOK=y
@@ -31,6 +31,7 @@ CONFIG_C99_BOOL8=y
CONFIG_CDCACM=y CONFIG_CDCACM=y
CONFIG_CDCACM_EPINTIN_HSSIZE=512 CONFIG_CDCACM_EPINTIN_HSSIZE=512
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DRIVER_NOTE=y
CONFIG_FAT_DMAMEMORY=y CONFIG_FAT_DMAMEMORY=y
CONFIG_FAT_LCNAMES=y CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y CONFIG_FAT_LFN=y
@@ -69,7 +70,6 @@ CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_HPWORKSTACKSIZE=1800 CONFIG_SCHED_HPWORKSTACKSIZE=1800
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SCHED_LPWORK=y CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKSTACKSIZE=1800 CONFIG_SCHED_LPWORKSTACKSIZE=1800
CONFIG_SCHED_NOTE_BUFSIZE=512 CONFIG_SCHED_NOTE_BUFSIZE=512
@@ -21,6 +21,7 @@ CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y CONFIG_DEV_ZERO=y
CONFIG_DRIVER_NOTE=y
CONFIG_EXAMPLES_HELLO=y CONFIG_EXAMPLES_HELLO=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y CONFIG_FS_PROCFS_REGISTER=y
@@ -48,7 +49,6 @@ CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200 CONFIG_RR_INTERVAL=200
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SMP=y CONFIG_SMP=y
CONFIG_SMP_NCPUS=2 CONFIG_SMP_NCPUS=2
CONFIG_SPINLOCK_IRQ=y CONFIG_SPINLOCK_IRQ=y
@@ -20,6 +20,7 @@ CONFIG_BUILTIN=y
CONFIG_DEBUG_FEATURES=y CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_SYMBOLS=y
CONFIG_DRIVER_NOTE=y
CONFIG_ESP32_UART0=y CONFIG_ESP32_UART0=y
CONFIG_EXAMPLES_HELLO=y CONFIG_EXAMPLES_HELLO=y
CONFIG_EXPERIMENTAL=y CONFIG_EXPERIMENTAL=y
@@ -44,7 +45,6 @@ CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200 CONFIG_RR_INTERVAL=200
CONFIG_SCHED_INSTRUMENTATION=y CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_BUFFER=y
CONFIG_SDCLONE_DISABLE=y CONFIG_SDCLONE_DISABLE=y
CONFIG_SMP=y CONFIG_SMP=y
CONFIG_SMP_IDLETHREAD_STACKSIZE=3072 CONFIG_SMP_IDLETHREAD_STACKSIZE=3072
+29 -2
View File
@@ -8,10 +8,37 @@ menu "Note Driver Support"
config DRIVER_NOTE config DRIVER_NOTE
bool "Scheduler instrumentation driver" bool "Scheduler instrumentation driver"
default n default n
depends on SCHED_INSTRUMENTATION_BUFFER && SCHED_NOTE_GET depends on !SCHED_INSTRUMENTATION_CSECTION && (!SCHED_INSTRUMENTATION_SPINLOCK || !SMP)
---help--- ---help---
Enable building a serial driver that can be used by an application If this option is selected, then in-memory buffering logic is
enabled to capture scheduler instrumentation data. This has
the advantage that (1) the platform logic does not have to provide
the sched_note_* interfaces described for the previous settings.
Instead, the buffering logic catches all of these. It encodes
timestamps the scheduler note and adds the note to an in-memory,
circular buffer. And (2) buffering the scheduler instrumentation
data (versus performing some output operation) minimizes the impact
of the instrumentation on the behavior of the system. If the in-memory
buffer becomes full, then older notes are overwritten by newer notes.
A character driver is provided which can be used by an application
to read data from the in-memory, scheduler instrumentation "note" to read data from the in-memory, scheduler instrumentation "note"
buffer. buffer.
NOTE: This option is not available if critical sections are being
monitor (nor if spinlocks are being monitored in SMP configuration)
because there would be a logical error in the design in those cases.
That error is that these interfaces call enter_ and leave_critical_section
(and which us spinlocks in SMP mode). That means that each call to
sched_note_get() causes several additional entries to be added from
the note buffer in order to remove one entry.
config SCHED_NOTE_BUFSIZE
int "Instrumentation buffer size"
depends on DRIVER_NOTE
default 2048
---help---
The size of the in-memory, circular instrumentation buffer (in
bytes).
endmenu endmenu
+312 -4
View File
@@ -44,11 +44,20 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <nuttx/spinlock.h>
#include <nuttx/sched_note.h> #include <nuttx/sched_note.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ /****************************************************************************
defined(CONFIG_DRIVER_NOTE) * Private Types
****************************************************************************/
struct note_info_s
{
volatile unsigned int ni_head;
volatile unsigned int ni_tail;
uint8_t ni_buffer[CONFIG_SCHED_NOTE_BUFSIZE];
};
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
@@ -75,10 +84,246 @@ static const struct file_operations note_fops =
#endif #endif
}; };
static struct note_info_s g_note_info;
#ifdef CONFIG_SMP
static volatile spinlock_t g_note_lock;
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: note_next
*
* Description:
* Return the circular buffer index at offset from the specified index
* value, handling wraparound
*
* Input Parameters:
* ndx - Old circular buffer index
*
* Returned Value:
* New circular buffer index
*
****************************************************************************/
static inline unsigned int note_next(unsigned int ndx, unsigned int offset)
{
ndx += offset;
if (ndx >= CONFIG_SCHED_NOTE_BUFSIZE)
{
ndx -= CONFIG_SCHED_NOTE_BUFSIZE;
}
return ndx;
}
/****************************************************************************
* Name: note_length
*
* Description:
* Length of data currently in circular buffer.
*
* Input Parameters:
* None
*
* Returned Value:
* Length of data currently in circular buffer.
*
****************************************************************************/
static unsigned int note_length(void)
{
unsigned int head = g_note_info.ni_head;
unsigned int tail = g_note_info.ni_tail;
if (tail > head)
{
head += CONFIG_SCHED_NOTE_BUFSIZE;
}
return head - tail;
}
/****************************************************************************
* Name: note_remove
*
* Description:
* Remove the variable length note from the tail of the circular buffer
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
* Assumptions:
* We are within a critical section.
*
****************************************************************************/
static void note_remove(void)
{
FAR struct note_common_s *note;
unsigned int tail;
unsigned int length;
/* Get the tail index of the circular buffer */
tail = g_note_info.ni_tail;
DEBUGASSERT(tail < CONFIG_SCHED_NOTE_BUFSIZE);
/* Get the length of the note at the tail index */
note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail];
length = note->nc_length;
DEBUGASSERT(length <= note_length());
/* Increment the tail index to remove the entire note from the circular
* buffer.
*/
g_note_info.ni_tail = note_next(tail, length);
}
/****************************************************************************
* Name: sched_note_get
*
* Description:
* Remove the next note from the tail of the circular buffer. The note
* is also removed from the circular buffer to make room for further notes.
*
* Input Parameters:
* buffer - Location to return the next note
* buflen - The length of the user provided buffer.
*
* Returned Value:
* On success, the positive, non-zero length of the return note is
* provided. Zero is returned only if the circular buffer is empty. A
* negated errno value is returned in the event of any failure.
*
****************************************************************************/
static ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen)
{
FAR struct note_common_s *note;
irqstate_t flags;
unsigned int remaining;
unsigned int tail;
ssize_t notelen;
size_t circlen;
DEBUGASSERT(buffer != NULL);
flags = enter_critical_section();
/* Verify that the circular buffer is not empty */
circlen = note_length();
if (circlen <= 0)
{
notelen = 0;
goto errout_with_csection;
}
/* Get the index to the tail of the circular buffer */
tail = g_note_info.ni_tail;
DEBUGASSERT(tail < CONFIG_SCHED_NOTE_BUFSIZE);
/* Get the length of the note at the tail index */
note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail];
notelen = note->nc_length;
DEBUGASSERT(notelen <= circlen);
/* Is the user buffer large enough to hold the note? */
if (buflen < notelen)
{
/* Remove the large note so that we do not get constipated. */
note_remove();
/* and return an error */
notelen = -EFBIG;
goto errout_with_csection;
}
/* Loop until the note has been transferred to the user buffer */
remaining = (unsigned int)notelen;
while (remaining > 0)
{
/* Copy the next byte at the tail index */
*buffer++ = g_note_info.ni_buffer[tail];
/* Adjust indices and counts */
tail = note_next(tail, 1);
remaining--;
}
g_note_info.ni_tail = tail;
errout_with_csection:
leave_critical_section(flags);
return notelen;
}
/****************************************************************************
* Name: sched_note_size
*
* Description:
* Return the size of the next note at the tail of the circular buffer.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero is returned if the circular buffer is empty. Otherwise, the size
* of the next note is returned.
*
****************************************************************************/
static ssize_t sched_note_size(void)
{
FAR struct note_common_s *note;
irqstate_t flags;
unsigned int tail;
ssize_t notelen;
size_t circlen;
flags = enter_critical_section();
/* Verify that the circular buffer is not empty */
circlen = note_length();
if (circlen <= 0)
{
notelen = 0;
goto errout_with_csection;
}
/* Get the index to the tail of the circular buffer */
tail = g_note_info.ni_tail;
DEBUGASSERT(tail < CONFIG_SCHED_NOTE_BUFSIZE);
/* Get the length of the note at the tail index */
note = (FAR struct note_common_s *)&g_note_info.ni_buffer[tail];
notelen = note->nc_length;
DEBUGASSERT(notelen <= circlen);
errout_with_csection:
leave_critical_section(flags);
return notelen;
}
/**************************************************************************** /****************************************************************************
* Name: note_read * Name: note_read
****************************************************************************/ ****************************************************************************/
@@ -143,6 +388,71 @@ static ssize_t note_read(FAR struct file *filep, FAR char *buffer,
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: note_add
*
* Description:
* Add the variable length note to the transport layer
*
* Input Parameters:
* note - The note buffer
* notelen - The buffer length
*
* Returned Value:
* None
*
* Assumptions:
* We are within a critical section.
*
****************************************************************************/
void note_add(FAR const uint8_t *note, uint8_t notelen)
{
unsigned int head;
unsigned int next;
#ifdef CONFIG_SMP
irqstate_t flags = up_irq_save();
spin_lock_wo_note(&g_note_lock);
#endif
/* Get the index to the head of the circular buffer */
DEBUGASSERT(note != NULL && notelen < CONFIG_SCHED_NOTE_BUFSIZE);
head = g_note_info.ni_head;
/* Loop until all bytes have been transferred to the circular buffer */
while (notelen > 0)
{
/* Get the next head index. Would it collide with the current tail
* index?
*/
next = note_next(head, 1);
if (next == g_note_info.ni_tail)
{
/* Yes, then remove the note at the tail index */
note_remove();
}
/* Save the next byte at the head index */
g_note_info.ni_buffer[head] = *note++;
head = next;
notelen--;
}
g_note_info.ni_head = head;
#ifdef CONFIG_SMP
spin_unlock_wo_note(&g_note_lock);
up_irq_restore(flags);
#endif
}
/**************************************************************************** /****************************************************************************
* Name: note_register * Name: note_register
* *
@@ -163,5 +473,3 @@ int note_register(void)
{ {
return register_driver("/dev/note", &note_fops, 0666, NULL); return register_driver("/dev/note", &note_fops, 0666, NULL);
} }
#endif /* CONFIG_SCHED_INSTRUMENTATION_BUFFER && CONFIG_DRIVER_NOTE */
+9 -43
View File
@@ -48,16 +48,10 @@
# define CONFIG_SCHED_INSTRUMENTATION_CPUSET 0xffff # define CONFIG_SCHED_INSTRUMENTATION_CPUSET 0xffff
#endif #endif
#ifndef CONFIG_SCHED_NOTE_BUFSIZE
# define CONFIG_SCHED_NOTE_BUFSIZE 2048
#endif
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SCHED_INSTRUMENTATION_BUFFER
/* This type identifies a note structure */ /* This type identifies a note structure */
enum note_type_e enum note_type_e
@@ -259,7 +253,6 @@ struct note_irqhandler_s
uint8_t nih_irq; /* IRQ number */ uint8_t nih_irq; /* IRQ number */
}; };
#endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */ #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
#endif /* CONFIG_SCHED_INSTRUMENTATION_BUFFER */
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
@@ -273,10 +266,6 @@ struct note_irqhandler_s
* logic must provide the following interfaces. These interfaces are not * logic must provide the following interfaces. These interfaces are not
* available to application code. * available to application code.
* *
* NOTE: if CONFIG_SCHED_INSTRUMENTATION_BUFFER, then these interfaces are
* *not* available to the platform-specific logic. Rather, they provided
* by the note buffering logic. See sched_note_get() below.
*
* Input Parameters: * Input Parameters:
* tcb - The TCB of the thread. * tcb - The TCB of the thread.
* *
@@ -349,47 +338,24 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: sched_note_get * Name: note_add
* *
* Description: * Description:
* Remove the next note from the tail of the circular buffer. The note * Add the variable length note to the transport layer
* is also removed from the circular buffer to make room for further notes.
* *
* Input Parameters: * Input Parameters:
* buffer - Location to return the next note * note - The note buffer
* buflen - The length of the user provided buffer. * notelen - The buffer length
* *
* Returned Value: * Returned Value:
* On success, the positive, non-zero length of the return note is * None
* provided. Zero is returned only if the circular buffer is empty. A *
* negated errno value is returned in the event of any failure. * Assumptions:
* We are within a critical section.
* *
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \ void note_add(FAR const uint8_t *note, uint8_t notelen);
defined(CONFIG_SCHED_NOTE_GET)
ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen);
#endif
/****************************************************************************
* Name: sched_note_size
*
* Description:
* Return the size of the next note at the tail of the circular buffer.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero is returned if the circular buffer is empty. Otherwise, the size
* of the next note is returned.
*
****************************************************************************/
#if defined(CONFIG_SCHED_INSTRUMENTATION_BUFFER) && \
defined(CONFIG_SCHED_NOTE_GET)
ssize_t sched_note_size(void);
#endif
#else /* CONFIG_SCHED_INSTRUMENTATION */ #else /* CONFIG_SCHED_INSTRUMENTATION */
-55
View File
@@ -914,8 +914,6 @@ config SCHED_INSTRUMENTATION
done in these interfaces. For example, normal devices may not be done in these interfaces. For example, normal devices may not be
used; syslog output cannot be performed. used; syslog output cannot be performed.
An option is to use SCHED_INSTRUMENTATION_BUFFER below.
if SCHED_INSTRUMENTATION if SCHED_INSTRUMENTATION
config SCHED_INSTRUMENTATION_CPUSET config SCHED_INSTRUMENTATION_CPUSET
@@ -977,59 +975,6 @@ config SCHED_INSTRUMENTATION_IRQHANDLER
void sched_note_irqhandler(int irq, FAR void *handler, bool enter); void sched_note_irqhandler(int irq, FAR void *handler, bool enter);
config SCHED_INSTRUMENTATION_BUFFER
bool "Buffer instrumentation data in memory"
default n
---help---
If this option is selected, then in-memory buffering logic is
enabled to capture scheduler instrumentation data. This has
the advantage that (1) the platform logic does not have to provide
the sched_note_* interfaces described for the previous settings.
Instead, the buffering logic catches all of these. It encodes
timestamps the scheduler note and adds the note to an in-memory,
circular buffer. And (2) buffering the scheduler instrumentation
data (versus performing some output operation) minimizes the impact
of the instrumentation on the behavior of the system.
If the in-memory buffer becomes full, then older notes are
overwritten by newer notes. The following interface is provided:
ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen);
Platform specific information must call this function and dispose
of it quickly so that overwriting of the tail of the circular buffer
does not occur. See include/nuttx/sched_note.h for additional
information.
if SCHED_INSTRUMENTATION_BUFFER
config SCHED_NOTE_BUFSIZE
int "Instrumentation buffer size"
default 2048
---help---
The size of the in-memory, circular instrumentation buffer (in
bytes).
config SCHED_NOTE_GET
bool "Callable interface to get instrumentation data"
default n
depends on !SCHED_INSTRUMENTATION_CSECTION && (!SCHED_INSTRUMENTATION_SPINLOCK || !SMP)
---help---
Add support for interfaces to get the size of the next note and also
to extract the next note from the instrumentation buffer:
ssize_t sched_note_get(FAR uint8_t *buffer, size_t buflen);
ssize_t sched_note_size(void);
NOTE: This option is not available if critical sections are being
monitor (nor if spinlocks are being monitored in SMP configuration)
because there would be a logical error in the design in those cases.
That error is that these interfaces call enter_ and leave_critical_section
(and which us spinlocks in SMP mode). That means that each call to
sched_note_get() causes several additional entries to be added from
the note buffer in order to remove one entry.
endif # SCHED_INSTRUMENTATION_BUFFER
endif # SCHED_INSTRUMENTATION endif # SCHED_INSTRUMENTATION
endmenu # Performance Monitoring endmenu # Performance Monitoring
+1 -1
View File
@@ -89,7 +89,7 @@ CSRCS += sched_tasklistlock.c
CSRCS += sched_thistask.c CSRCS += sched_thistask.c
endif endif
ifeq ($(CONFIG_SCHED_INSTRUMENTATION_BUFFER),y) ifeq ($(CONFIG_SCHED_INSTRUMENTATION),y)
CSRCS += sched_note.c CSRCS += sched_note.c
endif endif
+175 -337
View File
File diff suppressed because it is too large Load Diff