From owner-svn-src-stable-11@freebsd.org Wed Apr 4 08:41:12 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E15DDF9E658; Wed, 4 Apr 2018 08:41:11 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 92D8F6C7FE; Wed, 4 Apr 2018 08:41:11 +0000 (UTC) (envelope-from hselasky@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 8DAE5114D7; Wed, 4 Apr 2018 08:41:11 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w348fBbb037045; Wed, 4 Apr 2018 08:41:11 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w348fArw037034; Wed, 4 Apr 2018 08:41:10 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201804040841.w348fArw037034@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 4 Apr 2018 08:41:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r331996 - in stable/11/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/11/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 331996 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2018 08:41:12 -0000 Author: hselasky Date: Wed Apr 4 08:41:10 2018 New Revision: 331996 URL: https://svnweb.freebsd.org/changeset/base/331996 Log: MFC r331828: Optimise use of Giant in the LinuxKPI. - Make sure Giant is locked when calling PCI device methods. Newbus currently requires this. - Avoid unlocking Giant right before aquiring the sleepqueue lock. This can save a task switch. Sponsored by: Mellanox Technologies Modified: stable/11/sys/compat/linuxkpi/common/include/linux/module.h stable/11/sys/compat/linuxkpi/common/src/linux_compat.c stable/11/sys/compat/linuxkpi/common/src/linux_pci.c stable/11/sys/compat/linuxkpi/common/src/linux_rcu.c stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/compat/linuxkpi/common/include/linux/module.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/linux/module.h Wed Apr 4 08:40:49 2018 (r331995) +++ stable/11/sys/compat/linuxkpi/common/include/linux/module.h Wed Apr 4 08:41:10 2018 (r331996) @@ -78,9 +78,7 @@ _module_run(void *arg) printf("Running %s (%p)\n", name, pc); #endif fn = arg; - DROP_GIANT(); fn(); - PICKUP_GIANT(); } #define module_init(fn) \ Modified: stable/11/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- stable/11/sys/compat/linuxkpi/common/src/linux_compat.c Wed Apr 4 08:40:49 2018 (r331995) +++ stable/11/sys/compat/linuxkpi/common/src/linux_compat.c Wed Apr 4 08:41:10 2018 (r331996) @@ -1804,8 +1804,6 @@ linux_wait_for_common(struct completion *c, int flags) if (SCHEDULER_STOPPED()) return (0); - DROP_GIANT(); - task = current; if (flags != 0) @@ -1819,22 +1817,25 @@ linux_wait_for_common(struct completion *c, int flags) break; sleepq_add(c, NULL, "completion", flags, 0); if (flags & SLEEPQ_INTERRUPTIBLE) { + DROP_GIANT(); error = -sleepq_wait_sig(c, 0); + PICKUP_GIANT(); if (error != 0) { linux_schedule_save_interrupt_value(task, error); error = -ERESTARTSYS; goto intr; } - } else + } else { + DROP_GIANT(); sleepq_wait(c, 0); + PICKUP_GIANT(); + } } if (c->done != UINT_MAX) c->done--; sleepq_release(c); intr: - PICKUP_GIANT(); - return (error); } @@ -1851,8 +1852,6 @@ linux_wait_for_timeout_common(struct completion *c, in if (SCHEDULER_STOPPED()) return (0); - DROP_GIANT(); - task = current; if (flags != 0) @@ -1866,10 +1865,14 @@ linux_wait_for_timeout_common(struct completion *c, in break; sleepq_add(c, NULL, "completion", flags, 0); sleepq_set_timeout(c, linux_timer_jiffies_until(end)); + + DROP_GIANT(); if (flags & SLEEPQ_INTERRUPTIBLE) error = -sleepq_timedwait_sig(c, 0); else error = -sleepq_timedwait(c, 0); + PICKUP_GIANT(); + if (error != 0) { /* check for timeout */ if (error == -EWOULDBLOCK) { @@ -1889,8 +1892,6 @@ linux_wait_for_timeout_common(struct completion *c, in /* return how many jiffies are left */ error = linux_timer_jiffies_until(end); done: - PICKUP_GIANT(); - return (error); } Modified: stable/11/sys/compat/linuxkpi/common/src/linux_pci.c ============================================================================== --- stable/11/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 4 08:40:49 2018 (r331995) +++ stable/11/sys/compat/linuxkpi/common/src/linux_pci.c Wed Apr 4 08:41:10 2018 (r331996) @@ -171,12 +171,11 @@ linux_pci_attach(device_t dev) pdev->bus = pbus; } - DROP_GIANT(); spin_lock(&pci_lock); list_add(&pdev->links, &pci_devices); spin_unlock(&pci_lock); + error = pdrv->probe(pdev, id); - PICKUP_GIANT(); if (error) { spin_lock(&pci_lock); list_del(&pdev->links); @@ -194,9 +193,9 @@ linux_pci_detach(device_t dev) linux_set_current(curthread); pdev = device_get_softc(dev); - DROP_GIANT(); + pdev->pdrv->remove(pdev); - PICKUP_GIANT(); + spin_lock(&pci_lock); list_del(&pdev->links); spin_unlock(&pci_lock); @@ -258,11 +257,8 @@ linux_pci_shutdown(device_t dev) linux_set_current(curthread); pdev = device_get_softc(dev); - if (pdev->pdrv->shutdown != NULL) { - DROP_GIANT(); + if (pdev->pdrv->shutdown != NULL) pdev->pdrv->shutdown(pdev); - PICKUP_GIANT(); - } return (0); } Modified: stable/11/sys/compat/linuxkpi/common/src/linux_rcu.c ============================================================================== --- stable/11/sys/compat/linuxkpi/common/src/linux_rcu.c Wed Apr 4 08:40:49 2018 (r331995) +++ stable/11/sys/compat/linuxkpi/common/src/linux_rcu.c Wed Apr 4 08:41:10 2018 (r331996) @@ -297,13 +297,13 @@ linux_synchronize_rcu(void) td = curthread; - DROP_GIANT(); - /* * Synchronizing RCU might change the CPU core this function * is running on. Save current values: */ thread_lock(td); + + DROP_GIANT(); old_cpu = PCPU_GET(cpuid); old_pinned = td->td_pinned; Modified: stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c ============================================================================== --- stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c Wed Apr 4 08:40:49 2018 (r331995) +++ stable/11/sys/compat/linuxkpi/common/src/linux_schedule.c Wed Apr 4 08:41:10 2018 (r331996) @@ -55,6 +55,8 @@ linux_add_to_sleepqueue(void *wchan, struct task_struc sleepq_add(wchan, NULL, wmesg, flags, 0); if (timeout != 0) sleepq_set_timeout(wchan, timeout); + + DROP_GIANT(); if ((state & TASK_INTERRUPTIBLE) != 0) { if (timeout == 0) ret = -sleepq_wait_sig(wchan, 0); @@ -67,6 +69,8 @@ linux_add_to_sleepqueue(void *wchan, struct task_struc } else ret = -sleepq_timedwait(wchan, 0); } + PICKUP_GIANT(); + /* filter return value */ if (ret != 0 && ret != -EWOULDBLOCK) { linux_schedule_save_interrupt_value(task, ret); @@ -248,8 +252,6 @@ linux_wait_event_common(wait_queue_head_t *wqh, wait_q if (lock != NULL) spin_unlock_irq(lock); - DROP_GIANT(); - /* range check timeout */ if (timeout < 1) timeout = 1; @@ -272,8 +274,6 @@ linux_wait_event_common(wait_queue_head_t *wqh, wait_q } PRELE(task->task_thread->td_proc); - PICKUP_GIANT(); - if (lock != NULL) spin_lock_irq(lock); return (ret); @@ -297,8 +297,6 @@ linux_schedule_timeout(int timeout) remainder = ticks + timeout; - DROP_GIANT(); - sleepq_lock(task); state = atomic_read(&task->state); if (state != TASK_WAKING) { @@ -309,8 +307,6 @@ linux_schedule_timeout(int timeout) } set_task_state(task, TASK_RUNNING); - PICKUP_GIANT(); - if (timeout == 0) return (MAX_SCHEDULE_TIMEOUT); @@ -356,8 +352,6 @@ linux_wait_on_bit_timeout(unsigned long *word, int bit void *wchan; int ret; - DROP_GIANT(); - /* range check timeout */ if (timeout < 1) timeout = 1; @@ -380,8 +374,6 @@ linux_wait_on_bit_timeout(unsigned long *word, int bit } set_task_state(task, TASK_RUNNING); - PICKUP_GIANT(); - return (ret); } @@ -399,8 +391,6 @@ linux_wait_on_atomic_t(atomic_t *a, unsigned int state void *wchan; int ret; - DROP_GIANT(); - task = current; wchan = a; for (;;) { @@ -416,8 +406,6 @@ linux_wait_on_atomic_t(atomic_t *a, unsigned int state break; } set_task_state(task, TASK_RUNNING); - - PICKUP_GIANT(); return (ret); }