diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c index 7187af929e4..ae1c9796371 100644 --- a/drivers/note/note_driver.c +++ b/drivers/note/note_driver.c @@ -133,8 +133,8 @@ struct note_startalloc_s #if CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0 struct note_taskname_info_s { + pid_t pid; uint8_t size; - uint8_t pid[2]; char name[1]; }; @@ -190,28 +190,6 @@ static spinlock_t g_note_lock; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: sched_note_flatten - * - * Description: - * Copy the data in the little endian layout - * - ****************************************************************************/ - -static inline void sched_note_flatten(FAR uint8_t *dst, - FAR void *src, size_t len) -{ -#ifdef CONFIG_ENDIAN_BIG - FAR uint8_t *end = (FAR uint8_t *)src + len - 1; - while (len-- > 0) - { - *dst++ = *end--; - } -#else - memcpy(dst, src, len); -#endif -} - /**************************************************************************** * Name: note_common * @@ -247,7 +225,7 @@ static void note_common(FAR struct tcb_s *tcb, #ifdef CONFIG_SMP note->nc_cpu = 0; #endif - memset(note->nc_pid, 0, sizeof(tcb->pid)); + note->nc_pid = 0; } else { @@ -255,11 +233,11 @@ static void note_common(FAR struct tcb_s *tcb, #ifdef CONFIG_SMP note->nc_cpu = tcb->cpu; #endif - sched_note_flatten(note->nc_pid, &tcb->pid, sizeof(tcb->pid)); + note->nc_pid = tcb->pid; } - sched_note_flatten(note->nc_systime_nsec, &ts.tv_nsec, sizeof(ts.tv_nsec)); - sched_note_flatten(note->nc_systime_sec, &ts.tv_sec, sizeof(ts.tv_sec)); + note->nc_systime_sec = ts.tv_sec; + note->nc_systime_nsec = ts.tv_nsec; } /**************************************************************************** @@ -503,7 +481,7 @@ static FAR struct note_taskname_info_s *note_find_taskname(pid_t pid) { ti = (FAR struct note_taskname_info_s *) &g_note_taskname.buffer[n]; - if (ti->pid[0] + (ti->pid[1] << 8) == pid) + if (ti->pid == pid) { return ti; } @@ -580,8 +558,7 @@ static void note_record_taskname(pid_t pid, FAR const char *name) ti = (FAR struct note_taskname_info_s *) &g_note_taskname.buffer[g_note_taskname.head]; ti->size = skiplen; - ti->pid[0] = 0xff; - ti->pid[1] = 0xff; + ti->pid = INVALID_PROCESS_ID; ti->name[0] = '\0'; /* Move to the begin of circle buffer */ @@ -592,8 +569,7 @@ static void note_record_taskname(pid_t pid, FAR const char *name) ti = (FAR struct note_taskname_info_s *) &g_note_taskname.buffer[g_note_taskname.head]; ti->size = tilen; - ti->pid[0] = pid & 0xff; - ti->pid[1] = (pid >> 8) & 0xff; + ti->pid = pid; strlcpy(ti->name, name, namelen + 1); g_note_taskname.head += tilen; } @@ -1067,8 +1043,7 @@ void sched_note_premption(FAR struct tcb_s *tcb, bool locked) formatted = true; note_common(tcb, ¬e.npr_cmn, sizeof(struct note_preempt_s), locked ? NOTE_PREEMPT_LOCK : NOTE_PREEMPT_UNLOCK); - sched_note_flatten(note.npr_count, &tcb->lockcount, - sizeof(tcb->lockcount)); + note.npr_count = tcb->lockcount; } /* Add the note to circular buffer */ @@ -1110,8 +1085,7 @@ void sched_note_csection(FAR struct tcb_s *tcb, bool enter) note_common(tcb, ¬e.ncs_cmn, sizeof(struct note_csection_s), enter ? NOTE_CSECTION_ENTER : NOTE_CSECTION_LEAVE); #ifdef CONFIG_SMP - sched_note_flatten(note.ncs_count, &tcb->irqcount, - sizeof(tcb->irqcount)); + note.ncs_count = tcb->irqcount; #endif } @@ -1170,7 +1144,7 @@ void sched_note_spinlock(FAR struct tcb_s *tcb, formatted = true; note_common(tcb, ¬e.nsp_cmn, sizeof(struct note_spinlock_s), type); - sched_note_flatten(note.nsp_spinlock, &spinlock, sizeof(spinlock)); + note.nsp_spinlock = (uintptr_t)spinlock; note.nsp_value = *(FAR uint8_t *)spinlock; } @@ -1189,7 +1163,6 @@ void sched_note_syscall_enter(int nr, int argc, ...) bool formatted = false; FAR struct tcb_s *tcb = this_task(); unsigned int length; - FAR uint8_t *args; uintptr_t arg; va_list ap; int i; @@ -1238,12 +1211,10 @@ void sched_note_syscall_enter(int nr, int argc, ...) /* If needed, retrieve the given syscall arguments */ - args = note.nsc_args; for (i = 0; i < argc; i++) { arg = (uintptr_t)va_arg(copy, uintptr_t); - sched_note_flatten(args, &arg, sizeof(arg)); - args += sizeof(uintptr_t); + note.nsc_args[i] = arg; } } @@ -1291,8 +1262,7 @@ void sched_note_syscall_leave(int nr, uintptr_t result) NOTE_SYSCALL_LEAVE); DEBUGASSERT(nr <= UCHAR_MAX); note.nsc_nr = nr; - - sched_note_flatten(note.nsc_result, &result, sizeof(result)); + note.nsc_result = result; } /* Add the note to circular buffer */ @@ -1384,9 +1354,9 @@ void sched_note_string_ip(uint32_t tag, uintptr_t ip, FAR const char *buf) } note_common(tcb, ¬e->nst_cmn, length, NOTE_DUMP_STRING); - sched_note_flatten(note->nst_ip, &ip, sizeof(uintptr_t)); memcpy(note->nst_data, buf, length - sizeof(struct note_string_s)); data[length - 1] = '\0'; + note->nst_ip = ip; } /* Add the note to circular buffer */ @@ -1435,9 +1405,9 @@ void sched_note_event_ip(uint32_t tag, uintptr_t ip, uint8_t event, } note_common(tcb, ¬e->nbi_cmn, length, event); - sched_note_flatten(note->nbi_ip, &ip, sizeof(uintptr_t)); memcpy(note->nbi_data, buf, length - sizeof(struct note_binary_s) + 1); + note->nbi_ip = ip; } /* Add the note to circular buffer */ @@ -1490,8 +1460,7 @@ void sched_note_vprintf_ip(uint32_t tag, uintptr_t ip, } note_common(tcb, ¬e->nst_cmn, length, NOTE_DUMP_STRING); - - sched_note_flatten(note->nst_ip, &ip, sizeof(uintptr_t)); + note->nst_ip = ip; } /* Add the note to circular buffer */ @@ -1707,9 +1676,8 @@ void sched_note_vbprintf_ip(uint32_t tag, uintptr_t ip, } length = SIZEOF_NOTE_BINARY(next); - note_common(tcb, ¬e->nbi_cmn, length, NOTE_DUMP_BINARY); - sched_note_flatten(note->nbi_ip, &ip, sizeof(uintptr_t)); + note->nbi_ip = ip; } /* Add the note to circular buffer */ diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c index e3660672005..fa7ca7fdf3b 100644 --- a/drivers/note/noteram_driver.c +++ b/drivers/note/noteram_driver.c @@ -598,24 +598,6 @@ static void noteram_add(FAR struct note_driver_s *driver, spin_unlock_irqrestore_wo_note(&drv->lock, flags); } -/**************************************************************************** - * Name: noteram_dump_unflatten - ****************************************************************************/ - -static void noteram_dump_unflatten(FAR void *dst, FAR uint8_t *src, - size_t len) -{ -#ifdef CONFIG_ENDIAN_BIG - FAR uint8_t *end = (FAR uint8_t *)dst + len - 1; - while (len-- > 0) - { - *end-- = *src++; - } -#else - memcpy(dst, src, len); -#endif -} - /**************************************************************************** * Name: noteram_dump_init_context ****************************************************************************/ @@ -664,20 +646,17 @@ static int noteram_dump_header(FAR struct lib_outstream_s *s, FAR struct noteram_dump_context_s *ctx) { pid_t pid; - uint32_t nsec; - uint32_t sec; + uint32_t nsec = note->nc_systime_nsec; + uint32_t sec = note->nc_systime_sec; int ret; - noteram_dump_unflatten(&nsec, note->nc_systime_nsec, sizeof(nsec)); - noteram_dump_unflatten(&sec, note->nc_systime_sec, sizeof(sec)); + pid = note->nc_pid; #ifdef CONFIG_SMP int cpu = note->nc_cpu; #else int cpu = 0; #endif - noteram_dump_unflatten(&pid, note->nc_pid, sizeof(pid)); - ret = lib_sprintf(s, "%8s-%-3u [%d] %3" PRIu32 ".%09" PRIu32 ": ", get_task_name(pid), get_pid(pid), cpu, sec, nsec); return ret; @@ -745,7 +724,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, #endif cctx = &ctx->cpu[cpu]; - noteram_dump_unflatten(&pid, note->nc_pid, sizeof(pid)); + pid = note->nc_pid; if (cctx->current_pid < 0) { @@ -844,7 +823,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, for (i = j = 0; i < nsc->nsc_argc; i++) { - noteram_dump_unflatten(&arg, nsc->nsc_args, sizeof(arg)); + arg = nsc->nsc_args[i]; if (i == 0) { ret += lib_sprintf(s, "arg%d: 0x%" PRIxPTR, i, arg); @@ -872,7 +851,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, } ret += noteram_dump_header(s, note, ctx); - noteram_dump_unflatten(&result, nsc->nsc_result, sizeof(result)); + result = nsc->nsc_result; ret += lib_sprintf(s, "sys_%s -> 0x%" PRIxPTR "\n", g_funcnames[nsc->nsc_nr - CONFIG_SYS_RESERVED], result); @@ -939,7 +918,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, struct note_preempt_s *npr; int16_t count; npr = (FAR struct note_preempt_s *)p; - noteram_dump_unflatten(&count, npr->npr_count, sizeof(count)); + count = npr->npr_count; ret += noteram_dump_header(s, &npr->npr_cmn, ctx); ret += lib_sprintf(s, "tracing_mark_write: " "%c|%d|sched_lock:%d\n", @@ -957,7 +936,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, nst = (FAR struct note_string_s *)p; ret += noteram_dump_header(s, note, ctx); - noteram_dump_unflatten(&ip, nst->nst_ip, sizeof(ip)); + ip = nst->nst_ip; if (nst->nst_data[1] == '\0' && (nst->nst_data[0] == 'B' || nst->nst_data[0] == 'E')) @@ -980,7 +959,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, int len = note->nc_length - sizeof(struct note_binary_s); uintptr_t ip; - noteram_dump_unflatten(&ip, nbi->nbi_ip, sizeof(ip)); + ip = nbi->nbi_ip; ret += noteram_dump_header(s, &nbi->nbi_cmn, ctx); if (len > 0) { @@ -1023,8 +1002,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, nbi = (FAR struct note_binary_s *)p; ret += noteram_dump_header(s, note, ctx); count = note->nc_length - sizeof(struct note_binary_s) + 1; - - noteram_dump_unflatten(&ip, nbi->nbi_ip, sizeof(ip)); + ip = nbi->nbi_ip; ret += lib_sprintf(s, "tracing_mark_write: %pS: count=%u", (FAR void *)ip, count); diff --git a/include/nuttx/sched_note.h b/include/nuttx/sched_note.h index 2ba0d48920b..eb0ce3d8040 100644 --- a/include/nuttx/sched_note.h +++ b/include/nuttx/sched_note.h @@ -226,15 +226,15 @@ struct note_common_s #ifdef CONFIG_SMP uint8_t nc_cpu; /* CPU thread/task running on */ #endif - uint8_t nc_pid[sizeof(pid_t)]; /* ID of the thread/task */ + pid_t nc_pid; /* ID of the thread/task */ /* Time when note was buffered (sec) */ - uint8_t nc_systime_sec[sizeof(time_t)]; + time_t nc_systime_sec; /* Time when note was buffered (nsec) */ - uint8_t nc_systime_nsec[sizeof(long)]; + long nc_systime_nsec; }; /* This is the specific form of the NOTE_START note */ @@ -319,7 +319,7 @@ struct note_cpu_resumed_s struct note_preempt_s { struct note_common_s npr_cmn; /* Common note parameters */ - uint8_t npr_count[2]; /* Count of nested locks */ + uint16_t npr_count; /* Count of nested locks */ }; /* This is the specific form of the NOTE_CSECTION_ENTER/LEAVE note */ @@ -328,7 +328,7 @@ struct note_csection_s { struct note_common_s ncs_cmn; /* Common note parameters */ #ifdef CONFIG_SMP - uint8_t ncs_count[2]; /* Count of nested csections */ + uint16_t ncs_count; /* Count of nested csections */ #endif }; @@ -338,9 +338,9 @@ struct note_csection_s struct note_spinlock_s { - struct note_common_s nsp_cmn; /* Common note parameters */ - uint8_t nsp_spinlock[sizeof(uintptr_t)]; /* Address of spinlock */ - uint8_t nsp_value; /* Value of spinlock */ + struct note_common_s nsp_cmn; /* Common note parameters */ + uintptr_t nsp_spinlock; /* Address of spinlock */ + uint8_t nsp_value; /* Value of spinlock */ }; /* This is the specific form of the NOTE_SYSCALL_ENTER/LEAVE notes */ @@ -352,17 +352,17 @@ struct note_spinlock_s struct note_syscall_enter_s { - struct note_common_s nsc_cmn; /* Common note parameters */ - uint8_t nsc_nr; /* System call number */ - uint8_t nsc_argc; /* Number of system call arguments */ - uint8_t nsc_args[sizeof(uintptr_t) * MAX_SYSCALL_ARGS]; /* System call arguments */ + struct note_common_s nsc_cmn; /* Common note parameters */ + uint8_t nsc_nr; /* System call number */ + uint8_t nsc_argc; /* Number of system call arguments */ + uintptr_t nsc_args[MAX_SYSCALL_ARGS]; /* System call arguments */ }; struct note_syscall_leave_s { - struct note_common_s nsc_cmn; /* Common note parameters */ - uint8_t nsc_nr; /* System call number */ - uint8_t nsc_result[sizeof(uintptr_t)]; /* Result of the system call */ + struct note_common_s nsc_cmn; /* Common note parameters */ + uint8_t nsc_nr; /* System call number */ + uintptr_t nsc_result; /* Result of the system call */ }; /* This is the specific form of the NOTE_IRQ_ENTER/LEAVE notes */ @@ -377,7 +377,7 @@ struct note_irqhandler_s struct note_string_s { struct note_common_s nst_cmn; /* Common note parameters */ - uint8_t nst_ip[sizeof(uintptr_t)]; /* Instruction pointer called from */ + uintptr_t nst_ip; /* Instruction pointer called from */ char nst_data[1]; /* String data terminated by '\0' */ }; @@ -387,7 +387,7 @@ struct note_string_s struct note_binary_s { struct note_common_s nbi_cmn; /* Common note parameters */ - uint8_t nbi_ip[sizeof(uintptr_t)]; /* Instruction pointer called from */ + uintptr_t nbi_ip; /* Instruction pointer called from */ uint8_t nbi_data[1]; /* Binary data */ };