rptun dump: move rptun_dump.c to rptun.c, remove redundant code.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
This commit is contained in:
wangyongrong 2024-01-10 14:20:15 +08:00 committed by Xiang Xiao
parent e0051240fb
commit 6d27c12c57
4 changed files with 129 additions and 68 deletions

View file

@ -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})

View file

@ -22,7 +22,7 @@
ifeq ($(CONFIG_RPTUN),y)
CSRCS += rptun.c rptun_dump.c
CSRCS += rptun.c
DEPPATH += --dep-path rptun
VPATH += :rptun

View file

@ -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
@ -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)
@ -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;
@ -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;
@ -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);

View file

@ -1,37 +0,0 @@
/****************************************************************************
* drivers/rptun/rptun.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_RPTUN_RPTUN_H
#define __DRIVERS_RPTUN_RPTUN_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/rptun/rptun.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
int rptun_buffer_nused(FAR struct rpmsg_virtio_device *rvdev, bool rx);
void rptun_dump(FAR struct rpmsg_virtio_device *rvdev);
#endif /* __DRIVERS_RPTUN_RPTUN_H */