public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] help in tcp/ip stack !!!
@ 2001-06-04 18:07 wangwei
  2001-06-05  5:53 ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: wangwei @ 2001-06-04 18:07 UTC (permalink / raw)
  To: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Hi,all
help me !!
I make a tcp server in ecos. when client connect with it , appliaction
dynamically create a thread to communicate with client.
the client is running in linux, and can be run in background .
At normal, the server can running stably.
When I make a shell to run lots of client program in background,more than 30
clients,the server in ecos give "EXH 4" error.
In this application, My memory in ecos is more than 3M ,there is enough
memory for malloc. And when thread which run server program is ended, the
memory it used can be free .So I think memory cann't cause this problem.

I had met the "EXH 4" error before . When I try ipaq nanox package in ecos ,
it call nanosleep() in a no posix thread , and cause a "EXH 4" error.
so I suspect it is caused by the same reason .but I can't find out .

The program is in attachment . Does anybody read it and help me !!
thanks.

[-- Attachment #2: my_thread.h --]
[-- Type: text/plain, Size: 269 bytes --]

typedef struct EXTEND_THREAD_PARAM {
	char thread_name[50];
	cyg_handle_t handle;
	void * stack_base;
	void * memp;
	cyg_thread thread_instance;
	void * private;
	} Extend_Thread_Param;
typedef struct CLIENT_DATA{
	int sfd;
	struct sockaddr_in cliaddr;
	} client_data;

[-- Attachment #3: tcp_test.c --]
[-- Type: text/x-c, Size: 3859 bytes --]

#include <cyg/kernel/kapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <network.h>
#include <pkgconf/net.h>
#include <pkgconf/system.h>
#include <cyg/infra/testcase.h>
#include "my_thread.h"

static cyg_mbox mbox0,mbox1;
static cyg_handle_t m0,m1;
cyg_thread tdeamon,tcreater;
cyg_handle_t h_deamon,h_creater;
static int living_thread;

#define THREADNAME "testthread"

#define THREAD_STACK_SIZE 4096
char stack[2][THREAD_STACK_SIZE];

extern void * Malloc_Thread(int size)
{
        int true_size;
	void *p;
	Extend_Thread_Param *tp;
        // the true_size will include the thread parameter
        true_size=size+sizeof(Extend_Thread_Param);
        p=malloc(true_size);     
	tp=(Extend_Thread_Param *) p;
	tp->memp=p;
	tp->stack_base=p+sizeof(Extend_Thread_Param);
	return p;
}

void test( Extend_Thread_Param *p)

{
	Extend_Thread_Param my_thread_param;
	client_data *clidata;
	char net_addr[16],*addr,str[20];
	int i,j;

	sprintf(str,"0123456789\n");
	bzero(net_addr,sizeof(net_addr));
	my_thread_param=*p;
	clidata=my_thread_param.private;
	addr=inet_ntoa(clidata->cliaddr.sin_addr);
	sprintf(net_addr,"%s",addr);
	//printf("the stack is %x\n",(unsigned int ) p);
	//diag_printf("connect by %s,0x%x\n",net_addr,clidata->cliaddr.sin_port);
	i=rand()%50;
	for(j=0;j<i;j++)
	  write(clidata->sfd,str,11);
	
	close(clidata->sfd);
	free(clidata);
	cyg_mbox_put(m0,(void *)&my_thread_param);
	
	

	/*
	//printf("%s Param_thread_param address is %x\n",p->thread_name,
	//		(cyg_addrword_t)&my_thread_param);
	cyg_thread_delay(100+rand()%2000);
	//printf("%s is end \n",my_thread_param.thread_name);
	cyg_mbox_put(m0,(void *)&my_thread_param);
	*/
}


void deamon_thread(void)
{
	Extend_Thread_Param  *p,ThreadParam;
	while(1)
	{
	 p=(Extend_Thread_Param *) cyg_mbox_get(m0);
	 ThreadParam=*p;
	 cyg_thread_kill(ThreadParam.handle);
	 free(ThreadParam.memp);
	 living_thread--;
	}
}

void thread_creater()
{
	Extend_Thread_Param *tp;
	void *p;
	int sfd;
	struct sockaddr_in sock_host;
	
    	init_all_network_interfaces();
//	TNR_INIT();
	diag_printf("now server come in\n");

	sfd=socket(AF_INET,SOCK_STREAM,0);
	sock_host.sin_family=AF_INET;
	sock_host.sin_port=htons(9001);
	sock_host.sin_addr.s_addr=htonl(INADDR_ANY);
	bind(sfd,(struct sockaddr *)&sock_host,sizeof(sock_host));
	listen(sfd,8);
	while(1)
	{
	 client_data *client;
	 int cliaddr_len=sizeof(client->cliaddr),i;
	 client=malloc(sizeof(client_data)); 
	 client->sfd=accept(sfd,(struct sockaddr *)&(client->cliaddr),&cliaddr_len);
	 {
	   p=Malloc_Thread(THREAD_STACK_SIZE);
	   tp=(Extend_Thread_Param *)p;
	   sprintf(tp->thread_name,"client%d",i);
	   i++;
	   tp->private=client;
	   cyg_thread_create(14,test,(cyg_addrword_t)tp,
			tp->thread_name,tp->stack_base,THREAD_STACK_SIZE,
			&(tp->handle),&(tp->thread_instance));
	   cyg_thread_resume(tp->handle);
	   living_thread++;
	 }
	}
//	TNR_PRINT_ACTIVITY();
	 
/*
	int i=0,j;
	living_thread=0;
	for(;;)
	{
	 for(j=0;j<100;j++){
	 p=Malloc_Thread(THREAD_STACK_SIZE);
	 tp=(Extend_Thread_Param *)p;
	 sprintf(tp->thread_name,"%s%d",THREADNAME,i);
	 cyg_thread_create(14,test,(cyg_addrword_t)tp,
			tp->thread_name,tp->stack_base,THREAD_STACK_SIZE,
			&(tp->handle),&(tp->thread_instance));
	 cyg_thread_resume(tp->handle);
	 i++;living_thread++;
	 }
	 printf("thread created %d,leave %d\n",i,living_thread);
	 cyg_thread_delay(1000);
	}
*/
}

void cyg_user_start(void)
{
  
    cyg_mbox_create(&m0,&mbox0);
    cyg_mbox_create(&m1,&mbox1);
    

    cyg_thread_create(11,thread_creater,(cyg_addrword_t)0,
		     "Thread create",(void *)stack[0],THREAD_STACK_SIZE,
		     &h_creater,&tcreater);
    cyg_thread_create(10,deamon_thread,(cyg_addrword_t)0,
		     "Thread deamon",(void *)stack[1],THREAD_STACK_SIZE,
		     &h_deamon,&tdeamon);
    cyg_thread_resume(h_deamon);
    cyg_thread_resume(h_creater);
}


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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-04 18:07 [ECOS] help in tcp/ip stack !!! wangwei
@ 2001-06-05  5:53 ` Jonathan Larmour
  2001-06-06  3:34   ` wangwei
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Larmour @ 2001-06-05  5:53 UTC (permalink / raw)
  To: wangwei; +Cc: ecos-discuss

wangwei wrote:
> 
> Hi,all
> help me !!
> I make a tcp server in ecos. when client connect with it , appliaction
> dynamically create a thread to communicate with client.
> the client is running in linux, and can be run in background .
> At normal, the server can running stably.
> When I make a shell to run lots of client program in background,more than 30
> clients,the server in ecos give "EXH 4" error.
> In this application, My memory in ecos is more than 3M ,there is enough
> memory for malloc. And when thread which run server program is ended, the
> memory it used can be free .So I think memory cann't cause this problem.
> 
> I had met the "EXH 4" error before . When I try ipaq nanox package in ecos ,
> it call nanosleep() in a no posix thread , and cause a "EXH 4" error.
> so I suspect it is caused by the same reason .but I can't find out .

That means you got an exception.

I had a quick look at your code and I believe the problem is that you are
using cyg_thread_kill() and then freeing the threads memory. You almost
certainly want to use cyg_thread_delete() instead.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/

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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-05  5:53 ` Jonathan Larmour
@ 2001-06-06  3:34   ` wangwei
  2001-06-06  6:46     ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: wangwei @ 2001-06-06  3:34 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

Thank you ,Jonathan:

I try the method you told me, but the except still happened ,
and sometimes I got the error of  "out of mbuf" .
I suspect when many client connected the server,it will write much data
by tcp , and it will occupy too much mbuf , and cause "exh 4" when the
mbuffer is exhausted .

If so , are there any mechanism to avoid it happen ?
help me again .
thanks.
----- Original Message -----
From: "Jonathan Larmour" <jlarmour@redhat.com>
To: "wangwei" <wangw@start.com.cn>
Cc: <ecos-discuss@sources.redhat.com>
Sent: Tuesday, June 05, 2001 8:53 PM
Subject: Re: [ECOS] help in tcp/ip stack !!!


> wangwei wrote:
> >
> > Hi,all
> > help me !!
> > I make a tcp server in ecos. when client connect with it , appliaction
> > dynamically create a thread to communicate with client.
> > the client is running in linux, and can be run in background .
> > At normal, the server can running stably.
> > When I make a shell to run lots of client program in background,more
than 30
> > clients,the server in ecos give "EXH 4" error.
> > In this application, My memory in ecos is more than 3M ,there is enough
> > memory for malloc. And when thread which run server program is ended,
the
> > memory it used can be free .So I think memory cann't cause this problem.
> >
> > I had met the "EXH 4" error before . When I try ipaq nanox package in
ecos ,
> > it call nanosleep() in a no posix thread , and cause a "EXH 4" error.
> > so I suspect it is caused by the same reason .but I can't find out .
>
> That means you got an exception.
>
> I had a quick look at your code and I believe the problem is that you are
> using cyg_thread_kill() and then freeing the threads memory. You almost
> certainly want to use cyg_thread_delete() instead.
>
> Jifl
> --
> Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
> Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
> Come to the Red Hat TechWorld open source conference in Brussels!
> Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/

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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-06  3:34   ` wangwei
@ 2001-06-06  6:46     ` Jonathan Larmour
  2001-06-07 21:00       ` wangwei
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Larmour @ 2001-06-06  6:46 UTC (permalink / raw)
  To: wangwei; +Cc: ecos-discuss

wangwei wrote:
> 
> Thank you ,Jonathan:
> 
> I try the method you told me, but the except still happened ,
> and sometimes I got the error of  "out of mbuf" .
> I suspect when many client connected the server,it will write much data
> by tcp , and it will occupy too much mbuf , and cause "exh 4" when the
> mbuffer is exhausted .

It looks like you'll have to track down where the exception happened. You
should probably be able to install a signal handler for the exception in
question (likely a SEGV or BUS). If you look at the sival_ptr of the
siginfo_t, that will contain a pointer to the registers, in
Hal_SavedRegisters format. Or set a breakpoint on
cyg_posix_exception_handler and look at the exception_info argument which
is also a pointer to Hal_SavedRegisters.

From that you can determine the PC and possibly also what happened.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/

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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-06  6:46     ` Jonathan Larmour
@ 2001-06-07 21:00       ` wangwei
  2001-06-07 21:14         ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: wangwei @ 2001-06-07 21:00 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

Hi, Jonathan:
I trace it , and find a strange thing .
Before the memory exception happen , there are not any threads in the thread
queue ,system is runing  a thread which not exist . I trace the variable
"queue_map", and find :
     before that , system put idle thread  to sleep and give zero to
"queue_map", and make NONE thread in the
     running  queue .
At that time , I just connected one tcp to ecos , and the function
cyg_thread_delete hadn't run,ecos application is just doing write(),send
something through tcp . So I'm sure that the exception is not caused by the
application .

I think you maybe met this before , when you disigned ecos . because there
are many assertions about queue_map in the source code of mlqueue.cxx.
Can you give me some advice .It 's very important to me.
thinks.
Best regard .

----- Original Message -----
From: "Jonathan Larmour" <jlarmour@redhat.com>
To: "wangwei" <wangw@start.com.cn>
Cc: <ecos-discuss@sources.redhat.com>
Sent: Wednesday, June 06, 2001 9:45 PM
Subject: Re: [ECOS] help in tcp/ip stack !!!


> wangwei wrote:
> >
> > Thank you ,Jonathan:
> >
> > I try the method you told me, but the except still happened ,
> > and sometimes I got the error of  "out of mbuf" .
> > I suspect when many client connected the server,it will write much data
> > by tcp , and it will occupy too much mbuf , and cause "exh 4" when the
> > mbuffer is exhausted .
>
> It looks like you'll have to track down where the exception happened. You
> should probably be able to install a signal handler for the exception in
> question (likely a SEGV or BUS). If you look at the sival_ptr of the
> siginfo_t, that will contain a pointer to the registers, in
> Hal_SavedRegisters format. Or set a breakpoint on
> cyg_posix_exception_handler and look at the exception_info argument which
> is also a pointer to Hal_SavedRegisters.
>
> From that you can determine the PC and possibly also what happened.
>
> Jifl
> --
> Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
> Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
> Come to the Red Hat TechWorld open source conference in Brussels!
> Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/

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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-07 21:00       ` wangwei
@ 2001-06-07 21:14         ` Jonathan Larmour
  2001-06-10 17:41           ` wangwei
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Larmour @ 2001-06-07 21:14 UTC (permalink / raw)
  To: wangwei; +Cc: ecos-discuss

wangwei wrote:
> 
> Hi, Jonathan:
> I trace it , and find a strange thing .
> Before the memory exception happen , there are not any threads in the thread
> queue ,system is runing  a thread which not exist . I trace the variable
> "queue_map", and find :
>      before that , system put idle thread  to sleep and give zero to
> "queue_map", and make NONE thread in the
>      running  queue .
> At that time , I just connected one tcp to ecos , and the function
> cyg_thread_delete hadn't run,ecos application is just doing write(),send
> something through tcp . So I'm sure that the exception is not caused by the
> application .
> 
> I think you maybe met this before , when you disigned ecos . because there
> are many assertions about queue_map in the source code of mlqueue.cxx.
> Can you give me some advice .It 's very important to me.

Have you enabled assertions yourself? It sounds like you haven't then.
Enable CYGPKG_INFRA_DEBUG in your configuration.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/

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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-07 21:14         ` Jonathan Larmour
@ 2001-06-10 17:41           ` wangwei
  2001-06-11 12:55             ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: wangwei @ 2001-06-10 17:41 UTC (permalink / raw)
  To: Jonathan Larmour; +Cc: ecos-discuss

Thanks ! Jonathan
I got the bug !
In file io/fileio/src/socket.cxx , line 720,cyg_file_lock() must be modify
to cyg_file_unlock().
----------------------------------------------------------------------------
----------
static void cyg_sock_unlock( cyg_file *fp )
{
    cyg_nstab_entry *ns = (cyg_nstab_entry *)fp->f_mte;

    if( fp->f_syncmode & CYG_SYNCMODE_SOCK_NETSTACK )
        nstab_lock[ns-&nstab[0]].unlock();

    cyg_file_lock( fp, fp->f_syncmode>>CYG_SYNCMODE_SOCK_SHIFT);
}
----------------------------------------------------------------------------
----------

I'sure this bug make my system dump .
Do you think so ?
Best regard!

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

* Re: [ECOS] help in tcp/ip stack !!!
  2001-06-10 17:41           ` wangwei
@ 2001-06-11 12:55             ` Jonathan Larmour
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Larmour @ 2001-06-11 12:55 UTC (permalink / raw)
  To: wangwei; +Cc: ecos-discuss

wangwei wrote:
> 
> Thanks ! Jonathan
> I got the bug !
> In file io/fileio/src/socket.cxx , line 720,cyg_file_lock() must be modify
> to cyg_file_unlock().
> ----------------------------------------------------------------------------
> ----------
> static void cyg_sock_unlock( cyg_file *fp )
> {
>     cyg_nstab_entry *ns = (cyg_nstab_entry *)fp->f_mte;
> 
>     if( fp->f_syncmode & CYG_SYNCMODE_SOCK_NETSTACK )
>         nstab_lock[ns-&nstab[0]].unlock();
> 
>     cyg_file_lock( fp, fp->f_syncmode>>CYG_SYNCMODE_SOCK_SHIFT);
> }
> ----------------------------------------------------------------------------
> ----------
> 
> I'sure this bug make my system dump .
> Do you think so ?

It certainly looks like a bug. I'll fix our sources. Thanks for spotting
and reporting this!

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/

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

end of thread, other threads:[~2001-06-11 12:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-04 18:07 [ECOS] help in tcp/ip stack !!! wangwei
2001-06-05  5:53 ` Jonathan Larmour
2001-06-06  3:34   ` wangwei
2001-06-06  6:46     ` Jonathan Larmour
2001-06-07 21:00       ` wangwei
2001-06-07 21:14         ` Jonathan Larmour
2001-06-10 17:41           ` wangwei
2001-06-11 12:55             ` Jonathan Larmour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).