From owner-svn-src-all@freebsd.org Sat Dec 7 00:28:10 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E6D1F1BD64A; Sat, 7 Dec 2019 00:28:10 +0000 (UTC) (envelope-from kib@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47V9KP513Dz48nV; Sat, 7 Dec 2019 00:28:09 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 286EE97A1; Sat, 7 Dec 2019 00:28:09 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xB70S9HI018776; Sat, 7 Dec 2019 00:28:09 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xB70S9c7018775; Sat, 7 Dec 2019 00:28:09 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201912070028.xB70S9c7018775@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 7 Dec 2019 00:28:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355475 - head/sys/x86/x86 X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/x86/x86 X-SVN-Commit-Revision: 355475 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Dec 2019 00:28:11 -0000 Author: kib Date: Sat Dec 7 00:28:08 2019 New Revision: 355475 URL: https://svnweb.freebsd.org/changeset/base/355475 Log: x86: Restore the critical section around whole ipi_bitmap_handler() if hardclock IPI is delivered. In the current code after r355311, critical section is taken only around hardclockintr() call, and sched_preempt() is called after the section is exited. If we reschedule after exit, as we typically would due to conditions that caused IPI, in ULE the runq tdq_ipipending is not cleared, which blocks generation of further preempt IPIs. Since all relatively modern (10 years) hardware has per-cpu event timers, restoring the critical section conditionally does not affect it. Reported and tested by: cy Diagnosed and reviewed by: jeff (previous version) Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D22716 Modified: head/sys/x86/x86/mp_x86.c Modified: head/sys/x86/x86/mp_x86.c ============================================================================== --- head/sys/x86/x86/mp_x86.c Sat Dec 7 00:23:19 2019 (r355474) +++ head/sys/x86/x86/mp_x86.c Sat Dec 7 00:28:08 2019 (r355475) @@ -1262,10 +1262,28 @@ ipi_bitmap_handler(struct trapframe frame) u_int ipi_bitmap; td = curthread; + ipi_bitmap = atomic_readandclear_int(&cpuid_to_pcpu[cpu]-> + pc_ipi_bitmap); + + /* + * sched_preempt() must be called to clear the pending preempt + * IPI to enable delivery of further preempts. However, the + * critical section will cause extra scheduler lock thrashing + * when used unconditionally. Only critical_enter() if + * hardclock must also run, which requires the section entry. + */ + if (ipi_bitmap & (1 << IPI_HARDCLOCK)) + critical_enter(); + td->td_intr_nesting_level++; oldframe = td->td_intr_frame; td->td_intr_frame = &frame; - ipi_bitmap = atomic_readandclear_int(&cpuid_to_pcpu[cpu]->pc_ipi_bitmap); + if (ipi_bitmap & (1 << IPI_PREEMPT)) { +#ifdef COUNT_IPIS + (*ipi_preempt_counts[cpu])++; +#endif + sched_preempt(td); + } if (ipi_bitmap & (1 << IPI_AST)) { #ifdef COUNT_IPIS (*ipi_ast_counts[cpu])++; @@ -1273,23 +1291,15 @@ ipi_bitmap_handler(struct trapframe frame) /* Nothing to do for AST */ } if (ipi_bitmap & (1 << IPI_HARDCLOCK)) { - critical_enter(); #ifdef COUNT_IPIS (*ipi_hardclock_counts[cpu])++; #endif hardclockintr(); - critical_exit(); } - - /* Run preempt after clock handlers since it may switch. */ - if (ipi_bitmap & (1 << IPI_PREEMPT)) { -#ifdef COUNT_IPIS - (*ipi_preempt_counts[cpu])++; -#endif - sched_preempt(td); - } td->td_intr_frame = oldframe; td->td_intr_nesting_level--; + if (ipi_bitmap & (1 << IPI_HARDCLOCK)) + critical_exit(); } /*