Page MenuHomeFreeBSD

improvements to kproc/kthread man pages
Needs RevisionPublic

Authored by jmg on Aug 15 2015, 7:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, May 11, 7:03 AM
Unknown Object (File)
May 2 2024, 2:27 AM
Unknown Object (File)
Apr 29 2024, 3:57 AM
Unknown Object (File)
Apr 28 2024, 7:48 AM
Unknown Object (File)
Apr 11 2024, 11:14 PM
Unknown Object (File)
Apr 11 2024, 3:27 PM
Unknown Object (File)
Apr 11 2024, 2:53 PM
Unknown Object (File)
Apr 9 2024, 2:55 PM

Details

Reviewers
bjk
jhb
Group Reviewers
manpages
Summary

Document how to handle exiting properly for modules.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 114
Build 114: arc lint + arc unit

Event Timeline

jmg retitled this revision from to improvements to kproc/kthread man pages.
jmg updated this object.
jmg edited the test plan for this revision. (Show Details)
jmg added a reviewer: jhb.
jmg set the repository for this revision to rS FreeBSD src repository - subversion.

add documentation to kthread, and fix up kproc Sx

jmg edited edge metadata.
  • Fix date..

fix sentence on new line..

bjk requested changes to this revision.Aug 15 2015, 11:41 PM
bjk added a reviewer: bjk.
bjk added a subscriber: bjk.
bjk added inline comments.
share/man/man9/kproc.9
182

The section is named EXAMPLES (with an 'S').

share/man/man9/kthread.9
202

"used by callers" can lead to confusion about who is doing what. Does it allow other threads to receive a notification when the thread calling kthread_exit() terminates? That might be a more clear thing to say.

204

EXAMPLES again.

207

Maybe s/The/That/?

This revision now requires changes to proceed.Aug 15 2015, 11:41 PM
jmg edited edge metadata.

hopefully update the diff w/ complete change..

jmg edited edge metadata.
  • address comments from bjk...
jmg marked 4 inline comments as done.Aug 15 2015, 11:53 PM

Address all but /The/That/ change.. I understand why you suggested it, but it reads not as easily for me... We are only referencing the once example.

wblock added inline comments.
share/man/man9/kproc.9
328

Can "needs to" be replaced with "must" for clarity?

share/man/man9/kthread.9
28

Remember to update this.

198

Nice!

jmg edited edge metadata.
  • change a needs to to a must to be more correct.. If there are threads
jmg marked 3 inline comments as done.Aug 16 2015, 4:31 AM

Thanks. changed.

share/man/man9/kproc.9
185

There is a lot of ambiguity here. It reads like the proc pointer is what can be used to tell when a function is no longer running, but probably really means the result of the wakeup. "To know" is also kind of hard to interpret. Should "proc pointer" just be .Fa proc ?

A
.Fn wakeup
is issued on the proc pointer.
The (return value? which one?) can be used by callers to determine
whether the called function is no longer running.

The second sentence could be improved, but it depends on what it is trying to say.

...can be used by callers to determine if the called function is still running or has ended.
188

The "this" is nonspecific, we were just talking about ecode and wakeup, so it's not clear whether "this" might be referring to them.

The
.Sx EXAMPLES
section shows how to use
.Fn kproc_exit
to ensure that a module is unloaded safely.
share/man/man9/kproc.9
185

a wakeup is issued with the struct proc * returned from kproc_start.

*sleep will return success (for a wakeup) or some errno when it is interrupted or it times out.

359

likely want to unlock and destroy proc_interlock too.

Technically it is not a hard requirement that you call kthread_exit/kproc_exit(). If you return from your main routine, then fork_exit() calls kproc_exit(0) (should probably be fixed to call kthread_exit() instead).

share/man/man9/kproc.9
359

The PDROP unlocks the lock. However, a more realistic example is that you re-use an existing lock used in the "do work" section. Often you end up with something like:

struct mtx foo_lock;
volatile int foo_quit;
struct proc *foo_kproc;
struct foo_state foo_state;

void
foo_main(void *arg)
{

  mtx_lock(&foo_lock);
  while (!foo_quit) {
    /* do work */
    mtx_sleep(&foo_state, &foo_lock, ....);
  }
  mtx_unlock(&foo_lock);
  kproc_exit(0);
}

void
loadmod(void)
{

  kproc_create(foo_main, NULL, &foo_proc, 0, 0, "foo proc");
}

void
unloadmod(void)
{

  mtx_lock(&foo_lock);
  foo_quit = 1;
  wakeup(&foo_state);
  mtx_sleep(foo_proc, &foo_lock, PDROP, "fooexit", 0);
  /* foo_main has called kproc_exit, and module is safe to unload. */
}
timmoore88_gmail.com added inline comments.
share/man/man9/kthread.9
204

"See the EXAMPLES section in .Xr kproc 9 for how to use this to ensure that a module is unloaded safely." - seems a little confusing.

"Refer to the EXAMPLES section in .Xr kproc 9 for ways to ensure a module is unloaded safely." - suggested change.

share/man/man9/kproc.9
28

This needs to be bumped again.

This revision now requires changes to proceed.Jun 18 2020, 1:24 PM