Skip to content

Commit

Permalink
rptun dump: move rptun_dump.c to rptun.c, remove redundant code.
Browse files Browse the repository at this point in the history
Signed-off-by: wangyongrong <[email protected]>
  • Loading branch information
wyr-7 authored and xiaoxiang781216 committed Feb 19, 2024
1 parent e005124 commit 6d27c12
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 68 deletions.
2 changes: 1 addition & 1 deletion drivers/rptun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if(CONFIG_RPTUN)
set(SRCS)

list(APPEND SRCS rptun.c rptun_dump.c)
list(APPEND SRCS rptun.c)

target_include_directories(drivers PRIVATE ${NUTTX_DIR}/openamp/open-amp/lib)
target_sources(drivers PRIVATE ${SRCS})
Expand Down
2 changes: 1 addition & 1 deletion drivers/rptun/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

ifeq ($(CONFIG_RPTUN),y)

CSRCS += rptun.c rptun_dump.c
CSRCS += rptun.c

DEPPATH += --dep-path rptun
VPATH += :rptun
Expand Down
156 changes: 127 additions & 29 deletions drivers/rptun/rptun.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
#include <nuttx/kmalloc.h>
#include <nuttx/kthread.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/power/pm.h>
#include <nuttx/rptun/rptun.h>
#include <nuttx/semaphore.h>
#include <nuttx/wqueue.h>
#include <metal/utilities.h>
#include <openamp/remoteproc_loader.h>
#include <openamp/remoteproc_virtio.h>

#include "rptun.h"
#include <rpmsg/rpmsg_internal.h>

/****************************************************************************
* Pre-processor Definitions
Expand Down Expand Up @@ -167,6 +167,32 @@ static const struct rpmsg_ops_s g_rptun_rpmsg_ops =
* Private Functions
****************************************************************************/

static int rptun_buffer_nused(FAR struct rpmsg_virtio_device *rvdev, bool rx)
{
FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq;
uint16_t nused = vq->vq_ring.avail->idx - vq->vq_ring.used->idx;

if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx)
{
return nused;
}
else
{
return vq->vq_nentries - nused;
}
}

static void rptun_wakeup_tx(FAR struct rptun_priv_s *priv)
{
int semcount;

nxsem_get_value(&priv->semtx, &semcount);
while (semcount++ < 1)
{
nxsem_post(&priv->semtx);
}
}

#ifdef CONFIG_RPTUN_PM
static inline void rptun_pm_action(FAR struct rptun_priv_s *priv,
bool stay)
Expand Down Expand Up @@ -248,17 +274,6 @@ static bool rptun_is_recursive(FAR struct rptun_priv_s *priv)
return nxsched_gettid() == priv->tid;
}

static void rptun_wakeup_tx(FAR struct rptun_priv_s *priv)
{
int semcount;

nxsem_get_value(&priv->semtx, &semcount);
while (semcount++ < 1)
{
nxsem_post(&priv->semtx);
}
}

static int rptun_callback(FAR void *arg, uint32_t vqid)
{
FAR struct rptun_priv_s *priv = arg;
Expand Down Expand Up @@ -409,6 +424,104 @@ static int rptun_notify_wait(FAR struct remoteproc *rproc, uint32_t id)
return 0;
}

static void rptun_dump_buffer(FAR struct rpmsg_virtio_device *rvdev,
bool rx)
{
FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq;
FAR void *addr;
int desc_idx;
int num;
int i;

num = rptun_buffer_nused(rvdev, rx);
metal_log(METAL_LOG_EMERGENCY,
" %s buffer, total %d, pending %d\n",
rx ? "RX" : "TX", vq->vq_nentries, num);

for (i = 0; i < num; i++)
{
if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx)
{
desc_idx = (vq->vq_ring.used->idx + i) & (vq->vq_nentries - 1);
desc_idx = vq->vq_ring.avail->ring[desc_idx];
}
else
{
desc_idx = (vq->vq_ring.avail->idx + i) & (vq->vq_nentries - 1);
desc_idx = vq->vq_ring.used->ring[desc_idx].id;
}

addr = metal_io_phys_to_virt(vq->shm_io,
vq->vq_ring.desc[desc_idx].addr);
if (addr)
{
FAR struct rpmsg_hdr *hdr = addr;
FAR struct rpmsg_endpoint *ept;

ept = rpmsg_get_ept_from_addr(&rvdev->rdev,
rx ? hdr->dst : hdr->src);
if (ept)
{
metal_log(METAL_LOG_EMERGENCY,
" %s buffer %p hold by %s\n",
rx ? "RX" : "TX", hdr, ept->name);
}
}
}
}

static void rptun_dump(FAR struct rpmsg_virtio_device *rvdev)
{
FAR struct rpmsg_device *rdev = &rvdev->rdev;
FAR struct rpmsg_endpoint *ept;
FAR struct metal_list *node;
bool needlock = true;

if (!rvdev->vdev)
{
return;
}

if (up_interrupt_context() || sched_idletask() ||
nxmutex_is_hold(&rdev->lock))
{
needlock = false;
}

if (needlock)
{
metal_mutex_acquire(&rdev->lock);
}

metal_log(METAL_LOG_EMERGENCY,
"Dump rpmsg info between cpu (master: %s)%s <==> %s:\n",
rpmsg_virtio_get_role(rvdev) == RPMSG_HOST ? "yes" : "no",
CONFIG_RPMSG_LOCAL_CPUNAME, rpmsg_get_cpuname(rdev));

metal_log(METAL_LOG_EMERGENCY, "rpmsg vq RX:\n");
virtqueue_dump(rvdev->rvq);
metal_log(METAL_LOG_EMERGENCY, "rpmsg vq TX:\n");
virtqueue_dump(rvdev->svq);

metal_log(METAL_LOG_EMERGENCY, " rpmsg ept list:\n");

metal_list_for_each(&rdev->endpoints, node)
{
ept = metal_container_of(node, struct rpmsg_endpoint, node);
metal_log(METAL_LOG_EMERGENCY, " ept %s\n", ept->name);
}

metal_log(METAL_LOG_EMERGENCY, " rpmsg buffer list:\n");

rptun_dump_buffer(rvdev, true);
rptun_dump_buffer(rvdev, false);

if (needlock)
{
metal_mutex_release(&rdev->lock);
}
}

static int rptun_wait(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem)
{
FAR struct rptun_priv_s *priv = (FAR struct rptun_priv_s *)rpmsg;
Expand Down Expand Up @@ -935,21 +1048,6 @@ int rptun_panic(FAR const char *cpuname)
return rpmsg_ioctl(cpuname, RPMSGIOC_PANIC, 0);
}

int rptun_buffer_nused(FAR struct rpmsg_virtio_device *rvdev, bool rx)
{
FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq;
uint16_t nused = vq->vq_ring.avail->idx - vq->vq_ring.used->idx;

if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx)
{
return nused;
}
else
{
return vq->vq_nentries - nused;
}
}

void rptun_dump_all(void)
{
rpmsg_ioctl(NULL, RPMSGIOC_DUMP, 0);
Expand Down
37 changes: 0 additions & 37 deletions drivers/rptun/rptun.h

This file was deleted.

0 comments on commit 6d27c12

Please sign in to comment.