Skip to contentSkip to conversation

How to use CLOCK_REALTIME_ALARM

DISCUSSION fogobogo 1 participant 1 message Aug 29, 2011

lore
Share & tools
lore

fogobogo

author
#0 lore raw

Hi!

Since alarmtimers have been mainlined there are now 2 new clock id's, CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM which are supposed to wake up a machine from suspend too. It's roughly outlined here:

http://lwn.net/Articles/429925/

Now me residing in userspace wonder how to use those. It's the first time I try to use a kernel interface and it is quite possible the problem is on my end but I have no clue what might be wrong. Here is some barely working code:

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>

void
func()

{
    printf("pong.\n");
}

int
main(int argc, char *argv[])

{
    timer_t id;

    struct itimerspec A;
    struct sigevent se;

    int rc; /* return code */

    se.sigev_notify = SIGEV_THREAD;
    se.sigev_notify_function = func;
    se.sigev_notify_attributes = NULL;

    /* doesn't accept CLOCK_REALTIME_ALARM */
    rc = timer_create(CLOCK_REALTIME, &se, &id);
    printf("%d\n",rc);

    /* the only place that seems to actually accept it */
    clock_gettime(CLOCK_REALTIME_ALARM, &A.it_value);

    A.it_value.tv_sec += 10;

    A.it_interval.tv_sec = 0;
    A.it_interval.tv_nsec = 0;

    /* set timer */
    rc = timer_settime(&id, TIMER_ABSTIME, &A, 0);
    printf("%d\n",rc);

    printf("ping.\n");

    /* bad. bad. bad. */
    while(1);

    return 0;
}

I'd appreciate if someone could point me on what I'm doing wrong or tell me if the new clock id's work at all.

please CC answers. thanks in advance.