#define PLANCK_FEATURE_LOG 1 /* * The planck log line, EXACTLY as the 050 basis emits it: * * planck +79ms: PID 1 alive mem used=480K free=7.2M total=7.6M * * Milliseconds since PID 1 started. Nothing else. * * WHAT WAS HERE BEFORE, AND WHY IT IS GONE. This file used to sync to the kernel's printk clock: * write a marker to /dev/kmsg, read every buffered record back, parse the microsecond field out of * the "pri,seq,TS_USEC,flags;msg" prefix, and keep an offset so log lines shared the kernel's * timeline and printed as "[ 0.125851] planck-init: ...". Nice to read, and it cost open/read * loop + strchr + strtoll + a 2048-byte buffer in a PID 1 whose SIZE IS THE MEASUREMENT. The basis * this project is calibrated against does not have it, so neither do we -- the kernel already * stamps its own lines, and ours are relative to init, which is the number that matters here. * * No printf: see planck-fmt.c. One write(2) per line, so a line cannot interleave with printk. */ static long long planck_monotonic_ms(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (long long)ts.tv_sec * 1000LL + ts.tv_nsec / 1000000LL; } static void log_msg(const char *msg) { char lStrLine[MAX_LINE]; size_t lNumAt; /* * TIME SINCE BOOT, not since PID 1 started. CLOCK_MONOTONIC counts from boot on Linux, so this * is already the number wanted -- and it is the one the 050 basis printed ("planck +79ms:"). * An earlier version subtracted the first log's timestamp, which made every line read +0ms and * quietly threw away the only timing information the guest produces. That matters more once * printk is gone: the kernel's own timestamps disappear with it, and this becomes the ONLY * clock in the boot log. */ long long lNumMs = planck_monotonic_ms(); lNumAt = planck_cat(lStrLine, sizeof(lStrLine), 0, "planck +"); lNumAt = planck_catu(lStrLine, sizeof(lStrLine), lNumAt, (unsigned long long)lNumMs, 0, '0'); lNumAt = planck_cat(lStrLine, sizeof(lStrLine), lNumAt, "ms: "); lNumAt = planck_cat(lStrLine, sizeof(lStrLine), lNumAt, msg); lNumAt = planck_cat(lStrLine, sizeof(lStrLine), lNumAt, "\n"); write(2, lStrLine, lNumAt); }