From nobody Thu Jul 14 20:15:37 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 4LkQj52l9Jz4T4L8; Thu, 14 Jul 2022 20:15:37 +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 4LkQj52K3Dz3T4D; Thu, 14 Jul 2022 20:15:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657829737; 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=TL/Fz6d9VClXwta+ZespkM7eDHIRytlpzJvDrVAtcdk=; b=eKFq0ubtjwnq4xaY7iuWMlMIA9Ff4TOKQPWM4qr8aw9uquPZWkpZLxPCX5k/QMEj48ERV3 3qLI/Tq3sfWZAeddbpIvXH6K7SteHasQ2dLXnUeRcApEwy+WqGFbpJiMVp9WXUjZ4h/8iQ d526GJ/PztY04BHr7Dw7k6xA72TDLrRHiCYa9TbDx6InAV60qQ5HrpmB31+DQ18LCc9bh+ dJK5YgDx8smR8K5H8zPfrVVv467/6wAM+YGRuB5h6xm/Ti1eNWftVjSW2dKuQRG/8TUEV4 lXama8OTiu9qL51u6WL9gTwgn08ojB7Lsmzb5h7xUpIWyM0qCoKjHQmaH7DQ3Q== 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 4LkQj51QkBzG0d; Thu, 14 Jul 2022 20:15:37 +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 26EKFbU8088299; Thu, 14 Jul 2022 20:15:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26EKFbu0088298; Thu, 14 Jul 2022 20:15:37 GMT (envelope-from git) Date: Thu, 14 Jul 2022 20:15:37 GMT Message-Id: <202207142015.26EKFbu0088298@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: 954cffe95de1 - main - ule: 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: 954cffe95de1b9d70ed804daa45b7921f0f5c9da Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657829737; 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=TL/Fz6d9VClXwta+ZespkM7eDHIRytlpzJvDrVAtcdk=; b=P09uBRs5V+EVdzexiqKFpAgJRJjwc8f3YsLiKT/bkOo/V1inmrDkxdRYspjShqdsWDrQrR zwOM2ZQURy1W7Dj9+fJ6IOfNMLPz89TAW64YgErjr8jvqtbHaLH66jyjHj7naFzPGVFSOE nZQmvHJtNwrEbbqclIoksRarFTRZXFxzOiOYr3G650Y9jRDfsEUeNudOgJwWJBfLVp/fnX uvVEcYkmB+mstj5XWpzuexcCR7cuQpsf/rRoyiGWHJzV607Aixug0/Sf9PYrWCZK0a91ue e6e6eUkRqKry6ccmRDuq50tgMv/UHCfQzVzZj7F0i61NVGHtIq3X6R1GdNLHHw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657829737; a=rsa-sha256; cv=none; b=rNlyIGWmWYPf/uNv4wO/dWDH8UhBMTbthSLJgOpj26dkT7wdFotTcENPz8tBavP956c6e8 j05b5ycAIx6B3GkykOj1VVTuV3Swv+H9QCDj8ZHEg3EmkTxX0T1YvENvioYE38OpCzRgZS ih4KAV20/3c5rU1Ce/PEp/Nc2QHNcZmGu0HrmalsaQRrvrtINw3dJ8Zxth9/0H4AkdcT7P a9re54/KSiDL2OrqPeA/k7FnshRrZeKfHKVzchHrdhMmd0dDb+SiNWCcEscgV5UqlHDF21 1wO3q0ckmZ3CylLkWpnv8JM6GjY/paWc8ulX1n6rO7YdkT9ILyngDTFSrbT6Kg== 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=954cffe95de1b9d70ed804daa45b7921f0f5c9da commit 954cffe95de1b9d70ed804daa45b7921f0f5c9da Author: John Baldwin AuthorDate: 2022-07-14 20:13:57 +0000 Commit: John Baldwin CommitDate: 2022-07-14 20:13:57 +0000 ule: 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, markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D35644 --- sys/kern/sched_ule.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index c4eb46944b43..b5ddae868ebb 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -2375,6 +2375,15 @@ sched_wakeup(struct thread *td, int srqflags) sched_interact_update(td); sched_pctcpu_update(ts, 0); } + + /* + * When resuming an idle ithread, restore its base ithread + * priority. + */ + if (PRI_BASE(td->td_pri_class) == PRI_ITHD && + td->td_priority != td->td_base_ithread_pri) + sched_prio(td, td->td_base_ithread_pri); + /* * Reset the slice value since we slept and advanced the round-robin. */ @@ -2542,9 +2551,25 @@ sched_userret_slowpath(struct thread *td) thread_unlock(td); } +SCHED_STAT_DEFINE(ithread_demotions, "Interrupt thread priority demotions"); +SCHED_STAT_DEFINE(ithread_preemptions, + "Interrupt thread preemptions due to time-sharing"); + +/* + * Return time slice for a given thread. For ithreads this is + * sched_slice. For other threads it is tdq_slice(tdq). + */ +static inline int +td_slice(struct thread *td, struct tdq *tdq) +{ + if (PRI_BASE(td->td_pri_class) == PRI_ITHD) + return (sched_slice); + return (tdq_slice(tdq)); +} + /* * Handle a stathz tick. This is really only relevant for timeshare - * threads. + * and interrupt threads. */ void sched_clock(struct thread *td, int cnt) @@ -2602,9 +2627,22 @@ sched_clock(struct thread *td, int cnt) * time slice (default is 100ms). */ ts->ts_slice += cnt; - if (ts->ts_slice >= tdq_slice(tdq)) { + if (ts->ts_slice >= td_slice(td, tdq)) { ts->ts_slice = 0; - 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; } }