Comments (7)
我修改了下test.cc,去掉了<bits/stdc++.h>,并去掉了sleep1秒的注释,这样可以大大提高精度降低误差
from tscns.
只需要init一次,可以重复calibrate,这样不用等10ms,也不会有多线程问题
from tscns.
多路上面可能不准,通常情况下要定期校验,
多线程情况下周期性调用init 是否有问题?
include <bits/stdc++.h> 在macOS clang++上无法编译,似乎已经不是c++标准头文件了(gcc 保留)
from tscns.
可以周期性重复调用calibrate(),这是多线程安全的
from tscns.
服务器跨平台使用修改rdsysns,使用steady_clock 是否比high_resolution_clock 更稳定 还是没太大区别?
改成steady_clock 后,测试数据不一样,b2c 数据误差持续变大
a: 14642789863999881, b: 14642789864006251, c: 14642789864006229, a2b: 6370, b2c: -22, good: 0, rdsysns_latency: 6339
a: 14642790864015103, b: 14642790864021136, c: 14642790864021107, a2b: 6033, b2c: -29, good: 0, rdsysns_latency: 5995
a: 14642791864033885, b: 14642791864034313, c: 14642791864034287, a2b: 428, b2c: -26, good: 0, rdsysns_latency: 393
a: 14642792864040781, b: 14642792864041466, c: 14642792864041427, a2b: 685, b2c: -39, good: 0, rdsysns_latency: 637
...
a: 14643039691289192, b: 14643039691290108, c: 14643039691289648, a2b: 916, b2c: -460, good: 0, rdsysns_latency: 447
a: 14643040691297430, b: 14643040691298408, c: 14643040691297938, a2b: 978, b2c: -470, good: 0, rdsysns_latency: 499
定期同步校验init()每次至少10ms等待, 对于服务器有点卡
from tscns.
下面这段代码每200ms运行一次,为减少同步卡顿,做了如下校验不知是否有问题
void Clock::AdjustTime() const
{
const auto nowns = tn.rdns();
const auto nowss = tn.rdsysns(); //steady clock
if (std::abs(nowns - nowss) > 1000)
tn.init();
}
- 调整后的时钟是否因为较准往前回拨?
- ns_offset 变量(不同线程读写不会有同步问题?)
from tscns.
笔记本上使用发现时间漂移比较严重,盒盖再翻盖后时钟误差巨大,甚至出现回拨现象,按如下解决
void Clock::AdjustTime() const
{
const auto nowns = tn.rdns();
const auto nowss = tn.rdsysns(); //steady clock
if (std::abs(nowns - nowss) > 10'000) //误差比较大,频率可能发生较大变化
tn.init();
else if (std::abs(nowns - nowss) > 1000) //小范围内对齐
tn.calibrate();
}
from tscns.
Related Issues (12)
- Use constructor instead of init function HOT 1
- TSC计时在超频服务器上的问题 HOT 3
- 含有编译时错误 HOT 1
- 如果不定期calibrate(),int64_t转double做运算有数值溢出或精度损失风险 HOT 1
- Concurrency safe? HOT 1
- 关于sleep影响计时准确性的问题 HOT 1
- Need mfence after builtin_ia32_rtscp HOT 1
- rdns of HOT 2
- do it like the kernel HOT 3
- 精度不高的一个简单解决方案 HOT 3
- 请教为什么从rdtscp改回了rdtsc HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tscns.