From: Jiri Olsa <jolsa@redhat.com>
To: Riccardo Mancini <rickyman7@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Subject: Re: [RFC PATCH v2 06/10] perf workqueue: introduce workqueue struct
Date: Mon, 9 Aug 2021 14:04:59 +0200 [thread overview]
Message-ID: <YREZ65Jw9J5bB68u@krava> (raw)
In-Reply-To: <c946622ece7d1d1b99912563f6a7c56402955156.1627657061.git.rickyman7@gmail.com>
On Fri, Jul 30, 2021 at 05:34:13PM +0200, Riccardo Mancini wrote:
SNIP
> +static void worker_thread(int tidx, struct task_struct *task)
> +{
> +
> + pr_info("Hi from worker %d, executing task %p\n", tidx, task);
> +}
> +
> +/**
> + * attach_threadpool_to_workqueue - start @wq workers on @pool
> + */
> +static int attach_threadpool_to_workqueue(struct workqueue_struct *wq,
> + struct threadpool *pool)
> +{
> + if (!threadpool__is_ready(pool)) {
> + pr_debug2("workqueue: cannot attach to pool: pool is not ready\n");
> + return -WORKQUEUE_ERROR__NOTALLOWED;
> + }
> +
> + wq->pool = pool;
> +
> + wq->pool_errno = threadpool__execute(pool, &wq->task);
> + if (wq->pool_errno)
> + return -WORKQUEUE_ERROR__POOLEXE;
SNIP
> +
> +/**
> + * create_workqueue - create a workqueue associated to @pool
> + *
> + * Only one workqueue can execute on a pool at a time.
> + */
> +struct workqueue_struct *create_workqueue(struct threadpool *pool)
> +{
> + int ret, err = 0;
> + struct workqueue_struct *wq = malloc(sizeof(struct workqueue_struct));
> +
> + if (!wq) {
> + err = -ENOMEM;
> + goto out_return;
> + }
> +
> + ret = pthread_mutex_init(&wq->lock, NULL);
> + if (ret) {
> + err = -ret;
> + goto out_free_wq;
> + }
> +
> + ret = pthread_cond_init(&wq->idle_cond, NULL);
> + if (ret) {
> + err = -ret;
> + goto out_destroy_mutex;
> + }
> +
> + wq->pool = NULL;
> + INIT_LIST_HEAD(&wq->busy_list);
> + INIT_LIST_HEAD(&wq->idle_list);
> +
> + INIT_LIST_HEAD(&wq->pending);
> +
> + ret = pipe(wq->msg_pipe);
> + if (ret) {
> + err = -ENOMEM;
> + goto out_destroy_cond;
> + }
> +
> + wq->task.fn = worker_thread;
> +
> + ret = attach_threadpool_to_workqueue(wq, pool);
> + if (ret) {
> + err = ret;
> + goto out_destroy_cond;
> + }
> +
> + wq->status = WORKQUEUE_STATUS__READY;
> +
> + return wq;
> +
> +out_destroy_cond:
> + pthread_cond_destroy(&wq->idle_cond);
leaking wq->msg_pipe?
thanks,
jirka
> +out_destroy_mutex:
> + pthread_mutex_destroy(&wq->lock);
> +out_free_wq:
> + free(wq);
> +out_return:
> + return ERR_PTR(err);
> +}
> +
SNIP
next prev parent reply other threads:[~2021-08-09 12:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1627657061.git.rickyman7@gmail.com>
2021-07-30 15:34 ` [RFC PATCH v2 01/10] perf workqueue: threadpool creation and destruction Riccardo Mancini
2021-08-07 2:24 ` Namhyung Kim
2021-08-09 10:30 ` Riccardo Mancini
2021-08-10 18:54 ` Namhyung Kim
2021-08-10 20:24 ` Arnaldo Carvalho de Melo
2021-08-11 17:55 ` Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 02/10] perf tests: add test for workqueue Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 03/10] perf workqueue: add threadpool start and stop functions Riccardo Mancini
2021-08-07 2:43 ` Namhyung Kim
2021-08-09 10:35 ` Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 04/10] perf workqueue: add threadpool execute and wait functions Riccardo Mancini
2021-08-07 2:56 ` Namhyung Kim
2021-07-30 15:34 ` [RFC PATCH v2 05/10] tools: add sparse context/locking annotations in compiler-types.h Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 06/10] perf workqueue: introduce workqueue struct Riccardo Mancini
2021-08-09 12:04 ` Jiri Olsa [this message]
2021-07-30 15:34 ` [RFC PATCH v2 07/10] perf workqueue: implement worker thread and management Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 08/10] perf workqueue: add queue_work and flush_workqueue functions Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 09/10] perf workqueue: add utility to execute a for loop in parallel Riccardo Mancini
2021-07-30 15:34 ` [RFC PATCH v2 10/10] perf synthetic-events: use workqueue parallel_for Riccardo Mancini
2021-08-09 12:04 ` Jiri Olsa
2021-08-09 13:24 ` Riccardo Mancini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YREZ65Jw9J5bB68u@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=alexey.v.bayduraev@linux.intel.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=rickyman7@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).