canfdtest: remove usage of gettimeofday
This patch fixes this bug https://github.com/linux-can/can-utils/issues/13 Modified the existing millisleep function to use clock_nanosleep with MONOTONIC clock and relative timeout. Signed-off-by: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>pull/33/head
parent
4d0e6d5169
commit
cf1b2a177f
45
canfdtest.c
45
canfdtest.c
|
|
@ -120,22 +120,21 @@ static void compare_frame(struct can_frame *exp, struct can_frame *rec)
|
||||||
|
|
||||||
static void millisleep(int msecs)
|
static void millisleep(int msecs)
|
||||||
{
|
{
|
||||||
if (msecs <= 0) {
|
struct timespec rqtp, rmtp;
|
||||||
sched_yield();
|
int err;
|
||||||
} else {
|
|
||||||
struct timespec rqtp, rmtp;
|
|
||||||
|
|
||||||
/* sleep in ms */
|
/* sleep in ms */
|
||||||
rqtp.tv_sec = msecs / 1000;
|
rqtp.tv_sec = msecs / 1000;
|
||||||
rqtp.tv_nsec = (msecs % 1000) * 1000000;
|
rqtp.tv_nsec = msecs % 1000 * 1000000;
|
||||||
while (nanosleep(&rqtp, &rmtp)) {
|
|
||||||
if (errno != EINTR) {
|
do {
|
||||||
printf("t\n");
|
err = clock_nanosleep(CLOCK_MONOTONIC, 0, &rqtp, &rmtp);
|
||||||
break;
|
if (err != 0 && err != EINTR) {
|
||||||
}
|
printf("t\n");
|
||||||
rqtp = rmtp;
|
break;
|
||||||
}
|
}
|
||||||
}
|
rqtp = rmtp;
|
||||||
|
} while (err != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void echo_progress(unsigned char data)
|
static void echo_progress(unsigned char data)
|
||||||
|
|
@ -194,7 +193,6 @@ static int send_frame(struct can_frame *frame)
|
||||||
static int can_echo_dut(void)
|
static int can_echo_dut(void)
|
||||||
{
|
{
|
||||||
unsigned int frame_count = 0;
|
unsigned int frame_count = 0;
|
||||||
struct timeval tvn, tv_stop;
|
|
||||||
struct can_frame frame;
|
struct can_frame frame;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
@ -227,22 +225,7 @@ static int can_echo_dut(void)
|
||||||
*/
|
*/
|
||||||
if (frame_count == CAN_MSG_WAIT) {
|
if (frame_count == CAN_MSG_WAIT) {
|
||||||
frame_count = 0;
|
frame_count = 0;
|
||||||
if (gettimeofday(&tv_stop, NULL)) {
|
millisleep(3);
|
||||||
perror("gettimeofday failed\n");
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
tv_stop.tv_usec += 3000;
|
|
||||||
if (tv_stop.tv_usec > 999999) {
|
|
||||||
tv_stop.tv_sec++;
|
|
||||||
tv_stop.tv_usec =
|
|
||||||
tv_stop.tv_usec % 1000000;
|
|
||||||
}
|
|
||||||
gettimeofday(&tvn, NULL);
|
|
||||||
while ((tv_stop.tv_sec > tvn.tv_sec) ||
|
|
||||||
((tv_stop.tv_sec == tvn.tv_sec) &&
|
|
||||||
(tv_stop.tv_usec >= tvn.tv_usec)))
|
|
||||||
gettimeofday(&tvn, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue