Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

ep_rt_aot_thread_get_id and other call sites were using GetPalThreadIdForLogging(), a method intended only for logging purposes, to retrieve thread IDs for EventPipe, GC, and stress logging functionality.

Changes

  • Added Thread::GetOSThreadId() - New public method for proper thread ID access, aligning with CoreCLR's GetOSThreadId64() pattern
  • Removed Thread::GetPalThreadIdForLogging() - Deleted the logging-specific method that was being misused for general purposes
  • Updated all call sites - Changed ep_rt_aot_thread_get_id(), GCToEEInterface::GetThreadOSThreadId(), and stress logging calls to use GetOSThreadId()

The new GetOSThreadId() method returns m_threadId and provides proper semantics for all thread ID access needs.

// Before
ep_rt_thread_id_t ep_rt_aot_thread_get_id(ep_rt_thread_handle_t thread_handle)
{
    return (ep_rt_thread_id_t)thread_handle->GetPalThreadIdForLogging();
}

// After
ep_rt_thread_id_t ep_rt_aot_thread_get_id(ep_rt_thread_handle_t thread_handle)
{
    return (ep_rt_thread_id_t)thread_handle->GetOSThreadId();
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Consider a better implementation for ep_rt_aot_thread_get_id </issue_title>
<issue_description>Currently, we use GetPalThreadIdForLogging() to get the thread_id, which doesn't look the proper way to get the thread_id.

GetPalThreadIdForLogging() Implementation Details for completeness: EEThreadId classes seems to be doing the right thing to set its first field (pthread_self and GetCurrentThreadId), but doesn't expose a getter (reason for not using for 'normal' use?) GetPalThreadIdForLogging is using this field directly to get the value. See also details of the current_thread_get_id implementation concerns.</issue_description>

Comments on the Issue (you are @copilot in this section)

@ Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in [area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md) if you want to be subscribed.
Issue Details

Currently, we use GetPalThreadIdForLogging() to get the thread_id, which doesn't look the proper way to get the thread_id.

GetPalThreadIdForLogging() Implementation Details for completeness: EEThreadId classes seems to be doing the right thing to set its first field (pthread_self and GetCurrentThreadId), but doesn't expose a getter (reason for not using for 'normal' use?) GetPalThreadIdForLogging is using this field directly to get the value. See also details of the current_thread_get_id implementation concerns.

Author: LakshanF
Assignees: LakshanF
Labels:

area-NativeAOT-coreclr

Milestone: 9.0.0

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 3, 2025 22:05
…orLogging

Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Co-authored-by: agocke <515774+agocke@users.noreply.github.com>
Copilot AI changed the title [WIP] Consider better implementation for ep_rt_aot_thread_get_id Add GetOSThreadId() method for proper thread ID access in NativeAOT Nov 3, 2025
Copilot finished work on behalf of agocke November 3, 2025 22:09
Copilot AI requested a review from agocke November 3, 2025 22:09
…adId

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI changed the title Add GetOSThreadId() method for proper thread ID access in NativeAOT Replace GetPalThreadIdForLogging() with GetOSThreadId() in NativeAOT Nov 3, 2025
Copilot finished work on behalf of jkotas November 3, 2025 22:37
Copilot AI requested a review from jkotas November 3, 2025 22:37
@jkotas jkotas marked this pull request as ready for review November 4, 2025 02:49
Copilot AI review requested due to automatic review settings November 4, 2025 02:49
@jkotas
Copy link
Member

jkotas commented Nov 4, 2025

/ba-g timeouts

@jkotas jkotas merged commit 38154f0 into main Nov 4, 2025
94 of 100 checks passed
@jkotas jkotas deleted the copilot/improve-thread-id-implementation branch November 4, 2025 02:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR renames the GetPalThreadIdForLogging method to GetOSThreadId in the NativeAOT runtime to improve naming consistency and clarity.

  • The method name is changed from GetPalThreadIdForLogging to GetOSThreadId to better reflect its actual purpose and align with naming conventions used in the CoreCLR VM implementation.
  • All call sites across the NativeAOT runtime are updated to use the new method name.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/coreclr/nativeaot/Runtime/thread.h Declaration of the method is renamed from GetPalThreadIdForLogging to GetOSThreadId
src/coreclr/nativeaot/Runtime/thread.cpp Definition of the method is renamed, and call sites within STRESS_LOG macros are updated
src/coreclr/nativeaot/Runtime/gcenv.ee.cpp Updated call site in GCToEEInterface::GetThreadOSThreadId to use the renamed method
src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp Updated call site in ep_rt_aot_thread_get_id to use the renamed method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider a better implementation for ep_rt_aot_thread_get_id

3 participants