hv_utils: drain the timesync packets on onchannelcallback
Subsystems (2)
PATCH 1/1 hv_utils: drain the timesync packets on onchannelcallback
There could be instances where a system stall prevents the timesync packaets to be consumed. And this might lead to more than one packet pending in the ring buffer. Current code empties one packet per callback and it might be a stale one. So drain all the packets from ring buffer on each callback.
--- drivers/hv/hv_util.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/hv/hv_util.c +16 -3
@@ -387,10 +387,23 @@ static void timesync_onchannelcallback(void *context)struct ictimesync_ref_data *refdata;u8 *time_txf_buf = util_timesynch.recv_buffer; -vmbus_recvpacket (channel, time_txf_buf, -HV_HYP_PAGE_SIZE , &recvlen, &requestid); +/* +* Drain the ring buffer and use the last packet to update +* host_ts +*/ +while (1 ) { +int ret =vmbus_recvpacket (channel, time_txf_buf, +HV_HYP_PAGE_SIZE , &recvlen, + &requestid); +if (ret) { +pr_warn ("TimeSync IC pkt recv failed (Err: %d)\n" , + ret); +break ; + } + +if (!recvlen) +break ; -if (recvlen >0 ) { icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[sizeof (struct vmbuspipe_hdr )];
Signature · 1 line
2.17.1
From: Vineeth Pillai <[email protected]> Sent: Wednesday, August 19, 2020 10:48 AM
Quoted 23 lines
There could be instances where a system stall prevents the timesync packaets to be consumed. And this might lead to more than one packet pending in the ring buffer. Current code empties one packet per callback and it might be a stale one. So drain all the packets from ring buffer on each callback.
Signed-off-by Vineeth Pillai <[email protected]>--- drivers/hv/hv_util.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/hv/hv_util.c +1
-2@@ -387,10 +387,23 @@ static void timesync_onchannelcallback(void *context)struct ictimesync_ref_data *refdata;u8 *time_txf_buf = util_timesynch.recv_buffer; -vmbus_recvpacket (channel, time_txf_buf, -HV_HYP_PAGE_SIZE , &recvlen, &requestid); +/*
drivers/hv/hv_util.c static void timesync_onchannelcallback(void *context) · line 400
Quoted 10 lines
drivers/hv/hv_util.c +10
-0+* Drain the ring buffer and use the last packet to update +* host_ts +*/ +while (1 ) { +int ret =vmbus_recvpacket (channel, time_txf_buf, +HV_HYP_PAGE_SIZE , &recvlen, + &requestid); +if (ret) { +pr_warn ("TimeSync IC pkt recv failed (Err: %d)\n" , + ret);
Let's use pr_warn_once().
If there's a packet at the head of the ring buffer that specifies a bogus length, we could take the error path. But the bad packet stays at the head of the ring buffer, so if we end up back here again, we'll spit out the same error message. We actually should not end up here again because Hyper-V shouldn't interrupt when adding a packet to a non-empty ring buffer, but who knows what might happen.
Quoted 12 lines
drivers/hv/hv_util.c +5
-2+break ; + } + +if (!recvlen) +break ; -if (recvlen >0 ) { icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[sizeof (struct vmbuspipe_hdr )]; --2.17.1
Hi Michael,
Quoted 5 lines
drivers/hv/hv_util.c static void timesync_onchannelcallback(void *context) · line 400
Quoted 2 lines
drivers/hv/hv_util.c +2
-0+pr_warn ("TimeSync IC pkt recv failed (Err: %d)\n" , + ret);Let's use
pr_warn_once().
Quoted 7 lines
If there's a packet at the head of the ring buffer that specifies a bogus length, we could take the error path. But the bad packet stays at the head of the ring buffer, so if we end up back here again, we'll spit out the same error message. We actually should not end up here again because Hyper-V shouldn't interrupt when adding a packet to a non-empty ring buffer, but who knows what might happen.
Valid point, will fix this in the next iteration.
Thanks,
Vineeth