2016-03-17 16:49:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* sched/sched/sched_note.c
|
|
|
|
*
|
2020-06-16 19:30:58 +02: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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
2016-03-17 16:49:43 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
#include <nuttx/irq.h>
|
2016-03-17 16:49:43 +01:00
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/clock.h>
|
2016-11-28 17:33:46 +01:00
|
|
|
#include <nuttx/spinlock.h>
|
2016-03-17 16:49:43 +01:00
|
|
|
#include <nuttx/sched_note.h>
|
|
|
|
|
2016-11-28 17:33:46 +01:00
|
|
|
#include "sched/sched.h"
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
struct note_filter_s
|
|
|
|
{
|
|
|
|
struct note_filter_mode_s mode;
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
struct note_filter_irq_s irq_mask;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
struct note_filter_syscall_s syscall_mask;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
struct note_startalloc_s
|
|
|
|
{
|
2016-03-21 21:08:31 +01:00
|
|
|
struct note_common_s nsa_cmn; /* Common note parameters */
|
2016-03-17 16:49:43 +01:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-03-21 21:08:31 +01:00
|
|
|
char nsa_name[CONFIG_TASK_NAME_SIZE + 1];
|
2016-03-17 16:49:43 +01:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
# define SIZEOF_NOTE_START(n) (sizeof(struct note_start_s) + (n) - 1)
|
|
|
|
#else
|
|
|
|
# define SIZEOF_NOTE_START(n) (sizeof(struct note_start_s))
|
|
|
|
#endif
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
static struct note_filter_s g_note_filter =
|
|
|
|
{
|
2020-09-09 02:06:38 +02:00
|
|
|
.mode =
|
|
|
|
{
|
|
|
|
.flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
|
2020-07-23 15:18:03 +02:00
|
|
|
#ifdef CONFIG_SMP
|
2020-09-09 02:06:38 +02:00
|
|
|
.cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
|
2020-07-23 15:18:03 +02:00
|
|
|
#endif
|
2020-09-09 02:06:38 +02:00
|
|
|
}
|
2020-07-23 15:18:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static unsigned int g_note_disabled_irq_nest[CONFIG_SMP_NCPUS];
|
|
|
|
#else
|
|
|
|
static unsigned int g_note_disabled_irq_nest[1];
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-03-21 22:40:01 +01:00
|
|
|
* Name: note_common
|
2016-03-17 16:49:43 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-03-21 22:40:01 +01:00
|
|
|
* Fill in some of the common fields in the note structure.
|
2016-03-17 16:49:43 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2016-11-28 17:33:46 +01:00
|
|
|
* tcb - The TCB containing the information
|
|
|
|
* note - The common note structure to use
|
|
|
|
* length - The total lengthof the note structure
|
|
|
|
* type - The type of the note
|
2016-03-17 16:49:43 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-11 18:10:08 +01:00
|
|
|
static void note_common(FAR struct tcb_s *tcb,
|
|
|
|
FAR struct note_common_s *note,
|
2016-03-21 22:40:01 +01:00
|
|
|
uint8_t length, uint8_t type)
|
2016-03-17 16:49:43 +01:00
|
|
|
{
|
2020-05-04 16:15:10 +02:00
|
|
|
uint32_t systime = (uint32_t)clock_systime_ticks();
|
2016-03-21 22:40:01 +01:00
|
|
|
|
|
|
|
/* Save all of the common fields */
|
|
|
|
|
|
|
|
note->nc_length = length;
|
|
|
|
note->nc_type = type;
|
|
|
|
note->nc_priority = tcb->sched_priority;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
note->nc_cpu = tcb->cpu;
|
|
|
|
#endif
|
|
|
|
note->nc_pid[0] = (uint8_t)(tcb->pid & 0xff);
|
|
|
|
note->nc_pid[1] = (uint8_t)((tcb->pid >> 8) & 0xff);
|
2016-03-17 16:49:43 +01:00
|
|
|
|
|
|
|
/* Save the LS 32-bits of the system timer in little endian order */
|
|
|
|
|
2020-03-11 18:10:08 +01:00
|
|
|
note->nc_systime[0] = (uint8_t)(systime & 0xff);
|
2016-03-17 16:49:43 +01:00
|
|
|
note->nc_systime[1] = (uint8_t)((systime >> 8) & 0xff);
|
|
|
|
note->nc_systime[2] = (uint8_t)((systime >> 16) & 0xff);
|
|
|
|
note->nc_systime[3] = (uint8_t)((systime >> 24) & 0xff);
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_isenabled
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check whether the instrumentation is enabled.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True is returned if the instrumentation is enabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int note_isenabled(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Ignore notes that are not in the set of monitored CPUs */
|
|
|
|
|
|
|
|
if ((g_note_filter.mode.cpuset & (1 << this_cpu())) == 0)
|
|
|
|
{
|
|
|
|
/* Not in the set of monitored CPUs. Do not log the note. */
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_isenabled_syscall
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check whether the syscall instrumentation is enabled.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* nr - syscall number
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True is returned if the instrumentation is enabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
static inline int note_isenabled_syscall(int nr)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
if (!note_isenabled())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Exclude the case of syscall called by the interrupt handler which is
|
|
|
|
* not traced.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
int cpu = this_cpu();
|
|
|
|
#else
|
|
|
|
int cpu = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_note_disabled_irq_nest[cpu] > 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the syscall trace is disabled or the syscall number is masked,
|
|
|
|
* do nothing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_SYSCALL) ||
|
|
|
|
NOTE_FILTER_SYSCALLMASK_ISSET(nr - CONFIG_SYS_RESERVED,
|
|
|
|
&g_note_filter.syscall_mask))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_isenabled_irqhandler
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check whether the interrupt handler instrumentation is enabled.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* irq - IRQ number
|
|
|
|
* enter - interrupt enter/leave flag
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True is returned if the instrumentation is enabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
static inline int note_isenabled_irq(int irq, bool enter)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
if (!note_isenabled())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the IRQ trace is disabled or the IRQ number is masked, disable
|
|
|
|
* subsequent syscall traces until leaving the interrupt handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) ||
|
|
|
|
NOTE_FILTER_IRQMASK_ISSET(irq, &g_note_filter.irq_mask))
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
int cpu = this_cpu();
|
|
|
|
#else
|
|
|
|
int cpu = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (enter)
|
|
|
|
{
|
|
|
|
g_note_disabled_irq_nest[cpu]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_note_disabled_irq_nest[cpu]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-28 17:33:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_spincommon
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Common logic for NOTE_SPINLOCK, NOTE_SPINLOCKED, and NOTE_SPINUNLOCK
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - The TCB containing the information
|
|
|
|
* note - The common note structure to use
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
2020-08-06 20:57:30 +02:00
|
|
|
static void note_spincommon(FAR struct tcb_s *tcb,
|
|
|
|
FAR volatile spinlock_t *spinlock,
|
|
|
|
int type)
|
2016-11-28 17:33:46 +01:00
|
|
|
{
|
|
|
|
struct note_spinlock_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2016-11-28 17:33:46 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:57:30 +02:00
|
|
|
/* Format the note */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2020-08-06 20:57:30 +02:00
|
|
|
note_common(tcb, ¬e.nsp_cmn, sizeof(struct note_spinlock_s), type);
|
|
|
|
note.nsp_spinlock = (FAR void *)spinlock;
|
|
|
|
note.nsp_value = (uint8_t)*spinlock;
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2020-08-06 20:57:30 +02:00
|
|
|
/* Add the note to circular buffer */
|
2018-01-17 05:08:03 +01:00
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_spinlock_s));
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
2020-08-06 20:57:30 +02:00
|
|
|
#endif
|
2016-03-17 16:49:43 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_note_*
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* These are the hooks into the scheduling instrumentation logic. Each
|
|
|
|
* simply formats the note associated with the schedule event and adds
|
|
|
|
* that note to the circular buffer.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tcb - The TCB of the thread.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* We are within a critical section.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void sched_note_start(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
struct note_startalloc_s note;
|
|
|
|
unsigned int length;
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
int namelen;
|
|
|
|
#endif
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Copy the task name (if possible) and get the length of the note */
|
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
namelen = strlen(tcb->name);
|
|
|
|
|
|
|
|
DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
|
|
|
|
strncpy(note.nsa_name, tcb->name, CONFIG_TASK_NAME_SIZE + 1);
|
|
|
|
|
|
|
|
length = SIZEOF_NOTE_START(namelen + 1);
|
|
|
|
#else
|
|
|
|
length = SIZEOF_NOTE_START(0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Finish formatting the note */
|
|
|
|
|
2016-03-21 22:40:01 +01:00
|
|
|
note_common(tcb, ¬e.nsa_cmn, length, NOTE_START);
|
2016-03-17 16:49:43 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, length);
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_stop(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
struct note_stop_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2016-03-21 22:40:01 +01:00
|
|
|
note_common(tcb, ¬e.nsp_cmn, sizeof(struct note_stop_s), NOTE_STOP);
|
2016-03-17 16:49:43 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_stop_s));
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
|
2016-03-21 21:08:31 +01:00
|
|
|
void sched_note_suspend(FAR struct tcb_s *tcb)
|
2016-03-17 16:49:43 +01:00
|
|
|
{
|
2016-03-21 22:24:15 +01:00
|
|
|
struct note_suspend_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-21 22:24:15 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2020-03-11 18:10:08 +01:00
|
|
|
note_common(tcb, ¬e.nsu_cmn, sizeof(struct note_suspend_s),
|
|
|
|
NOTE_SUSPEND);
|
2016-03-21 22:24:15 +01:00
|
|
|
note.nsu_state = tcb->task_state;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_suspend_s));
|
2016-03-21 21:08:31 +01:00
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2016-03-21 21:08:31 +01:00
|
|
|
void sched_note_resume(FAR struct tcb_s *tcb)
|
|
|
|
{
|
2016-03-21 22:24:15 +01:00
|
|
|
struct note_resume_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-21 22:24:15 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2016-03-21 22:40:01 +01:00
|
|
|
note_common(tcb, ¬e.nre_cmn, sizeof(struct note_resume_s), NOTE_RESUME);
|
2016-03-21 22:24:15 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_resume_s));
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 00:14:57 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-12-07 16:08:20 +01:00
|
|
|
void sched_note_cpu_start(FAR struct tcb_s *tcb, int cpu)
|
|
|
|
{
|
|
|
|
struct note_cpu_start_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-07 16:08:20 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
note_common(tcb, ¬e.ncs_cmn, sizeof(struct note_cpu_start_s),
|
|
|
|
NOTE_CPU_START);
|
2016-12-07 16:08:20 +01:00
|
|
|
note.ncs_target = (uint8_t)cpu;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_cpu_start_s));
|
2016-12-07 16:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_started(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
struct note_cpu_started_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-07 16:08:20 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
note_common(tcb, ¬e.ncs_cmn, sizeof(struct note_cpu_started_s),
|
|
|
|
NOTE_CPU_STARTED);
|
2016-12-07 16:08:20 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_cpu_started_s));
|
2016-12-07 16:08:20 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 00:14:57 +01:00
|
|
|
void sched_note_cpu_pause(FAR struct tcb_s *tcb, int cpu)
|
|
|
|
{
|
|
|
|
struct note_cpu_pause_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-28 00:14:57 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
note_common(tcb, ¬e.ncp_cmn, sizeof(struct note_cpu_pause_s),
|
|
|
|
NOTE_CPU_PAUSE);
|
2016-11-28 00:14:57 +01:00
|
|
|
note.ncp_target = (uint8_t)cpu;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_cpu_pause_s));
|
2016-11-28 00:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_paused(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
struct note_cpu_paused_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-28 00:14:57 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
note_common(tcb, ¬e.ncp_cmn, sizeof(struct note_cpu_paused_s),
|
|
|
|
NOTE_CPU_PAUSED);
|
2016-11-28 00:14:57 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_cpu_paused_s));
|
2016-11-28 00:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_resume(FAR struct tcb_s *tcb, int cpu)
|
|
|
|
{
|
|
|
|
struct note_cpu_resume_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-28 00:14:57 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
note_common(tcb, ¬e.ncr_cmn, sizeof(struct note_cpu_resume_s),
|
|
|
|
NOTE_CPU_RESUME);
|
2016-11-28 00:14:57 +01:00
|
|
|
note.ncr_target = (uint8_t)cpu;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_cpu_resume_s));
|
2016-11-28 00:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_resumed(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
struct note_cpu_resumed_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-28 00:14:57 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2017-06-14 21:42:56 +02:00
|
|
|
note_common(tcb, ¬e.ncr_cmn, sizeof(struct note_cpu_resumed_s),
|
|
|
|
NOTE_CPU_RESUMED);
|
2016-11-28 00:14:57 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_cpu_resumed_s));
|
2016-11-28 00:14:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
|
|
|
|
void sched_note_premption(FAR struct tcb_s *tcb, bool locked)
|
|
|
|
{
|
|
|
|
struct note_preempt_s note;
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2016-03-21 22:40:01 +01:00
|
|
|
note_common(tcb, ¬e.npr_cmn, sizeof(struct note_preempt_s),
|
|
|
|
locked ? NOTE_PREEMPT_LOCK : NOTE_PREEMPT_UNLOCK);
|
|
|
|
note.npr_count[0] = (uint8_t)(tcb->lockcount & 0xff);
|
|
|
|
note.npr_count[1] = (uint8_t)((tcb->lockcount >> 8) & 0xff);
|
2016-03-17 16:49:43 +01:00
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_preempt_s));
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
|
|
|
|
void sched_note_csection(FAR struct tcb_s *tcb, bool enter)
|
|
|
|
{
|
2016-03-21 22:40:01 +01:00
|
|
|
struct note_csection_s note;
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
2016-03-21 22:40:01 +01:00
|
|
|
note_common(tcb, ¬e.ncs_cmn, sizeof(struct note_csection_s),
|
|
|
|
enter ? NOTE_CSECTION_ENTER : NOTE_CSECTION_LEAVE);
|
2016-03-21 21:08:31 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2016-03-21 22:40:01 +01:00
|
|
|
note.ncs_count[0] = (uint8_t)(tcb->irqcount & 0xff);
|
|
|
|
note.ncs_count[1] = (uint8_t)((tcb->irqcount >> 8) & 0xff);
|
2016-03-17 16:49:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_csection_s));
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-28 17:33:46 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
|
|
|
void sched_note_spinlock(FAR struct tcb_s *tcb, FAR volatile void *spinlock)
|
|
|
|
{
|
2017-01-12 15:03:36 +01:00
|
|
|
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_LOCK);
|
2016-11-28 17:33:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 18:10:08 +01:00
|
|
|
void sched_note_spinlocked(FAR struct tcb_s *tcb,
|
|
|
|
FAR volatile void *spinlock)
|
2016-11-28 17:33:46 +01:00
|
|
|
{
|
2017-01-12 15:03:36 +01:00
|
|
|
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_LOCKED);
|
2016-11-28 17:33:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 18:10:08 +01:00
|
|
|
void sched_note_spinunlock(FAR struct tcb_s *tcb,
|
|
|
|
FAR volatile void *spinlock)
|
2016-11-28 17:33:46 +01:00
|
|
|
{
|
2017-01-12 15:03:36 +01:00
|
|
|
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_UNLOCK);
|
2016-11-28 17:33:46 +01:00
|
|
|
}
|
2019-10-24 18:49:28 +02:00
|
|
|
|
2017-01-12 15:03:36 +01:00
|
|
|
void sched_note_spinabort(FAR struct tcb_s *tcb, FAR volatile void *spinlock)
|
2016-11-28 17:33:46 +01:00
|
|
|
{
|
2017-01-12 15:03:36 +01:00
|
|
|
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_ABORT);
|
2016-11-28 17:33:46 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 19:30:58 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
void sched_note_syscall_enter(int nr, int argc, ...)
|
|
|
|
{
|
|
|
|
struct note_syscall_enter_s note;
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled_syscall(nr))
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-16 19:30:58 +02:00
|
|
|
/* Format the note */
|
|
|
|
|
|
|
|
note_common(tcb, ¬e.nsc_cmn, sizeof(struct note_syscall_enter_s),
|
2020-06-18 07:24:10 +02:00
|
|
|
NOTE_SYSCALL_ENTER);
|
2020-07-22 15:40:17 +02:00
|
|
|
DEBUGASSERT(nr <= UCHAR_MAX);
|
2020-06-16 19:30:58 +02:00
|
|
|
note.nsc_nr = nr;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_syscall_enter_s));
|
2020-06-16 19:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_syscall_leave(int nr, uintptr_t result)
|
|
|
|
{
|
|
|
|
struct note_syscall_leave_s note;
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled_syscall(nr))
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-16 19:30:58 +02:00
|
|
|
/* Format the note */
|
|
|
|
|
|
|
|
note_common(tcb, ¬e.nsc_cmn, sizeof(struct note_syscall_leave_s),
|
2020-06-18 07:24:10 +02:00
|
|
|
NOTE_SYSCALL_LEAVE);
|
2020-06-16 19:30:58 +02:00
|
|
|
note.nsc_result = result;
|
2020-07-22 15:40:17 +02:00
|
|
|
DEBUGASSERT(nr <= UCHAR_MAX);
|
2020-06-16 19:30:58 +02:00
|
|
|
note.nsc_nr = nr;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-10 15:14:49 +02:00
|
|
|
sched_note_add(¬e, sizeof(struct note_syscall_leave_s));
|
2020-06-16 19:30:58 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
|
|
|
|
{
|
|
|
|
struct note_irqhandler_s note;
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled_irq(irq, enter))
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-16 19:30:58 +02:00
|
|
|
/* Format the note */
|
|
|
|
|
|
|
|
note_common(tcb, ¬e.nih_cmn, sizeof(struct note_irqhandler_s),
|
|
|
|
enter ? NOTE_IRQ_ENTER : NOTE_IRQ_LEAVE);
|
2020-07-22 15:40:17 +02:00
|
|
|
DEBUGASSERT(irq <= UCHAR_MAX);
|
2020-06-16 19:30:58 +02:00
|
|
|
note.nih_irq = irq;
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
2020-09-15 08:01:57 +02:00
|
|
|
sched_note_add((FAR const uint8_t *)¬e,
|
|
|
|
sizeof(struct note_irqhandler_s));
|
2020-06-16 19:30:58 +02:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-23 15:18:03 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_note_filter_mode
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set and get note filter mode.
|
|
|
|
* (Same as NOTECTL_GETMODE / NOTECTL_SETMODE ioctls)
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* oldm - A writable pointer to struct note_filter_mode_s to get current
|
|
|
|
* filter mode
|
|
|
|
* If 0, no data is written.
|
|
|
|
* newm - A read-only pointer to struct note_filter_mode_s which holds the
|
|
|
|
* new filter mode
|
|
|
|
* If 0, the filter mode is not updated.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void sched_note_filter_mode(struct note_filter_mode_s *oldm,
|
|
|
|
struct note_filter_mode_s *newm)
|
|
|
|
{
|
|
|
|
irqstate_t irq_mask;
|
|
|
|
|
|
|
|
irq_mask = enter_critical_section();
|
|
|
|
|
|
|
|
if (oldm != NULL)
|
|
|
|
{
|
|
|
|
*oldm = g_note_filter.mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newm != NULL)
|
|
|
|
{
|
|
|
|
g_note_filter.mode = *newm;
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(irq_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_note_filter_syscall
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set and get syscall filter setting
|
|
|
|
* (Same as NOTECTL_GETSYSCALLFILTER / NOTECTL_SETSYSCALLFILTER ioctls)
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* oldf - A writable pointer to struct note_filter_syscall_s to get
|
|
|
|
* current syscall filter setting
|
|
|
|
* If 0, no data is written.
|
|
|
|
* newf - A read-only pointer to struct note_filter_syscall_s of the
|
|
|
|
* new syscall filter setting
|
|
|
|
* If 0, the setting is not updated.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
void sched_note_filter_syscall(struct note_filter_syscall_s *oldf,
|
|
|
|
struct note_filter_syscall_s *newf)
|
|
|
|
{
|
|
|
|
irqstate_t irq_mask;
|
|
|
|
|
|
|
|
irq_mask = enter_critical_section();
|
|
|
|
|
|
|
|
if (oldf != NULL)
|
|
|
|
{
|
|
|
|
/* Return the current filter setting */
|
|
|
|
|
|
|
|
*oldf = g_note_filter.syscall_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newf != NULL)
|
|
|
|
{
|
|
|
|
/* Replace the syscall filter mask by the provided setting */
|
|
|
|
|
|
|
|
g_note_filter.syscall_mask = *newf;
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(irq_mask);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_note_filter_irq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set and get IRQ filter setting
|
|
|
|
* (Same as NOTECTL_GETIRQFILTER / NOTECTL_SETIRQFILTER ioctls)
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* oldf - A writable pointer to struct note_filter_irq_s to get
|
|
|
|
* current IRQ filter setting
|
|
|
|
* If 0, no data is written.
|
|
|
|
* newf - A read-only pointer to struct note_filter_irq_s of the new
|
|
|
|
* IRQ filter setting
|
|
|
|
* If 0, the setting is not updated.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
void sched_note_filter_irq(struct note_filter_irq_s *oldf,
|
|
|
|
struct note_filter_irq_s *newf)
|
|
|
|
{
|
|
|
|
irqstate_t irq_mask;
|
|
|
|
|
|
|
|
irq_mask = enter_critical_section();
|
|
|
|
|
|
|
|
if (oldf != NULL)
|
|
|
|
{
|
|
|
|
/* Return the current filter setting */
|
|
|
|
|
|
|
|
*oldf = g_note_filter.irq_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newf != NULL)
|
|
|
|
{
|
|
|
|
/* Replace the syscall filter mask by the provided setting */
|
|
|
|
|
|
|
|
g_note_filter.irq_mask = *newf;
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(irq_mask);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
|