From nobody Thu Jul 14 14:47:36 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 4LkHQc4qGcz2pHxF; Thu, 14 Jul 2022 14:47:36 +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 4LkHQc42gcz474K; Thu, 14 Jul 2022 14:47:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657810056; 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=TwYmVWd25m6LnL3iYsUFaN/jEa5O90VgdhNjyacY7y8=; b=HboAVe95th+e3QGKW3Ubq+BBGL+buHs+qogSSMfaZdgsWkmxSRiLfFwRyu93nRkvKi8v1f eaiiWiQQhwMh0QqsK5mBxlJ3nb/fY0s6MTC0grY8U7bF2/r9wR94xQKKJ4r7SNp0Phkq97 X3s/392OlEPIqh17UUD+/i7vHJ/G9XHN8fEIVRjYLVqw0W/jug4JBw4Q51qKbKLCNh0oSP gQK8RPhBlpOO7eQHeFtmwUr6c1VYyExdpyCgL6nk0utR0vbc3D+SHB9ADavp9RBfM415th scWyhKA5GOGWG4yCD6ogm8RP7UE6OHh7Mlass1XyUV2KwLHU4PgQhCPpS2yU9g== 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 4LkHQc32Y5z16W3; Thu, 14 Jul 2022 14:47:36 +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 26EElaaw041105; Thu, 14 Jul 2022 14:47:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26EElan2041104; Thu, 14 Jul 2022 14:47:36 GMT (envelope-from git) Date: Thu, 14 Jul 2022 14:47:36 GMT Message-Id: <202207141447.26EElan2041104@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: 0927ff78147b - main - sched_ule: Enable preemption of curthread in the load balancer 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0927ff78147b4d00a75054bbad299946208e1e91 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657810056; 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=TwYmVWd25m6LnL3iYsUFaN/jEa5O90VgdhNjyacY7y8=; b=YfZdg+i2Rwe75qHlY/6eQ59tAudlvr0z1LabFIzghKi9AoXCbrxQun9uNrJz9n7osZay40 BQHRcw888wFUviyOHU2MlmNRyJn8a+k1vTXt9YSEiWkhAb8DlTVcbS0WssvlvOjWcGv16f +Lg1arHC9Axe/TPevIgOTBR9kl+4JLQMJG41kfePQgmiq6L/Q1PA5/T2mS4om6PtOHZj4Z YRxlttsTMITt/G4Pi8hZ4U7niOhRBaLMa15ILoVIuGGPD7BwHYznDdz8urABMeKXggtuM5 MmxxtIYOldhz4Sw9FI4rvyJ03BQ+1BGnArCnDzpI02enCiiJQ6cobz6JYpLZ3w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657810056; a=rsa-sha256; cv=none; b=v746YD8VQtrAuDNwnnLIj1c/MyA1rvFQJ5weT8hc6/0H8E8t9ups04CNZHM8jzBUA24iRR XEWhZWB4RQ1wSapCzNDHsJFlUhE5C+12loAuhj0/uEPopcb7XYWOQOSExltWYgYrruf6hz MaMrOsIS8Gc0W8awVo9YItk3bas5gflSV6eTeZsu3pnQxfZ0mAEHWHCu8z7G2RrZZO8SnO +lq5/X+OOVwWFbVqYmNZw+touqqVxJ4p+7eIhZAsVj5/yLHH6TyjVm5OOGtVJ2p0wHsny7 T7V+4zrKHL26bf0da8IMXXR/9BuSJ2wjxdMLqG+eNjhF/vLYTuqRWgBNyqDo+g== 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=0927ff78147b4d00a75054bbad299946208e1e91 commit 0927ff78147b4d00a75054bbad299946208e1e91 Author: Mark Johnston AuthorDate: 2022-07-14 14:23:43 +0000 Commit: Mark Johnston CommitDate: 2022-07-14 14:27:58 +0000 sched_ule: Enable preemption of curthread in the load balancer The load balancer executes from statclock and periodically tries to move threads among CPUs in order to balance load. It may move a thread to the current CPU (the loader balancer always runs on CPU 0). When it does so, it may need to schedule preemption of the interrupted thread. Use sched_setpreempt() to do so, same as sched_add(). PR: 264867 Reviewed by: mav, kib, jhb MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35744 --- sys/kern/sched_ule.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 2652973f9b99..43991ca15c57 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -307,6 +307,7 @@ static struct tdq tdq_cpu; #define TDQ_UNLOCK(t) mtx_unlock_spin(TDQ_LOCKPTR((t))) #define TDQ_LOCKPTR(t) ((struct mtx *)(&(t)->tdq_lock)) +static void sched_setpreempt(int); static void sched_priority(struct thread *); static void sched_thread_priority(struct thread *, u_char); static int sched_interact_score(struct thread *); @@ -949,13 +950,15 @@ sched_balance_pair(struct tdq *high, struct tdq *low) lowpri = tdq_move(high, low); if (lowpri != -1) { /* - * In case the target isn't the current cpu notify it of + * In case the target isn't the current CPU notify it of * the new load, possibly sending an IPI to force it to - * reschedule. + * reschedule. Otherwise maybe schedule a preemption. */ cpu = TDQ_ID(low); if (cpu != PCPU_GET(cpuid)) tdq_notify(low, lowpri); + else + sched_setpreempt(low->tdq_lowpri); ret = true; } } @@ -2630,20 +2633,19 @@ sched_choose(void) } /* - * Set owepreempt if necessary. Preemption never happens directly in ULE, - * we always request it once we exit a critical section. + * Set owepreempt if the currently running thread has lower priority than "pri". + * Preemption never happens directly in ULE, we always request it once we exit a + * critical section. */ -static inline void -sched_setpreempt(struct thread *td) +static void +sched_setpreempt(int pri) { struct thread *ctd; int cpri; - int pri; - - THREAD_LOCK_ASSERT(curthread, MA_OWNED); ctd = curthread; - pri = td->td_priority; + THREAD_LOCK_ASSERT(ctd, MA_OWNED); + cpri = ctd->td_priority; if (pri < cpri) ctd->td_flags |= TDF_NEEDRESCHED; @@ -2720,7 +2722,7 @@ sched_add(struct thread *td, int flags) if (cpu != PCPU_GET(cpuid)) tdq_notify(tdq, lowpri); else if (!(flags & SRQ_YIELDING)) - sched_setpreempt(td); + sched_setpreempt(td->td_priority); #else tdq = TDQ_SELF(); /* @@ -2736,7 +2738,7 @@ sched_add(struct thread *td, int flags) } (void)tdq_add(tdq, td, flags); if (!(flags & SRQ_YIELDING)) - sched_setpreempt(td); + sched_setpreempt(td->td_priority); #endif if (!(flags & SRQ_HOLDTD)) thread_unlock(td);