From nobody Thu Jul 14 20:15:38 2022 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 4LkQj64S5kz4T4J9; Thu, 14 Jul 2022 20:15:38 +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 4LkQj63XNyz3TNs; Thu, 14 Jul 2022 20:15:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657829738; 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=c4IxxVhHBMGPeVpuQG9fJ3bh6P3oh1FRcqjKRBPwAt0=; b=UQfA/O+7C+km7KteXMQyWtjQKYGeWYk6uSl5mfF5/QMGa842zmWFaKGdGbqZqT6t3vcyIX 7cdBT7T+J1ZDaX5F9sh4QYt1qynRe4pA8n2ngAidu2HfTzx7qZEf4htb9BIXrDSmFU8h0W I5Vs1IGfeEziroF//J4Z8lCx5gRGaqOXk1EZZsoNaAWi/4QdAFVqCrHuDQK1koi3QSrrZK 9oSJJp9PoRBnNwaNtL4NOgrqA2vml9r8Ma521HsO3KwVdWXD/BQj3XuNGeMwjN4PIQbAhv GhRU7pel/NtxCoc5Jptd/Tnzyt2E+iDXr/ilILL9H5VAXhiJUxAxl7AUt2cnyQ== 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 4LkQj62RtvzGMj; Thu, 14 Jul 2022 20:15:38 +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 26EKFcBQ088324; Thu, 14 Jul 2022 20:15:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26EKFcG4088323; Thu, 14 Jul 2022 20:15:38 GMT (envelope-from git) Date: Thu, 14 Jul 2022 20:15:38 GMT Message-Id: <202207142015.26EKFcG4088323@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 40efe74352cf - main - 4bsd: Simplistic time-sharing for interrupt threads. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 40efe74352cfdddc26ddb6d1512efeffc44bacc3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657829738; 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=c4IxxVhHBMGPeVpuQG9fJ3bh6P3oh1FRcqjKRBPwAt0=; b=ryhwT0ukALDKHwtuXZD5VUBKvgr4+boNZXU3b62uOiKLnwOANnGBhKQZtn49KMKixZNint mGdlksQT2TP3bKVBIbo4i0VAsgCW6fRhdRf8Qdb3FrZGKLvigLnx3m1NP8MO2J2coQgjZk HZfJFHCNs5n4XCCrUj3hrcmFx3GRZfTLCsroZ/iK4gHGlakThWKrledbdW5f4VNYSOHunP 5r9qp2ZYZGcL1ZBPb6S/7xFWlhurl9xkrk0IHW+pfxyW3CQny9nmOqr0uVW8LUd6H9Oue5 qaFZF8M1ghAxtE8/HQx3mWwkLn/My8SRLn14aVCOnTU9ouShup0wQVNf0VrlVw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657829738; a=rsa-sha256; cv=none; b=Tq0JzjJ0RRHlu8kggW6qg58GMiGYqlj1exh/uR+Ph0lLjJ7WzP81emZCv1D2CLKqwHi/4K Sjtjb+186A2nuwLs9ozv6S+/njB/T7XGrPfQslNYI4LrXigl9qbcJY9XHbW9w+jxMmih4X 2Ftpiv5LKANOaLTgcsgVlnumiLTFG/hlraz0szTrvJaS3szHq3MSVKzH5lTRHjuraxyNyR 4QmK+jW4jBNxpm2NQdBDtmhb2C35pbFDJJDYoGg4B8w40u0ziebj+GYrc4kMwXUYRq7RDp j5F62G2pUiWUjERoAp4B9vTHBKD7hf0YyfdQTd/b6zNU9hvb1XuJNqm3+sfIfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=40efe74352cfdddc26ddb6d1512efeffc44bacc3 commit 40efe74352cfdddc26ddb6d1512efeffc44bacc3 Author: John Baldwin AuthorDate: 2022-07-14 20:14:17 +0000 Commit: John Baldwin CommitDate: 2022-07-14 20:14:17 +0000 4bsd: Simplistic time-sharing for interrupt threads. If an interrupt thread runs for a full quantum without yielding the CPU, demote its priority and schedule a preemption to give other ithreads a turn. Reviewed by: kib Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D35645 --- sys/kern/sched_4bsd.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index 779e1a7b4ef5..b85c32d54605 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -703,6 +703,10 @@ sched_rr_interval(void) return (imax(1, (sched_slice * hz + realstathz / 2) / realstathz)); } +SCHED_STAT_DEFINE(ithread_demotions, "Interrupt thread priority demotions"); +SCHED_STAT_DEFINE(ithread_preemptions, + "Interrupt thread preemptions due to time-sharing"); + /* * We adjust the priority of the current process. The priority of a * process gets worse as it accumulates CPU time. The cpu usage @@ -739,7 +743,20 @@ sched_clock_tick(struct thread *td) */ if (!TD_IS_IDLETHREAD(td) && --ts->ts_slice <= 0) { ts->ts_slice = sched_slice; - td->td_flags |= TDF_NEEDRESCHED | TDF_SLICEEND; + + /* + * If an ithread uses a full quantum, demote its + * priority and preempt it. + */ + if (PRI_BASE(td->td_pri_class) == PRI_ITHD) { + SCHED_STAT_INC(ithread_preemptions); + td->td_owepreempt = 1; + if (td->td_base_pri + RQ_PPQ < PRI_MAX_ITHD) { + SCHED_STAT_INC(ithread_demotions); + sched_prio(td, td->td_base_pri + RQ_PPQ); + } + } else + td->td_flags |= TDF_NEEDRESCHED | TDF_SLICEEND; } stat = DPCPU_PTR(idlestat); @@ -1134,6 +1151,15 @@ sched_wakeup(struct thread *td, int srqflags) td->td_slptick = 0; ts->ts_slptime = 0; ts->ts_slice = sched_slice; + + /* + * When resuming an idle ithread, restore its base ithread + * priority. + */ + if (PRI_BASE(td->td_pri_class) == PRI_ITHD && + td->td_base_pri != td->td_base_ithread_pri) + sched_prio(td, td->td_base_ithread_pri); + sched_add(td, srqflags); }