1 2 Previous Next 20 Replies Latest reply: Sep 19, 2010 5:34 PM by 807557 RSS

    Real Time on Ubuntu 10.04..It's my procedure ok?

    807557
      I'm an Italian student and I'm a beginner in java's Real Time context. I've installed on Ubuntu 10.04 the package "linux-image-rt " , a simply version of Netbeans with JDK 1.6.0_20 and the java_rts-2_2 and renamed the libcap2.so as libcap1 . As your guide suggest http://download.oracle.com/javase/realtime/doc_2.2/release/JavaRTSQuickStart.html I've modified the limit.conf file (each line WITHOUT the # before ) : the installation goes well because tipyng java -version I read "Java Real Time System HotSpot Client VM" . I've compiled and run my code with the instruction indicated in http://download.oracle.com/javase/realtime/doc_2.2/release/JavaRTSQuickStart.html#step6 and the example-code works fine .I've omitted something? When I programmed in RTAI , during the execution of RealTime code the computer were totally blocked ; however when I run my Java Real Time code I can move the mouse , close the shell etc.. It's all ok?Please help me,I'm disperate =)
        • 1. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
          807557
          If your real-time Java code would consume all available processors and runs at a real-time priority greater than the services that handle your mouse and shell etc then your system should "freeze" while that code executes. I know this from experience on Solaris and the RT Linux systems we support.

          But I can't tell you what your linux-image-rt actually provides in terms of real-time support. You'd have to ask the folks that provide it.

          Can you run top in another terminal window and see if your program is really running with real-time priorities? Are you sure it would consume all the available CPU?

          David Holmes
          Oracle
          • 2. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
            807557
            if I run in a shell my java real time code and in another shell another program ,they run together =(
            • 3. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
              807557
              I've installed linux-image-2.6.31-11-rt
              • 4. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                807557
                As I said while your real-time program is running check to see if it appears to be running with real-time priority.

                Can you show the sample code your are running? Will it consume all available CPUs? How many CPUs do you have?

                David Holmes
                • 5. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                  807557
                  I have only one CPU , and my java code is the example HelloWorldRT that Sun suggest on http://download.oracle.com/javase/realtime/doc_2.2/release/HelloWorldRT.java . When I run that program and another, they run together. How can I do to check the priority ? Thanks a lot for you're help! =) =)
                  • 6. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                    807557
                    That program doesn't consume 100% of the CPU, it runs a periodic thread with a 2ms period that checks the elapsed time when it wakes up. There's no reason other programs shouldn't run concurrently with it.

                    The check the priority use top - it shows real-time priority as a negative value if I recall correctly. Else check the ps man page and use a ps command that lists all your processes and displays real-time priority value.

                    Try running the program below and see if you "freeze" for 5 seconds.

                    BTW are you sure you only have one processor? It's not multi-core or even hyper-threaded?

                    David Holmes
                    --------------------
                    import javax.realtime.*;
                    
                    class Prog1 extends RealtimeThread {
                    
                        static final Timed timed =
                            new Timed(new RelativeTime(5000,0)); // fire after 5 seconds
                    
                        public void run() {
                            Interruptible runner = new Interruptible() {
                                    public void run(AsynchronouslyInterruptedException aie)
                                        throws AsynchronouslyInterruptedException {
                                        System.out.println("Runner.run started");
                                        while(true) { // spin till we get interrupted
                                            Thread.yield();
                                            if (user == null) break;
                                        }
                                        System.out.println("Runner.run done");
                                    }
                                    public void interruptAction( AsynchronouslyInterruptedException
                    aie) {
                                        System.out.println("Runner.interruptAction called");
                                    }
                                };
                            boolean accepted = true;
                            accepted = timed.doInterruptible(runner);
                            if (accepted) {
                                System.out.println("Runner accepted");
                            } else {
                                System.out.println("Runner rejected");
                            }
                        }
                    
                    
                        static Prog1 user = new Prog1();
                    
                        static public void main(String[] args) throws Throwable {
                            user.start();
                            try {
                                user.join();
                            } catch (InterruptedException e) {
                            }
                            System.out.println("Done");
                        }
                    }
                    Edited by: davidholmes on Sep 16, 2010 7:43 PM
                    • 7. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                      807557
                      The system doesn't freeze..only th execution last 5 second ..I've check top in another shell during the runnin of Your code and I see that

                      7773 root 20 0 302m 301m 56m S 101 30.3 0:03.05 java
                      4568 grimaldi 20 0 411m 137m 28m S 8 13.9 38:17.44 firefox-bin
                      4040 root 20 0 186m 42m 8436 S 3 4.3 7:58.61 Xorg
                      4399 grimaldi 20 0 46548 13m 10m S 2 1.4 14:41.70 gnome-terminal
                      7 root -50 -5 0 0 0 S 0 0.0 0:12.80 sirq-net-rx/0
                      22 root -50 -5 0 0 0 S 0 0.0 0:04.98 sirq-block/1
                      664 root -51 -5 0 0 0 S 0 0.0 0:06.42 irq/12-i8042
                      4992 root 20 0 4628 1968 1512 S 0 0.2 0:00.37 bash
                      1 root 20 0 2796 1516 1136 S 0 0.1 0:01.07 init
                      2 root 15 -5 0 0 0 S 0 0.0 0:00.00 kthreadd
                      3 root RT -5 0 0 0 S 0 0.0 0:00.00 migration/0
                      4 root -50 -5 0 0 0 S 0 0.0 0




                      There are negative value, value "RT" and java seems to be at 20 level of priority..what does it means?
                      • 8. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                        807557
                        Sorry I don't think top is showing you everything. There are multiple threads in the process and you're only seeing the main one I think.

                        Try running this ps command while java is running (maybe change the timeout in the program to be 50000 (50 seconds) to have more time to do this).

                        ps -C java -o pid,tid,class,rtprio,ni,pri,psr -m

                        David
                        • 9. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                          807557
                          Ok , while running java i've typed you command and this is the result

                          grimaldi@grimaldi-desktop:~/Scrivania$ ps -C java -o pid,tid,class,rtprio,ni,pri,psr -m
                          PID TID CLS RTPRIO NI PRI PSR
                          8064 - - - - - -
                          - 8064 TS - 0 19 0
                          - 8065 TS - 0 19 0
                          - 8066 TS - 0 19 0
                          - 8067 TS - 0 19 0
                          - 8068 TS - 0 19 0
                          - 8069 FF 25 - 65 0
                          - 8070 FF 1 - 41 1
                          - 8071 TS - 0 19 0
                          - 8072 TS - 0 19 0
                          - 8073 FF 25 - 65 1
                          - 8074 TS - 0 19 1
                          - 8075 FF 1 - 41 0
                          - 8076 TS - 0 19 1
                          - 8077 TS - 0 19 1
                          - 8078 TS - 0 19 1
                          - 8079 TS - 0 19 1
                          - 8080 TS - 0 19 1
                          - 8081 TS - 0 19 1
                          - 8082 FF 49 - 89 0
                          - 8083 FF 49 - 89 1
                          - 8084 FF 48 - 88 0
                          - 8085 FF 16 - 56 0
                          • 10. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                            807557
                            Ps in system monitor i check :

                            Processor 0 :Intel Pentium D CPU 2,66GHz

                            Processor 1 :Intel Pentium D CPU 2,66GHz
                            • 11. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                              807557
                              Yes I was about to point out to you that the PSR column indicates you have two processors - hence my program won't freeze your system as it only consumes one.

                              Change the timeout to, say 30 seconds, and run two copies of the program at once. That should freeze your system.

                              David
                              • 12. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                                807557
                                OK =) When I run both your code , the first 2-3 second the system isn't frooze but after 4 second mouse goes slowly :D Can I show you my code ?
                                It just interact with a program write in C that move up and down a pin of the LPT port via JNI.These operations are executable in real time context?I thinked yes,so i write that code :
                                import javax.realtime.RealtimeThread;
                                /**
                                 * 
                                 * @author grimaldi
                                 */
                                public class JRTOndaQTestRTAI {
                                 public static void main(String[] args) {
                                       
                                   RealtimeThread rt=new RealtimeThread(){
                                
                                    public void run() {
                                
                                        RTOndaQ10.alza();
                                
                                    }
                                
                                    };
                                   
                                    rt.start();
                                
                                }
                                }
                                The java class that implements the native metod is:
                                public class RTOndaQ10
                                
                                {
                                
                                   public static native void alza();
                                
                                
                                
                                
                                
                                   static
                                
                                   {
                                
                                      System.loadLibrary("RTOndaQ10");
                                
                                   }
                                
                                }
                                
                                 
                                and finally the C code is : {code

                                #include <asm/io.h>
                                #include <sys/mman.h>
                                #include "OndaQ10.h"
                                #include <stdio.h>
                                #include <string.h>
                                #include <stdlib.h>
                                //#include <sys/io.h>


                                #define range 8
                                #define BUF_SIZE 512
                                #define PORT 0x378
                                #define DEVICE_NAME "/dev/dsp"


                                JNIEXPORT void JNICALL Java_OndaQ10_alza(JNIEnv* env, jclass cl)
                                {

                                     unsigned long int i;
                                     unsigned long int j;
                                     unsigned long int k;
                                     ioperm(0x378,2,1);
                                     for(k=0;k<45000;k++){
                                          for(i=0;i<2E9;i++) if(inb(0x379)==0x3f) i=2E9; //check pin is dpwn
                                          for(i=0;i<2E9;i++) if(inb(0x379)==0x7f) i=2E9; //check pin is up
                                          outb(0x01, 0x378); //pin goes up
                                          for (j=0;j<2E6;j++) asm("nop");
                                          outb(0, 0x378); //pin goes down
                                     }
                                     
                                }



                                }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                • 13. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                                  807557
                                  Glad things seem to be working, though I would have expected a complete freeze ... though it does depend the system service and IRQ priorities.

                                  If the intent is that your code is not interruptible while strobing the pin you need to be aware of system interrupts as they could interrupt your code.

                                  David
                                  • 14. Re: Real Time on Ubuntu 10.04..It's my procedure ok?
                                    807557
                                    I run the code that you see on 2 identic PC and my goal is to misure the sincronization of that PC through an oscilloscope..Without any human IO interrupt , and closing all unnecessary programs (Firefox etc ) I believe that the PC are sincronized at microsecond (with CRTAI I measured a deviation standard of 10^-7 second )..what do you think about ? really a big big big thanks =)
                                    1 2 Previous Next