From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 189FE3858D3C for ; Fri, 12 Jan 2024 07:29:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 189FE3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=umich.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=umich.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 189FE3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705044590; cv=none; b=lFtuA4n805YbYqABJU6NXercg83POEkSKfXAh/60mDaONljYtvNE16SpBJ4CLeS79KG43QJIUkSfw8vyfoLiDskyBHvmuFrcdP1dFmapvvVxzFNiYeNls36G/bsBpOrip3goWijorkhPB2cxCmZ1WWTn28A9oETpJh6LiM9xehM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705044590; c=relaxed/simple; bh=DNaHem0d3zHA+nXLY2ic0x99WJWHGBc9SCYlzbfORbo=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=meO132vLBOfkcHU8Mw+CDmL6oMPyOT/e64gPX9ojq/FoNE6HegAVr0iAQEjeak6LqM/7S+SQoIL0fDnMvtoeDDbBuF5wh3c4X+RYylZmFmpHPxIZRC2mEe8tdlKe6WlXmn9c6IeGlzEYqoDzTSEX93onqIkws/2wXFbTSAL5Omk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5eefd0da5c0so63602127b3.2 for ; Thu, 11 Jan 2024 23:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=google-2016-06-03; t=1705044586; x=1705649386; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4QPT8Gi3lck6+0yvq2Y4xrMxzgoGnJQW7lyMuA0GD+8=; b=g4ZOecsbZdF9mvBB8gY8Wm4p2Dq6SfdB/m+q67aGPLZTv+HihBzBt2x9DriZRi4AHu /zmhBHhIQu5rBnvU83ZlFoDQuUDQw49cvNJV3MPPQv2d/+QixXR5BB5aGolIZL5O4f26 Q+rCpSvpzgAsGKAQQ87ElROn2oqiK0RPPNJ022k9L7uyVbteYvNJRQY75icCW3XAMIxm DkF3kiBSPMH7NX1MVxORep7odeWgQLdRZHba0znJ1OF8nkivkvgmZ3YXRENeP83IEuTc 1pOZbFXBQZ4v12mFHGb2cLNzQ25eKehU0KV8wltT0rYE9mJC98P7lxdaa2cWPtpakoZW hLng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705044586; x=1705649386; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4QPT8Gi3lck6+0yvq2Y4xrMxzgoGnJQW7lyMuA0GD+8=; b=UgoyP26Y7d1QtuhAZGH3/1inr2WyRmGbWzMBh3IPedDNzWM1OalCvrS8fxPM6q7hmL fOzu4T4nlMzTsKopgBhKUipKHl4remPSlMpVwbyefhtb3JbHCSPQAIZ9+sgXeT0zuszm TEOUK0ycQQfAHv7XyAtnn/HjiaDTZC21FRDHZD8GQBnNktSKs2PJvj+Q+79LjREDyUNT zbGaIjRyEvn0VuhOvkcFE1eG3oTEWIt2iLmJyqsYPgg/Hz/nQSPSe2LSM5VkEgFIrsi5 HY1kzmTfEoR9dv52NeZw7oK5Bwm8y/Pb/wq8PATHWgAX9knJLP3KD1hUeRxzppcxPp/e 9+Gw== X-Gm-Message-State: AOJu0YxRQqEDYAhOEPGMl6nOlqaw/fMQMr7++6qIQ6aR5q7yi2nYV/y6 epEgJfuUX73zCtpY9wuSJLfqvGC9UG068om40+5JbtcpT2+dCA== X-Google-Smtp-Source: AGHT+IEomky2zdjW9caWqS7NRQDRWUIt9me1hdZGLAxzfUW1K/zl+A88UHL2+qcyR4Sdqd04/6azK02Kmo+sGsnjy8c= X-Received: by 2002:a0d:cace:0:b0:5e7:50b6:9dd2 with SMTP id m197-20020a0dcace000000b005e750b69dd2mr1018426ywd.7.1705044586379; Thu, 11 Jan 2024 23:29:46 -0800 (PST) MIME-Version: 1.0 References: <4f03eba5-2ddc-1178-9ca1-d50614e9e441@redhat.com> In-Reply-To: <4f03eba5-2ddc-1178-9ca1-d50614e9e441@redhat.com> From: Trevor Gross Date: Fri, 12 Jan 2024 02:29:35 -0500 Message-ID: Subject: Re: RFC: A way to get a TID from a pthread_t handler To: "Carlos O'Donell" Cc: libc-help@sourceware.org, jistone@redhat.com, Florian Weimer Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Jan 11, 2024 at 1:23=E2=80=AFPM Carlos O'Donell = wrote: > > On 1/11/24 01:10, Trevor Gross via Libc-help wrote: > > It seems like there isn't a good way to get the thread ID from a > > pthread_t. If you are within the thread then you can call gettid(), > > but there is no public API to get a spawned thread's TID after calling > > pthread_create(). > > > > This value is stored in the pthread, so a new public function could > > just be a basic getter: > > > > pid_t pthread_gettid(pthread_t threadid) > > { > > struct pthread *pd =3D (struct pthread *) threadid; > > return pd->tid; > > } > > > > Would an addition like this likely get accepted? Or is there anything > > overlooked about an easier way to recover the spawned thread's TID? > > > > I could submit a patch, but require instruction on where this should li= ve. I appreciate the thorough response, > This is much more complicated than it seems at first :-) > > Please read through: > Bug 27880 - Please provide a pthread pid accessor > https://sourceware.org/bugzilla/show_bug.cgi?id=3D27880 > > Discussion here: > https://inbox.sourceware.org/libc-alpha/6d79a213-0df2-be8e-3596-e010f366a= 34f@linaro.org/ Whoops, I didn't come across these in my search. Actually did not at all come across pthread_getthreadid_np that is mentioned there, only the similarly named pthread_gettid_np. Thanks for the links. > I don't recommend this as a "first contribution" kind of patch. > > Are you looking to start with libc development? > > Are you looking for an initial project to work on? > > -- > Cheers, > Carlos. > This was sort of a need-based suggestion that I am still interested enough in looking into if there is a reasonable path forward. We were discussing how to expose the OS TID, it was pointed out that this is indirectly available via pthread_getcpuclockid ([1], [2]) but not directly. But indeed, it seems more complicated than originally thought :) I will follow up in Florian's response. - Trevor [1]: https://github.com/bminor/glibc/blob/520b1df08de68a3de328b65a25b86300a= 7ddf512/nptl/pthread_getcpuclockid.c#L38 [2]: https://github.com/bminor/glibc/blob/520b1df08de68a3de328b65a25b86300a= 7ddf512/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h#L23-L33