【问题标题】:sched_setaffinity and glibc - cross-compilationsched_setaffinity 和 glibc - 交叉编译
【发布时间】:2014-07-03 01:18:48
【问题描述】:

我正在使用带有 Alpha ISA 的完整系统模拟器 (GEM5)。我已经成功交叉编译(使用 gcc-4.3.2、glibc-2.6.1)Linux 2.6.27 for Alpha。现在,我正在交叉编译我自己的调用 sched_setaffinity 函数的程序。程序编译,但在运行时它返回 -1,错误号为“功能未实现”。该函数确实在我的交叉编译内核中实现(在 kernel/sched.c 中),但该实现从未被调用。

我认为问题可能在于 Alpha 磁盘映像上的 glibc (libc-2.3.5.so) 中未定义/实现 sched_setaffinity。如果我只是用更新的交叉编译版本替换 libc-2.3.5.so,它会使磁盘映像上的其他程序无法工作。我相信 sched_setaffinity 默认情况下应该已经存在于 libc-2.3.5.so 中。有没有办法强制我的程序使用内核中的实现?什么可能导致此问题?

提前致谢!

【问题讨论】:

    标签: c gcc linux-kernel cross-compiling glibc


    【解决方案1】:

    要调用没有 libc 包装器的 perf_event_open 系统调用,我使用以下函数:

    static long
    perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
                    int cpu, int group_fd, unsigned long flags)
    {
        int ret;
    
        ret = syscall(__NR_perf_event_open, hw_event, pid, cpu,
                       group_fd, flags);
        return ret;
    }
    

    也许你应该能够做一个类似的函数来直接调用 libc sched_set_affinity 函数使用的系统调用。查看我的 Linux 源代码树版本 3.11.0,我可以在 include/uapi/asm-generic/unistd.h 中看到以下行

    #define __NR_sched_setaffinity 122
    

    【讨论】:

    • __NR_sched_setaffinity 在多个 asm-* 目录(asm-x86、cris、xtensa、m32r、mips、parisc、mn10300、m68k、frv)中定义,但不是通用的。我尝试使用所有不同的定义调用 syscall,但 errno 一直是“无效参数”。我的 asm-generic 目录中也没有“unistd.h”。我应该在某个地方定义我自己的吗?正确的方法是什么?
    猜你喜欢
    • 2011-05-20
    • 2017-02-11
    • 2019-05-26
    • 2021-07-08
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多