Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Apr 2024 22:21:12 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Rocky Hotas <rockyhotas@tilde.team>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Re: Kernel module: return a number from a device
Message-ID:  <CANCZdfrN3HnqfLLptMF5PBaNGpDDkC-LwGCCzMj6unAw=U-JnQ@mail.gmail.com>
In-Reply-To: <qarvyeobx2iumkc3ae6noaiukffpfgwihap32vi4yaqnkqigbi@3nxb4nmvub32>
References:  <CANCZdfqAUWqp_s8ULhi9A97jrMCxA1CAXJKmUJ307=PSpekKug@mail.gmail.com> <qarvyeobx2iumkc3ae6noaiukffpfgwihap32vi4yaqnkqigbi@3nxb4nmvub32>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Sat, Apr 6, 2024 at 3:00 PM Rocky Hotas <rockyhotas@tilde.team> wrote:

> On apr 06 14:39, Warner Losh wrote:
> > When this happens, hit ^t (control t). That will give a traceback of the
> > call stack which may help you track down where it is hanging (most likely
> > something is sleeping waiting for an event).
>
> Thanks! It seems that cat itself is hanging (so, uiomove can still be
> the
> culprit...):
>
> $ cat rolld
> Opened device "rolld" successfully.
> load: 0.44  cmd: cat 13392 [running] 7.67r 1.25u 6.39s 38% 1936k
>

running means there's a tight loop somewhere... uiomove doesn't do that. It
is a bunch of ifs that go to a copyout.  Arc4random shouldn't either. I'd
add printf to see where.




> I also tried to modify rolld_read using only char variables:
>
> static int
> rolld_read(struct cdev *dev __unused, struct uio *uio, int ioflag
> __unused)
> {
>         char random_out;
>         char random_item;
>         int error;
>
>         random_item = (char) arc4random();
>         random_out = random_item % d_size;
>
>         if ((error = uiomove(&random_out, 1, uio)) != 0)
>                 uprintf("uiomove failed!\n");
>
>         return (error);
> }
>
>
> But nothing changed with respect to the first version.
>

This should produce an infinite number of chars...  maybe it is and d_size
is 1 and they are all NULs. Try cat -v.

Warner


> Rocky
>
>

[-- Attachment #2 --]
<div dir="auto"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 6, 2024 at 3:00 PM Rocky Hotas &lt;rockyhotas@tilde.team&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On apr 06 14:39, Warner Losh wrote:<br>
&gt; When this happens, hit ^t (control t). That will give a traceback of the<br>
&gt; call stack which may help you track down where it is hanging (most likely<br>
&gt; something is sleeping waiting for an event).<br>
<br>
Thanks! It seems that cat itself is hanging (so, uiomove can still be<br>
the<br>
culprit...):<br>
<br>
$ cat rolld <br>
Opened device &quot;rolld&quot; successfully.<br>
load: 0.44  cmd: cat 13392 [running] 7.67r 1.25u 6.39s 38% 1936k<br></blockquote><div><br></div><div>running means there&#39;s a tight loop somewhere... uiomove doesn&#39;t do that. It is a bunch of ifs that go to a copyout.  Arc4random shouldn&#39;t either. I&#39;d add printf to see where.</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I also tried to modify rolld_read using only char variables:<br>
<br>
static int<br>
rolld_read(struct cdev *dev __unused, struct uio *uio, int ioflag<br>
__unused)<br>
{<br>
        char random_out;<br>
        char random_item;<br>
        int error;<br>
<br>
        random_item = (char) arc4random();<br>
        random_out = random_item % d_size;<br>
<br>
        if ((error = uiomove(&amp;random_out, 1, uio)) != 0)<br>
                uprintf(&quot;uiomove failed!\n&quot;);<br>
<br>
        return (error);<br>
}<br>
<br>
<br>
But nothing changed with respect to the first version.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">This should produce an infinite number of chars...  maybe it is and d_size is 1 and they are all NULs. Try cat -v.</div><div dir="auto"><br></div><div dir="auto">Warner</div><div dir="auto"><br></div><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Rocky<br>
<br>
</blockquote></div></div></div>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrN3HnqfLLptMF5PBaNGpDDkC-LwGCCzMj6unAw=U-JnQ>