ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
* [sisyphus] Работа под 2.6.х с привязкой ко временным отметкам.
@ 2004-10-08 13:48 Epiphanov Sergei
  2004-10-11  0:27 ` Serge Pavlovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Epiphanov Sergei @ 2004-10-08 13:48 UTC (permalink / raw)
  To: Рассылка Sisyphus

Есть программа, которую решил привязать к таймеру для работы в реальном 
времени. Принцип простой: поставил обработку setitimer на запуск SIG_ALARM 
с шагом 10 мсек.

#define _XOPEN_SOURCE 600
#define _GNU_SOURCE
#include <sys/time.h>
#include <signal.h>
#include <stdio.h>
#include <pthread.h>



volatile int nextnum=0;
volatile pthread_mutex_t fastmutex;

void alarmsig(int i){
    pthread_mutex_lock( &fastmutex );
    nextnum++;
    pthread_mutex_unlock( &fastmutex );
}

static struct sigaction oldsig;

/*type<0.5 - drop timer
  type>0.5 - set timer*/
void settimer_(float *type, float *step){
    long int sec = *step;
    long int usec = (*step-sec)*1e6;
    struct itimerval tv,old;
    struct sigaction newsig,temp;
    pthread_mutexattr_t attr;
    printf("sec=%ld usec=%ld\n",sec,usec);
    if( *type>0.5 ){
 pthread_mutexattr_init( &attr );
 pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_FAST_NP );
 pthread_mutex_init( &fastmutex, &attr );
 pthread_mutexattr_destroy( &attr );
 tv.it_interval.tv_sec = sec;
 tv.it_interval.tv_usec = usec;
 tv.it_value.tv_sec = sec;
 tv.it_value.tv_usec = usec;
 nextnum = 0;
 newsig.sa_handler = alarmsig;
 newsig.sa_flags = SA_NOMASK;
 sigaction( SIGALRM, &newsig, &oldsig );
 setitimer( ITIMER_REAL, &tv, &old );
    } else{
 tv.it_interval.tv_sec = 0;
 tv.it_interval.tv_usec = 0;
 tv.it_value.tv_sec = 0;
 tv.it_value.tv_usec = 0;
 setitimer( ITIMER_REAL, &tv, &old );
 nextnum = 0;
 sigaction( SIGALRM, &oldsig, &temp );
 pthread_mutex_destroy( &fastmutex );
    }
    
}

void waittime_( float *err ){
    int cur = nextnum;
    if( cur>1 ){
 *err = cur;
 return;
    }
    while( !cur ){
 pthread_mutex_lock( &fastmutex );
 cur = nextnum;
 pthread_mutex_unlock( &fastmutex );
    }
    *err = 0;
    pthread_mutex_lock( &fastmutex );
    nextnum = 0;
    pthread_mutex_unlock( &fastmutex );
    return;
}

Затем:
1)t=0
2)в цикле:
а) основная программа
б) t=t+10мсек
в) waittime_(err)
г) завершение цикла при t>=100сек.

Так вот, при таком раскладе на ядре 2.6.8-std-smp-alt9 программа работает 
110сек (+10%). И этот расклад не зависит от шага (10мсек, 100мсек, 1сек). 
На ядре 2.4.26-std-up-alt6 эта же программа без пересборки работает точно 
100 сек. Что это может быть?

-- 
С уважением, Епифанов Сергей


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

end of thread, other threads:[~2004-10-11  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-08 13:48 [sisyphus] Работа под 2.6.х с привязкой ко временным отметкам Epiphanov Sergei
2004-10-11  0:27 ` Serge Pavlovsky
2004-10-11  7:42   ` Epiphanov Sergei

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git