Skip site navigation (1)Skip section navigation (2)
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>&gt;&gt; Based=
 on the explain of the thread: struct proc *td_proc; /* Associated proces=
s. */ in the struct<BR>&gt;&gt; thread.<BR>&gt;&gt; and refer to the CCD =
code.<BR>&gt;&gt; I modify this function as following:<BR>&gt;&gt; int ra=
idlookup(path, td, vpp)<BR>&gt;&gt;&nbsp; char&nbsp;&nbsp; *path;<BR>&gt;=
&gt;&nbsp; struct thread *td;<BR>&gt;&gt;&nbsp; struct vnode **vpp; /* re=
sult */<BR>&gt;&gt; {<BR>&gt;&gt;&nbsp; struct nameidata nd;<BR>&gt;&gt;&=
nbsp; struct vnode *vp;<BR>&gt;&gt;&nbsp; struct vattr va;<BR>&gt;&gt;&nb=
sp; struct proc *p;<BR>&gt;&gt;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp; error, =
flags;<BR>&gt;&gt;&nbsp; /* Sanity check the p_fd fields.&nbsp; This is r=
eally just a hack */<BR>&gt;&gt;&nbsp; p =3D td-&gt;td_proc;</DIV> <DIV>&=
gt;So it dies here?</DIV> <DIV>&gt;&gt; Now the system will be crash , wh=
en it excutes the "p =3D td-&gt;td_proc".<BR>&gt;&gt; the system Informat=
ion is :<BR>&gt;&gt; kernel: type 12 trap, code=3D0<BR>&gt;&gt; Stopped a=
t raidlookup+0x19: movl 0(%eax),%ebx</DIV> <DIV>&gt;Hmm, can you get the =
'faulting va (virtual address)' error message that it<BR>&gt;prints out?<=
/DIV> <DIV>&gt;Add a line to the beginning of the function as a sanity ch=
eck that does:</DIV> <DIV>&gt;KASSERT(td !=3D NULL, "thread is null");</D=
IV> <DIV>&gt;and compile your kernel with invariants and see if it panics=
 with<BR>&gt;"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-&gt;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=
-&gt;engine_thread =3D td;<BR>KASSERT(raidPtr-&gt;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>&nbsp;RF_THREADGROUP_WAIT_STA=
RT(&amp;raidPtr-&gt;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-&gt;engine_tg is the RF_ThreadGroup_s structure.</D=
IV> <DIV>struct RF_ThreadGroup_s {<BR>&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp; c=
reated;<BR>&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp; running;<BR>&nbsp;int&nbsp;&=
nbsp;&nbsp;&nbsp; shutdown;<BR>&nbsp;struct&nbsp; mtx mutex;<BR>&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp; cond;<BR>};=
<BR>/*<BR>&nbsp;* Wait for all threads to start running<BR>&nbsp;*/<BR>#d=
efine RF_THREADGROUP_WAIT_START(_g_) { \<BR>&nbsp;mtx_lock(&amp;(_g_)-&gt=
;mutex); \<BR>&nbsp;while((_g_)-&gt;running &lt; (_g_)-&gt;created) { \<B=
R>&nbsp;&nbsp;RF_LTSLEEP(&amp;((_g_)-&gt;cond), PRIBIO, "rfwcond", 0, &am=
p;((_g_)-&gt;mutex)); \<BR>&nbsp;} \<BR>&nbsp;mtx_unlock(&amp;(_g_)-&gt;m=
utex); \<BR>}</DIV> <DIV>RF_LTSLEEP(void *cond, int pri, const char *text=
, int time, struct mtx *mutex)<BR>{<BR>&nbsp;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>&nbsp;mt=
x_init(m, "RAIDFrame FreeBSD5.0", MTX_DEF);<BR>&nbsp;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>