在kernel/cpu.c中为smt建立了一个sysfs的入口,代码如下:
可以看到支持smt的cpu 有一下五种状态
static const char *smt_states[] = {
[CPU_SMT_ENABLED] = "on",
[CPU_SMT_DISABLED] = "off",
[CPU_SMT_FORCE_DISABLED] = "forceoff",
[CPU_SMT_NOT_SUPPORTED] = "notsupported",
[CPU_SMT_NOT_IMPLEMENTED] = "notimplemented",
};
static ssize_t
show_smt_control(struct device *dev, struct device_attribute *attr, char *buf)
{
const char *state = smt_states[cpu_smt_control];
return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
}
static ssize_t
store_smt_control(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return __store_smt_control(dev, attr, buf, count);
}
static DEVICE_ATTR(control, 0644, show_smt_control, store_smt_control);
static ssize_t
show_smt_active(struct device *dev, struct device_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
}
static DEVICE_ATTR(active, 0444, show_smt_active, NULL);
static struct attribute *cpuhp_smt_attrs[] = {
&dev_attr_control.attr,
&dev_attr_active.attr,
NULL
};
static const struct attribute_group cpuhp_smt_attr_group = {
.attrs = cpuhp_smt_attrs,
.name = "smt",
NULL
};
找一款不支持smt的cpu ,实际cat 如下:
[root@ip134 /]# cd ./sys/devices/system/cpu/smt
[root@ip134 smt]# ls
active control
[root@ip134 smt]# cat active
0
[root@ip134 smt]# cat control
notsupported
通过sysfs判断cpu是否支持smt
猜你喜欢
转载自blog.csdn.net/tiantao2012/article/details/113846523
今日推荐
周排行