Date: Sat, 18 Mar 2017 18:38:13 +0000 (UTC) From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315506 - head/sys/compat/linsysfs Message-ID: <201703181838.v2IIcDGQ075586@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dchagin Date: Sat Mar 18 18:38:12 2017 New Revision: 315506 URL: https://svnweb.freebsd.org/changeset/base/315506 Log: 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 Modified: head/sys/compat/linsysfs/linsysfs.c Modified: head/sys/compat/linsysfs/linsysfs.c ============================================================================== --- head/sys/compat/linsysfs/linsysfs.c Sat Mar 18 18:34:29 2017 (r315505) +++ head/sys/compat/linsysfs/linsysfs.c Sat Mar 18 18:38:12 2017 (r315506) @@ -221,13 +221,62 @@ linsysfs_run_bus(device_t dev, struct pf } /* + * 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 */ 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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703181838.v2IIcDGQ075586>