All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] POSIX API
@ 2008-05-13  3:51 Breno Carneiro Pinheiro
  2008-05-13  6:17 ` Wolfgang Grandegger
  2008-05-13  8:49 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 5+ messages in thread
From: Breno Carneiro Pinheiro @ 2008-05-13  3:51 UTC (permalink / raw)
  To: xenomai@xenomai.org


[-- Attachment #1.1: Type: text/plain, Size: 1989 bytes --]

Hi all, I wanna some help with my application. I'm learning about Xenomai
POSIX and Native API. I wonder know what is wrong with my code below because
both don't worked out:

POSIX:

#include <sys/mman.h>

#include <posix/pthread.h>
#include <posix/time.h>

#include <stdio.h>

static pthread_t task_desc;
void task_body (void *cookie)
 {
     struct timespec time;
     clock_gettime(CLOCK_MONOTONIC, &time);;
     pthread_make_periodic_np(pthread_self(),&time, 1000000000);
     while(1) {
     printf("%s\n","a");
     }
 }

int main (int argc, char *argv[])

 {
     int ret;
     pthread_attr_t thattr;

     pthread_attr_init(&thattr);
     pthread_attr_setdetachstate(&thattr, 0);
     pthread_attr_setstacksize(&thattr, 1024);
     ret = pthread_create(&task_desc, NULL, &task_body, NULL);

     if(!ret)
      pthread_join(task_desc, NULL);

 }

and NATIVE

#include <sys/mman.h>
#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/pipe.h>

#include <stdio.h>
#define TASK_PRIO  99 /* Highest RT priority */
#define TASK_MODE  0  /* No flags */
#define TASK_STKSZ 0  /* Stack size (use default one) */

RT_TASK task_desc;
RTIME period_ns =  1000000000llu;
void task_body (void *cookie)
 {
     unsigned long overrun;
     rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(period_ns));
     while(1) {
     rt_task_wait_period(&overrun);
     printf("%s\n","a");
     }
 }

int main (int argc, char *argv[])

 {
     int err;
     int ret;
     pthread_attr_t thattr;
     mlockall(MCL_CURRENT|MCL_FUTURE);

     err = rt_task_create(&task_desc,
                          "teste",
                          TASK_STKSZ,
                          TASK_PRIO,
                          TASK_MODE);


    if (!err)
         rt_task_start(&task_desc,&task_body,NULL);

     /* ... */
 }

 void cleanup (void)

 {
    rt_task_delete(&task_desc);
 }

I used the Makefile attached and tried to run on powerpc processor using
NFS.

Thanks,

Breno

[-- Attachment #1.2: Type: text/html, Size: 3774 bytes --]

[-- Attachment #2: Makefile --]
[-- Type: application/octet-stream, Size: 2504 bytes --]

###### CONFIGURATION ######

### List of applications to be build
APPLICATIONS = task_test

### Note: to override the search path for the xeno-config script, use "make XENO=..."


### List of modules to be build
MODULES =

### Note: to override the kernel source path, use "make KSRC=..."

all::

#task_test: task_test.c


###### USER SPACE BUILD (no change required normally) ######
ifeq ($(KERNELRELEASE),)
ifneq ($(APPLICATIONS),)

### Default Xenomai installation path
XENO ?= /home/breno/ELDK/ppc_6xx/usr/local/xenomai/

XENOCONFIG=$(shell PATH=$(XENO):$(XENO)/bin:$(PATH) which xeno-config 2>/dev/null)

### Sanity check
ifeq ($(XENOCONFIG),)
all::
	@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
	@echo
endif


CC=$(shell $(XENOCONFIG) --cc) -I/usr/local/xenomai/include

CFLAGS=-DCONSUMER $(shell $(XENOCONFIG) --posix-cflags) $(APP_CFLAGS)

LDFLAGS=$(shell $(XENOCONFIG) --posix-ldflags) $(APP_LDFLAGS)

# This includes the library path of given Xenomai into the binary to make live
# easier for beginners if Xenomai's libs are not in any default search path.
LDFLAGS+=-Xlinker -rpath -Xlinker $(shell $(XENOCONFIG) --libdir) -lpsos 

all:: $(APPLICATIONS)

clean::
	$(RM) $(APPLICATIONS) *.o

endif
endif



###### KERNEL MODULE BUILD (no change required normally) ######
ifneq ($(MODULES),)

### Default to sources of currently running kernel
#KSRC ?= /home/breno/ELDK/ppc_6xx/lib/modules/$(shell uname -r)/build
KSRC ?= /home/breno/ELDK/ppc_6xx/usr/src/Denx-kernel-tree-2
#KSRC ?= /lib/modules/$(shell uname -r)/build
OBJS     := ${patsubst %, %.o, $(MODULES)}
CLEANMOD := ${patsubst %, .%*, $(MODULES)}
PWD      := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

### Kernel 2.6
PATCHLEVEL:=$(shell sed 's/PATCHLEVEL = \(.*\)/\1/;t;d' $(KSRC)/Makefile)
ifeq ($(PATCHLEVEL),6)

obj-m        := $(OBJS)
EXTRA_CFLAGS := -DPRODUCER -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix $(ADD_CFLAGS) 

all::
	$(MAKE) -C $(KSRC) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) SUBDIRS=$(PWD) modules
	$(RM) *.o

### Kernel 2.4
else

ARCH    ?= $(shell uname -i)
INCLUDE := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/compat -I$(KSRC)/include/xenomai/posix
CFLAGS  := $(shell $(MAKE) -s -C $(KSRC) CC=$(CC) ARCH=$(ARCH) SUBDIRS=$(PWD) modules) $(INCLUDE)

all:: $(OBJS)

endif

## Target for capturing 2.4 module CFLAGS
modules:
	@echo "$(CFLAGS)"

clean::
	$(RM) $(CLEANMOD) *.o *.ko *.mod.c Module*.symvers
	$(RM) -R .tmp*
	$(RM) .runinfo

endif


[-- Attachment #3: Makefile.native --]
[-- Type: application/octet-stream, Size: 2467 bytes --]

###### CONFIGURATION ######

### List of applications to be build
#APPLICATIONS = trivial-periodic sigxcpu rtprint
APPLICATIONS = task_test_native
### Note: to override the search path for the xeno-config script, use "make XENO=..."


### List of modules to be build
MODULES =

### Note: to override the kernel source path, use "make KSRC=..."



###### USER SPACE BUILD (no change required normally) ######
ifeq ($(KERNELRELEASE),)
ifneq ($(APPLICATIONS),)

### Default Xenomai installation path
#XENO ?= /usr/xenomai
XENO ?= /home/breno/ELDK/ppc_6xx/usr/local/xenomai/
XENOCONFIG=$(shell PATH=$(XENO):$(XENO)/bin:$(PATH) which xeno-config 2>/dev/null)

### Sanity check
ifeq ($(XENOCONFIG),)
all::
	@echo ">>> Invoke make like this: \"make XENO=/path/to/xeno-config\" <<<"
	@echo
endif

CC=$(shell $(XENOCONFIG) --cc)

CFLAGS=$(shell $(XENOCONFIG) --xeno-cflags) $(MY_CFLAGS)

LDFLAGS=$(shell $(XENOCONFIG) --xeno-ldflags) $(MY_LDFLAGS) -lnative

# This includes the library path of given Xenomai into the binary to make live
# easier for beginners if Xenomai's libs are not in any default search path.
LDFLAGS+=-Xlinker -rpath -Xlinker $(shell $(XENOCONFIG) --libdir)

all:: $(APPLICATIONS)

clean::
	$(RM) $(APPLICATIONS) *.o

endif
endif



###### SPECIAL TARGET RULES ######
#task_test_native: task_test_native.c
#	$(CC) $(CFLAGS) $? $(LDFLAGS) -lrtdk -o $@
#	$(CC) $(CFLAGS) $? $(LDFLAGS) -lpsos -o $@



###### KERNEL MODULE BUILD (no change required normally) ######
ifneq ($(MODULES),)

### Default to sources of currently running kernel
#KSRC ?= /lib/modules/$(shell uname -r)/build
KSRC ?= /home/breno/ELDK/ppc_6xx/lib/modules/$(shell uname -r)/build

OBJS     := ${patsubst %, %.o, $(MODULES)}
CLEANMOD := ${patsubst %, .%*, $(MODULES)}
PWD      := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)

### Kernel 2.6
ifeq ($(findstring 2.6,$(KSRC)),2.6)

obj-m        := $(OBJS)
EXTRA_CFLAGS := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/posix $(ADD_CFLAGS)

all::
	$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules

### Kernel 2.4
else

ARCH    ?= $(shell uname -i)
INCLUDE := -I$(KSRC)/include/xenomai -I$(KSRC)/include/xenomai/compat -I$(KSRC)/include/xenomai/posix
CFLAGS  += $(shell $(MAKE) -s -C $(KSRC) CC=$(CC) ARCH=$(ARCH) SUBDIRS=$(PWD) modules) $(INCLUDE)

all:: $(OBJS)

endif

## Target for capturing 2.4 module CFLAGS
modules:
	@echo "$(CFLAGS)"

clean::
	$(RM) $(CLEANMOD) *.o *.ko *.mod.c Module*.symvers
	$(RM) -R .tmp*

endif

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

* Re: [Xenomai-help] POSIX API
  2008-05-13  3:51 Breno Carneiro Pinheiro
@ 2008-05-13  6:17 ` Wolfgang Grandegger
  2008-05-13  8:49 ` Gilles Chanteperdrix
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfgang Grandegger @ 2008-05-13  6:17 UTC (permalink / raw)
  To: Breno Carneiro Pinheiro; +Cc: xenomai@xenomai.org

Breno Carneiro Pinheiro wrote:
> Hi all, I wanna some help with my application. I'm learning about
> Xenomai POSIX and Native API. I wonder know what is wrong with my code
> below because both don't worked out:
> 
> POSIX:
> 
> #include <sys/mman.h>
> 
> #include <posix/pthread.h>
> #include <posix/time.h>
> 
> #include <stdio.h>
> 
> static pthread_t task_desc;
> void task_body (void *cookie)
>  {
>      struct timespec time;
>      clock_gettime(CLOCK_MONOTONIC, &time);;
>      pthread_make_periodic_np(pthread_self(),&time, 1000000000);
>      while(1) {
>      printf("%s\n","a");
>      }
>  }
>  
> int main (int argc, char *argv[])
>  
>  {
>      int ret;
>      pthread_attr_t thattr;
>  
>      pthread_attr_init(&thattr);
>      pthread_attr_setdetachstate(&thattr, 0);
>      pthread_attr_setstacksize(&thattr, 1024);
>      ret = pthread_create(&task_desc, NULL, &task_body, NULL);
>     
>      if(!ret)
>       pthread_join(task_desc, NULL);
>    
>  }
> 
> and NATIVE
> 
> #include <sys/mman.h>
> #include <native/task.h>
> #include <native/queue.h>
> #include <native/intr.h>
> #include <native/pipe.h>
> 
> #include <stdio.h>
> #define TASK_PRIO  99 /* Highest RT priority */
> #define TASK_MODE  0  /* No flags */
> #define TASK_STKSZ 0  /* Stack size (use default one) */
>  
> RT_TASK task_desc;
> RTIME period_ns =  1000000000llu;
> void task_body (void *cookie)
>  {
>      unsigned long overrun;
>      rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(period_ns));
>      while(1) {
>      rt_task_wait_period(&overrun);
>      printf("%s\n","a");
>      }
>  }
>  
> int main (int argc, char *argv[])
>  
>  {
>      int err;
>      int ret;
>      pthread_attr_t thattr;
>      mlockall(MCL_CURRENT|MCL_FUTURE);
>  
>      err = rt_task_create(&task_desc,
>                           "teste",
>                           TASK_STKSZ,
>                           TASK_PRIO,
>                           TASK_MODE);
>     
>     
>     if (!err)
>          rt_task_start(&task_desc,&task_body,NULL);
>  
>      /* ... */
>  }
> 
>  void cleanup (void)
> 
>  {
>     rt_task_delete(&task_desc);
>  }
> 
> I used the Makefile attached and tried to run on powerpc processor using
> NFS.

Please, don't bother use with obviously incomplete and buggy code.
Start with working examples. As I told you, there are examples on how to
use the native. POSIX and RTDM skin in

  http://www.rts.uni-hannover.de/xenomai/lxr/source/examples/

Can you make and run them on your target?

Wolfgang.


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

* Re: [Xenomai-help] POSIX API
  2008-05-13  3:51 Breno Carneiro Pinheiro
  2008-05-13  6:17 ` Wolfgang Grandegger
@ 2008-05-13  8:49 ` Gilles Chanteperdrix
  1 sibling, 0 replies; 5+ messages in thread
From: Gilles Chanteperdrix @ 2008-05-13  8:49 UTC (permalink / raw)
  To: Breno Carneiro Pinheiro; +Cc: xenomai@xenomai.org

On Tue, May 13, 2008 at 5:51 AM, Breno Carneiro Pinheiro
<brenodee@domain.hid> wrote:
> Hi all, I wanna some help with my application. I'm learning about Xenomai
> POSIX and Native API. I wonder know what is wrong with my code below because
> both don't worked out:
>
> POSIX:
>
> #include <sys/mman.h>
>
> #include <posix/pthread.h>
> #include <posix/time.h>

This should be:
#include <pthread.h>
#include <time.h>

If you want your application to be portable accross posix implementations.

>
> #include <stdio.h>
>
> static pthread_t task_desc;
> void task_body (void *cookie)
>  {
>      struct timespec time;
>      clock_gettime(CLOCK_MONOTONIC, &time);;
>       pthread_make_periodic_np(pthread_self(),&time, 1000000000);

Bad arguments type passed to pthread_make_periodic_np, read its
prototype in Xenomai online documentation. You should get a compiler
warning here, and if you do not get a compiler warning, then you are
not compiling with sufficient warnings, try -Wall or even -Wall -W. My
favorite is -Wall -W -Werror-implicit-function-declaration.

>      while(1) {
>      printf("%s\n","a");

missing pthread_wait_period_np. And in fact, you should not be using
pthread_make_periodic_np/pthread_wait_period_np at all since they are
rtlinux extensions to the posix interface and are implemented in
Xenomai posix skin only for compatibility with rtlinux, you should be
using clock_nanosleep.

Also, using printf in a real-time loop is not a good idea.

>      }
>  }
>
> int main (int argc, char *argv[])
>
>  {
>      int ret;
>       pthread_attr_t thattr;
>

Missing mlockall (unless you configured xenomai with --enable-posix-mlockall).

>      pthread_attr_init(&thattr);
>      pthread_attr_setdetachstate(&thattr, 0);
>      pthread_attr_setstacksize(&thattr, 1024);

Much too small, especially since you use printf which requires some
space on the stack. Use 65536 instead of 1024 for instance.
Also, since the thread you create is a real-time thread you should
give it a real-time priority, i.e. use the SCHED_FIFO policy with a
priority between 1 and 99.

>      ret = pthread_create(&task_desc, NULL, &task_body, NULL);

You initialized a thread attribute structure and do not use it.

>
>      if(!ret)
>       pthread_join(task_desc, NULL);
>
>  }
>


-- 
 Gilles


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

* [Xenomai-help] POSIX API
@ 2012-05-15  8:02 ali hagigat
  2012-05-15  8:55 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 5+ messages in thread
From: ali hagigat @ 2012-05-15  8:02 UTC (permalink / raw)
  To: xenomai

I am looking for all POSIX functions of Linux, i wonder if any body
has POSIX.1-2008 manual or IEEE1003.1 or a similar document.
Does xenomai change libc.a ? As far as I understood, xenomai adds new
functions(they start with rt_), besides it changes some of posix
functions while it keeps some posix functions untouched.
Is there any book regarding to the real time programming in xenomai?
Sorry for too many questions...
Regards


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

* Re: [Xenomai-help] POSIX API
  2012-05-15  8:02 [Xenomai-help] POSIX API ali hagigat
@ 2012-05-15  8:55 ` Gilles Chanteperdrix
  0 siblings, 0 replies; 5+ messages in thread
From: Gilles Chanteperdrix @ 2012-05-15  8:55 UTC (permalink / raw)
  To: ali hagigat; +Cc: xenomai

On 05/15/2012 10:02 AM, ali hagigat wrote:
> I am looking for all POSIX functions of Linux, i wonder if any body
> has POSIX.1-2008 manual or IEEE1003.1 or a similar document.
> Does xenomai change libc.a ? As far as I understood, xenomai adds new
> functions(they start with rt_), besides it changes some of posix
> functions while it keeps some posix functions untouched.

Functions which start with rt_ are part of the native skin. The
implementation of the posix skin does not change libc.a, it implements a
new library libpthread_rt.so, and the function substitution is done at
link-edition time by using the linker --wrap option.

> Is there any book regarding to the real time programming in xenomai?

You can start here:
http://www.xenomai.org/index.php/Included_documentation_summary

For instance the --wrap trick is explained here:
http://www.xenomai.org/index.php/Porting_POSIX_applications_to_Xenomai#Under_the_hood:_the_--wrap_flag

-- 
					    Gilles.


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

end of thread, other threads:[~2012-05-15  8:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-15  8:02 [Xenomai-help] POSIX API ali hagigat
2012-05-15  8:55 ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2008-05-13  3:51 Breno Carneiro Pinheiro
2008-05-13  6:17 ` Wolfgang Grandegger
2008-05-13  8:49 ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.