From nobody Tue Dec 07 18:19:40 2021 X-Original-To: dev-commits-src-all@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 C371218C09AB; Tue, 7 Dec 2021 18:19: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 4J7pVN2QCnz4bH7; Tue, 7 Dec 2021 18:19:40 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2EA8E246EC; Tue, 7 Dec 2021 18:19:40 +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 1B7IJeRu048478; Tue, 7 Dec 2021 18:19:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B7IJeuB048477; Tue, 7 Dec 2021 18:19:40 GMT (envelope-from git) Date: Tue, 7 Dec 2021 18:19:40 GMT Message-Id: <202112071819.1B7IJeuB048477@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: b3f404d51f29 - stable/12 - Implement GET_STACK_USAGE on remaining archs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b3f404d51f292644fa2b4ade5dc740018a4440e7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638901180; 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=hwqXi7P8VlPs7hJ2V3gabffuw4sus3+OmHaUugkdrQc=; b=pfVPTDfjdY2LPVkT54pnF6r3ZgAbmpAdU4Jwf0C5U/oWZTq/BJddL/AGbnwgN3SDT05BVd A6671mAT96q3ji/TL/HFZM3ip1WK/3m+1NW+zVTJFC4R5Q0RqA5VMwCDGcknoMeEMKG4LL eKLVgCFLvrY0GZX5uHs4wB8p6C0OMA+0/qyd9ufaovAYFdBqXAFZQSf47hXbPS1cBWilMH ADeRAG6fb46eQ7Nuwkq/EkJBZFFykGM/CYgX9oy6lIqkGqJHtWBJgHn1RLFSYkord4j2o4 +oF7yNDtiqG8OFRrP+A9EzpfmFAVvjBn3qPdVnIH49944KpVJgoB31S2goKkvA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638901180; a=rsa-sha256; cv=none; b=VE1CAWeBr1/tSzAMy9j8pCweNVk6tZriFiPyyV5vDawGio1LwiPQ7CXMrbYWSVmVWQuJnX Bz9MrKHGWJxyXm5Q5ENm1kOqqTDa/er+kQ4IcIJ2T4vn+FJT1Qdz6X/MuRpoXU/wRryxpM 96RQZ106ghuFg0FlYYKwkmEGuoLheRAlLyGGY5QGzi2BUQFz/H4ZWZ1nlqFTnv9Re8+Wyi q2b7lqHXgFRkh+xnpmhP20FbTIlov8ymPPSvzX7BuDzGuVjJvv7QHf/MmmYVPEzpTWU7rb W87q5L9uA3E17GRqDGyG40QKhhdLHD4WNWoiTngEF0RVI0SeRMJqlRgiHc9ylQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=b3f404d51f292644fa2b4ade5dc740018a4440e7 commit b3f404d51f292644fa2b4ade5dc740018a4440e7 Author: Mitchell Horne AuthorDate: 2021-11-25 16:01:11 +0000 Commit: Mitchell Horne CommitDate: 2021-12-07 18:15:59 +0000 Implement GET_STACK_USAGE on remaining archs This definition enables callers to estimate remaining space on the kstack, and take action on it. Notably, it enables optimizations in the GEOM and netgraph subsystems to directly dispatch work items when there is sufficient stack space, rather than queuing them for a worker thread. Implement it for riscv, arm, and mips. Remove the #ifdefs, so it will not go unimplemented elsewhere. PR: 259157 Reviewed by: mav, kib, markj (previous version) MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32580 (cherry picked from commit 0d2224733e970aaa67a4e1af7b340044adda92f6) --- sys/arm/include/proc.h | 11 +++++++++++ sys/geom/geom_io.c | 8 -------- sys/mips/include/proc.h | 11 +++++++++++ sys/netgraph/ng_base.c | 3 +-- sys/riscv/include/proc.h | 11 +++++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/sys/arm/include/proc.h b/sys/arm/include/proc.h index d70c7c3df17e..061a3553d1f3 100644 --- a/sys/arm/include/proc.h +++ b/sys/arm/include/proc.h @@ -78,4 +78,15 @@ struct syscall_args { u_int nap; } __aligned(8); +#ifdef _KERNEL +#include + +/* Get the current kernel thread stack usage. */ +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +#endif /* _KERNEL */ #endif /* !_MACHINE_PROC_H_ */ diff --git a/sys/geom/geom_io.c b/sys/geom/geom_io.c index 65d745bccaf4..c935b35dcc24 100644 --- a/sys/geom/geom_io.c +++ b/sys/geom/geom_io.c @@ -584,7 +584,6 @@ g_io_request(struct bio *bp, struct g_consumer *cp) else getbinuptime(&bp->bio_t0); -#ifdef GET_STACK_USAGE direct = (cp->flags & G_CF_DIRECT_SEND) != 0 && (pp->flags & G_PF_DIRECT_RECEIVE) != 0 && !g_is_geom_thread(curthread) && @@ -598,9 +597,6 @@ g_io_request(struct bio *bp, struct g_consumer *cp) if (su * 2 > st) direct = 0; } -#else - direct = 0; -#endif if (!TAILQ_EMPTY(&g_classifier_tailq) && !bp->bio_classifier1) { g_bioq_lock(&g_bio_run_down); @@ -701,7 +697,6 @@ g_io_deliver(struct bio *bp, int error) bp->bio_bcount = bp->bio_length; bp->bio_resid = bp->bio_bcount - bp->bio_completed; -#ifdef GET_STACK_USAGE direct = (pp->flags & G_PF_DIRECT_SEND) && (cp->flags & G_CF_DIRECT_RECEIVE) && !g_is_geom_thread(curthread); @@ -712,9 +707,6 @@ g_io_deliver(struct bio *bp, int error) if (su * 2 > st) direct = 0; } -#else - direct = 0; -#endif /* * The statistics collection is lockless, as such, but we diff --git a/sys/mips/include/proc.h b/sys/mips/include/proc.h index e35e0622513a..99e03a26aa47 100644 --- a/sys/mips/include/proc.h +++ b/sys/mips/include/proc.h @@ -98,4 +98,15 @@ struct syscall_args { #define KINFO_PROC_SIZE 816 #endif +#ifdef _KERNEL +#include + +/* Get the current kernel thread stack usage. */ +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +#endif /* _KERNEL */ #endif /* !_MACHINE_PROC_H_ */ diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 13dd44cd4f4a..1806a442d898 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -2281,7 +2281,7 @@ ng_snd_item(item_p item, int flags) queue = 1; } else { queue = 0; -#ifdef GET_STACK_USAGE + /* * Most of netgraph nodes have small stack consumption and * for them 25% of free stack space is more than enough. @@ -2296,7 +2296,6 @@ ng_snd_item(item_p item, int flags) ((node->nd_flags & NGF_HI_STACK) || (hook && (hook->hk_flags & HK_HI_STACK))))) queue = 1; -#endif } if (queue) { diff --git a/sys/riscv/include/proc.h b/sys/riscv/include/proc.h index 644bb91c4ad6..b8ade8a549d3 100644 --- a/sys/riscv/include/proc.h +++ b/sys/riscv/include/proc.h @@ -53,4 +53,15 @@ struct syscall_args { int narg; }; +#ifdef _KERNEL +#include + +/* Get the current kernel thread stack usage. */ +#define GET_STACK_USAGE(total, used) do { \ + struct thread *td = curthread; \ + (total) = td->td_kstack_pages * PAGE_SIZE - sizeof(struct pcb); \ + (used) = td->td_kstack + (total) - (vm_offset_t)&td; \ +} while (0) + +#endif /* _KERNEL */ #endif /* !_MACHINE_PROC_H_ */