Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix undefined symbol: gettid #2389 #2393

Merged
merged 5 commits into from Jun 5, 2023
Merged

Conversation

silencewood
Copy link
Contributor

#2389
gettid
Glibc does not provide a wrapper for this system call; call it using syscall(2).

   #define _GNU_SOURCE
   #include <unistd.h>
   #include <sys/syscall.h>
   #include <sys/types.h>

   int
   main(int argc, char *argv[])
   {
       pid_t tid;

       tid = syscall(SYS_gettid);
   }

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! Comments inline. Also please add a change log entry.

@dbwiddis
Copy link
Member

dbwiddis commented Jun 5, 2023

I played around with some microbenchmarking, with the syscall method vs. resolving the dynamic link of /proc/thread-self:

syscall = LinuxLibc.INSTANCE.syscall(code).intValue();
// vs.
proctask = ParseUtil.parseIntOrDefault(Files.readSymbolicLink(link).getFileName().toString(), 0);

Not much difference between them, and pretty sure the proc approach is more portable.

  Method     TID      Nanos
 syscall   27693   10589.64
proctask   27693   12773.40

@dbwiddis
Copy link
Member

dbwiddis commented Jun 5, 2023

Another test on an x86 system including the gettid native:

  Method     TID      Nanos
  gettid  955738     762.50
 syscall  955738    1836.52
proctask  955738    2543.79

@dbwiddis dbwiddis merged commit b28be65 into oshi:master Jun 5, 2023
15 checks passed
@dbwiddis
Copy link
Member

dbwiddis commented Jun 5, 2023

Thanks for your contribution! I made a few tweaks and merged it.

Let me know if there are any other changes needed, I'll probably get a release out tomorrow.

@dbwiddis
Copy link
Member

dbwiddis commented Jun 5, 2023

  • x86_64: 0xba = 186
  • x86 or arm: 0xe0 = 224
  • arm64: 0xb2 = 178

Digging into this again from primary headers and not a summary page, I think this is slightly off.

  • arm64 is 224
  • x86 is 224
  • x86_64 is 186
  • generic (fallback for non-intel/non-arm) is 178

I'll submit a quick fix for this.

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.

java.lang.UnsatisfiedLinkError: Error looking up function 'gettid': java: undefined symbol: gettid
3 participants