• Re: [讨论] RT进程状态一直为R(running),cpu占用率却很低

    谢谢,我试试看

    【 在 band812 的大作中提到: 】

    : 什么是strace?

    : strace是一个非常简单的工具,它可以跟踪系统调用的执行。最简单的方式,它可以从头到尾跟踪binary的执行,然后以一行文本输出系统调用的名字,参数和返回值。

    : ...................

    11月14日
  • Re: [讨论] RT进程状态一直为R(running),cpu占用率却很低

    程序启动也不受我控制

    【 在 band812 的大作中提到: 】

    : strace或者ltrace,应该不依赖-g编译。可以看看线程在做什么

    11月13日
  • Re: [讨论] RT进程状态一直为R(running),cpu占用率却很低

    代码不是开源的,也没有-g 编译,gdb不了

    好奇如何既不阻塞退出CPU,也有没有一直执行指令(运算),是如何做到的。

    【 在 band812 的大作中提到: 】

    : 状态一直为R,CPU占用很低。

    : 应该就是一直在运行,但是做的工作不是CPU密集的类型。

    : ...................

    11月13日
  • [讨论] RT进程状态一直为R(running),cpu占用率却很低

    在一个系统中有几个Real-time 线程绑定到了固定CPU核心,

    状态一直为R(running),cpu占用率却很低,这是如何做到的?

    11月13日
  • Re: [求助] 用户态的忙等为什么没有受SMI 中断影响?

    早期TSC时钟会随着CPU频率而改变,或者随着cpu c-state t-state节能状态而变化,这个局面近年已经不存在了,最新的intel cpu都是 contant, invariable TSC,正因为这个特性,所以被用来测试smi中断时长。

    【 在 ilovecpp 的大作中提到: 】

    : 没有。不过lwn嘛

    https://lwn.net/Articles/388286/

    10月31日
  • Re: [求助] 用户态的忙等为什么没有受SMI 中断影响?

    能否提供下相关参考资料学习下?

    BIOS的手册也行。

    【 在 ilovecpp 的大作中提到: 】

    : 取决于具体的bios

    10月31日
  • Re: [求助] 用户态的忙等为什么没有受SMI 中断影响?

    为什么我查到的相关资料和你的说法向左?

    比如

    The basic idea of an SMI detector is to occupy the CPU for

    configurable amounts of time, poll the Time Stamp Counter

    (TSC) register for some period, and then look for gaps in

    the TSC data. Because SMI has the highest priority, the SMI

    detector (which runs in protected mode) is frozen in SMM. As

    the TSC timer continues to run, any gap indicates the polling

    was interrupted, and the only reason for this would be an

    SMI

    再比如

    https://lwn.net/Articles/316622/

    +    do {

    +

    +        t1 = ktime_get();

    +        t2 = ktime_get();

    +

    +        total = ktime_to_us(ktime_sub(t2, start));

    +

    +        diff = ktime_to_us(ktime_sub(t2, t1));

    +        if (diff < 0) {

    +            printk(KERN_ERR SMI_BANNER "time running backwards\n");

    +            return 1;

    +        }

    +        if (diff > sample)

    +            sample = diff; /* only want highest value per sample */

    +

    +        if (diff > smi_data->threshold)

    +            spike = t1;

    +

    +    } while (total <= USEC_PER_MSEC*smi_sample_ms);

    【 在 ilovecpp 的大作中提到: 】

    : bios代码在进smi的时候保存tsc,退出时恢复,在你用户代码看来相当于没发生smi,tsc连续增长,没有跳变。

    10月30日
  • Re: [求助] 用户态的忙等为什么没有受SMI 中断影响?

    用的TSC时钟,smi期间不走的话,时钟应该是有跳变的,疑问是用户忙等程序为什么没有感觉,用的clock_gettime monotonic获取时间。

    【 在 ilovecpp 的大作中提到: 】

    : 你用的什么时钟?

    : 有的时钟分辨率不够。

    : 而TSC有可能在SMI期间是不走的。

    10月15日
  • [求助] 用户态的忙等为什么没有受SMI 中断影响?
    loading ...
    loading ...

    问题来源:

    之前写了个忙等定时线程,单独运行在被隔离的CPU core 上(类似于cyclictest测试实时性),周期间隔为100us,10小时测试结果显示忙等具有非常好的实时性(情理之中)。

    后来了解到SMI中断是运行于操作系统以下,由BIOS生成的中断,中断过程会停止所有核心的运行,在Core 0单独执行其ISR,类似于下图

    SMI的中断长度可以用rt-tests 的hwlatdetect 间接地测出来,下面是我的主机上运行结果

    hwlatdetect: test duration 120 seconds

    Latency threshold: 10us

    Sample window: 1000000us

    Sample width: 500000us

    Non-sampling period: 500000us

    Max Latency: 16us

    Samples recorded: 1

    Samples exceeding threshold: 1

    可以看到,2分钟内,最大SMI中断有16us。

    问题是:为什么用户层的定时没有受到SMI中断的影响?如果将SMI中断算进去,任何定时程序的抖动都不应该小于SMI中断的延迟(16us)。

    问题同样适用于cyclictest在测试CPU 核心的实时性。

    10月15日
  • Re: Qt绘制点后的如何擦除,保证高速实时刷新

    一个雷达一次刷新,

    有上千个移动目标?

    【 在 bigsen 的大作中提到: 】

    : 意思是一直更新这个“信息点列表”,在paintEvent中实时重绘,不用考虑消失问题对吧?

    : 144HZ是怎么算出来的? 具体一次更新多少个点没仔细算过,但是上千个肯定是有的。

    09月22日
  • Re: Qt绘制点后的如何擦除,保证高速实时刷新

    1. 点数据是保存在model 里的;

    2. 不要的点不是被擦除,是下一次update更新;

    3. model数据变化和刷新频率是两回事(如果是固定刷新频率,点更新过快甚至都不会被显示刷新);

    感觉你还没动手写代码吧。

    【 在 bigsen 的大作中提到: 】

    : 雷达坐标系下,探测出目标需要把相关点信息绘制出来,大量的点是移动状态的,即新的位置需要绘制出新的点,原有历史点则需要删除,历史轨迹点的清除一般用什么方法?会不会慢?

    09月22日
  • Re: CS专业,《数据结构》完全无感

    科学,任课老师认为基础课程非常重要,让整个班都挂了,第二学期全部重修,现在已经是副校长了。

    【 在 Mikov 的大作中提到: 】

    : 这不科学啊

    09月21日
  • Re: 有什么比vm和vbox更底层的虚拟工具吗

    基于hypervisor 的虚拟化,直接运行在硬件之上,在其上可安装不同的操作系统,Xen和Intel最近搞得ARCN属于这一类。

    物联网、车载系统有些是这样搞,一部分跑RTOS,一部分跑GPOS 。

    【 在 lobachevsky 的大作中提到: 】

    : 如题

    : 想跑多个操作系统

    : vm和vbox这种都是在OS之上的

    : ...................

    09月07日
  • Re: 这个版推荐惠普的少,联想和thinkpad的多

    惠普黑历史太多了吧,

    最近拆了一台惠普的笔记本,是见过做工最差的,扩展功能和可维修性也很差。

    【 在 smallpanda03 的大作中提到: 】

    : 惠普的怎么样,比如暗影精灵

    08月21日
  • Re: 计算机体系架构以前冷门专业,现在应届200万了。 (转载)(3)

    过段时间就鞭尸一次啊。

    【 在 wangnb 的大作中提到: 】

    : 哪里冷门了,还有国家科技进步一等奖:透明计算。

    08月06日
  • Re: 失眠的想自杀

    我现在也是您讲的这个状态,

    平时也逼着自己躺床上休息,想念大学听电台都能睡着。

    【 在 xuwobi 的大作中提到: 】

    : 我也是伴随失眠十几年了,想办法逐步解决,要了解自己先。

    : 第一,只要我不上班不上学不工作,或者处于放假状态就不会有失眠。

    : 第二,中午不能午休否则晚上必然失眠。

    : ...................

    07月17日
  • Re: 启动 CONFIG_PREEMPT 会不会有什么坑?

    您可以参考下我的实时性测试

    https://www.newsmth.net/nForum/#!article/Circuit/362473

    【 在 socket9999 的大作中提到: 】

    : 说的是CONFIG_PREEMPT_RT吧?CONFIG_PREEMPT早就有了。

    : CONFIG_PREEMPT_RT是把Linux配置成一个实时OS,做的事情主要是中断线程化以及用rt mutex替代spinlock,对桌面应用没有太多意义。而且Linux本身的设计决定它即使开启CONFIG_PREEMPT_RT以后实时性也不会太好。

    07月12日
  • Re: Re:启动 CONFIG_PREEMPT 会不会有什么坑?

    preempt 是抢占的意思,

    最大的区别是内核是不是可抢占,

    如果一个高优先级的进程来了,能不能抢占运行在低优先级的进程,哪怕这个低优先级进入了内核甚至临界区。普通的操作系统不满足这个需求。

    Linux 并不是实时系统,preempt 开始也不可能解决所有实时性问题,watch dog,migration 优先级都是最高的99,Intel CPU 的SMM/SMI 甚至工作在OS以下,这些对实时性都有很大的影响。

    【 在 hgoldfish 的大作中提到: 】

    : 对,我就是那个意思。

    : 所以实时操作系统是不是伪需求。。只要核心多,硬件资源足,压根不需要实时操作系统?

    07月12日
  • Re: [求助] nanosleep 休眠到指定时间有固定误差

    sudo vim编辑

    和sudo echo 0 > /proc/self/timerslack_ns 没成功,还需要再看看这个文件,之前没接触过。

    【 在 Gameplayer 的大作中提到: 】

    : 不修改优先级也行, 这个文件/proc/self/timerslack_ns是可以写的,普通进程也有权限修改本进程的值,非0即可,0表示用默认值

    07月03日
  • Re: [求助] nanosleep 休眠到指定时间有固定误差

    谢谢您的解答,看来是这样的。

    #define _GNU_SOURCE

    #include <time.h>

    #include <pthread.h>

    #include <semaphore.h>

    #include <string.h>

    #include <stdio.h>

    #include <stdlib.h>

    #include <sys/types.h>

    #include <unistd.h>

    /* sleep US micro-seconds */

    #define US 100

    #define LOOP 100

    #define PRIORITY_DEFAULT 40

    #define CHECK_RET(ret,msg);

    do{

    if(ret){

    printf("%sn",msg);

    exit(-1);

    }

    }while(0);

    double sleepList[LOOP];

    double deltaList[LOOP];

    double lduraList[LOOP];

    int main(void)

    {

    int loop = 0;

    struct timespec tm1, tm2, tm2_old;

    struct timespec ts;

    int ret;

    clock_gettime(CLOCK_MONOTONIC, &tm1);

    ts.tv_sec = tm1.tv_sec;

    ts.tv_nsec = tm1.tv_nsec;

    cpu_set_t cpuset;

    CPU_ZERO(&cpuset);

    CPU_SET(4, &cpuset);

    // set core affinity

    ret = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);

    CHECK_RET(ret, "Failed to set affinity!n");

    struct sched_param param;

    int rt_prio = PRIORITY_DEFAULT;

    param.sched_priority = rt_prio;

    ret = sched_setscheduler(getpid(), SCHED_FIFO, &param);

    CHECK_RET(ret, "Fail to set scheduler to FIFOn");

    while(1){

    ts.tv_nsec = ts.tv_nsec + US * 1000L;

    ts.tv_sec = ts.tv_sec + (ts.tv_nsec)/1000000000L;

    ts.tv_nsec = (ts.tv_nsec)%1000000000;

    clock_gettime(CLOCK_MONOTONIC, &tm1);

    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);

    clock_gettime(CLOCK_MONOTONIC, &tm2);

    deltaList[loop] = (tm2.tv_sec-ts.tv_sec)*1000000.0 +

    (tm2.tv_nsec - ts.tv_nsec)/1000.0;

    if(loop > 0){

    lduraList[loop] = (tm2.tv_sec-tm2_old.tv_sec)*1000000.0 +

    (tm2.tv_nsec - tm2_old.tv_nsec)/1000.0;

    }

    tm2_old.tv_sec = tm2.tv_sec;

    tm2_old.tv_nsec = tm2.tv_nsec;

    sleepList[loop] = (tm2.tv_sec-tm1.tv_sec)*1000000.0 +

    (tm2.tv_nsec - tm1.tv_nsec)/1000.0;

    /*

    printf("delayed %ld usn", (tm2.tv_sec-ts.tv_sec)*1000000L +

    (tm2.tv_nsec - ts.tv_nsec)/1000L);

    printf("tm1:%ld:%ldn", tm1.tv_sec, tm1.tv_nsec);

    printf(" ts:%ld:%ldn", ts.tv_sec, ts.tv_nsec);

    printf("tm2:%ld:%ldn", tm2.tv_sec, tm2.tv_nsec);

    */

    ++loop;

    //printf("loop:%dn", loop);

    if(loop >= LOOP) break;

    }

    for(int ii=0; ii<LOOP; ++ii){

    printf("sleepd %4.2f delayed %4.2f loop duration %4.2f diff %4.2fn",

    sleepList[ii], deltaList[ii], lduraList[ii], (lduraList[ii] - US));

    }

    }

    修改为上面源码,输出为:

    sleepd 60.54 delayed 2.50 loop duration 0.00 diff -100.00

    sleepd 97.03 delayed 1.38 loop duration 98.89 diff -1.11

    sleepd 99.95 delayed 1.37 loop duration 99.99 diff -0.01

    sleepd 99.87 delayed 1.26 loop duration 99.89 diff -0.11

    sleepd 99.94 delayed 1.22 loop duration 99.96 diff -0.04

    sleepd 99.97 delayed 1.21 loop duration 99.99 diff -0.01

    sleepd 100.09 delayed 1.32 loop duration 100.11 diff 0.11

    sleepd 99.97 delayed 1.31 loop duration 99.98 diff -0.02

    sleepd 99.97 delayed 1.30 loop duration 100.00 diff -0.00

    sleepd 99.94 delayed 1.26 loop duration 99.96 diff -0.04

    sleepd 100.03 delayed 1.31 loop duration 100.05 diff 0.05

    sleepd 99.95 delayed 1.29 loop duration 99.97 diff -0.03

    sleepd 99.94 delayed 1.25 loop duration 99.96 diff -0.04

    sleepd 99.98 delayed 1.25 loop duration 100.00 diff -0.00

    sleepd 100.04 delayed 1.31 loop duration 100.06 diff 0.06

    sleepd 99.96 delayed 1.29 loop duration 99.98 diff -0.02

    sleepd 99.98 delayed 1.30 loop duration 100.00 diff 0.00

    sleepd 100.01 delayed 1.33 loop duration 100.03 diff 0.03

    sleepd 99.96 delayed 1.31 loop duration 99.98 diff -0.02

    sleepd 99.94 delayed 1.27 loop duration 99.96 diff -0.04

    sleepd 99.94 delayed 1.23 loop duration 99.96 diff -0.04

    sleepd 99.98 delayed 1.24 loop duration 100.00 diff 0.00

    sleepd 100.05 delayed 1.31 loop duration 100.07 diff 0.07

    sleepd 99.96 delayed 1.29 loop duration 99.98 diff -0.02

    sleepd 99.98 delayed 1.28 loop duration 100.00 diff -0.00

    sleepd 99.94 delayed 1.25 loop duration 99.96 diff -0.04

    sleepd 100.03 delayed 1.30 loop duration 100.05 diff 0.05

    sleepd 99.97 delayed 1.29 loop duration 99.99 diff -0.01

    sleepd 99.92 delayed 1.23 loop duration 99.94 diff -0.06

    sleepd 99.98 delayed 1.23 loop duration 100.00 diff -0.00

    sleepd 100.05 delayed 1.29 loop duration 100.07 diff 0.07

    sleepd 99.98 delayed 1.29 loop duration 100.00 diff -0.00

    sleepd 99.97 delayed 1.28 loop duration 99.99 diff -0.01

    sleepd 99.94 delayed 1.24 loop duration 99.96 diff -0.04

    sleepd 100.02 delayed 1.29 loop duration 100.05 diff 0.05

    sleepd 99.95 delayed 1.26 loop duration 99.97 diff -0.03

    sleepd 99.94 delayed 1.22 loop duration 99.96 diff -0.04

    sleepd 99.98 delayed 1.22 loop duration 100.00 diff -0.00

    sleepd 100.07 delayed 1.31 loop duration 100.09 diff 0.09

    sleepd 99.94 delayed 1.27 loop duration 99.97 diff -0.03

    sleepd 100.02 delayed 1.32 loop duration 100.04 diff 0.04

    sleepd 99.90 delayed 1.23 loop duration 99.92 diff -0.08

    sleepd 100.07 delayed 1.32 loop duration 100.09 diff 0.09

    sleepd 99.87 delayed 1.21 loop duration 99.89 diff -0.11

    sleepd 99.97 delayed 1.21 loop duration 100.00 diff -0.00

    sleepd 99.97 delayed 1.20 loop duration 99.99 diff -0.01

    sleepd 100.10 delayed 1.32 loop duration 100.12 diff 0.12

    sleepd 99.97 delayed 1.31 loop duration 99.99 diff -0.01

    sleepd 100.00 delayed 1.33 loop duration 100.02 diff 0.02

    sleepd 99.96 delayed 1.30 loop duration 99.98 diff -0.02

    sleepd 99.99 delayed 1.31 loop duration 100.01 diff 0.01

    sleepd 99.91 delayed 1.25 loop duration 99.93 diff -0.07

    sleepd 99.98 delayed 1.25 loop duration 100.00 diff -0.00

    sleepd 99.96 delayed 1.23 loop duration 99.98 diff -0.02

    sleepd 100.06 delayed 1.31 loop duration 100.08 diff 0.08

    sleepd 99.98 delayed 1.30 loop duration 100.00 diff -0.00

    sleepd 99.97 delayed 1.29 loop duration 99.99 diff -0.01

    sleepd 99.98 delayed 1.29 loop duration 100.00 diff 0.00

    sleepd 99.99 delayed 1.31 loop duration 100.01 diff 0.01

    sleepd 99.94 delayed 1.26 loop duration 99.96 diff -0.04

    sleepd 99.95 delayed 1.24 loop duration 99.98 diff -0.02

    sleepd 99.97 delayed 1.23 loop duration 99.99 diff -0.01

    sleepd 100.06 delayed 1.30 loop duration 100.08 diff 0.08

    sleepd 99.98 delayed 1.30 loop duration 100.00 diff -0.00

    sleepd 99.96 delayed 1.28 loop duration 99.98 diff -0.02

    sleepd 99.97 delayed 1.28 loop duration 100.00 diff -0.00

    sleepd 100.00 delayed 1.30 loop duration 100.02 diff 0.02

    sleepd 99.92 delayed 1.24 loop duration 99.94 diff -0.06

    sleepd 99.96 delayed 1.23 loop duration 99.98 diff -0.02

    sleepd 100.00 delayed 1.25 loop duration 100.02 diff 0.02

    sleepd 100.03 delayed 1.30 loop duration 100.05 diff 0.05

    sleepd 99.97 delayed 1.29 loop duration 99.99 diff -0.01

    sleepd 100.19 delayed 1.50 loop duration 100.22 diff 0.22

    sleepd 99.78 delayed 1.30 loop duration 99.80 diff -0.20

    sleepd 99.94 delayed 1.27 loop duration 99.97 diff -0.03

    sleepd 99.98 delayed 1.27 loop duration 100.00 diff 0.00

    sleepd 99.92 delayed 1.21 loop duration 99.95 diff -0.05

    sleepd 100.05 delayed 1.29 loop duration 100.08 diff 0.08

    sleepd 99.98 delayed 1.29 loop duration 100.00 diff 0.00

    sleepd 99.96 delayed 1.27 loop duration 99.98 diff -0.02

    sleepd 100.01 delayed 1.30 loop duration 100.03 diff 0.03

    sleepd 99.96 delayed 1.28 loop duration 99.98 diff -0.02

    sleepd 100.00 delayed 1.30 loop duration 100.02 diff 0.02

    sleepd 99.92 delayed 1.25 loop duration 99.95 diff -0.05

    sleepd 99.94 delayed 1.21 loop duration 99.96 diff -0.04

    sleepd 100.05 delayed 1.28 loop duration 100.07 diff 0.07

    sleepd 100.02 delayed 1.32 loop duration 100.04 diff 0.04

    sleepd 99.96 delayed 1.31 loop duration 99.99 diff -0.01

    sleepd 99.97 delayed 1.31 loop duration 100.00 diff -0.00

    sleepd 100.00 delayed 1.33 loop duration 100.02 diff 0.02

    sleepd 99.97 delayed 1.32 loop duration 99.99 diff -0.01

    sleepd 99.95 delayed 1.28 loop duration 99.97 diff -0.03

    sleepd 99.94 delayed 1.24 loop duration 99.96 diff -0.04

    sleepd 100.05 delayed 1.31 loop duration 100.07 diff 0.07

    sleepd 99.98 delayed 1.31 loop duration 100.00 diff -0.00

    sleepd 99.97 delayed 1.30 loop duration 99.99 diff -0.01

    sleepd 99.98 delayed 1.30 loop duration 100.00 diff 0.00

    sleepd 99.99 delayed 1.32 loop duration 100.01 diff 0.01

    sleepd 99.95 delayed 1.29 loop duration 99.97 diff -0.03

    sleepd 99.97 delayed 1.27 loop duration 99.99 diff -0.01

    【 在 Gameplayer 的大作中提到: 】

    : nanosleep对普通优先级的进程有一个延迟(slack),可以从proc下读取:

    : cat /proc/self/timerslack_ns

    : 50000

    : ...................

    07月03日