Skip to content

Commit b46b4a8

Browse files
Vineeth Pillailiuw
authored andcommitted
hv_utils: drain the timesync packets on onchannelcallback
There could be instances where a system stall prevents the timesync packets 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]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent 90b125f commit b46b4a8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/hv/hv_util.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,23 @@ static void timesync_onchannelcallback(void *context)
387387
struct ictimesync_ref_data *refdata;
388388
u8 *time_txf_buf = util_timesynch.recv_buffer;
389389

390-
vmbus_recvpacket(channel, time_txf_buf,
391-
HV_HYP_PAGE_SIZE, &recvlen, &requestid);
390+
/*
391+
* Drain the ring buffer and use the last packet to update
392+
* host_ts
393+
*/
394+
while (1) {
395+
int ret = vmbus_recvpacket(channel, time_txf_buf,
396+
HV_HYP_PAGE_SIZE, &recvlen,
397+
&requestid);
398+
if (ret) {
399+
pr_warn_once("TimeSync IC pkt recv failed (Err: %d)\n",
400+
ret);
401+
break;
402+
}
403+
404+
if (!recvlen)
405+
break;
392406

393-
if (recvlen > 0) {
394407
icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[
395408
sizeof(struct vmbuspipe_hdr)];
396409

0 commit comments

Comments
 (0)