CV-Bowen opened a new pull request, #22030:
URL: https://github.com/apache/nuttx/pull/22030

   ## Summary
   
   Fixes and improvements to the rpmsg RTC (`drivers/timers/rpmsg_rtc.c`):
   
   - `fix nxstyle errors`: indent the `case` labels one level in from the
     switch braces and add two missing blank lines, so that the following
     commits pass checkpatch. No functional change.
   - `log the time sync messages`: `_info()` the time carried by each sync
     and set message on the client and the server.
   - `resync the server's system time to its RTC`: `rpmsg_rtc_server_sync()`
     sent the RTC time together with the server's `g_basetime` without
     updating it, so the clients got a time and a base time that disagree
     once the server's system time had drifted. Synchronize it first.
   - `bind the client to one server only`: when the client reaches the
     server over more than one rpmsg channel, every channel announces
     `rpmsg-rtc` and the client created its single endpoint again for each
     announcement. The endpoint ended up linked into two devices and the
     endpoint lists were corrupted. Ignore further announcements once
     bound, and add `CONFIG_RTC_RPMSG_SERVER_CPUNAME` to choose the server.
   - `run the client callback in the rx interrupt`: set `RPMSG_PRIO_RT` on
     the client endpoint, so rpmsg_virtio handles time sync and alarm
     messages without a worker thread wakeup. The server endpoint keeps
     the default priority.
   
   ## Impact
   
   - New Kconfig `RTC_RPMSG_SERVER_CPUNAME` (default empty: first server
     that announces). `RTC_RPMSG_SYNC_BASETIME` now also depends on
     `RTC_RPMSG`.
   - rpmsg RTC client callback runs in the rx interrupt on rpmsg_virtio
     transports.
   - No API change.
   
   ## Testing
   
   Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU 
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
   
   **Two channels (qemu-armv8a:rpserver + rpproxy).** These configs connect
   proxy and server over two rpmsg channels: ivshmem (`server`) and
   rpmsg_port_uart (`server2`). On top of them:
   
   - both: `CONFIG_RTC=y CONFIG_RTC_DRIVER=y CONFIG_RTC_ARCH=y
     CONFIG_RTC_PL031=y CONFIG_RTC_RPMSG=y`, nsh `date` enabled
   - server: `CONFIG_RTC_RPMSG_SERVER=y`
   - proxy: `CONFIG_RTC_EXTERNAL=y`
   
   plus a test-only patch (not in this PR) so the server exports its PL031
   through rpmsg and the proxy uses the rpmsg RTC:
   
   ```c
   /* arch/arm64/src/qemu/qemu_rtc.c, up_rtc_initialize() */
   #if defined(CONFIG_RTC_RPMSG) && !defined(CONFIG_RTC_RPMSG_SERVER)
     lower = rpmsg_rtc_initialize();
     up_rtc_set_lowerhalf(lower, false);
     return rtc_initialize(0, lower);
   #else
     lower = pl031_initialize(CONFIG_QEMU_RTC_PL031_BASE,
                              CONFIG_QEMU_RTC_PL031_IRQ);
   #  ifdef CONFIG_RTC_RPMSG_SERVER
     lower = rpmsg_rtc_server_initialize(lower);
   #  endif
   #endif
   ```
   
   Both started with (`-kernel` the server or the proxy image; the server
   side uses `server=on,wait=off` on the chardev):
   
   ```
   qemu-system-aarch64 -cpu cortex-a53 -nographic \
     -machine virt,virtualization=on,gic-version=3 -serial mon:stdio \
     -object 
memory-backend-file,discard-data=on,id=shm0,mem-path=/dev/shm/rtc,size=4194304,share=yes
 \
     -device ivshmem-plain,id=shmem0,memdev=shm0,addr=0xb \
     -device virtio-serial-device,bus=virtio-mmio-bus.0 \
     -chardev socket,path=/tmp/rtc.sock,server=off,id=foo \
     -device virtconsole,chardev=foo \
     -kernel nuttx
   ```
   
   nsh: proxy `rpmsg dump all`; server `date -s "Jan 01 12:00:00 2030"`;
   proxy `sleep 2`, `date`.
   
   | | master | this PR |
   |---|---|---|
   | `rpmsg-rtc` endpoints on the proxy | the same endpoint in both channels' 
lists, followed by a garbage entry | one, on one channel |
   | proxy `rpmsg dump all` | loops over the corrupted list, never returns | 
returns |
   | proxy `date` after the server sets 2030 | no answer (2 runs) | `Tue, Jan 
01 12:00:04 2030` (2 runs) |
   
   <details><summary>master: proxy rpmsg dump all</summary>
   
   ```
   [proxy] Remote: server2 state: 1
   [proxy]   rpmsg ept list:
   [proxy]     ept NS 0x406ba1f8: addr=53 dest=53 refcnt=1 priority=127 
priv=0x406ba020
   [proxy]     ept rpmsg-sensor 0x406b0800: addr=1024 dest=1025 refcnt=1 
priority=127 priv=0x406b07f0
   [proxy]     ept rpmsg-ping 0x406ba0d8: addr=1025 dest=1026 refcnt=1 
priority=127 priv=0
   [proxy]     ept rpmsg-ping-rt 0x406ba150: addr=1026 dest=1027 refcnt=1 
priority=255 priv=0
   [proxy]     ept rpmsg-rtc 0x406983c8: addr=1028 dest=1024 refcnt=1 
priority=127 priv=0x406983c0
   [proxy]     ept  0x4069e738: addr=1080656936 dest=0 refcnt=1080682216 
priority=2 priv=0x534e
   [proxy]     ept NS 0x4069e7a8: addr=53 dest=53 refcnt=1 priority=127 
priv=0x4069e798
   [proxy]     ept rpmsg-syslog 0x40690278: addr=1024 dest=1028 refcnt=1 
priority=127 priv=0x40690228
   [proxy]     ept rpmsg-sensor 0x4069ef20: addr=1025 dest=1025 refcnt=1 
priority=127 priv=0x4069ef10
   [proxy]     ept rpmsg-ping 0x4069e688: addr=1026 dest=1026 refcnt=1 
priority=127 priv=0
   [proxy]     ept rpmsg-ping-rt 0x4069e700: addr=1027 dest=1027 refcnt=1 
priority=255 priv=0
   [proxy]     ept rpmsg-rtc 0x406983c8: addr=1028 dest=1024 refcnt=1 
priority=127 priv=0x406983c0
   [proxy]     ept  0x4069e738: addr=1080656936 dest=0 refcnt=1080682216 
priority=2 priv=0x534e
   ... (repeats until the command times out)
   ```
   </details>
   
   <details><summary>this PR: proxy rpmsg dump all and date</summary>
   
   ```
   [proxy] Dump rpmsg info between cpu (master: no)proxy <==> server:
   [proxy]   rpmsg ept list:
   [proxy]     ept NS 0x4069e798: addr=53 dest=53 refcnt=1 priority=127 
priv=0x4069e788
   [proxy]     ept rpmsg-syslog 0x40690278: addr=1024 dest=1028 refcnt=1 
priority=127 priv=0x40690228
   [proxy]     ept rpmsg-sensor 0x4069ef10: addr=1025 dest=1025 refcnt=1 
priority=127 priv=0x4069ef00
   [proxy]     ept rpmsg-ping 0x4069e678: addr=1026 dest=1026 refcnt=1 
priority=127 priv=0
   [proxy]     ept rpmsg-ping-rt 0x4069e6f0: addr=1027 dest=1027 refcnt=1 
priority=255 priv=0
   ...
   [proxy] Remote: server2 state: 1
   [proxy]   rpmsg ept list:
   [proxy]     ept NS 0x406ba1f8: addr=53 dest=53 refcnt=1 priority=127 
priv=0x406ba020
   [proxy]     ept rpmsg-sensor 0x4069d020: addr=1024 dest=1025 refcnt=1 
priority=127 priv=0x4069d010
   [proxy]     ept rpmsg-ping 0x406ba0d8: addr=1025 dest=1026 refcnt=1 
priority=127 priv=0
   [proxy]     ept rpmsg-ping-rt 0x406ba150: addr=1026 dest=1027 refcnt=1 
priority=255 priv=0
   [proxy]     ept rpmsg-rtc 0x406983c8: addr=1027 dest=1024 refcnt=1 
priority=255 priv=0x406983c0
   
   server> date -s "Jan 01 12:00:00 2030"
   [proxy] rpmsg_rtc_ept_cb: rpmsg rtc client sync time:1893499200
   proxy> sleep 2
   proxy> date
   Tue, Jan 01 12:00:04 2030
   ```
   </details>
   
   **One channel (sim:rpserver + sim:rpproxy, unchanged configs; they
   already enable the rpmsg RTC).** Server `date -s "Jan 01 12:00:00 2030"`,
   then proxy `date` after 2 s: 2030 on master and with this PR. With this
   PR the proxy's `rpmsg-rtc` endpoint has priority 255 (127 on master):
   
   ```
   [server] rpmsg_rtc_server_sync: rpmsg rtc server sync time:1795023820
   [proxy] rpmsg_rtc_ept_cb: rpmsg rtc client sync time:1893499200
   proxy> date
   Tue, Jan 01 12:00:08 2030
   [proxy]     ept rpmsg-rtc 0xea950b6c: addr=1033 dest=1024 refcnt=1 
priority=255 priv=0xea950b68
   ```
   
   Not tested: alarms over rpmsg (no alarm user in these configs).
   
   No regression in rpmsg: sim:rpserver/rpproxy and 
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, 
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC 
disabled, which current master needs for nxinit to start nsh there; unrelated 
to this change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to