Date: Thu, 14 Jun 2018 11:09:52 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335132 - in head/sys: amd64/amd64 i386/i386 Message-ID: <201806141109.w5EB9qGk002680@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Thu Jun 14 11:09:51 2018 New Revision: 335132 URL: https://svnweb.freebsd.org/changeset/base/335132 Log: Reorganize code flow in fpudna()/npxdna() to highlight the critical section scope. Sprinkle __predict_false() for conditions known to never occur or occur only on rare platforms. Sponsored by: The FreeBSD Foundation Modified: head/sys/amd64/amd64/fpu.c head/sys/i386/i386/npx.c Modified: head/sys/amd64/amd64/fpu.c ============================================================================== --- head/sys/amd64/amd64/fpu.c Thu Jun 14 10:33:26 2018 (r335131) +++ head/sys/amd64/amd64/fpu.c Thu Jun 14 11:09:51 2018 (r335132) @@ -722,7 +722,7 @@ fpudna(void) KASSERT((curpcb->pcb_flags & PCB_FPUNOSAVE) == 0, ("fpudna while in fpu_kern_enter(FPU_KERN_NOCTX)")); - if (PCPU_GET(fpcurthread) == td) { + if (__predict_false(PCPU_GET(fpcurthread) == td)) { /* * Some virtual machines seems to set %cr0.TS at * arbitrary moments. Silently clear the TS bit @@ -730,15 +730,15 @@ fpudna(void) * mode. */ stop_emulating(); - critical_exit(); - return; + } else { + if (__predict_false(PCPU_GET(fpcurthread) != NULL)) { + panic( + "fpudna: fpcurthread = %p (%d), curthread = %p (%d)\n", + PCPU_GET(fpcurthread), + PCPU_GET(fpcurthread)->td_tid, td, td->td_tid); + } + restore_fpu_curthread(td); } - if (PCPU_GET(fpcurthread) != NULL) { - panic("fpudna: fpcurthread = %p (%d), curthread = %p (%d)\n", - PCPU_GET(fpcurthread), PCPU_GET(fpcurthread)->td_tid, - td, td->td_tid); - } - restore_fpu_curthread(td); critical_exit(); } Modified: head/sys/i386/i386/npx.c ============================================================================== --- head/sys/i386/i386/npx.c Thu Jun 14 10:33:26 2018 (r335131) +++ head/sys/i386/i386/npx.c Thu Jun 14 11:09:51 2018 (r335132) @@ -835,7 +835,7 @@ npxdna(void) return (0); td = curthread; critical_enter(); - if (PCPU_GET(fpcurthread) == td) { + if (__predict_false(PCPU_GET(fpcurthread) == td)) { /* * Some virtual machines seems to set %cr0.TS at * arbitrary moments. Silently clear the TS bit @@ -843,19 +843,18 @@ npxdna(void) * mode. */ stop_emulating(); - critical_exit(); - return (1); + } else { + if (__predict_false(PCPU_GET(fpcurthread) != NULL)) { + printf( + "npxdna: fpcurthread = %p (%d), curthread = %p (%d)\n", + PCPU_GET(fpcurthread), + PCPU_GET(fpcurthread)->td_proc->p_pid, + td, td->td_proc->p_pid); + panic("npxdna"); + } + restore_npx_curthread(td, td->td_pcb); } - if (PCPU_GET(fpcurthread) != NULL) { - printf("npxdna: fpcurthread = %p (%d), curthread = %p (%d)\n", - PCPU_GET(fpcurthread), - PCPU_GET(fpcurthread)->td_proc->p_pid, - td, td->td_proc->p_pid); - panic("npxdna"); - } - restore_npx_curthread(td, td->td_pcb); critical_exit(); - return (1); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806141109.w5EB9qGk002680>