xiaoxiang781216 commented on code in PR #8525: URL: https://github.com/apache/nuttx/pull/8525#discussion_r1113755756
########## drivers/note/notesnap_driver.c: ########## @@ -0,0 +1,441 @@ +/**************************************************************************** + * drivers/note/notesnap_driver.c + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <inttypes.h> +#include <stdatomic.h> +#include <syslog.h> + +#include <nuttx/arch.h> +#include <nuttx/note/note_driver.h> +#include <nuttx/note/notesnap_driver.h> +#include <nuttx/panic_notifier.h> +#include <nuttx/sched.h> +#include <nuttx/sched_note.h> +#include <nuttx/streams.h> +#include <sched/sched.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define IS_ALIGNED(x) (((x) & ((x) - 1)) == 0) + +#if !IS_ALIGNED(CONFIG_DRIVERS_NOTESNAP_NBUFFERS) +#error "CONFIG_DRIVERS_NOTESNAP_NBUFFERS must be a power of 2" +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct notesnap_chunk_s +{ + uint8_t type; +#ifdef CONFIG_SMP + uint8_t cpu; +#endif + pid_t pid; +#ifdef CONFIG_DRIVERS_NOTESNAP_PERFCOUNT + uint32_t tick; +#else + struct timespec time; +#endif + uintptr_t args; +}; + +struct notesnap_s +{ + struct note_driver_s driver; + struct notifier_block nb; + size_t index; + bool dumping; + struct notesnap_chunk_s buffer[CONFIG_DRIVERS_NOTESNAP_NBUFFERS]; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void notesnap_start(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +static void notesnap_stop(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH +static void notesnap_suspend(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +static void notesnap_resume(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +#ifdef CONFIG_SMP +static void notesnap_cpu_start(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb, int cpu); +static void notesnap_cpu_started(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +static void notesnap_cpu_pause(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb, int cpu); +static void notesnap_cpu_paused(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +static void notesnap_cpu_resume(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb, int cpu); +static void notesnap_cpu_resumed(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb); +#endif +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION +static void notesnap_premption(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb, bool locked); +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION +static void notesnap_csection(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb, bool enter); +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS +static void notesnap_spinlock(FAR struct note_driver_s *drv, + FAR struct tcb_s *tcb, + FAR volatile void *spinlock, int type); +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL +static void notesnap_syscall_enter(FAR struct note_driver_s *drv, int nr, + int argc, va_list *ap); +static void notesnap_syscall_leave(FAR struct note_driver_s *drv, int nr, + uintptr_t result); +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER +static void notesnap_irqhandler(FAR struct note_driver_s *drv, int irq, + FAR void *handler, bool enter); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct note_driver_ops_s g_notesnap_ops = +{ + NULL, + notesnap_start, + notesnap_stop, +#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH + notesnap_suspend, + notesnap_resume, +# ifdef CONFIG_SMP + notesnap_cpu_start, + notesnap_cpu_started, + notesnap_cpu_pause, + notesnap_cpu_paused, + notesnap_cpu_resume, + notesnap_cpu_resumed, +# endif +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION + notesnap_premption, +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION + notesnap_csection, +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS + notesnap_spinlock, +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL + notesnap_syscall_enter, + notesnap_syscall_leave, +#endif +#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER + notesnap_irqhandler, +#endif +}; + +static struct notesnap_s g_notesnap = +{ + {&g_notesnap_ops} +}; + +static const FAR char *g_notesnap_type[] = +{ + "NOTE_START", + "NOTE_STOP", + "NOTE_SUSPEND", + "NOTE_RESUME", + "NOTE_CPU_START", + "NOTE_CPU_STARTED", + "NOTE_CPU_PAUSE", + "NOTE_CPU_PAUSED", + "NOTE_CPU_RESUME", + "NOTE_CPU_RESUMED", + "NOTE_PREEMPT_LOCK", + "NOTE_PREEMPT_UNLOCK", + "NOTE_CSECTION_ENTER", + "NOTE_CSECTION_LEAVE", + "NOTE_SPINLOCK_LOCK", + "NOTE_SPINLOCK_LOCKED", + "NOTE_SPINLOCK_UNLOCK", + "NOTE_SPINLOCK_ABORT", + "NOTE_SYSCALL_ENTER", + "NOTE_SYSCALL_LEAVE", + "NOTE_IRQ_ENTER", + "NOTE_IRQ_LEAVE", + "NOTE_DUMP_STRING", + "NOTE_DUMP_BINARY" +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: notesnap_common + ****************************************************************************/ + +static inline void notesnap_common(FAR struct tcb_s *tcb, uint8_t type, + uintptr_t args) +{ + if (g_notesnap.dumping) + { + return; + } + + /* Atomic operation, equivalent to g_notesnap.index++; */ + + size_t index = atomic_fetch_add(&g_notesnap.index, 1); + FAR struct notesnap_chunk_s *note = Review Comment: which part not C89 compatible? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org