Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756099Ab0BXIv0 (ORCPT ); Wed, 24 Feb 2010 03:51:26 -0500 Received: from mtagate2.de.ibm.com ([195.212.17.162]:59823 "EHLO mtagate2.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755564Ab0BXIot (ORCPT ); Wed, 24 Feb 2010 03:44:49 -0500 Message-Id: <20100224084447.955310300@de.ibm.com> User-Agent: quilt/0.48-1 Date: Wed, 24 Feb 2010 09:44:35 +0100 From: Martin Schwidefsky To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Cc: Heiko Carstens , Sebastian Ott , Martin Schwidefsky Subject: [patch 05/32] [PATCH] cio: wait for channel report References: <20100224084430.193562869@de.ibm.com> Content-Disposition: inline; filename=104-cio-wait-channel-report.diff Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3653 Lines: 115 From: Sebastian Ott To fetch a pending channel report word (crw) we use a kernel thread which triggers stcrw and sleeps on a semaphore. The s390 machine check handler uses crw_handle_channel_report to handle one crw if needed. This patch replaces the semaphore with a waitqueue (to block the kernel thread) and an atomic_t (to count the number of pending requests). By this we achieve the ability to force this thread to check for a pending crw (independent on when it is triggered by the machine check handler) and wait for this action to finish. Signed-off-by: Sebastian Ott Signed-off-by: Martin Schwidefsky --- arch/s390/include/asm/crw.h | 1 + drivers/s390/cio/crw.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) Index: quilt-2.6/arch/s390/include/asm/crw.h =================================================================== --- quilt-2.6.orig/arch/s390/include/asm/crw.h 2010-02-24 09:28:13.000000000 +0100 +++ quilt-2.6/arch/s390/include/asm/crw.h 2010-02-24 09:44:23.000000000 +0100 @@ -32,6 +32,7 @@ extern int crw_register_handler(int rsc, crw_handler_t handler); extern void crw_unregister_handler(int rsc); extern void crw_handle_channel_report(void); +void crw_wait_for_channel_report(void); #define NR_RSCS 16 Index: quilt-2.6/drivers/s390/cio/crw.c =================================================================== --- quilt-2.6.orig/drivers/s390/cio/crw.c 2010-02-24 09:28:13.000000000 +0100 +++ quilt-2.6/drivers/s390/cio/crw.c 2010-02-24 09:44:23.000000000 +0100 @@ -8,15 +8,16 @@ * Heiko Carstens , */ -#include #include #include #include +#include #include -static struct semaphore crw_semaphore; static DEFINE_MUTEX(crw_handler_mutex); static crw_handler_t crw_handlers[NR_RSCS]; +static atomic_t crw_nr_req = ATOMIC_INIT(0); +static DECLARE_WAIT_QUEUE_HEAD(crw_handler_wait_q); /** * crw_register_handler() - register a channel report word handler @@ -59,12 +60,14 @@ static int crw_collect_info(void *unused) { struct crw crw[2]; - int ccode; + int ccode, signal; unsigned int chain; - int ignore; repeat: - ignore = down_interruptible(&crw_semaphore); + signal = wait_event_interruptible(crw_handler_wait_q, + atomic_read(&crw_nr_req) > 0); + if (unlikely(signal)) + atomic_inc(&crw_nr_req); chain = 0; while (1) { crw_handler_t handler; @@ -122,25 +125,23 @@ /* chain is always 0 or 1 here. */ chain = crw[chain].chn ? chain + 1 : 0; } + if (atomic_dec_and_test(&crw_nr_req)) + wake_up(&crw_handler_wait_q); goto repeat; return 0; } void crw_handle_channel_report(void) { - up(&crw_semaphore); + atomic_inc(&crw_nr_req); + wake_up(&crw_handler_wait_q); } -/* - * Separate initcall needed for semaphore initialization since - * crw_handle_channel_report might be called before crw_machine_check_init. - */ -static int __init crw_init_semaphore(void) +void crw_wait_for_channel_report(void) { - init_MUTEX_LOCKED(&crw_semaphore); - return 0; + crw_handle_channel_report(); + wait_event(crw_handler_wait_q, atomic_read(&crw_nr_req) == 0); } -pure_initcall(crw_init_semaphore); /* * Machine checks for the channel subsystem must be enabled -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/