Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1328287pxv; Fri, 16 Jul 2021 06:59:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJHCdzDJjIxenPfx+O3+ObN/XAzMc3/8clZnVOsLAGBD3P/mfYSSjmc+ylDvDrcQzUQNzk X-Received: by 2002:a05:6402:1103:: with SMTP id u3mr15074666edv.342.1626443975093; Fri, 16 Jul 2021 06:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626443975; cv=none; d=google.com; s=arc-20160816; b=cPOx8P/krUdJSrMNt/FBVgzo0Ywx1zE2sl3k+err0wLd8m88MpkGZetoO/SBGxi0I4 u4SreonErPawimUK0J1ppbxKRrY097RwW4Z2U19teYW82gjIoKwe1XcUbOSRM2PZ/g+6 xV/2jmHDTjWDIsqp2+Caf+1WNZh5Y24K2VGSAy/GbCm77XWnt2u+ja7wZMPq5vKQP+io TSRdwbnlFUwi8961+Cve+wufzCoEBujVPu5IIf/aCGSpxkPrZ6vYXLRBXAiI5HP1FiQM 2Y54GGGHAcH5rbvYi3zdP/XnL/SJlDuE+jzW6WSZvXDPTec7uuDg8d9on2GXCy/7kwx1 1ZRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=h6v+FDBeQnRoZ//cxoHOViS1xVmtQ5wKO8sbxgZ7IxQ=; b=fsuwVwlIIi7fzdMWP2kzmR5RVC1hjk8/go7DScrtCwkXdQ6MirYgcAHaj+o3Dd1Mhi KQj66T07WbaVjdR4nrI8F6JBl9KgTaQnXuHGtKDx6+P6kJ574PIaY7b2HHp+I5fHVXYQ 0polk4JvcujfyLtzn99eZBM/qYN4BMIeMJ9duoaoLSuxpxjvwPIXVrNE0n97TbCWcsv+ b2w5LEeZpUb2cdCS4hvMpTCUuLHpEqiW+ZdYla/EzNytinT2bd2iOR3rJ/R67Xo6r9vy 3JasV3vKc9vqCvwHcn63Urwc8TKqS1Moy1ZKDL3lRP2eurFbgtw+Mdxp0PlXwig0Ejmw /voQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Hs6+G709; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o18si9977662edq.519.2021.07.16.06.59.10; Fri, 16 Jul 2021 06:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Hs6+G709; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240237AbhGPN6i (ORCPT + 99 others); Fri, 16 Jul 2021 09:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239738AbhGPN6i (ORCPT ); Fri, 16 Jul 2021 09:58:38 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 397D7C06175F; Fri, 16 Jul 2021 06:55:42 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id a13so12176356wrf.10; Fri, 16 Jul 2021 06:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=h6v+FDBeQnRoZ//cxoHOViS1xVmtQ5wKO8sbxgZ7IxQ=; b=Hs6+G709aR5jo6GSikZL4aOziKc92p+cipf5wI8YSlbK+qAYGKa6Qh1R6iuNTnVgRM 9MapeAiGkmY36C3pgkL4FtMNb5r7a1BKNdCxgfs/02obR3IcRzulTPxIGLMM/A6pVSYI Sh8TH89Vf+nPJRlNaJHYo/vQEkzNBF03iuC7RcVRuNpzmHFOcYygkRko0DV0hMbE2aHL GtbywZRuj5pHT63OPXRYQzNHiIIy8OXOyteOgweFvBY76pysZTDmhqJv81CotPlukilf viSIzST9Fr+/IQF6JF8ppUKt7FyaBd5s1xy85G7aJ1YP+5mB5P5FtAFWy0AiDf2oyolJ 5Bww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=h6v+FDBeQnRoZ//cxoHOViS1xVmtQ5wKO8sbxgZ7IxQ=; b=CuPhqesRSioxWIjkLuylRPSylulVKhqsHliBwNOBS71SucGTmN/RS9WIzoXi8RLbJB yg3o5g5mo6+bko0IT0ZLln1QgWd/qNc9GJesHYK1aoQbXo/rFttAza4ZX667f6HhCAQz zf6iY3HmPXgDHLHmAzlYy134XG7yuesc7iFrSFsCe8ACLgJLnDl0etvUD4z75PmqFJ3s WtMqSEtSIceYUXolZikeUAL4ZmFgbW3A0BrSsyHwu7Ph7FM+VkhL7Hdhf4YqmujBazLy oyd/pw1+HuwZ7g7CoEN0tOdJu2T6xfMrP199/mrO567yeWpsS6JBXeAs6m32j//+A46x FBxQ== X-Gm-Message-State: AOAM533gw8uvASaJCOca0iIefZb6epOhsf7U8E3L8As69yRUH+YrGCz0 uLWd9+AXA6Lt7SMG0C+5WjM= X-Received: by 2002:a5d:6302:: with SMTP id i2mr12587159wru.366.1626443740776; Fri, 16 Jul 2021 06:55:40 -0700 (PDT) Received: from ?IPv6:2001:b07:6456:fd99:ced0:db1c:53e1:191e? ([2001:b07:6456:fd99:ced0:db1c:53e1:191e]) by smtp.gmail.com with ESMTPSA id d15sm10110214wri.39.2021.07.16.06.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 06:55:40 -0700 (PDT) Message-ID: Subject: Re: [RFC PATCH 04/10] perf workqueue: add threadpool execute and wait functions From: Riccardo Mancini To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Ian Rogers , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel , linux-perf-users Date: Fri, 16 Jul 2021 15:55:39 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.2 (3.40.2-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Namhyung, thanks again for the review. On Thu, 2021-07-15 at 16:56 -0700, Namhyung Kim wrote: > On Tue, Jul 13, 2021 at 5:11 AM Riccardo Mancini wrote: > > > > This patch adds: > >  - execute_in_threadpool: assigns a task to the threads to execute > >    asynchronously. > >  - wait_threadpool: waits for the task to complete on all threads. > > Furthermore, testing for these new functions is added. > > > > This patch completes the threadpool. > > > > Signed-off-by: Riccardo Mancini > > --- > >  tools/perf/tests/workqueue.c           |  86 ++++++++++++++++++++- > >  tools/perf/util/workqueue/threadpool.c | 103 +++++++++++++++++++++++++ > >  tools/perf/util/workqueue/threadpool.h |   5 ++ > >  3 files changed, 193 insertions(+), 1 deletion(-) > > > > diff --git a/tools/perf/tests/workqueue.c b/tools/perf/tests/workqueue.c > > index be377e9897bab4e9..3c64db8203556847 100644 > > --- a/tools/perf/tests/workqueue.c > > +++ b/tools/perf/tests/workqueue.c > > @@ -1,13 +1,59 @@ > >  // SPDX-License-Identifier: GPL-2.0 > > +#include > >  #include > > +#include > >  #include "tests.h" > >  #include "util/debug.h" > >  #include "util/workqueue/threadpool.h" > > > > +#define DUMMY_FACTOR 100000 > > +#define N_DUMMY_WORK_SIZES 7 > > + > >  struct threadpool_test_args_t { > >         int pool_size; > >  }; > > > > +struct test_task { > > +       struct task_struct task; > > +       int n_threads; > > +       int *array; > > +}; > > + > > +/** > > + * dummy_work - calculates DUMMY_FACTOR * (idx % N_DUMMY_WORK_SIZES) > > inefficiently > > + * > > + * This function uses modulus to create work items of different sizes. > > + */ > > +static void dummy_work(int idx) > > +{ > > +       int prod = 0; > > I'm not sure but having 'volatile' would prevent some kind of > possible compiler optimizations.. Agreed. > > > +       int k = idx % N_DUMMY_WORK_SIZES; > > +       int i, j; > > + > > +       for (i = 0; i < DUMMY_FACTOR; i++) > > +               for (j = 0; j < k; j++) > > +                       prod ++; > > + > > +       pr_debug3("dummy: %d * %d = %d\n", DUMMY_FACTOR, k, prod); > > +} > > + > > +static void test_task_fn1(int tidx, struct task_struct *task) > > +{ > > +       struct test_task *mtask = container_of(task, struct test_task, > > task); > > + > > +       dummy_work(tidx); > > +       mtask->array[tidx] = tidx+1; > > +} > > + > > +static void test_task_fn2(int tidx, struct task_struct *task) > > +{ > > +       struct test_task *mtask = container_of(task, struct test_task, > > task); > > + > > +       dummy_work(tidx); > > +       mtask->array[tidx] = tidx*2; > > +} > > + > > + > >  static int __threadpool__prepare(struct threadpool_struct **pool, int > > pool_size) > >  { > >         int ret; > > @@ -38,21 +84,59 @@ static int __threadpool__teardown(struct > > threadpool_struct *pool) > >         return 0; > >  } > > > > +static int __threadpool__exec_wait(struct threadpool_struct *pool, > > +                               struct task_struct *task) > > +{ > > +       int ret; > > + > > +       ret = execute_in_threadpool(pool, task); > > +       TEST_ASSERT_VAL("threadpool execute failure", ret == 0); > > +       TEST_ASSERT_VAL("threadpool is not executing", > > threadpool_is_busy(pool)); > > + > > +       ret = wait_threadpool(pool); > > +       TEST_ASSERT_VAL("threadpool wait failure", ret == 0); > > +       TEST_ASSERT_VAL("waited threadpool is not ready", > > threadpool_is_ready(pool)); > > + > > +       return 0; > > +} > > > >  static int __test__threadpool(void *_args) > >  { > >         struct threadpool_test_args_t *args = _args; > >         struct threadpool_struct *pool; > > -       int ret; > > +       int ret, i; > > +       struct test_task task; > > + > > +       task.task.fn = test_task_fn1; > > +       task.n_threads = args->pool_size; > > +       task.array = calloc(args->pool_size, sizeof(*task.array)); > > Need to check the return value. Thanks. > > > > >         ret = __threadpool__prepare(&pool, args->pool_size); > >         if (ret) > >                 return ret; > > > > +       ret = __threadpool__exec_wait(pool, &task.task); > > +       if (ret) > > +               return ret; > > + > > +       for (i = 0; i < args->pool_size; i++) > > +               TEST_ASSERT_VAL("failed array check (1)", task.array[i] == > > i+1); > > + > > +       task.task.fn = test_task_fn2; > > + > > +       ret = __threadpool__exec_wait(pool, &task.task); > > +       if (ret) > > +               return ret; > > + > > +       for (i = 0; i < args->pool_size; i++) > > +               TEST_ASSERT_VAL("failed array check (2)", task.array[i] == > > 2*i); > > + > >         ret = __threadpool__teardown(pool); > >         if (ret) > >                 return ret; > > > > +       free(task.array); > > All previous returns will leak it. Oh, right. Thanks, Riccardo > > Thanks, > Namhyung