From patchwork Wed Oct 28 02:45:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 7506241 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0D42F9F37F for ; Wed, 28 Oct 2015 02:46:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 225F22080C for ; Wed, 28 Oct 2015 02:46:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27A612080B for ; Wed, 28 Oct 2015 02:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755273AbbJ1Cq2 (ORCPT ); Tue, 27 Oct 2015 22:46:28 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:64127 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755235AbbJ1CqZ (ORCPT ); Tue, 27 Oct 2015 22:46:25 -0400 Received: from wuerfel.lan. ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue003) with ESMTPSA (Nemesis) id 0M2YnR-1ajdvS2Qh3-00sJPi; Wed, 28 Oct 2015 03:46:19 +0100 From: Arnd Bergmann To: tglx@linutronix.de Cc: Arnd Bergmann , Len Brown , linux-acpi@vger.kernel.org Subject: [PATCH 01/25] acpi: remove counting semaphores Date: Wed, 28 Oct 2015 03:45:49 +0100 Message-Id: <1446000373-1823620-2-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.1.0.rc2 In-Reply-To: <1446000373-1823620-1-git-send-email-arnd@arndb.de> References: <1446000373-1823620-1-git-send-email-arnd@arndb.de> X-Provags-ID: V03:K0:5IpF8KWQ6Oda8efCnhwAjkZH2bxuGTrVml2pO4CiiWVjoKeteRY iJWw/woVR17a9ZDrS8bYxGUj+kVjmeoZIhqIyJYsABMo+K9i0COVUqLS5frpaqT2pYmPpjQ eAxn5DPZ7EcjsEoFjng2dmD2ORJzWbPQmkRdDyRBo5fRtqSm7/YDujGqBUlu4Nvi4F1d/uy IOsUE1PyhnLm4Sh07jjng== X-UI-Out-Filterresults: notjunk:1; V01:K0:+gMNaUoJCeg=:gYOJFDF61TCjf5jhDqGL2S lPC7OCseiH6dRZVHjb1WZr4J3NPDQS7cgNT5K22i8pxRzsch0BROlKpqIWEj6btz1Y1fRh2wE xDJ4MWW7LqmGUieYWdQhU0DELi6Kep8ZC48+JWGPCFTiBGs9YxcMLNQOhMcGsyeCrMgzmRJdz oF+tgLYq73D4qC9fsPfHhNpXYWXHE2ZttBlRocbH5ZZMRsqpZ+xFR/cwiRFsvnp1FDWmzwfeD uOzjdem6jqMEfNMlWaOtCLnolFN0dwLv899/HldGceQkm/g9abOuhA8bxVVu8KEp6E6Fxip+J RiIJlikJymCFzHc+d5wzrTPS34drl9jEtl/KhqEMopGu+YCQ2G0UJxpBNaJNL2BNUL4pMuWCf EiDW0fcIhaHt64VqA1tBd6YqR3jvquIYsugYTzm1XIHkah6pBRLnxL9fEgoe4+UO+mbFpMsj0 NRG6DExU9mFeWu9nNrF7ZvaCZL6ySrkm/omdTwDpByxxiEhKzfQSnoD6fUI/TrOS43WRzvYHZ Q2llBmGl+MckykNdTC53U+HhOz7apmqw6YlalEaBhb/K6cJby8XdSVNuk62Ww5uiiGEX/nR6U pZJoSSqlorGRKIZKkg3Hve4nBNhzhzGRHJ5FQHuyLa74kQAYI7oj8/ktvhRCSB2nsjSYSCYr1 VK1h8vVsgXMleD3J6BlwdARjMeXdE72BxROwCJzTNkDOvqqsWj1t2yQOhWa4Gy3tZr1k= Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Counting semaphores are going away, so replace the ACPI code using them with an open-coded version. There are too many layers of other code, including mutexes and completions in ACPI built on top that it's not really possible to maintain a generic semaphore otherwise. Cc: Len Brown Cc: linux-acpi@vger.kernel.org Signed-off-by: Arnd Bergmann --- drivers/acpi/osl.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index f31c5c5f1b7e..89c535d2154b 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include @@ -918,17 +917,26 @@ void acpi_os_wait_events_complete(void *context) EXPORT_SYMBOL(acpi_os_wait_events_complete); +/* + * Linux semaphores are not compatible with the way that ACPI + * semaphores are defined, so it's easier to build our own here. + */ +struct acpi_os_semaphore { + wait_queue_head_t wq; + atomic_t count; +}; + acpi_status acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) { - struct semaphore *sem = NULL; + struct acpi_os_semaphore *sem = NULL; - sem = acpi_os_allocate(sizeof(struct semaphore)); + sem = acpi_os_allocate(sizeof(struct acpi_os_semaphore)); if (!sem) return AE_NO_MEMORY; - memset(sem, 0, sizeof(struct semaphore)); - sema_init(sem, initial_units); + init_waitqueue_head(&sem->wq); + atomic_set(&sem->count, initial_units); *handle = (acpi_handle *) sem; @@ -947,14 +955,14 @@ acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) acpi_status acpi_os_delete_semaphore(acpi_handle handle) { - struct semaphore *sem = (struct semaphore *)handle; + struct acpi_os_semaphore *sem = (struct acpi_os_semaphore *)handle; if (!sem) return AE_BAD_PARAMETER; ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle)); - BUG_ON(!list_empty(&sem->wait_list)); + BUG_ON(!list_empty(&sem->wq.task_list)); kfree(sem); sem = NULL; @@ -967,7 +975,7 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle) acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) { acpi_status status = AE_OK; - struct semaphore *sem = (struct semaphore *)handle; + struct acpi_os_semaphore *sem = (struct acpi_os_semaphore *)handle; long jiffies; int ret = 0; @@ -985,9 +993,17 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) else jiffies = msecs_to_jiffies(timeout); - ret = down_timeout(sem, jiffies); - if (ret) - status = AE_TIME; + if (timeout == ACPI_DO_NOT_WAIT) { + ret = atomic_add_unless(&sem->count, -1, 0); + if (!ret) + status = AE_TIME; + } else { + ret = wait_event_timeout(sem->wq, + atomic_add_unless(&sem->count, -1, 0), + jiffies); + if (ret == 0) + status = AE_TIME; + } if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, @@ -1008,7 +1024,7 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout) */ acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) { - struct semaphore *sem = (struct semaphore *)handle; + struct acpi_os_semaphore *sem = (struct acpi_os_semaphore *)handle; if (!sem || (units < 1)) return AE_BAD_PARAMETER; @@ -1019,7 +1035,8 @@ acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle, units)); - up(sem); + if (atomic_inc_return(&sem->count) == 1) + wake_up(&sem->wq); return AE_OK; }