Release 4.14 arch/um/os-Linux/time.c
/*
* Copyright (C) 2015 Anton Ivanov (aivanov@{brocade.com,kot-begemot.co.uk})
* Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
* Copyright (C) 2012-2014 Cisco Systems
* Copyright (C) 2000 - 2007 Jeff Dike (jdike{addtoit,linux.intel}.com)
* Licensed under the GPL
*/
#include <stddef.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <kern_util.h>
#include <os.h>
#include <string.h>
#include <timer-internal.h>
static timer_t event_high_res_timer = 0;
static inline long long timeval_to_ns(const struct timeval *tv)
{
return ((long long) tv->tv_sec * UM_NSEC_PER_SEC) +
tv->tv_usec * UM_NSEC_PER_USEC;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jeff Dike | 33 | 100.00% | 1 | 100.00% |
Total | 33 | 100.00% | 1 | 100.00% |
static inline long long timespec_to_ns(const struct timespec *ts)
{
return ((long long) ts->tv_sec * UM_NSEC_PER_SEC) +
ts->tv_nsec;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 19 | 61.29% | 1 | 16.67% |
Gennady Sharapov | 6 | 19.35% | 1 | 16.67% |
Jeff Dike | 4 | 12.90% | 3 | 50.00% |
Richard Weinberger | 2 | 6.45% | 1 | 16.67% |
Total | 31 | 100.00% | 6 | 100.00% |
long long os_persistent_clock_emulation (void) {
struct timespec realtime_tp;
clock_gettime(CLOCK_REALTIME, &realtime_tp);
return timespec_to_ns(&realtime_tp);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Paolo 'Blaisorblade' Giarrusso | 10 | 37.04% | 1 | 25.00% |
Anton Ivanov | 9 | 33.33% | 1 | 25.00% |
Jeff Dike | 8 | 29.63% | 2 | 50.00% |
Total | 27 | 100.00% | 4 | 100.00% |
/**
* os_timer_create() - create an new posix (interval) timer
*/
int os_timer_create(void* timer) {
timer_t* t = timer;
if(t == NULL) {
t = &event_high_res_timer;
}
if (timer_create(
CLOCK_MONOTONIC,
NULL,
t) == -1) {
return -1;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 42 | 82.35% | 1 | 33.33% |
Jeff Dike | 9 | 17.65% | 2 | 66.67% |
Total | 51 | 100.00% | 3 | 100.00% |
int os_timer_set_interval(void* timer, void* i)
{
struct itimerspec its;
unsigned long long nsec;
timer_t* t = timer;
struct itimerspec* its_in = i;
if(t == NULL) {
t = &event_high_res_timer;
}
nsec = UM_NSEC_PER_SEC / UM_HZ;
if(its_in != NULL) {
its.it_value.tv_sec = its_in->it_value.tv_sec;
its.it_value.tv_nsec = its_in->it_value.tv_nsec;
} else {
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = nsec;
}
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = nsec;
if(timer_settime(*t, 0, &its, NULL) == -1) {
return -errno;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 138 | 93.24% | 1 | 33.33% |
Jeff Dike | 8 | 5.41% | 1 | 33.33% |
Martin Pärtel | 2 | 1.35% | 1 | 33.33% |
Total | 148 | 100.00% | 3 | 100.00% |
/**
* os_timer_remain() - returns the remaining nano seconds of the given interval
* timer
* Because this is the remaining time of an interval timer, which correspondends
* to HZ, this value can never be bigger than one second. Just
* the nanosecond part of the timer is returned.
* The returned time is relative to the start time of the interval timer.
* Return an negative value in an error case.
*/
long os_timer_remain(void* timer)
{
struct itimerspec its;
timer_t* t = timer;
if(t == NULL) {
t = &event_high_res_timer;
}
if(timer_gettime(t, &its) == -1) {
return -errno;
}
return its.it_value.tv_nsec;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 51 | 87.93% | 1 | 50.00% |
Jeff Dike | 7 | 12.07% | 1 | 50.00% |
Total | 58 | 100.00% | 2 | 100.00% |
int os_timer_one_shot(int ticks)
{
struct itimerspec its;
unsigned long long nsec;
unsigned long sec;
nsec = (ticks + 1);
sec = nsec / UM_NSEC_PER_SEC;
nsec = nsec % UM_NSEC_PER_SEC;
its.it_value.tv_sec = nsec / UM_NSEC_PER_SEC;
its.it_value.tv_nsec = nsec;
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0; // we cheat here
timer_settime(event_high_res_timer, 0, &its, NULL);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 70 | 76.92% | 1 | 25.00% |
Jeff Dike | 20 | 21.98% | 2 | 50.00% |
Miklos Szeredi | 1 | 1.10% | 1 | 25.00% |
Total | 91 | 100.00% | 4 | 100.00% |
/**
* os_timer_disable() - disable the posix (interval) timer
* Returns the remaining interval timer time in nanoseconds
*/
long long os_timer_disable(void)
{
struct itimerspec its;
memset(&its, 0, sizeof(struct itimerspec));
timer_settime(event_high_res_timer, 0, &its, &its);
return its.it_value.tv_sec * UM_NSEC_PER_SEC + its.it_value.tv_nsec;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 46 | 85.19% | 1 | 50.00% |
Jeff Dike | 8 | 14.81% | 1 | 50.00% |
Total | 54 | 100.00% | 2 | 100.00% |
long long os_vnsecs(void)
{
struct timespec ts;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&ts);
return timespec_to_ns(&ts);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 17 | 62.96% | 1 | 50.00% |
Jeff Dike | 10 | 37.04% | 1 | 50.00% |
Total | 27 | 100.00% | 2 | 100.00% |
long long os_nsecs(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC,&ts);
return timespec_to_ns(&ts);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jeff Dike | 14 | 51.85% | 1 | 50.00% |
Anton Ivanov | 13 | 48.15% | 1 | 50.00% |
Total | 27 | 100.00% | 2 | 100.00% |
/**
* os_idle_sleep() - sleep for a given time of nsecs
* @nsecs: nanoseconds to sleep
*/
void os_idle_sleep(unsigned long long nsecs)
{
struct timespec ts;
if (nsecs <= 0) {
return;
}
ts = ((struct timespec) {
.tv_sec = nsecs / UM_NSEC_PER_SEC,
.tv_nsec = nsecs % UM_NSEC_PER_SEC
});
/*
* Relay the signal if clock_nanosleep is interrupted.
*/
if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL)) {
deliver_alarm();
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jeff Dike | 36 | 53.73% | 4 | 66.67% |
Gennady Sharapov | 17 | 25.37% | 1 | 16.67% |
Anton Ivanov | 14 | 20.90% | 1 | 16.67% |
Total | 67 | 100.00% | 6 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Ivanov | 432 | 66.26% | 1 | 5.26% |
Jeff Dike | 169 | 25.92% | 11 | 57.89% |
Gennady Sharapov | 32 | 4.91% | 1 | 5.26% |
Paolo 'Blaisorblade' Giarrusso | 12 | 1.84% | 2 | 10.53% |
Al Viro | 2 | 0.31% | 1 | 5.26% |
Martin Pärtel | 2 | 0.31% | 1 | 5.26% |
Richard Weinberger | 2 | 0.31% | 1 | 5.26% |
Miklos Szeredi | 1 | 0.15% | 1 | 5.26% |
Total | 652 | 100.00% | 19 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.