2016-02-16 20:40:15 +01:00
|
|
|
/****************************************************************************
|
2020-10-13 14:19:28 +02:00
|
|
|
* drivers/note/notelog_driver.c
|
2016-02-16 20:40:15 +01:00
|
|
|
*
|
2021-03-28 17:21:53 +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-02-16 20:40:15 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2021-06-26 07:55:54 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <syscall.h>
|
2016-02-16 20:40:15 +01:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <nuttx/sched.h>
|
2021-06-26 07:55:54 +02:00
|
|
|
#include <nuttx/sched_note.h>
|
2016-02-16 20:40:15 +01:00
|
|
|
|
2022-12-09 15:57:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-02-16 20:40:15 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-02-16 22:19:44 +01:00
|
|
|
* Name: sched_note_start, sched_note_stop, sched_note_switch,
|
|
|
|
* sched_note_premption
|
2016-02-16 20:40:15 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2016-02-16 22:19:44 +01:00
|
|
|
* Hooks to scheduler monitor
|
2016-02-16 20:40:15 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2016-02-16 22:19:44 +01:00
|
|
|
* Varies
|
2016-02-16 20:40:15 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2016-02-16 22:19:44 +01:00
|
|
|
* None
|
2016-02-16 20:40:15 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void sched_note_start(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Start %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->task_state);
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Start TCB@%p, state=%d\n"
|
|
|
|
tcb->cpu, tcb, tcb->task_state);
|
2016-02-16 20:40:15 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Start %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->name, tcb, tcb->task_state);
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Start TCB@%p, state=%d\n",
|
|
|
|
tcb, tcb->task_state);
|
2016-02-16 20:40:15 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_stop(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Stop %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->task_state);
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Stop TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb, tcb->task_state);
|
2016-02-16 20:40:15 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Stop %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->name, tcb, tcb->task_state);
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Stop TCB@%p, state=%d\n",
|
|
|
|
tcb, tcb->task_state);
|
2016-02-16 20:40:15 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-03-13 15:52:54 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
2016-03-23 01:18:37 +01:00
|
|
|
void sched_note_suspend(FAR struct tcb_s *tcb)
|
2016-02-16 20:40:15 +01:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Suspend %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->task_state);
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Suspend TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb, tcb->task_state);
|
2016-02-16 20:40:15 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Suspend %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->name, tcb, tcb->task_state);
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Suspend TCB@%p, state=%d\n",
|
|
|
|
tcb, tcb->task_state);
|
2016-03-23 01:18:37 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_resume(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Resume %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->task_state);
|
2016-03-23 01:18:37 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Resume TCB@%p, state=%d\n",
|
|
|
|
tcb->cpu, tcb, tcb->task_state);
|
2016-03-23 01:18:37 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Resume %s, TCB@%p, state=%d\n",
|
|
|
|
tcb->name, tcb, tcb->task_state);
|
2016-03-23 01:18:37 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Resume TCB@%p, state=%d\n",
|
|
|
|
tcb, tcb->task_state);
|
2016-02-16 20:40:15 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
2022-03-13 15:52:54 +01:00
|
|
|
#endif
|
2016-02-16 20:40:15 +01:00
|
|
|
|
2021-06-26 07:55:54 +02:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
void sched_note_cpu_start(FAR struct tcb_s *tcb, int cpu)
|
|
|
|
{
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d START\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, cpu);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d START\n",
|
|
|
|
tcb->cpu, tcb, cpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_started(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d STARTED\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->cpu);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d STARTED\n",
|
|
|
|
tcb->cpu, tcb, tcb->cpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-03-13 15:52:54 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
2021-06-26 07:55:54 +02:00
|
|
|
void sched_note_cpu_pause(FAR struct tcb_s *tcb, int cpu)
|
|
|
|
{
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d PAUSE\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, cpu);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d PAUSE\n",
|
|
|
|
tcb->cpu, tcb, cpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_paused(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d PAUSED\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->cpu);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d PAUSED\n",
|
|
|
|
tcb->cpu, tcb, tcb->cpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_resume(FAR struct tcb_s *tcb, int cpu)
|
|
|
|
{
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d RESUME\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, cpu);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d RESUME\n",
|
|
|
|
tcb->cpu, tcb, cpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_cpu_resumed(FAR struct tcb_s *tcb)
|
|
|
|
{
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d RESUMED\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, tcb->cpu);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d RESUMED\n",
|
|
|
|
tcb->cpu, tcb, tcb->cpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2022-03-13 15:52:54 +01:00
|
|
|
#endif
|
2021-06-26 07:55:54 +02:00
|
|
|
|
2016-02-16 22:19:44 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
|
2016-02-16 23:08:59 +01:00
|
|
|
/* This does not work well... it interferes with the operation of the
|
|
|
|
* simulated /dev/console device which, of course, does disable preemption
|
|
|
|
* and does use critical sections.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#warning CONFIG_SCHED_INSTRUMENTATION_PREEMPTION is a bad idea
|
|
|
|
|
2016-02-16 22:19:44 +01:00
|
|
|
void sched_note_premption(FAR struct tcb_s *tcb, bool locked)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p preemption %s\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, locked ? "LOCKED" : "UNLOCKED");
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p preemption %s\n",
|
|
|
|
tcb->cpu, tcb, locked ? "LOCKED" : "UNLOCKED");
|
2016-02-16 22:19:44 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Task %s, TCB@%p preemption %s\n",
|
|
|
|
tcb->name, tcb, locked ? "LOCKED" : "UNLOCKED");
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "TCB@%p preemption %s\n",
|
|
|
|
tcb, locked ? "LOCKED" : "UNLOCKED");
|
2016-02-16 22:19:44 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
|
2016-02-16 23:08:59 +01:00
|
|
|
/* This does not work well... it interferes with the operation of the
|
|
|
|
* simulated /dev/console device which, of course, does disable preemption
|
|
|
|
* and does use critical sections.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#warning CONFIG_SCHED_INSTRUMENTATION_CSECTION is a bad idea
|
|
|
|
|
2016-02-16 22:19:44 +01:00
|
|
|
void sched_note_csection(FAR struct tcb_s *tcb, bool enter)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p critical section %s\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, enter ? "ENTER" : "LEAVE");
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p critical section %s\n",
|
|
|
|
tcb->cpu, tcb, enter ? "ENTER" : "LEAVE");
|
2016-02-16 22:19:44 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "Task %s, TCB@%p critical section %s\n",
|
|
|
|
tcb->name, tcb, enter ? "ENTER" : "LEAVE");
|
2016-02-16 22:19:44 +01:00
|
|
|
#else
|
2016-06-20 16:57:08 +02:00
|
|
|
syslog(LOG_INFO, "TCB@%p critical section %s\n",
|
|
|
|
tcb, enter ? "ENTER" : "LEAVE");
|
2016-02-16 22:19:44 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2021-06-26 07:55:54 +02:00
|
|
|
|
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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-06-26 07:55:54 +02:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
|
|
|
void sched_note_spinlock(FAR struct tcb_s *tcb,
|
2022-12-16 05:27:09 +01:00
|
|
|
FAR volatile spinlock_t *spinlock,
|
|
|
|
int type)
|
2021-06-26 07:55:54 +02:00
|
|
|
{
|
2022-12-16 05:27:09 +01:00
|
|
|
FAR static const char * const tmp[] =
|
|
|
|
{
|
|
|
|
"LOCK",
|
|
|
|
"LOCKED",
|
|
|
|
"UNLOCK",
|
|
|
|
"ABORT"
|
|
|
|
};
|
2021-06-26 07:55:54 +02:00
|
|
|
|
2022-12-16 05:27:09 +01:00
|
|
|
FAR const char * msg = tmp[type - NOTE_SPINLOCK_LOCK];
|
2021-06-26 07:55:54 +02:00
|
|
|
|
2022-12-16 05:27:09 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p %s\n",
|
|
|
|
tcb->cpu, tcb->name, tcb, spinlock, msg);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p %s\n",
|
|
|
|
tcb->cpu, tcb, spinlock, msg);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
|
|
|
syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p %s\n",
|
|
|
|
tcb->name, tcb, spinlock, msg);
|
|
|
|
#else
|
|
|
|
syslog(LOG_INFO, "TCB@%p spinlock@%p %s\n",
|
|
|
|
tcb, spinlock, msg);
|
|
|
|
#endif
|
|
|
|
#endif
|
2021-06-26 07:55:54 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
void sched_note_syscall_enter(int nr, int argc, ...)
|
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
FAR char *p = buf;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, argc);
|
|
|
|
while (argc-- > 0)
|
|
|
|
{
|
|
|
|
if (argc)
|
|
|
|
{
|
|
|
|
p += sprintf(p, "%#"PRIxPTR", ", va_arg(ap, uintptr_t));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p += sprintf(p, "%#"PRIxPTR, va_arg(ap, uintptr_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
syslog(LOG_INFO, "%s@%d ENTER %s\n", g_funcnames[nr], nr, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sched_note_syscall_leave(int nr, uintptr_t result)
|
|
|
|
{
|
|
|
|
syslog(LOG_INFO, "%s@%d LEAVE %"PRIdPTR"\n", g_funcnames[nr], nr, result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
|
|
|
|
{
|
|
|
|
syslog(LOG_INFO, "IRQ%d handler@%p %s\n",
|
|
|
|
irq, handler, enter ? "ENTER" : "LEAVE");
|
|
|
|
}
|
|
|
|
#endif
|