linux - native task api 测试

本文展示了如何使用特定的编程技术实现周期性任务执行,并记录每次执行之间的实际时间间隔,通过实例代码演示了任务调度、定时器使用及输出控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

#include <native/task.h>
#include <native/timer.h>

RT_TASK demo_task;

/* NOTE: error handling omitted. */

void demo(void *arg)
{
    RTIME now, previous;

    /*
     * Arguments: &task (NULL=self),
     *            start time,
     *            period (here: 1 ms)
     */
    rt_task_set_periodic(NULL, TM_NOW, 1000000);
    previous = rt_timer_read();

    while (1) {
        rt_task_wait_period(NULL);
        now = rt_timer_read();

        /*
         * NOTE: printf may have unexpected impact on the timing of
         *       your program. It is used here in the critical loop
         *       only for demonstration purposes.
         */
        printf("Time since last turn: %ld.%06ld ms\n",
               (long)(now - previous) / 1000000,
               (long)(now - previous) % 1000000);
               previous = now;
    }
}

void catch_signal(int sig)
{
}

int main(int argc, char* argv[])
{
    signal(SIGTERM, catch_signal);
    signal(SIGINT, catch_signal);

    /* Avoids memory swapping for this program */
    mlockall(MCL_CURRENT|MCL_FUTURE);

    /*
     * Arguments: &task,
     *            name,
     *            stack size (0=default),
     *            priority,
     *            mode (FPU, start suspended, ...)
     */
    rt_task_create(&demo_task, "trivial", 0, 99, 0);

    /*
     * Arguments: &task,
     *            task function,
     *            function argument
     */
    rt_task_start(&demo_task, &demo, NULL);

    pause();

    rt_task_delete(&demo_task);

    return 0;
}

 

2 测试结果:

Time since last turn: 0.997940 ms                                               
Time since last turn: 1.001939 ms                                               
Time since last turn: 0.996909 ms                                               
Time since last turn: 1.000727 ms                                               
Time since last turn: 1.003576 ms                                               
Time since last turn: 1.000606 ms                                               
Time since last turn: 0.998909 ms                                               
Time since last turn: 0.998243 ms                                               
Time since last turn: 1.001333 ms                                               
Time since last turn: 0.997636 ms                                               
Time since last turn: 1.003152 ms                                               
Time since last turn: 0.996788 ms                                               
Time since last turn: 1.000060 ms                                               
Time since last turn: 0.998667 ms                                               
Time since last turn: 1.005030 ms                                               
Time since last turn: 0.995031 ms                                               
Time since last turn: 1.002545 ms                                               
Time since last turn: 1.002303 ms                                               
Time since last turn: 0.995515 ms                                               
Time since last turn: 1.002849 ms                                               
Time since last turn: 0.997878 ms                                               
Time since last turn: 1.002000 ms                                               
Time since last turn: 0.998546 ms                                               
Time since last turn: 0.999576 ms                                               
Time since last turn: 1.002363 ms                                               
Time since last turn: 0.998425 ms                                               
Time since last turn: 0.998969 ms                                               
Time since last turn: 1.000061 ms                                               
Time since last turn: 1.002788 ms                                               
Time since last turn: 0.996848 ms                                               
Time since last turn: 1.002182 ms                                               
Time since last turn: 0.999212 ms                                               
Time since last turn: 1.001455 ms                                               
Time since last turn: 0.997636 ms                                               
Time since last turn: 1.004546 ms                                               
Time since last turn: 0.995757 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 0.998485 ms                                               
Time since last turn: 1.001333 ms                                               
Time since last turn: 0.998485 ms                                               
Time since last turn: 1.001152 ms                                               
Time since last turn: 0.999878 ms                                               
Time since last turn: 0.999334 ms                                               
Time since last turn: 1.002121 ms                                               
Time since last turn: 0.999697 ms                                               
Time since last turn: 1.000242 ms                                               
Time since last turn: 0.997697 ms                                               
Time since last turn: 1.000303 ms                                               
Time since last turn: 0.999879 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 1.000061 ms                                               
Time since last turn: 0.999636 ms                                               
Time since last turn: 1.001454 ms                                               
Time since last turn: 0.997334 ms                                               
Time since last turn: 1.004666 ms                                               
Time since last turn: 0.996910 ms                                               
Time since last turn: 1.002545 ms                                               
Time since last turn: 0.996485 ms                                               
Time since last turn: 1.001273 ms                                               
Time since last turn: 0.998666 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 0.999758 ms                                               
Time since last turn: 1.000242 ms                                               
Time since last turn: 0.999091 ms                                               
Time since last turn: 1.002909 ms                                               
Time since last turn: 1.000485 ms                                               
Time since last turn: 0.996424 ms                                               
Time since last turn: 1.001818 ms

 

ERROR: qtwayland-5.15.3+gitAUTOINC+f9dfeb6e72-r0 do_configure: Error calling /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/recipe-sysroot-native/usr/bin/qmake -makefile -o Makefile QT_BUILD_PARTS-=examples QT_BUILD_PARTS-=tests /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/git/qtwayland.pro -- -no-feature-wayland-brcm -feature-wayland-client -no-feature-wayland-drm-egl-server-buffer -feature-wayland-egl -no-feature-wayland-libhybris-egl-server-buffer -feature-wayland-server -feature-wayland-vulkan-server-buffer -no-feature-xcomposite-egl -no-feature-xcomposite-glx ERROR: qtwayland-5.15.3+gitAUTOINC+f9dfeb6e72-r0 do_configure: ExecutionError('/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055', 1, None, None) ERROR: Logfile of failure stored in: /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/log.do_configure.120055 Log data follows: | DEBUG: Executing python function extend_recipe_sysroot | NOTE: Direct dependencies are ['/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtbase-native_git.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtbase_git.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtdeclarative_git.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-qti-distro/recipes-graphics/vulkan/vulkan-headers_1.2.162.0.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-qti-gfx-prop/recipes/adreno/adreno_2.0.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-core/glibc/glibc_2.35.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/gcc/gcc-cross_11.5.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/gcc/gcc-runtime_11.5.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/quilt/quilt-native_0.67.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-graphics/wayland/wayland_1.20.0.bb:do_populate_sysroot', '/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-graphics/xorg-lib/libxkbcommon_1.4.1.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtwayland_git.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/patch/patch_2.7.6.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/pkgconfig/pkgconfig_git.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-devtools/pseudo/pseudo_git.bb:do_populate_sysroot', 'virtual:native:/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta/recipes-graphics/wayland/wayland_1.20.0.bb:do_populate_sysroot'] | NOTE: Installed into sysroot: [] | NOTE: Skipping as already exists in sysroot: ['qtbase-native', 'qtbase', 'qtdeclarative', 'vulkan-headers', 'adreno', 'glibc', 'gcc-cross-aarch64', 'gcc-runtime', 'quilt-native', 'wayland', 'libxkbcommon', 'qtwayland-native', 'patch-native', 'pkgconfig-native', 'pseudo-native', 'wayland-native', 'qtdeclarative-native', 'zlib-native', 'dbus-native', 'libgcc', 'linux-libc-headers', 'libsync', 'liblog', 'libdmabufheap', 'gbm', 'libutils', 'libcutils', 'linux-msm-headers', 'glib-2.0', 'libtool-native', 'libxml2', 'libffi', 'expat', 'wayland-protocols', 'python3-native', 'expat-native', 'xz-native', 'libffi-native', 'libxml2-native', 'attr-native', 'flex-native', 'libmpc-native', 'binutils-cross-aarch64', 'texinfo-dummy-native', 'gnu-config-native', 'mpfr-native', 'gmp-native', 'zstd-native', 'gettext-minimal-native', 'glib-2.0-native', 'libion', 'libbase', 'libvmmem', 'displaydlkm-headers', 'display-commonsys', 'safe-iop', 'util-linux', 'libselinux', 'bash-completion', 'zlib', 'libpcre', 'python3', 'ncurses-native', 'readline-native', 'libnsl2-native', 'util-linux-libuuid-native', 'openssl-native', 'sqlite3-native', 'bzip2-native', 'gdbm-native', 'libtirpc-native', 'cmake-native', 'm4-native', 'util-linux-native', 'libpcre-native', 'gettext-native', 'libvmmem-headers', 'llvm-arm-toolchain-libs-ship', 'libcap-ng', 'opkg-utils', 'libxcrypt', 'util-linux-libuuid', 'libpam', 'ncurses', 'libsepol', 'bzip2', 'openssl', 'sqlite3', 'libnsl2', 'readline', 'libtirpc', 'xz', 'gdbm', 'perl-native', 'curl-native', 'libpcre2-native', 'libcap-ng-native', 'flex', 'cracklib', 'make-native'] | DEBUG: Python function extend_recipe_sysroot finished | DEBUG: Executing shell function qmake5_base_preconfigure | DEBUG: Shell function qmake5_base_preconfigure finished | DEBUG: Executing shell function do_configure | NOTE: qmake prevar substitution: ' QT_BUILD_PARTS-=examples QT_BUILD_PARTS-=tests ' | NOTE: qmake configure substitution: ' -no-feature-wayland-brcm -feature-wayland-client -no-feature-wayland-drm-egl-server-buffer -feature-wayland-egl -no-feature-wayland-libhybris-egl-server-buffer -feature-wayland-server -feature-wayland-vulkan-server-buffer -no-feature-xcomposite-egl -no-feature-xcomposite-glx' | | Running configuration tests... | Done running configuration tests. | | Configure summary: | | Qt Wayland Drivers: | EGL .................................... yes | Raspberry Pi ........................... no | XComposite EGL ......................... no | XComposite GLX ......................... no | DRM EGL ................................ no | libhybris EGL .......................... no | Linux dma-buf server buffer integration . no | Vulkan-based server buffer integration . no | Shm emulation server buffer integration . yes | Qt Wayland Client Shell Integrations: | xdg-shell .............................. yes | xdg-shell unstable v5 (deprecated) ..... yes | xdg-shell unstable v6 .................. yes | ivi-shell .............................. yes | wl-shell (deprecated) .................. yes | Qt Wayland Client ........................ yes | Qt Wayland Compositor .................... yes | Qt Wayland Compositor Layer Plugins: | VSP2 hardware layer integration ........ no | | ERROR: Feature 'wayland-vulkan-server-buffer' was enabled, but the pre-condition 'features.wayland-client && features.vulkan && features.opengl && features.egl && tests.vulkan-server-buffer' failed. | | ERROR: Feature 'wayland-vulkan-server-buffer' was enabled, but the pre-condition 'features.wayland-server && features.vulkan && features.opengl && features.egl && tests.vulkan-server-buffer' failed. | | Check config.log for details. | ERROR: Error calling /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/recipe-sysroot-native/usr/bin/qmake -makefile -o Makefile QT_BUILD_PARTS-=examples QT_BUILD_PARTS-=tests /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/git/qtwayland.pro -- -no-feature-wayland-brcm -feature-wayland-client -no-feature-wayland-drm-egl-server-buffer -feature-wayland-egl -no-feature-wayland-libhybris-egl-server-buffer -feature-wayland-server -feature-wayland-vulkan-server-buffer -no-feature-xcomposite-egl -no-feature-xcomposite-glx | WARNING: /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055:210 exit 1 from 'exit 1' | WARNING: Backtrace (BB generated script): | #1: bbfatal_log, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055, line 210 | #2: die, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055, line 200 | #3: qmake5_base_do_configure, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055, line 186 | #4: do_configure, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055, line 154 | #5: main, /DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/build-qti-distro-rb-debug/tmp-glibc/work/aarch64-oe-linux/qtwayland/5.15.3+gitAUTOINC+f9dfeb6e72-r0/temp/run.do_configure.120055, line 214 ERROR: Task (/DATA/Joynext/zhao_w1/SA8538/LE.PRODUCT.2.1.R3/poky/meta-joynext/meta-qt5/recipes-qt/qt5/qtwayland_git.bb:do_configure) failed with exit code '1'
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值