linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Start of the time slice
@ 2004-07-05  7:22 Nagy Imre (Vecsés)
  2004-07-05 10:39 ` Glynn Clements
  2004-07-05 12:35 ` J.
  0 siblings, 2 replies; 3+ messages in thread
From: Nagy Imre (Vecsés) @ 2004-07-05  7:22 UTC (permalink / raw)
  To: linux-c-programming

Dear List,

Excuse me, my English is limited, but I try to formulate clearly.

I would like to konw how many unexpired time is in my process. The normal
time slice (10ms) is enough for me, but I want to get run my function right
at the start of time slice. 

        _______________           ______________
____ ... 10 ms         __ . . . __  10 ms       ___

        |my f()                   |my f()


main()

{
.
.
.

while(1) {
   f();
}
.
.
.

Best regards,

Imre Nagy



Ezen uzenet es annak barmely csatolt anyaga bizalmas, jogi vedelem alatt all, a nyilvanos kozlestol vedett.
Az uzenetet kizarolag a cimzett, illetve az altala meghatalmazottak hasznalhatjak fel. Ha On nem az uzenet cimzettje, ugy kerjuk, hogy telefonon, vagy e-mail-ben ertesitse errol az uzenet kuldojet es torolje az uzenetet, 
valamint annak osszes csatolt mellekletet a rendszerebol. Ha On nem az uzenet cimzettje, abban az esetben tilos az 
uzenetet vagy annak barmely csatolt mellekletet lemasolnia, elmentenie, az uzenet tartalmat barkivel kozolnie 
vagy azzal visszaelnie.


This message and any attachment are confidential and are legally privileged. It is intended solely for the use of 
the individual or entity to whom it is addressed and others authorised to receive it. If you are not the intended 
recipient, please telephone or email the sender and delete this message and any attachment from your system. 
Please note that any dissemination, distribution, copying or use of or reliance upon the information contained in 
and transmitted with this e-mail by or to anyone other than the recipient designated above by the sender is 
unauthorised and strictly prohibited.



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

* Re: Start of the time slice
  2004-07-05  7:22 Start of the time slice Nagy Imre (Vecsés)
@ 2004-07-05 10:39 ` Glynn Clements
  2004-07-05 12:35 ` J.
  1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2004-07-05 10:39 UTC (permalink / raw)
  To: Nagy Imre (Vecsés); +Cc: linux-c-programming


Nagy Imre (Vecs^[-Bés) wrote:^[-A

> Excuse me, my English is limited, but I try to formulate clearly.
> 
> I would like to konw how many unexpired time is in my process. The normal
> time slice (10ms) is enough for me, but I want to get run my function right
> at the start of time slice. 

Try calling sched_yield(), or nanosleep() with a delay of 1ns.

-- 
Glynn Clements <glynn.clements@virgin.net>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: Start of the time slice
  2004-07-05  7:22 Start of the time slice Nagy Imre (Vecsés)
  2004-07-05 10:39 ` Glynn Clements
@ 2004-07-05 12:35 ` J.
  1 sibling, 0 replies; 3+ messages in thread
From: J. @ 2004-07-05 12:35 UTC (permalink / raw)
  To: linux-c-programming

On Mon, 5 Jul 2004, [iso-8859-2] Nagy Imre (Vecsés) wrote:
> Dear List,
> 
> Excuse me, my English is limited, but I try to formulate clearly.
> 
> I would like to konw how many unexpired time is in my process. The normal
> time slice (10ms) is enough for me, but I want to get run my function right
> at the start of time slice. 
>         _______________           ______________
> ____ ... 10 ms         __ . . . __  10 ms       ___
> 
>         |my f()                   |my f()
> 
> main()
> 
> {
> .
> 
> while(1) {
>    f();
> }
> .
> 
> Best regards,
> 
> Imre Nagy

I am not quite sure what your question is, but my best guess is that you
are asking how to time parts of your c code ??

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>

#define CPU_TIME (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + \
  ruse.ru_stime.tv_sec + 1e-6 * \
  (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec))

/* get resource limits and usage */
extern int getrusage();
struct rusage ruse;

int main(void) {
 double first, second;
 time_t start, end;

 /* record start time... */
 time(&start);
 first = CPU_TIME;

 /* produce some cpu cycles... */
 /* put your code to be timed here.. */
 /* .... */

 /* end time.. */
 second = CPU_TIME;
 time(&end);

 /* print the results */
 printf("cpu  : %.2f secs\n", second - first); 
 printf("user : %d secs\n", (int)(end - start));
}

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2004-07-05 12:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-05  7:22 Start of the time slice Nagy Imre (Vecsés)
2004-07-05 10:39 ` Glynn Clements
2004-07-05 12:35 ` J.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).