From nobody Wed Jul 13 14:04:39 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 328FD1CFC0E9; Wed, 13 Jul 2022 14:04:40 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LjfWX0zMCz49L6; Wed, 13 Jul 2022 14:04:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657721080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GD0gkdmO/Y0okW4BTO9okbXius436LbulBftj1tcmew=; b=FmJ22BI6FjJpVQJR26hPf4VeCdZ0FJqhxBh2e8qJxqwLCm/3eqRuftkQ/fNlTluXkETEfm Yq1AcAs/Rt7yKsaPGTCvEd43vopZRLO7/k4THMJmhT26J5A7P8Y1Zxo6OBUWobce2B8WvW ReexY1fIHOe107OB76KbY2s0PYZMYQgRC4dlblEIj7G56UTf2fNjQAwtoVZbsIc9u/pEuF r6kt+gNia+Jb70BADKGedBUK72zi92Rr3K8zpdj3cYT75pVasRHmomoNv36tOrCFr3IWfR EDFg6d6XQTaBRPVDHQ7SsEoScjx5YujC6rKN9XUrY64ZuK9O20DwFjwutEg9PA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LjfWW6vDGzQnF; Wed, 13 Jul 2022 14:04:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26DE4dO4035622; Wed, 13 Jul 2022 14:04:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26DE4dmM035621; Wed, 13 Jul 2022 14:04:39 GMT (envelope-from git) Date: Wed, 13 Jul 2022 14:04:39 GMT Message-Id: <202207131404.26DE4dmM035621@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 38e1d32dabc0 - main - callout: Simplify cpuid validation in callout_reset_sbt_on() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 38e1d32dabc015467e1eb7099fdc2b417ee9cd54 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657721080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GD0gkdmO/Y0okW4BTO9okbXius436LbulBftj1tcmew=; b=QKk3N4t0xSwJCnRxkLbcB2VQEJ6RtO+UMutJkq1ZWK37NWLGVMGxO/4nRNXesuHiUKegWC JLXQ/CAkPCHMSWEPfXKqOAgELcNnUZ7N62PrtpvP/D4xLTBCyIVeZ/W95MP/+16osR06F8 nCQaQCQxYh2tWPlUuruM0CnE5Zj0GTfjIW5j5Iqo4/Ki1Wd73qhvamFiB0iuewvy0USbh+ MAQaQ8HtTX5XTbf70AvIBr7i8fq8oAPZq9cANAP7GqO1hHbRc9s6QKzl2Sl/9PdRGAdmzq s8SYooJSvN9HAwMvr3JTE6P5JJZ2QysKtFHTn/LJF5f3gVZV6a0Lc9P85ffUyQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657721080; a=rsa-sha256; cv=none; b=M4u0zNPqzVSnWRUC6UsNIutwz/8P4t3ndU6gc3Tjg43nauI5GSEsfpuSiM/AkoWQ96TO+B MHntBTkhHTx+83vZ3s750jLnF/ZMtAciba4BL0i+Cx5h+9Mm63UC5FENL7jVsoz1MtREwO dRP8ZnirHpM5LdLJE54g/N9eRSC6eo7W6NateFSo156Uw2hDF0fdaO3eHUxPrsxyVZl7Pc R8+2uO4F7xFc6T/D00X/Wi5/TDYwt15v1URG86LyvZJdO2yqXdfLz3xTwLUEoVYk2dwtrb BkIi+xKVFYGSDwoeetv1vpsLof3x+9+J1CYp24RBwQAYrwvQ+zP8+T5jYqYwaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=38e1d32dabc015467e1eb7099fdc2b417ee9cd54 commit 38e1d32dabc015467e1eb7099fdc2b417ee9cd54 Author: Mark Johnston AuthorDate: 2022-07-13 13:42:31 +0000 Commit: Mark Johnston CommitDate: 2022-07-13 13:47:33 +0000 callout: Simplify cpuid validation in callout_reset_sbt_on() - Remove a flag variable. - Convert a runtime check of the passed cpuid to a KASSERT. - Remove the cc_inited flag. An attempt to schedule a callout before SI_SUB_CPU will crash anyway since the per-CPU mutexes won't have been initialized, and that flag was only checked in the case where a cpuid was explicitly specified by the caller. No functional change intended. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation --- sys/kern/kern_timeout.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index 121ee2b13f46..2f0705998158 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -174,7 +174,6 @@ struct callout_cpu { sbintime_t cc_lastscan; struct thread *cc_thread; u_int cc_bucket; - u_int cc_inited; #ifdef KTR char cc_ktr_event_name[20]; #endif @@ -323,7 +322,6 @@ callout_cpu_init(struct callout_cpu *cc, int cpu) int i; mtx_init(&cc->cc_lock, "callout", NULL, MTX_SPIN); - cc->cc_inited = 1; cc->cc_callwheel = malloc_domainset(sizeof(struct callout_list) * callwheelsize, M_CALLOUT, DOMAINSET_PREF(pcpu_find(cpu)->pc_domain), M_WAITOK); @@ -946,16 +944,8 @@ callout_reset_sbt_on(struct callout *c, sbintime_t sbt, sbintime_t prec, sbintime_t to_sbt, precision; struct callout_cpu *cc; int cancelled, direct; - int ignore_cpu=0; cancelled = 0; - if (cpu == -1) { - ignore_cpu = 1; - } else if ((cpu >= MAXCPU) || - ((CC_CPU(cpu))->cc_inited == 0)) { - /* Invalid CPU spec */ - panic("Invalid CPU in callout %d", cpu); - } callout_when(sbt, prec, flags, &to_sbt, &precision); /* @@ -971,13 +961,12 @@ callout_reset_sbt_on(struct callout *c, sbintime_t sbt, sbintime_t prec, KASSERT(!direct || c->c_lock == NULL || (LOCK_CLASS(c->c_lock)->lc_flags & LC_SPINLOCK), ("%s: direct callout %p has non-spin lock", __func__, c)); + cc = callout_lock(c); - /* - * Don't allow migration if the user does not care. - */ - if (ignore_cpu) { + if (cpu == -1) cpu = c->c_cpu; - } + KASSERT(cpu >= 0 && cpu <= mp_maxid && !CPU_ABSENT(cpu), + ("%s: invalid cpu %d", __func__, cpu)); if (cc_exec_curr(cc, direct) == c) { /*