Skip to content

Conversation

@Willmac16
Copy link
Contributor

Related Issue(s)
Has Unit Tests (y/n) n
Documentation Included (y/n) n
Generative AI was used in this contribution (y/n) n

Change Description

Os::Task for linux will set the thread name to the task's name.

Rationale

When attempting to profile fprime code, it would be beneficial to see which fprime tasks are eating up CPU resources from outside tooling.

Testing/Review Recommendations

The current implementation does not prefix the task name w/ the original process name as 16 characters is rather restrictive.

Future Work

N/A

AI Usage (see policy)

N/A

Copy link
Collaborator

@LeStarch LeStarch left a comment

Choose a reason for hiding this comment

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

A few questions, but otherwise looks good!

thomas-bc
thomas-bc previously approved these changes Nov 18, 2025
}

int set_task_name(pthread_t thread, const Os::Task::Arguments& arguments) {
int status = 0;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

status uses the basic integral type int rather than a typedef with size and signedness.
Comment on lines +124 to +125
#if defined(TGT_OS_TYPE_LINUX) && defined(__GLIBC__) && defined(_GNU_SOURCE) && defined(POSIX_THREADS_ENABLE_NAMES) && \
POSIX_THREADS_ENABLE_NAMES

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
name[Os::Posix::Task::PosixTaskHandle::PTHREAD_NAME_LENGTH - 1] = '\0';
status = pthread_setname_np(thread, name);
#endif
return status;

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter name has not been checked.
status = pthread_setname_np(thread, name);
#endif
return status;
}

Check warning

Code scanning / CodeQL

Unchecked function argument Warning

This use of parameter thread has not been checked.
// That's the circumstance in which we expect this feature to work.
#if defined(TGT_OS_TYPE_LINUX) && defined(__GLIBC__) && defined(_GNU_SOURCE) && defined(POSIX_THREADS_ENABLE_NAMES) && \
POSIX_THREADS_ENABLE_NAMES
// Force safe name usage

Check notice

Code scanning / CodeQL

Use of basic integral type Note

set_task_name uses the basic integral type int rather than a typedef with size and signedness.
// That's the circumstance in which we expect this feature to work.
#if defined(TGT_OS_TYPE_LINUX) && defined(__GLIBC__) && defined(_GNU_SOURCE) && defined(POSIX_THREADS_ENABLE_NAMES) && \
POSIX_THREADS_ENABLE_NAMES
// Force safe name usage

Check notice

Code scanning / CodeQL

Use of basic integral type Note

thread uses the basic integral type unsigned long rather than a typedef with size and signedness.
// That's the circumstance in which we expect this feature to work.
#if defined(TGT_OS_TYPE_LINUX) && defined(__GLIBC__) && defined(_GNU_SOURCE) && defined(POSIX_THREADS_ENABLE_NAMES) && \
POSIX_THREADS_ENABLE_NAMES
// Force safe name usage

Check notice

Code scanning / CodeQL

Use of basic integral type Note

name uses the basic integral type char rather than a typedef with size and signedness.
//! Is the above descriptor valid
bool m_is_valid = false;
#if defined(POSIX_THREADS_ENABLE_NAMES) && POSIX_THREADS_ENABLE_NAMES
char m_name[PosixTaskHandle::PTHREAD_NAME_LENGTH];

Check notice

Code scanning / CodeQL

Use of basic integral type Note

m_name uses the basic integral type char rather than a typedef with size and signedness.
thomas-bc
thomas-bc previously approved these changes Nov 20, 2025
Copy link
Collaborator

@timcanham timcanham left a comment

Choose a reason for hiding this comment

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

Minor comments, but LGTM

typedef void* (*pthread_func_ptr)(void*);

// Forward declaration
int set_task_name(pthread_t thread, char* name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: If these functions are used just in this file, I would declare them static

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could. The other functions in this file that are helpers are not declared static.

#if defined(POSIX_THREADS_ENABLE_NAMES) && POSIX_THREADS_ENABLE_NAMES
Fw::StringUtils::string_copy(handle.m_name, arguments.m_name.toChar(), sizeof(handle.m_name));
#endif

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
Fw::StringUtils::string_copy(handle.m_name, arguments.m_name.toChar(), sizeof(handle.m_name));
#endif

(void)pthread_attr_destroy(&attributes);

Check warning

Code scanning / CodeQL

Unchecked return value Warning

The return value of non-void function
string_copy
is not checked.
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.

4 participants