From patchwork Sat Jul 31 14:59:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 116197 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6VG7kTb027084 for ; Sat, 31 Jul 2010 16:08:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756157Ab0GaO7w (ORCPT ); Sat, 31 Jul 2010 10:59:52 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:55010 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756093Ab0GaO7m (ORCPT ); Sat, 31 Jul 2010 10:59:42 -0400 Received: by mail-bw0-f46.google.com with SMTP id 1so870874bwz.19 for ; Sat, 31 Jul 2010 07:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=wY1dfc/pvH+P6Y5u0Nig8Bpfr+si8lENl8y/ZRiEhQg=; b=G2pwbvUn14wcyUMt2bfTxqTptkZyZZTKO6zJtyx+aZGkjSoLfMp6gxsmMxmec/Fcu2 7OcIxLEWK7fROTQ6ZQXXFpPJXzDlEMMxCj/LoQjZ0KX2ElORxieYrvkYaHicqvH+Vg/I XoxCGVnFa3cOqkyzlVEbDMESzscq+GgcIjJEM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=hRQbUB0ALk8/2o3geV4lovLL6F9lnBRwlyGi8sjDYpYzEy2tDSq4v3WLLW2jyYZKK8 Y7ZKNqkf5BMRzoCm45XqvJ3C040+tza4BAbIBvphiBDpOdSElILuE0tXEVBNdYMRtLuw fsdDK74aLjilNEjhxkCkLOWEXiz7RBW6eIAn8= Received: by 10.204.126.205 with SMTP id d13mr2249988bks.126.1280588381454; Sat, 31 Jul 2010 07:59:41 -0700 (PDT) Received: from localhost.localdomain (IGLD-84-228-252-15.inter.net.il [84.228.252.15]) by mx.google.com with ESMTPS id a9sm2445428bky.23.2010.07.31.07.59.39 (version=SSLv3 cipher=RC4-MD5); Sat, 31 Jul 2010 07:59:41 -0700 (PDT) From: Maxim Levitsky To: lirc-list@lists.sourceforge.net Cc: Jarod Wilson , linux-input@vger.kernel.org, linux-media@vger.kernel.org, Mauro Carvalho Chehab , Christoph Bartelmus , Maxim Levitsky Subject: [PATCH 04/13] IR: replace workqueue with kthread Date: Sat, 31 Jul 2010 17:59:17 +0300 Message-Id: <1280588366-26101-5-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1280588366-26101-1-git-send-email-maximlevitsky@gmail.com> References: <1280588366-26101-1-git-send-email-maximlevitsky@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 31 Jul 2010 16:08:52 +0000 (UTC) diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h index dc26e2b..84c7a9a 100644 --- a/drivers/media/IR/ir-core-priv.h +++ b/drivers/media/IR/ir-core-priv.h @@ -32,7 +32,7 @@ struct ir_raw_handler { struct ir_raw_event_ctrl { struct list_head list; /* to keep track of raw clients */ - struct work_struct rx_work; /* for the rx decoding workqueue */ + struct task_struct *thread; struct kfifo kfifo; /* fifo for the pulse/space durations */ ktime_t last_event; /* when last event occurred */ enum raw_event_type last_type; /* last event type */ diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c index 9d5c029..d0c18db 100644 --- a/drivers/media/IR/ir-raw-event.c +++ b/drivers/media/IR/ir-raw-event.c @@ -12,9 +12,10 @@ * GNU General Public License for more details. */ -#include +#include #include #include +#include #include "ir-core-priv.h" /* Define the max number of pulse/space transitions to buffer */ @@ -33,20 +34,30 @@ static u64 available_protocols; static struct work_struct wq_load; #endif -static void ir_raw_event_work(struct work_struct *work) +static int ir_raw_event_thread(void *data) { struct ir_raw_event ev; struct ir_raw_handler *handler; - struct ir_raw_event_ctrl *raw = - container_of(work, struct ir_raw_event_ctrl, rx_work); + struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data; + + while (!kthread_should_stop()) { + try_to_freeze(); - while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) { mutex_lock(&ir_raw_handler_lock); - list_for_each_entry(handler, &ir_raw_handler_list, list) - handler->decode(raw->input_dev, ev); + + while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) { + list_for_each_entry(handler, &ir_raw_handler_list, list) + handler->decode(raw->input_dev, ev); + raw->prev_ev = ev; + } + mutex_unlock(&ir_raw_handler_lock); - raw->prev_ev = ev; + + set_current_state(TASK_INTERRUPTIBLE); + schedule(); } + + return 0; } /** @@ -141,7 +152,7 @@ void ir_raw_event_handle(struct input_dev *input_dev) if (!ir->raw) return; - schedule_work(&ir->raw->rx_work); + wake_up_process(ir->raw->thread); } EXPORT_SYMBOL_GPL(ir_raw_event_handle); @@ -170,7 +181,7 @@ int ir_raw_event_register(struct input_dev *input_dev) return -ENOMEM; ir->raw->input_dev = input_dev; - INIT_WORK(&ir->raw->rx_work, ir_raw_event_work); + ir->raw->enabled_protocols = ~0; rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE, GFP_KERNEL); @@ -180,6 +191,15 @@ int ir_raw_event_register(struct input_dev *input_dev) return rc; } + ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw, + "rc%u", (unsigned int)ir->devno); + + if (IS_ERR(ir->raw->thread)) { + kfree(ir->raw); + ir->raw = NULL; + return PTR_ERR(ir->raw->thread); + } + mutex_lock(&ir_raw_handler_lock); list_add_tail(&ir->raw->list, &ir_raw_client_list); list_for_each_entry(handler, &ir_raw_handler_list, list) @@ -198,7 +218,7 @@ void ir_raw_event_unregister(struct input_dev *input_dev) if (!ir->raw) return; - cancel_work_sync(&ir->raw->rx_work); + kthread_stop(ir->raw->thread); mutex_lock(&ir_raw_handler_lock); list_del(&ir->raw->list);