2016-03-17 16:49:43 +01:00
|
|
|
/****************************************************************************
|
2022-12-11 13:55:08 +01:00
|
|
|
* drivers/note/note_driver.c
|
2016-03-17 16:49:43 +01:00
|
|
|
*
|
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>
|
|
|
|
|
2021-11-17 10:23:43 +01:00
|
|
|
#include <stdio.h>
|
2016-03-17 16:49:43 +01:00
|
|
|
#include <stdint.h>
|
2020-07-23 15:18:14 +02:00
|
|
|
#include <stdarg.h>
|
2016-03-17 16:49:43 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2020-09-03 08:18:12 +02:00
|
|
|
#include <time.h>
|
2016-03-17 16:49:43 +01:00
|
|
|
|
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>
|
2022-12-16 11:31:28 +01:00
|
|
|
#include <nuttx/note/note_driver.h>
|
|
|
|
#include <nuttx/note/noteram_driver.h>
|
2022-12-30 05:02:33 +01:00
|
|
|
#include <nuttx/note/notelog_driver.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>
|
2023-10-08 12:20:43 +02:00
|
|
|
#include <nuttx/instrument.h>
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2016-11-28 17:33:46 +01:00
|
|
|
#include "sched/sched.h"
|
|
|
|
|
2023-10-08 12:20:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-14 05:06:31 +02:00
|
|
|
#if defined(CONFIG_DRIVERS_NOTERAM) + defined(CONFIG_DRIVERS_NOTELOG) + \
|
|
|
|
defined(CONFIG_DRIVERS_NOTESNAP) + defined(CONFIG_DRIVERS_NOTERTT) + \
|
|
|
|
defined(CONFIG_SEGGER_SYSVIEW) > CONFIG_DRIVERS_NOTE_MAX
|
|
|
|
# error "Maximum channel number exceeds. "
|
|
|
|
#endif
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
#define note_add(drv, note, notelen) \
|
|
|
|
((drv)->ops->add(drv, note, notelen))
|
|
|
|
#define note_start(drv, tcb) \
|
|
|
|
((drv)->ops->start && ((drv)->ops->start(drv, tcb), true))
|
|
|
|
#define note_stop(drv, tcb) \
|
|
|
|
((drv)->ops->stop && ((drv)->ops->stop(drv, tcb), true))
|
|
|
|
#define note_suspend(drv, tcb) \
|
|
|
|
((drv)->ops->suspend && ((drv)->ops->suspend(drv, tcb), true))
|
|
|
|
#define note_resume(drv, tcb) \
|
|
|
|
((drv)->ops->resume && ((drv)->ops->resume(drv, tcb), true))
|
|
|
|
#define note_cpu_start(drv, tcb, cpu) \
|
|
|
|
((drv)->ops->cpu_start && ((drv)->ops->cpu_start(drv, tcb, cpu), true))
|
|
|
|
#define note_cpu_started(drv, tcb) \
|
|
|
|
((drv)->ops->cpu_started && ((drv)->ops->cpu_started(drv, tcb), true))
|
|
|
|
#define note_cpu_pause(drv, tcb, cpu) \
|
|
|
|
((drv)->ops->cpu_pause && ((drv)->ops->cpu_pause(drv, tcb, cpu), true))
|
|
|
|
#define note_cpu_paused(drv, tcb) \
|
|
|
|
((drv)->ops->cpu_paused && ((drv)->ops->cpu_paused(drv, tcb), true))
|
|
|
|
#define note_cpu_resume(drv, tcb, cpu) \
|
|
|
|
((drv)->ops->cpu_resume && ((drv)->ops->cpu_resume(drv, tcb, cpu), true))
|
|
|
|
#define note_cpu_resumed(drv, tcb) \
|
|
|
|
((drv)->ops->cpu_resumed && ((drv)->ops->cpu_resumed(drv, tcb), true))
|
|
|
|
#define note_premption(drv, tcb, locked) \
|
|
|
|
((drv)->ops->premption && ((drv)->ops->premption(drv, tcb, locked), true))
|
|
|
|
#define note_csection(drv, tcb, enter) \
|
|
|
|
((drv)->ops->csection && ((drv)->ops->csection(drv, tcb, enter), true))
|
|
|
|
#define note_spinlock(drv, tcb, spinlock, type) \
|
|
|
|
((drv)->ops->spinlock && \
|
|
|
|
((drv)->ops->spinlock(drv, tcb, spinlock, type), true))
|
2022-12-29 07:43:20 +01:00
|
|
|
#define note_syscall_enter(drv, nr, argc, ap) \
|
|
|
|
((drv)->ops->syscall_enter && \
|
|
|
|
((drv)->ops->syscall_enter(drv, nr, argc, ap), true))
|
|
|
|
#define note_syscall_leave(drv, nr, result) \
|
|
|
|
((drv)->ops->syscall_leave && \
|
|
|
|
((drv)->ops->syscall_leave(drv, nr, result), true))
|
2022-12-16 11:31:28 +01:00
|
|
|
#define note_irqhandler(drv, irq, handler, enter) \
|
|
|
|
((drv)->ops->irqhandler && \
|
|
|
|
((drv)->ops->irqhandler(drv, irq, handler, enter), true))
|
|
|
|
#define note_string(drv, ip, buf) \
|
|
|
|
((drv)->ops->string && ((drv)->ops->string(drv, ip, buf), true))
|
2023-10-16 05:05:17 +02:00
|
|
|
#define note_event(drv, ip, event, buf, len) \
|
|
|
|
((drv)->ops->event && ((drv)->ops->event(drv, ip, event, buf, len), true))
|
2022-12-16 11:31:28 +01:00
|
|
|
#define note_vprintf(drv, ip, fmt, va) \
|
|
|
|
((drv)->ops->vprintf && ((drv)->ops->vprintf(drv, ip, fmt, va), true))
|
2023-10-16 05:05:17 +02:00
|
|
|
#define note_vbprintf(drv, ip, fmt, va) \
|
|
|
|
((drv)->ops->vbprintf && ((drv)->ops->vbprintf(drv, ip, fmt, va), true))
|
2022-12-16 11:31:28 +01:00
|
|
|
|
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;
|
2023-02-28 09:16:55 +01:00
|
|
|
# ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
|
|
|
struct note_filter_tag_s tag_mask;
|
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
2020-07-23 15:18:03 +02:00
|
|
|
struct note_filter_irq_s irq_mask;
|
2023-02-28 09:16:55 +01:00
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
2020-07-23 15:18:03 +02:00
|
|
|
struct note_filter_syscall_s syscall_mask;
|
2023-02-28 09:16:55 +01:00
|
|
|
# endif
|
2020-07-23 15:18:03 +02:00
|
|
|
};
|
|
|
|
#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
|
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
#if CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0
|
2022-12-26 06:18:33 +01:00
|
|
|
struct note_taskname_info_s
|
|
|
|
{
|
2023-10-31 15:10:06 +01:00
|
|
|
pid_t pid;
|
2022-12-26 06:18:33 +01:00
|
|
|
uint8_t size;
|
|
|
|
char name[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct note_taskname_s
|
|
|
|
{
|
|
|
|
size_t head;
|
|
|
|
size_t tail;
|
2023-02-20 08:21:31 +01:00
|
|
|
char buffer[CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE];
|
2022-12-26 06:18:33 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-10-08 12:20:43 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
|
|
|
|
static void note_driver_instrument_enter(FAR void *this_fn,
|
|
|
|
FAR void *call_site, FAR void *arg) noinstrument_function;
|
|
|
|
static void note_driver_instrument_leave(FAR void *this_fn,
|
|
|
|
FAR void *call_site, FAR void *arg) noinstrument_function;
|
|
|
|
static struct instrument_s g_note_instrument =
|
|
|
|
{
|
2024-01-22 09:58:14 +01:00
|
|
|
.enter = note_driver_instrument_enter,
|
|
|
|
.leave = note_driver_instrument_leave,
|
2023-10-08 12:20:43 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
static struct note_filter_s g_note_filter =
|
|
|
|
{
|
2022-03-26 21:51:22 +01:00
|
|
|
{
|
2022-12-30 05:02:47 +01:00
|
|
|
CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE
|
2020-07-23 15:18:03 +02:00
|
|
|
#ifdef CONFIG_SMP
|
2023-03-15 04:27:17 +01:00
|
|
|
, (cpu_set_t)CONFIG_SCHED_INSTRUMENTATION_CPUSET
|
2020-07-23 15:18:03 +02:00
|
|
|
#endif
|
2022-03-26 21:51:22 +01:00
|
|
|
}
|
2020-07-23 15:18:03 +02:00
|
|
|
};
|
|
|
|
|
2021-11-26 18:11:11 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
2020-07-23 15:18:03 +02:00
|
|
|
static unsigned int g_note_disabled_irq_nest[CONFIG_SMP_NCPUS];
|
|
|
|
#endif
|
2021-11-26 18:11:11 +01:00
|
|
|
#endif
|
2020-07-23 15:18:03 +02:00
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
FAR static struct note_driver_s *
|
|
|
|
g_note_drivers[CONFIG_DRIVERS_NOTE_MAX + 1] =
|
2022-12-16 11:31:28 +01:00
|
|
|
{
|
2023-02-20 08:21:31 +01:00
|
|
|
#ifdef CONFIG_DRIVERS_NOTERAM
|
2023-04-27 13:42:27 +02:00
|
|
|
(FAR struct note_driver_s *)&g_noteram_driver,
|
2022-12-16 11:31:28 +01:00
|
|
|
#endif
|
2023-02-20 08:21:31 +01:00
|
|
|
#ifdef CONFIG_DRIVERS_NOTELOG
|
2022-12-30 05:02:33 +01:00
|
|
|
&g_notelog_driver,
|
|
|
|
#endif
|
|
|
|
NULL
|
2022-12-16 11:31:28 +01:00
|
|
|
};
|
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
#if CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0
|
2022-12-26 06:18:33 +01:00
|
|
|
static struct note_taskname_s g_note_taskname;
|
|
|
|
#endif
|
|
|
|
|
2023-08-11 04:31:03 +02:00
|
|
|
#if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER)
|
2022-12-30 05:02:47 +01:00
|
|
|
static spinlock_t g_note_lock;
|
2023-08-02 11:02:07 +02:00
|
|
|
#endif
|
2022-12-30 05:02:47 +01:00
|
|
|
|
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-09-03 08:18:12 +02:00
|
|
|
struct timespec ts;
|
2023-09-28 10:37:27 +02:00
|
|
|
perf_convert(perf_gettime(), &ts);
|
2016-03-21 22:40:01 +01:00
|
|
|
|
|
|
|
/* Save all of the common fields */
|
|
|
|
|
2023-09-28 10:37:27 +02:00
|
|
|
note->nc_length = length;
|
|
|
|
note->nc_type = type;
|
2023-02-22 12:30:43 +01:00
|
|
|
|
|
|
|
if (tcb == NULL)
|
|
|
|
{
|
|
|
|
note->nc_priority = CONFIG_INIT_PRIORITY;
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
note->nc_cpu = 0;
|
|
|
|
#endif
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nc_pid = 0;
|
2023-02-22 12:30:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
note->nc_priority = tcb->sched_priority;
|
2016-03-21 22:40:01 +01:00
|
|
|
#ifdef CONFIG_SMP
|
2023-02-22 12:30:43 +01:00
|
|
|
note->nc_cpu = tcb->cpu;
|
2016-03-21 22:40:01 +01:00
|
|
|
#endif
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nc_pid = tcb->pid;
|
2023-02-22 12:30:43 +01:00
|
|
|
}
|
|
|
|
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nc_systime_sec = ts.tv_sec;
|
|
|
|
note->nc_systime_nsec = ts.tv_nsec;
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
|
2023-02-01 05:41:47 +01:00
|
|
|
if (CPU_ISSET(this_cpu(), &g_note_filter.mode.cpuset) == 0)
|
2020-07-23 15:18:03 +02:00
|
|
|
{
|
|
|
|
/* Not in the set of monitored CPUs. Do not log the note. */
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_isenabled_switch
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check whether the switch instrumentation is enabled.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True is returned if the instrumentation is enabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
|
|
|
static inline int note_isenabled_switch(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
if (!note_isenabled())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the switch trace is disabled, do nothing. */
|
|
|
|
|
|
|
|
if ((g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_SWITCH) == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
int cpu = this_cpu();
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
int cpu = this_cpu();
|
|
|
|
|
|
|
|
if (enter)
|
|
|
|
{
|
|
|
|
g_note_disabled_irq_nest[cpu]++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_note_disabled_irq_nest[cpu]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_isenabled_dump
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check whether the dump instrumentation is enabled.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2023-02-28 09:16:55 +01:00
|
|
|
* tag: The dump instrumentation tag
|
2022-02-18 08:05:23 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* True is returned if the instrumentation is enabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
2023-02-28 09:16:55 +01:00
|
|
|
static inline int note_isenabled_dump(uint32_t tag)
|
2022-02-18 08:05:23 +01:00
|
|
|
{
|
2023-02-28 09:16:55 +01:00
|
|
|
# ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the dump trace is disabled, do nothing. */
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_DUMP) ||
|
2023-04-08 09:22:55 +02:00
|
|
|
NOTE_FILTER_TAGMASK_ISSET(tag, &g_note_filter.tag_mask))
|
2022-02-18 08:05:23 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2023-02-28 09:16:55 +01:00
|
|
|
# endif
|
2022-02-18 08:05:23 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
#if CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0
|
2022-12-26 06:18:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_find_taskname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Find task name info corresponding to the specified PID
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* PID - Task ID
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Pointer to the task name info
|
|
|
|
* If the corresponding info doesn't exist in the buffer, NULL is returned.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR struct note_taskname_info_s *note_find_taskname(pid_t pid)
|
|
|
|
{
|
|
|
|
FAR struct note_taskname_info_s *ti;
|
|
|
|
int n = g_note_taskname.tail;
|
|
|
|
|
|
|
|
while (n != g_note_taskname.head)
|
|
|
|
{
|
|
|
|
ti = (FAR struct note_taskname_info_s *)
|
|
|
|
&g_note_taskname.buffer[n];
|
2023-10-31 15:10:06 +01:00
|
|
|
if (ti->pid == pid)
|
2022-12-26 06:18:33 +01:00
|
|
|
{
|
|
|
|
return ti;
|
|
|
|
}
|
|
|
|
|
|
|
|
n += ti->size;
|
2023-02-20 08:21:31 +01:00
|
|
|
if (n >= CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE)
|
2022-12-26 06:18:33 +01:00
|
|
|
{
|
2023-02-20 08:21:31 +01:00
|
|
|
n -= CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE;
|
2022-12-26 06:18:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_record_taskname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Record the task name info of the specified task
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* PID - Task ID
|
|
|
|
* name - task name
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void note_record_taskname(pid_t pid, FAR const char *name)
|
|
|
|
{
|
|
|
|
FAR struct note_taskname_info_s *ti;
|
|
|
|
size_t tilen;
|
|
|
|
size_t namelen;
|
|
|
|
size_t skiplen;
|
|
|
|
size_t remain;
|
|
|
|
|
|
|
|
namelen = strlen(name);
|
|
|
|
DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
|
|
|
|
tilen = sizeof(struct note_taskname_info_s) + namelen;
|
|
|
|
DEBUGASSERT(tilen <= UCHAR_MAX);
|
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
skiplen = CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE - g_note_taskname.head;
|
2022-12-26 06:18:33 +01:00
|
|
|
if (skiplen >= tilen + sizeof(struct note_taskname_info_s))
|
|
|
|
{
|
|
|
|
skiplen = 0; /* Have enough space at the tail - needn't skip */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_note_taskname.head >= g_note_taskname.tail)
|
|
|
|
{
|
2023-02-20 08:21:31 +01:00
|
|
|
remain = CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE -
|
2022-12-26 06:18:33 +01:00
|
|
|
(g_note_taskname.head - g_note_taskname.tail);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
remain = g_note_taskname.tail - g_note_taskname.head;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (skiplen + tilen >= remain)
|
|
|
|
{
|
|
|
|
/* No enough space, drop the old info */
|
|
|
|
|
|
|
|
ti = (FAR struct note_taskname_info_s *)
|
|
|
|
&g_note_taskname.buffer[g_note_taskname.tail];
|
|
|
|
g_note_taskname.tail = (g_note_taskname.tail + ti->size) %
|
2023-02-20 08:21:31 +01:00
|
|
|
CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE;
|
2022-12-26 06:18:33 +01:00
|
|
|
remain += ti->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skiplen)
|
|
|
|
{
|
|
|
|
/* Fill the skipped region with an invalid info */
|
|
|
|
|
|
|
|
ti = (FAR struct note_taskname_info_s *)
|
|
|
|
&g_note_taskname.buffer[g_note_taskname.head];
|
|
|
|
ti->size = skiplen;
|
2023-10-31 15:10:06 +01:00
|
|
|
ti->pid = INVALID_PROCESS_ID;
|
2022-12-26 06:18:33 +01:00
|
|
|
ti->name[0] = '\0';
|
|
|
|
|
|
|
|
/* Move to the begin of circle buffer */
|
|
|
|
|
|
|
|
g_note_taskname.head = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ti = (FAR struct note_taskname_info_s *)
|
|
|
|
&g_note_taskname.buffer[g_note_taskname.head];
|
|
|
|
ti->size = tilen;
|
2023-10-31 15:10:06 +01:00
|
|
|
ti->pid = pid;
|
2022-12-26 06:18:33 +01:00
|
|
|
strlcpy(ti->name, name, namelen + 1);
|
|
|
|
g_note_taskname.head += tilen;
|
|
|
|
}
|
|
|
|
#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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
|
|
|
|
2016-03-17 16:49:43 +01:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_start(*driver, tcb))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
|
|
|
|
/* Copy the task name (if possible) and
|
|
|
|
* get the length of the note
|
|
|
|
*/
|
2016-03-17 16:49:43 +01:00
|
|
|
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2022-12-16 11:31:28 +01:00
|
|
|
namelen = strlen(tcb->name);
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
|
|
|
|
strlcpy(note.nsa_name, tcb->name, sizeof(note.nsa_name));
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
length = SIZEOF_NOTE_START(namelen + 1);
|
2016-03-17 16:49:43 +01:00
|
|
|
#else
|
2022-12-16 11:31:28 +01:00
|
|
|
length = SIZEOF_NOTE_START(0);
|
2016-03-17 16:49:43 +01:00
|
|
|
#endif
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Finish formatting the note */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_common(tcb, ¬e.nsa_cmn, length, NOTE_START);
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬e, length);
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_stop(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
struct note_stop_s note;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
#if CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0
|
2022-12-26 06:18:33 +01:00
|
|
|
note_record_taskname(tcb->pid, tcb->name);
|
|
|
|
#endif
|
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_stop(*driver, tcb))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.nsp_cmn, sizeof(struct note_stop_s),
|
|
|
|
NOTE_STOP);
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, ¬e, sizeof(struct note_stop_s));
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
|
2021-12-03 05:26:42 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled_switch())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
2023-03-15 04:31:59 +01:00
|
|
|
if (note_suspend(*driver, tcb))
|
2022-12-16 11:31:28 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.nsu_cmn, sizeof(struct note_suspend_s),
|
|
|
|
NOTE_SUSPEND);
|
|
|
|
note.nsu_state = tcb->task_state;
|
|
|
|
}
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled_switch())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_resume(*driver, tcb))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.nre_cmn, sizeof(struct note_resume_s),
|
|
|
|
NOTE_RESUME);
|
|
|
|
}
|
2016-03-21 22:24:15 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, ¬e, sizeof(struct note_resume_s));
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
2021-12-03 05:26:42 +01:00
|
|
|
#endif
|
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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_cpu_start(*driver, tcb, cpu))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.ncs_cmn, sizeof(struct note_cpu_start_s),
|
|
|
|
NOTE_CPU_START);
|
|
|
|
note.ncs_target = (uint8_t)cpu;
|
|
|
|
}
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_cpu_started(*driver, tcb))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2016-12-07 16:08:20 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.ncs_cmn, sizeof(struct note_cpu_started_s),
|
|
|
|
NOTE_CPU_STARTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, ¬e, sizeof(struct note_cpu_started_s));
|
|
|
|
}
|
2016-12-07 16:08:20 +01:00
|
|
|
}
|
|
|
|
|
2021-12-03 05:26:42 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled_switch())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_cpu_pause(*driver, tcb, cpu))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.ncp_cmn, sizeof(struct note_cpu_pause_s),
|
|
|
|
NOTE_CPU_PAUSE);
|
|
|
|
note.ncp_target = (uint8_t)cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled_switch())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_cpu_paused(*driver, tcb))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.ncp_cmn, sizeof(struct note_cpu_paused_s),
|
|
|
|
NOTE_CPU_PAUSED);
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled_switch())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_cpu_resume(*driver, tcb, cpu))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
|
|
|
|
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.ncr_cmn, sizeof(struct note_cpu_resume_s),
|
|
|
|
NOTE_CPU_RESUME);
|
|
|
|
note.ncr_target = (uint8_t)cpu;
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-02-18 08:05:23 +01:00
|
|
|
if (!note_isenabled_switch())
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_cpu_resumed(*driver, tcb))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2016-11-28 00:14:57 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.ncr_cmn, sizeof(struct note_cpu_resumed_s),
|
|
|
|
NOTE_CPU_RESUMED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, ¬e, sizeof(struct note_cpu_resumed_s));
|
|
|
|
}
|
2016-11-28 00:14:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
2021-12-03 05:26:42 +01:00
|
|
|
#endif
|
2016-11-28 00:14:57 +01:00
|
|
|
|
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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_premption(*driver, tcb, locked))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
|
|
|
|
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.npr_cmn, sizeof(struct note_preempt_s),
|
|
|
|
locked ? NOTE_PREEMPT_LOCK : NOTE_PREEMPT_UNLOCK);
|
2023-10-31 15:10:06 +01:00
|
|
|
note.npr_count = tcb->lockcount;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_csection(*driver, tcb, enter))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
|
|
|
|
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
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
|
2023-10-31 15:10:06 +01:00
|
|
|
note.ncs_count = tcb->irqcount;
|
2016-03-17 16:49:43 +01:00
|
|
|
#endif
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2016-03-17 16:49:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬e, sizeof(struct note_csection_s));
|
|
|
|
}
|
2016-03-17 16:49:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-16 05:27:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_note_spinlock
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-11-28 17:33:46 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
2022-12-16 05:27:09 +01:00
|
|
|
void sched_note_spinlock(FAR struct tcb_s *tcb,
|
|
|
|
FAR volatile spinlock_t *spinlock,
|
|
|
|
int type)
|
2016-11-28 17:33:46 +01:00
|
|
|
{
|
2022-12-16 05:27:09 +01:00
|
|
|
struct note_spinlock_s note;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2016-11-28 17:33:46 +01:00
|
|
|
|
2022-12-16 05:27:09 +01:00
|
|
|
if (!note_isenabled())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-11-28 17:33:46 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_spinlock(*driver, tcb, spinlock, type))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-24 18:49:28 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2022-12-16 05:27:09 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.nsp_cmn, sizeof(struct note_spinlock_s),
|
|
|
|
type);
|
2023-10-31 15:10:06 +01:00
|
|
|
note.nsp_spinlock = (uintptr_t)spinlock;
|
2022-12-16 11:31:28 +01:00
|
|
|
note.nsp_value = *(FAR uint8_t *)spinlock;
|
|
|
|
}
|
2022-12-16 05:27:09 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2022-12-16 05:27:09 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬e, sizeof(struct note_spinlock_s));
|
|
|
|
}
|
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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2020-06-16 19:30:58 +02:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
2020-07-23 15:18:14 +02:00
|
|
|
unsigned int length;
|
|
|
|
uintptr_t arg;
|
2022-03-31 14:22:25 +02:00
|
|
|
va_list ap;
|
|
|
|
int i;
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
if (!note_isenabled_syscall(nr))
|
2020-08-06 20:57:30 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:18:14 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
|
|
|
|
if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_SYSCALL_ARGS))
|
|
|
|
{
|
|
|
|
argc = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-12-29 07:43:20 +01:00
|
|
|
va_start(ap, argc);
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
2022-12-29 07:43:20 +01:00
|
|
|
va_list copy;
|
2022-12-30 04:46:06 +01:00
|
|
|
|
2022-12-29 07:43:20 +01:00
|
|
|
va_copy(copy, ap);
|
|
|
|
if (note_syscall_enter(*driver, nr, argc, ©))
|
2022-12-16 11:31:28 +01:00
|
|
|
{
|
2022-12-29 07:43:20 +01:00
|
|
|
va_end(copy);
|
2022-12-16 11:31:28 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
2022-12-30 04:46:06 +01:00
|
|
|
va_end(copy);
|
2022-12-16 11:31:28 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the note */
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
length = SIZEOF_NOTE_SYSCALL_ENTER(argc);
|
|
|
|
note_common(tcb, ¬e.nsc_cmn, length, NOTE_SYSCALL_ENTER);
|
|
|
|
DEBUGASSERT(nr <= UCHAR_MAX);
|
|
|
|
note.nsc_nr = nr;
|
|
|
|
DEBUGASSERT(argc <= MAX_SYSCALL_ARGS);
|
|
|
|
note.nsc_argc = argc;
|
2020-07-23 15:18:14 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* If needed, retrieve the given syscall arguments */
|
2020-07-23 15:18:14 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
2022-12-29 07:43:20 +01:00
|
|
|
arg = (uintptr_t)va_arg(copy, uintptr_t);
|
2023-10-31 15:10:06 +01:00
|
|
|
note.nsc_args[i] = arg;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-30 04:46:06 +01:00
|
|
|
va_end(copy);
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬e, length);
|
|
|
|
}
|
2022-12-29 07:43:20 +01:00
|
|
|
|
|
|
|
va_end(ap);
|
2020-06-16 19:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_syscall_leave(int nr, uintptr_t result)
|
|
|
|
{
|
|
|
|
struct note_syscall_leave_s note;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2020-06-16 19:30:58 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
2022-12-29 07:43:20 +01:00
|
|
|
if (note_syscall_leave(*driver, nr, result))
|
2022-12-16 11:31:28 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-31 14:19:15 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2020-10-16 15:49:46 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.nsc_cmn,
|
|
|
|
sizeof(struct note_syscall_leave_s),
|
|
|
|
NOTE_SYSCALL_LEAVE);
|
|
|
|
DEBUGASSERT(nr <= UCHAR_MAX);
|
|
|
|
note.nsc_nr = nr;
|
2023-10-31 15:10:06 +01:00
|
|
|
note.nsc_result = result;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, ¬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;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2020-06-16 19:30:58 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
|
|
|
{
|
|
|
|
if (note_irqhandler(*driver, irq, handler, enter))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note_common(tcb, ¬e.nih_cmn, sizeof(struct note_irqhandler_s),
|
|
|
|
enter ? NOTE_IRQ_ENTER : NOTE_IRQ_LEAVE);
|
|
|
|
DEBUGASSERT(irq <= UCHAR_MAX);
|
|
|
|
note.nih_irq = irq;
|
2023-06-20 10:56:24 +02:00
|
|
|
note.nih_handler = (uintptr_t)handler;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2020-06-16 19:30:58 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, ¬e, sizeof(struct note_irqhandler_s));
|
|
|
|
}
|
2020-06-16 19:30:58 +02:00
|
|
|
}
|
|
|
|
#endif
|
2020-07-23 15:18:03 +02:00
|
|
|
|
2021-11-17 10:23:43 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
2023-02-28 09:16:55 +01:00
|
|
|
void sched_note_string_ip(uint32_t tag, uintptr_t ip, FAR const char *buf)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
FAR struct note_string_s *note;
|
|
|
|
uint8_t data[255];
|
|
|
|
unsigned int length;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2021-11-17 10:23:43 +01:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
if (!note_isenabled_dump(tag))
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2022-12-16 11:31:28 +01:00
|
|
|
if (note_string(*driver, ip, buf))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note = (FAR struct note_string_s *)data;
|
|
|
|
length = SIZEOF_NOTE_STRING(strlen(buf));
|
|
|
|
if (length > sizeof(data))
|
|
|
|
{
|
|
|
|
length = sizeof(data);
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_common(tcb, ¬e->nst_cmn, length, NOTE_DUMP_STRING);
|
|
|
|
memcpy(note->nst_data, buf, length - sizeof(struct note_string_s));
|
|
|
|
data[length - 1] = '\0';
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nst_ip = ip;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, note, length);
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
}
|
|
|
|
|
2023-10-10 16:45:02 +02:00
|
|
|
void sched_note_event_ip(uint32_t tag, uintptr_t ip, uint8_t event,
|
|
|
|
FAR const void *buf, size_t len)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
FAR struct note_binary_s *note;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2021-11-17 10:23:43 +01:00
|
|
|
char data[255];
|
|
|
|
unsigned int length;
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
if (!note_isenabled_dump(tag))
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2023-10-16 05:05:17 +02:00
|
|
|
if (note_event(*driver, ip, event, buf, len))
|
2022-12-16 11:31:28 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note = (FAR struct note_binary_s *)data;
|
|
|
|
length = SIZEOF_NOTE_BINARY(len);
|
|
|
|
if (length > sizeof(data))
|
|
|
|
{
|
|
|
|
length = sizeof(data);
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2023-10-10 16:45:02 +02:00
|
|
|
note_common(tcb, ¬e->nbi_cmn, length, event);
|
2022-12-16 11:31:28 +01:00
|
|
|
memcpy(note->nbi_data, buf,
|
|
|
|
length - sizeof(struct note_binary_s) + 1);
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nbi_ip = ip;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, note, length);
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
}
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
void sched_note_vprintf_ip(uint32_t tag, uintptr_t ip,
|
|
|
|
FAR const char *fmt, va_list va)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
FAR struct note_string_s *note;
|
|
|
|
uint8_t data[255];
|
|
|
|
unsigned int length;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2021-11-17 10:23:43 +01:00
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
if (!note_isenabled_dump(tag))
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2022-12-16 11:31:28 +01:00
|
|
|
if (note_vprintf(*driver, ip, fmt, va))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note = (FAR struct note_string_s *)data;
|
|
|
|
length = vsnprintf(note->nst_data,
|
|
|
|
sizeof(data) - sizeof(struct note_string_s),
|
|
|
|
fmt,
|
|
|
|
va);
|
|
|
|
length = SIZEOF_NOTE_STRING(length);
|
|
|
|
if (length > sizeof(data))
|
|
|
|
{
|
|
|
|
length = sizeof(data);
|
|
|
|
}
|
2022-03-31 14:22:25 +02:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_common(tcb, ¬e->nst_cmn, length, NOTE_DUMP_STRING);
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nst_ip = ip;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the note to circular buffer */
|
|
|
|
|
|
|
|
note_add(*driver, note, length);
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
}
|
|
|
|
|
2023-10-16 05:05:17 +02:00
|
|
|
void sched_note_vbprintf_ip(uint32_t tag, uintptr_t ip,
|
2023-02-28 09:16:55 +01:00
|
|
|
FAR const char *fmt, va_list va)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
FAR struct note_binary_s *note;
|
2022-12-16 11:31:28 +01:00
|
|
|
FAR struct note_driver_s **driver;
|
|
|
|
bool formatted = false;
|
2021-11-17 10:23:43 +01:00
|
|
|
uint8_t data[255];
|
|
|
|
begin_packed_struct union
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
2022-07-12 21:32:11 +02:00
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
2021-11-17 10:23:43 +01:00
|
|
|
long long ll;
|
|
|
|
#endif
|
|
|
|
intmax_t im;
|
|
|
|
size_t sz;
|
|
|
|
ptrdiff_t ptr;
|
|
|
|
#ifdef CONFIG_HAVE_FLOAT
|
|
|
|
float f;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_HAVE_DOUBLE
|
|
|
|
double d;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
|
|
|
long double ld;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
end_packed_struct *var;
|
|
|
|
|
|
|
|
char c;
|
|
|
|
int length;
|
2023-10-05 14:02:51 +02:00
|
|
|
bool infmt = false;
|
2021-11-17 10:23:43 +01:00
|
|
|
int next = 0;
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
if (!note_isenabled_dump(tag))
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
for (driver = g_note_drivers; *driver; driver++)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2023-10-16 05:05:17 +02:00
|
|
|
if (note_vbprintf(*driver, ip, fmt, va))
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if ((*driver)->ops->add == NULL)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2022-12-16 11:31:28 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Format the note */
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (!formatted)
|
|
|
|
{
|
|
|
|
formatted = true;
|
|
|
|
note = (FAR struct note_binary_s *)data;
|
|
|
|
length = sizeof(data) - sizeof(struct note_binary_s) + 1;
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
while ((c = *fmt++) != '\0')
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2023-10-05 14:02:51 +02:00
|
|
|
if (c != '%' && !infmt)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2022-12-16 11:31:28 +01:00
|
|
|
continue;
|
2021-11-17 10:23:43 +01:00
|
|
|
}
|
|
|
|
|
2023-10-05 14:02:51 +02:00
|
|
|
infmt = true;
|
2022-12-16 11:31:28 +01:00
|
|
|
var = (FAR void *)¬e->nbi_data[next];
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (c == 'd' || c == 'i' || c == 'u' ||
|
|
|
|
c == 'o' || c == 'x' || c == 'X')
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2022-12-16 11:31:28 +01:00
|
|
|
if (*(fmt - 2) == 'h' && *(fmt - 3) == 'h')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->c) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->c = va_arg(va, int);
|
|
|
|
next += sizeof(var->c);
|
|
|
|
}
|
|
|
|
else if (*(fmt - 2) == 'h')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->s) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->s = va_arg(va, int);
|
|
|
|
next += sizeof(var->s);
|
|
|
|
}
|
|
|
|
else if (*(fmt - 2) == 'j')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->im) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->im = va_arg(va, intmax_t);
|
|
|
|
next += sizeof(var->im);
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
|
|
|
else if (*(fmt - 2) == 'l' && *(fmt - 3) == 'l')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->ll) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->ll = va_arg(va, long long);
|
|
|
|
next += sizeof(var->ll);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (*(fmt - 2) == 'l')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->l) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->l = va_arg(va, long);
|
|
|
|
next += sizeof(var->l);
|
|
|
|
}
|
|
|
|
else if (*(fmt - 2) == 'z')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->sz) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->sz = va_arg(va, size_t);
|
|
|
|
next += sizeof(var->sz);
|
|
|
|
}
|
|
|
|
else if (*(fmt - 2) == 't')
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->ptr) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->ptr = va_arg(va, ptrdiff_t);
|
|
|
|
next += sizeof(var->ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (next + sizeof(var->i) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->i = va_arg(va, int);
|
|
|
|
next += sizeof(var->i);
|
|
|
|
}
|
|
|
|
|
2023-10-05 14:02:51 +02:00
|
|
|
infmt = false;
|
2021-11-17 10:23:43 +01:00
|
|
|
}
|
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
if (c == 'e' || c == 'f' || c == 'g' ||
|
|
|
|
c == 'E' || c == 'F' || c == 'G')
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
2022-12-16 11:31:28 +01:00
|
|
|
if (*(fmt - 2) == 'L')
|
|
|
|
{
|
2021-11-17 10:23:43 +01:00
|
|
|
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
2022-12-16 11:31:28 +01:00
|
|
|
if (next + sizeof(var->ld) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
var->ld = va_arg(va, long double);
|
|
|
|
next += sizeof(var->ld);
|
2021-11-17 10:23:43 +01:00
|
|
|
#endif
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
|
|
|
else if (*(fmt - 2) == 'l')
|
|
|
|
{
|
2021-11-17 10:23:43 +01:00
|
|
|
#ifdef CONFIG_HAVE_DOUBLE
|
2022-12-16 11:31:28 +01:00
|
|
|
if (next + sizeof(var->d) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
var->d = va_arg(va, double);
|
|
|
|
next += sizeof(var->d);
|
2021-11-17 10:23:43 +01:00
|
|
|
#endif
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
|
|
|
else
|
2021-11-17 10:23:43 +01:00
|
|
|
#ifdef CONFIG_HAVE_FLOAT
|
2022-12-16 11:31:28 +01:00
|
|
|
{
|
|
|
|
if (next + sizeof(var->l) > length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->l = va_arg(va, double);
|
|
|
|
next += sizeof(var->l);
|
2021-11-17 10:23:43 +01:00
|
|
|
#endif
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2023-10-05 14:02:51 +02:00
|
|
|
infmt = false;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
length = SIZEOF_NOTE_BINARY(next);
|
|
|
|
note_common(tcb, ¬e->nbi_cmn, length, NOTE_DUMP_BINARY);
|
2023-10-31 15:10:06 +01:00
|
|
|
note->nbi_ip = ip;
|
2022-12-16 11:31:28 +01:00
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
/* Add the note to circular buffer */
|
2021-11-17 10:23:43 +01:00
|
|
|
|
2022-12-16 11:31:28 +01:00
|
|
|
note_add(*driver, note, length);
|
|
|
|
}
|
2021-11-17 10:23:43 +01:00
|
|
|
}
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
void sched_note_printf_ip(uint32_t tag, uintptr_t ip,
|
|
|
|
FAR const char *fmt, ...)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2023-02-28 09:16:55 +01:00
|
|
|
sched_note_vprintf_ip(tag, ip, fmt, va);
|
2021-11-17 10:23:43 +01:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
|
2023-10-16 05:05:17 +02:00
|
|
|
void sched_note_bprintf_ip(uint32_t tag, uintptr_t ip,
|
2023-02-28 09:16:55 +01:00
|
|
|
FAR const char *fmt, ...)
|
2021-11-17 10:23:43 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2023-10-16 05:05:17 +02:00
|
|
|
sched_note_vbprintf_ip(tag, ip, fmt, va);
|
2021-11-17 10:23:43 +01:00
|
|
|
va_end(va);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SCHED_INSTRUMENTATION_DUMP */
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-12-12 03:04:16 +01:00
|
|
|
void sched_note_filter_mode(FAR struct note_filter_mode_s *oldm,
|
|
|
|
FAR struct note_filter_mode_s *newm)
|
2020-07-23 15:18:03 +02:00
|
|
|
{
|
|
|
|
irqstate_t irq_mask;
|
|
|
|
|
2022-12-30 05:02:47 +01:00
|
|
|
irq_mask = spin_lock_irqsave_wo_note(&g_note_lock);
|
2020-07-23 15:18:03 +02:00
|
|
|
|
|
|
|
if (oldm != NULL)
|
|
|
|
{
|
|
|
|
*oldm = g_note_filter.mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newm != NULL)
|
|
|
|
{
|
|
|
|
g_note_filter.mode = *newm;
|
|
|
|
}
|
|
|
|
|
2022-12-30 05:02:47 +01:00
|
|
|
spin_unlock_irqrestore_wo_note(&g_note_lock, irq_mask);
|
2020-07-23 15:18:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
2022-12-12 03:04:16 +01:00
|
|
|
void sched_note_filter_syscall(FAR struct note_filter_syscall_s *oldf,
|
|
|
|
FAR struct note_filter_syscall_s *newf)
|
2020-07-23 15:18:03 +02:00
|
|
|
{
|
|
|
|
irqstate_t irq_mask;
|
|
|
|
|
2022-12-30 05:02:47 +01:00
|
|
|
irq_mask = spin_lock_irqsave_wo_note(&g_note_lock);
|
2020-07-23 15:18:03 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-30 05:02:47 +01:00
|
|
|
spin_unlock_irqrestore_wo_note(&g_note_lock, irq_mask);
|
2020-07-23 15:18:03 +02:00
|
|
|
}
|
|
|
|
#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
|
2022-12-12 03:04:16 +01:00
|
|
|
void sched_note_filter_irq(FAR struct note_filter_irq_s *oldf,
|
|
|
|
FAR struct note_filter_irq_s *newf)
|
2020-07-23 15:18:03 +02:00
|
|
|
{
|
|
|
|
irqstate_t irq_mask;
|
|
|
|
|
2022-12-30 05:02:47 +01:00
|
|
|
irq_mask = spin_lock_irqsave_wo_note(&g_note_lock);
|
2020-07-23 15:18:03 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-30 05:02:47 +01:00
|
|
|
spin_unlock_irqrestore_wo_note(&g_note_lock, irq_mask);
|
2020-07-23 15:18:03 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-02-28 09:16:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sched_note_filter_tag
|
|
|
|
*
|
|
|
|
* Description:
|
2023-04-08 09:22:55 +02:00
|
|
|
* Set and get tag filter setting
|
2023-02-28 09:16:55 +01:00
|
|
|
* (Same as NOTECTL_GETDUMPFILTER / NOTECTL_SETDUMPFILTER ioctls)
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* oldf - A writable pointer to struct note_filter_tag_s to get
|
|
|
|
* current dump filter setting
|
|
|
|
* If 0, no data is written.
|
|
|
|
* newf - A read-only pointer to struct note_filter_tag_s of the
|
|
|
|
* new dump filter setting
|
|
|
|
* If 0, the setting is not updated.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-02 11:02:07 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP
|
2023-04-08 09:22:55 +02:00
|
|
|
void sched_note_filter_tag(FAR struct note_filter_tag_s *oldf,
|
|
|
|
FAR struct note_filter_tag_s *newf)
|
2023-02-28 09:16:55 +01:00
|
|
|
{
|
|
|
|
irqstate_t falgs;
|
|
|
|
|
|
|
|
falgs = spin_lock_irqsave_wo_note(&g_note_lock);
|
|
|
|
|
|
|
|
if (oldf != NULL)
|
|
|
|
{
|
|
|
|
/* Return the current filter setting */
|
|
|
|
|
|
|
|
*oldf = g_note_filter.tag_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newf != NULL)
|
|
|
|
{
|
|
|
|
/* Replace the dump filter mask by the provided setting */
|
|
|
|
|
|
|
|
g_note_filter.tag_mask = *newf;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore_wo_note(&g_note_lock, falgs);
|
|
|
|
}
|
2023-08-02 11:02:07 +02:00
|
|
|
#endif
|
2023-02-28 09:16:55 +01:00
|
|
|
|
2020-07-23 15:18:03 +02:00
|
|
|
#endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
|
2022-12-26 06:18:33 +01:00
|
|
|
|
2023-02-20 08:21:31 +01:00
|
|
|
#if CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0
|
2022-12-26 06:18:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_get_taskname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the task name string of the specified PID
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* PID - Task ID
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2023-08-11 04:31:03 +02:00
|
|
|
* Retrun name if task name can be retrieved, otherwise NULL
|
2022-12-26 06:18:33 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-11 04:31:03 +02:00
|
|
|
FAR const char *note_get_taskname(pid_t pid)
|
2022-12-26 06:18:33 +01:00
|
|
|
{
|
|
|
|
FAR struct note_taskname_info_s *ti;
|
|
|
|
FAR struct tcb_s *tcb;
|
|
|
|
|
|
|
|
tcb = nxsched_get_tcb(pid);
|
|
|
|
if (tcb != NULL)
|
|
|
|
{
|
2023-08-11 04:31:03 +02:00
|
|
|
return tcb->name;
|
2022-12-26 06:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ti = note_find_taskname(pid);
|
|
|
|
if (ti != NULL)
|
|
|
|
{
|
2023-08-11 04:31:03 +02:00
|
|
|
return ti->name;
|
2022-12-26 06:18:33 +01:00
|
|
|
}
|
|
|
|
|
2023-08-11 04:31:03 +02:00
|
|
|
return NULL;
|
2022-12-26 06:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2023-01-05 11:15:06 +01:00
|
|
|
|
2023-10-08 12:20:43 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
|
|
|
|
static void note_driver_instrument_enter(FAR void *this_fn,
|
|
|
|
FAR void *call_site,
|
|
|
|
FAR void *arg)
|
|
|
|
{
|
|
|
|
sched_note_string_ip(NOTE_TAG_ALWAYS, (uintptr_t)this_fn, "B");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void note_driver_instrument_leave(FAR void *this_fn,
|
|
|
|
FAR void *call_site,
|
|
|
|
FAR void *arg)
|
|
|
|
{
|
|
|
|
sched_note_string_ip(NOTE_TAG_ALWAYS, (uintptr_t)this_fn, "E");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: note_driver_register
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int note_driver_register(FAR struct note_driver_s *driver)
|
|
|
|
{
|
|
|
|
int i;
|
2023-10-08 12:20:43 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
|
|
|
|
static bool initialized;
|
2023-01-05 11:15:06 +01:00
|
|
|
|
2023-10-08 12:20:43 +02:00
|
|
|
if (!initialized)
|
|
|
|
{
|
2024-01-22 09:58:14 +01:00
|
|
|
instrument_register(&g_note_instrument);
|
2023-10-08 12:20:43 +02:00
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DEBUGASSERT(driver);
|
2023-02-20 08:21:31 +01:00
|
|
|
for (i = 0; i < CONFIG_DRIVERS_NOTE_MAX; i++)
|
2023-01-05 11:15:06 +01:00
|
|
|
{
|
|
|
|
if (g_note_drivers[i] == NULL)
|
|
|
|
{
|
|
|
|
g_note_drivers[i] = driver;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2023-04-06 17:11:02 +02:00
|
|
|
|