Skip to content

Commit

Permalink
rpmsg_virtio.c: replace metal_cpu_yield to new libmetal API metal_yield
Browse files Browse the repository at this point in the history
The CPU yield is not supported by all OSes/processors. If not supported,
this causes a busy loop that monopolizes the CPU. Replace it with
metal_sleep_usec, which is OS-dependent and allows the OS scheduler to
switch to another thread.

Signed-off-by: Yongrong Wang <[email protected]>
  • Loading branch information
wyr-7 committed Oct 8, 2024
1 parent c468328 commit 31aa1f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/remoteproc/remoteproc_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <openamp/remoteproc.h>
#include <openamp/remoteproc_virtio.h>
#include <openamp/virtqueue.h>
#include <metal/cpu.h>
#include <metal/sys.h>
#include <metal/utilities.h>
#include <metal/alloc.h>

Expand Down Expand Up @@ -412,6 +412,6 @@ void rproc_virtio_wait_remote_ready(struct virtio_device *vdev)
status = rproc_virtio_get_status(vdev);
if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
return;
metal_cpu_yield();
metal_yield();
}
}
4 changes: 2 additions & 2 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <metal/alloc.h>
#include <metal/sleep.h>
#include <metal/sys.h>
#include <metal/utilities.h>
#include <openamp/rpmsg_virtio.h>
#include <openamp/virtqueue.h>
Expand Down Expand Up @@ -271,8 +272,7 @@ static int rpmsg_virtio_wait_remote_ready(struct rpmsg_virtio_device *rvdev)
} else if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK) {
return 0;
}
/* TODO: clarify metal_cpu_yield usage*/
metal_cpu_yield();
metal_yield();
}
}

Expand Down

0 comments on commit 31aa1f9

Please sign in to comment.