/* Temporary variables */
FILE *f_msgs;
FILE *f_hist;
+ FILE *f_hist_gw;
FILE *f_stat;
};
struct timespec ts_rx_onwire, ts_rx_onwire_kern;
struct timespec ts_rx_final, ts_rx_final_kern;
struct can_frame sent, received;
+ unsigned lat_measured_us, tx_time_us;
};
#define MAX_INFOS 10000
struct msg_info msg_infos[MAX_INFOS];
-struct histogram histogram;
+struct histogram histogram, histogram_gw;
void sprint_canframe(char *buf , struct can_frame *cf, int sep) {
/* documentation see lib.h */
crc_t crc = 0;
uint32_t crcx;
+/* char received[64]; */
+/* sprint_canframe(received, frame, true); */
+/* printf("Frame: %s\n", received); */
+
if (frame->can_id & CAN_EFF_FLAG) {
bitmap[0] =
((frame->can_id & CAN_EFF_MASK) >> 25);
ones = !ones;
}
//printf ("STUFFED %d BITS\n", stuffed);
+ return stuffed;
}
-unsigned calc_frame_txtime(struct can_frame *frame) {
+unsigned calc_frame_txtime_us(struct can_frame *frame) {
return calc_stuff_bits(frame) +
1 + /* SOF */
11 + /* ID A */
num, S(mi->ts_sent), sent, S(mi->ts_rx_final_kern), S(mi->ts_rx_final), received,
DIFF(mi->ts_sent, mi->ts_rx_final_kern),
DIFF(mi->ts_sent, mi->ts_rx_final),
- calc_frame_txtime(&mi->received));
+ mi->tx_time_us);
break;
case 3:
fprintf(f, "%ld: %s %s -> %s (%s) -> %s (%s) %s = %s (%s), %s (%s) %d\n",
DIFF(mi->ts_sent, mi->ts_rx_onwire),
DIFF(mi->ts_rx_onwire_kern, mi->ts_rx_final_kern),
DIFF(mi->ts_rx_onwire, mi->ts_rx_final),
- calc_frame_txtime(&mi->received));
+ mi->tx_time_us);
break;
}
#undef S
printf("%s sec=%ld nsec=%ld\n", msg, tv->tv_sec, tv->tv_nsec);
}
-static inline unsigned get_msg_latency_us(struct msg_info *mi)
+static inline void calc_msg_latencies(struct msg_info *mi)
{
struct timespec diff;
switch (num_interfaces) {
timespec_subtract(&diff, &mi->ts_rx_final_kern, &mi->ts_sent);
break;
default:
- return 0;
+ return;
}
- return diff.tv_sec * 1000000 + diff.tv_nsec/1000;
+ mi->lat_measured_us = diff.tv_sec * 1000000 + diff.tv_nsec/1000;
+ mi->tx_time_us = calc_frame_txtime_us(&mi->received);
}
void set_sched_policy_and_prio(int policy, int rtprio)
mi->ts_rx_final = ts_user;
mi->received = frame;
- histogram_add(&histogram, get_msg_latency_us(mi));
+ calc_msg_latencies(mi);
+
+ histogram_add(&histogram, mi->lat_measured_us);
+ histogram_add(&histogram_gw, mi->lat_measured_us - mi->tx_time_us);
ret = write(completion_pipe[1], &mi, sizeof(mi));
if (ret == -1)
}
if (opt.name) {
- char *f = talloc_asprintf(local, "%s-hist.txt", opt.name);
+ char *f = talloc_asprintf(local, "%s-hist-raw.txt", opt.name);
opt.f_hist = fopen(f, "w");
if (!opt.f_hist)
error(1, errno, "fopen: %s", f);
}
+ if (opt.name) {
+ char *f = talloc_asprintf(local, "%s-hist.txt", opt.name);
+ opt.f_hist_gw = fopen(f, "w");
+ if (!opt.f_hist_gw)
+ error(1, errno, "fopen: %s", f);
+ }
+
if (opt.name) {
char *f = talloc_asprintf(local, "%s-stat.txt", opt.name);
opt.f_stat = fopen(f, "w");
msg_infos[i].id = -1;
histogram_init(&histogram, 5000000, 1);
+ histogram_init(&histogram_gw, 5000000, 1);
ret = pipe(completion_pipe);
if (ret == -1)
close(completion_pipe[1]);
histogram_fprint(&histogram, opt.f_hist);
+ histogram_fprint(&histogram_gw, opt.f_hist_gw);
fclose(opt.f_hist);
+ fclose(opt.f_hist_gw);
fclose(opt.f_msgs);