ivan_wl's recent timeline updates
ivan_wl

ivan_wl

V2EX member #14049, joined on 2011-11-28 09:42:01 +08:00
Today's activity rank 3149
ivan_wl's recent replies

@aiche8848 这是什么东西……名字都搜不到

@yolee599 我本地跑了一下

GCC 11.4

操作 TAILQ 平均值 cc_list 平均值 cc_list 变化
insert head 72.580 27.852 -61.6%
insert tail 27.381 27.950 +2.1%
insert before 27.248 27.569 +1.2%
insert after 27.293 27.569 +1.0%
forward 30.634 29.582 -3.4%
reverse 45.275 30.581 -32.5%
delete 37.434 35.361 -5.5%

Clang 16.0.6

操作 TAILQ 平均值 cc_list 平均值 cc_list 变化
insert head 74.710 75.406 +0.9%
insert tail 28.013 28.333 +1.1%
insert before 27.920 28.061 +0.5%
insert after 27.206 28.061 +3.1%
forward 30.617 29.725 -2.9%
reverse 45.248 30.476 -32.6%
delete 42.779 37.420 -12.5%

@yolee599 https://godbolt.org/z/YfojE9h7G 试下这个 develop 分支上的版本,基本上 cc_list 都比 TAILQ 强了,另外 godbolt 的性能测试好像不太稳定,经常跑出几百 ms 的情况,最好还是本地测试

@yolee599 58 行 cc_list_foreach 参数写反了,改成 cc_list_foreach(&test_list, p_tmp_node, entries)就行了

@yolee599 这个就是我前面回复里说的 BSD TAILQ 吧,正向遍历是直接指容器的,反向遍历是个别扭的二级指针,效率特别低。

@CrescentMoon sub 是一条减法,且后续指令访存要依赖它的结果,没法优化的。
cc_list 在 head 上用 container_of 和 list_head 在 node 上反推 container 本质上是一样的。而且 head 计算出的影子 container 并没有解引用,根本没有内存访问,就没有越界之说。
list_head 更野,每个 node 都是假定 container 是你要的类型,直接反推 container 后就解引用了。
cc_list 至少还是类型安全的,指错类型编译时就报错了,其实比 list_head 更“安全”。

@levelworm Linux 内核可能一开始就这么写了也很稳定,效率也不是瓶颈,也就没动力改了;也可以看一下 BSD 的 TAILQ,它的正向遍历也是直接指向容器的,跟 cc_list 效率是一样的,但是 TAILQ 反向遍历就特别的别扭,非常的别扭,不是一般的别扭,这么多年了也没改。

@firear 我的 example/里,cc_task 和 C++ 协程都用 epoll 跑网络收发,遇到过 cc_task 吞吐更低的问题,是因为 cc_task 用户态代码比 C++ 协程少,导致 epoll 的唤醒更频繁,每次唤醒拿到的事件更少,batch 太小,切换到内核态次数更多。epoll 也不能设置 batch 参数。
但是总体来说 cc_task 的用户态代码是比 C++ 协程少的,理论性能也更高。
有兴趣的话,你也可以用 cc_task + io_uring 试一下

@Mozalic
@Desiree
用 Duff's device 技巧实现 C 语言协程,包括 protothreads,都是很古老的东西了,clang 的 C 语言闭包也很古老了,但是这么久了也没发现有人把它们结合起来,cc_task 摘了这个桃子

@ToBeHacker 先看下代码或文档呢?cc_task 的恢复标志比 protothread 的 LINE 和你的手动写序号更强,它是自动生成 0 1 2 3... 递增的恢复标志,编译器可以充分优化,还不用手动维护。

About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1340 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 17:13 · PVG 01:13 · LAX 09:13 · JFK 12:13
♥ Do have faith in what you're doing.