Implement support for FN_RATE stat column into stat-file.
For the output part, only minimal change is required. Reuse the function
read_freq_ctr() to print the same value in both stats output and
stats-file dump.
For counter preloading, define a new utility function
preload_freq_ctr(). This can be used to initialize a freq-ctr type by
preloading previous period value. Reuse this function in load_ctr()
during stats-file parsing.
At the moment, no rate column is defined as generic. Thus, this commit
does not have functional change. This will be changed as soon as FN_RATE
are converted to generic columns.
int freq_ctr_overshoot_period(const struct freq_ctr *ctr, uint period, uint freq);
uint update_freq_ctr_period_slow(struct freq_ctr *ctr, uint period, uint inc);
+/* Only usable during single threaded startup phase. */
+static inline void preload_freq_ctr(struct freq_ctr *ctr, uint value)
+{
+ ctr->curr_ctr = 0;
+ ctr->prev_ctr = value;
+ ctr->curr_tick = now_ms & ~1;
+}
+
/* Update a frequency counter by <inc> incremental units. It is automatically
* rotated if the period is over. It is important that it correctly initializes
* a null area.
value.u.u64 = read_uint64(&ptr, istend(token));
break;
+ case FF_U32:
+ value.u.u32 = read_uint(&ptr, istend(token));
+ break;
+
default:
/* Unsupported field nature. */
return 1;
if (fn == FN_COUNTER && ff == FF_U64) {
*(uint64_t *)counter = value.u.u64;
}
+ else if (fn == FN_RATE && ff == FF_U32) {
+ preload_freq_ctr(counter, value.u.u32);
+ }
else {
/* Unsupported field format/nature combination. */
return 1;
ABORT_NOW();
}
}
+ else if (fn == FN_RATE) {
+ /* freq-ctr always uses FF_U32 */
+ BUG_ON(stcol_format(col) != FF_U32);
+ value = mkf_u32(FN_RATE, read_freq_ctr(counter));
+ }
else {
/* No generic column available for other field nature. */
ABORT_NOW();