This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/2987] New: CLOCK_PROCESS_CPUTIME_ID is not settable


My understanding is that the CLOCK_PROCESS_CPUTIME_ID should be settable
(like CLOCK_THREAD_CPUTIME_ID is settable) using clock_settime().  
However, this does not work, as can be demonstrated using the program
below.  For CLOCK_PROCESS_CPUTIME_ID, clock_settime() returns
a success status, but does not change the clock; either it should fail
for this clock, or it should actually change the clock.

An example run is as follows:
$ /lib/libc.so.6  | egrep '(release|system)'
GNU C Library development release version 2.4 (20060428), by Roland McGrath et al.
Compiled on a Linux 2.6.16 system on 2006-04-28.
$ uname -srv
Linux 2.6.18-rc3 #12 SMP PREEMPT Mon Jul 31 10:49:05 CEST 2006
$ ./t_CLOCK_PROCESS_CPUTIME_ID
CLOCK_PROCESS_CPUTIME_ID:           0.004000000 (resolution: 0.000000001)

Consuming CPU time...
CLOCK_PROCESS_CPUTIME_ID:           2.176000000

Resetting CLOCK_PROCESS_CPUTIME_ID
CLOCK_PROCESS_CPUTIME_ID:           2.176000000
(CLOCK_PROCESS_THREAD_ID:           2.176000000)

--8x----8x----8x----8x----8x----8x----8x----8x----8x----8x----8x--

/* t_CLOCK_PROCESS_CPUTIME_ID.c */

#define _XOPEN_SOURCE 600
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>


#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                        } while (0)

int
main(int argc, char *argv[])
{
    struct timespec ts;
    int j;

    if (argc > 1 && strcmp(argv[1], "--help") == 0) {
        fprintf(stderr, "%s secs\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1)
        errExit("clock_gettime-CLOCK_PROCESS_CPUTIME_ID");
    printf("CLOCK_PROCESS_CPUTIME_ID: %11ld.%09ld", (long) ts.tv_sec,
            (long) ts.tv_nsec);

    if (clock_getres(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1)
        errExit("clock_getres-CLOCK_PROCESS_CPUTIME_ID");
    printf(" (resolution: %ld.%09ld)\n", (long) ts.tv_sec,
            (long) ts.tv_nsec);

    printf("\nConsuming CPU time...\n");

    for (j = 0; j < 2000000; j++)
        getppid();

    if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1)
        errExit("clock_gettime-CLOCK_PROCESS_CPUTIME_ID");
    printf("CLOCK_PROCESS_CPUTIME_ID: %11ld.%09ld\n", (long) ts.tv_sec,
            (long) ts.tv_nsec);

    printf("\nResetting CLOCK_PROCESS_CPUTIME_ID\n");

    ts.tv_sec = (argc > 1) ? atoi(argv[1]) : 0;
    ts.tv_nsec = 0;

    if (clock_settime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1)
        errExit("clock_settime-CLOCK_PROCESS_CPUTIME_ID");

    if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1)
        errExit("clock_gettime-CLOCK_PROCESS_CPUTIME_ID");
    printf("CLOCK_PROCESS_CPUTIME_ID: %11ld.%09ld\n", (long) ts.tv_sec,
            (long) ts.tv_nsec);

    if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) == -1)
        errExit("clock_gettime-CLOCK_THREAD_CPUTIME_ID");
    printf("(CLOCK_PROCESS_THREAD_ID: %11ld.%09ld)\n", (long) ts.tv_sec,
            (long) ts.tv_nsec);

    exit(EXIT_SUCCESS);
}

-- 
           Summary: CLOCK_PROCESS_CPUTIME_ID is not settable
           Product: glibc
           Version: 2.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: michael dot kerrisk at gmx dot net
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=2987

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]