Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jun 2008 00:23:32 -0700
From:      Julian Elischer <julian@elischer.org>
To:        Saradhi Kothapalli <saikothapalli@gmail.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: Threads stuck in kserel state
Message-ID:  <4860A0F4.1040304@elischer.org>
In-Reply-To: <52db57fb0806232344y95eb159ra2dd43a4462ee082@mail.gmail.com>
References:  <52db57fb0806232344y95eb159ra2dd43a4462ee082@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Saradhi Kothapalli wrote:
> Hi
> 
> I am running FreeBSD 5.4 on my machine. When i run mpd on it, i see it stuck
> in kserel state.
> I have written a sample thread program to check whether its an mpd problem
> or not.
> 
> Observations on the Sample test program:
> 
> I have created only one thread from the process, but the top output shows
> total 3 entries.

yes

The thread you started in sleeping in ttyin.
the thread library greated a background thread to handle signal 
delivery (ksesig).
When the main thread did ttyin, it blocked, so a third thread was 
created to make sure that if any other work had to be done there was a 
thread to do it. that third thread is waiting for more work to appear,
and in kserel (kse-release).

> Even when the thread has finished i see 2 entries that to one in kserel and
> other in ksesig state.
> 
> Is the main process stuck in "kserel" state or is it an expected behavior?
> Is it because of KSE the other thread is shown in top output? Is the state
> "ksesig" signifies that it is waiting for an event to occur?
> 
> 
> Thanks in advance for the help.
> 
> Regards
> Saradhi
> 
> 
> The Sample Test program:
> 
> #include <stdio.h>
> #include <pthread.h>
> #include <pdel/structs/structs.h>
> #include <pdel/structs/type/array.h>
> #include <pdel/util/typed_mem.h>
> #include <pdel/util/pevent.h>
> #include <pdel/util/paction.h>
> #include <pdel/util/ghash.h>
> #include <unistd.h>
> 
> pthread_mutex_t mutex;
> 
> static void
> startFn(void * arg)
> {
>     printf("\n *** Thread Start Function *** \n");
>     getchar();
>     return;
> }
> 
> static void
> endFn(void * arg, int done)
> {
>     printf("\n *** Thread End Function *** \n");
>     getchar();
>     return;
> }
> 
> static void
> thrStart()
> {
>     struct paction * thr;
>     uint32_t temp;
> 
>     if ( paction_start(&thr, &mutex, startFn, endFn, &temp) == -1 )
>     {
>         printf("\n *** Failed to start thread *** \n ");
>         getchar();
>     }
>     return ;
> }
> 
> int main()
> {
> 
>     int ret = pthread_mutex_init(&mutex, NULL);
>     if ( ret != 0 )
>     {
>         printf("\n *** Mutex initialization Failed *** \n");
>         return -1;
>     }
> 
>     printf("\n *** calling thread start *** \n ");
>     getchar();
> 
>     thrStart();
> 
>     for ( ; ; )
>     {
>         sleep(1);
>     }
>     return 0;
> }
> 
> THE TOP OUTPUT WITH THREAD DISPLAY TURNED ON:
> 
> When the thread is in existence (both during start and end function):
> -----------------------------------------------------------------------------------------------------
> 
> 18387 root      20    0  3384K  1760K ksesig   0:00  0.00%  0.00% thrd
> 18387 root      20    0  3384K  1760K kserel   0:00  0.00%  0.00% thrd
> 18387 root       5    0  3384K  1760K  ttyin    0:00  0.00%  0.00% thrd
> 
> After the thread execution is completed (the for loop):
> ---------------------------------------------------------
> 18387 root      20    0  3384K  1752K ksesig   0:00  0.00%  0.00% thrd
> 18387 root      20    0  3384K  1752K kserel   0:00  0.00%  0.00% thrd
> _______________________________________________
> freebsd-threads@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org"




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4860A0F4.1040304>