Date: Mon, 3 Jun 2002 11:30:40 +0800 From: "kai ouyang" <oykai@msn.com> To: "John Baldwin" <jhb@FreeBSD.org>, <current@FreeBSD.org> Subject: Re:Help: from proc to thread? Message-ID: <OE73usjzpDr3Di32AvJ00011357@hotmail.com>
next in thread | raw e-mail | index | archive | help
------=_NextPart_001_0000_01C20AF2.1747CCA0
Content-Type: multipart/alternative; boundary="----=_NextPart_002_0001_01C20AF2.1747CCA0"
------=_NextPart_002_0001_01C20AF2.1747CCA0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: quoted-printable
>> Based on the explain of the thread: struct proc *td_proc; /* Associate=
d process. */ in the struct
>> thread.
>> and refer to the CCD code.
>> I modify this function as following:
>> int raidlookup(path, td, vpp)
>>  char   *path;
>>  struct thread *td;
>>  struct vnode **vpp; /* result */
>> {
>>  struct nameidata nd;
>>  struct vnode *vp;
>>  struct vattr va;
>>  struct proc *p;
>>  int     error, flags;
>>  /* Sanity check the p_fd fields.  This is really just a hack */
>>  p =3D td->td_proc;
>So it dies here?
>> Now the system will be crash , when it excutes the "p =3D td->td_proc"=
.
>> the system Information is :
>> kernel: type 12 trap, code=3D0
>> Stopped at raidlookup+0x19: movl 0(%eax),%ebx
>Hmm, can you get the 'faulting va (virtual address)' error message that =
it
>prints out?
>Add a line to the beginning of the function as a sanity check that does:
>KASSERT(td !=3D NULL, "thread is null");
>and compile your kernel with invariants and see if it panics with
>"thread is null".
Yeah, thread is NULL.
But I view all the callers, I did not find any assignment to td.
I do not know the kernel how assign td to the structure.
The RAIDFrame has the similar function as the vinum. I find this problem =20
when I config a RAID level volume.
Now, I check the raidctlioctl() function,because the process is here from=
 user space to =20
kernel space.
Because the raidlookup's td is gotten from raidctlioctl() function.
I add the two line to the latter function.
KASSERT(td !=3D NULL, ("raidctlioctl thread is NULL"));
KASSERT(raidPtr->engine_thread !=3D NULL, ("raidctlioctl engine thread is=
 NULL"));
It debugs in the second line. So, the raidctlioctl funcion has the td, bu=
t didn't =20
transfer the parameter to the raidlookup().
Hmmmm....
I take place the two line by the following lines:
KASSERT(td !=3D NULL, ("raidctlioctl thread is NULL"));
raidPtr->engine_thread =3D td;
KASSERT(raidPtr->engine_thread !=3D NULL, ("raidctlioctl engine thread is=
 NULL"));
now it pass.
I want to know when the kernel assign td to raidctlioctl function?
Now, the RAIDFrame will be crash here:
 RF_THREADGROUP_WAIT_START(&raidPtr->engine_tg);
panic: runq_choose: process 218(raid) in state 3
Debugger("panic")
Stopped at Debugger+0x40: xorl %eax,%eax
raidPtr->engine_tg is the RF_ThreadGroup_s structure.
struct RF_ThreadGroup_s {
 int     created;
 int     running;
 int     shutdown;
 struct  mtx mutex;
        int     cond;
};
/*
 * Wait for all threads to start running
 */
#define RF_THREADGROUP_WAIT_START(_g_) { \
 mtx_lock(&(_g_)->mutex); \
 while((_g_)->running < (_g_)->created) { \
  RF_LTSLEEP(&((_g_)->cond), PRIBIO, "rfwcond", 0, &((_g_)->mutex)); \
 } \
 mtx_unlock(&(_g_)->mutex); \
}
RF_LTSLEEP(void *cond, int pri, const char *text, int time, struct mtx *m=
utex)
{
 return (msleep(cond, mutex, pri, text, time));
}
I man mtx_lock and find it excute after mtx_init().
before the macro RF_THREADGROUP_WAIT_START, it call the rf_mtx_init();
int rf_mutex_init(m)
struct mtx *m;
{
 mtx_init(m, "RAIDFrame FreeBSD5.0", MTX_DEF);
 return (0);
}
So..... I am puzzled about it.=B4=D3=CD=F8=D5=BE=B5=C3=B5=BD=B8=FC=B6=E0=D0=
=C5=CF=A2=A1=A3MSN Explorer =C3=E2=B7=D1=CF=C2=D4=D8:http://explorer.msn.=
com/lccn
------=_NextPart_002_0001_01C20AF2.1747CCA0
Content-Type: text/html; charset="gb2312"
Content-Transfer-Encoding: quoted-printable
<HTML><BODY STYLE=3D"font:10pt verdana; border:none;"><DIV>>> Based=
 on the explain of the thread: struct proc *td_proc; /* Associated proces=
s. */ in the struct<BR>>> thread.<BR>>> and refer to the CCD =
code.<BR>>> I modify this function as following:<BR>>> int ra=
idlookup(path, td, vpp)<BR>>>  char   *path;<BR>>=
>  struct thread *td;<BR>>>  struct vnode **vpp; /* re=
sult */<BR>>> {<BR>>>  struct nameidata nd;<BR>>>&=
nbsp; struct vnode *vp;<BR>>>  struct vattr va;<BR>>>&nb=
sp; struct proc *p;<BR>>>  int     error, =
flags;<BR>>>  /* Sanity check the p_fd fields.  This is r=
eally just a hack */<BR>>>  p =3D td->td_proc;</DIV> <DIV>&=
gt;So it dies here?</DIV> <DIV>>> Now the system will be crash , wh=
en it excutes the "p =3D td->td_proc".<BR>>> the system Informat=
ion is :<BR>>> kernel: type 12 trap, code=3D0<BR>>> Stopped a=
t raidlookup+0x19: movl 0(%eax),%ebx</DIV> <DIV>>Hmm, can you get the =
'faulting va (virtual address)' error message that it<BR>>prints out?<=
/DIV> <DIV>>Add a line to the beginning of the function as a sanity ch=
eck that does:</DIV> <DIV>>KASSERT(td !=3D NULL, "thread is null");</D=
IV> <DIV>>and compile your kernel with invariants and see if it panics=
 with<BR>>"thread is null".</DIV> <DIV>Yeah, thread is NULL.<BR>But I =
view all the callers, I did not find any assignment to td.<BR>I do not kn=
ow the kernel how assign td to the structure.<BR>The RAIDFrame has the si=
milar function as the vinum. I find this problem <BR>when I config a RAID=
 level volume.<BR>Now, I check the raidctlioctl() function,because the pr=
ocess is here from user space to <BR>kernel space.<BR>Because the raidloo=
kup's td is gotten from raidctlioctl() function.<BR>I add the two line to=
 the latter function.<BR>KASSERT(td !=3D NULL, ("raidctlioctl thread is N=
ULL"));<BR>KASSERT(raidPtr->engine_thread !=3D NULL, ("raidctlioctl en=
gine thread is NULL"));<BR>It debugs in the second line. So, the raidctli=
octl funcion has the td, but didn't <BR>transfer the parameter to the rai=
dlookup().<BR>Hmmmm....<BR>I take place the two line by the following lin=
es:<BR>KASSERT(td !=3D NULL, ("raidctlioctl thread is NULL"));<BR>raidPtr=
->engine_thread =3D td;<BR>KASSERT(raidPtr->engine_thread !=3D NULL=
, ("raidctlioctl engine thread is NULL"));<BR>now it pass.</DIV> <DIV>I w=
ant to know when the kernel assign td to raidctlioctl function?</DIV> <DI=
V>Now, the RAIDFrame will be crash here:<BR> RF_THREADGROUP_WAIT_STA=
RT(&raidPtr->engine_tg);<BR>panic: runq_choose: process 218(raid) =
in state 3<BR>Debugger("panic")<BR>Stopped at Debugger+0x40: xorl %eax,%e=
ax</DIV> <DIV>raidPtr->engine_tg is the RF_ThreadGroup_s structure.</D=
IV> <DIV>struct RF_ThreadGroup_s {<BR> int     c=
reated;<BR> int     running;<BR> int &=
nbsp;   shutdown;<BR> struct  mtx mutex;<BR> &nb=
sp;      int     cond;<BR>};=
<BR>/*<BR> * Wait for all threads to start running<BR> */<BR>#d=
efine RF_THREADGROUP_WAIT_START(_g_) { \<BR> mtx_lock(&(_g_)->=
;mutex); \<BR> while((_g_)->running < (_g_)->created) { \<B=
R>  RF_LTSLEEP(&((_g_)->cond), PRIBIO, "rfwcond", 0, &am=
p;((_g_)->mutex)); \<BR> } \<BR> mtx_unlock(&(_g_)->m=
utex); \<BR>}</DIV> <DIV>RF_LTSLEEP(void *cond, int pri, const char *text=
, int time, struct mtx *mutex)<BR>{<BR> return (msleep(cond, mutex, =
pri, text, time));<BR>}</DIV> <DIV>I man mtx_lock and find it excute afte=
r mtx_init().<BR>before the macro RF_THREADGROUP_WAIT_START, it call the =
rf_mtx_init();<BR>int rf_mutex_init(m)<BR>struct mtx *m;<BR>{<BR> mt=
x_init(m, "RAIDFrame FreeBSD5.0", MTX_DEF);<BR> return (0);<BR>}<BR>=
So..... I am puzzled about it.</DIV></BODY></HTML><br clear=3Dall><hr>=B4=
=D3=CD=F8=D5=BE=B5=C3=B5=BD=B8=FC=B6=E0=D0=C5=CF=A2=A1=A3MSN Explorer =C3=
=E2=B7=D1=CF=C2=D4=D8=A3=BA<a href=3D'http://explorer.msn.com/lccn'>http:=
//explorer.msn.com/lccn</a><br></p>
------=_NextPart_002_0001_01C20AF2.1747CCA0--
------=_NextPart_001_0000_01C20AF2.1747CCA0
Content-Type: text/plain; name="rehelp.txt"
Content-Disposition: attachment; filename="rehelp.txt"
Content-Transfer-Encoding: quoted-printable
>> Based on the explain of the thread: struct proc *td_proc; /* Associate=
d process. */ in the struct
>> thread.
>> and refer to the CCD code.
>> I modify this function as following:
>> int raidlookup(path, td, vpp)
>>  char   *path;
>>  struct thread *td;
>>  struct vnode **vpp; /* result */
>> {
>>  struct nameidata nd;
>>  struct vnode *vp;
>>  struct vattr va;
>>  struct proc *p;
>>  int     error, flags;
>>  /* Sanity check the p_fd fields.  This is really just a hack */
>>  p =3D td->td_proc;
>So it dies here?
>> Now the system will be crash , when it excutes the "p =3D td->td_proc"=
.
>> the system Information is :
>> kernel: type 12 trap, code=3D0
>> Stopped at raidlookup+0x19: movl 0(%eax),%ebx
>Hmm, can you get the 'faulting va (virtual address)' error message that =
it
>prints out?
>Add a line to the beginning of the function as a sanity check that does:
>KASSERT(td !=3D NULL, "thread is null");
>and compile your kernel with invariants and see if it panics with
>"thread is null".
Yeah, thread is NULL.
But I view all the callers, I did not find any assignment to td.
I do not know the kernel how assign td to the structure.
The RAIDFrame has the similar function as the vinum. I find this problem =20
when I config a RAID level volume.
Now, I check the raidctlioctl() function,because the process is here from=
 user space to =20
kernel space.
Because the raidlookup's td is gotten from raidctlioctl() function.
I add the two line to the latter function.
KASSERT(td !=3D NULL, ("raidctlioctl thread is NULL"));
KASSERT(raidPtr->engine_thread !=3D NULL, ("raidctlioctl engine thread is=
 NULL"));
It debugs in the second line. So, the raidctlioctl funcion has the td, bu=
t didn't =20
transfer the parameter to the raidlookup().
Hmmmm....
I take place the two line by the following lines:
KASSERT(td !=3D NULL, ("raidctlioctl thread is NULL"));
raidPtr->engine_thread =3D td;
KASSERT(raidPtr->engine_thread !=3D NULL, ("raidctlioctl engine thread is=
 NULL"));
now it pass.
I want to know when the kernel assign td to raidctlioctl function?
Now, the RAIDFrame will be crash here:
	RF_THREADGROUP_WAIT_START(&raidPtr->engine_tg);
panic: runq_choose: process 218(raid) in state 3
Debugger("panic")
Stopped at Debugger+0x40: xorl %eax,%eax
raidPtr->engine_tg is the RF_ThreadGroup_s structure.
struct RF_ThreadGroup_s {
	int     created;
	int     running;
	int     shutdown;
	struct  mtx mutex;
        int     cond;
};
/*
 * Wait for all threads to start running
 */
#define RF_THREADGROUP_WAIT_START(_g_) { \
	mtx_lock(&(_g_)->mutex); \
	while((_g_)->running < (_g_)->created) { \
		RF_LTSLEEP(&((_g_)->cond), PRIBIO, "rfwcond", 0, &((_g_)->mutex)); \
	} \
	mtx_unlock(&(_g_)->mutex); \
}
RF_LTSLEEP(void *cond, int pri, const char *text, int time, struct mtx *m=
utex)
{
	return (msleep(cond, mutex, pri, text, time));
}
I man mtx_lock and find it excute after mtx_init().
------=_NextPart_001_0000_01C20AF2.1747CCA0--
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?OE73usjzpDr3Di32AvJ00011357>
