diff mbox

[uclibc-ng-devel] pthread_getcpuclockid.c: fix clockid calculation

Message ID CAKo4hFJz3=0KAay54eH=9h6zWVR-sjMfTpBcZjHHACKYN8p8yw@mail.gmail.com
State Superseded
Headers show

Commit Message

Sergey Korolev April 27, 2017, 7:22 a.m. UTC
Hi,

I found that MAKE_THREAD_CPUCLOCK really introduced in
Linux 2.6.12 with POSIX timers implementation. So it is safe to
change clockid computation for all kernels (that support POSIX timers).

On Thu, Apr 27, 2017 at 9:23 AM, Waldemar Brodkorb <wbx@uclibc-ng.org>
wrote:

> Hi,
> Sergey Korolev wrote,
>
> > Hi, Waldemar.
> >
> > Should uClibc-ng support Linux kernels before 2.6.24?
>
> That would be good, some users still use something like 2.6.18 IIRC.
>
> best regards
>  Waldemar
>

Comments

Waldemar Brodkorb April 30, 2017, 8:38 a.m. UTC | #1
Hi,
Sergey Korolev wrote,

> Hi,
> 
> I found that MAKE_THREAD_CPUCLOCK really introduced in
> Linux 2.6.12 with POSIX timers implementation. So it is safe to
> change clockid computation for all kernels (that support POSIX timers).

Will you sent a new patch?

thanks
 Waldemar
Sergey Korolev April 30, 2017, 9:17 a.m. UTC | #2
Hi, Waldemar.

No, I suppose my lastest patch is sufficient to fix a bug for all kernels
>= 2.6.12.

Regards,
Sergey.

On Sun, Apr 30, 2017 at 11:38 AM, Waldemar Brodkorb <wbx@uclibc-ng.org>
wrote:

> Hi,
> Sergey Korolev wrote,
>
> > Hi,
> >
> > I found that MAKE_THREAD_CPUCLOCK really introduced in
> > Linux 2.6.12 with POSIX timers implementation. So it is safe to
> > change clockid computation for all kernels (that support POSIX timers).
>
> Will you sent a new patch?
>
> thanks
>  Waldemar
>
Waldemar Brodkorb May 12, 2017, 3:56 p.m. UTC | #3
Hi Sergey,
Sergey Korolev wrote,

> Hi, Waldemar.
> 
> No, I suppose my lastest patch is sufficient to fix a bug for all kernels >=
> 2.6.12.

Thanks, I added your test-case to uclibc-ng-test and your patch to
master uclibc-ng.

best regards
 Waldemar
diff mbox

Patch

From 57326b60773d5cafa3aa219b60ff91a703a90964 Mon Sep 17 00:00:00 2001
From: Sergey Korolev <s.korolev@ndmsystems.com>
Date: Tue, 25 Apr 2017 02:14:59 +0300
Subject: [PATCH] pthread_getcpuclockid.c: fix clockid computation

For the linux kernel (since 2.6.12) MAKE_THREAD_CPUCLOCK
macro-like computation should be used to get clockid.
---
 libpthread/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c b/libpthread/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c
index ca3570f..f4ed2dc 100644
--- a/libpthread/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c
+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/pthread_getcpuclockid.c
@@ -20,6 +20,8 @@ 
 #include <sys/time.h>
 #include <tls.h>
 
+#define CPUCLOCK_PERTHREAD_MASK	4
+#define CPUCLOCK_SCHED		2
 
 int
 pthread_getcpuclockid (
@@ -46,7 +48,8 @@  pthread_getcpuclockid (
     return ERANGE;
 
   /* Store the number.  */
-  *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE);
+  *clockid = ((~(clockid_t) (pd->tid)) << CLOCK_IDFIELD_SIZE)
+    | CPUCLOCK_SCHED | CPUCLOCK_PERTHREAD_MASK;
 
   return 0;
 #else
-- 
2.7.4