From patchwork Fri Mar 20 22:10:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vesely X-Patchwork-Id: 6061321 Return-Path: X-Original-To: patchwork-dri-devel@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 C1BE59F399 for ; Fri, 20 Mar 2015 22:10:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B4C9A204E3 for ; Fri, 20 Mar 2015 22:10:36 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8BBD920523 for ; Fri, 20 Mar 2015 22:10:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D1A256ED07; Fri, 20 Mar 2015 15:10:32 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f177.google.com (mail-qc0-f177.google.com [209.85.216.177]) by gabe.freedesktop.org (Postfix) with ESMTP id BAE906E3B7 for ; Fri, 20 Mar 2015 15:10:31 -0700 (PDT) Received: by qcbkw5 with SMTP id kw5so105404836qcb.2 for ; Fri, 20 Mar 2015 15:10:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=A98u+GVtzWyqHxFzX0hYi5cdsIrad6LN2svD6kPpVGU=; b=Oyf1Y0lDOD/77KT42th3uEKZjTzsAM4u0VgImzVwMOmrxm9AFkFTElkk9zpScOXYRW DwFBZ1sq3aDwBYHzhHqkY5JI5lQBIlPYzMp39t/MnbwY/oOOVAB6dbCrj2VAvHqoMdbX 7+LUjQ4PJ82Si3cFPP6jkDDj/GvxWB3lEtn6G3su0PxKGIq9gsdaZqeizwbbzDC15jjU Pgs7z7bJjfuyYujXIaleBSL3V5h6sebS98UWDBew9V9wgD2si4cWEGd26xxuFc/Mqtb+ 8GWHP3brL0Oif6Vp47kZ3SuSMk/It1VsPp4bKWnDLNdALvv4s/adARotA2VIiaF5Kc5f DvFQ== X-Gm-Message-State: ALoCoQl4u10qC4AjBfDXxoNSpNDVX3DprPq6OiYqgpAle//VfnHULELDqUEklEWkudd5Ub+YH8LP X-Received: by 10.140.238.2 with SMTP id j2mr106397230qhc.5.1426889431299; Fri, 20 Mar 2015 15:10:31 -0700 (PDT) Received: from adriatix.rutgers.edu ([198.151.130.140]) by mx.google.com with ESMTPSA id b69sm3928946qka.11.2015.03.20.15.10.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Mar 2015 15:10:30 -0700 (PDT) From: Jan Vesely To: dri-devel@lists.freedesktop.org, Emil Velikov Subject: [PATCH libdrm 4/4] drmSL: Remove test parts Date: Fri, 20 Mar 2015 18:10:28 -0400 Message-Id: <1426889428-4847-4-git-send-email-jan.vesely@rutgers.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426889428-4847-1-git-send-email-jan.vesely@rutgers.edu> References: <1426889428-4847-1-git-send-email-jan.vesely@rutgers.edu> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_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 Signed-off-by: Jan Vesely Reviewed-by: Emil Velikov --- xf86drmSL.c | 172 +++--------------------------------------------------------- 1 file changed, 6 insertions(+), 166 deletions(-) diff --git a/xf86drmSL.c b/xf86drmSL.c index cf588ac..bb9ca7f 100644 --- a/xf86drmSL.c +++ b/xf86drmSL.c @@ -41,13 +41,7 @@ #include #include -#define SL_MAIN 0 - -#if !SL_MAIN -# include "xf86drm.h" -#else -# include -#endif +#include "xf86drm.h" #define SL_LIST_MAGIC 0xfacade00LU #define SL_ENTRY_MAGIC 0x00fab1edLU @@ -56,21 +50,10 @@ #define SL_DEBUG 0 #define SL_RANDOM_SEED 0xc01055a1LU -#if SL_MAIN -#define SL_ALLOC malloc -#define SL_FREE free -#define SL_RANDOM_DECL static int state = 0; -#define SL_RANDOM_INIT(seed) if (!state) { srandom(seed); ++state; } -#define SL_RANDOM random() -#else -#define SL_ALLOC drmMalloc -#define SL_FREE drmFree #define SL_RANDOM_DECL static void *state = NULL #define SL_RANDOM_INIT(seed) if (!state) state = drmRandomCreate(seed) #define SL_RANDOM drmRandom(state) -#endif - typedef struct SLEntry { unsigned long magic; /* SL_ENTRY_MAGIC */ unsigned long key; @@ -87,27 +70,13 @@ typedef struct SkipList { SLEntryPtr p0; /* Position for iteration */ } SkipList, *SkipListPtr; -#if SL_MAIN -extern void *drmSLCreate(void); -extern int drmSLDestroy(void *l); -extern int drmSLLookup(void *l, unsigned long key, void **value); -extern int drmSLInsert(void *l, unsigned long key, void *value); -extern int drmSLDelete(void *l, unsigned long key); -extern int drmSLNext(void *l, unsigned long *key, void **value); -extern int drmSLFirst(void *l, unsigned long *key, void **value); -extern void drmSLDump(void *l); -extern int drmSLLookupNeighbors(void *l, unsigned long key, - unsigned long *prev_key, void **prev_value, - unsigned long *next_key, void **next_value); -#endif - static SLEntryPtr SLCreateEntry(int max_level, unsigned long key, void *value) { SLEntryPtr entry; if (max_level < 0 || max_level > SL_MAX_LEVEL) max_level = SL_MAX_LEVEL; - entry = SL_ALLOC(sizeof(*entry) + entry = drmMalloc(sizeof(*entry) + (max_level + 1) * sizeof(entry->forward[0])); if (!entry) return NULL; entry->magic = SL_ENTRY_MAGIC; @@ -134,7 +103,7 @@ void *drmSLCreate(void) SkipListPtr list; int i; - list = SL_ALLOC(sizeof(*list)); + list = drmMalloc(sizeof(*list)); if (!list) return NULL; list->magic = SL_LIST_MAGIC; list->level = 0; @@ -158,11 +127,11 @@ int drmSLDestroy(void *l) if (entry->magic != SL_ENTRY_MAGIC) return -1; /* Bad magic */ next = entry->forward[0]; entry->magic = SL_FREED_MAGIC; - SL_FREE(entry); + drmFree(entry); } list->magic = SL_FREED_MAGIC; - SL_FREE(list); + drmFree(list); return 0; } @@ -236,7 +205,7 @@ int drmSLDelete(void *l, unsigned long key) } entry->magic = SL_FREED_MAGIC; - SL_FREE(entry); + drmFree(entry); while (list->level && !list->head->forward[list->level]) --list->level; --list->count; @@ -348,132 +317,3 @@ void drmSLDump(void *l) } } } - -#if SL_MAIN -static void print(SkipListPtr list) -{ - unsigned long key; - void *value; - - if (drmSLFirst(list, &key, &value)) { - do { - printf("key = %5lu, value = %p\n", key, value); - } while (drmSLNext(list, &key, &value)); - } -} - -static double do_time(int size, int iter) -{ - SkipListPtr list; - int i, j; - unsigned long keys[1000000]; - unsigned long previous; - unsigned long key; - void *value; - struct timeval start, stop; - double usec; - SL_RANDOM_DECL; - - SL_RANDOM_INIT(12345); - - list = drmSLCreate(); - - for (i = 0; i < size; i++) { - keys[i] = SL_RANDOM; - drmSLInsert(list, keys[i], NULL); - } - - previous = 0; - if (drmSLFirst(list, &key, &value)) { - do { - if (key <= previous) { - printf( "%lu !< %lu\n", previous, key); - } - previous = key; - } while (drmSLNext(list, &key, &value)); - } - - gettimeofday(&start, NULL); - for (j = 0; j < iter; j++) { - for (i = 0; i < size; i++) { - if (drmSLLookup(list, keys[i], &value)) - printf("Error %lu %d\n", keys[i], i); - } - } - gettimeofday(&stop, NULL); - - usec = (double)(stop.tv_sec * 1000000 + stop.tv_usec - - start.tv_sec * 1000000 - start.tv_usec) / (size * iter); - - printf("%0.2f microseconds for list length %d\n", usec, size); - - drmSLDestroy(list); - - return usec; -} - -static void print_neighbors(void *list, unsigned long key) -{ - unsigned long prev_key = 0; - unsigned long next_key = 0; - void *prev_value; - void *next_value; - int retval; - - retval = drmSLLookupNeighbors(list, key, - &prev_key, &prev_value, - &next_key, &next_value); - printf("Neighbors of %5lu: %d %5lu %5lu\n", - key, retval, prev_key, next_key); -} - -int main(void) -{ - SkipListPtr list; - double usec, usec2, usec3, usec4; - - list = drmSLCreate(); - printf( "list at %p\n", list); - - print(list); - printf("\n==============================\n\n"); - - drmSLInsert(list, 123, NULL); - drmSLInsert(list, 213, NULL); - drmSLInsert(list, 50, NULL); - print(list); - printf("\n==============================\n\n"); - - print_neighbors(list, 0); - print_neighbors(list, 50); - print_neighbors(list, 51); - print_neighbors(list, 123); - print_neighbors(list, 200); - print_neighbors(list, 213); - print_neighbors(list, 256); - printf("\n==============================\n\n"); - - drmSLDelete(list, 50); - print(list); - printf("\n==============================\n\n"); - - drmSLDump(list); - drmSLDestroy(list); - printf("\n==============================\n\n"); - - usec = do_time(100, 10000); - usec2 = do_time(1000, 500); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 1000.0/100.0, usec2 / usec); - - usec3 = do_time(10000, 50); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 10000.0/100.0, usec3 / usec); - - usec4 = do_time(100000, 4); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 100000.0/100.0, usec4 / usec); - - return 0; -} -#endif