Skip to contentSkip to conversation

real time task disapears... memory problem ?

Xenomai-help [email protected] 5 participants 31 messages Jun 7, 2007 – Jul 16, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw
Quoted 2 lines

What kind of statistics would you precisely need? And where would you need it, means where is your scheduler located, what API does it use?

I need execution time (and not response time). A patch for this has been create by a former student (now Doctor David Robert) working before me. You can find it enclosed with this mail. Anyway the problem doesn't come from this patch, it appears also with vanilla xenomai.

Quoted 3 lines

Primarily code. We need your code that demonstrates the weird behaviour. If you patched Xenomai in any way, that patch would be required as well of course.

I have reduced the size of the code to the thing that is not working. You can find it enclosed.
The main program creates a task that calls the gsl_qp function (a quadratic solver).
The problem appends during the call of ql0001_. If I remove this call, it works. I if keep it, the task disapears without any error (I only see that in /proc/xenomai/stat ).

Quoted 2 lines

BTW, did you already try to attach gdb to your disappearing process? Maybe it can catch what makes it terminate.

I have tried without success, but I don really know how to use it in that way...

My config: (I have install the last availlable xenomai since last mail)
- Linux kernel : 2.6.20.3
- xenomai : 2.3.1
- Adeos : 1.7-03
- Laptop compact Evo N600c Pentium 3M 1.2Ghz

Quoted 1 line

.config, Xenomai version, and I-pipe version can be helpful too.

.config is enclosed (DentiX231)

Quoted 1 line

Jan

Thanks for your help

Arnaud DESVAGES

include/native/syscall.h +1 -1
diff -urN xenomai-2.3.1/include/native/syscall.h xenomai-exectime-2.3.1/include/native/syscall.h
@@ -119,7 +119,7 @@
 #define __native_timer_tsc2ns       93
 #define __native_queue_write        94
 #define __native_queue_read         95
-
+#define __native_task_get_exectime  96
 struct rt_arg_bulk {
 
     u_long a1;
include/native/task.h +2 -0
diff -urN xenomai-2.3.1/include/native/task.h xenomai-exectime-2.3.1/include/native/task.h
@@ -292,6 +292,8 @@
 int rt_task_slice(RT_TASK *task,
 		  RTIME quantum);
 
+int rt_task_get_exectime (RT_TASK *task, RTIME *exectime);
+
 ssize_t rt_task_send(RT_TASK *task,
 		     RT_TASK_MCB *mcb_s,
 		     RT_TASK_MCB *mcb_r,
include/nucleus/pod.h +2 -0
diff -urN xenomai-2.3.1/include/nucleus/pod.h xenomai-exectime-2.3.1/include/nucleus/pod.h
@@ -486,6 +486,8 @@
 
 xnticks_t xnpod_get_time(void);
 
+xnticks_t xnpod_get_exectime (xnthread_t *thread);
+
 static inline xntime_t xnpod_get_cpu_time(void)
 {
 	return xnarch_get_cpu_time();
include/nucleus/thread.h +3 -0
diff -urN xenomai-2.3.1/include/nucleus/thread.h xenomai-exectime-2.3.1/include/nucleus/thread.h
@@ -228,6 +228,9 @@
 
     void *cookie;		/* Cookie to pass to the entry routine */
 
+    xnticks_t lastswitch;	/* timestamp of the last switch to execute the thread */ 
+    xnticks_t exectime;	/* execution time since the start of the thread */ 
+
     XNARCH_DECL_DISPLAY_CONTEXT();
 
 } xnthread_t;
ksrc/nucleus/pod.c +39 -1
diff -urN xenomai-2.3.1/ksrc/nucleus/pod.c xenomai-exectime-2.3.1/ksrc/nucleus/pod.c
@@ -2453,6 +2453,10 @@
 	xnstat_runtime_switch(sched, &threadin->stat.account);
 	xnstat_counter_inc(&threadin->stat.csw);
 
+	/* David */
+	threadout->exectime += xnarch_get_cpu_tsc() - threadout->lastswitch;
+ 	threadin->lastswitch=xnarch_get_cpu_tsc();
+ 	
 	xnarch_switch_to(xnthread_archtcb(threadout),
 			 xnthread_archtcb(threadin));
 
@@ -2537,7 +2541,7 @@
 void xnpod_schedule_runnable(xnthread_t *thread, int flags)
 {
 	xnsched_t *sched = thread->sched;
-	xnthread_t *runthread = sched->runthread, *threadin;
+	xnthread_t *runthread = sched->runthread, *threadout, *threadin;
 
 	xnltt_log_event(xeno_ev_fastsched);
 	xnarch_trace_pid(xnthread_user_task(thread) ?
@@ -2625,6 +2629,11 @@
 	xnstat_runtime_switch(sched, &threadin->stat.account);
 	xnstat_counter_inc(&threadin->stat.csw);
 
+	/* David */
+	threadout = runthread;	
+	threadout->exectime += xnarch_get_cpu_tsc() - threadout->lastswitch;
+ 	threadin->lastswitch=xnarch_get_cpu_tsc();
+
 	xnarch_switch_to(xnthread_archtcb(runthread),
 			 xnthread_archtcb(threadin));
 
@@ -2710,6 +2719,34 @@
 	return xntimer_get_jiffies() + nkpod->wallclock_offset;
 }
 
+
+
+/*!
+ * \fn xnticks_t xnpod_get_exectime (xnthread_t *thread);
+ * \brief Get the thread execution time.
+ *
+ * This service gets the CPU time consumed by the task in the Xenomai domain. 
+ * The result is expressed in CPU clock ticks.
+ * 
+ * @return The execution time expressed in CPU clock ticks.
+ *
+ * Environments:
+ *
+ * This service can be called from: (to be checked)
+ * - Kernel module initialization/cleanup code
+ * - Kernel-based task
+ * - User-space task
+ * 
+ * Rescheduling: never
+ */
+
+xnticks_t xnpod_get_exectime (xnthread_t *thread)
+
+{
+	return thread->exectime;
+}
+
+
 /*! 
  * \fn int xnpod_add_hook(int type,void (*routine)(xnthread_t *))
  * \brief Install a nucleus hook.
@@ -3581,6 +3618,7 @@
 EXPORT_SYMBOL(xnpod_delete_thread);
 EXPORT_SYMBOL(xnpod_fatal_helper);
 EXPORT_SYMBOL(xnpod_get_time);
+EXPORT_SYMBOL(xnpod_get_exectime);
 EXPORT_SYMBOL(xnpod_init);
 EXPORT_SYMBOL(xnpod_init_thread);
 EXPORT_SYMBOL(xnpod_migrate_thread);
ksrc/nucleus/thread.c +2 -0
diff -urN xenomai-2.3.1/ksrc/nucleus/thread.c xenomai-exectime-2.3.1/ksrc/nucleus/thread.c
@@ -97,6 +97,8 @@
 	thread->cookie = 0;
 	thread->stime = 0;
 
+ 	thread->lastswitch = 0;
+ 	thread->exectime = 0;
 	if (name)
 		xnobject_copy_name(thread->name, name);
 	else
ksrc/skins/native/syscall.c +47 -0

59 lines not on this page · raw message

ksrc/skins/native/task.c +62 -0

74 lines not on this page · raw message

src/skins/native/task.c +9 -0
diff -urN xenomai-2.3.1/src/skins/native/task.c xenomai-exectime-2.3.1/src/skins/native/task.c
@@ -256,6 +256,15 @@
 				 info);
 }
 
+int rt_task_get_exectime (RT_TASK *task,
+			 RTIME *exectime)
+ {
+ 	return XENOMAI_SKINCALL2(__native_muxid,
+ 				__native_task_get_exectime,
+ 				task,
+ 				exectime);	
+ }
+ 
 int rt_task_notify(RT_TASK *task, rt_sigset_t signals)
 {
 	return XENOMAI_SKINCALL2(__native_muxid,

/* Set error number */
#define SETERRNO(nr) {errno = nr; return -1;}
//#define SETERRNO(nr) {return -1;}
/* Error number definitions */
#define ECONVERGE (sys_nerr+0) /* Iterative algoritm failed to converge */

#include <math.h>
#include <gsl/gsl_matrix.h>
//#include "Exec/prr.h"
//#include <unistd.h> //appel a sysconf
//#include <native/heap.h>
//#include "test_essai_qld.h"

#define HORIZON 27//25//25

#define Npas    2 //10 //nombre de pas entre deux points apres l'horizon normal
#define HORIZ2  0//15//10 // NOMBRE de points de l'horizon ou le pas augmente
#define Nin     4//
#define Nout    2//
#define Nst     9//
#define Noptim  (Nout+(HORIZON+1)*Nst+HORIZON*Nin) //taille du vecteur d'optimisation

#define Nconstr (Nout+(HORIZON+1)*Nst+2*HORIZON*Nin+Nout) //taille du vecteur de contraintes (eq+ineq)

int gsl_qp()//(gsl_matrix *x,const gsl_matrix *C,const gsl_matrix *d,int me, const gsl_matrix *A,const gsl_matrix *b,const gsl_matrix *xl, const gsl_matrix *xu) {

/* Variables for call to qld */
int mnn = Nconstr +2*Noptim;//A->size1+2*C->size1; /* Constant set to m+2*n */

double* qp_Cd; // Objective function [nxn]
double* qp_dd; // Constant vector of the objective function [n]
double* qp_Ad; // Data constraints [mxn]
double* qp_bd; // Constant data of linear constraints [m]
double *qp_xud,*qp_xld; // Constraints
double* qp_xd; // Output
double* qp_u; // Lagrange multipliers [m+n+n] (output vector)
double* qp_war; // Workspace [3*n*n/2 + 10*n + 2*n]
int* qp_iwar; // Integer workspace [n]

int iout = 0; /* Not used (code comented out in qld.c) */
int ifail = 0; /* Termination reason 0 == OK (output value) */
int iprint = 0; /* Print control 0 == off */
// double* war; // Workspace [3*n*n/2 + 10*n + 2*n]
int lwar = 3*Noptim*Noptim/2 + 10*Noptim + 2*Nconstr + 1; //3*C->size1*C->size1/2 + 10*C->size1 + 2*A->size1 +1; /* Workspace size */
// int* iwar; // Integer workspace [n]
int liwar = Noptim; //C->size1; /* Integer workspace size */
double eps1 = 1.11e-16; /* Machine presision */

int i,j,k;

#define HEAP_SIZE (16*1024*1024)
#define HEAP_MODE 0 // Local heap.

RT_HEAP heap_desc;
void *block;
int err;

  int varNoptim = Noptim;
  int varNconstr = Nconstr;
  int me= Nconstr /2;
    err = rt_heap_create(&heap_desc,"gsl_qp_Heap",HEAP_SIZE,HEAP_MODE); 

  
    err = rt_heap_alloc(&heap_desc,Noptim*Noptim*sizeof(double),TM_NONBLOCK,(void*)&qp_Cd);  
    err |= rt_heap_alloc(&heap_desc,Noptim*sizeof(double),TM_NONBLOCK,(void*)&qp_dd);  
    err |= rt_heap_alloc(&heap_desc,Noptim*Nconstr*sizeof(double),TM_NONBLOCK,(void*)&qp_Ad);  
    err |= rt_heap_alloc(&heap_desc,Nconstr*sizeof(double),TM_NONBLOCK,(void*)&qp_bd);  
    err |= rt_heap_alloc(&heap_desc,Noptim*sizeof(double),TM_NONBLOCK,(void*)&qp_xld);  
    err |= rt_heap_alloc(&heap_desc,Noptim*sizeof(double),TM_NONBLOCK,(void*)&qp_xud);  
    err |= rt_heap_alloc(&heap_desc,Noptim*sizeof(double),TM_NONBLOCK,(void*)&qp_xd); 
    err |= rt_heap_alloc(&heap_desc,mnn*sizeof(double),TM_NONBLOCK,(void*)&qp_u);  
    err |= rt_heap_alloc(&heap_desc,lwar*sizeof(double),TM_NONBLOCK,(void*)&qp_war);  
    err |= rt_heap_alloc(&heap_desc,liwar*sizeof(double),TM_NONBLOCK,(void*)&qp_iwar);  
  //remise a zero des variables (u, war, iwar) qui ne sont pas initialis�es automatiquement derriere
  for (i=0;i<(Nconstr+2*Noptim);i++)
    qp_u[i] = 0;
  for (i=0;i<(3*Noptim*Noptim/2 + 10*Noptim + 2*(Nout+(HORIZON+1)*Nst+2*HORIZON*Nin+Nout) +1);i++)
    qp_war[i] = 0;
  for (i=0;i<(Noptim);i++)
    qp_iwar[i] = 0;


  
  qp_iwar[0]=1;

  // Copy data in C, d and A, b to Cd, dd and Ad, bd (Fortran 77 standard) 
  for(k=0,j=0;j<Noptim;j++)
    for(i=0;i<Noptim;i++,k++)
      qp_Cd[k] = k;//gsl_matrix_get(C,i,j);
  for(i=0;i<Noptim;i++)
    qp_dd[i] = i;//gsl_matrix_get(d,i,0); 
  for(k=0,j=0;j<Noptim;j++)
    for(i=0;i<Nconstr;i++,k++)
      qp_Ad[k] = k;//-1.0 * gsl_matrix_get(A,i,j); 
  for(i=0;i<Nconstr;i++)
    qp_bd[i] = i;//gsl_matrix_get(b,i,0); 
  // Copy data in x, xu and xl to xd, xud and xld
  for(i=0;i<Noptim;i++)
    {   qp_xd[i]  = i;//gsl_matrix_get(x,i,0); 
      qp_xud[i] = i;//gsl_matrix_get(xu,i,0); 
      qp_xld[i] = i;//gsl_matrix_get(xl,i,0);
    };

  // Call interface function in qld.c
  ql0001_(&varNconstr, &me, &varNconstr, &varNoptim, &varNoptim, &mnn, qp_Cd, qp_dd, qp_Ad, qp_bd, qp_xld, qp_xud, qp_xd, qp_u, &iout, &ifail, &iprint, qp_war, &lwar, qp_iwar, &liwar, &eps1);

  //rt_task_set_mode(T_WARNSW , 0,  NULL);
  

  
  // Free the block: rt_heap_free(&heap_desc,block);
  rt_heap_free(&heap_desc,qp_iwar); 
  rt_heap_free(&heap_desc,qp_war); 
  rt_heap_free(&heap_desc,qp_u); 
  rt_heap_free(&heap_desc,qp_xd); 
  rt_heap_free(&heap_desc,qp_xud); 
  rt_heap_free(&heap_desc,qp_xld); 
  rt_heap_free(&heap_desc,qp_Ad); 
  rt_heap_free(&heap_desc,qp_bd); 
  rt_heap_free(&heap_desc,qp_dd); 
  rt_heap_free(&heap_desc,qp_Cd); 

  //printf("Heap Freed Succed\n");

  rt_heap_delete(&heap_desc); 
  //printf("Heap Delete Succeed\n");
  
  //rt_task_set_mode(0, T_WARNSW , NULL);
  //rt_task_set_mode(0, T_PRIMARY , NULL);

  /* If failure return -1 */
  if(ifail != 0)
    SETERRNO(ECONVERGE);

return 0;
}

#ifndef F2C_INCLUDE
#define F2C_INCLUDE

typedef int integer;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; typedef long int logical;
typedef short int shortlogical;

#define TRUE_ (1)
#define FALSE_ (0)

/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif

/* I/O stuff */

#ifdef f2c_i2
/* for -i2 */
typedef short flag;
typedef short ftnlen;
typedef short ftnint;
#else
typedef long flag;
typedef long ftnlen;
typedef long ftnint;
#endif

/*external read, write*/
typedef struct

{	flag cierr;
	ftnint ciunit;
	flag ciend;
	char *cifmt;
	ftnint cirec;
} cilist;

/*internal read, write*/
typedef struct

{	flag icierr;
	char *iciunit;
	flag iciend;
	char *icifmt;
	ftnint icirlen;
	ftnint icirnum;
} icilist;

/*open*/
typedef struct

{	flag oerr;
	ftnint ounit;
	char *ofnm;
	ftnlen ofnmlen;
	char *osta;
	char *oacc;
	char *ofm;
	ftnint orl;
	char *oblnk;
} olist;

/*close*/
typedef struct

{	flag cerr;
	ftnint cunit;
	char *csta;
} cllist;

/*rewind, backspace, endfile*/
typedef struct

{	flag aerr;
	ftnint aunit;
} alist;

/* inquire */
typedef struct

{	flag inerr;
	ftnint inunit;
	char *infile;
	ftnlen infilen;
	ftnint	*inex;	/*parameters in standard's order*/
	ftnint	*inopen;
	ftnint	*innum;
	ftnint	*innamed;
	char	*inname;
	ftnlen	innamlen;
	char	*inacc;
	ftnlen	inacclen;
	char	*inseq;
	ftnlen	inseqlen;
	char 	*indir;
	ftnlen	indirlen;
	char	*infmt;
	ftnlen	infmtlen;
	char	*inform;
	ftnint	informlen;
	char	*inunf;
	ftnlen	inunflen;
	ftnint	*inrecl;
	ftnint	*innrec;
	char	*inblank;
	ftnlen	inblanklen;
} inlist;

#define VOID void

union Multitype { /* for multiple entry points */

	shortint h;
	integer i;
	real r;
	doublereal d;
	complex c;
	doublecomplex z;
	};

typedef union Multitype Multitype;

typedef long Long;

struct Vardesc { /* for Namelist */

	char *name;
	char *addr;
	Long *dims;
	int  type;
	};

typedef struct Vardesc Vardesc;

struct Namelist {
	char *name;
	Vardesc **vars;
	int nvars;
	};

typedef struct Namelist Namelist;

#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (doublereal)abs(x)
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (doublereal)min(a,b)
#define dmax(a,b) (doublereal)max(a,b)

/* procedure parameter types for -A and -C++ */

#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef int /* Unknown procedure type */ (*U_fp)(...); typedef shortint (*J_fp)(...);
typedef integer (*I_fp)(...);
typedef real (*R_fp)(...);
typedef doublereal (*D_fp)(...), (*E_fp)(...); typedef /* Complex */ VOID (*C_fp)(...);
typedef /* Double Complex */ VOID (*Z_fp)(...); typedef logical (*L_fp)(...);
typedef shortlogical (*K_fp)(...);
typedef /* Character */ VOID (*H_fp)(...); typedef /* Subroutine */ int (*S_fp)(...);
#else
typedef int /* Unknown procedure type */ (*U_fp)(); typedef shortint (*J_fp)();
typedef integer (*I_fp)();
typedef real (*R_fp)();
typedef doublereal (*D_fp)(), (*E_fp)();
typedef /* Complex */ VOID (*C_fp)();
typedef /* Double Complex */ VOID (*Z_fp)(); typedef logical (*L_fp)();
typedef shortlogical (*K_fp)();
typedef /* Character */ VOID (*H_fp)();
typedef /* Subroutine */ int (*S_fp)();
#endif
/* E_fp is for real functions when -R is not specified */
typedef VOID C_f; /* complex function */
typedef VOID H_f; /* character function */
typedef VOID Z_f; /* double complex function */
typedef doublereal E_f; /* real function with -R not specified */

/* undef any lower-case symbols that your C compiler predefines, e.g.: */

#ifndef Skip_f2c_Undefs
#undef cray
#undef gcos
#undef mc68010
#undef mc68020
#undef mips
#undef pdp11
#undef sgi
#undef sparc
#undef sun
#undef sun2
#undef sun3
#undef sun4
#undef u370
#undef u3b
#undef u3b2
#undef u3b5
#undef unix
#undef vax
#endif
#endif

/* Common Block Declarations */

struct {
    doublereal eps;
} cmache_;

#define cmache_1 cmache_

/* Table of constant values */

/*static integer c__1 = 1; */

/* umd */
/*
ql0002_ is declared here to provide ANSI C compliance. (Thanks got to Martin Wauchope for providing this correction) */
/* umd */
/*
When the fortran code was f2c converted, the use of fortran COMMON blocks was no longer available. Thus an additional variable, eps1, was added to the parameter list to account for this.
*/
/* umd */
/*
Two alternative definitions are provided in order to give ANSI compliance.
*/
int ql0002_(integer *n,integer *m,integer *meq,integer *mmax,
integer *mn,integer *mnn,integer *nmax,
logical *lql,
doublereal *a,doublereal *b,doublereal *grad, doublereal *g,doublereal *xl,doublereal *xu,doublereal *x, integer *nact,integer *iact,integer *maxit, doublereal *vsmall,
integer *info,
doublereal *diag, doublereal *w,
integer *lw)

{
    /* System generated locals */
    integer a_dim1, a_offset, g_dim1, g_offset, i__1, i__2, i__3, i__4;
    doublereal d__1, d__2, d__3, d__4;

    /* Builtin functions */
    /* umd */
    /* double sqrt();    */

    /* Local variables */
    static doublereal onha, xmag, suma, sumb, sumc, temp, step, zero;
    static integer iwwn;
    static doublereal sumx, sumy;
    static integer i, j, k;
    static doublereal fdiff;
    static integer iflag, jflag, kflag, lflag;
    static doublereal diagr;
    static integer ifinc, kfinc, jfinc, mflag, nflag;
    static doublereal vfact, tempa;
    static integer iterc, itref;
    static doublereal cvmax, ratio, xmagr;
    static integer kdrop;
    static logical lower;
    static integer knext, k1;
    static doublereal ga, gb;
    static integer ia, id;
    static doublereal fdiffa;
    static integer ii, il, kk, jl, ip, ir, nm, is, iu, iw, ju, ix, iz, nu, iy;

    static doublereal parinc, parnew;
    static integer ira, irb, iwa;
    static doublereal one;
    static integer iwd, iza;
    static doublereal res;
    static integer ipp, iwr, iws;
    static doublereal sum;
    static integer iww, iwx, iwy;
    static doublereal two;
    static integer iwz;



    /* Parameter adjustments */
    --w;
    --iact;
    --x;
    --xu;
    --xl;
    g_dim1 = *nmax;
    g_offset = g_dim1 + 1;
    g -= g_offset;
    --grad;
    --b;
    a_dim1 = *mmax;
    a_offset = a_dim1 + 1;
    a -= a_offset;

    /* Function Body */
    iwz = *nmax;
    iwr = iwz + *nmax * *nmax;
    iww = iwr + *nmax * (*nmax + 3) / 2;
    iwd = iww + *nmax;
    iwx = iwd + *nmax;
    iwa = iwx + *nmax;

/* SET SOME CONSTANTS. */

    zero = 0.;
    one = 1.;
    two = 2.;
    onha = 1.5;
    vfact = 1.;
/*     SET SOME PARAMETERS. */
/*     NUMBER LESS THAN VSMALL ARE ASSUMED TO BE NEGLIGIBLE. */
/*     THE MULTIPLE OF I THAT IS ADDED TO G IS AT MOST DIAGR TIMES */

/* THE LEAST MULTIPLE OF I THAT GIVES POSITIVE DEFINITENESS. */
/* X IS RE-INITIALISED IF ITS MAGNITUDE IS REDUCED BY THE */
/* FACTOR XMAGR. */
/* A CHECK IS MADE FOR AN INCREASE IN F EVERY IFINC ITERATIONS, */
/* AFTER KFINC ITERATIONS ARE COMPLETED. */

    diagr = two;
    xmagr = .01;
    ifinc = 3;
    kfinc = max(10,*n);

/* FIND THE RECIPROCALS OF THE LENGTHS OF THE CONSTRAINT NORMALS. */
/* RETURN IF A CONSTRAINT IS INFEASIBLE DUE TO A ZERO NORMAL. */

    *nact = 0;
    if (*m <= 0) {
	goto L45;
    }
    i__1 = *m;
    for (k = 1; k <= i__1; ++k) {
	sum = zero;
	i__2 = *n;
	for (i = 1; i <= i__2; ++i) {
/* L10: */
/* Computing 2nd power */
	    d__1 = a[k + i * a_dim1];
	    sum += d__1 * d__1;
	}
	if (sum > zero) {
	    goto L20;
	}
	if (b[k] == zero) {
	    goto L30;
	}
	*info = -k;
	if (k <= *meq) {
	    goto L730;
	}
	if (b[k] <= 0.) {
	    goto L30;
	} else {
	    goto L730;
	}
L20:
	sum = one / sqrt(sum);
L30:
	ia = iwa + k;
/* L40: */
	w[ia] = sum;
    }
L45:
    i__1 = *n;
    for (k = 1; k <= i__1; ++k) {
	ia = iwa + *m + k;
/* L50: */
	w[ia] = one;
    }

/* IF NECESSARY INCREASE THE DIAGONAL ELEMENTS OF G. */

    if (! (*lql)) {
	goto L165;
    }
    *diag = zero;
    i__1 = *n;
    for (i = 1; i <= i__1; ++i) {
	id = iwd + i;
	w[id] = g[i + i * g_dim1];
/* Computing MAX */
	d__1 = *diag, d__2 = *vsmall - w[id];
	*diag = max(d__1,d__2);
	if (i == *n) {
	    goto L60;
	}
	ii = i + 1;
	i__2 = *n;
	for (j = ii; j <= i__2; ++j) {
/* Computing MIN */
	    d__1 = w[id], d__2 = g[j + j * g_dim1];
	    ga = -min(d__1,d__2);
	    gb = (d__1 = w[id] - g[j + j * g_dim1], abs(d__1)) + (d__2 = g[i 
		    + j * g_dim1], abs(d__2));
	    if (gb > zero) {
/* Computing 2nd power */
		d__1 = g[i + j * g_dim1];
		ga += d__1 * d__1 / gb;
	    }
/* L55: */
	    *diag = max(*diag,ga);
	}
L60:
	;
    }
    if (*diag <= zero) {
	goto L90;
    }
L70:
    *diag = diagr * *diag;
    i__1 = *n;
    for (i = 1; i <= i__1; ++i) {
	id = iwd + i;
/* L80: */
	g[i + i * g_dim1] = *diag + w[id];
    }

/* FORM THE CHOLESKY FACTORISATION OF G. THE TRANSPOSE */
/* OF THE FACTOR WILL BE PLACED IN THE R-PARTITION OF W. */

L90:

    ir = iwr;
    i__1 = *n;
    for (j = 1; j <= i__1; ++j) {
	ira = iwr;
	irb = ir + 1;
	i__2 = j;
	for (i = 1; i <= i__2; ++i) {
	    temp = g[i + j * g_dim1];
	    if (i == 1) {
		goto L110;
	    }
	    i__3 = ir;
	    for (k = irb; k <= i__3; ++k) {
		++ira;
/* L100: */
		temp -= w[k] * w[ira];
	    }
L110:
	    ++ir;
	    ++ira;
	    if (i < j) {
		w[ir] = temp / w[ira];
	    }
/* L120: */
	}
	if (temp < *vsmall) {
	    goto L140;
	}
/* L130: */
	w[ir] = sqrt(temp);
    }
    goto L170;

/* INCREASE FURTHER THE DIAGONAL ELEMENT OF G. */

L140:

    w[j] = one;
    sumx = one;
    k = j;
L150:
    sum = zero;
    ira = ir - 1;
    i__1 = j;
    for (i = k; i <= i__1; ++i) {
	sum -= w[ira] * w[i];
/* L160: */
	ira += i;
    }
    ir -= k;
    --k;
    w[k] = sum / w[ir];
/* Computing 2nd power */
    d__1 = w[k];
    sumx += d__1 * d__1;
    if (k >= 2) {
	goto L150;
    }
    *diag = *diag + *vsmall - temp / sumx;
    goto L70;

/* STORE THE CHOLESKY FACTORISATION IN THE R-PARTITION */
/* OF W. */

L165:

    ir = iwr;
    i__1 = *n;
    for (i = 1; i <= i__1; ++i) {
	i__2 = i;
	for (j = 1; j <= i__2; ++j) {
	    ++ir;
/* L166: */
	    w[ir] = g[j + i * g_dim1];
	}
    }

/* SET Z THE INVERSE OF THE MATRIX IN R. */

L170:

    nm = *n - 1;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	iz = iwz + i;
	if (i == 1) {
	    goto L190;
	}
	i__1 = i;
	for (j = 2; j <= i__1; ++j) {
	    w[iz] = zero;
/* L180: */
	    iz += *n;
	}
L190:
	ir = iwr + (i + i * i) / 2;
	w[iz] = one / w[ir];
	if (i == *n) {
	    goto L220;
	}
	iza = iz;
	i__1 = nm;
	for (j = i; j <= i__1; ++j) {
	    ir += i;
	    sum = zero;
	    i__3 = iz;
	    i__4 = *n;
	    for (k = iza; i__4 < 0 ? k >= i__3 : k <= i__3; k += i__4) {
		sum += w[k] * w[ir];
/* L200: */
		++ir;
	    }
	    iz += *n;
/* L210: */
	    w[iz] = -sum / w[ir];
	}
L220:
	;
    }
/*     SET THE INITIAL VALUES OF SOME VARIABLES. */
/*     ITERC COUNTS THE NUMBER OF ITERATIONS. */
/*     ITREF IS SET TO ONE WHEN ITERATIVE REFINEMENT IS REQUIRED. */
/*     JFINC INDICATES WHEN TO TEST FOR AN INCREASE IN F. */
    iterc = 1;
    itref = 0;
    jfinc = -kfinc;

/* SET X TO ZERO AND SET THE CORRESPONDING RESIDUALS OF THE */
/* KUHN-TUCKER CONDITIONS. */

L230:

    iflag = 1;
    iws = iww - *n;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	x[i] = zero;
	iw = iww + i;
	w[iw] = grad[i];
	if (i > *nact) {
	    goto L240;
	}
	w[i] = zero;
	is = iws + i;
	k = iact[i];
	if (k <= *m) {
	    goto L235;
	}
	if (k > *mn) {
	    goto L234;
	}
	k1 = k - *m;
	w[is] = xl[k1];
	goto L240;
L234:
	k1 = k - *mn;
	w[is] = -xu[k1];
	goto L240;
L235:
	w[is] = b[k];
L240:
	;
    }
    xmag = zero;
    vfact = 1.;
    if (*nact <= 0) {
	goto L340;
    } else {
	goto L280;
    }

/* SET THE RESIDUALS OF THE KUHN-TUCKER CONDITIONS FOR GENERAL X. */

L250:

    iflag = 2;
    iws = iww - *n;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	iw = iww + i;
	w[iw] = grad[i];
	if (*lql) {
	    goto L259;
	}
	id = iwd + i;
	w[id] = zero;
	i__1 = *n;
	for (j = i; j <= i__1; ++j) {
/* L251: */
	    w[id] += g[i + j * g_dim1] * x[j];
	}
	i__1 = i;
	for (j = 1; j <= i__1; ++j) {
	    id = iwd + j;
/* L252: */
	    w[iw] += g[j + i * g_dim1] * w[id];
	}
	goto L260;
L259:
	i__1 = *n;
	for (j = 1; j <= i__1; ++j) {
/* L261: */
	    w[iw] += g[i + j * g_dim1] * x[j];
	}
L260:
	;
    }
    if (*nact == 0) {
	goto L340;
    }
    i__2 = *nact;
    for (k = 1; k <= i__2; ++k) {
	kk = iact[k];
	is = iws + k;
	if (kk > *m) {
	    goto L265;
	}
	w[is] = b[kk];
	i__1 = *n;
	for (i = 1; i <= i__1; ++i) {
	    iw = iww + i;
	    w[iw] -= w[k] * a[kk + i * a_dim1];
/* L264: */
	    w[is] -= x[i] * a[kk + i * a_dim1];
	}
	goto L270;
L265:
	if (kk > *mn) {
	    goto L266;
	}
	k1 = kk - *m;
	iw = iww + k1;
	w[iw] -= w[k];
	w[is] = xl[k1] - x[k1];
	goto L270;
L266:
	k1 = kk - *mn;
	iw = iww + k1;
	w[iw] += w[k];
	w[is] = -xu[k1] + x[k1];
L270:
	;
    }

/* PRE-MULTIPLY THE VECTOR IN THE S-PARTITION OF W BY THE */
/* INVERS OF R TRANSPOSE. */

L280:

    ir = iwr;
    ip = iww + 1;
    ipp = iww + *n;
    il = iws + 1;
    iu = iws + *nact;
    i__2 = iu;
    for (i = il; i <= i__2; ++i) {
	sum = zero;
	if (i == il) {
	    goto L300;
	}
	ju = i - 1;
	i__1 = ju;
	for (j = il; j <= i__1; ++j) {
	    ++ir;
/* L290: */
	    sum += w[ir] * w[j];
	}
L300:
	++ir;
/* L310: */
	w[i] = (w[i] - sum) / w[ir];
    }

/* SHIFT X TO SATISFY THE ACTIVE CONSTRAINTS AND MAKE THE */
/* CORRESPONDING CHANGE TO THE GRADIENT RESIDUALS. */

    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	iz = iwz + i;
	sum = zero;
	i__1 = iu;
	for (j = il; j <= i__1; ++j) {
	    sum += w[j] * w[iz];
/* L320: */
	    iz += *n;
	}
	x[i] += sum;
	if (*lql) {
	    goto L329;
	}
	id = iwd + i;
	w[id] = zero;
	i__1 = *n;
	for (j = i; j <= i__1; ++j) {
/* L321: */
	    w[id] += g[i + j * g_dim1] * sum;
	}
	iw = iww + i;
	i__1 = i;
	for (j = 1; j <= i__1; ++j) {
	    id = iwd + j;
/* L322: */
	    w[iw] += g[j + i * g_dim1] * w[id];
	}
	goto L330;
L329:
	i__1 = *n;
	for (j = 1; j <= i__1; ++j) {
	    iw = iww + j;
/* L331: */
	    w[iw] += sum * g[i + j * g_dim1];
	}
L330:
	;
    }

/* FORM THE SCALAR PRODUCT OF THE CURRENT GRADIENT RESIDUALS */
/* WITH EACH COLUMN OF Z. */

L340:

    kflag = 1;
    goto L930;
L350:
    if (*nact == *n) {
	goto L380;
    }

/* SHIFT X SO THAT IT SATISFIES THE REMAINING KUHN-TUCKER */
/* CONDITIONS. */

    il = iws + *nact + 1;
    iza = iwz + *nact * *n;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	sum = zero;
	iz = iza + i;
	i__1 = iww;
	for (j = il; j <= i__1; ++j) {
	    sum += w[iz] * w[j];
/* L360: */
	    iz += *n;
	}
/* L370: */
	x[i] -= sum;
    }
    *info = 0;
    if (*nact == 0) {
	goto L410;
    }

/* UPDATE THE LAGRANGE MULTIPLIERS. */

L380:

    lflag = 3;
    goto L740;
L390:
    i__2 = *nact;
    for (k = 1; k <= i__2; ++k) {
	iw = iww + k;
/* L400: */
	w[k] += w[iw];
    }

/* REVISE THE VALUES OF XMAG. */
/* BRANCH IF ITERATIVE REFINEMENT IS REQUIRED. */

L410:

    jflag = 1;
    goto L910;
L420:
    if (iflag == itref) {
	goto L250;
    }

/* DELETE A CONSTRAINT IF A LAGRANGE MULTIPLIER OF AN */
/* INEQUALITY CONSTRAINT IS NEGATIVE. */

    kdrop = 0;
    goto L440;
L430:
    ++kdrop;
    if (w[kdrop] >= zero) {
	goto L440;
    }
    if (iact[kdrop] <= *meq) {
	goto L440;
    }
    nu = *nact;
    mflag = 1;
    goto L800;
L440:
    if (kdrop < *nact) {
	goto L430;
    }

/* SEEK THE GREATEAST NORMALISED CONSTRAINT VIOLATION, DISREGARDING */

/* ANY THAT MAY BE DUE TO COMPUTER ROUNDING ERRORS. */

L450:

    cvmax = zero;
    if (*m <= 0) {
	goto L481;
    }
    i__2 = *m;
    for (k = 1; k <= i__2; ++k) {
	ia = iwa + k;
	if (w[ia] <= zero) {
	    goto L480;
	}
	sum = -b[k];
	i__1 = *n;
	for (i = 1; i <= i__1; ++i) {
/* L460: */
	    sum += x[i] * a[k + i * a_dim1];
	}
	sumx = -sum * w[ia];
	if (k <= *meq) {
	    sumx = abs(sumx);
	}
	if (sumx <= cvmax) {
	    goto L480;
	}
	temp = (d__1 = b[k], abs(d__1));
	i__1 = *n;
	for (i = 1; i <= i__1; ++i) {
/* L470: */
	    temp += (d__1 = x[i] * a[k + i * a_dim1], abs(d__1));
	}
	tempa = temp + abs(sum);
	if (tempa <= temp) {
	    goto L480;
	}
	temp += onha * abs(sum);
	if (temp <= tempa) {
	    goto L480;
	}
	cvmax = sumx;
	res = sum;
	knext = k;
L480:
	;
    }
L481:
    i__2 = *n;
    for (k = 1; k <= i__2; ++k) {
	lower = TRUE_;
	ia = iwa + *m + k;
	if (w[ia] <= zero) {
	    goto L485;
	}
	sum = xl[k] - x[k];
	if (sum < 0.) {
	    goto L482;
	} else if (sum == 0) {
	    goto L485;
	} else {
	    goto L483;
	}
L482:
	sum = x[k] - xu[k];
	lower = FALSE_;
L483:
	if (sum <= cvmax) {
	    goto L485;
	}
	cvmax = sum;
	res = -sum;
	knext = k + *m;
	if (lower) {
	    goto L485;
	}
	knext = k + *mn;
L485:
	;
    }

/* TEST FOR CONVERGENCE */

    *info = 0;
    if (cvmax <= *vsmall) {
	goto L700;
    }

/* RETURN IF, DUE TO ROUNDING ERRORS, THE ACTUAL CHANGE IN */
/* X MAY NOT INCREASE THE OBJECTIVE FUNCTION */

    ++jfinc;
    if (jfinc == 0) {
	goto L510;
    }
    if (jfinc != ifinc) {
	goto L530;
    }
    fdiff = zero;
    fdiffa = zero;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	sum = two * grad[i];
	sumx = abs(sum);
	if (*lql) {
	    goto L489;
	}
	id = iwd + i;
	w[id] = zero;
	i__1 = *n;
	for (j = i; j <= i__1; ++j) {
	    ix = iwx + j;
/* L486: */
	    w[id] += g[i + j * g_dim1] * (w[ix] + x[j]);
	}
	i__1 = i;
	for (j = 1; j <= i__1; ++j) {
	    id = iwd + j;
	    temp = g[j + i * g_dim1] * w[id];
	    sum += temp;
/* L487: */
	    sumx += abs(temp);
	}
	goto L495;
L489:
	i__1 = *n;
	for (j = 1; j <= i__1; ++j) {
	    ix = iwx + j;
	    temp = g[i + j * g_dim1] * (w[ix] + x[j]);
	    sum += temp;
/* L490: */
	    sumx += abs(temp);
	}
L495:
	ix = iwx + i;
	fdiff += sum * (x[i] - w[ix]);
/* L500: */
	fdiffa += sumx * (d__1 = x[i] - w[ix], abs(d__1));
    }
    *info = 2;
    sum = fdiffa + fdiff;
    if (sum <= fdiffa) {
	goto L700;
    }
    temp = fdiffa + onha * fdiff;
    if (temp <= sum) {
	goto L700;
    }
    jfinc = 0;
    *info = 0;
L510:
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	ix = iwx + i;
/* L520: */
	w[ix] = x[i];
    }
/*     FORM THE SCALAR PRODUCT OF THE NEW CONSTRAINT NORMAL WITH EACH */
/*     COLUMN OF Z. PARNEW WILL BECOME THE LAGRANGE MULTIPLIER OF */
/*     THE NEW CONSTRAINT. */

L530:

    ++iterc;
    if (iterc <= *maxit) {
	goto L531;
    }
    *info = 1;
    goto L710;
L531:
    iws = iwr + (*nact + *nact * *nact) / 2;
    if (knext > *m) {
	goto L541;
    }
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	iw = iww + i;
/* L540: */
	w[iw] = a[knext + i * a_dim1];
    }
    goto L549;
L541:
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	iw = iww + i;
/* L542: */
	w[iw] = zero;
    }
    k1 = knext - *m;
    if (k1 > *n) {
	goto L545;
    }
    iw = iww + k1;
    w[iw] = one;
    iz = iwz + k1;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	is = iws + i;
	w[is] = w[iz];
/* L543: */
	iz += *n;
    }
    goto L550;
L545:
    k1 = knext - *mn;
    iw = iww + k1;
    w[iw] = -one;
    iz = iwz + k1;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	is = iws + i;
	w[is] = -w[iz];
/* L546: */
	iz += *n;
    }
    goto L550;
L549:
    kflag = 2;
    goto L930;
L550:
    parnew = zero;

/* APPLY GIVENS ROTATIONS TO MAKE THE LAST (N-NACT-2) SCALAR */
/* PRODUCTS EQUAL TO ZERO. */

    if (*nact == *n) {
	goto L570;
    }
    nu = *n;
    nflag = 1;
    goto L860;

/* BRANCH IF THERE IS NO NEED TO DELETE A CONSTRAINT. */

L560:

    is = iws + *nact;
    if (*nact == 0) {
	goto L640;
    }
    suma = zero;
    sumb = zero;
    sumc = zero;
    iz = iwz + *nact * *n;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	++iz;
	iw = iww + i;
	suma += w[iw] * w[iz];
	sumb += (d__1 = w[iw] * w[iz], abs(d__1));
/* L563: */
/* Computing 2nd power */
	d__1 = w[iz];
	sumc += d__1 * d__1;
    }
    temp = sumb + abs(suma) * .1;
    tempa = sumb + abs(suma) * .2;
    if (temp <= sumb) {
	goto L570;
    }
    if (tempa <= temp) {
	goto L570;
    }
    if (sumb > *vsmall) {
	goto L5;
    }
    goto L570;
L5:
    sumc = sqrt(sumc);
    ia = iwa + knext;
    if (knext <= *m) {
	sumc /= w[ia];
    }
    temp = sumc + abs(suma) * .1;
    tempa = sumc + abs(suma) * .2;
    if (temp <= sumc) {
	goto L567;
    }
    if (tempa <= temp) {
	goto L567;
    }
    goto L640;
/*     CALCULATE THE MULTIPLIERS FOR THE NEW CONSTRAINT NORMAL */
/*     EXPRESSED IN TERMS OF THE ACTIVE CONSTRAINT NORMALS. */
/*     THEN WORK OUT WHICH CONTRAINT TO DROP. */

L567:

    lflag = 4;
    goto L740;
L570:
    lflag = 1;
    goto L740;

/* COMPLETE THE TEST FOR LINEARLY DEPENDENT CONSTRAINTS. */

L571:

    if (knext > *m) {
	goto L574;
    }
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	suma = a[knext + i * a_dim1];
	sumb = abs(suma);
	if (*nact == 0) {
	    goto L581;
	}
	i__1 = *nact;
	for (k = 1; k <= i__1; ++k) {
	    kk = iact[k];
	    if (kk <= *m) {
		goto L568;
	    }
	    kk -= *m;
	    temp = zero;
	    if (kk == i) {
		temp = w[iww + kk];
	    }
	    kk -= *n;
	    if (kk == i) {
		temp = -w[iww + kk];
	    }
	    goto L569;
L568:
	    iw = iww + k;
	    temp = w[iw] * a[kk + i * a_dim1];
L569:
	    suma -= temp;
/* L572: */
	    sumb += abs(temp);
	}
L581:
	if (suma <= *vsmall) {
	    goto L573;
	}
	temp = sumb + abs(suma) * .1;
	tempa = sumb + abs(suma) * .2;
	if (temp <= sumb) {
	    goto L573;
	}
	if (tempa <= temp) {
	    goto L573;
	}
	goto L630;
L573:
	;
    }
    lflag = 1;
    goto L775;
L574:
    k1 = knext - *m;
    if (k1 > *n) {
	k1 -= *n;
    }
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	suma = zero;
	if (i != k1) {
	    goto L575;
	}
	suma = one;
	if (knext > *mn) {
	    suma = -one;
	}
L575:
	sumb = abs(suma);
	if (*nact == 0) {
	    goto L582;
	}
	i__1 = *nact;
	for (k = 1; k <= i__1; ++k) {
	    kk = iact[k];
	    if (kk <= *m) {
		goto L579;
	    }
	    kk -= *m;
	    temp = zero;
	    if (kk == i) {
		temp = w[iww + kk];
	    }
	    kk -= *n;
	    if (kk == i) {
		temp = -w[iww + kk];
	    }
	    goto L576;
L579:
	    iw = iww + k;
	    temp = w[iw] * a[kk + i * a_dim1];
L576:
	    suma -= temp;
/* L577: */
	    sumb += abs(temp);
	}
L582:
	temp = sumb + abs(suma) * .1;
	tempa = sumb + abs(suma) * .2;
	if (temp <= sumb) {
	    goto L578;
	}
	if (tempa <= temp) {
	    goto L578;
	}
	goto L630;
L578:
	;
    }
    lflag = 1;
    goto L775;

/* BRANCH IF THE CONTRAINTS ARE INCONSISTENT. */

L580:

    *info = -knext;
    if (kdrop == 0) {
	goto L700;
    }
    parinc = ratio;
    parnew = parinc;

/* REVISE THE LAGRANGE MULTIPLIERS OF THE ACTIVE CONSTRAINTS. */

L590:

    if (*nact == 0) {
	goto L601;
    }
    i__2 = *nact;
    for (k = 1; k <= i__2; ++k) {
	iw = iww + k;
	w[k] -= parinc * w[iw];
	if (iact[k] > *meq) {
/* Computing MAX */
	    d__1 = zero, d__2 = w[k];
	    w[k] = max(d__1,d__2);
	}
/* L600: */
    }
L601:
    if (kdrop == 0) {
	goto L680;
    }
/*     DELETE THE CONSTRAINT TO BE DROPPED. */
/*     SHIFT THE VECTOR OF SCALAR PRODUCTS. */
/*     THEN, IF APPROPRIATE, MAKE ONE MORE SCALAR PRODUCT ZERO. */
    nu = *nact + 1;
    mflag = 2;
    goto L800;
L610:
    iws = iws - *nact - 1;
    nu = min(*n,nu);
    i__2 = nu;
    for (i = 1; i <= i__2; ++i) {
	is = iws + i;
	j = is + *nact;
/* L620: */
	w[is] = w[j + 1];
    }
    nflag = 2;
    goto L860;

/* CALCULATE THE STEP TO THE VIOLATED CONSTRAINT. */

L630:

    is = iws + *nact;
L640:
    sumy = w[is + 1];
    step = -res / sumy;
    parinc = step / sumy;
    if (*nact == 0) {
	goto L660;
    }

/* CALCULATE THE CHANGES TO THE LAGRANGE MULTIPLIERS, AND REDUCE */
/* THE STEP ALONG THE NEW SEARCH DIRECTION IF NECESSARY. */

    lflag = 2;
    goto L740;
L650:
    if (kdrop == 0) {
	goto L660;
    }
    temp = one - ratio / parinc;
    if (temp <= zero) {
	kdrop = 0;
    }
    if (kdrop == 0) {
	goto L660;
    }
    step = ratio * sumy;
    parinc = ratio;
    res = temp * res;

/* UPDATE X AND THE LAGRANGE MULTIPIERS. */
/* DROP A CONSTRAINT IF THE FULL STEP IS NOT TAKEN. */

L660:

    iwy = iwz + *nact * *n;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	iy = iwy + i;
/* L670: */
	x[i] += step * w[iy];
    }
    parnew += parinc;
    if (*nact >= 1) {
	goto L590;
    }

/* ADD THE NEW CONSTRAINT TO THE ACTIVE SET. */

L680:

    ++(*nact);
    w[*nact] = parnew;
    iact[*nact] = knext;
    ia = iwa + knext;
    if (knext > *mn) {
	ia -= *n;
    }
    w[ia] = -w[ia];

/* ESTIMATE THE MAGNITUDE OF X. THEN BEGIN A NEW ITERATION, */
/* RE-INITILISING X IF THIS MAGNITUDE IS SMALL. */

    jflag = 2;
    goto L910;
L690:
    if (sum < xmagr * xmag) {
	goto L230;
    }
    if (itref <= 0) {
	goto L450;
    } else {
	goto L250;
    }

/* INITIATE ITERATIVE REFINEMENT IF IT HAS NOT YET BEEN USED, */
/* OR RETURN AFTER RESTORING THE DIAGONAL ELEMENTS OF G. */

L700:

    if (iterc == 0) {
	goto L710;
    }
    ++itref;
    jfinc = -1;
    if (itref == 1) {
	goto L250;
    }
L710:
    if (! (*lql)) {
	return 0;
    }
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	id = iwd + i;
/* L720: */
	g[i + i * g_dim1] = w[id];
    }
L730:
    return 0;

/* THE REMAINIG INSTRUCTIONS ARE USED AS SUBROUTINES. */

/* ******************************************************************** */

/* CALCULATE THE LAGRANGE MULTIPLIERS BY PRE-MULTIPLYING THE */
/* VECTOR IN THE S-PARTITION OF W BY THE INVERSE OF R. */

L740:

    ir = iwr + (*nact + *nact * *nact) / 2;
    i = *nact;
    sum = zero;
    goto L770;
L750:
    ira = ir - 1;
    sum = zero;
    if (*nact == 0) {
	goto L761;
    }
    i__2 = *nact;
    for (j = i; j <= i__2; ++j) {
	iw = iww + j;
	sum += w[ira] * w[iw];
/* L760: */
	ira += j;
    }
L761:
    ir -= i;
    --i;
L770:
    iw = iww + i;
    is = iws + i;
    w[iw] = (w[is] - sum) / w[ir];
    if (i > 1) {
	goto L750;
    }
    if (lflag == 3) {
	goto L390;
    }
    if (lflag == 4) {
	goto L571;
    }

/* CALCULATE THE NEXT CONSTRAINT TO DROP. */

L775:

    ip = iww + 1;
    ipp = iww + *nact;
    kdrop = 0;
    if (*nact == 0) {
	goto L791;
    }
    i__2 = *nact;
    for (k = 1; k <= i__2; ++k) {
	if (iact[k] <= *meq) {
	    goto L790;
	}
	iw = iww + k;
	if (res * w[iw] >= zero) {
	    goto L790;
	}
	temp = w[k] / w[iw];
	if (kdrop == 0) {
	    goto L780;
	}
	if (abs(temp) >= abs(ratio)) {
	    goto L790;
	}
L780:
	kdrop = k;
	ratio = temp;
L790:
	;
    }
L791:
    switch ((int)lflag) {
	case 1:  goto L580;
	case 2:  goto L650;
    }

/* ******************************************************************** */

/* DROP THE CONSTRAINT IN POSITION KDROP IN THE ACTIVE SET. */

L800:

    ia = iwa + iact[kdrop];
    if (iact[kdrop] > *mn) {
	ia -= *n;
    }
    w[ia] = -w[ia];
    if (kdrop == *nact) {
	goto L850;
    }

/* SET SOME INDICES AND CALCULATE THE ELEMENTS OF THE NEXT */
/* GIVENS ROTATION. */

    iz = iwz + kdrop * *n;
    ir = iwr + (kdrop + kdrop * kdrop) / 2;
L810:
    ira = ir;
    ir = ir + kdrop + 1;
/* Computing MAX */
    d__3 = (d__1 = w[ir - 1], abs(d__1)), d__4 = (d__2 = w[ir], abs(d__2));
    temp = max(d__3,d__4);
/* Computing 2nd power */
    d__1 = w[ir - 1] / temp;
/* Computing 2nd power */
    d__2 = w[ir] / temp;
    sum = temp * sqrt(d__1 * d__1 + d__2 * d__2);
    ga = w[ir - 1] / sum;
    gb = w[ir] / sum;

/* EXCHANGE THE COLUMNS OF R. */

    i__2 = kdrop;
    for (i = 1; i <= i__2; ++i) {
	++ira;
	j = ira - kdrop;
	temp = w[ira];
	w[ira] = w[j];
/* L820: */
	w[j] = temp;
    }
    w[ir] = zero;

/* APPLY THE ROTATION TO THE ROWS OF R. */

    w[j] = sum;
    ++kdrop;
    i__2 = nu;
    for (i = kdrop; i <= i__2; ++i) {
	temp = ga * w[ira] + gb * w[ira + 1];
	w[ira + 1] = ga * w[ira + 1] - gb * w[ira];
	w[ira] = temp;
/* L830: */
	ira += i;
    }

/* APPLY THE ROTATION TO THE COLUMNS OF Z. */

    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	++iz;
	j = iz - *n;
	temp = ga * w[j] + gb * w[iz];
	w[iz] = ga * w[iz] - gb * w[j];
/* L840: */
	w[j] = temp;
    }

/* REVISE IACT AND THE LAGRANGE MULTIPLIERS. */

    iact[kdrop - 1] = iact[kdrop];
    w[kdrop - 1] = w[kdrop];
    if (kdrop < *nact) {
	goto L810;
    }
L850:
    --(*nact);
    switch ((int)mflag) {
	case 1:  goto L250;
	case 2:  goto L610;
    }

/* ******************************************************************** */

/* APPLY GIVENS ROTATION TO REDUCE SOME OF THE SCALAR */
/* PRODUCTS IN THE S-PARTITION OF W TO ZERO. */

L860:

    iz = iwz + nu * *n;
L870:
    iz -= *n;
L880:
    is = iws + nu;
    --nu;
    if (nu == *nact) {
	goto L900;
    }
    if (w[is] == zero) {
	goto L870;
    }
/* Computing MAX */
    d__3 = (d__1 = w[is - 1], abs(d__1)), d__4 = (d__2 = w[is], abs(d__2));
    temp = max(d__3,d__4);
/* Computing 2nd power */
    d__1 = w[is - 1] / temp;
/* Computing 2nd power */
    d__2 = w[is] / temp;
    sum = temp * sqrt(d__1 * d__1 + d__2 * d__2);
    ga = w[is - 1] / sum;
    gb = w[is] / sum;
    w[is - 1] = sum;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	k = iz + *n;
	temp = ga * w[iz] + gb * w[k];
	w[k] = ga * w[k] - gb * w[iz];
	w[iz] = temp;
/* L890: */
	--iz;
    }
    goto L880;
L900:
    switch ((int)nflag) {
	case 1:  goto L560;
	case 2:  goto L630;
    }

/* ******************************************************************** */

/* CALCULATE THE MAGNITUDE OF X AN REVISE XMAG. */

L910:

    sum = zero;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	sum += (d__1 = x[i], abs(d__1)) * vfact * ((d__2 = grad[i], abs(d__2))
		 + (d__3 = g[i + i * g_dim1] * x[i], abs(d__3)));
	if (*lql) {
	    goto L920;
	}
	if (sum < 1e-30) {
	    goto L920;
	}
	vfact *= 1e-10;
	sum *= 1e-10;
	xmag *= 1e-10;
L920:
	;
    }
/* L925: */
    xmag = max(xmag,sum);
    switch ((int)jflag) {
	case 1:  goto L420;
	case 2:  goto L690;
    }

/* ******************************************************************** */

/* PRE-MULTIPLY THE VECTOR IN THE W-PARTITION OF W BY Z TRANSPOSE. */

L930:

    jl = iww + 1;
    iz = iwz;
    i__2 = *n;
    for (i = 1; i <= i__2; ++i) {
	is = iws + i;
	w[is] = zero;
	iwwn = iww + *n;
	i__1 = iwwn;
	for (j = jl; j <= i__1; ++j) {
	    ++iz;
/* L940: */
	    w[is] += w[iz] * w[j];
	}
    }
    switch ((int)kflag) {
	case 1:  goto L350;
	case 2:  goto L550;
    }
    return 0;
} /* ql0002_ */

#ifdef __STDC__
int ql0001_(int *m,int *me,int *mmax,int *n,int *nmax,int *mnn,
double *c,double *d,double *a,double *b,double *xl, double *xu,double *x,double *u,int *iout,int *ifail, int *iprint,double *war,int *lwar,int *iwar,int *liwar, double *eps1)
#else
/* Subroutine */
int ql0001_(m, me, mmax, n, nmax, mnn, c, d, a, b, xl, xu, x,
u, iout, ifail, iprint, war, lwar, iwar, liwar, eps1)
integer *m, *me, *mmax, *n, *nmax, *mnn;
doublereal *c, *d, *a, *b, *xl, *xu, *x, *u;
integer *iout, *ifail, *iprint;
doublereal *war;
integer *lwar, *iwar, *liwar;
doublereal *eps1;
#endif

{
    /* Format strings */

/* static char fmt_1000[] = "(/8x,\002***QL: MATRIX G WAS ENLARGED\002,i3\ */
/* ,\002-TIMES BY UNITMATRIX\002)"; */
/* static char fmt_1100[] = "(/8x,\002***QL: CONSTRAINT \002,i5,\002 NOT CO\ */
/* NSISTENT TO \002,/,(10x,10i5))"; */

/*     static char fmt_1200[] = "(/8x,\002***QL: LWAR TOO SMALL\002)"; */
/*     static char fmt_1210[] = "(/8x,\002***QL: LIWAR TOO SMALL\002)"; */
/*     static char fmt_1220[] = "(/8x,\002***QL: MNN TOO SMALL\002)"; */
/*     static char fmt_1300[] = "(/8x,\002***QL: TOO MANY ITERATIONS (MORE THA\ */

/* N\002,i6,\002)\002)"; */
/* static char fmt_1400[] = "(/8x,\002***QL: ACCURACY INSUFFICIENT TO ATTAI\ */
/* N CONVERGENCE\002)"; */

    /* System generated locals */
    integer c_dim1, c_offset, a_dim1, a_offset, i__1;

    /* Builtin functions */

/* integer s_wsfe(), do_fio(), e_wsfe(); */

    /* Local variables */
    static doublereal diag;
    /* extern int ql0002_(); */
    static integer nact, info;
    static doublereal zero;
    static integer i, j, idiag, maxit;
    static doublereal qpeps;
    static integer in, mn, lw;
    static doublereal ten;
    static logical lql;
    static integer inw1, inw2;

    /* Fortran I/O blocks */
    /*     static cilist io___16 = { 0, 0, 0, fmt_1000, 0 }; */
    /*     static cilist io___18 = { 0, 0, 0, fmt_1100, 0 }; */
    /*     static cilist io___19 = { 0, 0, 0, fmt_1200, 0 }; */
    /*     static cilist io___20 = { 0, 0, 0, fmt_1210, 0 }; */
    /*     static cilist io___21 = { 0, 0, 0, fmt_1220, 0 }; */
    /*     static cilist io___22 = { 0, 0, 0, fmt_1300, 0 }; */
    /*     static cilist io___23 = { 0, 0, 0, fmt_1400, 0 }; */

/* INTRINSIC FUNCTIONS: DSQRT */

    /* Parameter adjustments */
    --iwar;
    --war;
    --u;
    --x;
    --xu;
    --xl;
    --b;
    a_dim1 = *mmax;
    a_offset = a_dim1 + 1;
    a -= a_offset;
    --d;
    c_dim1 = *nmax;
    c_offset = c_dim1 + 1;
    c -= c_offset;

    /* Function Body */
    cmache_1.eps = *eps1;

/* CONSTANT DATA */

/* ################################################################# */

    if (fabs(c[*nmax + *nmax * c_dim1]) == 0.e0) {
	c[*nmax + *nmax * c_dim1] = cmache_1.eps;
    }

/* umd */

/*  This prevents a subsequent more major modification of the Hessian */
/*  matrix in the important case when a minmax problem (yielding a */
/*  singular Hessian matrix) is being solved. */

/* ----UMCP, April 1991, Jian L. Zhou */
/* ################################################################# */

    lql = FALSE_;
    if (iwar[1] == 1) {
	lql = TRUE_;
    }
    zero = 0.;
    ten = 10.;
    maxit = (*m + *n) * 40;
    qpeps = cmache_1.eps;
    inw1 = 1;
    inw2 = inw1 + *mmax;

/* PREPARE PROBLEM DATA FOR EXECUTION */

    if (*m <= 0) {
	goto L20;
    }
    in = inw1;
    i__1 = *m;
    for (j = 1; j <= i__1; ++j) {
	war[in] = -b[j];
/* L10: */
	++in;
    }
L20:
    lw = *nmax * 3 * *nmax / 2 + *nmax * 10 + *m;
    if (inw2 + lw > *lwar) {
	goto L80;
    }
    if (*liwar < *n) {
	goto L81;
    }
    if (*mnn < *m + *n + *n) {
	goto L82;
    }
    mn = *m + *n;

/* CALL OF QL0002 */

    ql0002_(n, m, me, mmax, &mn, mnn, nmax, &lql, &a[a_offset], &war[inw1], &
	    d[1], &c[c_offset], &xl[1], &xu[1], &x[1], &nact, &iwar[1], &
	    maxit, &qpeps, &info, &diag, &war[inw2], &lw);

/* TEST OF MATRIX CORRECTIONS */

    *ifail = 0;
    if (info == 1) {
	goto L40;
    }
    if (info == 2) {
	goto L90;
    }
    idiag = 0;
    if (diag > zero && diag < 1e3) {
	idiag = (integer) diag;
    }
/*
    if (*iprint > 0 && idiag > 0) {
	io___16.ciunit = *iout;
	s_wsfe(&io___16);
	do_fio(&c__1, (char *)&idiag, (ftnlen)sizeof(integer));
	e_wsfe();
    }
*/
    if (info < 0) {
	goto L70;
    }

/* REORDER MULTIPLIER */

    i__1 = *mnn;
    for (j = 1; j <= i__1; ++j) {
/* L50: */
	u[j] = zero;
    }
    in = inw2 - 1;
    if (nact == 0) {
	goto L30;
    }
    i__1 = nact;
    for (i = 1; i <= i__1; ++i) {
	j = iwar[i];
	u[j] = war[in + i];
/* L60: */
    }
L30:
    return 0;

/* ERROR MESSAGES */

L70:

    *ifail = -info + 10;
/*
    if (*iprint > 0 && nact > 0) {
	io___18.ciunit = *iout;
	s_wsfe(&io___18);
	i__1 = -info;
	do_fio(&c__1, (char *)&i__1, (ftnlen)sizeof(integer));
	i__2 = nact;
	for (i = 1; i <= i__2; ++i) {
	    do_fio(&c__1, (char *)&iwar[i], (ftnlen)sizeof(integer));
	}
	e_wsfe();
    }
*/
    return 0;
L80:
    *ifail = 5;
/*
    if (*iprint > 0) {
	io___19.ciunit = *iout;
	s_wsfe(&io___19);
	e_wsfe();
    }
*/
    return 0;
L81:
    *ifail = 5;
/*
    if (*iprint > 0) {
	io___20.ciunit = *iout;
	s_wsfe(&io___20);
	e_wsfe();
    }
*/
    return 0;
L82:
    *ifail = 5;
/*
    if (*iprint > 0) {
	io___21.ciunit = *iout;
	s_wsfe(&io___21);
	e_wsfe();
    }
*/
    return 0;
L40:
    *ifail = 1;
/*
    if (*iprint > 0) {
	io___22.ciunit = *iout;
	s_wsfe(&io___22);
	do_fio(&c__1, (char *)&maxit, (ftnlen)sizeof(integer));
	e_wsfe();
    }
*/
    return 0;
L90:
    *ifail = 2;
/*
    if (*iprint > 0) {
	io___23.ciunit = *iout;
	s_wsfe(&io___23);
	e_wsfe();
    }
*/
    return 0;

/* FORMAT-INSTRUCTIONS */

} /* ql0001_ */

/* umd
Two alternative definitions are provided in order to give ANSI compliance.
(Thanks got to Martin Wauchope for providing this correction) */
//#ifdef __STDC__

//#include "orcnative.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <native/types.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/timer.h>
#include <native/sem.h>
#include <native/alarm.h>
#include <native/heap.h>
#include <native/queue.h>
#include <native/syscall.h>
#define STACK_SIZE 8192
#define MIN_PRIO 1
#define MAX_PRIO 99

#include "qld.c"

typedef void * (*FUNCPTR) (void *);
typedef void * (*SOSO) (void *); /**< Special type to be used for casting in pthread_create() */
// --s-ms-us-ns
RTIME task_period_ns = 10000000000llu;
#define NSEC_PER_SEC 1000000000
#define NBCLKS 3
#define BASECLK 0.001 //seconds !!!

#define OK 0
#define ERROR -1
#define STATUS int

#define FALSE 0
#define TRUE 1
#define POLICY 1

static int ji = 0;
//static int togparport = 0;
static RTIME startime, now;// inittime, nexttime; static long long hjitter, jinc, max, moy, drift, jitter; struct timespec clock_resolution;

RT_SEM mainSem;
RT_SEM handSem;
RT_ALARM BaseClk;
int status, err2, end = 0;
//pthread_t * tid;
char *dummy;
RT_TASK thr_clockit;

///Function that returns the cpu time in nanoseconds inline long long GetCpuTime(void)
{
return (long long)rt_timer_ticks2ns(rt_timer_read());
}

// Trap Ctrl C Interruption
void clean_exit(int dummy)

{
    printf("Ctrl C Interrupt\n");
/*     printf("rt_sem_v(mainSem); \n"); */
/*     rt_sem_v(&mainSem); */
    end = 1;
    err2 = rt_task_join(&thr_clockit);
    if (err2 != 0)printf("rt_task_join() error %d \n", err2);

    printf("deleting rt devices \n");
    rt_alarm_delete(&BaseClk);
    if((err2 = rt_task_delete(&thr_clockit)) != 0)
      printf("rt_task_delete err2or %d \n", err2);
    //rt_sem_delete(&mainSem);
    return ;
}

int orcTimerSigMask(void)

{
    sigset_t set;
    sigfillset(&set);
    if ((err2 = pthread_sigmask(SIG_BLOCK, &set, NULL)) != OK)
    {
        printf("pthread_sigmask Failed %d \n", err2);
        return ERROR;
    }
    sigemptyset(&set);
    sigaddset(&set, SIGINT);
    sigaddset(&set, SIGTERM);
    if ((err2 = pthread_sigmask(SIG_UNBLOCK, &set, NULL)) != OK)
    {
        printf("pthread_sigmask Failed %d \n", err2);
        return ERROR;
    }

    return OK;
}

void setTimer(void)

{
    /***starting timer ***/
    err2 = rt_alarm_create(&BaseClk, "BaseClock");
    if (err2 != 0)printf("rt_alarm_create() error %d \n", err2);
    err2 = rt_alarm_start(&BaseClk,
			 rt_timer_ns2ticks(task_period_ns),
			 //                         1000,
                         rt_timer_ns2ticks(task_period_ns));
    if (err2 != 0)printf("rt_alarm_start() error %d \n", err2);

    else printf("alarm started with period %llu ns \n", task_period_ns);
    printf("period in ticks %ld \n", (long)rt_timer_ns2ticks(task_period_ns));
    return ;

}

//void *clock_it(void *cookie)
FUNCPTR clock_it()
{

  //int ret;
    while (!end)
    {
       rt_alarm_wait(&BaseClk);
       printf("rt_alarm_wait \n");
       gsl_qp();
    } 
    return OK;
}

int main(void)
{

    orcTimerSigMask();

    mlockall(MCL_CURRENT | MCL_FUTURE);

    signal(SIGTERM, clean_exit);
    signal(SIGINT, clean_exit);

    setTimer();
    err2 = rt_task_spawn(&thr_clockit,
                        "MyAlarmServer",
                        0,
                        MAX_PRIO,
                        T_FPU|T_JOINABLE,
                        (void *) clock_it,
                        NULL);

    if (err2 != 0) printf("rt_task_spawn error %d \n", err2);


    pause();
    fflush(NULL);

    return 0;
}
#1 lore raw
Quoted 5 lines · [email protected] wrote:
Quoted 2 lines

What kind of statistics would you precisely need? And where would you need it, means where is your scheduler located, what API does it use?

I need execution time (and not response time). A patch for this has been create by a former student (now Doctor David Robert) working before me.

Hmm, the patch looks like it consequently reimplements existing runtime statistics instead of reusing them as a foundation...

Anyway, I think we could discuss some API extension of Xenomai (for native, probably via rt_task_inquire). Likely we would keep this report optional, ie. make it return -1 or so if CONFIG_XENO_OPT_STATS is off. Tracking stats is not as costly as other instrumentations, but it's also not free. If you are interested, let us know. It won't be a one-liner, but it doesn't look like it has to be as invasive as your approach.

Quoted 2 lines

You can find it enclosed with this mail. Anyway the problem doesn't come from this patch, it appears also with vanilla xenomai.

OK.

Quoted 5 lines
Quoted 4 lines

Primarily code. We need your code that demonstrates the weird behaviour. If you patched Xenomai in any way, that patch would be required as well of course.

Quoted 7 lines

I have reduced the size of the code to the thing that is not working. You can find it enclosed.
The main program creates a task that calls the gsl_qp function (a quadratic solver).
The problem appends during the call of ql0001_. If I remove this call, it works. I if keep it, the task disapears without any error (I only see that in /proc/xenomai/stat ).

This sounds like some fault is triggered and your program simply terminates on report of the same ("Hey, if I add that printf, my program stops. What's wrong with printf?" -- You can't imagine how often I already heard this. ;) ).

Quoted 5 lines
Quoted 3 lines

BTW, did you already try to attach gdb to your disappearing process? Maybe it can catch what makes it terminate.

I have tried without success, but I don really know how to use it in that way...

You should compile it with "-g", start it with "gdb <your program>" (or the graphical front-end "ddd"), simply let it "run" and wait what gdb reports. It should really say /something/.

I can't help anyway, some files are missing, at least gsl/gsl_matrix.h. If I shall have a look, I really need a smaller test-case, only including Xenomai interaction.

Quoted 8 lines

My config: (I have install the last availlable xenomai since last mail)
- Linux kernel : 2.6.20.3
- xenomai : 2.3.1
- Adeos : 1.7-03
- Laptop compact Evo N600c Pentium 3M 1.2Ghz

Quoted 1 line

.config, Xenomai version, and I-pipe version can be helpful too.

Quoted 9 lines

.config is enclosed (DentiX231)

Quoted 1 line

Jan

Thanks for your help

Arnaud DESVAGES

Jan

#2 lore raw

[Xenomai-help] measuring tasks execution time

On Thu, 07 Jun 2007 19:44:47 +0200
Jan Kiszka <[email protected]> wrote:

Hello, opening a new thead forking from the one opened yesterday by Arnaud Desvages

Quoted 3 lines

Hmm, the patch looks like it consequently reimplements existing runtime statistics instead of reusing them as a foundation...

Yes, might be simpler now. This patch has been done in urgency upon xenomai 2.1 and was more or less sleeping since one year. It has been weakly tested, only on Pentium 3 cpus.

Quoted 6 lines

Anyway, I think we could discuss some API extension of Xenomai (for native, probably via ). Likely we would keep this report optional, ie. make it return -1 or so if CONFIG_XENO_OPT_STATS is off. Tracking stats is not as costly as other instrumentations, but it's also not free. If you are interested, let us know. It won't be a one-liner, but it doesn't look like it has to be as invasive as your approach.

Our goal is computing the accumulated cost of some selected real-time tasks to get an image of the cpu load.

What we need is a record of the accumulated execution time of the rt_tasks (not the response time, hence the instants when the task is preempted or suspended must not be counted).
This record must be accessible at any time, either from the calling task or by another one.

Our current patch only does that for tasks running in primary mode (and moreover the measure seems not correctly updated for the calling task record).

Thus we would be very happy to get an improved instrumentation api. I understand that xnstat_runtime_update() handles the measure we need? Making it available, e.g. via a rt_task_inquire call, would be great!

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
#3 lore raw

Re: [Xenomai-core] [Xenomai-help] measuring tasks execution time

Quoted 5 lines · Daniel Simon

On Thu, 07 Jun 2007 19:44:47 +0200
Jan Kiszka <[email protected]> wrote:

Hello, opening a new thead forking from the one opened yesterday by Arnaud Desvages

I moved the thread to xenomai-core, hope you don't mind.

Quoted 6 lines
Quoted 4 lines

Hmm, the patch looks like it consequently reimplements existing runtime statistics instead of reusing them as a foundation...

Yes, might be simpler now. This patch has been done in urgency upon xenomai 2.1 and was more or less sleeping since one year. It has been weakly

This explains why your changes are right below the xnstat infrastructure code...

Quoted 18 lines

tested, only on Pentium 3 cpus.

Quoted 6 lines

Anyway, I think we could discuss some API extension of Xenomai (for native, probably via ). Likely we would keep this report optional, ie. make it return -1 or so if CONFIG_XENO_OPT_STATS is off. Tracking stats is not as costly as other instrumentations, but it's also not free. If you are interested, let us know. It won't be a one-liner, but it doesn't look like it has to be as invasive as your approach.

Our goal is computing the accumulated cost of some selected real-time tasks to get an image of the cpu load.

What we need is a record of the accumulated execution time of the rt_tasks (not the response time, hence the instants when the task is preempted or suspended must not be counted).
This record must be accessible at any time, either from the calling task or by another one.

Quoted 6 lines

Our current patch only does that for tasks running in primary mode (and moreover the measure seems not correctly updated for the calling task record).

Thus we would be very happy to get an improved instrumentation api. I understand that xnstat_runtime_update() handles the measure we need?

It was designed to collect precise runtime statistics to be displayed in /proc/xenomai/stat. We would just have to keep a total counter for each task as dumping /proc resets the statistics ATM.

Quoted 1 line

Making it available, e.g. via a rt_task_inquire call, would be great!

Well, the best (==most comfortable :o) ) way from my POV would be if you could try rebasing your work on your own first. Questions, even on minor details, are always welcome, review on patches will be provided. Should be no problem to get this into Xenomai 2.4.

The rough to-do list would be:

o add some persistent runtimer counter to xnthread::stat and maintain it
o introduce an xnpod service (inline function) to obtain it (let that thing return [0..LONGLONG_MAX] when stats are available, -1 otherwise)
o export the runtime via struct rt_task_info, maybe also the task start time

Jan

#4 lore raw

Re: [Xenomai-core] [Xenomai-help] measuring tasks execution time

Quoted 8 lines · On Fri, 08 Jun 2007 13:20:11 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 5 lines · Daniel Simon

On Thu, 07 Jun 2007 19:44:47 +0200
Jan Kiszka <[email protected]> wrote:

Hello, opening a new thead forking from the one opened yesterday by Arnaud Desvages

I moved the thread to xenomai-core, hope you don't mind.

OK, I guess it is the right place

Quoted 1 line
Quoted 1 line

[...]

Quoted 37 lines
Quoted 9 lines

Our goal is computing the accumulated cost of some selected real-time tasks to get an image of the cpu load.

What we need is a record of the accumulated execution time of the rt_tasks (not the response time, hence the instants when the task is preempted or suspended must not be counted).
This record must be accessible at any time, either from the calling task or by another one.

Quoted 6 lines

Our current patch only does that for tasks running in primary mode (and moreover the measure seems not correctly updated for the calling task record).

Thus we would be very happy to get an improved instrumentation api. I understand that xnstat_runtime_update() handles the measure we need?

It was designed to collect precise runtime statistics to be displayed in /proc/xenomai/stat. We would just have to keep a total counter for each task as dumping /proc resets the statistics ATM.

Quoted 1 line

Making it available, e.g. via a rt_task_inquire call, would be great!

Well, the best (==most comfortable :o) ) way from my POV would be if you could try rebasing your work on your own first. Questions, even on minor details, are always welcome, review on patches will be provided. Should be no problem to get this into Xenomai 2.4.

The rough to-do list would be:

o add some persistent runtimer counter to xnthread::stat and maintain it
o introduce an xnpod service (inline function) to obtain it (let that thing return [0..LONGLONG_MAX] when stats are available, -1 otherwise)
o export the runtime via struct rt_task_info, maybe also the task start time

Quoted 2 lines

Jan

I am afraid that it is far beyond my own programming capabilities, and I have no longer skilled enough students at hand...
Anyway there are some highly skilled (and overloaded) engineers around, i'll try to hire one of them!
Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
#5 lore raw

Re: [Xenomai-core] [Xenomai-help] measuring tasks execution time

Quoted 48 lines · Daniel Simon
Quoted 7 lines · On Fri, 08 Jun 2007 13:20:11 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 5 lines · Daniel Simon

On Thu, 07 Jun 2007 19:44:47 +0200
Jan Kiszka <[email protected]> wrote:

Hello, opening a new thead forking from the one opened yesterday by Arnaud Desvages

I moved the thread to xenomai-core, hope you don't mind.

OK, I guess it is the right place
[...]

Quoted 35 lines
Quoted 9 lines

Our goal is computing the accumulated cost of some selected real-time tasks to get an image of the cpu load.

What we need is a record of the accumulated execution time of the rt_tasks (not the response time, hence the instants when the task is preempted or suspended must not be counted).
This record must be accessible at any time, either from the calling task or by another one.

Quoted 6 lines

Our current patch only does that for tasks running in primary mode (and moreover the measure seems not correctly updated for the calling task record).

Thus we would be very happy to get an improved instrumentation api. I understand that xnstat_runtime_update() handles the measure we need?

It was designed to collect precise runtime statistics to be displayed in /proc/xenomai/stat. We would just have to keep a total counter for each task as dumping /proc resets the statistics ATM.

Quoted 1 line

Making it available, e.g. via a rt_task_inquire call, would be great!

Well, the best (==most comfortable :o) ) way from my POV would be if you could try rebasing your work on your own first. Questions, even on minor details, are always welcome, review on patches will be provided. Should be no problem to get this into Xenomai 2.4.

The rough to-do list would be:

o add some persistent runtimer counter to xnthread::stat and maintain it
o introduce an xnpod service (inline function) to obtain it (let that thing return [0..LONGLONG_MAX] when stats are available, -1 otherwise)
o export the runtime via struct rt_task_info, maybe also the task start time

Quoted 6 lines
Quoted 2 lines

Jan

I am afraid that it is far beyond my own programming capabilities, and I have no longer skilled enough students at hand...
Anyway there are some highly skilled (and overloaded) engineers around, i'll try to hire one of them!

Any support is welcome, offers still stand!

Damn, meanwhile I started thinking about this more than I wanted. So, whoever will implement it, a few more remarks/suggestions:

- Considering the existing xnthread:stime and its usage (I didn't found a place), I would say just add another xnstat_runtime_t to xnthread::stat for life-time statistics and delete stime.

- Note that migrating life-time stats between CPUs requires rebasing the thread start time properly.

- And then I think we could also dump the life-time CPU usage based on that new data in /proc/xenomai/stat. Would be a nice test besides the native API extension... :->

Jan

#6 lore raw

Re: [Xenomai-core] [Xenomai-help] measuring tasks execution time

Quoted 3 lines · Jan Kiszka

...
- Note that migrating life-time stats between CPUs requires rebasing the thread start time properly.

Nonsense. CPU-local clocks are considered offset-free for Xenomai use.

#7 lore raw

Re: [Xenomai-core] measuring tasks execution time

In reply to Jan Kiszka

On Fri, 08 Jun 2007 13:20:11 +0200
Jan Kiszka <[email protected]> wrote:

Hello,

Quoted 7 lines

Well, the best (==most comfortable :o) ) way from my POV would be if you could try rebasing your work on your own first. Questions, even on minor details, are always welcome, review on patches will be provided. Should be no problem to get this into Xenomai 2.4.

The rough to-do list would be:

Quoted 7 lines

o add some persistent runtimer counter to xnthread::stat and maintain it
o introduce an xnpod service (inline function) to obtain it (let that thing return [0..LONGLONG_MAX] when stats are available, -1 otherwise)
o export the runtime via struct rt_task_info, maybe also the task start time

Coming back on this topic:
please find attached a first draft of a patch following (more or less) your suggestions:
-there is an additional field "exectime" in TASK_INFO, which can be set by rt_task_inquire and read in the info structure (the computation is slightly different for self and remote measurement); -xnthread_get_exectime() and xnthread_get_lastswitch() pass the values of the current thread's timing out of xn;
-exectime and lastswitch times are stored in an extended xnstat_runtime_t, updated by xnstat_runtime_update() (but not exactly like the "total" item)

it has been tested (only on P3 single core cpu) with the testexec program also attached : there are 2 periodic tasks, clockit and loop, which measure either their exectime, or the one of the other task: the measures seems reasonable, except when the clockit task measures itself, in that case the first and second printed values are always absurd for a reason I cannot understand...)

Only works in primary mode... (also I hope that the tsc is monotonic?)

I have no idea of what may happen on a smp or when on the fly migrating tasks!

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
include/native/task.h +2 -0
diff -urN xenomai-2.3.1-orig/include/native/task.h xenomai-2.3.1/include/native/task.h
@@ -91,6 +91,8 @@
     
     char name[XNOBJECT_NAME_LEN];  /**< Symbolic name assigned at creation. */
 
+    xnticks_t exectime; /**<execution time in tsc ticks since the task started. */
+
 } RT_TASK_INFO;
 
 #define RT_MCB_FSTORE_LIMIT  64
include/nucleus/stat.h +8 -0
diff -urN xenomai-2.3.1-orig/include/nucleus/stat.h xenomai-2.3.1/include/nucleus/stat.h
@@ -31,6 +31,10 @@
 
 	xnticks_t total; /* Accumulated execution time */
 
+	xnticks_t exectime; /* Overall execution time from taskspawn upto lastswitch*/
+
+	xnticks_t lastswitch; /* Last time the task was made active */
+
 } xnstat_runtime_t;
 
 /* Return current date which can be passed to other xnstat services for
@@ -42,6 +46,10 @@
 do { \
 	(sched)->current_account->total += \
 		start - (sched)->last_account_switch; \
+	(sched)->current_account->exectime += \
+                xnstat_runtime_now() - (sched)->last_account_switch; \
+	(sched)->current_account->lastswitch = \
+                xnstat_runtime_now(); \
 	(sched)->last_account_switch = start; \
 } while (0)
 
include/nucleus/thread.h +3 -1
diff -urN xenomai-2.3.1-orig/include/nucleus/thread.h xenomai-2.3.1/include/nucleus/thread.h
@@ -228,6 +228,7 @@
 
     void *cookie;		/* Cookie to pass to the entry routine */
 
+
     XNARCH_DECL_DISPLAY_CONTEXT();
 
 } xnthread_t;
@@ -277,7 +278,8 @@
 #define xnthread_user_pid(thread) \
     (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
     0 : xnarch_user_pid(xnthread_archtcb(thread)))
-
+#define xnthread_get_exectime(thread)      ((thread)->stat.account.exectime)
+#define xnthread_get_lastswitch(thread)    ((thread)->stat.account.lastswitch)
 #ifdef __cplusplus
 extern "C" {
 #endif
ksrc/nucleus/thread.c +4 -1
diff -urN xenomai-2.3.1-orig/ksrc/nucleus/thread.c xenomai-2.3.1/ksrc/nucleus/thread.c
@@ -89,7 +89,10 @@
 	thread->registry.waitkey = NULL;
 #endif /* CONFIG_XENO_OPT_REGISTRY */
 	memset(&thread->stat, 0, sizeof(thread->stat));
-
+#ifdef CONFIG_XENO_OPT_STATS
+	thread->stat.account.exectime = 0;
+	thread->stat.account.lastswitch = 0;
+#endif
 	/* These will be filled by xnpod_start_thread() */
 	thread->imask = 0;
 	thread->imode = 0;
ksrc/skins/native/task.c +18 -6
diff -urN xenomai-2.3.1-orig/ksrc/skins/native/task.c xenomai-2.3.1/ksrc/skins/native/task.c
@@ -1102,15 +1102,22 @@
 
 int rt_task_inquire(RT_TASK *task, RT_TASK_INFO *info)
 {
-	int err = 0;
-	spl_t s;
-
-	if (!task) {
+  int err = 0;
+  spl_t s;
+	/* xnprintf("1- task value ptr = %p \n", (task)); */
+	if (!task) {		
+	 /*  xnprintf("if(!task) est vrai\n"); */
 		if (!xnpod_primary_p())
 			return -EPERM;
-
 		task = xeno_current_task();
 	}
+/* 	else  */
+/* 	  { */
+/* 	     xnprintf("if(!task) est fx\n"); */
+/* 	  } */
+
+/* 	xnprintf("2- task value ptr = %p\n",(task)); */
+	
 
 	xnlock_get_irqsave(&nklock, s);
 
@@ -1126,7 +1133,12 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
-
+	if(task == xeno_current_task()){
+	  info->exectime = xnthread_get_exectime(&task->thread_base) + (xnstat_runtime_now() - xnthread_get_lastswitch(&task->thread_base));
+	  xnprintf("self inquire runtime_now %llu lastswitch %llu exectime %llu\n", (xnstat_runtime_now()), xnthread_get_lastswitch(&task->thread_base), (info->exectime));}
+	else {
+	  info->exectime = xnthread_get_exectime(&task->thread_base);
+	  xnprintf("not self %lld \n", (long long)info->exectime);}
       unlock_and_exit:
 
 	xnlock_put_irqrestore(&nklock, s);

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <native/types.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/timer.h>
#include <native/sem.h>
#include <native/alarm.h>
#include <native/heap.h>
#include <native/queue.h>
#include <native/syscall.h>
#define STACK_SIZE 8192
#define MIN_PRIO 1
#define MAX_PRIO 99
#define PRI_MT_MAX MAX_PRIO - 6
#define PRI_MT_MIN MIN_PRIO

typedef void * (*FUNCPTR) (void *);
typedef void (*SOSO) (void *); /**< Special type to be used for casting in task_create() */ #define ORCMSGQ RT_QUEUE * /**< Message Queue Type */
#define ORCSEM_ID RT_SEM * /**< Semaphore Type */
#define ORCFULL 1 /**< State of a Full Binary Semaphore */
#define ORCEMPTY 0 /**< State of a Empty Binary Semaphore */
#define ORCFOREVER TM_INFINITE /**< State of a ??? Binary Semaphore */
#define SIZE_QUEUE 100 /**< Size of the Message Queue */
#define SIZE_MES_MAX 4056 /**< Maximum size of a message in Message Queue */
#define SIZE_MES_MIN 128 /**< Minimum size of a message in Message Queue */
/*-------Tasks----------*/
#define ORCTHR_ID RT_TASK * /**< Xeno RT-Task Type */
#define STACKSIZE int /**< Stack size Type */

#define SCHED_OTHER             0
#define SCHED_FIFO              1
#define SCHED_RR                2
#define SCHEDPOLICY SCHED_FIFO  /**< Scheduling policy (see schedbits.h, sched.h )*/

#define SMALL_STACK 1000 /**< Small task stack size PTHREAD_STACK_MIN not defined */
#define NORMAL_STACK (5*SMALL_STACK) /**< Normal task stack size */
#define BIG_STACK (15*SMALL_STACK) /**< Big task stack size */
// --s-ms-us-ns
RTIME task_period_ns = 500000000llu;
#define NSEC_PER_SEC 1000000000

#define OK 0
#define ERROR -1
#define STATUS int

#define FALSE 0
#define TRUE 1
#define POLICY 1

static int ji = 0;
//static int togparport = 0;
static RTIME startime, now; // inittime, nexttime; struct timespec clock_resolution;
static int message_counter = 0;

RT_ALARM BaseClk;
int status, err, end = 0, loops = 10;

char *dummy;

ORCTHR_ID thr_clockit;
ORCTHR_ID thr_loop;
ORCMSGQ Queue;

ORCSEM_ID SynchroSem;

static int cpt_sem = 10000;
char nameSem[10];
int crexec, cr;
long past = 0;
ORCTHR_ID MAIN_RT;
/*-------Message Queues----------*/
/**
* Function to create a message queue
*
* @param
* @return ORCMSGQ pointer if message queue created, NULL otherwise and errno is set
* @see ORCMSGQ
* @see <sys/msg.h>#msgget
* @see <sys/msg.h>#msgctl
*/
ORCMSGQ orcMsgQCreate()

{
    size_t size;
    ORCMSGQ OrcQueue;
    message_counter = 0;
    size = SIZE_MES_MAX;
    int err;

    OrcQueue = malloc(sizeof(RT_QUEUE));
    if (OrcQueue == 0)
    {
        printf("ERROR  orcMsgQCreate malloc\n");
        return 0;
    }
    memset(OrcQueue, 0, sizeof(RT_QUEUE));
    if ((err = rt_queue_create(OrcQueue, "OrcRTQ", SIZE_MES_MAX*SIZE_QUEUE, SIZE_QUEUE, Q_FIFO | Q_SHARED)) != 0)
    {
      printf("orcMsgQCreate ERROR %d \n", err);
    }
    else printf("orcMsgQCreate OK\n");
    return OrcQueue;
}

/**
* Function to get the number of messages pending in a message queue
*
* @param queue pointer to the message queue
* @return long number of messages if no error occurs otherwise ERROR and errno is set
* @see <sys/msg.h>#msgctl
*/
long orcMsgQNumMsgs(ORCMSGQ queue)

{
    return (long)message_counter;
}

/**
* Function to send a message on a message queue
* Sending the message is done according to a priority level such as :
*
* @param queue pointer to the message queue
* @param msg message to be sent
* @param prio message priority level
* @return OK if successfull, ERROR otherwise and errno is set
* @see <sys/msg.h>#msgsnd
*/
int orcMsgQSend(ORCMSGQ OrcQueue, int msg, int prio)

{
    int i;
    void * tmpbuf;
    size_t orcEventSize;
    orcEventSize = (size_t)sizeof(int);
    if ((tmpbuf = rt_queue_alloc(OrcQueue, orcEventSize)) == 0)
    {
        printf("ERROR orcMsgQSend tmpbuf not created \n");
        return ERROR;
    }
    memcpy(tmpbuf, &msg, orcEventSize);
    if ((i = rt_queue_send(OrcQueue, tmpbuf, orcEventSize, Q_NORMAL)) < 0)
    {
        printf("ERROR orcMsgQSend %d \n", i);
        return ERROR;
    }
    message_counter++;
    return OK;
}

/**
* Function to receive messages on a message queue
*
* @param queue pointer to the message queue
* @param msg pointer to the received message
* @return OK if successfull, ERROR otherwise and errno is set
* @see <sys/msg.h>#msgrcv
*
*/
int orcMsgQReceive(ORCMSGQ OrcQueue, int *msg)

{
    ssize_t i;
    void *message;

    if ((i = rt_queue_receive(OrcQueue, &message, TM_INFINITE )) < 0)
    {
        printf("ERREUR orcMsgQReceive %d \n", i);
        return ERROR;
    }
    else
    {
      memcpy(msg, message, i);
        rt_queue_free(OrcQueue, message);
        message_counter--;
        return OK;
    }
}

/**
* Function to close and erase a message queue
*
* @param queue pointer to the message queue
* @return OK if successfull, ERROR otherwise and errno is set
* @see <sys/msg.h>#msgctl
*/
int orcMsgQClose(ORCMSGQ OrcQueue)

{
    int i;
    if (OrcQueue == 0)
        return ERROR;
    if ((i = rt_queue_delete(OrcQueue)) != 0)
    {
        printf("ERREUR orcMsgQClose %d \n", i);
        return ERROR;
    }

    else
    {
        free(OrcQueue);
        return OK;
    }
}

/*-------Semaphores----------*/
/**
* Function to create a semaphore
*
* @param initState semaphore initial creation state, eg ORCFULL, ORCEMPTY
* @return ORCSEM_ID semaphore pointer created if successfull, NULL otherwise
* @see ORCFULL
* @see ORCEMPTY
* @see <semaphore.h>#sem_init
*/

ORCSEM_ID orcSemCreate(int initState)

{
    ORCSEM_ID newSem;
    int status;

    sprintf(nameSem,"%d",cpt_sem);
    newSem = malloc(sizeof(RT_SEM));
    if (newSem == 0)
    {
        printf("ERROR orcSem init \n");
        return 0;
    }
    memset(newSem, 0, sizeof(RT_SEM));
    if(initState == ORCFULL)
{
        status = rt_sem_create(newSem, nameSem, initState, S_FIFO);
#ifdef DEBUG
        printf("WARNING binary Sem created FULL \n");
#endif 
}
    else
        status = rt_sem_create(newSem, nameSem, initState, S_FIFO|S_PULSE);
    if (status == OK)
    {
#ifdef DEBUG
        printf("orcSemCreate %p\n", newSem);
#endif
        cpt_sem++;
        return newSem;
    }
    else
    {
#ifdef DEBUG
        printf("orcSemCreate ERROR %d\n", status);
#endif
        return NULL;
    }
}

ORCSEM_ID orcSemCreate_count(int initState)

{
    RT_SEM * newSem;
    int status;

    sprintf(nameSem,"%d",cpt_sem);
    newSem = malloc(sizeof(RT_SEM));
    if (newSem == 0)
    {
        printf("ERROR SemCreate_count init \n");
        return 0;
    }
    memset(newSem, 0, sizeof(RT_SEM));

    status = rt_sem_create(newSem, nameSem, initState, S_FIFO);
    if (status == OK)
    {
#ifdef DEBUG
        printf("orcSemCreate_count %p\n", newSem);
#endif
        cpt_sem++;
        return newSem;
    }
    else
    {
#ifdef DEBUG
        printf("orcSemCreate ERROR %d \n", status);
#endif
        return NULL;
    }

}

/**
* Function to delete a given semaphore
*
* @param sem semaphore to be deleted
* @return sem_destroy() returned value
* @see <semaphore.h>#sem_destroy
*/
int orcSemDelete(ORCSEM_ID sem)

{
    if (sem == 0)
        return ERROR;
    if (rt_sem_delete(sem) == 0)
    {
        free(sem);
        return OK;
    }
    printf("Erreur:orcSemDelete\n");
    return ERROR;
}

/**
* Function to give a semaphore
*
* @param sem semaphore id
* @return sem_post) returned value
* @see <semaphore.h>#sem_post
*/
int orcSemGive(ORCSEM_ID sem)
{

#ifdef DEBUG
    printf("SemGive %p\n", sem);
#endif
    return (rt_sem_v(sem));
}

/**
* Function to take a semaphore
* TODO : no timeout in Posix semaphores
*
* @param sem semaphore
* @param timeout value
* @return sem_wait() returned value
* @see <semaphore.h>#sem_wait
*/
int orcSemTake(ORCSEM_ID sem, int timeout)
{

#ifdef DEBUG
    printf("SemTake %p\n", sem);
#endif
    return (rt_sem_p(sem, timeout));
}

/*-------Tasks----------*/
/**
* Function for suspending current process
* TODO : no taskDelay in Posix (sleep uses seconds, delay ?, nanosleep ?) *
* @param delay
* @return OK
*/
int orcTaskDelay(int delay)

{
    //int dummy = delay; // set to avoid compilation warnings

    return OK;
}

/// Function to set relative linux task priority
int orcScalePriority(int os_priority)

{
    if ((PRI_MT_MIN + os_priority < PRI_MT_MAX) && os_priority > 0)
        return ( PRI_MT_MIN + os_priority );
    printf("ERROR orcScalePriority, priority=%d\n", os_priority);
    return PRI_MT_MAX;
}

/**
* Function to check if a task is still valid or not *
* @param Id task identifier
* @return OK if task is valid, ERROR otherwise
* @see ORCTHR_ID
* @see pthread_kill
*/
int orcTaskIdVerify(ORCTHR_ID Id)

{
    if (Id != NULL)
    {
        return OK;
    }
    printf("orcTaskIdVerify ERROR \n");
    return ERROR;
}

/**
* Function to kill a task (pthread)
*
* @param Id task identifier
* @return ERROR or pthread_cancel returned value
* @see ORCTHR_ID
* @see <pthread.h>#pthread_kill
* @see <pthread.h>#pthread_cancel
*/
int orcTaskDelete(ORCTHR_ID task)

{
    int result;

    if (task == 0)
    {
        printf("ERROR rt_task_delete, task == 0\n");
        return ERROR;
    }
    result = rt_task_delete(task);
    if (result != 0)
    {
        printf("ERROR rt_task_delete  %p error %d\n", task, result);
        return ERROR;
    }
    //    if (result == 0)
    free(task);
    return OK;
}

/**
* Function to spawn a task
*
* @param tid task identifier
* @param name name descripting the task
* @param prio task priority level
* @param stackSize stack size to be allocated for the task
* @param funcptr routine to be spawn by the task
* @param arg argument needed for the routine to be spawn
* @return pthread_create returned value
* @see ORCTHR_ID
* @see STACKSIZE
* @see FUNCPTR
* @see <pthread.h>#pthread_create
*/
int orcSpawn(ORCTHR_ID *tid, const char *name, int prio, STACKSIZE stackSize, SOSO funcptr, void * arg)

{
    int err;

    //Allocate memory
    if (((*tid) = (RT_TASK*) malloc (sizeof(RT_TASK))) == NULL)
    {
        printf("Error malloc orcspawn\n" );
        return ERROR;
    }
    if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU|T_JOINABLE|T_CPU(0), (SOSO) funcptr, arg)) != 0)
      //if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU, (SOSO) funcptr, arg)) != 0)

    {
        printf("ERROR %d rt_task_init\n", err);
        return ERROR;
    }
    //#ifdef DEBUG
    printf("rt_task create %s prio %d StackSize %d Id %p \n", name, prio, stackSize, tid);
    //#endif
    return OK;
}
int orcSpawn1(ORCTHR_ID *tid, const char *name, int prio, STACKSIZE stackSize, SOSO funcptr, void * arg)
{
    int err;

    //Allocate memory
    if (((*tid) = (RT_TASK*) malloc (sizeof(RT_TASK))) == NULL)
    {
        printf("Error malloc orcspawn\n" );
        return ERROR;
    }
    if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU|T_JOINABLE|T_CPU(1), (SOSO) funcptr, arg)) != 0)
      //if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU, (SOSO) funcptr, arg)) != 0)

    {
        printf("ERROR %d rt_task_init\n", err);
        return ERROR;
    }
    //#ifdef DEBUG
    printf("rt_task create %s prio %d StackSize %d Id %p \n", name, prio, stackSize, tid);
    //#endif
    return OK;
}

/**
* Function to lock a task
* This function does nothing : defined for interoperability between OS needs *
* @param
* @return OK
*/
int orcTaskLock()

{
    return OK;
}

/**
* Function to unlock a task
* This function does nothing : defined for interoperability between OS needs *
* @param
* @return OK
*/
int orcTaskUnlock()

{
    return OK;
}

int orcTaskSuspend(ORCTHR_ID task)

{
    return rt_task_suspend(task);
}

///Function that returns the cpu time in nanoseconds inline long long GetCpuTime(void)

{
    return (long long)rt_timer_ticks2ns(rt_timer_read());
}

inline unsigned long long orcGetExecTime(ORCTHR_ID task) {
RT_TASK_INFO info;
crexec = rt_task_inquire(task,&info);

  if (crexec != 0){
    printf("rt_task_get_exectime error %d \n", crexec);
    return (unsigned long long)0;}

else return (unsigned long long)rt_timer_tsc2ns((SRTIME)info.exectime);
}

inline long long orcGetStartTime(ORCTHR_ID task)

{
    return (long long)0;
}

int orcMakeRealTime(void)
{

int prio_main = PRI_MT_MAX + 1;
    mlockall(MCL_CURRENT | MCL_FUTURE);
    if ((cr = rt_task_shadow(MAIN_RT, "MAIN_PRR", prio_main, T_FPU | T_JOINABLE)) != 0)
      {printf("rt_task_shadow error %d \n", cr);}
    else {printf("rt_task_shadow done priority %d \n", prio_main);}
    return cr;
}

int orcTaskJoin(ORCTHR_ID task)
{
cr = rt_task_join(task);
if (cr != 0){
printf("rt_task_join error %d on task %p \n", cr, task); return cr;}
else return OK;
}

// Trap Ctrl C Interruption
void clean_exit(int dummy)

{
    printf("Ctrl C Interrupt\n");
    end = 1;
    err = rt_task_join(thr_clockit);
    if (err != 0)printf("rt_task_join() error %d \n", err);
    err = rt_task_join(thr_loop);
    if (err != 0)printf("rt_task_join() error %d \n", err);

    printf("deleting rt devices \n");
    err = rt_alarm_delete(&BaseClk);
    if (err != 0)printf("rt_alarm_delete() error %d \n", err);

    orcMsgQClose(Queue);
    orcSemDelete(SynchroSem);
    return ;
}

int orcTimerSigMask(void)

{
    sigset_t set;
    sigfillset(&set);
    if ((err = pthread_sigmask(SIG_BLOCK, &set, NULL)) != OK)
    {
        printf("pthread_sigmask Failed %d \n", err);
        return ERROR;
    }
    sigemptyset(&set);
    sigaddset(&set, SIGINT);
    sigaddset(&set, SIGTERM);
    if ((err = pthread_sigmask(SIG_UNBLOCK, &set, NULL)) != OK)
    {
        printf("pthread_sigmask Failed %d \n", err);
        return ERROR;
    }

    return OK;
}

void setTimer(void)

{
    /***starting timer ***/
    err = rt_alarm_create(&BaseClk, "BaseClock");
    if (err != 0)printf("rt_alarm_create() error %d \n", err);
    err = rt_alarm_start(&BaseClk,
                         rt_timer_ns2ticks(task_period_ns),
                         rt_timer_ns2ticks(task_period_ns));
    if (err != 0)printf("rt_alarm_start() error %d \n", err);

    else printf("alarm started with period %llu ns \n", task_period_ns);
    printf("period in ticks %ld \n", (long)rt_timer_ns2ticks(task_period_ns));
    return ;

}

void clock_it(void)

{
    int msg = 1;    
    unsigned long long clockexectime, clockdiff;
    static unsigned long long clockpast = 0;
    while (!end)
    {
        err = rt_alarm_wait(&BaseClk);

	//rt_timer_spin((RTIME)rt_timer_ns2ticks(100000000));	
/*       clockexectime = orcGetExecTime(NULL); */
/*       if(msg > 2){ */
/*       clockdiff = clockexectime - clockpast; */
/*       clockpast  = clockexectime; */
/*       printf("clockexectime %llu clockdiff %llu \n", clockexectime, clockdiff );} */
/*       else clockpast  = clockexectime; */
            orcMsgQSend(Queue, msg, 0);
            msg++;
    }
/*     printf("clocktotal %llu clockdiffexec moyen %llu \n", clockexectime, (clockexectime/msg)); */
    return ;
}
void func_loop()
{
    int msg;
    unsigned long long loopexectime, loopdiff;
    static unsigned long long looppast;
    while (!end)
    {
      //printf("WAITING FOR MESSAGE  \n");
      orcMsgQReceive(Queue, &msg);
      printf("RECEIVED MESSAGE  \n");
      rt_timer_spin((RTIME)rt_timer_ns2ticks(100000000));
      loopexectime = orcGetExecTime(NULL);
      if(msg > 2){
	  loopdiff = loopexectime - looppast;
	  looppast  = loopexectime;
      printf("loopexectime  %llu loopdiff %llu \n", loopexectime, loopdiff );}
      else looppast  = loopexectime;
      printf("received msg = %d \n", msg);
	    }
    printf("ENDING msg = %d \n", msg); 
/*     printf("looptotal %llu loopdiffexec moyen %llu \n", loopexectime, (loopexectime/msg)); */
    printf("convert 1000 ticks = %llu ns \n", rt_timer_tsc2ns(1000));
    return;
}

int main(void)
{

    orcTimerSigMask();

    signal(SIGTERM, clean_exit);
    signal(SIGINT, clean_exit);

    orcMakeRealTime();

    setTimer();

    SynchroSem = orcSemCreate(ORCEMPTY);
    Queue = orcMsgQCreate();
    
    orcSpawn(&thr_clockit, "AlarmServer", MAX_PRIO, NORMAL_STACK, (SOSO) clock_it, NULL);
    orcSpawn(&thr_loop, "Loop", MAX_PRIO - 1, NORMAL_STACK, (SOSO) func_loop, NULL);

    pause();
    fflush(NULL);

    return 0;
}
#8 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 20 lines · Daniel Simon

On Fri, 08 Jun 2007 13:20:11 +0200
Jan Kiszka <[email protected]> wrote:

Hello,

Quoted 7 lines

Well, the best (==most comfortable :o) ) way from my POV would be if you could try rebasing your work on your own first. Questions, even on minor details, are always welcome, review on patches will be provided. Should be no problem to get this into Xenomai 2.4.

The rough to-do list would be:

Quoted 7 lines

o add some persistent runtimer counter to xnthread::stat and maintain it
o introduce an xnpod service (inline function) to obtain it (let that thing return [0..LONGLONG_MAX] when stats are available, -1 otherwise)
o export the runtime via struct rt_task_info, maybe also the task start time

Quoted 10 lines

Coming back on this topic:
please find attached a first draft of a patch following (more or less) your suggestions:
-there is an additional field "exectime" in TASK_INFO, which can be set by rt_task_inquire and read in the info structure (the computation is slightly different for self and remote measurement); -xnthread_get_exectime() and xnthread_get_lastswitch() pass the values of the current thread's timing out of xn;
-exectime and lastswitch times are stored in an extended xnstat_runtime_t, updated by xnstat_runtime_update() (but not exactly like the "total" item)

That was not my idea, and there is a reason for it, see below.

Quoted 7 lines

it has been tested (only on P3 single core cpu) with the testexec program also attached : there are 2 periodic tasks, clockit and loop, which measure either their exectime, or the one of the other task: the measures seems reasonable, except when the clockit task measures itself, in that case the first and second printed values are always absurd for a reason I cannot understand...)

A few generic wishes related to your patch:

- Please don't include debug or commented out code in your patches.

- Please avoid unrelated changes

- Please use an editor that properly formats your code, e.g. doesn't insert spaces where tabs belong according to kernel style

Quoted 2 lines

Only works in primary mode... (also I hope that the tsc is monotonic?)

Don't worry, TSC can be considered monotonic under Xenomai (that's why you have to switch off frequency scaling e.g.).

Quoted 2 lines

I have no idea of what may happen on a smp or when on the fly migrating tasks!

SMP should not be an issue, given that we rely on more or less synchronised TSCs anyway.

...

Quoted 15 lines

diff -urN xenomai-2.3.1-orig/include/nucleus/stat.h xenomai-2.3.1/include/nucleus/stat.h

include/nucleus/stat.h +4 -0
@@ -31,6 +31,10 @@
 
 	xnticks_t total; /* Accumulated execution time */
 
+	xnticks_t exectime; /* Overall execution time from taskspawn upto lastswitch*/
+
+	xnticks_t lastswitch; /* Last time the task was made active */
+
 } xnstat_runtime_t;
 
 /* Return current date which can be passed to other xnstat services for

include/nucleus/stat.h line 52

Quoted 7 lines
include/nucleus/stat.h +4 -0
@@ -42,6 +46,10 @@
 do { \
 	(sched)->current_account->total += \
 		start - (sched)->last_account_switch; \
+	(sched)->current_account->exectime += \
+                xnstat_runtime_now() - (sched)->last_account_switch; \
+	(sched)->current_account->lastswitch = \
+                xnstat_runtime_now(); \

My idea was to keep a persistent version the existing xnstat_runtime_t instance in xnthread (and later on also xnintr). That one shall not be reset on readout via /proc.

Instead, you establish quite some new calculations that break the existing API (the switch date is given via "start" - which was misnamed so far, I just changed it to "date") and increase the runtime overhead in the hotpath. Why? All the information you should need is already there, it just has to be saved from being vaporised when the user dumps /proc/xenomai/stat.

include/nucleus/stat.h line 55

Quoted 3 lines
include/nucleus/stat.h +0 -0
 	(sched)->last_account_switch = start; \
 } while (0)
 

Let's try it like this: Change Xenomai so that it leaves the existing xnthread_t::stat.account untouched when it reads /proc. Rather add something like "xnstat_runtime_t last;" to xnthread_t::stat. On readout for /proc output, do the stats now like "account-last" and then move account into last. For your task exectime, you can then read xnthread_t::stat.account directly, because it will always reflect the full task history. Would't this work better?

Thanks for working on this!

Jan

#9 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 3 lines · On Mon, 25 Jun 2007 18:55:45 +0200 Jan Kiszka <[email protected]> wrote:

My idea was to keep a persistent version the existing xnstat_runtime_t instance in xnthread (and later on also xnintr). That one shall not be reset on readout via /proc.

Is it necessary to keep also the reset one?

Quoted 3 lines

Instead, you establish quite some new calculations that break the existing API (the switch date is given via "start" - which was misnamed so far, I just changed it to "date")

ok, better fit the behaviour.
I should better work from the last svn version?

Quoted 5 lines

and increase the runtime
overhead in the hotpath. Why? All the information you should need is already there, it just has to be saved from being vaporised when the user dumps /proc/xenomai/stat.

Quoted 8 lines
Quoted 3 lines

(sched)->last_account_switch = start; \
} while (0)

Let's try it like this: Change Xenomai so that it leaves the existing xnthread_t::stat.account untouched when it reads /proc. Rather add something like "xnstat_runtime_t last;" to xnthread_t::stat. On readout for /proc output,

Where is this done? I've found one place in module::stat_seq_open where total is reset to 0, is it the only one?
In fact I don't have a clear picture of the stat
process and what it is assumed to do (and thus did not want to break something!)

Quoted 6 lines

do the stats now like "account-last" and then move
account into last. For your task exectime, you can then read xnthread_t::stat.account directly, because it will always reflect the full task history. Would't this work better?

Thanks for working on this!

I'll try to find enough time by the end of this week to improve this...

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
#10 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 9 lines · Daniel Simon
Quoted 3 lines · On Mon, 25 Jun 2007 18:55:45 +0200 Jan Kiszka <[email protected]> wrote:

My idea was to keep a persistent version the existing xnstat_runtime_t instance in xnthread (and later on also xnintr). That one shall not be reset on readout via /proc.

Is it necessary to keep also the reset one?

Yep, at least virtually (as in my proposal): We are dumping CPU share percentages in /proc, and those need to be calculated over the same measurement period. Thus we restart the measurement each time the user reads the stats.

Quoted 7 lines
Quoted 4 lines

Instead, you establish quite some new calculations that break the existing API (the switch date is given via "start" - which was misnamed so far, I just changed it to "date")

ok, better fit the behaviour.
I should better work from the last svn version?

SVN trunk would be best, indeed.

Quoted 9 lines
Quoted 9 lines

and increase the runtime
overhead in the hotpath. Why? All the information you should need is already there, it just has to be saved from being vaporised when the user dumps /proc/xenomai/stat.

Quoted 3 lines

(sched)->last_account_switch = start; \
} while (0)

Quoted 6 lines
Quoted 4 lines

Let's try it like this: Change Xenomai so that it leaves the existing xnthread_t::stat.account untouched when it reads /proc. Rather add something like "xnstat_runtime_t last;" to xnthread_t::stat. On readout for /proc output,

Where is this done? I've found one place in module::stat_seq_open where total is reset to 0, is it the only one?

That's one spot, the other is xnpod_migrate_thread() (xnstat_runtime_reset_stats()) IIRC.

Quoted 2 lines

In fact I don't have a clear picture of the stat
process and what it is assumed to do (and thus did not want to break something!)

Stat generation happens based on services that are provided by nucleus/stat.h, stat dumping is concentrated in modules.c, namely stat_seq_open. Using the cross reference [1] can help if you want to verify this on your own.

Quoted 10 lines
Quoted 6 lines

do the stats now like "account-last" and then move
account into last. For your task exectime, you can then read xnthread_t::stat.account directly, because it will always reflect the full task history. Would't this work better?

Thanks for working on this!

I'll try to find enough time by the end of this week to improve this...

Daniel

Looking forward.

Jan

[1] http://www.rts.uni-hannover.de/xenomai/lxr/source/?v=SVN-trunk

#11 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 13 lines · On Wed, 27 Jun 2007 13:56:04 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 7 lines
Quoted 3 lines · On Mon, 25 Jun 2007 18:55:45 +0200 Jan Kiszka <[email protected]> wrote:

My idea was to keep a persistent version the existing xnstat_runtime_t instance in xnthread (and later on also xnintr). That one shall not be reset on readout via /proc.

Is it necessary to keep also the reset one?

Yep, at least virtually (as in my proposal): We are dumping CPU share percentages in /proc, and those need to be calculated over the same measurement period. Thus we restart the measurement each time the user reads the stats.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Let's try it like this: Change Xenomai so that it leaves the existing xnthread_t::stat.account untouched when it reads /proc. Rather add something like " last;" to xnthread_t::stat. On readout for /proc output,

That's one spot, the other is xnpod_migrate_thread() (xnstat_runtime_reset_stats()) IIRC.

ok, i've found only these two reset points.

the account structure is also partially touched by xnstat_runtime_finalize() in pod.c, I don't understand when and why...

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

account into last. For your task exectime, you can then read xnthread_t::stat.account directly, because it will always reflect the full task history. Would't this work better?

Jan

please find attached a new patch following these ideas:
(patch against svn trunk Revision: 2672)

account is now persistent, its "start" field is the last_switch time, and the new xnstat_runtime_t "lastperiod" handles the past values necessary to compute the runtime values plot at snapshot time.

from a few trials, it seems that /proc/xenomai/stat still behaves normally (i.e. like in the original version where the first reading of stat does gives nothing for the tasks runtime?)

exectime returns likely values when a task is measured by another one, but self measurement (with the NULL task calling parameter in rt_task_inquire) sometime provides incoherent values (e.g. returns the period rather than the exectime, or returns non-monotonic exectime values...).
I could not manage to fix this bug upto now.
And unfortunately i'll be away and probably far from any xenomai-capable machine next week...

Looking forward,
Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
include/native/task.h +2 -0
diff -urN xenomai-orig/include/native/task.h xenomai/include/native/task.h
@@ -90,6 +90,8 @@
     
     char name[XNOBJECT_NAME_LEN];  /**< Symbolic name assigned at creation. */
 
+    RTIME exectime; /**<execution time in tsc ticks since the task spawned (primary mode only) */
+
 } RT_TASK_INFO;
 
 #define RT_MCB_FSTORE_LIMIT  64
include/nucleus/stat.h +1 -1
diff -urN xenomai-orig/include/nucleus/stat.h xenomai/include/nucleus/stat.h
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \
 } while (0)
 
 /* Update the current account reference, returning the previous one. */
include/nucleus/thread.h +4 -2
diff -urN xenomai-orig/include/nucleus/thread.h xenomai/include/nucleus/thread.h
@@ -204,7 +204,8 @@
 	xnstat_counter_t ssw;	/* Primary -> secondary mode switch count */
 	xnstat_counter_t csw;	/* Context switches (includes secondary -> primary switches) */
 	xnstat_counter_t pf;	/* Number of page faults */
-	xnstat_runtime_t account; /* Runtime accounting entity */
+	xnstat_runtime_t account; /* Exectime accounting entity */
+	xnstat_runtime_t lastperiod;  /* Runtime accounting entity */
     } stat;
 
     int errcode;		/* Local errno */
@@ -291,7 +292,8 @@
 #define xnthread_user_pid(thread) \
     (xnthread_test_state((thread),XNROOT) || !xnthread_user_task(thread) ? \
     0 : xnarch_user_pid(xnthread_archtcb(thread)))
-
+#define xnthread_get_exectime(thread)      ((thread)->stat.account.total)
+#define xnthread_get_lastswitch(thread)    ((thread)->stat.account.start)
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)
 {
ksrc/nucleus/module.c +4 -4
diff -urN xenomai-orig/ksrc/nucleus/module.c xenomai/ksrc/nucleus/module.c
@@ -421,16 +421,16 @@
 		stat_info->csw = xnstat_counter_get(&thread->stat.csw);
 		stat_info->pf = xnstat_counter_get(&thread->stat.pf);
 
-		period = sched->last_account_switch - thread->stat.account.start;
+		period = sched->last_account_switch - thread->stat.lastperiod.start;
 		if (!period && thread == sched->runthread) {
 			stat_info->runtime = 1;
 			stat_info->account_period = 1;
 		} else {
-			stat_info->runtime = thread->stat.account.total;
+			stat_info->runtime = thread->stat.account.total - thread->stat.lastperiod.total;
 			stat_info->account_period = period;
 		}
-		thread->stat.account.total = 0;
-		thread->stat.account.start = sched->last_account_switch;
+		thread->stat.lastperiod.total = thread->stat.account.total;
+		thread->stat.lastperiod.start = sched->last_account_switch;
 
 		holder = nextq(&nkpod->threadq, holder);
 
ksrc/nucleus/pod.c +1 -1
diff -urN xenomai-orig/ksrc/nucleus/pod.c xenomai/ksrc/nucleus/pod.c
@@ -1772,7 +1772,7 @@
 	xnpod_schedule();
 
 	/* Reset execution time stats due to unsync'ed TSCs */
-	xnstat_runtime_reset_stats(&thread->stat.account);
+	xnstat_runtime_reset_stats(&thread->stat.lastperiod);
 
       unlock_and_exit:
 
ksrc/nucleus/thread.c +6 -1
diff -urN xenomai-orig/ksrc/nucleus/thread.c xenomai/ksrc/nucleus/thread.c
@@ -97,7 +97,12 @@
 	thread->registry.waitkey = NULL;
 #endif /* CONFIG_XENO_OPT_REGISTRY */
 	memset(&thread->stat, 0, sizeof(thread->stat));
-
+#ifdef CONFIG_XENO_OPT_STATS
+	thread->stat.account.total = 0;
+	thread->stat.account.start = 0;
+	thread->stat.lastperiod.total = 0;
+	thread->stat.lastperiod.start = 0;
+#endif
 	/* These will be filled by xnpod_start_thread() */
 	thread->imask = 0;
 	thread->imode = 0;
ksrc/skins/native/task.c +4 -1
diff -urN xenomai-orig/ksrc/skins/native/task.c xenomai/ksrc/skins/native/task.c
@@ -1144,7 +1144,10 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
-
+	if(task == xeno_current_task())
+	  info->exectime = xnthread_get_exectime(&task->thread_base) + (xnstat_runtime_now() - xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnthread_get_exectime(&task->thread_base);
       unlock_and_exit:
 
 	xnlock_put_irqrestore(&nklock, s);
#12 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 20 lines · Daniel Simon
Quoted 16 lines · On Wed, 27 Jun 2007 13:56:04 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 7 lines
Quoted 3 lines · On Mon, 25 Jun 2007 18:55:45 +0200 Jan Kiszka <[email protected]> wrote:

My idea was to keep a persistent version the existing xnstat_runtime_t instance in xnthread (and later on also xnintr). That one shall not be reset on readout via /proc.

Is it necessary to keep also the reset one?

Yep, at least virtually (as in my proposal): We are dumping CPU share percentages in /proc, and those need to be calculated over the same measurement period. Thus we restart the measurement each time the user reads the stats.

Quoted 4 lines
Quoted 4 lines

Let's try it like this: Change Xenomai so that it leaves the existing xnthread_t::stat.account untouched when it reads /proc. Rather add something like " last;" to xnthread_t::stat. On readout for /proc output,

Quoted 7 lines
Quoted 2 lines

That's one spot, the other is xnpod_migrate_thread() (xnstat_runtime_reset_stats()) IIRC.

ok, i've found only these two reset points.

the account structure is also partially touched by xnstat_runtime_finalize() in pod.c, I don't understand when and why...

xnstat_runtime_finalize is called when a task passes away, i.e. you wouldn't be able to retrieve it's stats later on anyway.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

account into last. For your task exectime, you can then read xnthread_t::stat.account directly, because it will always reflect the full task history. Would't this work better?

Jan

please find attached a new patch following these ideas:
(patch against svn trunk Revision: 2672)

Quoted 7 lines

account is now persistent, its "start" field is the last_switch time, and the new xnstat_runtime_t "lastperiod" handles the past values necessary to compute the runtime values plot at snapshot time.

from a few trials, it seems that /proc/xenomai/stat still behaves normally (i.e. like in the original version where the first reading of stat does gives nothing for the tasks runtime?)

The first dump is always bogus as the task set changed since the previous measurement date (here: Xenomai start-up time).

Quoted 6 lines

exectime returns likely values when a task is measured by another one, but self measurement (with the NULL task calling parameter in rt_task_inquire) sometime provides incoherent values (e.g. returns the period rather than the exectime, or returns non-monotonic exectime values...).
I could not manage to fix this bug upto now.

I think I already see one, though it doesn't explain all your observed behaviour to me:

ksrc/skins/native/task.c line 1150

Quoted 11 lines
ksrc/skins/native/task.c +4 -1
@@ -1144,7 +1144,10 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
-
+	if(task == xeno_current_task())
+	  info->exectime = xnthread_get_exectime(&task->thread_base) + (xnstat_runtime_now() - xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnthread_get_exectime(&task->thread_base);

Exectime is only updated on task switches. So you are not obtaining the true value when requesting your own data. Use the same formula for both cases.

Quoted 3 lines

And unfortunately i'll be away and probably far from any xenomai-capable machine next week...

OK. I'll try to look into this in the meantime. But I think it should be no problem to merge a final version even after the approaching 2.4-rc1, the patch is yet fairly confined.

Jan

#13 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 2 lines · On Fri, 29 Jun 2007 17:00:39 +0200 Jan Kiszka <[email protected]> wrote:

Exectime is only updated on task switches. So you are not obtaining the true value when requesting your own data. Use the same formula for both cases.

yes, but like that the fraction of time spent in the current execution is not accounted, which might be sometimes useful (e.g. to integrate the cost of a feedback scheduler in the total control budget)

another potentially useful feature would be also accounting the execution time spent in secondary mode... no idea on how to do that.
BTW, Posix defines an optional CLOCK_THREAD_CPUTIME which is assumed to provide this measure ?

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
#14 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 6 lines · Daniel Simon
Quoted 2 lines · On Fri, 29 Jun 2007 17:00:39 +0200 Jan Kiszka <[email protected]> wrote:

Exectime is only updated on task switches. So you are not obtaining the true value when requesting your own data. Use the same formula for both cases.

Quoted 6 lines

yes, but like that the fraction of time spent in the current execution is not accounted, which might be sometimes useful (e.g. to integrate the cost of a feedback scheduler in the total control budget)

another potentially useful feature would be also accounting the execution time spent in secondary mode... no idea on how to do that.

Xenomai-wise, secondary mode starts for an emerging thread in xnshadow_map(), then stops when exiting xnshadow_harden(), then resumes when exiting xnshadow_relax(). All routines are defined in nucleus/shadow.c.

Quoted 5 lines

BTW, Posix defines an optional CLOCK_THREAD_CPUTIME which is assumed to provide this measure ?

Daniel

Signature · 1 line
Philippe.
#15 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 11 lines · Philippe Gerum
Quoted 10 lines · Daniel Simon
Quoted 2 lines · On Fri, 29 Jun 2007 17:00:39 +0200 Jan Kiszka <[email protected]> wrote:

Exectime is only updated on task switches. So you are not obtaining the true value when requesting your own data. Use the same formula for both cases.

yes, but like that the fraction of time spent in the current execution is not accounted, which might be sometimes useful (e.g. to integrate the cost of a feedback scheduler in the total control budget)

Quoted 7 lines
Quoted 2 lines

another potentially useful feature would be also accounting the execution time spent in secondary mode... no idea on how to do that.

Xenomai-wise, secondary mode starts for an emerging thread in xnshadow_map(), then stops when exiting xnshadow_harden(), then resumes when exiting xnshadow_relax(). All routines are defined in nucleus/shadow.c.

Additionnaly when a task is suspended by Linux, the function do_schedule_event is triggered by Adeos.

Signature · 1 line
                                              Gilles Chanteperdrix
#16 lore raw

Re: [Xenomai-core] measuring tasks execution time

In reply to Daniel Simon
Quoted 9 lines · Daniel Simon
Quoted 2 lines · On Fri, 29 Jun 2007 17:00:39 +0200 Jan Kiszka <[email protected]> wrote:

Exectime is only updated on task switches. So you are not obtaining the true value when requesting your own data. Use the same formula for both cases.

yes, but like that the fraction of time spent in the current execution is not accounted, which might be sometimes useful (e.g. to integrate the cost of a feedback scheduler in the total control budget)

Yeah, true, I applied the inverse logic. However, this interface is inconsistent, one should expects the same algorithm applied on both local as well as remote task queries. Why do you differentiate?

Quoted 5 lines

another potentially useful feature would be also accounting the execution time spent in secondary mode... no idea on how to do that.
BTW, Posix defines an optional CLOCK_THREAD_CPUTIME which is assumed to provide this measure ?

This should work for shadow threads to retrieve their secondary-mode runtime. Give it a try.

Jan

#17 lore raw

Re: [Xenomai-core] measuring tasks execution time

In reply to Daniel Simon
Quoted 3 lines · Daniel Simon

please find attached a new patch following these ideas:
(patch against svn trunk Revision: 2672)

Based on this version, I integrated your patch into my patch stack. The actual rt_task_inquire interface is totally untested, but the rest appears to cause no regressions here. See

http://www.rts.uni-hannover.de/rtaddon/patches/xenomai

namely the enhance-thread-stats.patch. It may depend on some of the previous patches in the stack, but only organisationally, not technically.

You are welcome to test, fix, improve, or just use it. Looking forward to your feedback!

Jan

#18 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 2 lines · On Sun, 08 Jul 2007 12:11:56 +0200 Jan Kiszka <[email protected]> wrote:

You are welcome to test, fix, improve, or just use it. Looking forward to your feedback!

Thanks, I'll try it this week

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
#19 lore raw

Re: [Xenomai-core] measuring tasks execution time

In reply to Jan Kiszka

On Sun, 08 Jul 2007 12:11:56 +0200
Jan Kiszka <[email protected]> wrote:

Hello,

Quoted 2 lines

You are welcome to test, fix, improve, or just use it. Looking forward to your feedback!

here are attached some corrections against your previous patch (itself against #2758 files): from my tests I now get likely exectime values from both remote and self measurement (i.e. we get the accumulated exectime at the instant we call rt_task_inquire ), and the stats given in /proc still seem to behave normally...

the full patch against the original 2758 version is also given in attachement

Looking forward to your feedback...

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
include/nucleus/stat.h +5 -1
diff -urN xenomai-2758/include/nucleus/stat.h xenomai-2758-V2/include/nucleus/stat.h
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \
 	/* All changes must be committed before changing the current_account \
 	   reference in sched (required for xnintr_sync_stat_references) */ \
 	xnarch_memory_barrier(); \
@@ -71,6 +71,9 @@
 #define xnstat_runtime_get_start(account)	((account)->start)
 #define xnstat_runtime_get_total(account)	((account)->total)
 
+/* Obtain last time something has been switched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -113,6 +116,7 @@
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
 #define xnstat_runtime_get_start(account)			({ 0; })
 #define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
 typedef struct xnstat_counter {
include/nucleus/thread.h +1 -1
diff -urN xenomai-2758/include/nucleus/thread.h xenomai-2758-V2/include/nucleus/thread.h
@@ -294,7 +294,7 @@
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
 #define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
-#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_start(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)
 
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)
ksrc/skins/native/task.c +3 -0
diff -urN xenomai-2758/ksrc/skins/native/task.c xenomai-2758-V2/ksrc/skins/native/task.c
@@ -1144,10 +1144,13 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if(task == xeno_current_task())
 	info->exectime = xnarch_tsc_to_ns(
 		xnthread_get_exectime(&task->thread_base) +
 		xnstat_runtime_now() -
 		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));
 	info->modeswitches = xnstat_counter_get(&task->thread_base.stat.ssw);
 	info->ctxswitches = xnstat_counter_get(&task->thread_base.stat.csw);
 	info->pagefaults = xnstat_counter_get(&task->thread_base.stat.pf);
include/native/task.h +8 -0
diff -urN xenomai/include/native/task.h xenomai-2758-V2/include/native/task.h
@@ -90,6 +90,14 @@
     
     char name[XNOBJECT_NAME_LEN];  /**< Symbolic name assigned at creation. */
 
+    RTIME exectime; /**< Execution time in primary mode in nanoseconds. */
+
+    int modeswitches; /**< Number of primary->secondary mode switches. */
+
+    int ctxswitches; /**< Number of context switches. */
+
+    int pagefaults; /**< Number of triggered page faults. */
+
 } RT_TASK_INFO;
 
 #define RT_MCB_FSTORE_LIMIT  64
include/nucleus/stat.h +12 -2
diff -urN xenomai/include/nucleus/stat.h xenomai-2758-V2/include/nucleus/stat.h
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \
 	/* All changes must be committed before changing the current_account \
 	   reference in sched (required for xnintr_sync_stat_references) */ \
 	xnarch_memory_barrier(); \
@@ -67,6 +67,13 @@
 	(sched)->current_account = (new_account); \
 } while (0)
 
+/* Obtain content of xnstat_runtime_t */
+#define xnstat_runtime_get_start(account)	((account)->start)
+#define xnstat_runtime_get_total(account)	((account)->total)
+
+/* Obtain last time something has been switched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -104,9 +111,12 @@
 
 #define xnstat_runtime_now()					({ 0; })
 #define xnstat_runtime_update(sched, date)			do { } while (0)
-#define xnstat_runtime_set_current(sched, new_account)	({ (void)sched; NULL; })
+#define xnstat_runtime_set_current(sched, new_account)		({ (void)sched; NULL; })
 #define xnstat_runtime_get_current(sched)			({ (void)sched; NULL; })
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
+#define xnstat_runtime_get_start(account)			({ 0; })
+#define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
 typedef struct xnstat_counter {
include/nucleus/thread.h +4 -3
diff -urN xenomai/include/nucleus/thread.h xenomai-2758-V2/include/nucleus/thread.h
@@ -205,7 +205,8 @@
 	xnstat_counter_t ssw;	/* Primary -> secondary mode switch count */
 	xnstat_counter_t csw;	/* Context switches (includes secondary -> primary switches) */
 	xnstat_counter_t pf;	/* Number of page faults */
-	xnstat_runtime_t account; /* Runtime accounting entity */
+	xnstat_runtime_t account; /* Execution time accounting entity */
+	xnstat_runtime_t lastperiod; /* Interval marker for execution time reports */
     } stat;
 
     int errcode;		/* Local errno */
@@ -235,8 +236,6 @@
 
     char name[XNOBJECT_NAME_LEN]; /* Symbolic name of thread */
 
-    xnticks_t stime;		/* Start time */
-
     void (*entry)(void *cookie); /* Thread entry routine */
 
     void *cookie;		/* Cookie to pass to the entry routine */
@@ -294,6 +293,8 @@
     0 : xnarch_user_pid(xnthread_archtcb(thread)))
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
+#define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)
 
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)
ksrc/nucleus/module.c +5 -4
diff -urN xenomai/ksrc/nucleus/module.c xenomai-2758-V2/ksrc/nucleus/module.c
@@ -421,16 +421,17 @@
 		stat_info->csw = xnstat_counter_get(&thread->stat.csw);
 		stat_info->pf = xnstat_counter_get(&thread->stat.pf);
 
-		period = sched->last_account_switch - thread->stat.account.start;
+		period = sched->last_account_switch - thread->stat.lastperiod.start;
 		if (!period && thread == sched->runthread) {
 			stat_info->runtime = 1;
 			stat_info->account_period = 1;
 		} else {
-			stat_info->runtime = thread->stat.account.total;
+			stat_info->runtime = thread->stat.account.total -
+				thread->stat.lastperiod.total;
 			stat_info->account_period = period;
 		}
-		thread->stat.account.total = 0;
-		thread->stat.account.start = sched->last_account_switch;
+		thread->stat.lastperiod.total = thread->stat.account.total;
+		thread->stat.lastperiod.start = sched->last_account_switch;
 
 		holder = nextq(&nkpod->threadq, holder);
 
ksrc/nucleus/pod.c +3 -3
diff -urN xenomai/ksrc/nucleus/pod.c xenomai-2758-V2/ksrc/nucleus/pod.c
@@ -832,7 +832,6 @@
 	thread->imode = (mode & XNTHREAD_MODE_BITS);
 	thread->entry = entry;
 	thread->cookie = cookie;
-	thread->stime = xnarch_get_cpu_time();
 
 	if (xnthread_test_state(thread, XNRRB))
 		thread->rrcredit = thread->rrperiod;
@@ -1781,8 +1780,9 @@
 
 	xnpod_schedule();
 
-	/* Reset execution time stats due to unsync'ed TSCs */
-	xnstat_runtime_reset_stats(&thread->stat.account);
+	/* Reset execution time measurement period so that we don't mess up
+	   per-CPU statistics. */
+	xnstat_runtime_reset_stats(&thread->stat.lastperiod);
 
       unlock_and_exit:
 
ksrc/nucleus/thread.c +0 -1
diff -urN xenomai/ksrc/nucleus/thread.c xenomai-2758-V2/ksrc/nucleus/thread.c
@@ -103,7 +103,6 @@
 	thread->imode = 0;
 	thread->entry = NULL;
 	thread->cookie = 0;
-	thread->stime = 0;
 	thread->ops = ops;
 
 	inith(&thread->glink);
ksrc/skins/native/task.c +10 -0
diff -urN xenomai/ksrc/skins/native/task.c xenomai-2758-V2/ksrc/skins/native/task.c
@@ -1144,6 +1144,16 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if(task == xeno_current_task())
+	info->exectime = xnarch_tsc_to_ns(
+		xnthread_get_exectime(&task->thread_base) +
+		xnstat_runtime_now() -
+		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));
+	info->modeswitches = xnstat_counter_get(&task->thread_base.stat.ssw);
+	info->ctxswitches = xnstat_counter_get(&task->thread_base.stat.csw);
+	info->pagefaults = xnstat_counter_get(&task->thread_base.stat.pf);
 
       unlock_and_exit:
 
#20 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 7 lines · Daniel Simon

On Sun, 08 Jul 2007 12:11:56 +0200
Jan Kiszka <[email protected]> wrote:

Hello,

Quoted 2 lines

You are welcome to test, fix, improve, or just use it. Looking forward to your feedback!

Quoted 7 lines

here are attached some corrections against your previous patch (itself against #2758 files): from my tests I now get likely exectime values from both remote and self measurement (i.e. we get the accumulated exectime at the instant we call rt_task_inquire ), and the stats given in /proc still seem to behave normally...

the full patch against the original 2758 version is also given in attachement

To check if I got it the first attachment is an add-on patch, the second one is the base patch as in my repos + the former add-on patch?

Then let's comment on the add-on:

include/nucleus/stat.h line 45

Quoted 9 lines

diff -urN xenomai-2758/include/nucleus/stat.h xenomai-2758-V2/include/nucleus/stat.h

include/nucleus/stat.h +1 -1
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \

That looks bogus on first sight, but I might miss your intention. current_account points to the overall stats of an accounted entity. Therefore, start must always contain the start time, not the last switch time. Please explain your idea.

include/nucleus/stat.h line 76

Quoted 10 lines
include/nucleus/stat.h +3 -0
 	/* All changes must be committed before changing the current_account \
 	   reference in sched (required for xnintr_sync_stat_references) */ \
 	xnarch_memory_barrier(); \
@@ -71,6 +71,9 @@
 #define xnstat_runtime_get_start(account)	((account)->start)
 #define xnstat_runtime_get_total(account)	((account)->total)
 
+/* Obtain last time something has been switched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+

OK (though a more precise comment would be good :))

Quoted 15 lines
include/nucleus/stat.h +1 -0
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -113,6 +116,7 @@
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
 #define xnstat_runtime_get_start(account)			({ 0; })
 #define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
 typedef struct xnstat_counter {

diff -urN xenomai-2758/include/nucleus/thread.h xenomai-2758-V2/include/nucleus/thread.h

include/nucleus/thread.h line 297

Quoted 5 lines
include/nucleus/thread.h +1 -1
@@ -294,7 +294,7 @@
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
 #define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
-#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_start(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)

Yeah, that was wrong. Did your first patch hunk relate to an initial attempt to fix this bug?

Quoted 7 lines
include/nucleus/thread.h +0 -0
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)

diff -urN xenomai-2758/ksrc/skins/native/task.c xenomai-2758-V2/ksrc/skins/native/task.c

ksrc/skins/native/task.c line 1153

Quoted 10 lines
ksrc/skins/native/task.c +3 -0
@@ -1144,10 +1144,13 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if(task == xeno_current_task())
 	info->exectime = xnarch_tsc_to_ns(
 		xnthread_get_exectime(&task->thread_base) +
 		xnstat_runtime_now() -
 		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));

OK, second bug taken. But you approach was written without SMP in mind (while I thought too much about SMP). The correct condition is "task is running, somewhere?":

if (task->thread_base.sched->runthread == &task->thread_base)
<exectime up to now>
else
<currently stored exectime>

Of course, one may still optimise the expression.

ksrc/skins/native/task.c line 1156

Quoted 5 lines
ksrc/skins/native/task.c +0 -0
 	info->modeswitches = xnstat_counter_get(&task->thread_base.stat.ssw);
 	info->ctxswitches = xnstat_counter_get(&task->thread_base.stat.csw);
 	info->pagefaults = xnstat_counter_get(&task->thread_base.stat.pf);

Jan

#21 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 14 lines · On Wed, 11 Jul 2007 16:30:03 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 13 lines · Daniel Simon

On Sun, 08 Jul 2007 12:11:56 +0200
Jan Kiszka <[email protected]> wrote:

Hello,

Quoted 2 lines

You are welcome to test, fix, improve, or just use it. Looking forward to your feedback!

here are attached some corrections against your previous patch (itself against #2758 files): from my tests I now get likely exectime values from both remote and self measurement (i.e. we get the accumulated exectime at the instant we call rt_task_inquire ), and the stats given in /proc still seem to behave normally...

Quoted 4 lines
Quoted 1 line

the full patch against the original 2758 version is also given in attachement

To check if I got it the first attachment is an add-on patch, the second one is the base patch as in my repos + the former add-on patch?

yes

Quoted 16 lines

Then let's comment on the add-on:

include/nucleus/stat.h line 45

Quoted 9 lines

diff -urN xenomai-2758/include/nucleus/stat.h xenomai-2758-V2/include/nucleus/stat.h

include/nucleus/stat.h +1 -1
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \

That looks bogus on first sight, but I might miss your intention. current_account points to the overall stats of an accounted entity. Therefore, start must always contain the start time, not the last switch time. Please explain your idea.

sorry, I forgot to delete this attempt to correct a former bug, it's useless now, line 45 in stat.h remains as in your original patch

	(sched)->last_account_switch = date; \

just tested, the exectime measure still works...

Quoted 7 lines
Quoted 7 lines
include/nucleus/stat.h +0 -0
 	/* All changes must be committed before changing the current_account \
 	   reference in sched (required for xnintr_sync_stat_references) */ \
 	xnarch_memory_barrier(); \
@@ -71,6 +71,9 @@
 #define xnstat_runtime_get_start(account)	((account)->start)
 #define xnstat_runtime_get_total(account)	((account)->total)
 
Quoted 6 lines

include/nucleus/stat.h line 76

Quoted 3 lines
include/nucleus/stat.h +3 -0
+/* Obtain last time something has been switched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+

OK (though a more precise comment would be good :))

/* Get the last time the calling thread was switched active */

may be better, but it could be also an intr. handler, isn't?

Quoted 10 lines
Quoted 10 lines
include/nucleus/stat.h +1 -0
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -113,6 +116,7 @@
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
 #define xnstat_runtime_get_start(account)			({ 0; })
 #define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
Quoted 14 lines

include/nucleus/thread.h line 297

Quoted 10 lines
include/nucleus/stat.h +0 -0
 typedef struct xnstat_counter {

diff -urN xenomai-2758/include/nucleus/thread.h xenomai-2758-V2/include/nucleus/thread.h

include/nucleus/thread.h +1 -1
@@ -294,7 +294,7 @@
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
 #define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
-#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_start(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)

Yeah, that was wrong. Did your first patch hunk relate to an initial attempt to fix this bug?

yes, it was made to cancel an extra period in the measure

Quoted 22 lines
Quoted 7 lines
include/nucleus/thread.h +0 -0
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)

diff -urN xenomai-2758/ksrc/skins/native/task.c xenomai-2758-V2/ksrc/skins/native/task.c

ksrc/skins/native/task.c line 1153

Quoted 10 lines
ksrc/skins/native/task.c +3 -0
@@ -1144,10 +1144,13 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if(task == xeno_current_task())
 	info->exectime = xnarch_tsc_to_ns(
 		xnthread_get_exectime(&task->thread_base) +
 		xnstat_runtime_now() -
 		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));

OK, second bug taken. But you approach was written without SMP in mind (while I thought too much about SMP). The correct condition is "task is running, somewhere?":

Quoted 4 lines

if (task->thread_base.sched->runthread == &task->thread_base)
<exectime up to now>
else
<currently stored exectime>

Can I leave you handling (and testing) this correction, as I don't have a running Xenomai/SMP machine at hand?

Quoted 11 lines

Of course, one may still optimise the expression.

ksrc/skins/native/task.c line 1156

Quoted 5 lines
ksrc/skins/native/task.c +0 -0
 	info->modeswitches = xnstat_counter_get(&task->thread_base.stat.ssw);
 	info->ctxswitches = xnstat_counter_get(&task->thread_base.stat.csw);
 	info->pagefaults = xnstat_counter_get(&task->thread_base.stat.pf);

Jan

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
#22 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 49 lines · Daniel Simon
Quoted 13 lines · On Wed, 11 Jul 2007 16:30:03 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 12 lines · Daniel Simon

On Sun, 08 Jul 2007 12:11:56 +0200
Jan Kiszka <[email protected]> wrote:

Hello,

Quoted 2 lines

You are welcome to test, fix, improve, or just use it. Looking forward to your feedback!

here are attached some corrections against your previous patch (itself against #2758 files): from my tests I now get likely exectime values from both remote and self measurement (i.e. we get the accumulated exectime at the instant we call rt_task_inquire ), and the stats given in /proc still seem to behave normally...

Quoted 3 lines
Quoted 1 line

the full patch against the original 2758 version is also given in attachement

To check if I got it the first attachment is an add-on patch, the second one is the base patch as in my repos + the former add-on patch?

yes

Quoted 15 lines

Then let's comment on the add-on:

include/nucleus/stat.h line 45

Quoted 9 lines

diff -urN xenomai-2758/include/nucleus/stat.h xenomai-2758-V2/include/nucleus/stat.h

include/nucleus/stat.h +1 -1
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \

That looks bogus on first sight, but I might miss your intention. current_account points to the overall stats of an accounted entity. Therefore, start must always contain the start time, not the last switch time. Please explain your idea.

sorry, I forgot to delete this attempt to correct a former bug, it's useless now, line 45 in stat.h remains as in your original patch

	(sched)->last_account_switch = date; \

just tested, the exectime measure still works...

Quoted 7 lines
Quoted 7 lines
include/nucleus/stat.h +0 -0
 	/* All changes must be committed before changing the current_account \
 	   reference in sched (required for xnintr_sync_stat_references) */ \
 	xnarch_memory_barrier(); \
@@ -71,6 +71,9 @@
 #define xnstat_runtime_get_start(account)	((account)->start)
 #define xnstat_runtime_get_total(account)	((account)->total)
 
Quoted 8 lines
Quoted 5 lines

include/nucleus/stat.h line 76

Quoted 3 lines
include/nucleus/stat.h +3 -0
+/* Obtain last time something has been switched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+

OK (though a more precise comment would be good :))

/* Get the last time the calling thread was switched active */

may be better, but it could be also an intr. handler, isn't?

Yep, we have executable entities here (threads and interrupt handlers) that have an exectime account. And that account is switched.

"Get last account switch date on given sched", or so.

Quoted 46 lines
Quoted 11 lines
Quoted 11 lines
include/nucleus/stat.h +1 -0
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -113,6 +116,7 @@
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
 #define xnstat_runtime_get_start(account)			({ 0; })
 #define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
Quoted 13 lines

include/nucleus/thread.h line 297

Quoted 10 lines
include/nucleus/stat.h +0 -0
 typedef struct xnstat_counter {

diff -urN xenomai-2758/include/nucleus/thread.h xenomai-2758-V2/include/nucleus/thread.h

include/nucleus/thread.h +1 -1
@@ -294,7 +294,7 @@
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
 #define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
-#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_start(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)

Yeah, that was wrong. Did your first patch hunk relate to an initial attempt to fix this bug?

yes, it was made to cancel an extra period in the measure

Quoted 21 lines
Quoted 7 lines
include/nucleus/thread.h +0 -0
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)

diff -urN xenomai-2758/ksrc/skins/native/task.c xenomai-2758-V2/ksrc/skins/native/task.c

ksrc/skins/native/task.c line 1153

Quoted 10 lines
ksrc/skins/native/task.c +3 -0
@@ -1144,10 +1144,13 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if(task == xeno_current_task())
 	info->exectime = xnarch_tsc_to_ns(
 		xnthread_get_exectime(&task->thread_base) +
 		xnstat_runtime_now() -
 		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));

OK, second bug taken. But you approach was written without SMP in mind (while I thought too much about SMP). The correct condition is "task is running, somewhere?":

Quoted 6 lines
Quoted 4 lines

if (task->thread_base.sched->runthread == &task->thread_base)
<exectime up to now>
else
<currently stored exectime>

Can I leave you handling (and testing) this correction, as I don't have a running Xenomai/SMP machine at hand?

Let's find a compromise: I will try to role out -v2 of this patch with your fixes soon. And you will try to do the in-depth tests of exectime reporting once you have a Xenomai box again? Hacking is cheap, testing takes the time... :) Or does the test code you once submitted report clear results /wrt the correctness of the exectime data?

Jan

#23 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 5 lines · On Wed, 11 Jul 2007 17:56:09 +0200 Jan Kiszka <[email protected]> wrote:

Let's find a compromise: I will try to role out -v2 of this patch with your fixes soon. And you will try to do the in-depth tests of exectime reporting once you have a Xenomai box again? Hacking is cheap, testing takes the time... :) Or does the test code you once submitted report clear results /wrt the correctness of the exectime data?

What I mean is that I can perform tests _only on a Pentium3 UP_, and on this machine I upto now get consistent results on the basic tests using the last fixes (and I will do further testing with various applications).

I cannot (and will not be able in a previsible future) perform tests neither on a SMP nor on not_i386 architectures...

In attachment:
the full exectime-V2.patch (including all the fixes we discussed today) against a vanilla 2758 release, which compiled and behaves well on my basic examples and UP machine. (it also patches with no hunk against last release 2764),
and the add-on against your original patch (I don't know what
is the easiest way for you...)

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/
include/native/task.h +8 -0
diff -urN xenomai/include/native/task.h xenomai-2758-V2/include/native/task.h
@@ -90,6 +90,14 @@
     
     char name[XNOBJECT_NAME_LEN];  /**< Symbolic name assigned at creation. */
 
+    RTIME exectime; /**< Execution time in primary mode in nanoseconds. */
+
+    int modeswitches; /**< Number of primary->secondary mode switches. */
+
+    int ctxswitches; /**< Number of context switches. */
+
+    int pagefaults; /**< Number of triggered page faults. */
+
 } RT_TASK_INFO;
 
 #define RT_MCB_FSTORE_LIMIT  64
include/nucleus/stat.h +12 -2
diff -urN xenomai/include/nucleus/stat.h xenomai-2758-V2/include/nucleus/stat.h
@@ -42,7 +42,7 @@
 do { \
 	(sched)->current_account->total += \
 		date - (sched)->last_account_switch; \
-	(sched)->last_account_switch = date; \
+	(sched)->last_account_switch = (sched)->current_account->start = date; \
 	/* All changes must be committed before changing the current_account \
 	   reference in sched (required for xnintr_sync_stat_references) */ \
 	xnarch_memory_barrier(); \
@@ -67,6 +67,13 @@
 	(sched)->current_account = (new_account); \
 } while (0)
 
+/* Obtain content of xnstat_runtime_t */
+#define xnstat_runtime_get_start(account)	((account)->start)
+#define xnstat_runtime_get_total(account)	((account)->total)
+
+/* Obtain last time something has been switched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -104,9 +111,12 @@
 
 #define xnstat_runtime_now()					({ 0; })
 #define xnstat_runtime_update(sched, date)			do { } while (0)
-#define xnstat_runtime_set_current(sched, new_account)	({ (void)sched; NULL; })
+#define xnstat_runtime_set_current(sched, new_account)		({ (void)sched; NULL; })
 #define xnstat_runtime_get_current(sched)			({ (void)sched; NULL; })
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
+#define xnstat_runtime_get_start(account)			({ 0; })
+#define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
 typedef struct xnstat_counter {
include/nucleus/thread.h +4 -3
diff -urN xenomai/include/nucleus/thread.h xenomai-2758-V2/include/nucleus/thread.h
@@ -205,7 +205,8 @@
 	xnstat_counter_t ssw;	/* Primary -> secondary mode switch count */
 	xnstat_counter_t csw;	/* Context switches (includes secondary -> primary switches) */
 	xnstat_counter_t pf;	/* Number of page faults */
-	xnstat_runtime_t account; /* Runtime accounting entity */
+	xnstat_runtime_t account; /* Execution time accounting entity */
+	xnstat_runtime_t lastperiod; /* Interval marker for execution time reports */
     } stat;
 
     int errcode;		/* Local errno */
@@ -235,8 +236,6 @@
 
     char name[XNOBJECT_NAME_LEN]; /* Symbolic name of thread */
 
-    xnticks_t stime;		/* Start time */
-
     void (*entry)(void *cookie); /* Thread entry routine */
 
     void *cookie;		/* Cookie to pass to the entry routine */
@@ -294,6 +293,8 @@
     0 : xnarch_user_pid(xnthread_archtcb(thread)))
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
+#define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)
 
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)
ksrc/nucleus/module.c +5 -4
diff -urN xenomai/ksrc/nucleus/module.c xenomai-2758-V2/ksrc/nucleus/module.c
@@ -421,16 +421,17 @@
 		stat_info->csw = xnstat_counter_get(&thread->stat.csw);
 		stat_info->pf = xnstat_counter_get(&thread->stat.pf);
 
-		period = sched->last_account_switch - thread->stat.account.start;
+		period = sched->last_account_switch - thread->stat.lastperiod.start;
 		if (!period && thread == sched->runthread) {
 			stat_info->runtime = 1;
 			stat_info->account_period = 1;
 		} else {
-			stat_info->runtime = thread->stat.account.total;
+			stat_info->runtime = thread->stat.account.total -
+				thread->stat.lastperiod.total;
 			stat_info->account_period = period;
 		}
-		thread->stat.account.total = 0;
-		thread->stat.account.start = sched->last_account_switch;
+		thread->stat.lastperiod.total = thread->stat.account.total;
+		thread->stat.lastperiod.start = sched->last_account_switch;
 
 		holder = nextq(&nkpod->threadq, holder);
 
ksrc/nucleus/pod.c +3 -3
diff -urN xenomai/ksrc/nucleus/pod.c xenomai-2758-V2/ksrc/nucleus/pod.c
@@ -832,7 +832,6 @@
 	thread->imode = (mode & XNTHREAD_MODE_BITS);
 	thread->entry = entry;
 	thread->cookie = cookie;
-	thread->stime = xnarch_get_cpu_time();
 
 	if (xnthread_test_state(thread, XNRRB))
 		thread->rrcredit = thread->rrperiod;
@@ -1781,8 +1780,9 @@
 
 	xnpod_schedule();
 
-	/* Reset execution time stats due to unsync'ed TSCs */
-	xnstat_runtime_reset_stats(&thread->stat.account);
+	/* Reset execution time measurement period so that we don't mess up
+	   per-CPU statistics. */
+	xnstat_runtime_reset_stats(&thread->stat.lastperiod);
 
       unlock_and_exit:
 
ksrc/nucleus/thread.c +0 -1
diff -urN xenomai/ksrc/nucleus/thread.c xenomai-2758-V2/ksrc/nucleus/thread.c
@@ -103,7 +103,6 @@
 	thread->imode = 0;
 	thread->entry = NULL;
 	thread->cookie = 0;
-	thread->stime = 0;
 	thread->ops = ops;
 
 	inith(&thread->glink);
ksrc/skins/native/task.c +10 -0
diff -urN xenomai/ksrc/skins/native/task.c xenomai-2758-V2/ksrc/skins/native/task.c
@@ -1144,6 +1144,16 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if(task == xeno_current_task())
+	info->exectime = xnarch_tsc_to_ns(
+		xnthread_get_exectime(&task->thread_base) +
+		xnstat_runtime_now() -
+		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));
+	info->modeswitches = xnstat_counter_get(&task->thread_base.stat.ssw);
+	info->ctxswitches = xnstat_counter_get(&task->thread_base.stat.csw);
+	info->pagefaults = xnstat_counter_get(&task->thread_base.stat.pf);
 
       unlock_and_exit:
 
include/nucleus/stat.h +4 -0
diff -urN xenomai-2758/include/nucleus/stat.h xenomai-exectime-V2/include/nucleus/stat.h
@@ -71,6 +71,9 @@
 #define xnstat_runtime_get_start(account)	((account)->start)
 #define xnstat_runtime_get_total(account)	((account)->total)
 
+/*Get last account switch date on considered sched */
+#define xnstat_runtime_get_last_switch(sched)	((sched)->last_account_switch)
+
 /* Reset statistics from inside the accounted entity (e.g. after CPU
    migration). */
 #define xnstat_runtime_reset_stats(stat) \
@@ -113,6 +116,7 @@
 #define xnstat_runtime_finalize(sched, new_account)		do { } while (0)
 #define xnstat_runtime_get_start(account)			({ 0; })
 #define xnstat_runtime_get_total(account)			({ 0; })
+#define xnstat_runtime_get_last_switch(sched)			({ 0; })
 #define xnstat_runtime_reset_stats(account)			do { } while (0)
 
 typedef struct xnstat_counter {
include/nucleus/thread.h +1 -1
diff -urN xenomai-2758/include/nucleus/thread.h xenomai-exectime-V2/include/nucleus/thread.h
@@ -294,7 +294,7 @@
 #define xnthread_affinity(thread)          ((thread)->affinity)
 #define xnthread_affine_p(thread, cpu)     xnarch_cpu_isset(cpu, (thread)->affinity)
 #define xnthread_get_exectime(thread)      xnstat_runtime_get_total(&(thread)->stat.account)
-#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_start(&(thread)->stat.account)
+#define xnthread_get_lastswitch(thread)    xnstat_runtime_get_last_switch((thread)->sched)
 
 /* Class-level operations for threads. */
 static inline int xnthread_get_denormalized_prio(xnthread_t *t)
ksrc/skins/native/task.c +3 -0
diff -urN xenomai-2758/ksrc/skins/native/task.c xenomai-exectime-V2/ksrc/skins/native/task.c
@@ -1144,10 +1144,13 @@
 	info->cprio = xnthread_current_priority(&task->thread_base);
 	info->status = xnthread_state_flags(&task->thread_base);
 	info->relpoint = xntimer_get_date(&task->thread_base.ptimer);
+	if (task->thread_base.sched->runthread == &task->thread_base)
 	info->exectime = xnarch_tsc_to_ns(
 		xnthread_get_exectime(&task->thread_base) +
 		xnstat_runtime_now() -
 		xnthread_get_lastswitch(&task->thread_base));
+	else 
+	  info->exectime = xnarch_tsc_to_ns(xnthread_get_exectime(&task->thread_base));
 	info->modeswitches = xnstat_counter_get(&task->thread_base.stat.ssw);
 	info->ctxswitches = xnstat_counter_get(&task->thread_base.stat.csw);
 	info->pagefaults = xnstat_counter_get(&task->thread_base.stat.pf);
#24 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 9 lines · Daniel Simon
Quoted 5 lines · On Wed, 11 Jul 2007 17:56:09 +0200 Jan Kiszka <[email protected]> wrote:

Let's find a compromise: I will try to role out -v2 of this patch with your fixes soon. And you will try to do the in-depth tests of exectime reporting once you have a Xenomai box again? Hacking is cheap, testing takes the time... :) Or does the test code you once submitted report clear results /wrt the correctness of the exectime data?

Quoted 3 lines

What I mean is that I can perform tests _only on a Pentium3 UP_, and on this machine I upto now get consistent results on the basic tests using the last fixes (and I will do further testing with various applications).

Ah, ok, /me should have read more thoroughly.

Quoted 4 lines

I cannot (and will not be able in a previsible future) perform tests neither on a SMP nor on not_i386 architectures...

Quoted 8 lines

In attachment:
the full exectime-V2.patch (including all the fixes we discussed today) against a vanilla 2758 release, which compiled and behaves well on my basic examples and UP machine. (it also patches with no hunk against last release 2764),
and the add-on against your original patch (I don't know what
is the easiest way for you...)

I've merge you changes (whitespaces...), reformatted it a bit, and uploaded the result. See

http://www.rts.uni-hannover.de/rtaddon/patches/xenomai/enhance-thread-stats-v2.patch

Hope I didn't messed anything up, it was just compile-tested in a hurry. If the patch happens to work fine, I would start advertising it for merge into trunk.

Jan

#25 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 1 line · On Wed, 11 Jul 2007 23:20:47 +0200 Jan Kiszka <[email protected]> wrote:

I've merge you changes (whitespaces...)

sorry for bad formatting, my dev. tool is emacs, which sometimes refuse to understand tabs...

Quoted 1 line

http://www.rts.uni-hannover.de/rtaddon/patches/xenomai/enhance-thread-stats-v2.patch

this patch seems ok:
-patched against release 2764 (with 2 self-corrected hunks), compiled on a 2.6.20 kernel and test on a P3/UP

-my former basic tests (2 periodic tasks providing remote or self
exectime probing) still give consistent measures (exectime.c in attachment)

-I am thinking about more demanding tests, with intertasks preemption and overloads, but in that case the problem is how to assess the measurements? Logic analyzer? Be care also with rt_timer_spin, which is not busy-sleeping for all the specified time when it is preempted...

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <signal.h>
#include <math.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <native/types.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/timer.h>
#include <native/sem.h>
#include <native/alarm.h>
#include <native/heap.h>
#include <native/queue.h>
#include <native/syscall.h>
#define STACK_SIZE 8192
#define MIN_PRIO 1
#define MAX_PRIO 99
#define PRI_MT_MAX MAX_PRIO - 6
#define PRI_MT_MIN MIN_PRIO

typedef void * (*FUNCPTR) (void *);
typedef void (*SOSO) (void *); /**< Special type to be used for casting in task_create() */ #define ORCMSGQ RT_QUEUE * /**< Message Queue Type */
#define ORCSEM_ID RT_SEM * /**< Semaphore Type */
#define ORCFULL 1 /**< State of a Full Binary Semaphore */
#define ORCEMPTY 0 /**< State of a Empty Binary Semaphore */
#define ORCFOREVER TM_INFINITE /**< Waiting forever in sem_wait */
#define SIZE_QUEUE 100 /**< Size of the Message Queue */
#define SIZE_MES_MAX 4056 /**< Maximum size of a message in Message Queue */
#define SIZE_MES_MIN 128 /**< Minimum size of a message in Message Queue */
/*-------Tasks----------*/
#define ORCTHR_ID RT_TASK * /**< Xeno RT-Task Type */
#define STACKSIZE int /**< Stack size Type */
#define SMALL_STACK 1000 /**< Small task stack size PTHREAD_STACK_MIN not defined */
#define NORMAL_STACK (5*SMALL_STACK) /**< Normal task stack size */
#define BIG_STACK (15*SMALL_STACK) /**< Big task stack size */
// --s-ms-us-ns
RTIME task_period_ns = 500000000llu;
#define NSEC_PER_SEC 1000000000

#define OK 0
#define ERROR -1
#define STATUS int

#define FALSE 0
#define TRUE 1
#define POLICY 1

static int ji = 0;
static RTIME startime, now;
struct timespec clock_resolution;
static int message_counter = 0;

RT_ALARM BaseClk;
int status, err, end = 0, loops = 10;

char *dummy;

ORCTHR_ID thr_clockit;
ORCTHR_ID thr_loop;
ORCMSGQ Queue;

ORCSEM_ID SynchroSem;

static int cpt_sem = 10000;
char nameSem[10];
int crexec, cr;
long past = 0;
ORCTHR_ID MAIN_RT;

ORCMSGQ orcMsgQCreate()

{
        size_t size;
        ORCMSGQ OrcQueue;
        message_counter = 0;
        size = SIZE_MES_MAX;
        int err;

        OrcQueue = malloc(sizeof(RT_QUEUE));
        if (OrcQueue == 0) {
                printf("ERROR  orcMsgQCreate malloc\n");
                return 0;
        }
        memset(OrcQueue, 0, sizeof(RT_QUEUE));
        if ((err = rt_queue_create(OrcQueue, "OrcRTQ", SIZE_MES_MAX*SIZE_QUEUE, SIZE_QUEUE, Q_FIFO | Q_SHARED)) != 0) {
                printf("orcMsgQCreate ERROR %d \n", err);
        } else printf("orcMsgQCreate OK\n");
        return OrcQueue;
}

int orcMsgQSend(ORCMSGQ OrcQueue, int msg, int prio)

{
        int i;
        void * tmpbuf;
        size_t orcEventSize;
        orcEventSize = (size_t)sizeof(int);
        if ((tmpbuf = rt_queue_alloc(OrcQueue, orcEventSize)) == 0) {
                printf("ERROR orcMsgQSend tmpbuf not created \n");
                return ERROR;
        }
        memcpy(tmpbuf, &msg, orcEventSize);
        if ((i = rt_queue_send(OrcQueue, tmpbuf, orcEventSize, Q_NORMAL)) < 0) {
                printf("ERROR orcMsgQSend %d \n", i);
                return ERROR;
        }
        message_counter++;
        return OK;
}

int orcMsgQReceive(ORCMSGQ OrcQueue, int *msg)

{
        ssize_t i;
        void *message;

        if ((i = rt_queue_receive(OrcQueue, &message, TM_INFINITE )) < 0) {
                printf("ERREUR orcMsgQReceive %d \n", i);
                return ERROR;
        } else {
                memcpy(msg, message, i);
                rt_queue_free(OrcQueue, message);
                message_counter--;
                return OK;
        }
}

int orcMsgQClose(ORCMSGQ OrcQueue)

{
        int i;
        if (OrcQueue == 0)
                return ERROR;
        if ((i = rt_queue_delete(OrcQueue)) != 0) {
                printf("ERREUR orcMsgQClose %d \n", i);
                return ERROR;
        }

        else {
                free(OrcQueue);
                return OK;
        }
}

ORCSEM_ID orcSemCreate(int initState)

{
        RT_SEM * newSem;
        int status;

        sprintf(nameSem,"%d",cpt_sem);
        newSem = malloc(sizeof(RT_SEM));
        if (newSem == 0) {
                printf("ERROR SemCreate_count init \n");
                return 0;
        }
        memset(newSem, 0, sizeof(RT_SEM));

        status = rt_sem_create(newSem, nameSem, initState, S_FIFO);
        if (status == OK) {
                cpt_sem++;
                return newSem;
        } else {
                return NULL;
        }

}

int orcSemDelete(ORCSEM_ID sem)

{
        if (sem == 0)
                return ERROR;
        if (rt_sem_delete(sem) == 0) {
                free(sem);
                return OK;
        }
        printf("Erreur:orcSemDelete\n");
        return ERROR;
}

int orcSemGive(ORCSEM_ID sem)

{
        return (rt_sem_v(sem));
}

int orcSemTake(ORCSEM_ID sem, int timeout)

{
        return (rt_sem_p(sem, timeout));
}

int orcTaskIdVerify(ORCTHR_ID Id)

{
        if (Id != NULL) {
                return OK;
        }
        printf("orcTaskIdVerify ERROR \n");
        return ERROR;
}

int orcTaskDelete(ORCTHR_ID task)

{
        int result;

        if (task == 0) {
                printf("ERROR rt_task_delete, task == 0\n");
                return ERROR;
        }
        result = rt_task_delete(task);
        if (result != 0) {
                printf("ERROR rt_task_delete  %p error %d\n", task, result);
                return ERROR;
        }
        free(task);
        return OK;
}

int orcSpawn(ORCTHR_ID *tid, const char *name, int prio, STACKSIZE stackSize, SOSO funcptr, void * arg)

{
        int err;
        //Allocate memory
        if (((*tid) = (RT_TASK*) malloc (sizeof(RT_TASK))) == NULL) {
                printf("Error malloc orcspawn\n" );
                return ERROR;
        }
        if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU|T_JOINABLE|T_CPU(0), (SOSO) funcptr, arg)) != 0) {
                printf("ERROR %d rt_task_init\n", err);
                return ERROR;
        }
        printf("rt_task create %s prio %d StackSize %d Id %p \n", name, prio, stackSize, tid);
        return OK;
}
int orcSpawn1(ORCTHR_ID *tid, const char *name, int prio, STACKSIZE stackSize, SOSO funcptr, void * arg)
{
        int err;
        //Allocate memory
        if (((*tid) = (RT_TASK*) malloc (sizeof(RT_TASK))) == NULL) {
                printf("Error malloc orcspawn\n" );
                return ERROR;
        }
        if ((err = rt_task_spawn(*tid, name, stackSize, prio, T_FPU|T_JOINABLE|T_CPU(1), (SOSO) funcptr, arg)) != 0) {
                printf("ERROR %d rt_task_init\n", err);
                return ERROR;
        }
        printf("rt_task create %s prio %d StackSize %d Id %p \n", name, prio, stackSize, tid);
        return OK;
}

int orcTaskSuspend(ORCTHR_ID task)

{
        return rt_task_suspend(task);
}

///Function that returns the cpu time in nanoseconds inline long long GetCpuTime(void)

{
        return (long long)rt_timer_ticks2ns(rt_timer_read());
}
///Function that returns the task accumulated excectime in nanoseconds
inline long long orcGetExecTime(ORCTHR_ID task)
{
        RT_TASK_INFO info;
        crexec = rt_task_inquire(task,&info);
        if (crexec != 0) {
                printf("rt_task_get_exectime error %d \n", crexec);
                return (long long)0;
        } else return (long long)info.exectime;
}
///Function that shadows main in real time
int orcMakeRealTime(void)
{
        int prio_main = PRI_MT_MAX + 1;
        mlockall(MCL_CURRENT | MCL_FUTURE);
        if ((cr = rt_task_shadow(MAIN_RT, "MAIN_PRR", prio_main, T_FPU | T_JOINABLE)) != 0) {
                printf("rt_task_shadow error %d \n", cr);
        } else {
                printf("rt_task_shadow done priority %d \n", prio_main);
        }
        return cr;
}

// Traps Ctrl C Interruption
void clean_exit(int dummy)

{
        printf("Ctrl C Interrupt\n");
        end = 1;
        err = rt_task_join(thr_clockit);
        if (err != 0)printf("rt_task_join() error %d \n", err);
        err = rt_task_join(thr_loop);
        if (err != 0)printf("rt_task_join() error %d \n", err);
        printf("deleting rt devices \n");
        err = rt_alarm_delete(&BaseClk);
        if (err != 0)printf("rt_alarm_delete() error %d \n", err);
        orcMsgQClose(Queue);
        return ;
}
/// Masking all signals but SIGINT and SIGTERM
int orcTimerSigMask(void)
{
        sigset_t set;
        sigfillset(&set);
        if ((err = pthread_sigmask(SIG_BLOCK, &set, NULL)) != OK) {
                printf("pthread_sigmask Failed %d \n", err);
                return ERROR;
        }
        sigemptyset(&set);
        sigaddset(&set, SIGINT);
        sigaddset(&set, SIGTERM);
        if ((err = pthread_sigmask(SIG_UNBLOCK, &set, NULL)) != OK) {
                printf("pthread_sigmask Failed %d \n", err);
                return ERROR;
        }

        return OK;
}

void setTimer(void)

{
        /***starting timer ***/
        err = rt_alarm_create(&BaseClk, "BaseClock");
        if (err != 0)printf("rt_alarm_create() error %d \n", err);
        err = rt_alarm_start(&BaseClk,
                             rt_timer_ns2ticks(task_period_ns),
                             rt_timer_ns2ticks(task_period_ns));
        if (err != 0)printf("rt_alarm_start() error %d \n", err);

        else printf("alarm started with period %llu ns \n", task_period_ns);
        printf("period in ticks %ld \n", (long)rt_timer_ns2ticks(task_period_ns));
        return ;

}
long long loopbusytime, clockbusytime;
void clock_it(void)

{
        int msg = 1;

        long long clockexectime, clockdiff;
        static long long clockpast = 0;
        while (!end) {
                err = rt_alarm_wait(&BaseClk);
                clockbusytime = llabs(30000000*(cos((double)GetCpuTime()/NSEC_PER_SEC)));
                //clockbusytime = 30000000;
                rt_timer_spin((RTIME)clockbusytime);
                clockexectime = orcGetExecTime(NULL);
                /*       clockexectime = orcGetExecTime(thr_loop); */
                if (msg > 2) {
                        clockdiff = clockexectime - clockpast;
                        clockpast  = clockexectime;
			/*clockdiff should me busytime + a handfull of usecs, be carefull to print the busytime of the measured task!!!*/
                        printf("clockexectime %lld clockdiff %lld  busytime %lld \n", clockexectime, clockdiff, clockbusytime );
                } else clockpast  = clockexectime;

                orcMsgQSend(Queue, msg, 0);
                msg++;
        }
        return ;
}
void func_loop()
{
        int msg;
        long long loopexectime, loopdiff;
        static long long looppast;
        while (!end) {
                orcMsgQReceive(Queue, &msg);
                loopbusytime = llabs(20000000*(cos((double)GetCpuTime()/NSEC_PER_SEC)));
                //loopbusytime = 20000000;
                rt_timer_spin((RTIME)loopbusytime);
                /*       loopexectime = orcGetExecTime(thr_clockit); */
                /*       loopexectime = orcGetExecTime(NULL); */
                /*       if(msg > 2){ */
                /* 	  loopdiff = loopexectime - looppast; */
                /* 	  looppast  = loopexectime; */
		/*clockdiff should me busytime + a handfull of usecs, be carefull to print the busytime of the measured task!!!*/
                /* 	  printf("loopexectime  %lld loopdiff %lld busytime %lld \n", loopexectime, loopdiff, loopbusytime );} */
                /*       else looppast  = loopexectime; */
                printf("received msg = %d \n", msg);
        }
        return;
}

int main(void)
{

        orcTimerSigMask();

        signal(SIGTERM, clean_exit);
        signal(SIGINT, clean_exit);

        orcMakeRealTime();

        setTimer();

        Queue = orcMsgQCreate();

        orcSpawn(&thr_clockit, "AlarmServer", MAX_PRIO -2, NORMAL_STACK, (SOSO) clock_it, NULL);
        orcSpawn(&thr_loop, "Loop", MAX_PRIO - 3, NORMAL_STACK, (SOSO) func_loop, NULL);

        pause();
        fflush(NULL);

        return 0;
}
#26 lore raw

Re: [Xenomai-core] measuring tasks execution time

Quoted 7 lines · Daniel Simon
Quoted 1 line · On Wed, 11 Jul 2007 23:20:47 +0200 Jan Kiszka <[email protected]> wrote:

I've merge you changes (whitespaces...)

sorry for bad formatting, my dev. tool is emacs, which sometimes refuse to understand tabs...

Quoted 8 lines
Quoted 1 line

http://www.rts.uni-hannover.de/rtaddon/patches/xenomai/enhance-thread-stats-v2.patch

this patch seems ok:
-patched against release 2764 (with 2 self-corrected hunks), compiled on a 2.6.20 kernel and test on a P3/UP

-my former basic tests (2 periodic tasks providing remote or self
exectime probing) still give consistent measures (exectime.c in attachment)

Nice to hear.

Quoted 5 lines

-I am thinking about more demanding tests, with intertasks preemption and overloads, but in that case the problem is how to assess the measurements? Logic analyzer? Be care also with rt_timer_spin, which is not busy-sleeping for all the specified time when it is preempted...

You could play with the I-pipe tracer
(http://xenomai.org/index.php/I-pipe:Tracer). If you disable function tracing (CONFIG_IPIPE_TRACE_MCOUNT), you will be left with far less overwhelming data, specifically with the instrumentation points on every Xenomai context switch. That should allow some estimation of the thread execution times (minus noise due to the IRQs). And then there is highly experimental LTTng, but it's... well, highly experimental.

Jan

#27 lore raw

Re: [Xenomai-core] measuring tasks execution time

On Thu, 12 Jul 2007 13:02:35 +0200
Jan Kiszka <[email protected]> wrote:

Hi Jan,

Quoted 2 lines
Quoted 2 lines

-I am thinking about more demanding tests, with intertasks preemption and overloads,

I have shaked my examples in various ways, with
preemptions, overruns and high load on the machine, and the exectime patch behaves well, providing data consistent with the expectations (and with the rt_timer_read() probe when usable).

Daniel

Signature · 5 lines
       Daniel SIMON    Projet NeCS  INRIA Rhone-Alpes
        Inovallee, 655 avenue de l'Europe, Montbonnot
             38 334 Saint Ismier Cedex France
 [email protected] Phone:(33)476615328 Fax:(33)476615252
          http://necs.inrialpes.fr/people/simon/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#29 lore raw
Quoted 79 lines · [email protected] wrote:
Quoted 8 lines
Quoted 4 lines · [email protected] wrote:
Quoted 2 lines

What kind of statistics would you precisely need? And where would you need it, means where is your scheduler located, what API does it use?

I need execution time (and not response time). A patch for this has been create by a former student (now Doctor David Robert) working before me.

Hmm, the patch looks like it consequently reimplements existing runtime statistics instead of reusing them as a foundation...

Quoted 6 lines

Anyway, I think we could discuss some API extension of Xenomai (for native, probably via rt_task_inquire). Likely we would keep this report optional, ie. make it return -1 or so if CONFIG_XENO_OPT_STATS is off. Tracking stats is not as costly as other instrumentations, but it's also not free. If you are interested, let us know. It won't be a one-liner, but it doesn't look like it has to be as invasive as your approach.

It can be interesting to have something like that. My tutor will probably explain better than me what could be the best. I let him open a new topic on this patch.

Quoted 23 lines
Quoted 2 lines

You can find it enclosed with this mail. Anyway the problem doesn't come from this patch, it appears also with vanilla xenomai.

OK.

Quoted 4 lines
Quoted 4 lines

Primarily code. We need your code that demonstrates the weird behaviour.
If you patched Xenomai in any way, that patch would be required as well of course.

Quoted 10 lines

I have reduced the size of the code to the thing that is not working. You
can find it enclosed.
The main program creates a task that calls the gsl_qp function (a quadratic solver).
The problem appends during the call of ql0001_. If I remove this call, it
works. I if keep it, the task disapears without any error (I only see that
in /proc/xenomai/stat ).

This sounds like some fault is triggered and your program simply terminates on report of the same ("Hey, if I add that printf, my program stops. What's wrong with printf?" -- You can't imagine how often I already heard this. ;) ).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

BTW, did you already try to attach gdb to your disappearing process? Maybe it can catch what makes it terminate.

I have tried without success, but I don really know how to use it in that
way...

You should compile it with "-g", start it with "gdb <your program>" (or the graphical front-end "ddd"), simply let it "run" and wait what gdb reports. It should really say /something/.

Yes I only know how to use ddd in fact, and the -g flag is used at compile time. And with ddd, no bug is found... I don't catch anything. The problem only appears when I launch the program in console mode.
The thing I didn't really know how to use id the attach command of gdb, that I have read on the web it can catch errors on program launched from outside gdb. Am I wrong ?

Quoted 4 lines

I can't help anyway, some files are missing, at least gsl/gsl_matrix.h. If I shall have a look, I really need a smaller test-case, only including Xenomai interaction.

It's a mistake, I forgot to remove this unuseful include line. I have tried to reduce the program at the minimum (some heap data allocation with random values, and a call to the optimizer function that cause the termination of the task). Normally you can remove this include, and there will only stay xenomai calls...

Quoted 10 lines
Quoted 10 lines

My config: (I have install the last availlable xenomai since last mail)
- Linux kernel : 2.6.20.3
- xenomai : 2.3.1
- Adeos : 1.7-03
- Laptop compact Evo N600c Pentium 3M 1.2Ghz

Quoted 1 line

.config, Xenomai version, and I-pipe version can be helpful too.

.config is enclosed (DentiX231)

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

Jan

Thanks for your help

Arnaud DESVAGES

Jan

Hope these new information will help to solve it.

From my kernel console after running your program for a few seconds:

Xenomai: watchdog triggered -- killing runaway thread 'MyAlarmServer'

Previously, "rt_alarm_wait" was printed on the console, thus gsl_qp() likely entered some infinite loop. You have the watchdog enabled as well, so you should see the same effect, right?

Jan

#30 lore raw
Quoted 10 lines

From my kernel console after running your program for a few seconds:

Xenomai: watchdog triggered -- killing runaway thread 'MyAlarmServer'

Previously, "rt_alarm_wait" was printed on the console, thus gsl_qp() likely entered some infinite loop. You have the watchdog enabled as well, so you should see the same effect, right?

Jan

In my console, I only see the "rt_alarm_wait". Is there something to activate to enable xenomai errors messages ?

As this gsl_qp() function takes about 6/7 secondes to solve my quadratic problem, the watchdog could effectively be the thing that goes wrong...

To be sure to understand how works the watchdog in xenomai:
- Is it a limit on the execution time (so time effectively used by the task)
- or is it a limit on the response time (the time between the beginning and the end of the task, even if it is preempted) ?

Because, if it is the first case, maybe that putting the gsl_qp() function in primary mode increases the execution time measured by xenomai, and this activate the watchdog ? whereas in secondary mode, time is not counted by xenomai watchdog ?

I will try to increase the watchdog time to see if this is only a matter of a task taking to much time.

Thanks a lot for your help !

Arnaud DESVAGES

#31 lore raw
Quoted 4 lines · [email protected] wrote:
Quoted 4 lines

From my kernel console after running your program for a few seconds:

Xenomai: watchdog triggered -- killing runaway thread 'MyAlarmServer'

Quoted 8 lines
Quoted 5 lines

Previously, "rt_alarm_wait" was printed on the console, thus gsl_qp() likely entered some infinite loop. You have the watchdog enabled as well, so you should see the same effect, right?

Jan

In my console, I only see the "rt_alarm_wait". Is there something to activate to enable xenomai errors messages ?

Not local console, _kernel console_. Check your systems log files (eg. /var/log/syslog or .../messages), or run "dmesg" to see the last kernel messages.

Quoted 3 lines

As this gsl_qp() function takes about 6/7 secondes to solve my quadratic problem, the watchdog could effectively be the thing that goes wrong...

Well, don't blame others until you are sure (== you measured) that it is not your own code. :)

Quoted 5 lines

To be sure to understand how works the watchdog in xenomai:
- Is it a limit on the execution time (so time effectively used by the task)
- or is it a limit on the response time (the time between the beginning and the end of the task, even if it is preempted) ?

See documentation. Linux must be able to run at least once in _4_ seconds.

Quoted 5 lines

Because, if it is the first case, maybe that putting the gsl_qp() function in primary mode increases the execution time measured by xenomai, and this activate the watchdog ? whereas in secondary mode, time is not counted by xenomai watchdog ?

Yes, secondary mode would be accounted to Linux, thus the watchdog would be happy (and your Linux subsystem as well because it would be allowed to breath).

Quoted 3 lines

I will try to increase the watchdog time to see if this is only a matter of a task taking to much time.

Wrong approach. First check how long your loop actually takes. If you have to tweak the watchdog (and there is no bug in the trivial watchdog code), it's your code that is broken.

Jan