linux, os::current_thread_id() vs os::Linux::gettid()

Thomas Stüfe thomas.stuefe at gmail.com
Tue Aug 26 07:18:01 UTC 2014


Ok, I will change this first in our code base and then Goetz or me will
port it to the OpenJdk.

Thank you for clarification!

..Thomas


On Tue, Aug 26, 2014 at 8:33 AM, David Holmes <david.holmes at oracle.com>
wrote:

> On 26/08/2014 4:24 PM, Thomas Stüfe wrote:
>
>> Hi David,
>>
>> Thank you for answering.
>>
>> The reason I ask is that I work on the AIX port and would like to remove
>> the use of kernel thread ids.
>>
>> For one, AIX kernel thread ids are 64bit, so we have a truncation error
>> by casting them to 32bit pid_t; also, a pthread may be scheduled to
>> multiple kernel threads during its lifetime by the AIX scheduler. I
>> think the reason we introduced kernel thread ids was because other
>> platform ports do it too, so I wanted to know the reason.
>>
>
> I think it would be safe to remove them. Any port that started from the
> linux code tends to inherit its historical baggage.
>
> David
>
>
>> Thomas
>>
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Aug 26, 2014 at 5:57 AM, David Holmes <david.holmes at oracle.com
>> <mailto:david.holmes at oracle.com>> wrote:
>>
>>     On 26/08/2014 1:46 PM, David Holmes wrote:
>>
>>         Hi Thomas,
>>
>>         On 26/08/2014 12:55 AM, Thomas Stüfe wrote:
>>
>>             Hi,
>>
>>             I wonder about the implementation of os::current_thread_id()
>>             on Linux.
>>
>>             There is os::Linux::gettid() and os::current_thread_id().
>>             os::Linux::gettid() returns the kernel thread id,
>>             os::current_thread_id()
>>             returns the pthread id.
>>
>>             os::Linux::gettid() is used to initialize
>>             OSThread::_thread_id, so that
>>             contains the kernel thread id. So now we get conflicting
>>             information from
>>             OSThread::thread_id and os::current_thread_id().
>>
>>             As far as I see, all other platforms consistently return the
>>             kernel
>>             thread id on both code paths.
>>
>>
>>         Only AIX and BSD have gettid and both those ports were based on
>> the
>>         Linux code.
>>
>>
>>     Sorry misunderstood your comment. Yes other platforms currently use
>>     the same low-level thread id for the OSThread and
>>     os::current_thread_id(). I suspect if you could look back in time
>>     that Solaris would have also had different usages eg for LWP id
>>     versus user-level thread id.
>>
>>     David
>>     -----
>>
>>
>>             Am I overlooking something or is this behaviour intentional?
>>
>>
>>         Intentional but historical, going back to old LinuxThreads.
>>         Probably one
>>         of many cleanups that can be done in the linux code.
>>
>>         David
>>
>>
>>             Kind Regards,
>>
>>             ..Thomas
>>
>>
>>


More information about the hotspot-dev mailing list