From owner-svn-src-all@freebsd.org Fri Dec 4 02:28:46 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3792A4B7FB9; Fri, 4 Dec 2020 02:28:46 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CnGq214NSz3NpV; Fri, 4 Dec 2020 02:28:46 +0000 (UTC) (envelope-from kevans@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1316123EF0; Fri, 4 Dec 2020 02:28:46 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0B42Sjtx061726; Fri, 4 Dec 2020 02:28:45 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0B42SjqO061725; Fri, 4 Dec 2020 02:28:45 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202012040228.0B42SjqO061725@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 4 Dec 2020 02:28:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r368324 - stable/12/sys/kern X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/12/sys/kern X-SVN-Commit-Revision: 368324 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Dec 2020 02:28:46 -0000 Author: kevans Date: Fri Dec 4 02:28:45 2020 New Revision: 368324 URL: https://svnweb.freebsd.org/changeset/base/368324 Log: MFC r368009-r368010: kern: cpuset: minor improvements r368009: kern: cpuset: allow cpuset_create() to take an allocated *setp Currently, it must always allocate a new set to be used for passing to _cpuset_create, but it doesn't have to. This is purely kern_cpuset.c internal and it's sparsely used, so just change it to use *setp if it's not-NULL and modify the two consumers to pass in the address of a NULL cpuset. This paves the way for consumers that want the unr allocation without the possibility of sleeping as long as they've done their due diligence to ensure that the mask will properly apply atop the supplied parent (i.e. avoiding the free_unr() in the last failure path). r368010: kern: cpuset: rename _cpuset_create() to cpuset_init() cpuset_init() is better descriptor for what the function actually does. The name was previously taken by a sysinit that setup cpuset_zero's mask from all_cpus, it was removed in r331698 before stable/12 branched. A comment referencing the removed sysinit has now also been removed, since the setup previously done was moved into cpuset_thread0(). Modified: stable/12/sys/kern/kern_cpuset.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/kern/kern_cpuset.c ============================================================================== --- stable/12/sys/kern/kern_cpuset.c Fri Dec 4 02:20:41 2020 (r368323) +++ stable/12/sys/kern/kern_cpuset.c Fri Dec 4 02:28:45 2020 (r368324) @@ -287,12 +287,12 @@ cpuset_lookup(cpusetid_t setid, struct thread *td) } /* - * Create a set in the space provided in 'set' with the provided parameters. + * Initialize a set in the space provided in 'set' with the provided parameters. * The set is returned with a single ref. May return EDEADLK if the set * will have no valid cpu based on restrictions from the parent. */ static int -_cpuset_create(struct cpuset *set, struct cpuset *parent, +cpuset_init(struct cpuset *set, struct cpuset *parent, const cpuset_t *mask, struct domainset *domain, cpusetid_t id) { @@ -326,6 +326,10 @@ _cpuset_create(struct cpuset *set, struct cpuset *pare * Create a new non-anonymous set with the requested parent and mask. May * return failures if the mask is invalid or a new number can not be * allocated. + * + * If *setp is not NULL, then it will be used as-is. The caller must take + * into account that *setp will be inserted at the head of cpuset_ids and + * plan any potentially conflicting cs_link usage accordingly. */ static int cpuset_create(struct cpuset **setp, struct cpuset *parent, const cpuset_t *mask) @@ -333,16 +337,22 @@ cpuset_create(struct cpuset **setp, struct cpuset *par struct cpuset *set; cpusetid_t id; int error; + bool dofree; id = alloc_unr(cpuset_unr); if (id == -1) return (ENFILE); - *setp = set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); - error = _cpuset_create(set, parent, mask, NULL, id); + dofree = (*setp == NULL); + if (*setp != NULL) + set = *setp; + else + *setp = set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); + error = cpuset_init(set, parent, mask, NULL, id); if (error == 0) return (0); free_unr(cpuset_unr, id); - uma_zfree(cpuset_zone, set); + if (dofree) + uma_zfree(cpuset_zone, set); return (error); } @@ -978,7 +988,7 @@ cpuset_shadow(struct cpuset *set, struct cpuset **nset else d = set->cs_domain; nset = LIST_FIRST(cpusets); - error = _cpuset_create(nset, parent, mask, d, CPUSET_INVALID); + error = cpuset_init(nset, parent, mask, d, CPUSET_INVALID); if (error == 0) { LIST_REMOVE(nset, cs_link); *nsetp = nset; @@ -1458,9 +1468,7 @@ domainset_zero(void) * sets: * * 0 - The root set which should represent all valid processors in the - * system. It is initially created with a mask of all processors - * because we don't know what processors are valid until cpuset_init() - * runs. This set is immutable. + * system. This set is immutable. * 1 - The default set which all processes are a member of until changed. * This allows an administrator to move all threads off of given cpus to * dedicate them to high priority tasks or save power etc. @@ -1497,14 +1505,14 @@ cpuset_thread0(void) * Now derive a default (1), modifiable set from that to give out. */ set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); - error = _cpuset_create(set, cpuset_zero, NULL, NULL, 1); + error = cpuset_init(set, cpuset_zero, NULL, NULL, 1); KASSERT(error == 0, ("Error creating default set: %d\n", error)); cpuset_default = set; /* * Create the kernel set (2). */ set = uma_zalloc(cpuset_zone, M_WAITOK | M_ZERO); - error = _cpuset_create(set, cpuset_zero, NULL, NULL, 2); + error = cpuset_init(set, cpuset_zero, NULL, NULL, 2); KASSERT(error == 0, ("Error creating kernel set: %d\n", error)); set->cs_domain = &domainset2; cpuset_kernel = set; @@ -1557,16 +1565,17 @@ cpuset_create_root(struct prison *pr, struct cpuset ** KASSERT(pr != NULL, ("[%s:%d] invalid pr", __func__, __LINE__)); KASSERT(setp != NULL, ("[%s:%d] invalid setp", __func__, __LINE__)); - error = cpuset_create(setp, pr->pr_cpuset, &pr->pr_cpuset->cs_mask); + set = NULL; + error = cpuset_create(&set, pr->pr_cpuset, &pr->pr_cpuset->cs_mask); if (error) return (error); - KASSERT(*setp != NULL, ("[%s:%d] cpuset_create returned invalid data", + KASSERT(set != NULL, ("[%s:%d] cpuset_create returned invalid data", __func__, __LINE__)); /* Mark the set as root. */ - set = *setp; set->cs_flags |= CPU_SET_ROOT; + *setp = set; return (0); } @@ -1623,6 +1632,7 @@ sys_cpuset(struct thread *td, struct cpuset_args *uap) thread_lock(td); root = cpuset_refroot(td->td_cpuset); thread_unlock(td); + set = NULL; error = cpuset_create(&set, root, &root->cs_mask); cpuset_rel(root); if (error)