【发布时间】:2019-12-21 15:07:01
【问题描述】:
我对 Linux 内核中 kernel/sched/sched.h 中的代码感到困惑。 就像 kernel.org 中的最新版本代码一样。 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/sched/sched.h?h=v5.3-rc4 第 285-299 行。
__dl_update(dl_b, (s32)tsk_bw / cpus);
函数“__dl_update”在第二个参数中需要 s64 类型。 tsk_bw 是 u64 类型。 为什么使用“s32”而不是“s64”???
static inline void __dl_update(struct dl_bw *dl_b, s64 bw);
static inline
void __dl_sub(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
{
dl_b->total_bw -= tsk_bw;
__dl_update(dl_b, (s32)tsk_bw / cpus);
}
static inline
void __dl_add(struct dl_bw *dl_b, u64 tsk_bw, int cpus)
{
dl_b->total_bw += tsk_bw;
__dl_update(dl_b, -((s32)tsk_bw / cpus));
}
static inline
bool __dl_overflow(struct dl_bw *dl_b, int cpus, u64 old_bw, u64 new_bw)
{
return dl_b->bw != -1 &&
dl_b->bw * cpus < dl_b->total_bw - old_bw + new_bw;
}
【问题讨论】: