Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1360631pxb; Fri, 20 Aug 2021 03:59:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlYC50LvqNMBhamBsruvlddzWFdBrk5mQtSefhb89lV/fuLfT3mhAgp+zcP0pSvA0IIE2r X-Received: by 2002:a17:906:ae86:: with SMTP id md6mr12374313ejb.33.1629457168130; Fri, 20 Aug 2021 03:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629457168; cv=none; d=google.com; s=arc-20160816; b=gBSWrb3IEpSCLJMeLxZsYbIX7UaLN16ZtH8aC/bQiHydZ+/7fvMm2HcVnxqV9TQs+F kfkKQvQrV5EA+TKoHXWXeot2qgLkHx7ldeD9LTxSnmRhX8YnqwQBeYC/ra4/q9CZt3Nn YCEht4W+iWs0Iqc10YLHry9UQTsuaRP9DZnRjkaDI+/O8O8ZLUOWrILCpK0hh/2lZXqY P0va2nBv8MRlsl+GBKXqsOhq+K2fN0vUlDh+t4AWKoSrhmp91AS21aUdhgB6jICE0Rj3 IJs1zUcKLvTVA0VZcSuahR3OR6yh3TuFOGfPYogdUhI9A15Anf3BqtEsvLpplMxfKnJf kplA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eCdBEtrU7CII7A1ikCE1/NS99NEQQoA1vVPvKWOOetQ=; b=CDYE8GEc4YWuPy4zPKgSW0QeKDdDWnal79tz93TYXrfHQ7ze2OdhcQIX7oA1T5qar/ yNVEbffOsDf5tIKo78dITq0Pap9MDT78Ljx0cc20ndlS7UDYx9Q3gRQIhkoDlSJgtI8B Ge8a2He8N3psKNvFk/IbNZW16L1iqF/SHq3e5NEP/Ihi7tXZjVAiKPUCpygWpKHutIxB KRl7/nZ+PZej7Y9x+nIhWOyN65hBQwmeqaCfDqhSenO078Ss4l+IJ1uIpUN3KmbIAQbN dgiLoyguHSNc9nPLOR7bshVAxUv+gyWn0LxKR06Y8iXAGfkOOwK1My1cIDjRuRNDSxIT UbZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DyKBEd7u; 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 m4si895726edc.427.2021.08.20.03.59.03; Fri, 20 Aug 2021 03:59:28 -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=DyKBEd7u; 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 S239539AbhHTKzb (ORCPT + 99 others); Fri, 20 Aug 2021 06:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239403AbhHTKzN (ORCPT ); Fri, 20 Aug 2021 06:55:13 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35F9CC061575; Fri, 20 Aug 2021 03:54:28 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id r19so13354484eds.13; Fri, 20 Aug 2021 03:54:28 -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=eCdBEtrU7CII7A1ikCE1/NS99NEQQoA1vVPvKWOOetQ=; b=DyKBEd7uEHaEajl3j0govc1fPM+ZZzjZ9ECdv839kuWWKl59aIEA9II40QzTl6WUOt /Y9u7132H1u4BhMocw6ICPk7aI2bv4jy5gjpvb+qpOEaM19oCHGvBcUajLEnB8ODkw0/ ayeAinFI3MG1U19Crpv27A5daBCiEembwlcamKn3x23I3/Oz6TgOyTKNp1CQeaPsQXs+ Lw1l4fHqSa1srryc6mCEJ0NJxeiLKzr40D/9AXdhNIqjR2VKwJa/29gB2jw3P+ySiExI yNPcrrxw82IYBhSyFfZLqqVtJn/ZlPRntya1qOQohyrxZXP8bXaqlHP8NBbQOvv9usOG zG1g== 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=eCdBEtrU7CII7A1ikCE1/NS99NEQQoA1vVPvKWOOetQ=; b=ZIgMBy1/YPBL11wqj0BhT+cZDHd5epy3ab7a9jUsHFcZqejmIH74RZCIRcl+h9XM1x bcjcJLi/5LqJqeYNYy1MHWewhJtt4g+SCumbQQMP6oiAjK7kRmjEBK+KpG56THlNbNbj GvfzKf08vebLIxkyin43gFxUQB8PbQ0SBGMvndhsQHwKNC3WokmBofkSXFVHUVyaw5gw VQEqKB+tDV/j/n0/uEYpnkX5KI/GM9rwN68c4wdTIA1bLmo7+VE9ovS6ltVx5gurX4QW i4PXZZitG5tL5/IB14oMD/TtUY5xtN72QtI+p2lxOUWj/R4AUlTvYay6SjHWM8tdFgXW EyVw== X-Gm-Message-State: AOAM531OUx1bLn28JTzaL8zOjqTyXVcu4cOsic5VnoTtq42sTGbIch9J 9+S2oyKlwDkqsaOf4E8RtqzZi3pm1Ktb4QBHwzQ= X-Received: by 2002:a05:6402:8ce:: with SMTP id d14mr21700113edz.228.1629456866754; Fri, 20 Aug 2021 03:54:26 -0700 (PDT) Received: from honeypot.epfl.ch (mob-176-243-199-7.net.vodafone.it. [176.243.199.7]) by smtp.googlemail.com with ESMTPSA id g29sm3451459edf.31.2021.08.20.03.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 03:54:25 -0700 (PDT) From: Riccardo Mancini To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Alexey Bayduraev , Riccardo Mancini Subject: [RFC PATCH v3 10/15] perf workqueue: create global workqueue Date: Fri, 20 Aug 2021 12:53:56 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds a global static workqueue, using the same API from the kernel (schedule_work, flush_scheduled_work, and so on). Before use, the global workqueue should be set up using setup_global_workqueue and eventually destroyed using teardown_global_workqueue. Signed-off-by: Riccardo Mancini --- tools/perf/util/workqueue/workqueue.c | 2 ++ tools/perf/util/workqueue/workqueue.h | 49 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/tools/perf/util/workqueue/workqueue.c b/tools/perf/util/workqueue/workqueue.c index 305a9cda39810b84..a89370e68bd720c8 100644 --- a/tools/perf/util/workqueue/workqueue.c +++ b/tools/perf/util/workqueue/workqueue.c @@ -13,6 +13,8 @@ #include #include "workqueue.h" +struct workqueue_struct *global_wq; + enum worker_msg { WORKER_MSG__UNDEFINED, WORKER_MSG__READY, /* from worker: ack */ diff --git a/tools/perf/util/workqueue/workqueue.h b/tools/perf/util/workqueue/workqueue.h index 37ef84fc9c6ed4b6..fc6166757f0e1d0d 100644 --- a/tools/perf/util/workqueue/workqueue.h +++ b/tools/perf/util/workqueue/workqueue.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "threadpool.h" struct work_struct; @@ -29,6 +30,54 @@ extern int flush_workqueue(struct workqueue_struct *wq); extern void init_work(struct work_struct *work); +/* Global workqueue */ + +extern struct workqueue_struct *global_wq; + +/** + * setup_global_wq - create the global_wq + */ +static inline int setup_global_workqueue(int nr_threads) +{ + global_wq = create_workqueue(nr_threads); + return IS_ERR(global_wq) ? PTR_ERR(global_wq) : 0; +} + +/** + * teardown_global_wq - destroy the global_wq + */ +static inline int teardown_global_workqueue(void) +{ + int ret = destroy_workqueue(global_wq); + + global_wq = NULL; + return ret; +} + +/** + * schedule_work - queue @work on the global_wq + */ +static inline int schedule_work(struct work_struct *work) +{ + return queue_work(global_wq, work); +} + +/** + * schedule_work - queue @work on thread @tidx of global_wq + */ +static inline int schedule_work_on_worker(int tidx, struct work_struct *work) +{ + return queue_work_on_worker(tidx, global_wq, work); +} + +/** + * flush_scheduled_work - ensure that any scheduled work in global_wq has run to completion + */ +static inline int flush_scheduled_work(void) +{ + return flush_workqueue(global_wq); +} + #define WORKQUEUE_STRERR_BUFSIZE (128+THREADPOOL_STRERR_BUFSIZE) #define WORKQUEUE_ERROR__OFFSET 512 enum { -- 2.31.1