Glibc get_nprocs() and get_nprocs_conf() uses the sysfs cpu infrastructure

to get number of processors. Implement /sys/devices/system/cpu/.

MFC after:	1 month
This commit is contained in:
Dmitry Chagin 2017-03-18 18:38:12 +00:00
parent b1ba0846f1
commit 039aba0861

View File

@ -220,6 +220,55 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, char
return (1);
}
/*
* Filler function for sys/devices/system/cpu/online
*/
static int
linsysfs_cpuonline(PFS_FILL_ARGS)
{
sbuf_printf(sb, "%d-%d\n", CPU_FIRST(), mp_maxid);
return (0);
}
/*
* Filler function for sys/devices/system/cpu/cpuX/online
*/
static int
linsysfs_cpuxonline(PFS_FILL_ARGS)
{
sbuf_printf(sb, "1\n");
return (0);
}
static void
linsysfs_listcpus(struct pfs_node *dir)
{
struct pfs_node *cpu;
char *name;
int i, count, len;
len = 1;
count = mp_maxcpus;
while (count > 10) {
count /= 10;
len++;
}
len += sizeof("cpu");
name = malloc(len, M_TEMP, M_WAITOK);
for (i = 0; i < mp_ncpus; ++i) {
/* /sys/devices/system/cpu/cpuX */
sprintf(name, "cpu%d", i);
cpu = pfs_create_dir(dir, name, NULL, NULL, NULL, 0);
pfs_create_file(cpu, "online", &linsysfs_cpuxonline,
NULL, NULL, NULL, PFS_RD);
}
free(name, M_TEMP);
}
/*
* Constructor
*/
@ -227,7 +276,7 @@ static int
linsysfs_init(PFS_INIT_ARGS)
{
struct pfs_node *root;
struct pfs_node *dir;
struct pfs_node *dir, *sys, *cpu;
struct pfs_node *pci;
struct pfs_node *scsi;
devclass_t devclass;
@ -241,10 +290,10 @@ linsysfs_init(PFS_INIT_ARGS)
scsi = pfs_create_dir(root, "class", NULL, NULL, NULL, 0);
scsi = pfs_create_dir(scsi, "scsi_host", NULL, NULL, NULL, 0);
/* /sys/device */
/* /sys/devices */
dir = pfs_create_dir(root, "devices", NULL, NULL, NULL, 0);
/* /sys/device/pci0000:00 */
/* /sys/devices/pci0000:00 */
pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0);
devclass = devclass_find("root");
@ -254,6 +303,18 @@ linsysfs_init(PFS_INIT_ARGS)
dev = devclass_get_device(devclass, 0);
linsysfs_run_bus(dev, pci, scsi, "/pci0000:00", "0000");
/* /sys/devices/system */
sys = pfs_create_dir(dir, "system", NULL, NULL, NULL, 0);
/* /sys/devices/system/cpu */
cpu = pfs_create_dir(sys, "cpu", NULL, NULL, NULL, 0);
pfs_create_file(cpu, "online", &linsysfs_cpuonline,
NULL, NULL, NULL, PFS_RD);
linsysfs_listcpus(cpu);
return (0);
}