From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-5.6 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A49081F8C6 for ; Thu, 26 Aug 2021 16:49:20 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C11E5385843B for ; Thu, 26 Aug 2021 16:49:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C11E5385843B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629996559; bh=d6iOP6KsDSMFzIqy6kbBdttkV7A7Spicp4U3KPHqkvI=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rl76JvgtCAYM5vFOeWcMkCuLOmCyoruUZPt6Hrtd2Aerb1zAoMEFmmZIdymR5Uwcl bIcZJiCw+9I07g/NHEVeOEKE/ym7FhF5VhHq4+nbFhumOcZnP8AlNIuesx/HUbzjws 59qWgTHhxGy1Z0KXz9w8rYX+rA+bouP1Twrg3rqU= Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by sourceware.org (Postfix) with ESMTPS id 8B2B03858413 for ; Thu, 26 Aug 2021 16:48:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B2B03858413 Received: by mail-qt1-x82f.google.com with SMTP id s32so2983970qtc.12 for ; Thu, 26 Aug 2021 09:48: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:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=d6iOP6KsDSMFzIqy6kbBdttkV7A7Spicp4U3KPHqkvI=; b=oWAINsWXONhv1GAfnOYQxtxAgp6akvzq0QIplBEKxbC6/5oxKwFPuc792LB1CnNjaG FqtLcdGLukka3KC3g5lbhirrj3sUHqh5F54Rho/TxDUfq6ehyiHBXjeUhkZNRFd3qIWP 9FraZLOHHhfeaV6QSPhIYxnGoCZQh7dXADaDmT4HWAf0BxKYkTb1cbcNstdiVAcXMZNG 7yKFFS3hJymq6LApugmH0AjZ/rL1kyhMF2VIOZo8y61HQT2vUFt35QROfnN5RmIudGhK IEEVD7274X9aTSbjWS4y5oE5UX8X+UulaxgRU3mXvIQLP2kZtylFoU6rm6Y5RBfHtNYX 5UGQ== X-Gm-Message-State: AOAM5309roUGMyL6xwusdJmnCR4h/ax6Fsm6cM3FvkwjyHJTrivSvuLy Xim4SmN+HYq6duOBmLG77F2eG/TiWCmktQ== X-Google-Smtp-Source: ABdhPJw+cA7ZztpI3MGg8uF6ACQlZCxp1FhiyR1htAZCOoPOq1qB3au2mCw4jVXQgem83WgFx8S6oQ== X-Received: by 2002:ac8:5a13:: with SMTP id n19mr3128798qta.380.1629996529888; Thu, 26 Aug 2021 09:48:49 -0700 (PDT) Received: from ?IPv6:2804:431:c7ca:1a68:4e82:9e7c:b7e4:7f3? ([2804:431:c7ca:1a68:4e82:9e7c:b7e4:7f3]) by smtp.gmail.com with ESMTPSA id h17sm2005285qtu.68.2021.08.26.09.48.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Aug 2021 09:48:49 -0700 (PDT) Subject: Re: [PATCH v2 06/19] nptl: Replace struct thread cancelhandling field To: Florian Weimer References: <20210823195047.543237-1-adhemerval.zanella@linaro.org> <20210823195047.543237-7-adhemerval.zanella@linaro.org> <87r1eg5l6h.fsf@oldenburg.str.redhat.com> Message-ID: <51cfec46-c7ee-b588-80e1-00a83034c358@linaro.org> Date: Thu, 26 Aug 2021 13:48:47 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <87r1eg5l6h.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" On 26/08/2021 11:34, Florian Weimer wrote: > * Adhemerval Zanella: > >> Now that both thread state and setxid is being tracked by two different >> fields ('joinstate' and 'setxid_flag'), there is no need to keep track >> of exiting (EXITING_BIT) and terminated (TERMINATED_BIT) state in >> 'cancelhandling'. >> >> The 'cancelhandling' field is renamed to 'cancelstatus' and it only >> signals whether the thread has been cancelled (set by pthread_cancel()). >> It allows simplify the atomic operation required to avoid CAS >> operations. > > “cancelstatus” is a bad name because “cancel state” is POSIX terminology > with different meaning. Please choose a different name. > > I think pending_cancel or cancel_requested would work. The cancel_requested sounds ok. > >> There is no need to check the thread state on >> __pthread_enable_asynccancel() nor on pthread_testcancel () anymore, >> since cancellation is explicit disabled when thread start the exit code >> on __do_cancel(). > > “explict[ly]” Ack. > >> >> On __nptl_free_tcp(), the 'joinstate' now defines whether it is the > > “__nptl_free_tcb”. Ack. > >> creating thread or the created thread that calls it. So there is >> no concurrent call within the function and thus no need to set the >> TERMINATED_BIT. >> >> For SIGCANCEL handler, sigcancel_handler(), 'joinstate' is used instead >> (pthread_cancel() might still be called concurrenty in assynchronous >> mode). > > “as[]ynchronous” > Ack. >> diff --git a/nptl/nptl_free_tcb.c b/nptl/nptl_free_tcb.c >> index cbf3580f59..15e1a18562 100644 >> --- a/nptl/nptl_free_tcb.c >> +++ b/nptl/nptl_free_tcb.c >> @@ -24,22 +24,12 @@ >> void >> __nptl_free_tcb (struct pthread *pd) >> { >> - /* The thread is exiting now. */ >> - if (atomic_bit_test_set (&pd->cancelhandling, TERMINATED_BIT) == 0) >> - { >> - /* Free TPP data. */ >> - if (pd->tpp != NULL) >> - { >> - struct priority_protection_data *tpp = pd->tpp; >> + free (pd->tpp); >> + pd->tpp = NULL; > > For detached threads, this is called on the thread after signals have > been blocked. I don't think this is entirely correct. And things > become rather interesting if malloc needs pd->tpp. Why do you think this is not correct? This is accessed through mutex code, so I don't think this would matter on the detached exit phase. And what do you mean by malloc needing? > > It's not clear to me whether this could happen before. > >> + /* Queue the stack memory block for reuse and exit the process. The kernel >> + will signal via writing to the address returned by QUEUE-STACK when the >> + stack is available. */ >> + __nptl_deallocate_stack (pd); >> } > > That old comment seems to be out-of-date. It is still correct I think, __nptl_stack_in_use() now checks the joinstate which is still advertise by the kernel. > >> libc_hidden_def (__nptl_free_tcb) >> diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c >> index 67e00ef007..aed6c1ea47 100644 >> --- a/nptl/pthread_cancel.c >> +++ b/nptl/pthread_cancel.c > >> @@ -93,8 +90,9 @@ __pthread_cancel (pthread_t th) >> } >> #endif >> >> - int oldch = atomic_fetch_or_acquire (&pd->cancelhandling, CANCELED_BITMASK); >> - if ((oldch & CANCELED_BITMASK) != 0) >> + /* If already cancelled just return (cancellation will be acted upon in next >> + cancellation entrypoint). */ >> + if (atomic_exchange_acquire (&pd->cancelstatus, 1) == 1) >> return 0; > > This should probably use relaxed MO. Ack. > > The libthreaddb changes look okay to me. > > Thanks, > Florian >