From 6d27c12c57e7090e8ccbfdd8885142f3755c015c Mon Sep 17 00:00:00 2001 From: wangyongrong Date: Wed, 10 Jan 2024 14:20:15 +0800 Subject: [PATCH] rptun dump: move rptun_dump.c to rptun.c, remove redundant code. Signed-off-by: wangyongrong --- drivers/rptun/CMakeLists.txt | 2 +- drivers/rptun/Make.defs | 2 +- drivers/rptun/rptun.c | 156 ++++++++++++++++++++++++++++------- drivers/rptun/rptun.h | 37 --------- 4 files changed, 129 insertions(+), 68 deletions(-) delete mode 100644 drivers/rptun/rptun.h diff --git a/drivers/rptun/CMakeLists.txt b/drivers/rptun/CMakeLists.txt index bab4f294bf..a3375d79d4 100644 --- a/drivers/rptun/CMakeLists.txt +++ b/drivers/rptun/CMakeLists.txt @@ -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}) diff --git a/drivers/rptun/Make.defs b/drivers/rptun/Make.defs index e78aab215a..029eb034d4 100644 --- a/drivers/rptun/Make.defs +++ b/drivers/rptun/Make.defs @@ -22,7 +22,7 @@ ifeq ($(CONFIG_RPTUN),y) -CSRCS += rptun.c rptun_dump.c +CSRCS += rptun.c DEPPATH += --dep-path rptun VPATH += :rptun diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index 023b9bfca1..c4840406ac 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -35,14 +35,14 @@ #include #include #include -#include #include +#include +#include #include #include #include #include - -#include "rptun.h" +#include /**************************************************************************** * 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); diff --git a/drivers/rptun/rptun.h b/drivers/rptun/rptun.h deleted file mode 100644 index 25227d1902..0000000000 --- a/drivers/rptun/rptun.h +++ /dev/null @@ -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 - -/**************************************************************************** - * 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 */