drivers/note: unify spinlock related functions

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2022-12-09 22:57:31 +08:00 committed by Xiang Xiao
parent a5a1a68a25
commit 026c8eede0

View File

@ -30,6 +30,60 @@
#include <nuttx/sched.h>
#include <nuttx/sched_note.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* 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
static inline void note_spincommon(FAR struct tcb_s *tcb,
FAR volatile void *spinlock,
int type)
{
FAR static const char * const tmp[] =
{
"LOCK",
"LOCKED",
"UNLOCK",
"ABORT"
};
FAR const char * msg = tmp[type - NOTE_SPINLOCK_LOCK];
#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
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -269,89 +323,25 @@ void sched_note_csection(FAR struct tcb_s *tcb, bool enter)
void sched_note_spinlock(FAR struct tcb_s *tcb,
FAR volatile void *spinlock)
{
#ifdef CONFIG_SMP
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p LOCK\n",
tcb->cpu, tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p LOCK\n",
tcb->cpu, tcb, spinlock);
#endif
#else
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p LOCK\n",
tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "TCB@%p spinlock@%p LOCK\n",
tcb, spinlock);
#endif
#endif
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_LOCK);
}
void sched_note_spinlocked(FAR struct tcb_s *tcb,
FAR volatile void *spinlock)
{
#ifdef CONFIG_SMP
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p LOCKED\n",
tcb->cpu, tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p LOCKED\n",
tcb->cpu, tcb, spinlock);
#endif
#else
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p LOCKED\n",
tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "TCB@%p spinlock@%p LOCKED\n",
tcb, spinlock);
#endif
#endif
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_LOCKED);
}
void sched_note_spinunlock(FAR struct tcb_s *tcb,
FAR volatile void *spinlock)
{
#ifdef CONFIG_SMP
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p UNLOCK\n",
tcb->cpu, tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p UNLOCK\n",
tcb->cpu, tcb, spinlock);
#endif
#else
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p UNLOCK\n",
tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "TCB@%p spinlock@%p UNLOCK\n",
tcb, spinlock);
#endif
#endif
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_UNLOCK);
}
void sched_note_spinabort(FAR struct tcb_s *tcb,
FAR volatile void *spinlock)
{
#ifdef CONFIG_SMP
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p ABORT\n",
tcb->cpu, tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p ABORT\n",
tcb->cpu, tcb, spinlock);
#endif
#else
#if CONFIG_TASK_NAME_SIZE > 0
syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p ABORT\n",
tcb->name, tcb, spinlock);
#else
syslog(LOG_INFO, "TCB@%p spinlock@%p ABORT\n",
tcb, spinlock);
#endif
#endif
note_spincommon(tcb, spinlock, NOTE_SPINLOCK_ABORT);
}
#endif