From patchwork Fri Apr 2 20:22:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Uladzislau Rezki (Sony)" X-Patchwork-Id: 12181511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01E3FC43460 for ; Fri, 2 Apr 2021 20:22:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 866AE61151 for ; Fri, 2 Apr 2021 20:22:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 866AE61151 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A27EA6B0095; Fri, 2 Apr 2021 16:22:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D9A76B0098; Fri, 2 Apr 2021 16:22:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78D416B0099; Fri, 2 Apr 2021 16:22:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 568D56B0095 for ; Fri, 2 Apr 2021 16:22:51 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0049B184B009D for ; Fri, 2 Apr 2021 20:22:50 +0000 (UTC) X-FDA: 77988550542.19.30F2D69 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by imf14.hostedemail.com (Postfix) with ESMTP id 354CEC0001FE for ; Fri, 2 Apr 2021 20:22:48 +0000 (UTC) Received: by mail-lj1-f173.google.com with SMTP id o16so6651112ljp.3 for ; Fri, 02 Apr 2021 13:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NlTZYOTP6gxY+A8f1lp9gD0t94fGeKsz+KEdX5TSTq4=; b=IL8emjWCMFzBpzm2REpTKSDItPqwcRHkwDyhpVa+fQUkJHytbmfdiE4bYlyWATY2+w vGTzZ0xBGkMjQPOKifR5x0SRxTG5xC72QHw+kb5i6FZbHNZsW5bB5fBxr6sojWyFhWt4 X1xXaYrNxVN9lblPGDiEvQMy5/KffFH4hkIo8BEUkoY3t793mTbMa9DxGLkN3te4my0o RXKafDau/hoEXeBFpQ4TuNACE7UmlDCyaBx8kX6IhRI6V4d1HnMZ/KogECpPd0Hd3Ub0 53KDDwBj5vpxhBAzPjV0CNJ/XDi9uCuiiJ7J/rXVXGxLoqAYHSZmfWj+F8WQOdZ5e5N+ CtOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NlTZYOTP6gxY+A8f1lp9gD0t94fGeKsz+KEdX5TSTq4=; b=q4J+D0GWncxciuwV7FtXNheWa7XJhLEsWrDdKHiDlMKkaqP1LrV87elr3H5Y6vg8Yw tSp3kj9PmxZTMryYWBXsQ1+9bYndLuMnqyT5CXAlq/6ciyP6xy0tknaVAQ73uvaIp0jv tOpnbKqLSi8aOdbR61J6eUkoxeRPFgLLaSUfBczmnsLqz2iKt8CK67yPFZZMU1ggwuom t5Ib4j/339M59LkgHuk5s+a6tH/tqyGAbDOG/EzXF9TAq9pjnpKyoj3+D7uEsIW+3Iqe YasLik2R5NHBz0vAQoR22T3DasRzzle3JXKnFzWXY4YoBfS1eXBupHdr1vsA3U7vEQuT KzUA== X-Gm-Message-State: AOAM531XWXm+JtYhHrQBhiIqqSaVQMBf8pvgUsJzdWiXbE6nmn+LQlIo 9+wSUTRZa72AXrojRxklFI8= X-Google-Smtp-Source: ABdhPJxrao1ogZYKuL2wEhq0h305cuoO/EgEpfZutWpdL6CCxZVyr0MHx315wkyYwd+B5ezHkncHwQ== X-Received: by 2002:a2e:6e17:: with SMTP id j23mr9128468ljc.209.1617394969128; Fri, 02 Apr 2021 13:22:49 -0700 (PDT) Received: from pc638.lan (h5ef52e3d.seluork.dyn.perspektivbredband.net. [94.245.46.61]) by smtp.gmail.com with ESMTPSA id f11sm952514lfr.119.2021.04.02.13.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Apr 2021 13:22:48 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: Andrew Morton Cc: linux-mm@kvack.org, LKML , Uladzislau Rezki , Hillf Danton , Michal Hocko , Matthew Wilcox , Oleksiy Avramchenko , Steven Rostedt Subject: [PATCH-next 2/5] lib/test_vmalloc.c: add a new 'nr_threads' parameter Date: Fri, 2 Apr 2021 22:22:34 +0200 Message-Id: <20210402202237.20334-2-urezki@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210402202237.20334-1-urezki@gmail.com> References: <20210402202237.20334-1-urezki@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 354CEC0001FE X-Stat-Signature: bfncxrzh3spws8p9kzhsh7oiqt7a5m97 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=mail-lj1-f173.google.com; client-ip=209.85.208.173 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617394968-180089 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: By using this parameter we can specify how many workers are created to perform vmalloc tests. By default it is one CPU. The maximum value is set to 1024. As a result of this change a 'single_cpu_test' one becomes obsolete, therefore it is no longer needed. Signed-off-by: Uladzislau Rezki (Sony) --- lib/test_vmalloc.c | 88 +++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index 4eb6abdaa74e..d337985e4c5e 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -23,8 +23,8 @@ module_param(name, type, 0444); \ MODULE_PARM_DESC(name, msg) \ -__param(bool, single_cpu_test, false, - "Use single first online CPU to run tests"); +__param(int, nr_threads, 0, + "Number of workers to perform tests(min: 1 max: 1024)"); __param(bool, sequential_test_order, false, "Use sequential stress tests order"); @@ -50,13 +50,6 @@ __param(int, run_test_mask, INT_MAX, /* Add a new test case description here. */ ); -/* - * Depends on single_cpu_test parameter. If it is true, then - * use first online CPU to trigger a test on, otherwise go with - * all online CPUs. - */ -static cpumask_t cpus_run_test_mask = CPU_MASK_NONE; - /* * Read write semaphore for synchronization of setup * phase that is done in main thread and workers. @@ -386,16 +379,13 @@ struct test_case_data { u64 time; }; -/* Split it to get rid of: WARNING: line over 80 characters */ -static struct test_case_data - per_cpu_test_data[NR_CPUS][ARRAY_SIZE(test_case_array)]; - static struct test_driver { struct task_struct *task; + struct test_case_data data[ARRAY_SIZE(test_case_array)]; + unsigned long start; unsigned long stop; - int cpu; -} per_cpu_test_driver[NR_CPUS]; +} *tdriver; static void shuffle_array(int *arr, int n) { @@ -423,9 +413,6 @@ static int test_func(void *private) ktime_t kt; u64 delta; - if (set_cpus_allowed_ptr(current, cpumask_of(t->cpu)) < 0) - pr_err("Failed to set affinity to %d CPU\n", t->cpu); - for (i = 0; i < ARRAY_SIZE(test_case_array); i++) random_array[i] = i; @@ -450,9 +437,9 @@ static int test_func(void *private) kt = ktime_get(); for (j = 0; j < test_repeat_count; j++) { if (!test_case_array[index].test_func()) - per_cpu_test_data[t->cpu][index].test_passed++; + t->data[index].test_passed++; else - per_cpu_test_data[t->cpu][index].test_failed++; + t->data[index].test_failed++; } /* @@ -461,7 +448,7 @@ static int test_func(void *private) delta = (u64) ktime_us_delta(ktime_get(), kt); do_div(delta, (u32) test_repeat_count); - per_cpu_test_data[t->cpu][index].time = delta; + t->data[index].time = delta; } t->stop = get_cycles(); @@ -477,53 +464,56 @@ static int test_func(void *private) return 0; } -static void +static int init_test_configurtion(void) { /* - * Reset all data of all CPUs. + * A maximum number of workers is defined as hard-coded + * value and set to 1024. We add such gap just in case + * and for potential heavy stressing. */ - memset(per_cpu_test_data, 0, sizeof(per_cpu_test_data)); + nr_threads = clamp(nr_threads, 1, 1024); - if (single_cpu_test) - cpumask_set_cpu(cpumask_first(cpu_online_mask), - &cpus_run_test_mask); - else - cpumask_and(&cpus_run_test_mask, cpu_online_mask, - cpu_online_mask); + /* Allocate the space for test instances. */ + tdriver = kcalloc(nr_threads, sizeof(*tdriver), GFP_KERNEL); + if (tdriver == NULL) + return -1; if (test_repeat_count <= 0) test_repeat_count = 1; if (test_loop_count <= 0) test_loop_count = 1; + + return 0; } static void do_concurrent_test(void) { - int cpu, ret; + int i, ret; /* * Set some basic configurations plus sanity check. */ - init_test_configurtion(); + ret = init_test_configurtion(); + if (ret < 0) + return; /* * Put on hold all workers. */ down_write(&prepare_for_test_rwsem); - for_each_cpu(cpu, &cpus_run_test_mask) { - struct test_driver *t = &per_cpu_test_driver[cpu]; + for (i = 0; i < nr_threads; i++) { + struct test_driver *t = &tdriver[i]; - t->cpu = cpu; - t->task = kthread_run(test_func, t, "vmalloc_test/%d", cpu); + t->task = kthread_run(test_func, t, "vmalloc_test/%d", i); if (!IS_ERR(t->task)) /* Success. */ atomic_inc(&test_n_undone); else - pr_err("Failed to start kthread for %d CPU\n", cpu); + pr_err("Failed to start %d kthread\n", i); } /* @@ -541,29 +531,31 @@ static void do_concurrent_test(void) ret = wait_for_completion_timeout(&test_all_done_comp, HZ); } while (!ret); - for_each_cpu(cpu, &cpus_run_test_mask) { - struct test_driver *t = &per_cpu_test_driver[cpu]; - int i; + for (i = 0; i < nr_threads; i++) { + struct test_driver *t = &tdriver[i]; + int j; if (!IS_ERR(t->task)) kthread_stop(t->task); - for (i = 0; i < ARRAY_SIZE(test_case_array); i++) { - if (!((run_test_mask & (1 << i)) >> i)) + for (j = 0; j < ARRAY_SIZE(test_case_array); j++) { + if (!((run_test_mask & (1 << j)) >> j)) continue; pr_info( "Summary: %s passed: %d failed: %d repeat: %d loops: %d avg: %llu usec\n", - test_case_array[i].test_name, - per_cpu_test_data[cpu][i].test_passed, - per_cpu_test_data[cpu][i].test_failed, + test_case_array[j].test_name, + t->data[j].test_passed, + t->data[j].test_failed, test_repeat_count, test_loop_count, - per_cpu_test_data[cpu][i].time); + t->data[j].time); } - pr_info("All test took CPU%d=%lu cycles\n", - cpu, t->stop - t->start); + pr_info("All test took worker%d=%lu cycles\n", + i, t->stop - t->start); } + + kfree(tdriver); } static int vmalloc_test_init(void)