From owner-svn-src-head@freebsd.org Sat Mar 18 18:38:14 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5BD3ED12614; Sat, 18 Mar 2017 18:38:14 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0EF1011EC; Sat, 18 Mar 2017 18:38:13 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2IIcD0C075587; Sat, 18 Mar 2017 18:38:13 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2IIcDGQ075586; Sat, 18 Mar 2017 18:38:13 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201703181838.v2IIcDGQ075586@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Sat, 18 Mar 2017 18:38:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315506 - head/sys/compat/linsysfs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Mar 2017 18:38:14 -0000 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); }