Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752966AbZHPAtH (ORCPT ); Sat, 15 Aug 2009 20:49:07 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752234AbZHPAtG (ORCPT ); Sat, 15 Aug 2009 20:49:06 -0400 Received: from sing.entic.net ([208.64.63.147]:34171 "EHLO mail.q-ag.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750899AbZHPAtF (ORCPT ); Sat, 15 Aug 2009 20:49:05 -0400 Message-Id: <200908160048.n7G0mtO1023800@mail.q-ag.de> From: Manfred Spraul To: linux-kernel@vger.kernel.org Cc: npiggin@suse.de Cc: Andrew Morton Cc: Nadia Derbey Cc: Pierre Peiffer Date: Sat, 15 Aug 2009 23:57:12 +0200 Subject: [PATCH 0/4] ipc/sem.c: Alternative to Nick's patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following series of 4 patches are an alternative to Nick's 4th patch. They are intended to be applied after the first 3 patches from Nick. The advantages are simple: - Lower number of new code lines. - Lower total code size increase. - Lower runtime memory consumption. - 4 simple patches with the individual changes, each one can be reviewed individually. - Lower number of seperate codepaths. The disadvantage is also clear: My patch doesn't optimize wait-for-zero as good as Nick's patch. For example: * n wait-for-zero entries and one decrement by 2 to be woken up, semval at 1, an increment by 2 arrives: Nick's patch is O(1) and my patch is O(n). Neither of us knows if anyone uses that scenario and there are other codepaths that are O(n^2), too. Thus I don't think this is a big issue. Below is the test app/benchmark app I used: The present kernel breaks down if lots of tasks are sleeping on the same semaphore array, with the patch, the breakdown disappears. With my test app, the performance of Nick's and my patch are comparable. -- Manfred ---- /* * Copyright (C) 2009 by Manfred Spraul. * * Redistribution of this file is permitted under the terms of the GNU * General Public License (GPL) */ #include #include #include #include #include #include #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 union semun { int val; struct semid_ds *buf; unsigned short int *array; struct seminfo* __buf; }; #define barrier() __asm__ __volatile__("": : : "memory") int g_loops; int g_busy_in; int g_busy_out; int g_sem; int g_completedsem; static void thread_fnc(int id) { int i; volatile int j; int res; struct sembuf sop[1]; for (i=0;i \n"); if(argc != 6) { printf("Invalid parameters.\n"); return 1; } nsems=atoi(argv[1]); tasks=atoi(argv[2]); g_loops=atoi(argv[3]); g_loops = (g_loops+tasks-1)/tasks; g_busy_in=atoi(argv[4]); g_busy_out=atoi(argv[5]); g_completedsem = nsems; res = semget(IPC_PRIVATE, nsems+1, 0777 | IPC_CREAT); if(res == -1) { printf(" create failed.\n"); return 1; } g_sem = res; fflush(stdout); pids = malloc(sizeof(pid_t)*tasks); for (i=0;i