[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [rtl] Update rtl2.2 to 3.0p10



	Well, the first thing i can pick out that might be making this not
work is that you need to set the scheduling for the thread where you do the
wait.  See below where i inserted code as to how i would do it.

On Tue, Jan 09, 2001 at 07:58:38PM +0100, Peter Helbig wrote:
> Hello Everybody! 
> 
> I updated from rtlV2.2 to V3.0p10 and found a different behaviour of  
> pthread_make_periodic_np(...,...,0). In V2.2 it works as suspected: The 
>  thread is called once and is sentenced to wait with a 
> pthread_wait_np()  afterwards.  In V3.0p10 the call of 
> pthread_wait_np() blocks the thread  forever. 
> 
> Code example: 
> 
> void *thread_code(void *param) 
> { 
> 
	struct sched_param my_sparam;
> // blabla 
> --------------- snip ----------------------------------------------- 
>     do 
>      { 
>            min_diff = 2000000000; 
>             max_diff = -2000000000; 
> 
>         for (i = 0; i < ntests; i++) 
>         { 
>                 now = clock_gethrtime(rtl_getschedclock()); 
>                  if (advance && !mode) 
>                  { 
>                       if (now < expected) 
>                       { 
>                              rtl_delay (expected - now); 
>                       } 
>                         now = clock_gethrtime(CLOCK_UST); 
>                   } 
> 
>                         /* start of next time element */ 
>                         do_rayonic_start(); 
>                         do_rayonic(loops); 
>                         do_rayonic_fini(); 
> 
>                         /* finished user part of measurement */ 
>                         fini = clock_gethrtime(rtl_getschedclock()); 
>                         samp.fini = fini; 
> 
>                         /* calculate time for next activation */ 
>                         /* 1) difference from expectation */ 
>                         diff = now - expected; 
>                         samp.diff = diff; 
>                         if (diff < min_diff) 
>                         { 
>                                 min_diff = diff; 
>                         } 
> 
>                         if (diff > max_diff) 
>                         { 
>                                 max_diff = diff; 
>                         } 
> 
>                         /* 2) theoretical sleeping duration */ 
>                         sleepfor = CYCLETIME-(fini-now); 
>                         samp.sleepfor = sleepfor; 
> 
>                         /* 3) adaptive control towards expected time */ 
>                         sleepfor -= diff; 
> 
>                         /* 4) avoid processor overload */ 
>                         expected += CYCLETIME; 
>                         while (sleepfor < MAXLOAD) 
>                         { 
>                                 sleepfor += CYCLETIME; 
>                                 expected += CYCLETIME; 
>                                 samp.skipped ++; 
>                         } 
> 
>                         /* 5) absolute time for reactivation */ 
>                         sleepto = (now+sleepfor); 
>                         samp.sleepto = sleepto; 
> 
	my_sparam.sched_priority = 1;

	if (
	    (retval =
	     pthread_setschedparam(pthread_self(), SCHED_FIFO,
				   &my_sparam)) != 0) {
		return (void *) retval;
	}

>                         pthread_make_periodic_np 
> (pthread_self(),sleepto,0); 
> //++++++++++++++++++++++++++++++++++++++++++++++++ 
> 			// In V3.0p10 the next call blocks the thread 
> forever, 
> 			// in V2.2 it works properly....	 
> //++++++++++++++++++++++++++++++++++++++++++++++++ 
>                      pthread_wait_np(); 
>                 } 
> 
>                 samp.min = min_diff; 
>                 samp.max = max_diff; 
>                 write (fifo_monitor, &samp, sizeof(samp)); 
> 
>         } while (1);    // endless... 
>                                                                      
> ----------------- snap 
> ----------------------------------------------------------- 
> } // thread end 
> 
> 
> Any hints will be welcome! 
> 
> 
> Peter 
> 
> 
> Peter Helbig
> Rayonic Sensor Systems GmbH
> Entwicklung Software
> Bayreuther Strasse 108
> D-91301 Forchheim
> 
> Tel: ++49 (0) 9191 72 818-0
> Fax: ++49 (0) 9191 640 333
> Email: Peter.Helbig@rayonic.de
> http://www.rayonic.de
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail majordomo@rtlinux.org OR
> echo "unsubscribe rtl " | mail majordomo@rtlinux.org
> ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/rtlinux/
> 
>