public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Linux application level timers?
@ 2003-01-22 22:17 Tom Sanders
  2003-01-22 23:03 ` Steven Dake
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Tom Sanders @ 2003-01-22 22:17 UTC (permalink / raw)
  To: redhat-list, linux-kernel, redhat-devel-list

I'm writing an application server which receives
requests from other applications. For each request
received, I want to start a timer so that I can fail
the application request if it could not be completed
in max specified time.

Which Linux timer facility can be used for this?

I have checked out alarm() and signal() system calls,
but these calls doesn't take an argument, so its not
possible to associate application request with the
matured alarm.

Any inputs?

Thanks in advance,
Tom

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-22 22:17 Linux application level timers? Tom Sanders
@ 2003-01-22 23:03 ` Steven Dake
  2003-01-22 23:35 ` george anzinger
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Steven Dake @ 2003-01-22 23:03 UTC (permalink / raw)
  To: Tom Sanders, linux-kernel

Try select().

Depending on your architecture (ie: if requests come in via TCP file 
descriptors) you can use select.  Select takes as an argument a timeout 
value.  You can calculate the minimum timeout value for a set of 
timeouts by finding the minimum, and use that as your select timeout. 
 Before each time you call select, you can figure out all the timeout 
values to find the minimum select period.  This way you can control what 
you do when with the timeout.  After the select, you can then calculate 
which timeouts have occured and act on them appropriately.

I use this for example to detect when a function should be polled while 
also waiting on event-driven i/o from a tcp socket.  I also use this to 
detect when a heartbeat message should have been received but was not in 
the alloted time, causing the socket to close and reconnect.

Thanks
-steve

Tom Sanders wrote:

>I'm writing an application server which receives
>requests from other applications. For each request
>received, I want to start a timer so that I can fail
>the application request if it could not be completed
>in max specified time.
>
>Which Linux timer facility can be used for this?
>
>I have checked out alarm() and signal() system calls,
>but these calls doesn't take an argument, so its not
>possible to associate application request with the
>matured alarm.
>
>Any inputs?
>
>Thanks in advance,
>Tom
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
>http://mailplus.yahoo.com
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/
>
>
>
>  
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-22 22:17 Linux application level timers? Tom Sanders
  2003-01-22 23:03 ` Steven Dake
@ 2003-01-22 23:35 ` george anzinger
  2003-01-23  4:36 ` Gerhard Mack
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: george anzinger @ 2003-01-22 23:35 UTC (permalink / raw)
  To: Tom Sanders; +Cc: redhat-list, linux-kernel, redhat-devel-list

Tom Sanders wrote:
> 
> I'm writing an application server which receives
> requests from other applications. For each request
> received, I want to start a timer so that I can fail
> the application request if it could not be completed
> in max specified time.
> 
> Which Linux timer facility can be used for this?
> 
> I have checked out alarm() and signal() system calls,
> but these calls doesn't take an argument, so its not
> possible to associate application request with the
> matured alarm.

Sounds like a job for POSIX clocks & timers.  See here:
http://sourceforge.net/projects/high-res-timers/

-g
> 
> Any inputs?
> 
> Thanks in advance,
> Tom
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
George Anzinger   george@mvista.com
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-22 22:17 Linux application level timers? Tom Sanders
  2003-01-22 23:03 ` Steven Dake
  2003-01-22 23:35 ` george anzinger
@ 2003-01-23  4:36 ` Gerhard Mack
  2003-01-23  8:37 ` Narsimha Reddy CH
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Gerhard Mack @ 2003-01-23  4:36 UTC (permalink / raw)
  To: Tom Sanders; +Cc: redhat-list, linux-kernel, redhat-devel-list

On Wed, 22 Jan 2003, Tom Sanders wrote:

> I'm writing an application server which receives
> requests from other applications. For each request
> received, I want to start a timer so that I can fail
> the application request if it could not be completed
> in max specified time.
>
> Which Linux timer facility can be used for this?
>
> I have checked out alarm() and signal() system calls,
> but these calls doesn't take an argument, so its not
> possible to associate application request with the
> matured alarm.
>
> Any inputs?

Write a timer funtion internal to your application that checks an
internal list of deadlines and when it gets the signal just check the
internal list to see what timer has gone off and set alarm() to the next
item.

If you want example code write me off list.

	Gerhard

--
Gerhard Mack

gmack@innerfire.net

<>< As a computer I find your faith in technology amusing.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-22 22:17 Linux application level timers? Tom Sanders
                   ` (2 preceding siblings ...)
  2003-01-23  4:36 ` Gerhard Mack
@ 2003-01-23  8:37 ` Narsimha Reddy CH
  2003-01-23  8:51 ` Riku Meskanen
  2003-01-23 16:28 ` Chris Friesen
  5 siblings, 0 replies; 8+ messages in thread
From: Narsimha Reddy CH @ 2003-01-23  8:37 UTC (permalink / raw)
  To: Tom Sanders; +Cc: redhat-list, linux-kernel, redhat-devel-list


You can also use the poll() system call. The last arguement
of this system call is the timeout value is milli-seconds.
When timeout is occurred it will return 0. Refer the
manual page for more details.

hope this helps you,
-- 
Narsimha Reddy CH
Storage Area Networking, HCL Technologies
Contact  +91-044 2372 8366 ext 1128

http://san.hcltech.com
http://www.hcltech.com



Tom Sanders wrote:
> 
> I'm writing an application server which receives
> requests from other applications. For each request
> received, I want to start a timer so that I can fail
> the application request if it could not be completed
> in max specified time.
> 
> Which Linux timer facility can be used for this?
> 
> I have checked out alarm() and signal() system calls,
> but these calls doesn't take an argument, so its not
> possible to associate application request with the
> matured alarm.
> 
> Any inputs?
> 
> Thanks in advance,
> Tom
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-22 22:17 Linux application level timers? Tom Sanders
                   ` (3 preceding siblings ...)
  2003-01-23  8:37 ` Narsimha Reddy CH
@ 2003-01-23  8:51 ` Riku Meskanen
  2003-01-23 16:28 ` Chris Friesen
  5 siblings, 0 replies; 8+ messages in thread
From: Riku Meskanen @ 2003-01-23  8:51 UTC (permalink / raw)
  To: redhat-devel-list; +Cc: redhat-list, linux-kernel

On Wed, 22 Jan 2003, Tom Sanders wrote:

> I'm writing an application server which receives
> requests from other applications. For each request
> received, I want to start a timer so that I can fail
> the application request if it could not be completed
> in max specified time.
>
> Which Linux timer facility can be used for this?
>
> I have checked out alarm() and signal() system calls,
> but these calls doesn't take an argument, so its not
> possible to associate application request with the
> matured alarm.
>
> Any inputs?
>
Yes, get a book like "Advanced Programming in
the UNIX Environment" W. Richard Stevens and
look how to use signals and select()/poll()
from there.

Also if you are able to use tools to have the
protocol defined by ASN.1 that would help, because
then you could be able to have tools to generate
automatically protocol handling code too with C or
C++ etc.

I'm not in the latter business, read and used
some code from the above book long time ago,
but I've seen nice tools used more and more rather
than hand-coding the protocol (because it's very
easy get in troubles with hard to find errors
of incomplete state-machine etc.)

HTH,

:-) riku

-- 
    [ This .signature intentionally left blank ]


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-22 22:17 Linux application level timers? Tom Sanders
                   ` (4 preceding siblings ...)
  2003-01-23  8:51 ` Riku Meskanen
@ 2003-01-23 16:28 ` Chris Friesen
  2003-01-23 17:26   ` DervishD
  5 siblings, 1 reply; 8+ messages in thread
From: Chris Friesen @ 2003-01-23 16:28 UTC (permalink / raw)
  To: Tom Sanders; +Cc: redhat-list, linux-kernel, redhat-devel-list

Tom Sanders wrote:
> I'm writing an application server which receives
> requests from other applications. For each request
> received, I want to start a timer so that I can fail
> the application request if it could not be completed
> in max specified time.
> 
> Which Linux timer facility can be used for this?

I used setitimer for a similar task.  Since you can only have one timer 
going at any given time, I set up a linked list of timing events, with 
each event's timeout expressed as a delta from the previous event.  This 
way changing the time on the system has no effect on the application. 
The itimer is then set for the first event in the list.  When a timer 
goes off, it optionally re-inserts the event into the list, starts the 
next itimer, and then calls a callback function for the expired event 
with an opaque data pointer as an argument.

Works really well.

Chris



-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Linux application level timers?
  2003-01-23 16:28 ` Chris Friesen
@ 2003-01-23 17:26   ` DervishD
  0 siblings, 0 replies; 8+ messages in thread
From: DervishD @ 2003-01-23 17:26 UTC (permalink / raw)
  To: Chris Friesen; +Cc: Tom Sanders, redhat-list, linux-kernel, redhat-devel-list

    Hi Chris and Tom :))

> >Which Linux timer facility can be used for this?
> I used setitimer for a similar task.  Since you can only have one timer 
> going at any given time, I set up a linked list of timing events, with 
> each event's timeout expressed as a delta from the previous event.

    Tom, if you're interested, I coded a timer multiplexor for Linux
(user space, I mean) a time ago, and although it hasn't been released
yet, has been in use for a year in The Puto Amo Window Manager, so I
think it is pretty stable. It's GPL'd, but not released yet because
it lacks documentation by now and I want to change a couple of
things.

    If you want, I can attach you the code (is pretty simple), or
even better, you can go to www.pleyades.net/~pawm, download the
window manager and pick the code from there (is a bit more updated
that mine, since has a couple of contributions). The file is called
timux.[c,h], and needs too the file chain.c for the data container.
Just let me know. And count on any help you need with TiMux ;))

    Raúl

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-01-23 17:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-22 22:17 Linux application level timers? Tom Sanders
2003-01-22 23:03 ` Steven Dake
2003-01-22 23:35 ` george anzinger
2003-01-23  4:36 ` Gerhard Mack
2003-01-23  8:37 ` Narsimha Reddy CH
2003-01-23  8:51 ` Riku Meskanen
2003-01-23 16:28 ` Chris Friesen
2003-01-23 17:26   ` DervishD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox