public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: fogobogo <fogobogo@archlinux.us>
To: linux-kernel@vger.kernel.org
Subject: How to use CLOCK_REALTIME_ALARM
Date: Mon, 29 Aug 2011 23:13:04 +0200	[thread overview]
Message-ID: <4E5C00E0.3080107@archlinux.us> (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.

                 reply	other threads:[~2011-08-29 21:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E5C00E0.3080107@archlinux.us \
    --to=fogobogo@archlinux.us \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox