在内核文件sched.c中有这样的应用,记录如下:
#define SCHED_FEAT(name, enabled) /
__SCHED_FEAT_##name ,
enum {
#include "sched_features.h"
};
#undef SCHED_FEAT
#define SCHED_FEAT(name, enabled) /
(1UL << __SCHED_FEAT_##name) * enabled |
const_debug unsigned int sysctl_sched_features =
#include "sched_features.h"
0;
其中sched_features.h文件中内容如下,为了看着方便,去掉其中的注释:
SCHED_FEAT(FAIR_SLEEPERS, 1)
SCHED_FEAT(GENTLE_FAIR_SLEEPERS, 1)
SCHED_FEAT(NORMALIZED_SLEEPER, 0)
SCHED_FEAT(START_DEBIT, 1)
SCHED_FEAT(WAKEUP_PREEMPT, 1)
SCHED_FEAT(ADAPTIVE_GRAN, 1)
SCHED_FEAT(ASYM_GRAN, 1)
SCHED_FEAT(WAKEUP_SYNC, 0)
SCHED_FEAT(WAKEUP_OVERLAP, 0)
SCHED_FEAT(WAKEUP_RUNNING, 0)
SCHED_FEAT(SYNC_WAKEUPS, 1)
SCHED_FEAT(AFFINE_WAKEUPS, 1)
SCHED_FEAT(SYNC_LESS, 1)
SCHED_FEAT(SYNC_MORE, 0)
SCHED_FEAT(NEXT_BUDDY, 0)
SCHED_FEAT(LAST_BUDDY, 1)
SCHED_FEAT(CACHE_HOT_BUDDY, 1)
SCHED_FEAT(ARCH_POWER, 0)
SCHED_FEAT(HRTICK, 0)
SCHED_FEAT(DOUBLE_TICK, 0)
SCHED_FEAT(LB_BIAS, 1)
SCHED_FEAT(LB_SHARES_UPDATE, 1)
SCHED_FEAT(ASYM_EFF_LOAD, 1)
SCHED_FEAT(OWNER_SPIN, 1)
这个宏替换之后会是神马样子呢?编了一个小文件main.c, 用gcc -E main.c > main.txt 看了一下, 以下是main.txt中内容
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "main.c"
enum{
# 1 "sched_features.h" 1
__SCHED_FEAT_FAIR_SLEEPERS,
__SCHED_FEAT_GENTLE_FAIR_SLEEPERS,
__SCHED_FEAT_NORMALIZED_SLEEPER,
__SCHED_FEAT_START_DEBIT,
__SCHED_FEAT_WAKEUP_PREEMPT,
__SCHED_FEAT_ADAPTIVE_GRAN,
__SCHED_FEAT_ASYM_GRAN,
__SCHED_FEAT_WAKEUP_SYNC,
__SCHED_FEAT_WAKEUP_OVERLAP,
__SCHED_FEAT_WAKEUP_RUNNING,
__SCHED_FEAT_SYNC_WAKEUPS,
__SCHED_FEAT_AFFINE_WAKEUPS,
__SCHED_FEAT_SYNC_LESS,
__SCHED_FEAT_SYNC_MORE,
__SCHED_FEAT_NEXT_BUDDY,
__SCHED_FEAT_LAST_BUDDY,
__SCHED_FEAT_CACHE_HOT_BUDDY,
__SCHED_FEAT_ARCH_POWER,
__SCHED_FEAT_HRTICK,
__SCHED_FEAT_DOUBLE_TICK,
__SCHED_FEAT_LB_BIAS,
__SCHED_FEAT_LB_SHARES_UPDATE,
__SCHED_FEAT_ASYM_EFF_LOAD,
__SCHED_FEAT_OWNER_SPIN,
# 7 "main.c" 2
};
unsigned int sysctl_sched_features =
# 1 "sched_features.h" 1
(1UL << __SCHED_FEAT_FAIR_SLEEPERS) * 1 |
(1UL << __SCHED_FEAT_GENTLE_FAIR_SLEEPERS) * 1 |
(1UL << __SCHED_FEAT_NORMALIZED_SLEEPER) * 0 |
(1UL << __SCHED_FEAT_START_DEBIT) * 1 |
(1UL << __SCHED_FEAT_WAKEUP_PREEMPT) * 1 |
(1UL << __SCHED_FEAT_ADAPTIVE_GRAN) * 1 |
(1UL << __SCHED_FEAT_ASYM_GRAN) * 1 |
(1UL << __SCHED_FEAT_WAKEUP_SYNC) * 0 |
(1UL << __SCHED_FEAT_WAKEUP_OVERLAP) * 0 |
(1UL << __SCHED_FEAT_WAKEUP_RUNNING) * 0 |
(1UL << __SCHED_FEAT_SYNC_WAKEUPS) * 1 |
(1UL << __SCHED_FEAT_AFFINE_WAKEUPS) * 1 |
(1UL << __SCHED_FEAT_SYNC_LESS) * 1 |
(1UL << __SCHED_FEAT_SYNC_MORE) * 0 |
(1UL << __SCHED_FEAT_NEXT_BUDDY) * 0 |
(1UL << __SCHED_FEAT_LAST_BUDDY) * 1 |
(1UL << __SCHED_FEAT_CACHE_HOT_BUDDY) * 1 |
(1UL << __SCHED_FEAT_ARCH_POWER) * 0 |
(1UL << __SCHED_FEAT_HRTICK) * 0 |
(1UL << __SCHED_FEAT_DOUBLE_TICK) * 0 |
(1UL << __SCHED_FEAT_LB_BIAS) * 1 |
(1UL << __SCHED_FEAT_LB_SHARES_UPDATE) * 1 |
(1UL << __SCHED_FEAT_ASYM_EFF_LOAD) * 1 |
(1UL << __SCHED_FEAT_OWNER_SPIN) * 1 |
# 16 "main.c" 2
0;
int main(int argc, char **argv)
{
return 0;
}