You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/12/16 14:01:19 UTC
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7900: drivers/note: move taskname related functions to note_taskname.c
xiaoxiang781216 commented on code in PR #7900:
URL: https://github.com/apache/nuttx/pull/7900#discussion_r1050786045
##########
drivers/note/note_driver.c:
##########
@@ -1261,3 +1315,147 @@ void sched_note_filter_irq(FAR struct note_filter_irq_s *oldf,
#endif
#endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * 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
+ *
+ ****************************************************************************/
+
+void note_record_taskname(pid_t pid, FAR const char *name)
+{
+ FAR struct note_taskname_info_s *ti;
+ size_t tilen;
+ size_t namelen;
+
+ namelen = strlen(name);
+ DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
+ tilen = sizeof(struct note_taskname_info_s) + namelen;
+ DEBUGASSERT(tilen <= UCHAR_MAX);
+
+ if (g_note_taskname.buffer_used + tilen >
+ CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE)
+ {
+ /* No space in the buffer - ignored */
+
+ return;
+ }
+
+ ti = (FAR struct note_taskname_info_s *)
+ &g_note_taskname.buffer[g_note_taskname.buffer_used];
+ ti->size = tilen;
+ ti->pid[0] = pid & 0xff;
+ ti->pid[1] = (pid >> 8) & 0xff;
+ strlcpy(ti->name, name, namelen + 1);
+ g_note_taskname.buffer_used += tilen;
+}
+
+/****************************************************************************
+ * Name: note_remove_taskname
+ *
+ * Description:
+ * Remove the task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ * PID - Task ID
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void note_remove_taskname(pid_t pid)
+{
+ FAR struct note_taskname_info_s *ti;
+ size_t tilen;
+ FAR char *src;
+ int sindex;
+
+ ti = note_find_taskname(pid);
+ if (ti == NULL)
+ {
+ return;
+ }
+
+ tilen = ti->size;
+ src = (FAR char *)ti + tilen;
+ sindex = src - g_note_taskname.buffer;
+
+ memcpy(ti, src, g_note_taskname.buffer_used - sindex);
+ g_note_taskname.buffer_used -= tilen;
+}
+
+/****************************************************************************
+ * Name: note_get_taskname
+ *
+ * Description:
+ * Get the task name string of the specified PID
+ *
+ * Input Parameters:
+ * PID - Task ID
+ *
+ * Returned Value:
+ * Pointer to the task name string
+ * If the corresponding name doesn't exist in the buffer, NULL is returned.
+ *
+ ****************************************************************************/
+
+FAR const char *note_get_taskname(pid_t pid)
+{
+ irqstate_t irq_mask;
+ FAR const char *ret = NULL;
+ FAR struct note_taskname_info_s *ti;
+ FAR struct tcb_s *tcb;
+
+ irq_mask = enter_critical_section();
+
+ ti = note_find_taskname(pid);
+ if (ti != NULL)
+ {
+ ret = ti->name;
+ }
+ else
+ {
+ tcb = nxsched_get_tcb(pid);
+ if (tcb != NULL)
+ {
+ note_record_taskname(pid, tcb->name);
+ ret = tcb->name;
+ }
+ }
+
+ leave_critical_section(irq_mask);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: note_clear_taskname
+ *
+ * Description:
+ * Reset the buffer of note_taskname_s
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void note_clear_taskname(void)
Review Comment:
why need
##########
drivers/note/note_driver.c:
##########
@@ -1261,3 +1315,147 @@ void sched_note_filter_irq(FAR struct note_filter_irq_s *oldf,
#endif
#endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * 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
+ *
+ ****************************************************************************/
+
+void note_record_taskname(pid_t pid, FAR const char *name)
Review Comment:
move to private section
##########
drivers/note/noteram_driver.c:
##########
@@ -442,7 +260,7 @@ static void noteram_remove(void)
nc_pid[1] = g_noteram_info.ni_buffer[noteram_next(tail, 4)];
#endif
- noteram_remove_taskname(nc_pid[0] + (nc_pid[1] << 8));
+ note_remove_taskname(nc_pid[0] + (nc_pid[1] << 8));
Review Comment:
ditto, remove
##########
drivers/note/noteram_driver.c:
##########
@@ -820,9 +638,9 @@ void sched_note_add(FAR const void *note, size_t notelen)
note_st = (FAR struct note_start_s *)note;
if (note_st->nst_cmn.nc_type == NOTE_START)
{
- noteram_record_taskname(note_st->nst_cmn.nc_pid[0] +
- (note_st->nst_cmn.nc_pid[1] << 8),
- note_st->nst_name);
+ note_record_taskname(note_st->nst_cmn.nc_pid[0] +
Review Comment:
move the record to note_driver.c
##########
drivers/note/noteram_driver.c:
##########
@@ -306,7 +124,7 @@ static void noteram_buffer_clear(void)
}
#if CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE > 0
- g_noteram_taskname.buffer_used = 0;
+ note_clear_taskname();
Review Comment:
Task name array is a resource shared by all note driver instance, it isn't good to clear it when one note driver instance clears its internal buffer.
##########
drivers/note/note_driver.c:
##########
@@ -1261,3 +1315,147 @@ void sched_note_filter_irq(FAR struct note_filter_irq_s *oldf,
#endif
#endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
+#if CONFIG_TASK_NAME_SIZE > 0
+
+/****************************************************************************
+ * 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
+ *
+ ****************************************************************************/
+
+void note_record_taskname(pid_t pid, FAR const char *name)
+{
+ FAR struct note_taskname_info_s *ti;
+ size_t tilen;
+ size_t namelen;
+
+ namelen = strlen(name);
+ DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
+ tilen = sizeof(struct note_taskname_info_s) + namelen;
+ DEBUGASSERT(tilen <= UCHAR_MAX);
+
+ if (g_note_taskname.buffer_used + tilen >
+ CONFIG_DRIVER_NOTERAM_TASKNAME_BUFSIZE)
+ {
+ /* No space in the buffer - ignored */
+
+ return;
+ }
+
+ ti = (FAR struct note_taskname_info_s *)
+ &g_note_taskname.buffer[g_note_taskname.buffer_used];
+ ti->size = tilen;
+ ti->pid[0] = pid & 0xff;
+ ti->pid[1] = (pid >> 8) & 0xff;
+ strlcpy(ti->name, name, namelen + 1);
+ g_note_taskname.buffer_used += tilen;
+}
+
+/****************************************************************************
+ * Name: note_remove_taskname
+ *
+ * Description:
+ * Remove the task name info corresponding to the specified PID
+ *
+ * Input Parameters:
+ * PID - Task ID
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void note_remove_taskname(pid_t pid)
Review Comment:
move to private section
--
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-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org