Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • redox redox
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 226
    • Issues 226
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 14
    • Merge requests 14
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • redox-os
  • redoxredox
  • Issues
  • #575
Closed
Open
Created Mar 22, 2016 by Jeremy Soller@jackpot51Owner

clock_gettime doesn't always return an updated time

Created by: glegris

Reproduction: Inside a process, successive calls of clock_gettime gives the same time value, except if sleep is called between the calls. The code below allows to reproduce the 2 behaviors.

  1. Compile the test code: i386-elf-redox-gcc -o time_test time_test.c

  2. Test 1 currently fails (simple loop between two calls of clock_gettime) time_test

  3. Test 2 (sleep between two clock_gettime calls) time_test sleep

Expected behavior:

timespec should be updated between successive calls to clock_gettime

I provide the source code below as attachment doesn't work for me (!)


include <stdlib.h>

include <stdio.h>

include <dirent.h>

include <sys/time.h>

include <time.h>

include <unistd.h>

int main(int argc, char ** argv){ printf("Test %d\n", argc); int i; for(i = 0; i < argc; i++){ printf("%d: %s\n", i, argv[i]); }

struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
int start_time = (int)tp.tv_sec; 
printf("clock_gettime start %d %d\n", (int)tp.tv_sec, (int)tp.tv_nsec);
int a = 64;
if (argc > 1) {
    sleep(2);
} else {
    for(i = 1; i < 100000000; i++){
     a += a / i;
    }
}
clock_gettime(CLOCK_REALTIME, &tp);
printf("clock_gettime end %d %d\n", (int)tp.tv_sec, (int)tp.tv_nsec);
if ((int)tp.tv_sec - start_time < 2) {
    printf("Oops ! time was not updated !\n");
} else {
    printf("OK\n");
}
printf("%i\n", a);    

}

Assignee
Assign to
Time tracking