Current uClibc-ng version incorrectly calculates clockid in pthread_getcpuclockid (at least for modern kernels). The simplest test program
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int main()
{
clockid_t clk;
struct timespec ts;
const int err = pthread_getcpuclockid(pthread_self(), &clk);
if (err != 0) {
errno = err;
perror("pthread_getcpuclockid");
return EXIT_FAILURE;
}
if (clock_gettime(clk, &ts) == -1) {
perror("clock_gettime");
return EXIT_FAILURE;
}
printf("Thread time is %lu.%06lu.\n",
ts.tv_sec,
ts.tv_nsec / 1000);
return EXIT_SUCCESS;
}
fails with
clock_gettime: Invalid argument
Tested on Linux 3.4 / MIPS built with GCC 5.4.0.
Other implementations, for example musl, use a simple calculation
Looks strange, but the official glibc repository
has the same implementation as in uClibc-ng.
I propose an intermediate solution: use MAKE_THREAD_CPUCLOCK like computation of clockid when __NR_clock_getres defined and do a fallback to an older implementation when not.