From: Michal Sojka Date: Fri, 17 Dec 2010 16:18:32 +0000 (+0100) Subject: Merge branch 'master' of rtime.felk.cvut.cz:/can-benchmark X-Git-Tag: fix-allnoconfig~201 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-benchmark.git/commitdiff_plain/3ea7fae8477eb1f8a65e07a2e5f8c139110a2a81?hp=-c Merge branch 'master' of rtime.felk.cvut.cz:/can-benchmark --- 3ea7fae8477eb1f8a65e07a2e5f8c139110a2a81 diff --combined latester/latester.c index e4185b2,b7bb38b..61b2b43 --- a/latester/latester.c +++ b/latester/latester.c @@@ -83,6 -83,7 +83,7 @@@ struct unsigned lost; struct timespec tic, tac; unsigned timeouts; + unsigned invalid_frame; } stats; int num_interfaces = 0; @@@ -132,7 -133,7 +133,7 @@@ void sprint_canframe(char *buf , struc } } -static inline struct msg_info *frame2info(struct can_frame *frame) +static inline uint16_t frame_index(struct can_frame *frame) { uint16_t idx; if (frame->can_dlc >= 2) { @@@ -143,12 -144,7 +144,12 @@@ error(1, 0, "%s error", __FUNCTION__); } - return &msg_infos[idx]; + return idx; +} + +static inline struct msg_info *frame2info(struct can_frame *frame) +{ + return &msg_infos[frame_index(frame)]; } static inline char *tstamp_str(const void *ctx, struct timespec *tstamp) @@@ -339,11 -335,16 +340,16 @@@ static inline void trace_off(int ret write(trace_fd, "0", 1); } - void msg_info_free(struct msg_info *mi) + static inline void msg_info_free(struct msg_info *mi) { mi->id = -1; } + static inline bool msg_info_used(struct msg_info *mi) + { + return mi->id != -1; + } + int send_frame(int socket) { struct can_frame frame; @@@ -355,7 -356,7 +361,7 @@@ MEMSET_ZERO(frame); i = curr_msg+1; - while (msg_infos[i].id != -1 && i != curr_msg) { + while (msg_info_used(&msg_infos[i]) && i != curr_msg) { i++; if (i >= MAX_INFOS) i = 0; @@@ -484,8 -485,11 +490,11 @@@ void process_on_wire_rx(int s struct msg_info *mi; receive(s, &frame, &ts_kern, &ts_user); mi = frame2info(&frame); - mi->ts_rx_onwire_kern = ts_kern; - mi->ts_rx_onwire = ts_user; + if (msg_info_used(mi)) { + mi->ts_rx_onwire_kern = ts_kern; + mi->ts_rx_onwire = ts_user; + } else + stats.invalid_frame++; } @@@ -602,15 -606,13 +611,15 @@@ void *measure_thread(void *arg } pfd[0].revents = 0; - if (num_interfaces == 3 && pfd[1].revents != 0) { + if (num_interfaces == 3 && pfd[1].revents & POLLIN) { process_on_wire_rx(pfd[1].fd); pfd[1].revents = 0; } + if (num_interfaces == 3 && pfd[1].revents & ~POLLIN) + error(1, 0, "Unexpected pfd[1].revents: 0x%04x\n", pfd[1].revents); i = (num_interfaces == 2) ? 1 : 2; - if (pfd[i].revents != 0) { + if (pfd[i].revents & POLLIN) { consecutive_timeouts = 0; process_final_rx(pfd[i].fd); msg_in_progress--; @@@ -620,8 -622,6 +629,8 @@@ SEND(); } } + if (pfd[i].revents & ~POLLIN) + error(1, 0, "Unexpected pfd[%d].revents: 0x%04x\n", pfd[i].revents); } } @@@ -818,6 -818,9 +827,9 @@@ int main(int argc, const char *argv[] fprintf(opt.f_stat, "timeouts=%d\n", stats.timeouts); if (stats.timeouts && !opt.quiet) printf("timeouts=%d\n", stats.timeouts); + fprintf(opt.f_stat, "invalid_frame=%d\n", stats.timeouts); + if (stats.timeouts && !opt.quiet) + printf("invalid_frame=%d\n", stats.timeouts); fclose(opt.f_stat);