Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp167692imd; Fri, 26 Oct 2018 06:50:08 -0700 (PDT) X-Google-Smtp-Source: AJdET5eveDZzvveeC26nAQjCdGq8aUB3DzkKWZhdQCZAGzS/cPF3xIYDjyjPMQB4FCjHTXDAaAou X-Received: by 2002:a17:902:7802:: with SMTP id p2-v6mr3568320pll.170.1540561808145; Fri, 26 Oct 2018 06:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540561808; cv=none; d=google.com; s=arc-20160816; b=ZeLc7KUcuEtC7zQDgxcTjHdr5hT4gIUftekGzCRH62kRKSX9uA4mAZbsnC3xstt/Qb bazoshD5jNjLdw8YWhFLhGUVeJojqqeitVa0GC4KVuHhlgh1ZAgOe5gzjGEWtnZBx7FM MSDP2jjiwpi4vSDVuiqRucUIQh4VwLAb5UaJLNPxjCbrvrdGqQqx5+TV7mZ3M/8UACfT ReLdhLe89wpmzxeRUQn/INz41awoF4svOuQGiGT4WIWyIz5vQFWpAsSQf0IznQCfoV+b 6JleR2ZC9P7d9xG0aLJ7/egvmmb5gAeQBXIYGJB61fASkmQgs9dA14qXQg/NjWdF1ocX dLyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uMx3w0HJMbmddnsBHHQ6czrd/1e2yhafNrkviih0GTI=; b=e/goZ4jrfqq7SJxslk0p/WLvy7n9ZdP0ZuAGe0R+Q8wTjb+V2dBMPYDLD+Vzjbb1Nj iI48mj0a4aTgzK2IeOoO318x6ejUBCBWl7NhTe9VNdjezBATw/3kkdASjpRT0IEVD1Dq Owo3qT7ipGbkQovJzAd804zvew7qUgJMn9WCaHDO2S8njKq6fRLfLbPclO3o+UFZqpQA ZcANUoLJDAayLWpF3jWP6KKBROPNwKXHWy9T4k10TYrSniOjp1UVeZM6XKVNlqYIP7I4 7C+FqVycI0EiywhZXmnhZKjUTIo3L/D3ec8g2nsXAC3rZhdsvq16AsJAnnINv7mbkdIA Zejw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i189-v6si11694904pfg.281.2018.10.26.06.49.52; Fri, 26 Oct 2018 06:50:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727606AbeJZWZr (ORCPT + 99 others); Fri, 26 Oct 2018 18:25:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:44790 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727431AbeJZWZq (ORCPT ); Fri, 26 Oct 2018 18:25:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 11A1DB04D; Fri, 26 Oct 2018 13:48:37 +0000 (UTC) From: Nicolas Saenz Julienne To: stefan.wahren@i2se.com, eric@anholt.net, dave.stevenson@raspberrypi.org Cc: nsaenzjulienne@suse.de, linux-rpi-kernel@lists.infradead.org, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 12/18] staging: vchiq_util: use completions instead of semaphores Date: Fri, 26 Oct 2018 15:48:07 +0200 Message-Id: <20181026134813.7775-13-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026134813.7775-1-nsaenzjulienne@suse.de> References: <20181026134813.7775-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is preferred in the kernel to avoid using semaphores to wait for events, as they are optimised for the opposite situation; where the common case is that they are available and may block only occasionally. FYI see this thread: https://lkml.org/lkml/2008/4/11/323. Also completions are semantically more explicit in this case. Signed-off-by: Nicolas Saenz Julienne --- .../interface/vchiq_arm/vchiq_util.c | 16 ++++++++-------- .../interface/vchiq_arm/vchiq_util.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c index 2e52f07bbaa9..44b954daa74a 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c @@ -48,8 +48,8 @@ int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size) queue->write = 0; queue->initialized = 1; - sema_init(&queue->pop, 0); - sema_init(&queue->push, 0); + init_completion(&queue->pop); + init_completion(&queue->push); queue->storage = kcalloc(size, sizeof(VCHIQ_HEADER_T *), GFP_KERNEL); if (!queue->storage) { @@ -80,7 +80,7 @@ void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header) return; while (queue->write == queue->read + queue->size) { - if (down_interruptible(&queue->pop) != 0) + if (wait_for_completion_interruptible(&queue->pop)) flush_signals(current); } @@ -100,17 +100,17 @@ void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header) queue->write++; - up(&queue->push); + complete(&queue->push); } VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue) { while (queue->write == queue->read) { - if (down_interruptible(&queue->push) != 0) + if (wait_for_completion_interruptible(&queue->push)) flush_signals(current); } - up(&queue->push); // We haven't removed anything from the queue. + complete(&queue->push); // We haven't removed anything from the queue. /* * Read from queue->storage must be visible after read from @@ -126,7 +126,7 @@ VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue) VCHIQ_HEADER_T *header; while (queue->write == queue->read) { - if (down_interruptible(&queue->push) != 0) + if (wait_for_completion_interruptible(&queue->push)) flush_signals(current); } @@ -146,7 +146,7 @@ VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue) queue->read++; - up(&queue->pop); + complete(&queue->pop); return header; } diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h index 5a1540d349d3..b226227fe5bc 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h @@ -35,7 +35,7 @@ #define VCHIQ_UTIL_H #include -#include +#include #include #include #include @@ -60,8 +60,8 @@ typedef struct { int write; int initialized; - struct semaphore pop; - struct semaphore push; + struct completion pop; + struct completion push; VCHIQ_HEADER_T **storage; } VCHIU_QUEUE_T; -- 2.19.1