Re: FW: Linux preempt policy serial port communication

From: Xianghua Xiao
Date: Tue Jun 29 2010 - 11:55:11 EST


On Tue, Jun 29, 2010 at 4:06 AM, Zhang, Yongchao (GE Healthcare)
<Yongchao.Zhang@xxxxxx> wrote:
> Hi,
> Â We have some problems about serial port. We need your expertise. The
> detail is like this:
>
> 1.Our Goal:
> Â We want to make test on serial port, and want to know whether the
> serial port communication is still OK Âunder heavy system load.
>
> 2.Environment:
> Â Â 1). Two computer,one is as server,another is as client.
> Â Â Â Â The "Server" sends data to serial port. We use a serial port
> tool run on WINXP as server.
> Â Â Â Â The "Client" reads the data from serial port,and run on Linux.
>
> 3.The way access serial port for "client" program:
> Â Â During test procedure, we use Âtwo kinds of way to "read" data from
> serial port. One way is "select +none block read" ,another is Â"block
> read".
> Â Â The code slice Âis as the follwoing:
> Â Â Â Â (1).select+none block read. like this:
> Â Â Â Â Â Â Â Â Â ......
> Â Â Â Â Â Â Â Â Â while(num_of_bytes < len)
> Â Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â Â Â //wait till notified.
> Â Â Â Â Â Â Â Â Â Â Â Â Â while((select(m_fileDescriptor+1,&m_readSet,
> NULL, NULL, NULL)) == -1 && errno == EINTR)
> Â Â Â Â Â Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âusleep(1000);
> Â Â Â Â Â Â Â Â Â Â Â Â Â }
>
> Â Â Â Â Â Â Â Â Â Â Â Â Â //read data
> Â Â Â Â Â Â Â Â Â Â Â Â Â if((readBytes = ::read(m_fileDescriptor,
> (buff+num_of_bytes), (len-num_of_bytes))) == -1)
> Â Â Â Â Â Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âclose();
>
> printf("CS_ERR_READ_SERIAL_PORT_FAIL");
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âexit(0);
> Â Â Â Â Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â Â Â Â Â Â else
> Â Â Â Â Â Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Ânum_of_bytes += readBytes;
> Â Â Â Â Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â Â ......
>
> Â Â Â Â(2).block read
> Â Â Â Â Â Â Â Âfirst set paramer c_cc as this during init.
> Â Â Â Â Â Â Â Â Â Âport_settings.c_cc[VMIN ] Â= 1 ;
> Â Â Â Â Â Â Â Â Â Âport_settings.c_cc[VTIME] = 0 ;
> Â Â Â Â Â Â Â Âsecond,read directly
> Â Â Â Â Â Â Â Â Â ÂreadBytes = ::read(m_fileDescriptor,
> (buff+num_of_bytes), (len-num_of_bytes))) == -1
>
> 4. The heavy load simulation program.
> Â Â Â Â ÂHere we write a program to simulate heavy CPU load in linux
> system. This "heavy load program" create one thread and promote thread
> prority to 99, which is the top most in system. This thread did nothing
> but empty loop and never release CPU resource actively.The code slice as
> following:
>
> Â Â Â Â Â //create this thread
> Â Â Â Â Â ....
> Â Â Â Â Â pthread_create(&m_hThread[1],NULL,fifo_99_1 Â,(void*)&trans)
> Â Â Â Â Â ....
>
> Â Â Â Â Â //thread proc
> Â Â Â Â Â void* fifo_99(void *para)
> Â Â Â Â Â {
> Â Â Â Â Â Â Â struct sched_param param;
>
> Â Â Â Â Â Â Â //adjust prority to FIFO 99.
>        pthread_t thread_t   = pthread_self();
> Â Â Â Â Â Â Â param.sched_priority = 99;
> Â Â Â Â Â Â Â pthread_setschedparam(thread_t,SCHED_FIFO,&param);
>
> Â Â Â Â Â Â Â //only cost CPU resource
> Â Â Â Â Â Â Â while(1)
> Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â for (int z = 0; z < 10000; z++)
> Â Â Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â }
> Â Â Â Â Â Â Â }
> Â Â Â Â Â }
>
> 5. Test procedure
> Â Â(1).
> Â Â Â Â Procedure:
> Â Â Â Â Â ÂRun serial port client program,the program is just waitting
> serial port data. ÂThe "client" program is run with normal priority.
> Â Â Â Â Â ÂRun 99 FIFO emluator,so the CPU cost is 100% almost now.
> Â Â Â Â Â ÂRun serial tool in WindowXP,and send data to client,total
> send several groups of data.
>
> Â Â Â Â Test result:
> Â Â Â Â Â ÂFind the "client" program could not recevie the data during
> FIFO 99 emluator running. But if break the emluator , the "client"
> program could read out all the data
> Âimmediately. We get know that it is "select" statement that always
> blocked without waken up if FIFO 99 running . So it seems the system
> could not notify the "serial port data received signal" to "select"
> statement in time.
>
> Â Â Â Â Analysis & ÂQuestion:
> Â Â Â Â Â ÂWhy FIFO 99 could affect on serial port read? Could you
> please point out the detail code position(maybe in serial port driver)?
> And how to avoid this to let "serial port reading" could not be
> disturbed by any other thread or process even if FIFO 99?
>
> Â (2).
> Â Â Â ÂProcedure
> Â Â Â Â Â The same procedure with (1). But this time we also promote
> the "client" program to FIFO 99.
> Â Â Â ÂTest result:
> Â Â Â Â Â The same with (1).
> Â Â Â ÂAnalysis & Question:
> Â Â Â Â Â Once we doube that the thread priority of the "client"
> program is too low to get CPU resource, so we promote "client" program
> also to FIFO 99.
> Â Â Â Â Â But also could not read out the data until heavy load is
> over. Maybe even high priority for "client" program have no effect on
> this.
>
> Â (3).
> Â Â Â Â Procedure:
> Â Â Â Â Â ÂThe same with (1). But this time change FIFO 99 to FIFO 98,
> and also "client" program is run with normal priority.
> Â Â Â Â Test result:
> Â Â Â Â Â ÂThe "client" program could read the data in time,all is OK.
> Â Â Â Â Analysis & Question:
> Â Â Â Â Â ÂFIFO 99,98 are both high prority in system. But 98 could not
> affect on the serial port,99 could. FIFO 99,98 are both high priority,
> why is it so much difference for serial port reading?
>
> Â (4).
> Â Â Â Â Procedure:
> Â Â Â Â Â ÂThe same with (3). But this time we run two heavy load
> programs i.e. two FIFO 98 in linux system.
> Â Â Â Â Test result:
> Â Â Â Â Â ÂThere is much difference with (1) and (3). ÂWe will find
> "client" program could receive the data but have some delay(about 2~4
> seconds delay)
> Â Â Â Â Analysis & Question:
> Â Â Â Â Â ÂTwo FIFO98 are also heavy load to system,but compared with
> FIFO 99,FIFO 98 is not so rigorous. So system maybe give "some running
> slice" to notify the "select" statement though could not be in time but
> still have opportunity to notify. Right?
>
>
> Â From our tests, we want to consult with you following questions:
>
> Â 1. Why FIFO 99 could affect on serial port read? Could you please
> point out the detail code position(maybe in serial port driver)? ÂAnd
> how to avoid this to let "serial port reading" could not be disturbed by
> any other thread or process even if FIFO 99?
>
> Â 2. From procedure (2),To FIFO 99,98,why is there so much difference
> for serial port reading?
>
>
> Thanks!
>
> Best Regards!
>
> -------------------------
> Philip
> 2010.06.29
> -------------------------
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
which kernel/rt-patch are you using to do this test?
can you also list all the RT threads with their priorities, e.g.
softirqs etc, say: ps -e -o pid,rtprio,comm | grep sirq


Xianghua
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/