V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  reus  ›  全部回复第 71 页 / 共 348 页
回复总数  6941
1 ... 67  68  69  70  71  72  73  74  75  76 ... 348  
2020-07-19 09:51:52 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@vcfghtyjc 任何可以手工控制内存分配的语言都可以。你居然不是用 C ?
2020-07-19 09:49:37 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@ryd994 我没说这叫 false sharing,我说的是“类似避免 false sharing”。
2020-07-19 01:44:28 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@vcfghtyjc 场景就是类似避免 false sharing,但你这里不是多个线程共用 cache line 的问题,而是多次运行共用 cache line 的问题。而且涉及的是一次运行用到的全部内存,不能和另一次有任何共享 cache line 。我想到的是提前分配好各次需要用到的内存,然后再开始跑。内存分配器可能要自己写,因为一般的内存分配器都是尽量利用 cache locality,和你的目的完全相反……
2020-07-19 01:35:35 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@vcfghtyjc 那你只要精细分配好每次用到的内存,保证各次不出现共用 cache line 的情况就行了,locality 自然不生效。就不知道你的程序能不能完全自己控制分配了。
2020-07-19 01:11:10 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@vcfghtyjc 你给的链接里面,就提到一个办法是 touching a lot of memory,这个应该是最简便的了,都不需要什么特权指令。但是这个似乎也不完全可靠,因为操作系统可能会将进程调度到另一个 cpu,这样就白填了。可能设一下 cpu affinity 会减少这类调度。
其实,我感觉这个也不是最初的问题。你说的“运行多次”,究竟是多少次?我觉得,只要运行足够多,例如几十万上百万次,缓存带来的抖动,就会被稀释,似乎不需要刻意消除。如果只是跑了几次几十次,那抖动就可能显著了。
2020-07-19 01:00:09 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@vcfghtyjc 最简单的,跑完一次,去读一下其他地方的没用内存,让 cpu 缓存填满这些没用的数据,然后再继续下一次,这样可以保证 cpu 不会命中上一次留下的。看你 cpu 的 L3 多大,读个几兆几十兆应该就能填满。
例如一开始就 malloc 一块,然后测试完一次,memcpy 这块。
2020-07-19 00:45:27 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
根据#45 楼的补充,楼主是想在多次运行同一段程序时,消除缓存带来的抖动
楼主想出的办法是关闭 cpu 缓存,但这个实际是偏离了原本的问题
原本的问题,搜 x86 performance benchmark flush cache 会有答案


拿着十年前的半桶水知识就来指点江山,呵呵
是,全世界就你知道 cpu 有 bug,这两年的什么 meltdown 、什么 specture,现代的年轻人都一无所知的!
恶臭。
2020-07-19 00:33:34 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@vcfghtyjc 你要的不是禁用缓存,是每次运行代码前 flush 缓存: https://stackoverflow.com/questions/1756825/how-can-i-do-a-cpu-cache-flush-in-x86-windows 。不用重启……
2020-07-18 16:44:01 +08:00
回复了 felix021 创建的主题 程序员 踩坑记: Go 服务灵异 panic
你们没有开 -race 的测试?

全文缩写成一句话:读写竞态。
2020-07-18 16:19:26 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@realpg 狗屁不通。
2020-07-18 16:17:52 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@imbushuo 所以这样做,可以消除 cache locality 吗?楼主就是想达到这个目的。
“不是每个人看那么仔细的,都是为了薅羊毛,谁在意这些”

不在意就不在意呗,还能怪谷歌坑?
2020-07-18 13:44:16 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
@realpg 我不知道你在说什么。反正 intel 手册里是这样写的:

11.5.3 Preventing Caching

To disable the L1, L2, and L3 caches after they have been enabled and have received cache fills, perform the following steps:

1. Enter the no-fill cache mode. (Set the CD flag in control register CR0 to 1 and the NW flag to 0.
2. Flush all caches using the WBINVD instruction.
3. Disable the MTRRs and set the default memory type to uncached or set all MTRRs for the uncached memory type (see the discussion of the discussion of the TYPE field and the E flag in Section 11.11.2.1, “IA32_MTRR_DEF_TYPE MSR”).

The caches must be flushed (step 2) after the CD flag is set to insure system memory coherency. If the caches are not flushed, cache hits on reads will still occur and data will be read from valid cache lines.The intent of the three separate steps listed above address three distinct requirements: (i) discontinue new data replacing existing data in the cache (ii) ensure data already in the cache are evicted to memory, (iii) ensure subse-quent memory references observe UC memory type semantics. Different processor implementation of caching control hardware may allow some variation of software implementation of these three requirements. See note below.

或者你可以只看第一句:“To disable the L1, L2, and L3 caches ”。
2020-07-18 13:17:34 +08:00
回复了 vcfghtyjc 创建的主题 Linux Linux 下如何关闭 CPU cache?
2020-07-18 10:47:08 +08:00
回复了 johnchshen 创建的主题 分享发现 拼多多“百亿补贴”口碑已经超越天猫
@Mavious 芯片没假货?打磨 cpu 了解一下,改固件假型号了解一下
2020-07-18 10:40:41 +08:00
回复了 miaomiao2014 创建的主题 问与答 玩 ubuntu 用 wsl2 还是虚拟机?
自己尝试自己判断,不愿意尝试就别用 linux 了
2020-07-18 10:36:27 +08:00
回复了 jss 创建的主题 程序员 [一个特殊需求] 第三方平台如何获取 vx 用户聊天记录
如果微信提供这个接口,那自愿不自愿,就不是你口头说说就可以保证的了
2020-07-17 14:43:05 +08:00
回复了 lwlizhe 创建的主题 投资 话说为什么这三天跌这么狠?
@gcy330 说得好!
@Telegram 一般说道德是约束别人的人,道德水平都是非常卑劣的,法律也是不在乎的,对付这样的人,只能用武器的批判
1 ... 67  68  69  70  71  72  73  74  75  76 ... 348  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2203 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 71ms · UTC 14:22 · PVG 22:22 · LAX 07:22 · JFK 10:22
Developed with CodeLauncher
♥ Do have faith in what you're doing.