簡體   English   中英

未找到 DEADLINE 調度策略

[英]DEADLINE scheduling policy not found

我想在 C 中實現 DEADLINE 調度策略。我知道該功能是從Linux 3.14.10實現的,我使用的是 Ubuntu 14.04 Linux #### 3.17.0-031700-lowlatency #201410060605 SMP PREEMPT應該足夠新. 我使用 Eclipse(以 sudo 啟動)開發程序。

我已經定義了_GNU_SOURCE並包含了sched.h ,但我仍然無法使用關鍵字SCHED_DEADLINE來定義struct sched_attr或使用像sched_getattr這樣的sched_getattr

#define _GNU_SOURCE
#include <sched.h>

這些關鍵字和函數都沒有在我的/usr/include/文件夾中定義,但我設法在/usr/src/linux-headers-3.17.0-031700/include/找到它們。 我試圖在我的項目的構建選項中包含這個文件夾,但它似乎產生了鏈接錯誤。

我不太習慣 C 開發(我最初是 JS 開發人員)所以如果有人能解釋我做錯了什么以及如何解決這個問題,那將是非常好的。

/usr/include/linux/sched.h內容

#ifndef _LINUX_SCHED_H
#define _LINUX_SCHED_H

/*
 * cloning flags:
 */
#define CSIGNAL     0x000000ff  /* signal mask to be sent at exit */
#define CLONE_VM    0x00000100  /* set if VM shared between processes */
#define CLONE_FS    0x00000200  /* set if fs info shared between processes */
#define CLONE_FILES 0x00000400  /* set if open files shared between processes */
#define CLONE_SIGHAND   0x00000800  /* set if signal handlers and blocked signals shared */
#define CLONE_PTRACE    0x00002000  /* set if we want to let tracing continue on the child too */
#define CLONE_VFORK 0x00004000  /* set if the parent wants the child to wake it up on mm_release */
#define CLONE_PARENT    0x00008000  /* set if we want to have the same parent as the cloner */
#define CLONE_THREAD    0x00010000  /* Same thread group? */
#define CLONE_NEWNS 0x00020000  /* New namespace group? */
#define CLONE_SYSVSEM   0x00040000  /* share system V SEM_UNDO semantics */
#define CLONE_SETTLS    0x00080000  /* create a new TLS for the child */
#define CLONE_PARENT_SETTID 0x00100000  /* set the TID in the parent */
#define CLONE_CHILD_CLEARTID    0x00200000  /* clear the TID in the child */
#define CLONE_DETACHED      0x00400000  /* Unused, ignored */
#define CLONE_UNTRACED      0x00800000  /* set if the tracing process can't force CLONE_PTRACE on this clone */
#define CLONE_CHILD_SETTID  0x01000000  /* set the TID in the child */
/* 0x02000000 was previously the unused CLONE_STOPPED (Start in stopped state)
   and is now available for re-use. */
#define CLONE_NEWUTS        0x04000000  /* New utsname group? */
#define CLONE_NEWIPC        0x08000000  /* New ipcs */
#define CLONE_NEWUSER       0x10000000  /* New user namespace */
#define CLONE_NEWPID        0x20000000  /* New pid namespace */
#define CLONE_NEWNET        0x40000000  /* New network namespace */
#define CLONE_IO        0x80000000  /* Clone io context */

/*
 * Scheduling policies
 */
#define SCHED_NORMAL        0
#define SCHED_FIFO      1
#define SCHED_RR        2
#define SCHED_BATCH     3
/* SCHED_ISO: reserved but not implemented yet */
#define SCHED_IDLE      5
/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
#define SCHED_RESET_ON_FORK     0x40000000


#endif /* _LINUX_SCHED_H */

編輯

我想要的文件位於/usr/src/linux-headers-3.17.0-031700/include/文件夾中。 無論如何,我嘗試使用多種方法將該文件夾添加到我的項目中。 首先使用 gcc 的-I標志,然后使用C_INCLUDE_PATH環境變量。

在這兩種方式中,gcc 在默認位置優先搜索並找到錯誤的<sched.h>文件。 我嘗試使用-nostdinc選項來抑制默認位置,但這更糟糕......我遇到了很多錯誤。

我實際上升級到了kernel 4.4.0-21-lowlatency Ubuntu 16.04 LTS ,現在默認定義了關鍵字SCHED_DEADLINE

問題是struct sched_attr和方法sched_getattr() / sched_setattr()仍然缺失!

經過一些研究(感謝谷歌)我發現這篇文章是由內核開發者發布的。 在文檔的最后,描述了如何使用截止時間調度策略。 他們只是自己定義結構並使用syscall來獲取/設置方法。

答案可能取決於分布! 此示例基於 Debian 8.4

另外,在這些情況下,您會發現兩個有用的工具 - 都可以在 debian 的存儲庫中使用 - ack ( ack-grep ) 和locate ack 將幫助您在所有子目錄中找到給定的字符串,而 locate 將幫助您找到實際文件(在updatedb之后)如果它存在於您的系統中。 例如,您可以使用locate sched.h從 root 開始找到所有文件,如locate sched.h

首先你應該#include 如果你沒有這個特定的包含,嘗試從存儲庫下載它,如果你使用的是 Debian - 這個文件可以在(最好是最新的) libc6-dev 中找到(注意開發包將包含包含和頭文件用於開發目的)或linux-headers

此外,如果您的編譯器找不到linux/sched.h嘗試給編譯器一個路徑提示,在我的情況下它將是: gcc -I/usr/include (在這種情況下完全沒用 - 這是 linux 中的默認包含目錄)

注意/usr/include/linux/sched.h/usr/include/sched.h可能略有不同

顯然,盡管三年前SCHED_DEADLINE成為主線,libc 的包含文件仍然缺少截止時間調度程序的接口(即sched_setattr()sched_getattr()sched_attr等)。 這種行為在某種程度上類似於讓 libc 包裝getttid()系統調用的時間

因此,目前最好的選擇是從 GitHub 下載 rt-app並使用libdl接口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM