Skip to content

logging: Use k_uptime_get_32 for high frequency system clock #14074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions subsys/logging/log_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,18 @@ void log_hexdump_sync(struct log_msg_ids src_level, const char *metadata,

static u32_t timestamp_get(void)
{
return k_cycle_get_32();
if (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) {
return k_uptime_get_32();
} else {
return k_cycle_get_32();
}
}

void log_core_init(void)
{
u32_t freq = (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000) ?
1000 : CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;

if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
log_msg_pool_init();
log_list_init(&list);
Expand All @@ -298,7 +305,7 @@ void log_core_init(void)

/* Set default timestamp. */
timestamp_func = timestamp_get;
log_output_timestamp_freq_set(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
log_output_timestamp_freq_set(freq);
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we actually make this a lot simpler by not requiring a separate static function at all:

if (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000)
        timestamp_func = k_uptime_get_32;
        log_output_timestamp_freq_set(MSEC_PER_SEC);
} else {
        timestamp_func = k_cycle_get_32;
        log_output_timestamp_freq_set(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
}

I'll leave it up to you to decide if it makes sense/is worth it.


/*
* Initialize aggregated runtime filter levels (no backends are
Expand Down