我正在尝试打印 cpus ,允许运行特定任务。
在 struct task_struct (可以找到here)里面有 cpumask_t cpus_allowed ,根据我的理解,其中包含我正在寻找的内容。 是对的吗 ?
如果是这样,我如何提取允许的cpus号码?
例如我的comp有8个逻辑核心 - 所以我期待 cpus_allowed 中的某个地方我可以找到这些数字(例如 - 0,2,5)
答案 0 :(得分:1)
宏final CheckBox ChckBoxNo = (CheckBox) promptsView.findViewById(R.id.ChkBoxNo);
final CheckBox ChckBoxYes = (CheckBox) promptsView.findViewById(R.id.ChkBoxYes);
ChckBoxNo.setChecked(true);
ChckBoxYes.setChecked(false);
ChckBoxNo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (ChckBoxNo.isChecked()) {
ChckBoxYes.setChecked(false);
} else if (!ChckBoxNo.isChecked()) {
ChckBoxYes.setChecked(true);
}
}
});
ChckBoxYes.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (ChckBoxYes.isChecked()) {
ChckBoxNo.setChecked(false);
} else if (!ChckBoxYes.isChecked()) {
ChckBoxNo.setChecked(true);
}
}
});
//these if's allways response to "ChckBoxNo.IsChecked()" ,even if its the
// opposite and "ChckBoxYes.isChcked()"
if(ChckBoxYes.isChecked())
{do ...
}
else if (ChckBoxNo.isChecked()
{ do ...
}
将迭代所有CPU,由给定的掩码允许:
for_each_cpu
答案 1 :(得分:0)
好的,我发现内核中的一个函数完全符合cpumask.h cpumask_scnprintf 所需的内容:
/**
* cpumask_scnprintf - print a cpumask into a string as comma-separated hex
* @buf: the buffer to sprintf into
* @len: the length of the buffer
* @srcp: the cpumask to print
*
* If len is zero, returns zero. Otherwise returns the length of the
* (nul-terminated) @buf string.
*/
static inline int cpumask_scnprintf(char *buf, int len,
const struct cpumask *srcp)
{
return bitmap_scnprintf(buf, len, cpumask_bits(srcp), nr_cpumask_bits);
}
答案 2 :(得分:0)