printf: Convert %l to %ll

In order to make our printf more standard, utilize %ll for long long
arguments, rather than %l. This does cost a little bit in flash space
for that extra l in a couple of places, but enables us to turn on
compile-time printf format checking.

For this commit only, the semantics are such that both %l and %ll
take 64-bit arguments. In the next commit, %l goes to its correct
behavior of taking a sizeof(long) argument.

BUG=chromium:984041
TEST=make -j buildall
BRANCH=none

Cq-Depend:chrome-internal:1863686,chrome-internal:1860161,chrome-internal:1914029
Change-Id: I18081b55a8dbf5ef8ec15fc499ca75e59d31da58
Signed-off-by: Evan Green <evgreen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1819652
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
This commit is contained in:
Evan Green 2019-09-23 13:07:06 -07:00 committed by Commit Bot
parent 3564b23531
commit 0c2d7b648e
21 changed files with 74 additions and 50 deletions

View File

@ -606,8 +606,8 @@ static void print_stats(const char *name, const struct pm_stat *stat)
{
if (stat->count)
ccprintf(" %s:\n"
" counts: %lu\n"
" time: %.6lus\n",
" counts: %llu\n"
" time: %.6llus\n",
name, stat->count, stat->total_time_us);
}
@ -619,7 +619,7 @@ static int command_idle_stats(int argc, char **argv)
struct ish_aon_share *aon_share = pm_ctx.aon_share;
ccprintf("Aontask exists: %s\n", pm_ctx.aon_valid ? "Yes" : "No");
ccprintf("Total time on: %.6lus\n", get_time().val);
ccprintf("Total time on: %.6llus\n", get_time().val);
ccprintf("Idle sleep:\n");
print_stats("D0i0", &pm_stats.d0i0);

View File

@ -603,9 +603,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that doze: %d\n", idle_doze_cnt);
ccprintf("Num idle calls that sleep: %d\n", idle_sleep_cnt);
ccprintf("Total Time spent in sleep(sec): %.6ld(s)\n",
ccprintf("Total Time spent in sleep(sec): %.6lld(s)\n",
total_idle_sleep_time_us);
ccprintf("Total time on: %.6lds\n\n", ts.val);
ccprintf("Total time on: %.6llds\n\n", ts.val);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(idlestats, command_idle_stats,

View File

@ -692,9 +692,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that sleep: %d\n", idle_sleep_cnt);
ccprintf("Num idle calls that deep-sleep: %d\n", idle_dsleep_cnt);
ccprintf("Time spent in deep-sleep: %.6lds\n",
ccprintf("Time spent in deep-sleep: %.6llds\n",
idle_dsleep_time_us);
ccprintf("Total time on: %.6lds\n", ts.val);
ccprintf("Total time on: %.6llds\n", ts.val);
ccprintf("Deep-sleep closest to wake deadline: %dus\n",
dsleep_recovery_margin_us);

View File

@ -697,9 +697,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that deep-sleep: %d\n",
idle_dsleep_cnt);
ccprintf("Total Time spent in deep-sleep(sec): %.6ld(s)\n",
ccprintf("Total Time spent in deep-sleep(sec): %.6lld(s)\n",
total_idle_dsleep_time_us);
ccprintf("Total time on: %.6lds\n\n",
ccprintf("Total time on: %.6llds\n\n",
ts.val);
#ifdef CONFIG_MCHP_DEEP_SLP_DEBUG

View File

@ -426,9 +426,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that sleep: %d\n", idle_sleep_cnt);
ccprintf("Num idle calls that deep-sleep: %d\n", idle_dsleep_cnt);
ccprintf("Total Time spent in deep-sleep(sec): %.6ld(s)\n",
ccprintf("Total Time spent in deep-sleep(sec): %.6lld(s)\n",
total_idle_dsleep_time_us);
ccprintf("Total time on: %.6lds\n\n", ts.val);
ccprintf("Total time on: %.6llds\n\n", ts.val);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(idlestats, command_idle_stats,

View File

@ -197,8 +197,8 @@ static int command_cacheinfo(int argc, char **argv)
uint64_t access = ((uint64_t)SCP_CACHE_CCNT0U(c) << 32) |
SCP_CACHE_CCNT0L(c);
ccprintf("%ccache hit count: %lu\n", cache_name[c], hit);
ccprintf("%ccache access count: %lu\n", cache_name[c], access);
ccprintf("%ccache hit count: %llu\n", cache_name[c], hit);
ccprintf("%ccache access count: %llu\n", cache_name[c], access);
}
return EC_SUCCESS;

View File

@ -439,9 +439,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that sleep: %d\n", idle_sleep_cnt);
ccprintf("Num idle calls that deep-sleep: %d\n", idle_dsleep_cnt);
ccprintf("Time spent in deep-sleep: %.6lds\n",
ccprintf("Time spent in deep-sleep: %.6llds\n",
idle_dsleep_time_us);
ccprintf("Total time on: %.6lds\n", ts.val);
ccprintf("Total time on: %.6llds\n", ts.val);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(idlestats, command_idle_stats,

View File

@ -492,9 +492,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that sleep: %d\n", idle_sleep_cnt);
ccprintf("Num idle calls that deep-sleep: %d\n", idle_dsleep_cnt);
ccprintf("Time spent in deep-sleep: %.6lds\n",
ccprintf("Time spent in deep-sleep: %.6llds\n",
idle_dsleep_time_us);
ccprintf("Total time on: %.6lds\n", ts.val);
ccprintf("Total time on: %.6llds\n", ts.val);
ccprintf("Deep-sleep closest to wake deadline: %dus\n",
dsleep_recovery_margin_us);

View File

@ -369,9 +369,9 @@ static int command_idle_stats(int argc, char **argv)
ccprintf("Num idle calls that sleep: %d\n", idle_sleep_cnt);
ccprintf("Num idle calls that deep-sleep: %d\n", idle_dsleep_cnt);
ccprintf("Time spent in deep-sleep: %.6lds\n",
ccprintf("Time spent in deep-sleep: %.6llds\n",
idle_dsleep_time_us);
ccprintf("Total time on: %.6lds\n", ts.val);
ccprintf("Total time on: %.6llds\n", ts.val);
ccprintf("Deep-sleep closest to wake deadline: %dus\n",
dsleep_recovery_margin_us);

View File

@ -644,7 +644,7 @@ void print_connection_state(void)
CPRINTF("interval(hex): %x\n", conn_params.interval);
CPRINTF("latency(hex): %x\n", conn_params.latency);
CPRINTF("timeout(hex): %x\n", conn_params.timeout);
CPRINTF("channel_map(hex): %lx\n", conn_params.channel_map);
CPRINTF("channel_map(hex): %llx\n", conn_params.channel_map);
CPRINTF("hop(hex): %x\n", conn_params.hop_increment);
CPRINTF("SCA(hex): %x\n", conn_params.sleep_clock_accuracy);
CPRINTF("transmitWindowOffset: %d\n", conn_params.transmitWindowOffset);

View File

@ -142,7 +142,7 @@ static void physical_detect_check_press(void)
mutex_lock(&pp_mutex);
CPRINTS("PP press dt=%.6ld", dt);
CPRINTS("PP press dt=%.6lld", dt);
/* If we no longer care about presses, ignore them */
if (!pp_detect_in_progress())

View File

@ -226,10 +226,30 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
/*
* Handle length:
* %l - long
* %ll - long long
* %z - size_t
*/
if (c == 'l') {
/*
* For just this commit, allow both %l and %ll
* to be 64-bit. This is obviously wrong, but
* enables this change to be cherry-picked
* into firmware branches without changing
* semantics for any existing printf calls.
* This is removed in the subsequent commit on
* master.
*/
flags |= PF_64BIT;
if (sizeof(long) == sizeof(uint64_t))
flags |= PF_64BIT;
c = *format++;
if (c == 'l') {
flags |= PF_64BIT;
c = *format++;
}
} else if (c == 'z') {
if (sizeof(size_t) == sizeof(uint64_t))
flags |= PF_64BIT;

View File

@ -236,15 +236,15 @@ void timer_print_info(void)
__hw_clock_event_get();
int tskid;
ccprintf("Time: 0x%016lx us, %11.6ld s\n"
"Deadline: 0x%016lx -> %11.6ld s from now\n"
ccprintf("Time: 0x%016llx us, %11.6lld s\n"
"Deadline: 0x%016llx -> %11.6lld s from now\n"
"Active timers:\n",
t.val, t.val, deadline, deadline - t.val);
cflush();
for (tskid = 0; tskid < TASK_ID_COUNT; tskid++) {
if (timer_running & BIT(tskid)) {
ccprintf(" Tsk %2d 0x%016lx -> %11.6ld\n", tskid,
ccprintf(" Tsk %2d 0x%016llx -> %11.6lld\n", tskid,
timer_deadline[tskid].val,
timer_deadline[tskid].val - t.val);
cflush();
@ -342,7 +342,7 @@ static int command_force_time(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM2;
ccprintf("Time: 0x%016lx = %.6ld s\n", new.val, new.val);
ccprintf("Time: 0x%016llx = %.6lld s\n", new.val, new.val);
force_time(new);
return EC_SUCCESS;
@ -356,7 +356,7 @@ DECLARE_CONSOLE_COMMAND(forcetime, command_force_time,
static int command_get_time(int argc, char **argv)
{
timestamp_t ts = get_time();
ccprintf("Time: 0x%016lx = %.6ld s\n", ts.val, ts.val);
ccprintf("Time: 0x%016llx = %.6lld s\n", ts.val, ts.val);
return EC_SUCCESS;
}

View File

@ -933,7 +933,7 @@ void task_print_list(void)
sp++)
stackused -= sizeof(uint32_t);
ccprintf("%4d %c %-16s %08x %11.6ld %3d/%3d\n", i, is_ready,
ccprintf("%4d %c %-16s %08x %11.6lld %3d/%3d\n", i, is_ready,
task_names[i], tasks[i].events, tasks[i].runtime,
stackused, tasks_init[i].stack_size);
cflush();
@ -961,10 +961,10 @@ int command_task_info(int argc, char **argv)
ccprintf("Service calls: %11d\n", svc_calls);
ccprintf("Total exceptions: %11d\n", total + svc_calls);
ccprintf("Task switches: %11d\n", task_switches);
ccprintf("Task switching started: %11.6ld s\n", task_start_time);
ccprintf("Time in tasks: %11.6ld s\n",
ccprintf("Task switching started: %11.6lld s\n", task_start_time);
ccprintf("Time in tasks: %11.6lld s\n",
get_time().val - task_start_time);
ccprintf("Time in exceptions: %11.6ld s\n", exc_total_time);
ccprintf("Time in exceptions: %11.6lld s\n", exc_total_time);
#endif
return EC_SUCCESS;

View File

@ -566,7 +566,7 @@ void task_print_list(void)
sp++)
stackused -= sizeof(uint32_t);
ccprintf("%4d %c %-16s %08x %11.6ld %3d/%3d\n", i, is_ready,
ccprintf("%4d %c %-16s %08x %11.6lld %3d/%3d\n", i, is_ready,
task_names[i], tasks[i].events, tasks[i].runtime,
stackused, tasks_init[i].stack_size);
cflush();
@ -594,10 +594,10 @@ int command_task_info(int argc, char **argv)
ccprintf("Service calls: %11d\n", svc_calls);
ccprintf("Total exceptions: %11d\n", total + svc_calls);
ccprintf("Task switches: %11d\n", task_switches);
ccprintf("Task switching started: %11.6ld s\n", task_start_time);
ccprintf("Time in tasks: %11.6ld s\n",
ccprintf("Task switching started: %11.6lld s\n", task_start_time);
ccprintf("Time in tasks: %11.6lld s\n",
get_time().val - task_start_time);
ccprintf("Time in exceptions: %11.6ld s\n", exc_total_time);
ccprintf("Time in exceptions: %11.6lld s\n", exc_total_time);
#endif
return EC_SUCCESS;

View File

@ -528,12 +528,12 @@ void task_print_list(void)
if (IS_ENABLED(CONFIG_FPU)) {
char use_fpu = tasks[i].use_fpu ? 'Y' : 'N';
ccprintf("%4d %c %-16s %08x %11.6ld %3d/%3d %c\n",
ccprintf("%4d %c %-16s %08x %11.6lld %3d/%3d %c\n",
i, is_ready, task_get_name(i), tasks[i].events,
tasks[i].runtime, stackused,
tasks_init[i].stack_size, use_fpu);
} else {
ccprintf("%4d %c %-16s %08x %11.6ld %3d/%3d\n",
ccprintf("%4d %c %-16s %08x %11.6lld %3d/%3d\n",
i, is_ready, task_get_name(i), tasks[i].events,
tasks[i].runtime, stackused,
tasks_init[i].stack_size);
@ -562,11 +562,12 @@ int command_task_info(int argc, char **argv)
ccprintf("Service calls: %11d\n", svc_calls);
ccprintf("Total exceptions: %11d\n", total + svc_calls);
ccprintf("Task switches: %11d\n", task_switches);
ccprintf("Task switching started: %11.6ld s\n",
ccprintf("Task switching started: %11.6lld s\n",
task_start_time);
ccprintf("Time in tasks: %11.6ld s\n",
ccprintf("Time in tasks: %11.6lld s\n",
get_time().val - task_start_time);
ccprintf("Time in exceptions: %11.6ld s\n", exc_total_time);
ccprintf("Time in exceptions: %11.6lld s\n",
exc_total_time);
}
return EC_SUCCESS;

View File

@ -696,7 +696,7 @@ void task_print_list(void)
sp++)
stackused -= sizeof(uint32_t);
ccprintf("%4d %c %-16s %08x %11.6ld %3d/%3d\n", i, is_ready,
ccprintf("%4d %c %-16s %08x %11.6lld %3d/%3d\n", i, is_ready,
task_names[i], tasks[i].events, tasks[i].runtime,
stackused, tasks_init[i].stack_size);
cflush();
@ -725,10 +725,10 @@ int command_task_info(int argc, char **argv)
ccprintf("Service calls: %11d\n", svc_calls);
ccprintf("Total exceptions: %11d\n", total + svc_calls);
ccprintf("Task switches: %11d\n", task_switches);
ccprintf("Task switching started: %11.6ld s\n", task_start_time);
ccprintf("Time in tasks: %11.6ld s\n",
ccprintf("Task switching started: %11.6lld s\n", task_start_time);
ccprintf("Time in tasks: %11.6lld s\n",
get_time().val - task_start_time);
ccprintf("Time in exceptions: %11.6ld s\n", exc_total_time);
ccprintf("Time in exceptions: %11.6lld s\n", exc_total_time);
#endif
return EC_SUCCESS;

View File

@ -91,14 +91,14 @@ static enum cts_rc test_ticks(void)
error_pct = (interval - HOOK_TICK_INTERVAL) * 100 /
HOOK_TICK_INTERVAL;
if (error_pct < -10 || 10 < error_pct) {
CPRINTS("tick error=%d%% interval=%ld", error_pct, interval);
CPRINTS("tick error=%d%% interval=%lld", error_pct, interval);
return CTS_RC_FAILURE;
}
interval = second_time[1].val - second_time[0].val;
error_pct = (interval - SECOND) * 100 / SECOND;
if (error_pct < -10 || 10 < error_pct) {
CPRINTS("second error=%d%% interval=%ld", error_pct, interval);
CPRINTS("second error=%d%% interval=%lld", error_pct, interval);
return CTS_RC_FAILURE;
}

View File

@ -544,8 +544,10 @@ static int st_tp_read_system_info(int reload)
ST_TP_SHOW(chip0_ver);
ST_TP_SHOW(scr_tx_len);
ST_TP_SHOW(scr_rx_len);
ST_TP_SHOW(release_info);
#define ST_TP_SHOW64(attr) CPRINTS(#attr ": %04llx", system_info.attr)
ST_TP_SHOW64(release_info);
#undef ST_TP_SHOW
#undef ST_TP_SHOW64
return ret;
}
@ -1753,7 +1755,7 @@ static int st_tp_usb_set_interface(usb_uint alternate_setting,
if (alternate_setting == 1) {
if ((system_info.release_info & 0xFF) <
ST_TP_MIN_HEATMAP_VERSION) {
CPRINTS("release version %04x doesn't support heatmap",
CPRINTS("release version %04llx doesn't support heatmap",
system_info.release_info);
/* Heatmap mode is not supported in this version. */
return -1;

View File

@ -35,8 +35,9 @@
* useful for printing times, voltages, and currents.
*
* Length may be:
* - 'z' = integer is sizeof(size_t)
* - 'l' = integer is 64-bit instead of native 32-bit
* - 'l' = integer is 64-bit instead of native 32-bit
* - 'll' = integer is 64-bit
* - 'z' = integer is sizeof(size_t)
*
* Type may be:
* - 'c' - character

View File

@ -639,7 +639,7 @@ static void siglog_deferred(void)
for (i = 0; i < siglog_entries; i++) {
if (i)
tdiff.val = siglog[i].time.val - siglog[i-1].time.val;
CPRINTF(" %.6ld +%.6ld %s => %d\n",
CPRINTF(" %.6lld +%.6lld %s => %d\n",
siglog[i].time.val, tdiff.val,
power_signal_get_name(siglog[i].signal),
siglog[i].level);