Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3388182pxb; Mon, 30 Aug 2021 00:24:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySC12UQzeVpYR0BEkGlfepahj26kCDyVbIPa0IY/uIFpTCmgWAu0haCVbEZ6pW0djvJfT9 X-Received: by 2002:a05:6638:bcf:: with SMTP id g15mr17031529jad.1.1630308287841; Mon, 30 Aug 2021 00:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630308287; cv=none; d=google.com; s=arc-20160816; b=Yap3nPKxlSOxRGNLglNQGIEmXRAI4vZrvN9Z8/EtvB/+wG2DEirJuJmN4Q14W0RJ96 perJ+pzqC+Gcy3yrBfD/bhxDi6ZEC1HZUd+1Qz3nmVbznK0JwcMFxvTQYTe2RnCl3ZOG lz+tF+nXuUKcOCQItYI0zAxXeMnNXbnPTRtY7pPtvPWkE1sSYyPVDSxMJodh+SVlxdNT 2ytqFVeYYeXErep23c1GDi8u8BUILUAd3VngMbW1VazNWq8nmzvylMWbWlwziGCgA7su q/WwC1hvK/fzDggBCIWoutaVIJ7tK+7v0PePQs/vbEaVS7CS94pKgue75alzcSkU0342 fmQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Of3siqEPDqPdwmkid/X1JM35PbSnr5CA8rhlc97cSLk=; b=FPSFfcj9n/I8X/QwlRr6QtPob+rxl/t6ddfOSNBr6Fp7Zg2l+C095w3kEZQ0ApU8Me anEO2Wpf3PvmkxeyJqQMtwRwhU41jBxRJYoUrPnvV8h2cn7UYwokqxc1GzgJIsDf4YfC ghNgM+pnz54lc4TyBGQsM2iSCq6UcvS6kwl2H41EtBamsQjaDQ10lZZRTuhWelHFINmW UkKgajs0B8nmnE+dGeXGHetnn0FWN6ipy4cKYW0rsjMz6jnPyEKeOFzQdnP/nzKh8QXa 8SlS153rIZYpc0zGJVDUgPx0ersxhaQJszbwJ1G1qelQCimQPFGYkWD99ugfq60A88T4 SEBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=evJ8pU0E; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s19si12597443ioj.101.2021.08.30.00.24.35; Mon, 30 Aug 2021 00:24:47 -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=@redhat.com header.s=mimecast20190719 header.b=evJ8pU0E; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233957AbhH3HXr (ORCPT + 99 others); Mon, 30 Aug 2021 03:23:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55724 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233963AbhH3HXq (ORCPT ); Mon, 30 Aug 2021 03:23:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630308172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Of3siqEPDqPdwmkid/X1JM35PbSnr5CA8rhlc97cSLk=; b=evJ8pU0ERiGsg8Fi3xasxlfn9ogseMoVm2bLNW7RGeoWWKALQkaVY50Ss08lJ82K/Vu3MV 7kj93m7V5qwJxs2uQbSwi8DnrdqANzsLZc+Cqc2fD0aPMS9pAWgNay5+4WDbAvKP30uK/U uFkRpvQVPh2CcWSglM9rw1cvt/G7IXk= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-tDFVD-RkMn6YwipRhUceCA-1; Mon, 30 Aug 2021 03:22:50 -0400 X-MC-Unique: tDFVD-RkMn6YwipRhUceCA-1 Received: by mail-ej1-f70.google.com with SMTP id o14-20020a1709062e8e00b005d37183e041so3768434eji.21 for ; Mon, 30 Aug 2021 00:22:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Of3siqEPDqPdwmkid/X1JM35PbSnr5CA8rhlc97cSLk=; b=QDmPQkzhIwwfafxpEwyc/TJsnWew+p/sZSOwoKbpkgZBlR/GoF1a76f6Qy7GU3BoWT YzaiN0oDrx5lINtUqr9lj6udBlt2Iqanh1Wbmdz7RK1eR6pfipE72qeI/z3fAGLTzINT qSOGKdbrUEeWaj7tAplil8W+jCfdBUXfbnQ9mDtKVhBGaHz+ZTDj+H3COYgjvaj1CqqM +Z5uzELixLY2zafSuO9QtnAdyAAcgSqc5yHhlsTDc4dfi0F7DTVjkhCwZLDfv2Lg6PlH r5UtaDAwZKJeMGSs1dY85gODpZ8dPeNX8AqoPnPKLPgGeUqXYBxK1gGgBm+jxbF0m4Ml vkDg== X-Gm-Message-State: AOAM533ZNuTMc/CInO8hMiGny9FvEPIlZe4cRx90eOMqS1dB3dNx4BYs QP343Fq2hY5i49nGw1qujgtD5FPe1Ioth5K6nfzWNpSrydRGIp+S0iZ0WsoEa+ztUM+2oiMl+Z0 eL0lJW1rKGamiXFAMpW4sVW67 X-Received: by 2002:a17:906:4fd6:: with SMTP id i22mr24095530ejw.92.1630308169315; Mon, 30 Aug 2021 00:22:49 -0700 (PDT) X-Received: by 2002:a17:906:4fd6:: with SMTP id i22mr24095517ejw.92.1630308169151; Mon, 30 Aug 2021 00:22:49 -0700 (PDT) Received: from krava ([83.240.63.86]) by smtp.gmail.com with ESMTPSA id p16sm7057110eds.63.2021.08.30.00.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 00:22:48 -0700 (PDT) Date: Mon, 30 Aug 2021 09:22:47 +0200 From: Jiri Olsa To: Riccardo Mancini Cc: Arnaldo Carvalho de Melo , Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Alexey Bayduraev Subject: Re: [RFC PATCH v3 07/15] perf workqueue: implement worker thread and management Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 20, 2021 at 12:53:53PM +0200, Riccardo Mancini wrote: SNIP > /** > * create_workqueue - create a workqueue associated to @pool > * > @@ -41,7 +361,8 @@ static const char * const workqueue_errno_str[] = { > */ > struct workqueue_struct *create_workqueue(int nr_threads) > { > - int ret, err = 0; > + int ret, err = 0, t; > + struct worker *worker; > struct workqueue_struct *wq = zalloc(sizeof(struct workqueue_struct)); > > if (!wq) { > @@ -56,10 +377,16 @@ struct workqueue_struct *create_workqueue(int nr_threads) > goto out_free_wq; > } > > + wq->workers = calloc(nr_threads, sizeof(*wq->workers)); > + if (!wq->workers) { > + err = -ENOMEM; > + goto out_delete_pool; > + } > + > ret = pthread_mutex_init(&wq->lock, NULL); > if (ret) { > err = -ret; > - goto out_delete_pool; > + goto out_free_workers; > } > > ret = pthread_cond_init(&wq->idle_cond, NULL); > @@ -77,12 +404,41 @@ struct workqueue_struct *create_workqueue(int nr_threads) > goto out_destroy_cond; > } > > + wq->task.fn = worker_thread; > + > + wq->pool_errno = threadpool__execute(wq->pool, &wq->task); > + if (wq->pool_errno) { > + err = -WORKQUEUE_ERROR__POOLEXE; > + goto out_close_pipe; > + } hum, why the threadpool__execute in here? threads are not runnig at this point, so nothing will happen right? jirka > + > + for (t = 0; t < nr_threads; t++) { > + err = spinup_worker(wq, t); > + if (err) > + goto out_stop_pool; > + } > + > return wq; > > +out_stop_pool: > + lock_workqueue(wq); > + for_each_idle_worker(wq, worker) { > + ret = stop_worker(worker); > + if (ret) > + err = ret; > + } > + unlock_workqueue(wq); > +out_close_pipe: > + close(wq->msg_pipe[0]); > + wq->msg_pipe[0] = -1; > + close(wq->msg_pipe[1]); > + wq->msg_pipe[1] = -1; > out_destroy_cond: > pthread_cond_destroy(&wq->idle_cond); > out_destroy_mutex: > pthread_mutex_destroy(&wq->lock); > +out_free_workers: > + free(wq->workers); > out_delete_pool: > threadpool__delete(wq->pool); > out_free_wq: > @@ -96,12 +452,27 @@ struct workqueue_struct *create_workqueue(int nr_threads) > */ SNIP