Skip to content

Conversation

mjy-acc
Copy link

@mjy-acc mjy-acc commented May 13, 2025

Note: Please adhere to Contributing Guidelines.

Summary

In the current code, the note module gets the time from perf_gettime(). When encountering instructions such as idle WFI, the CPU cycle will not continue to grow, resulting in time distortion.
Support note to obtain time from clock_gettime() to support scenarios when the CPUis sleeping.

Impact

The note module obtains time from perf_gettime() by default. Add configuration to support obtaining time from clock_gettime().

Testing

Test environment

  • CPU: X280 (RISCV)
  • Compiler: gcc
  • Target: When encountering WFI instruction CPU sleep, note can get the correct time

Signed-off-by: Majingyun <majingyun@lixiang.com>
@github-actions github-actions bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels May 13, 2025
@@ -794,7 +794,17 @@ static int noteram_dump_header(FAR struct lib_outstream_s *s,
pid_t pid;
int ret;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

Copy link
Contributor

@jerpelea jerpelea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a commit message

Comment on lines +40 to +46
bool "Note get time config"
default y
---help---
If this option is selected, then note get time from perf time

config NOTE_GET_CLOCK_TIME
bool "Note get time config"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use the same message ("Note get time config") in boot configs, it will confuse users. The description in the config should be clear to the users!

bool "Note get time config"
default y
---help---
If this option is selected, then note get time from perf time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve the "---help---", what is "perf time"? What difference to "clock time", etc. These are question that user need to know before enabling this option

@@ -36,6 +36,19 @@ config DRIVERS_NOTECTL
If this option is selected, the instrumentation filter control device
/dev/notectl is provided.

config NOTE_GET_PERF_TIME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change to choice

@@ -217,7 +217,17 @@ static void note_common(FAR struct tcb_s *tcb,
note->nc_pid = tcb->pid;
}

#if defined (CONFIG_NOTE_GET_PERF_TIME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined (CONFIG_NOTE_GET_PERF_TIME)
#if defined(CONFIG_NOTE_GET_PERF_TIME)

note->nc_systime = perf_gettime();

#elif defined (CONFIG_NOTE_GET_CLOCK_TIME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#elif defined (CONFIG_NOTE_GET_CLOCK_TIME)
#elif defined(CONFIG_NOTE_GET_CLOCK_TIME)

note->nc_systime = perf_gettime();

#elif defined (CONFIG_NOTE_GET_CLOCK_TIME)
struct timespec ts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't allow define the variable in the middle of function

clock_gettime(CLOCK_REALTIME, &ts);
note->nc_systime = ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;

#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -36,6 +36,19 @@ config DRIVERS_NOTECTL
If this option is selected, the instrumentation filter control device
/dev/notectl is provided.

config NOTE_GET_PERF_TIME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRIVERS_NOTE_PERF_TIME

---help---
If this option is selected, then note get time from perf time

config NOTE_GET_CLOCK_TIME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRIVERS_NOTE_CLOCK_TIME

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Drivers Drivers issues Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants