From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id TpX6AwLzLWPR5j4AWB0awg (envelope-from ) for ; Fri, 23 Sep 2022 13:55:14 -0400 Received: by simark.ca (Postfix, from userid 112) id 047691E112; Fri, 23 Sep 2022 13:55:14 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=lists.lttng.org header.i=@lists.lttng.org header.a=rsa-sha256 header.s=default header.b=Iti8KnUu; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.lttng.org (lists.lttng.org [167.114.26.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E83B41E0D5 for ; Fri, 23 Sep 2022 13:55:12 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.lttng.org; s=default; t=1663955712; bh=EGCaaatWt/FhsQj+yRvqo3HGbC4P5WB+E5rRIBqVdR4=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Iti8KnUuXx65h9RiYYZDKgLDWrd1XMPoTHkqfJ6YpAXa6ogAXHc5qWXnfUfBR78ks B7f3Jsky4/6Gy7r7cY5b7qvWq1Oi1tadib6rJ0+gxtPTyLa+aj2F2pjqnp8PBXTAZA gbNdMVMXHCjGWG/mPHrWY/ZcwTR+x2P82klnLJIX3SoMnfNYj9S25+PRlKyyE+EJBl ylIKpGz2VhRo21ufOTs6qKajgnRPDrJQ80nFH4V74WZlMr7GqsDEiGfbU1Wgx4BxLN DtyUDRRo/AFYtKQO4ncJWS0fiWJYwnCTCXvLTakO1d1wdY/yyd7iGF7XO0aplLDrQT 44bQYsvviZVhQ== Received: from lists-lttng01.efficios.com (localhost [IPv6:::1]) by lists.lttng.org (Postfix) with ESMTP id 4MZ0DJ0z2nz24LW; Fri, 23 Sep 2022 13:55:12 -0400 (EDT) Received: from dcvr.yhbt.net (dcvr.yhbt.net [173.255.242.215]) by lists.lttng.org (Postfix) with ESMTPS id 4MZ0DH1h2Fz24LV for ; Fri, 23 Sep 2022 13:55:11 -0400 (EDT) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A6FB11F506; Fri, 23 Sep 2022 17:55:03 +0000 (UTC) Date: Fri, 23 Sep 2022 17:55:03 +0000 To: Mathieu Desnoyers Cc: lttng-dev@lists.lttng.org Message-ID: <20220923175503.M564483@dcvr> References: <20220922091536.GA4597@dcvr> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Subject: Re: [lttng-dev] URCU background threads vs signalfd X-BeenThere: lttng-dev@lists.lttng.org X-Mailman-Version: 2.1.39 Precedence: list List-Id: LTTng development list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Eric Wong via lttng-dev Reply-To: Eric Wong Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: lttng-dev-bounces@lists.lttng.org Sender: "lttng-dev" Mathieu Desnoyers wrote: > On 2022-09-22 05:15, Eric Wong via lttng-dev wrote: > > Hello, I'm using urcu-bp + rculfhash + call_rcu to implement > > malloc instrumentation (via LD_PRELOAD) on an existing > > single-threaded Perl codebase which uses Linux signalfd. > > > > signalfd depends on signals being blocked in all threads > > of the process, otherwise threads with unblocked signals > > can receive them and starve the signalfd. > > > > While some threads in URCU do block signals (e.g. workqueue > > worker for rculfhash), the call_rcu thread and rculfhash > > partition_resize_helper threads do not... > > > > Should all threads URCU creates block signals (aside from SIGRCU)? > > Yes, I think you are right. The SIGRCU signal is only needed for the > urcu-signal flavor though. > > Would you like to submit a patch ? Sure. Is there a way to detect at runtime when urcu-signal is in use so SIGRCU (SIGUSR1) doesn't get unblocked when using other flavors? I actually use SIGUSR1 in my signalfd-using codebase. I also want to remove cds_lfht_worker_init entirely since it's racy. Signal blocking needs to be done in the parent before pthread_create to avoid a window where the child has unblocked signals. Thanks. Anyways, this is my work-in-progress: diff --git a/src/rculfhash.c b/src/rculfhash.c index 7c0b9fb..5f455af 100644 --- a/src/rculfhash.c +++ b/src/rculfhash.c @@ -1251,6 +1251,7 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i, struct partition_resize_work *work; int ret; unsigned long thread, nr_threads; + sigset_t newmask, oldmask; urcu_posix_assert(nr_cpus_mask != -1); if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD) @@ -1273,6 +1274,12 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i, dbg_printf("error allocating for resize, single-threading\n"); goto fallback; } + + ret = sigfillset(&newmask); + urcu_posix_assert(!ret); + ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); + urcu_posix_assert(!ret); + for (thread = 0; thread < nr_threads; thread++) { work[thread].ht = ht; work[thread].i = i; @@ -1294,6 +1301,10 @@ void partition_resize_helper(struct cds_lfht *ht, unsigned long i, } urcu_posix_assert(!ret); } + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); + for (thread = 0; thread < nr_threads; thread++) { ret = pthread_join(work[thread].thread_id, NULL); urcu_posix_assert(!ret); diff --git a/src/urcu-call-rcu-impl.h b/src/urcu-call-rcu-impl.h index e9366b4..9f85d55 100644 --- a/src/urcu-call-rcu-impl.h +++ b/src/urcu-call-rcu-impl.h @@ -434,6 +434,7 @@ static void call_rcu_data_init(struct call_rcu_data **crdpp, { struct call_rcu_data *crdp; int ret; + sigset_t newmask, oldmask; crdp = malloc(sizeof(*crdp)); if (crdp == NULL) @@ -448,9 +449,18 @@ static void call_rcu_data_init(struct call_rcu_data **crdpp, crdp->gp_count = 0; cmm_smp_mb(); /* Structure initialized before pointer is planted. */ *crdpp = crdp; + + ret = sigfillset(&newmask); + urcu_posix_assert(!ret); + ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); + urcu_posix_assert(!ret); + ret = pthread_create(&crdp->tid, NULL, call_rcu_thread, crdp); if (ret) urcu_die(ret); + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); } /* diff --git a/src/urcu-defer-impl.h b/src/urcu-defer-impl.h index b5d7926..1c96287 100644 --- a/src/urcu-defer-impl.h +++ b/src/urcu-defer-impl.h @@ -409,9 +409,18 @@ void defer_rcu(void (*fct)(void *p), void *p) static void start_defer_thread(void) { int ret; + sigset_t newmask, oldmask; + + ret = sigfillset(&newmask); + urcu_posix_assert(!ret); + ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); + urcu_posix_assert(!ret); ret = pthread_create(&tid_defer, NULL, thr_defer, NULL); urcu_posix_assert(!ret); + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); } static void stop_defer_thread(void) diff --git a/src/workqueue.c b/src/workqueue.c index b6361ad..1039d72 100644 --- a/src/workqueue.c +++ b/src/workqueue.c @@ -284,6 +284,7 @@ struct urcu_workqueue *urcu_workqueue_create(unsigned long flags, { struct urcu_workqueue *workqueue; int ret; + sigset_t newmask, oldmask; workqueue = malloc(sizeof(*workqueue)); if (workqueue == NULL) @@ -304,10 +305,20 @@ struct urcu_workqueue *urcu_workqueue_create(unsigned long flags, workqueue->cpu_affinity = cpu_affinity; workqueue->loop_count = 0; cmm_smp_mb(); /* Structure initialized before pointer is planted. */ + + ret = sigfillset(&newmask); + urcu_posix_assert(!ret); + ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); + urcu_posix_assert(!ret); + ret = pthread_create(&workqueue->tid, NULL, workqueue_thread, workqueue); if (ret) { urcu_die(ret); } + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); + return workqueue; } @@ -464,13 +475,23 @@ void urcu_workqueue_resume_worker(struct urcu_workqueue *workqueue) void urcu_workqueue_create_worker(struct urcu_workqueue *workqueue) { int ret; + sigset_t newmask, oldmask; /* Clear workqueue state from parent. */ workqueue->flags &= ~URCU_WORKQUEUE_PAUSED; workqueue->flags &= ~URCU_WORKQUEUE_PAUSE; workqueue->tid = 0; + + ret = sigfillset(&newmask); + urcu_posix_assert(!ret); + ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); + urcu_posix_assert(!ret); + ret = pthread_create(&workqueue->tid, NULL, workqueue_thread, workqueue); if (ret) { urcu_die(ret); } + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); } _______________________________________________ lttng-dev mailing list lttng-dev@lists.lttng.org https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev